Skip to content

Commit c1a8e85

Browse files
authored
[1.9.x] Name mappers cleanup and new GAECV mapper (#1674)
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 f181c06 commit c1a8e85

17 files changed

Lines changed: 335 additions & 31 deletions

File tree

maven-resolver-impl/src/main/java/org/eclipse/aether/impl/guice/AetherModule.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,11 @@
9595
import org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapterFactory;
9696
import org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapterFactoryImpl;
9797
import org.eclipse.aether.internal.impl.synccontext.named.providers.DiscriminatingNameMapperProvider;
98+
import org.eclipse.aether.internal.impl.synccontext.named.providers.FileGAECVNameMapperProvider;
9899
import org.eclipse.aether.internal.impl.synccontext.named.providers.FileGAVNameMapperProvider;
100+
import org.eclipse.aether.internal.impl.synccontext.named.providers.FileHashingGAECVNameMapperProvider;
99101
import org.eclipse.aether.internal.impl.synccontext.named.providers.FileHashingGAVNameMapperProvider;
102+
import org.eclipse.aether.internal.impl.synccontext.named.providers.GAECVNameMapperProvider;
100103
import org.eclipse.aether.internal.impl.synccontext.named.providers.GAVNameMapperProvider;
101104
import org.eclipse.aether.internal.impl.synccontext.named.providers.StaticNameMapperProvider;
102105
import org.eclipse.aether.named.NamedLockFactory;
@@ -282,6 +285,10 @@ protected void configure() {
282285
.annotatedWith(Names.named(NameMappers.GAV_NAME))
283286
.toProvider(GAVNameMapperProvider.class)
284287
.in(Singleton.class);
288+
bind(NameMapper.class)
289+
.annotatedWith(Names.named(NameMappers.GAECV_NAME))
290+
.toProvider(GAECVNameMapperProvider.class)
291+
.in(Singleton.class);
285292
bind(NameMapper.class)
286293
.annotatedWith(Names.named(NameMappers.DISCRIMINATING_NAME))
287294
.toProvider(DiscriminatingNameMapperProvider.class)
@@ -290,10 +297,18 @@ protected void configure() {
290297
.annotatedWith(Names.named(NameMappers.FILE_GAV_NAME))
291298
.toProvider(FileGAVNameMapperProvider.class)
292299
.in(Singleton.class);
300+
bind(NameMapper.class)
301+
.annotatedWith(Names.named(NameMappers.FILE_GAECV_NAME))
302+
.toProvider(FileGAECVNameMapperProvider.class)
303+
.in(Singleton.class);
293304
bind(NameMapper.class)
294305
.annotatedWith(Names.named(NameMappers.FILE_HGAV_NAME))
295306
.toProvider(FileHashingGAVNameMapperProvider.class)
296307
.in(Singleton.class);
308+
bind(NameMapper.class)
309+
.annotatedWith(Names.named(NameMappers.FILE_HGAECV_NAME))
310+
.toProvider(FileHashingGAECVNameMapperProvider.class)
311+
.in(Singleton.class);
297312

298313
bind(NamedLockFactory.class)
299314
.annotatedWith(Names.named(NoopNamedLockFactory.NAME))
@@ -393,20 +408,27 @@ Map<String, ChecksumAlgorithmFactory> provideChecksumTypes(
393408
return Collections.unmodifiableMap(result);
394409
}
395410

411+
@SuppressWarnings("checkstyle:parameternumber")
396412
@Provides
397413
@Singleton
398414
Map<String, NameMapper> provideNameMappers(
399415
@Named(NameMappers.STATIC_NAME) NameMapper staticNameMapper,
400416
@Named(NameMappers.GAV_NAME) NameMapper gavNameMapper,
417+
@Named(NameMappers.GAECV_NAME) NameMapper gaecvNameMapper,
401418
@Named(NameMappers.DISCRIMINATING_NAME) NameMapper discriminatingNameMapper,
402419
@Named(NameMappers.FILE_GAV_NAME) NameMapper fileGavNameMapper,
403-
@Named(NameMappers.FILE_HGAV_NAME) NameMapper fileHashingGavNameMapper) {
420+
@Named(NameMappers.FILE_GAECV_NAME) NameMapper fileGaecvNameMapper,
421+
@Named(NameMappers.FILE_HGAV_NAME) NameMapper fileHashingGavNameMapper,
422+
@Named(NameMappers.FILE_HGAECV_NAME) NameMapper fileHashingGaecvNameMapper) {
404423
Map<String, NameMapper> result = new HashMap<>();
405424
result.put(NameMappers.STATIC_NAME, staticNameMapper);
406425
result.put(NameMappers.GAV_NAME, gavNameMapper);
426+
result.put(NameMappers.GAECV_NAME, gaecvNameMapper);
407427
result.put(NameMappers.DISCRIMINATING_NAME, discriminatingNameMapper);
408428
result.put(NameMappers.FILE_GAV_NAME, fileGavNameMapper);
429+
result.put(NameMappers.FILE_GAECV_NAME, fileGaecvNameMapper);
409430
result.put(NameMappers.FILE_HGAV_NAME, fileHashingGavNameMapper);
431+
result.put(NameMappers.FILE_HGAECV_NAME, fileHashingGaecvNameMapper);
410432
return Collections.unmodifiableMap(result);
411433
}
412434

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: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,24 @@
3030

3131
/**
3232
* Artifact GAV {@link NameMapper}, uses artifact and metadata coordinates to name their corresponding locks. Is not
33-
* considering local repository, only the artifact coordinates. May use custom prefixes and sufixes and separators,
33+
* considering local repository, only the artifact coordinates. May use custom prefixes and suffixes and separators,
3434
* hence this instance may or may not be filesystem friendly (depends on strings used).
35+
* <p>
36+
* Note: in earlier Resolver 1.9.x versions this mapper was the default, but it changed to {@link GAECVNameMapper}
37+
* in 1.9.25.
3538
*/
3639
public class GAVNameMapper implements NameMapper {
37-
private final boolean fileSystemFriendly;
40+
protected final boolean fileSystemFriendly;
3841

39-
private final String artifactPrefix;
42+
protected final String artifactPrefix;
4043

41-
private final String artifactSuffix;
44+
protected final String artifactSuffix;
4245

43-
private final String metadataPrefix;
46+
protected final String metadataPrefix;
4447

45-
private final String metadataSuffix;
48+
protected final String metadataSuffix;
4649

47-
private final String fieldSeparator;
50+
protected final String fieldSeparator;
4851

4952
public GAVNameMapper(
5053
boolean fileSystemFriendly,
@@ -88,7 +91,7 @@ public Collection<String> nameLocks(
8891
return keys;
8992
}
9093

91-
private String getArtifactName(Artifact artifact) {
94+
protected String getArtifactName(Artifact artifact) {
9295
return artifactPrefix
9396
+ artifact.getGroupId()
9497
+ fieldSeparator
@@ -98,9 +101,9 @@ private String getArtifactName(Artifact artifact) {
98101
+ artifactSuffix;
99102
}
100103

101-
private static final String MAVEN_METADATA = "maven-metadata.xml";
104+
protected static final String MAVEN_METADATA = "maven-metadata.xml";
102105

103-
private String getMetadataName(Metadata metadata) {
106+
protected String getMetadataName(Metadata metadata) {
104107
String name = metadataPrefix;
105108
if (!metadata.getGroupId().isEmpty()) {
106109
name += metadata.getGroupId();
@@ -122,10 +125,18 @@ private String getMetadataName(Metadata metadata) {
122125
return name + metadataSuffix;
123126
}
124127

128+
/**
129+
* @deprecated Use {@link NameMappers} to create name mappers instead.
130+
*/
131+
@Deprecated
125132
public static NameMapper gav() {
126133
return new GAVNameMapper(false, "artifact:", "", "metadata:", "", ":");
127134
}
128135

136+
/**
137+
* @deprecated Use {@link NameMappers} to create name mappers instead.
138+
*/
139+
@Deprecated
129140
public static NameMapper fileGav() {
130141
return new GAVNameMapper(true, "artifact~", ".lock", "metadata~", ".lock", "~");
131142
}

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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
public class NamedLockFactoryAdapterFactoryImpl implements NamedLockFactoryAdapterFactory, Service {
6161
private static final String DEFAULT_FACTORY_NAME = LocalReadWriteLockNamedLockFactory.NAME;
6262

63-
private static final String DEFAULT_NAME_MAPPER_NAME = NameMappers.GAV_NAME;
63+
private static final String DEFAULT_NAME_MAPPER_NAME = NameMappers.GAECV_NAME;
6464

6565
private static Map<String, NamedLockFactory> getManuallyCreatedFactories() {
6666
HashMap<String, NamedLockFactory> factories = new HashMap<>();
@@ -75,9 +75,12 @@ private static Map<String, NameMapper> getManuallyCreatedNameMappers() {
7575
HashMap<String, NameMapper> mappers = new HashMap<>();
7676
mappers.put(NameMappers.STATIC_NAME, NameMappers.staticNameMapper());
7777
mappers.put(NameMappers.GAV_NAME, NameMappers.gavNameMapper());
78+
mappers.put(NameMappers.GAECV_NAME, NameMappers.gaecvNameMapper());
7879
mappers.put(NameMappers.DISCRIMINATING_NAME, NameMappers.discriminatingNameMapper());
7980
mappers.put(NameMappers.FILE_GAV_NAME, NameMappers.fileGavNameMapper());
81+
mappers.put(NameMappers.FILE_GAECV_NAME, NameMappers.fileGaecvNameMapper());
8082
mappers.put(NameMappers.FILE_HGAV_NAME, NameMappers.fileHashingGavNameMapper());
83+
mappers.put(NameMappers.FILE_HGAECV_NAME, NameMappers.fileHashingGaecvNameMapper());
8184
return Collections.unmodifiableMap(mappers);
8285
}
8386

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)