Skip to content

Commit e767edc

Browse files
authored
Name mappers cleanup and new GAECV mapper (#1677)
Cleanup name mappers usage and introduce new, more selective mapper GAECV. Changes: * introduce GAECV next to existing GAV name mapper. * make default GAECV
1 parent f299b25 commit e767edc

File tree

20 files changed

+352
-55
lines changed

20 files changed

+352
-55
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.eclipse.aether.internal.impl.synccontext.named;
20+
21+
import org.eclipse.aether.artifact.Artifact;
22+
23+
/**
24+
* Artifact GAECV {@link NameMapper} extends {@link GAVNameMapper} and improves artifact name mapping selectivity by
25+
* using all coordinates.
26+
*
27+
* @since 1.9.25
28+
*/
29+
public class GAECVNameMapper extends GAVNameMapper {
30+
public GAECVNameMapper(
31+
boolean fileSystemFriendly,
32+
String artifactPrefix,
33+
String artifactSuffix,
34+
String metadataPrefix,
35+
String metadataSuffix,
36+
String fieldSeparator) {
37+
super(fileSystemFriendly, artifactPrefix, artifactSuffix, metadataPrefix, metadataSuffix, fieldSeparator);
38+
}
39+
40+
@Override
41+
protected String getArtifactName(Artifact artifact) {
42+
if (artifact.getClassifier().isEmpty()) {
43+
return artifactPrefix
44+
+ artifact.getGroupId()
45+
+ fieldSeparator
46+
+ artifact.getArtifactId()
47+
+ fieldSeparator
48+
+ artifact.getExtension()
49+
+ fieldSeparator
50+
+ artifact.getBaseVersion()
51+
+ artifactSuffix;
52+
} else {
53+
return artifactPrefix
54+
+ artifact.getGroupId()
55+
+ fieldSeparator
56+
+ artifact.getArtifactId()
57+
+ fieldSeparator
58+
+ artifact.getExtension()
59+
+ fieldSeparator
60+
+ artifact.getClassifier()
61+
+ fieldSeparator
62+
+ artifact.getBaseVersion()
63+
+ artifactSuffix;
64+
}
65+
}
66+
}

maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/GAVNameMapper.java

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,30 @@
2727
import org.eclipse.aether.metadata.Metadata;
2828
import org.eclipse.aether.named.NamedLockKey;
2929
import org.eclipse.aether.util.PathUtils;
30+
import org.eclipse.aether.util.artifact.ArtifactIdUtils;
3031

3132
import static java.util.Objects.requireNonNull;
3233

3334
/**
3435
* Artifact GAV {@link NameMapper}, uses artifact and metadata coordinates to name their corresponding locks. Is not
3536
* considering local repository, only the artifact coordinates. May use custom prefixes and suffixes and separators,
3637
* hence this instance may or may not be filesystem friendly (depends on strings used).
38+
* <p>
39+
* Note: in earlier Resolver 1.9.x versions this mapper was the default, but it changed to {@link GAECVNameMapper}
40+
* in 1.9.25.
3741
*/
3842
public class GAVNameMapper implements NameMapper {
39-
private final boolean fileSystemFriendly;
43+
protected final boolean fileSystemFriendly;
4044

41-
private final String artifactPrefix;
45+
protected final String artifactPrefix;
4246

43-
private final String artifactSuffix;
47+
protected final String artifactSuffix;
4448

45-
private final String metadataPrefix;
49+
protected final String metadataPrefix;
4650

47-
private final String metadataSuffix;
51+
protected final String metadataSuffix;
4852

49-
private final String fieldSeparator;
53+
protected final String fieldSeparator;
5054

5155
public GAVNameMapper(
5256
boolean fileSystemFriendly,
@@ -78,61 +82,81 @@ public Collection<NamedLockKey> nameLocks(
7882
TreeSet<NamedLockKey> keys = new TreeSet<>(Comparator.comparing(NamedLockKey::name));
7983
if (artifacts != null) {
8084
for (Artifact artifact : artifacts) {
81-
keys.add(NamedLockKey.of(
82-
getArtifactName(artifact, artifactPrefix, fieldSeparator, artifactSuffix),
83-
getArtifactName(artifact, "", ":", "")));
85+
keys.add(NamedLockKey.of(getArtifactName(artifact), ArtifactIdUtils.toBaseId(artifact)));
8486
}
8587
}
8688

8789
if (metadatas != null) {
8890
for (Metadata metadata : metadatas) {
89-
keys.add(NamedLockKey.of(
90-
getMetadataName(metadata, fileSystemFriendly, metadataPrefix, fieldSeparator, metadataSuffix),
91-
getMetadataName(metadata, false, "", ":", "")));
91+
keys.add(NamedLockKey.of(getMetadataName(metadata), toMetadataId(metadata)));
9292
}
9393
}
9494
return keys;
9595
}
9696

97-
private static String getArtifactName(Artifact artifact, String prefix, String separator, String suffix) {
98-
return prefix
97+
protected String getArtifactName(Artifact artifact) {
98+
return artifactPrefix
9999
+ artifact.getGroupId()
100-
+ separator
100+
+ fieldSeparator
101101
+ artifact.getArtifactId()
102-
+ separator
102+
+ fieldSeparator
103103
+ artifact.getBaseVersion()
104-
+ suffix;
104+
+ artifactSuffix;
105105
}
106106

107-
private static final String MAVEN_METADATA = "maven-metadata.xml";
107+
protected static final String MAVEN_METADATA = "maven-metadata.xml";
108108

109-
private static String getMetadataName(
110-
Metadata metadata, boolean fileSystemFriendly, String prefix, String separator, String suffix) {
111-
String name = prefix;
109+
protected String getMetadataName(Metadata metadata) {
110+
String name = metadataPrefix;
112111
if (!metadata.getGroupId().isEmpty()) {
113112
name += metadata.getGroupId();
114113
if (!metadata.getArtifactId().isEmpty()) {
115-
name += separator + metadata.getArtifactId();
114+
name += fieldSeparator + metadata.getArtifactId();
116115
if (!metadata.getVersion().isEmpty()) {
117-
name += separator + metadata.getVersion();
116+
name += fieldSeparator + metadata.getVersion();
118117
}
119118
}
120119
if (!MAVEN_METADATA.equals(metadata.getType())) {
121-
name += separator
120+
name += fieldSeparator
122121
+ (fileSystemFriendly ? PathUtils.stringToPathSegment(metadata.getType()) : metadata.getType());
123122
}
124123
} else {
125124
if (!MAVEN_METADATA.equals(metadata.getType())) {
126125
name += (fileSystemFriendly ? PathUtils.stringToPathSegment(metadata.getType()) : metadata.getType());
127126
}
128127
}
129-
return name + suffix;
128+
return name + metadataSuffix;
130129
}
131130

131+
protected String toMetadataId(Metadata metadata) {
132+
String name = "";
133+
if (!metadata.getGroupId().isEmpty()) {
134+
name += metadata.getGroupId();
135+
if (!metadata.getArtifactId().isEmpty()) {
136+
name += ":" + metadata.getArtifactId();
137+
if (!metadata.getVersion().isEmpty()) {
138+
name += ":" + metadata.getVersion();
139+
}
140+
}
141+
}
142+
if (!metadata.getType().isEmpty()) {
143+
name += (name.isEmpty() ? "" : ":") + metadata.getType();
144+
}
145+
return name;
146+
}
147+
148+
/**
149+
* @deprecated Use {@link NameMappers} to create name mappers instead.
150+
*/
151+
@Deprecated
132152
public static NameMapper gav() {
133153
return new GAVNameMapper(false, "artifact:", "", "metadata:", "", ":");
134154
}
135155

156+
/**
157+
* @deprecated Use {@link NameMappers} to create name mappers instead.
158+
*/
159+
@Deprecated
136160
public static NameMapper fileGav() {
137161
return new GAVNameMapper(true, "artifact~", ".lock", "metadata~", ".lock", "~");
138162
}

maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/NameMappers.java

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@
2121
/**
2222
* As end-user "mappers" are actually configurations/compositions and are constructed from several NameMapper
2323
* implementations, this helper class constructing them. This class also holds "names" used by service locator and
24-
* Guice/Sisu as well.
24+
* Guice/Sisu as well. Ideally, name mapper you want should exist here, constructing name mappers should not be
25+
* needed (unless some very specific case or testing).
2526
*
2627
* @since 1.9.4
2728
*/
2829
public final class NameMappers {
30+
private NameMappers() {}
31+
2932
public static final String STATIC_NAME = "static";
3033

3134
public static final String GAV_NAME = "gav";
@@ -34,6 +37,21 @@ public final class NameMappers {
3437

3538
public static final String FILE_HGAV_NAME = "file-hgav";
3639

40+
/**
41+
* @since 1.9.25
42+
*/
43+
public static final String GAECV_NAME = "gaecv";
44+
45+
/**
46+
* @since 1.9.25
47+
*/
48+
public static final String FILE_GAECV_NAME = "file-gaecv";
49+
50+
/**
51+
* @since 1.9.25
52+
*/
53+
public static final String FILE_HGAECV_NAME = "file-hgaecv";
54+
3755
/**
3856
* @since 1.9.6
3957
*/
@@ -46,11 +64,47 @@ public static NameMapper staticNameMapper() {
4664
}
4765

4866
public static NameMapper gavNameMapper() {
49-
return GAVNameMapper.gav();
67+
return gavNameMapper(false);
68+
}
69+
70+
/**
71+
* @since 1.9.25
72+
*/
73+
public static NameMapper gavNameMapper(boolean fileSystemFriendly) {
74+
if (fileSystemFriendly) {
75+
return new GAVNameMapper(true, "artifact~", ".lock", "metadata~", ".lock", "~");
76+
} else {
77+
return new GAVNameMapper(false, "artifact:", "", "metadata:", "", ":");
78+
}
79+
}
80+
81+
/**
82+
* @since 1.9.25
83+
*/
84+
public static NameMapper gaecvNameMapper() {
85+
return gaecvNameMapper(false);
86+
}
87+
88+
/**
89+
* @since 1.9.25
90+
*/
91+
public static NameMapper gaecvNameMapper(boolean fileSystemFriendly) {
92+
if (fileSystemFriendly) {
93+
return new GAECVNameMapper(true, "artifact~", ".lock", "metadata~", ".lock", "~");
94+
} else {
95+
return new GAECVNameMapper(false, "artifact:", "", "metadata:", "", ":");
96+
}
5097
}
5198

5299
public static NameMapper fileGavNameMapper() {
53-
return new BasedirNameMapper(GAVNameMapper.fileGav());
100+
return new BasedirNameMapper(gavNameMapper(true));
101+
}
102+
103+
/**
104+
* @since 1.9.25
105+
*/
106+
public static NameMapper fileGaecvNameMapper() {
107+
return new BasedirNameMapper(gaecvNameMapper(true));
54108
}
55109

56110
/**
@@ -61,10 +115,17 @@ public static NameMapper fileStaticNameMapper() {
61115
}
62116

63117
public static NameMapper fileHashingGavNameMapper() {
64-
return new BasedirNameMapper(new HashingNameMapper(GAVNameMapper.gav()));
118+
return new BasedirNameMapper(new HashingNameMapper(gavNameMapper(false)));
119+
}
120+
121+
/**
122+
* @since 1.9.25
123+
*/
124+
public static NameMapper fileHashingGaecvNameMapper() {
125+
return new BasedirNameMapper(new HashingNameMapper(gaecvNameMapper(false)));
65126
}
66127

67128
public static NameMapper discriminatingNameMapper() {
68-
return new DiscriminatingNameMapper(GAVNameMapper.gav());
129+
return new DiscriminatingNameMapper(gavNameMapper(false));
69130
}
70131
}

maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/NamedLockFactoryAdapterFactoryImpl.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@
5353
public class NamedLockFactoryAdapterFactoryImpl implements NamedLockFactoryAdapterFactory {
5454
public static final String DEFAULT_FACTORY_NAME = FileLockNamedLockFactory.NAME;
5555

56-
public static final String DEFAULT_NAME_MAPPER_NAME = NameMappers.FILE_GAV_NAME;
56+
public static final String DEFAULT_NAME_MAPPER_NAME = NameMappers.FILE_GAECV_NAME;
5757

5858
/**
59-
* Name of the lock factory to use in session.
59+
* Name of the lock factory to use in session. Out of the box supported ones are "file-lock", "rwlock-local",
60+
* "semaphore-local", "noop". By adding extensions one can extend available lock factories (for example IPC locking).
6061
*
6162
* @configurationSource {@link RepositorySystemSession#getConfigProperties()}
6263
* @configurationType {@link java.lang.String}
@@ -65,8 +66,8 @@ public class NamedLockFactoryAdapterFactoryImpl implements NamedLockFactoryAdapt
6566
public static final String CONFIG_PROP_FACTORY_KEY = NamedLockFactoryAdapter.CONFIG_PROPS_PREFIX + "factory";
6667

6768
/**
68-
* Name of the name mapper to use in session. Out of the box supported ones are "static", "gav", "file-gav",
69-
* "file-hgav", "file-static" and "discriminating".
69+
* Name of the name mapper to use in session. Out of the box supported ones are "static", "gav", "gaecv", "file-gav",
70+
* "file-gaecv", "file-hgav", "file-hgaecv", "file-static" and "discriminating".
7071
*
7172
* @configurationSource {@link RepositorySystemSession#getConfigProperties()}
7273
* @configurationType {@link java.lang.String}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.eclipse.aether.internal.impl.synccontext.named.providers;
20+
21+
import javax.inject.Named;
22+
import javax.inject.Provider;
23+
import javax.inject.Singleton;
24+
25+
import org.eclipse.aether.internal.impl.synccontext.named.NameMapper;
26+
import org.eclipse.aether.internal.impl.synccontext.named.NameMappers;
27+
28+
/**
29+
* The "file-gaecv" name mapper provider.
30+
*
31+
* @since 1.9.25
32+
*/
33+
@Singleton
34+
@Named(NameMappers.FILE_GAECV_NAME)
35+
public class FileGAECVNameMapperProvider implements Provider<NameMapper> {
36+
private final NameMapper mapper;
37+
38+
public FileGAECVNameMapperProvider() {
39+
this.mapper = NameMappers.fileGaecvNameMapper();
40+
}
41+
42+
@Override
43+
public NameMapper get() {
44+
return mapper;
45+
}
46+
}

0 commit comments

Comments
 (0)