Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
9785685
GURK
cstamas Nov 19, 2025
6307d54
Tidy up + javadoc
cstamas Nov 19, 2025
e516623
WIP
cstamas Nov 19, 2025
cfe231d
Remove unsed
cstamas Nov 19, 2025
ab265fa
WIP
cstamas Nov 19, 2025
f11bcf7
WIP
cstamas Nov 19, 2025
d7e0774
Merge remote-tracking branch 'upstream/master' into gurk
cstamas Nov 20, 2025
d2d4a5a
Last bits
cstamas Nov 20, 2025
a88e1fb
Merge remote-tracking branch 'upstream/master' into gurk
cstamas Nov 21, 2025
e9cf931
Fix helper methods, add TODO
cstamas Nov 21, 2025
8add1c7
Use cache for cache
cstamas Nov 21, 2025
cdb8c90
Don't make Simple unusable; cache simple repository key function as well
cstamas Nov 21, 2025
00be04a
Use enum, add more functions to play.
cstamas Nov 21, 2025
1a2a6a8
Rename config
cstamas Nov 21, 2025
1f8b460
Merge remote-tracking branch 'upstream/master' into gurk
cstamas Nov 24, 2025
467be59
Update
cstamas Nov 24, 2025
9b50daf
More key functions
cstamas Nov 24, 2025
205bf60
Merge remote-tracking branch 'upstream/master' into gurk
cstamas Nov 27, 2025
c2a6ddb
Implement missing pieces
cstamas Nov 27, 2025
8d50666
Make key function used consistently across system.
cstamas Nov 27, 2025
b665c11
Reuse better
cstamas Nov 27, 2025
0b7f135
Lessen repetition
cstamas Nov 27, 2025
e09b300
Unify where needed
cstamas Nov 27, 2025
38dd75b
Typos, tidy up
cstamas Nov 27, 2025
621b80f
More
cstamas Nov 27, 2025
867fe05
Reorder
cstamas Nov 27, 2025
95a7908
Merge remote-tracking branch 'upstream/master' into gurk
cstamas Nov 28, 2025
889486b
Pull out RepositoryKeyInterface
cstamas Nov 28, 2025
065ea1a
Remove unneeded
cstamas Nov 28, 2025
155050c
Create dedicated component to create repositoryKey instances
cstamas Nov 28, 2025
4817504
Make it SPI
cstamas Nov 28, 2025
a819319
Add UT
cstamas Nov 28, 2025
4ba9473
Reformat
cstamas Nov 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ public final class ConfigurationProperties {
*/
public static final String CACHED_PRIORITIES = PREFIX_PRIORITY + "cached";

/**
* The default caching of priority components if {@link #CACHED_PRIORITIES} isn't set. Default value is {@code true}.
*
* @since 2.0.0
*/
public static final boolean DEFAULT_CACHED_PRIORITIES = true;

/**
* The priority to use for a certain extension class. {@code <class>} can either be the fully qualified
* name or the simple name of a class. If the class name ends with Factory that suffix could optionally be left out.
Expand All @@ -171,13 +178,6 @@ public final class ConfigurationProperties {
*/
public static final String CLASS_PRIORITIES = PREFIX_PRIORITY + "<class>";

/**
* The default caching of priority components if {@link #CACHED_PRIORITIES} isn't set. Default value is {@code true}.
*
* @since 2.0.0
*/
public static final boolean DEFAULT_CACHED_PRIORITIES = true;

/**
* A flag indicating whether interaction with the user is allowed.
*
Expand Down Expand Up @@ -560,6 +560,23 @@ public final class ConfigurationProperties {
public static final String DEFAULT_REPOSITORY_SYSTEM_DEPENDENCY_VISITOR =
REPOSITORY_SYSTEM_DEPENDENCY_VISITOR_LEVELORDER;

/**
* <b>Experimental:</b> Configuration for system-wide "repository key" function.
* Accepted and recommended values: "nid" (default), "nid_hurl" and "ngurk", while "simple" is Maven 3 legacy,
* technically equivalent to "nid". For complete description see enum
* {@code org.eclipse.aether.util.repository.RepositoryIdHelper.RepositoryKeyType} in utils. <em>Warning:</em>
* repository key function affects Resolver fundamentally and may have unexpected results! Only change this
* if you know what you are doing!
*
* @since 2.0.14
* @configurationSource {@link RepositorySystemSession#getConfigProperties()}
* @configurationType {@link java.lang.String}
* @configurationDefaultValue {@link #DEFAULT_REPOSITORY_SYSTEM_REPOSITORY_KEY_FUNCTION}
*/
public static final String REPOSITORY_SYSTEM_REPOSITORY_KEY_FUNCTION = PREFIX_SYSTEM + "repositoryKeyFunction";

public static final String DEFAULT_REPOSITORY_SYSTEM_REPOSITORY_KEY_FUNCTION = "nid";

/**
* A flag indicating whether version scheme cache statistics should be printed on JVM shutdown.
* This is useful for analyzing cache performance and effectiveness in development and testing scenarios.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,25 @@
* the repository.
*/
public final class LocalRepository implements ArtifactRepository {
public static final String ID = "local";

private final Path basePath;

private final String type;

private final int hashCode;

/**
* Creates a new local repository with the specified base directory and unknown type.
*
* @param basedir The base directory of the repository, may be {@code null}.
* @deprecated Use {@link LocalRepository(Path)} instead.
*/
@Deprecated
public LocalRepository(String basedir) {
this.basePath = Paths.get(RepositoryUriUtils.toUri(basedir)).toAbsolutePath();
this.type = "";
this.hashCode = Objects.hash(this.basePath, this.type);
}

/**
Expand Down Expand Up @@ -99,6 +105,7 @@ public LocalRepository(File basedir, String type) {
public LocalRepository(Path basePath, String type) {
this.basePath = basePath;
this.type = (type != null) ? type : "";
this.hashCode = Objects.hash(this.basePath, this.type);
}

@Override
Expand All @@ -108,7 +115,7 @@ public String getContentType() {

@Override
public String getId() {
return "local";
return ID;
}

/**
Expand Down Expand Up @@ -153,13 +160,6 @@ public boolean equals(Object obj) {

@Override
public int hashCode() {
int hash = 17;
hash = hash * 31 + hash(basePath);
hash = hash * 31 + hash(type);
return hash;
}

private static int hash(Object obj) {
return obj != null ? obj.hashCode() : 0;
return hashCode;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.eclipse.aether.repository;

import java.util.function.BiFunction;

/**
* The repository key function, it produces keys (strings) for given {@link RemoteRepository} instances.
*
* @since 2.0.14
*/
@FunctionalInterface
public interface RepositoryKeyFunction extends BiFunction<RemoteRepository, String, String> {
/**
* Produces a string representing "repository key" for given {@link RemoteRepository} and
* optionally (maybe {@code null}) "context".
*
* @param repository The {@link RemoteRepository}, may not be {@code null}.
* @param context The "context" string, or {@code null}.
* @return The "repository key" string, never {@code null}.
*/
@Override
String apply(RemoteRepository repository, String context);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.eclipse.aether.repository;

import java.util.Objects;
import java.util.UUID;

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

private final String type;

private final Object key;

private final int hashCode;

/**
* Creates a new workspace repository of type {@code "workspace"} and a random key.
*/
Expand All @@ -58,14 +62,15 @@ public WorkspaceRepository(String type) {
public WorkspaceRepository(String type, Object key) {
this.type = (type != null) ? type : "";
this.key = (key != null) ? key : UUID.randomUUID().toString().replace("-", "");
this.hashCode = Objects.hash(type, key);
}

public String getContentType() {
return type;
}

public String getId() {
return "workspace";
return ID;
}

/**
Expand Down Expand Up @@ -99,9 +104,6 @@ public boolean equals(Object obj) {

@Override
public int hashCode() {
int hash = 17;
hash = hash * 31 + getKey().hashCode();
hash = hash * 31 + getContentType().hashCode();
return hash;
return hashCode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;

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

private final LocalRepository localRepository;

public Resolver(String[] args, String remoteRepository, String localRepository) {
public Resolver(String[] args, String remoteRepository, Path localRepository) {
this.args = args;
this.remoteRepository = remoteRepository;
this.repositorySystem = Booter.newRepositorySystem(Booter.selectFactory(args));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.maven.resolver.examples.resolver;

import java.io.File;
import java.nio.file.Paths;
import java.util.List;

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

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

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

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

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

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

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

Artifact artifact = new DefaultArtifact("com.mycompany.super", "super-core", "jar", "0.1-SNAPSHOT");
artifact = artifact.setFile(new File("jar-from-whatever-process.jar"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
*/
package org.eclipse.aether.internal.impl;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

import java.util.function.Function;

import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.repository.ArtifactRepository;
import org.eclipse.aether.util.repository.RepositoryIdHelper;
import org.eclipse.aether.repository.RepositoryKeyFunction;
import org.eclipse.aether.spi.remoterepo.RepositoryKeyFunctionFactory;

import static java.util.Objects.requireNonNull;

/**
* Default local path prefix composer factory: it fully reuses {@link LocalPathPrefixComposerFactorySupport} class
Expand All @@ -36,6 +37,13 @@
@Singleton
@Named
public final class DefaultLocalPathPrefixComposerFactory extends LocalPathPrefixComposerFactorySupport {
private final RepositoryKeyFunctionFactory repositoryKeyFunctionFactory;

@Inject
public DefaultLocalPathPrefixComposerFactory(RepositoryKeyFunctionFactory repositoryKeyFunctionFactory) {
this.repositoryKeyFunctionFactory = requireNonNull(repositoryKeyFunctionFactory);
}

@Override
public LocalPathPrefixComposer createComposer(RepositorySystemSession session) {
return new DefaultLocalPathPrefixComposer(
Expand All @@ -48,7 +56,7 @@ public LocalPathPrefixComposer createComposer(RepositorySystemSession session) {
isSplitRemoteRepositoryLast(session),
getReleasesPrefix(session),
getSnapshotsPrefix(session),
RepositoryIdHelper.cachedIdToPathSegment(session));
repositoryKeyFunctionFactory.systemRepositoryKeyFunction(session));
}

/**
Expand All @@ -66,7 +74,7 @@ private DefaultLocalPathPrefixComposer(
boolean splitRemoteRepositoryLast,
String releasesPrefix,
String snapshotsPrefix,
Function<ArtifactRepository, String> idToPathSegmentFunction) {
RepositoryKeyFunction repositoryKeyFunction) {
super(
split,
localPrefix,
Expand All @@ -77,7 +85,7 @@ private DefaultLocalPathPrefixComposer(
splitRemoteRepositoryLast,
releasesPrefix,
snapshotsPrefix,
idToPathSegmentFunction);
repositoryKeyFunction);
}
}
}
Loading
Loading