Skip to content

Commit 37de872

Browse files
committed
Merge remote-tracking branch 'upstream/master' into locking-inhibitor-spi
2 parents 2041988 + 79b6d5f commit 37de872

File tree

39 files changed

+958
-303
lines changed

39 files changed

+958
-303
lines changed

maven-resolver-api/src/main/java/org/eclipse/aether/ConfigurationProperties.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ public final class ConfigurationProperties {
149149
*/
150150
public static final String CACHED_PRIORITIES = PREFIX_PRIORITY + "cached";
151151

152+
/**
153+
* The default caching of priority components if {@link #CACHED_PRIORITIES} isn't set. Default value is {@code true}.
154+
*
155+
* @since 2.0.0
156+
*/
157+
public static final boolean DEFAULT_CACHED_PRIORITIES = true;
158+
152159
/**
153160
* The priority to use for a certain extension class. {@code <class>} can either be the fully qualified
154161
* name or the simple name of a class. If the class name ends with Factory that suffix could optionally be left out.
@@ -171,13 +178,6 @@ public final class ConfigurationProperties {
171178
*/
172179
public static final String CLASS_PRIORITIES = PREFIX_PRIORITY + "<class>";
173180

174-
/**
175-
* The default caching of priority components if {@link #CACHED_PRIORITIES} isn't set. Default value is {@code true}.
176-
*
177-
* @since 2.0.0
178-
*/
179-
public static final boolean DEFAULT_CACHED_PRIORITIES = true;
180-
181181
/**
182182
* A flag indicating whether interaction with the user is allowed.
183183
*
@@ -560,6 +560,23 @@ public final class ConfigurationProperties {
560560
public static final String DEFAULT_REPOSITORY_SYSTEM_DEPENDENCY_VISITOR =
561561
REPOSITORY_SYSTEM_DEPENDENCY_VISITOR_LEVELORDER;
562562

563+
/**
564+
* <b>Experimental:</b> Configuration for system-wide "repository key" function.
565+
* Accepted and recommended values: "nid" (default), "nid_hurl" and "ngurk", while "simple" is Maven 3 legacy,
566+
* technically equivalent to "nid". For complete description see enum
567+
* {@code org.eclipse.aether.util.repository.RepositoryIdHelper.RepositoryKeyType} in utils. <em>Warning:</em>
568+
* repository key function affects Resolver fundamentally and may have unexpected results! Only change this
569+
* if you know what you are doing!
570+
*
571+
* @since 2.0.14
572+
* @configurationSource {@link RepositorySystemSession#getConfigProperties()}
573+
* @configurationType {@link java.lang.String}
574+
* @configurationDefaultValue {@link #DEFAULT_REPOSITORY_SYSTEM_REPOSITORY_KEY_FUNCTION}
575+
*/
576+
public static final String REPOSITORY_SYSTEM_REPOSITORY_KEY_FUNCTION = PREFIX_SYSTEM + "repositoryKeyFunction";
577+
578+
public static final String DEFAULT_REPOSITORY_SYSTEM_REPOSITORY_KEY_FUNCTION = "nid";
579+
563580
/**
564581
* A flag indicating whether version scheme cache statistics should be printed on JVM shutdown.
565582
* This is useful for analyzing cache performance and effectiveness in development and testing scenarios.

maven-resolver-api/src/main/java/org/eclipse/aether/repository/LocalRepository.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,25 @@
3131
* the repository.
3232
*/
3333
public final class LocalRepository implements ArtifactRepository {
34+
public static final String ID = "local";
3435

3536
private final Path basePath;
3637

3738
private final String type;
3839

40+
private final int hashCode;
41+
3942
/**
4043
* Creates a new local repository with the specified base directory and unknown type.
4144
*
4245
* @param basedir The base directory of the repository, may be {@code null}.
46+
* @deprecated Use {@link LocalRepository(Path)} instead.
4347
*/
48+
@Deprecated
4449
public LocalRepository(String basedir) {
4550
this.basePath = Paths.get(RepositoryUriUtils.toUri(basedir)).toAbsolutePath();
4651
this.type = "";
52+
this.hashCode = Objects.hash(this.basePath, this.type);
4753
}
4854

4955
/**
@@ -99,6 +105,7 @@ public LocalRepository(File basedir, String type) {
99105
public LocalRepository(Path basePath, String type) {
100106
this.basePath = basePath;
101107
this.type = (type != null) ? type : "";
108+
this.hashCode = Objects.hash(this.basePath, this.type);
102109
}
103110

104111
@Override
@@ -108,7 +115,7 @@ public String getContentType() {
108115

109116
@Override
110117
public String getId() {
111-
return "local";
118+
return ID;
112119
}
113120

114121
/**
@@ -153,13 +160,6 @@ public boolean equals(Object obj) {
153160

154161
@Override
155162
public int hashCode() {
156-
int hash = 17;
157-
hash = hash * 31 + hash(basePath);
158-
hash = hash * 31 + hash(type);
159-
return hash;
160-
}
161-
162-
private static int hash(Object obj) {
163-
return obj != null ? obj.hashCode() : 0;
163+
return hashCode;
164164
}
165165
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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.repository;
20+
21+
import java.util.function.BiFunction;
22+
23+
/**
24+
* The repository key function, it produces keys (strings) for given {@link RemoteRepository} instances.
25+
*
26+
* @since 2.0.14
27+
*/
28+
@FunctionalInterface
29+
public interface RepositoryKeyFunction extends BiFunction<RemoteRepository, String, String> {
30+
/**
31+
* Produces a string representing "repository key" for given {@link RemoteRepository} and
32+
* optionally (maybe {@code null}) "context".
33+
*
34+
* @param repository The {@link RemoteRepository}, may not be {@code null}.
35+
* @param context The "context" string, or {@code null}.
36+
* @return The "repository key" string, never {@code null}.
37+
*/
38+
@Override
39+
String apply(RemoteRepository repository, String context);
40+
}

maven-resolver-api/src/main/java/org/eclipse/aether/repository/WorkspaceRepository.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package org.eclipse.aether.repository;
2020

21+
import java.util.Objects;
2122
import java.util.UUID;
2223

2324
/**
@@ -27,11 +28,14 @@
2728
* the contained artifacts is handled by a {@link WorkspaceReader}.
2829
*/
2930
public final class WorkspaceRepository implements ArtifactRepository {
31+
public static final String ID = "workspace";
3032

3133
private final String type;
3234

3335
private final Object key;
3436

37+
private final int hashCode;
38+
3539
/**
3640
* Creates a new workspace repository of type {@code "workspace"} and a random key.
3741
*/
@@ -58,14 +62,15 @@ public WorkspaceRepository(String type) {
5862
public WorkspaceRepository(String type, Object key) {
5963
this.type = (type != null) ? type : "";
6064
this.key = (key != null) ? key : UUID.randomUUID().toString().replace("-", "");
65+
this.hashCode = Objects.hash(type, key);
6166
}
6267

6368
public String getContentType() {
6469
return type;
6570
}
6671

6772
public String getId() {
68-
return "workspace";
73+
return ID;
6974
}
7075

7176
/**
@@ -99,9 +104,6 @@ public boolean equals(Object obj) {
99104

100105
@Override
101106
public int hashCode() {
102-
int hash = 17;
103-
hash = hash * 31 + getKey().hashCode();
104-
hash = hash * 31 + getContentType().hashCode();
105-
return hash;
107+
return hashCode;
106108
}
107109
}

maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/resolver/Resolver.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.ByteArrayOutputStream;
2222
import java.io.PrintStream;
2323
import java.nio.charset.StandardCharsets;
24+
import java.nio.file.Path;
2425

2526
import org.apache.maven.resolver.examples.util.Booter;
2627
import org.eclipse.aether.RepositorySystem;
@@ -55,7 +56,7 @@ public class Resolver {
5556

5657
private final LocalRepository localRepository;
5758

58-
public Resolver(String[] args, String remoteRepository, String localRepository) {
59+
public Resolver(String[] args, String remoteRepository, Path localRepository) {
5960
this.args = args;
6061
this.remoteRepository = remoteRepository;
6162
this.repositorySystem = Booter.newRepositorySystem(Booter.selectFactory(args));

maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/resolver/ResolverDemo.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.apache.maven.resolver.examples.resolver;
2020

2121
import java.io.File;
22+
import java.nio.file.Paths;
2223
import java.util.List;
2324

2425
import org.eclipse.aether.artifact.Artifact;
@@ -37,7 +38,8 @@ public static void main(String[] args) throws Exception {
3738
System.out.println("------------------------------------------------------------");
3839
System.out.println(ResolverDemo.class.getSimpleName());
3940

40-
Resolver resolver = new Resolver(args, "https://repo.maven.apache.org/maven2/", "target/resolver-demo-repo");
41+
Resolver resolver =
42+
new Resolver(args, "https://repo.maven.apache.org/maven2/", Paths.get("target/resolver-demo-repo"));
4143
ResolverResult result = resolver.resolve("junit", "junit", "4.13.2");
4244

4345
System.out.println("Result:");
@@ -47,8 +49,8 @@ public static void main(String[] args) throws Exception {
4749
}
4850

4951
public void resolve(String[] args) throws DependencyResolutionException {
50-
Resolver resolver =
51-
new Resolver(args, "http://localhost:8081/nexus/content/groups/public", "target/aether-repo");
52+
Resolver resolver = new Resolver(
53+
args, "http://localhost:8081/nexus/content/groups/public", Paths.get("target/aether-repo"));
5254

5355
ResolverResult result = resolver.resolve("com.mycompany.app", "super-app", "1.0");
5456

@@ -66,8 +68,8 @@ public void resolve(String[] args) throws DependencyResolutionException {
6668
}
6769

6870
public void installAndDeploy(String[] args) throws InstallationException, DeploymentException {
69-
Resolver resolver =
70-
new Resolver(args, "http://localhost:8081/nexus/content/groups/public", "target/aether-repo");
71+
Resolver resolver = new Resolver(
72+
args, "http://localhost:8081/nexus/content/groups/public", Paths.get("target/aether-repo"));
7173

7274
Artifact artifact = new DefaultArtifact("com.mycompany.super", "super-core", "jar", "0.1-SNAPSHOT");
7375
artifact = artifact.setFile(new File("jar-from-whatever-process.jar"));

maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultLocalPathPrefixComposerFactory.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
*/
1919
package org.eclipse.aether.internal.impl;
2020

21+
import javax.inject.Inject;
2122
import javax.inject.Named;
2223
import javax.inject.Singleton;
2324

24-
import java.util.function.Function;
25-
2625
import org.eclipse.aether.RepositorySystemSession;
27-
import org.eclipse.aether.repository.ArtifactRepository;
28-
import org.eclipse.aether.util.repository.RepositoryIdHelper;
26+
import org.eclipse.aether.repository.RepositoryKeyFunction;
27+
import org.eclipse.aether.spi.remoterepo.RepositoryKeyFunctionFactory;
28+
29+
import static java.util.Objects.requireNonNull;
2930

3031
/**
3132
* Default local path prefix composer factory: it fully reuses {@link LocalPathPrefixComposerFactorySupport} class
@@ -36,6 +37,13 @@
3637
@Singleton
3738
@Named
3839
public final class DefaultLocalPathPrefixComposerFactory extends LocalPathPrefixComposerFactorySupport {
40+
private final RepositoryKeyFunctionFactory repositoryKeyFunctionFactory;
41+
42+
@Inject
43+
public DefaultLocalPathPrefixComposerFactory(RepositoryKeyFunctionFactory repositoryKeyFunctionFactory) {
44+
this.repositoryKeyFunctionFactory = requireNonNull(repositoryKeyFunctionFactory);
45+
}
46+
3947
@Override
4048
public LocalPathPrefixComposer createComposer(RepositorySystemSession session) {
4149
return new DefaultLocalPathPrefixComposer(
@@ -48,7 +56,7 @@ public LocalPathPrefixComposer createComposer(RepositorySystemSession session) {
4856
isSplitRemoteRepositoryLast(session),
4957
getReleasesPrefix(session),
5058
getSnapshotsPrefix(session),
51-
RepositoryIdHelper.cachedIdToPathSegment(session));
59+
repositoryKeyFunctionFactory.systemRepositoryKeyFunction(session));
5260
}
5361

5462
/**
@@ -66,7 +74,7 @@ private DefaultLocalPathPrefixComposer(
6674
boolean splitRemoteRepositoryLast,
6775
String releasesPrefix,
6876
String snapshotsPrefix,
69-
Function<ArtifactRepository, String> idToPathSegmentFunction) {
77+
RepositoryKeyFunction repositoryKeyFunction) {
7078
super(
7179
split,
7280
localPrefix,
@@ -77,7 +85,7 @@ private DefaultLocalPathPrefixComposer(
7785
splitRemoteRepositoryLast,
7886
releasesPrefix,
7987
snapshotsPrefix,
80-
idToPathSegmentFunction);
88+
repositoryKeyFunction);
8189
}
8290
}
8391
}

0 commit comments

Comments
 (0)