From f33f6c3121fb6f0e49972e75f759fad49bd7319a Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Thu, 9 Nov 2023 15:18:24 +0100 Subject: [PATCH 01/17] [MRESOLVER-302] Addendum Changes: * rename closeable session to lessen repetition in source * make builder implement session interface but explain what is the intent here --- https://issues.apache.org/jira/browse/MRESOLVER-302 --- .../eclipse/aether/RepositorySystemSession.java | 14 ++++++++++---- .../aether/impl/RepositorySystemLifecycle.java | 12 ++++++------ .../impl/DefaultRepositorySystemLifecycle.java | 8 ++++---- ...emSession.java => DefaultCloseableSession.java} | 8 ++++---- .../impl/session/DefaultSessionBuilder.java | 13 ++++--------- 5 files changed, 28 insertions(+), 27 deletions(-) rename maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/{DefaultCloseableRepositorySystemSession.java => DefaultCloseableSession.java} (97%) diff --git a/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java b/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java index 2f1ce20c4..01354f0b5 100644 --- a/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java +++ b/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java @@ -57,7 +57,7 @@ public interface RepositorySystemSession { * * @since TBD */ - interface CloseableRepositorySystemSession extends RepositorySystemSession, Closeable { + interface CloseableSession extends RepositorySystemSession, Closeable { /** * Returns the ID of this closeable session instance. Each closeable session has different ID, unique within * repository system they were created with. @@ -88,12 +88,18 @@ interface CloseableRepositorySystemSession extends RepositorySystemSession, Clos } /** - * Builder for building {@link CloseableRepositorySystemSession} instances. Builder instances can be created with + * Builder for building {@link CloseableSession} instances. Builder instances can be created with * {@link RepositorySystem#createSessionBuilder()} method. + *

+ * Note: while this interface extend {@link RepositorySystemSession}, it should NOT be used as such, it is just + * a helper ability, to make possible uses like {@link #withLocalRepository(File)} method is, where + * "chicken or egg" situation would appear (you need session for not-yet-built session). This class is NOT + * immutable nor thread safe. It is highly recommended that upon configuring builder is done, invoke + * {@link #build()} method and use resulting immutable session throughout your code. * * @since TBD */ - interface SessionBuilder { + interface SessionBuilder extends RepositorySystemSession { /** * Controls whether the repository system operates in offline mode and avoids/refuses any access to remote * repositories. @@ -404,7 +410,7 @@ interface SessionBuilder { /** * Creates a session instance. */ - CloseableRepositorySystemSession build(); + CloseableSession build(); } /** diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/impl/RepositorySystemLifecycle.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/impl/RepositorySystemLifecycle.java index 3048ed7e2..37f849c55 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/impl/RepositorySystemLifecycle.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/impl/RepositorySystemLifecycle.java @@ -18,7 +18,7 @@ */ package org.eclipse.aether.impl; -import org.eclipse.aether.RepositorySystemSession.CloseableRepositorySystemSession; +import org.eclipse.aether.RepositorySystemSession.CloseableSession; /** * Lifecycle managing component for repository system. @@ -49,25 +49,25 @@ public interface RepositorySystemLifecycle { * * @since TBD */ - void sessionStarted(CloseableRepositorySystemSession session); + void sessionStarted(CloseableSession session); /** * Signals that passed in session was ended, it will not be used anymore. Repository system * will invoke the registered handlers for this session, if any. This method throws if the passed in session - * instance was not passed to method {@link #sessionStarted(CloseableRepositorySystemSession)} beforehand. + * instance was not passed to method {@link #sessionStarted(CloseableSession)} beforehand. *

* Same session instance can be ended only once. * * @since TBD */ - void sessionEnded(CloseableRepositorySystemSession session); + void sessionEnded(CloseableSession session); /** * Registers an "on session end" handler. *

- * Throws if session was not passed to {@link #sessionStarted(CloseableRepositorySystemSession)} beforehand. + * Throws if session was not passed to {@link #sessionStarted(CloseableSession)} beforehand. * * @since TBD */ - void addOnSessionEndedHandle(CloseableRepositorySystemSession session, Runnable handler); + void addOnSessionEndedHandle(CloseableSession session, Runnable handler); } diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRepositorySystemLifecycle.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRepositorySystemLifecycle.java index 73a25c7a6..2472bbb19 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRepositorySystemLifecycle.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRepositorySystemLifecycle.java @@ -29,7 +29,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.eclipse.aether.MultiRuntimeException; -import org.eclipse.aether.RepositorySystemSession.CloseableRepositorySystemSession; +import org.eclipse.aether.RepositorySystemSession.CloseableSession; import org.eclipse.aether.impl.RepositorySystemLifecycle; import static java.util.Objects.requireNonNull; @@ -89,7 +89,7 @@ public void addOnSystemEndedHandler(Runnable handler) { } @Override - public void sessionStarted(CloseableRepositorySystemSession session) { + public void sessionStarted(CloseableSession session) { requireNonNull(session, "session cannot be null"); requireNotShutdown(); String sessionId = session.sessionId(); @@ -102,7 +102,7 @@ public void sessionStarted(CloseableRepositorySystemSession session) { } @Override - public void sessionEnded(CloseableRepositorySystemSession session) { + public void sessionEnded(CloseableSession session) { requireNonNull(session, "session cannot be null"); requireNotShutdown(); String sessionId = session.sessionId(); @@ -127,7 +127,7 @@ public void sessionEnded(CloseableRepositorySystemSession session) { } @Override - public void addOnSessionEndedHandle(CloseableRepositorySystemSession session, Runnable handler) { + public void addOnSessionEndedHandle(CloseableSession session, Runnable handler) { requireNonNull(session, "session cannot be null"); requireNonNull(handler, "handler cannot be null"); requireNotShutdown(); diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultCloseableRepositorySystemSession.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultCloseableSession.java similarity index 97% rename from maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultCloseableRepositorySystemSession.java rename to maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultCloseableSession.java index a9bc520da..bf842a901 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultCloseableRepositorySystemSession.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultCloseableSession.java @@ -25,7 +25,7 @@ import org.eclipse.aether.RepositoryCache; import org.eclipse.aether.RepositoryListener; import org.eclipse.aether.RepositorySystem; -import org.eclipse.aether.RepositorySystemSession.CloseableRepositorySystemSession; +import org.eclipse.aether.RepositorySystemSession.CloseableSession; import org.eclipse.aether.SessionData; import org.eclipse.aether.artifact.ArtifactTypeRegistry; import org.eclipse.aether.collection.DependencyGraphTransformer; @@ -47,9 +47,9 @@ import static java.util.Objects.requireNonNull; /** - * A default implementation of repository system session that is immutable. + * A default implementation of repository system session that is immutable and thread-safe. */ -public final class DefaultCloseableRepositorySystemSession implements CloseableRepositorySystemSession { +public final class DefaultCloseableSession implements CloseableSession { private final String sessionId; private final AtomicBoolean closed; @@ -109,7 +109,7 @@ public final class DefaultCloseableRepositorySystemSession implements CloseableR private final RepositorySystemLifecycle repositorySystemLifecycle; @SuppressWarnings("checkstyle:parameternumber") - public DefaultCloseableRepositorySystemSession( + public DefaultCloseableSession( String sessionId, AtomicBoolean closed, boolean offline, diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java index 2077d87e0..a8dd65b51 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java @@ -52,14 +52,9 @@ import static java.util.Objects.requireNonNull; /** - * A default implementation of session builder. - *

- * Note: while this class implements {@link RepositorySystemSession}, it should NOT be used as such, it is just - * an internal technical detail to allow this class some more functional helper abilities, like - * {@link #withLocalRepository(File)} method is, where "chicken or egg" situation would be present. This class is - * NOT immutable nor thread safe. + * A default implementation of session builder. Is not immutable nor thread-safe. */ -public final class DefaultSessionBuilder implements SessionBuilder, RepositorySystemSession { +public final class DefaultSessionBuilder implements SessionBuilder { private static final MirrorSelector NULL_MIRROR_SELECTOR = r -> null; private static final ProxySelector NULL_PROXY_SELECTOR = RemoteRepository::getProxy; @@ -523,8 +518,8 @@ public SessionBuilder withRepositorySystemSession(RepositorySystemSession sessio } @Override - public CloseableRepositorySystemSession build() { - CloseableRepositorySystemSession result = new DefaultCloseableRepositorySystemSession( + public CloseableSession build() { + CloseableSession result = new DefaultCloseableSession( sessionId, closed, offline, From 39e8d0dced89fe6d33d567cf6ca6e9ab522bd747 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Thu, 9 Nov 2023 15:35:36 +0100 Subject: [PATCH 02/17] Validate system state --- .../eclipse/aether/internal/impl/DefaultRepositorySystem.java | 1 + 1 file changed, 1 insertion(+) diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRepositorySystem.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRepositorySystem.java index 3769bcc5f..eaba59598 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRepositorySystem.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRepositorySystem.java @@ -356,6 +356,7 @@ public LocalRepositoryManager newLocalRepositoryManager( RepositorySystemSession session, LocalRepository localRepository) { requireNonNull(session, "session cannot be null"); requireNonNull(localRepository, "localRepository cannot be null"); + validateSystem(); try { return localRepositoryProvider.newLocalRepositoryManager(session, localRepository); From 3ccb96077ea31dc1e96d0b1ed956e1d9c5db9906 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Thu, 9 Nov 2023 17:05:19 +0100 Subject: [PATCH 03/17] Builder is NOT Session. --- .../aether/RepositorySystemSession.java | 22 ++++++++++++++++++- .../impl/session/DefaultSessionBuilder.java | 7 +++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java b/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java index 01354f0b5..a519e6a0f 100644 --- a/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java +++ b/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java @@ -55,6 +55,9 @@ public interface RepositorySystemSession { * Immutable session that is closeable, should be handled as a resource. These session instances can be * created with {@link SessionBuilder}. * + * @noimplement This interface is not intended to be implemented by clients. + * @noextend This interface is not intended to be extended by clients. + * * @since TBD */ interface CloseableSession extends RepositorySystemSession, Closeable { @@ -97,9 +100,12 @@ interface CloseableSession extends RepositorySystemSession, Closeable { * immutable nor thread safe. It is highly recommended that upon configuring builder is done, invoke * {@link #build()} method and use resulting immutable session throughout your code. * + * @noimplement This interface is not intended to be implemented by clients. + * @noextend This interface is not intended to be extended by clients. + * * @since TBD */ - interface SessionBuilder extends RepositorySystemSession { + interface SessionBuilder { /** * Controls whether the repository system operates in offline mode and avoids/refuses any access to remote * repositories. @@ -399,6 +405,20 @@ interface SessionBuilder extends RepositorySystemSession { */ SessionBuilder withLocalRepository(File basedir); + /** + * Creates a new manager for the specified local repository. If the specified local repository has no type, the + * default local repository type of the system will be used. Note: It is expected that this method + * invocation is one of the last steps of setting up a new session, in particular any configuration properties + * should have been set already. + * + * @param localRepository The local repository to create a manager for, must not be {@code null}. + * @return The local repository manager, never {@code null}. + * @throws IllegalArgumentException If the specified repository type is not recognized or no base directory is + * given. + * @see RepositorySystem#newLocalRepositoryManager(RepositorySystemSession, LocalRepository) + */ + LocalRepositoryManager newLocalRepositoryManager(LocalRepository localRepository); + /** * Shortcut method to shallow-copy passed in session into current builder. * diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java index a8dd65b51..c22d514eb 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java @@ -54,7 +54,7 @@ /** * A default implementation of session builder. Is not immutable nor thread-safe. */ -public final class DefaultSessionBuilder implements SessionBuilder { +public final class DefaultSessionBuilder implements SessionBuilder, RepositorySystemSession { private static final MirrorSelector NULL_MIRROR_SELECTOR = r -> null; private static final ProxySelector NULL_PROXY_SELECTOR = RemoteRepository::getProxy; @@ -486,6 +486,11 @@ public SessionBuilder withLocalRepository(File basedir) { return this; } + @Override + public LocalRepositoryManager newLocalRepositoryManager(LocalRepository localRepository) { + return repositorySystem.newLocalRepositoryManager(this, localRepository); + } + @Override public SessionBuilder withRepositorySystemSession(RepositorySystemSession session) { requireNonNull(session, "repository system session cannot be null"); From aad6e4e45dd045f9c0cff54317f195c2514fac98 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Thu, 9 Nov 2023 18:30:44 +0100 Subject: [PATCH 04/17] Improvements Add factory method for LRM, that supports chained LRM as well, and introduce new config as well. --- .../aether/RepositorySystemSession.java | 34 ++++++++--------- .../impl/session/DefaultSessionBuilder.java | 37 +++++++++++++++---- .../ChainedLocalRepositoryManager.java | 13 +++++++ src/site/markdown/configuration.md | 3 +- 4 files changed, 61 insertions(+), 26 deletions(-) diff --git a/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java b/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java index a519e6a0f..4cefe0364 100644 --- a/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java +++ b/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java @@ -398,26 +398,15 @@ interface SessionBuilder { SessionBuilder setCache(RepositoryCache cache); /** - * Shortcut method to set up local repository manager. + * Shortcut method to set up local repository manager directly onto builder. There must be at least one non-null + * {@link File} passed in this method. In case multiple files, session builder will use chained local repository + * manager. * - * @param basedir The local repository base directory, may be {@code null} if none. + * @param basedir The local repository base directories. * @return This session for chaining, never {@code null}. + * @see #newLocalRepositoryManager(LocalRepository...) */ - SessionBuilder withLocalRepository(File basedir); - - /** - * Creates a new manager for the specified local repository. If the specified local repository has no type, the - * default local repository type of the system will be used. Note: It is expected that this method - * invocation is one of the last steps of setting up a new session, in particular any configuration properties - * should have been set already. - * - * @param localRepository The local repository to create a manager for, must not be {@code null}. - * @return The local repository manager, never {@code null}. - * @throws IllegalArgumentException If the specified repository type is not recognized or no base directory is - * given. - * @see RepositorySystem#newLocalRepositoryManager(RepositorySystemSession, LocalRepository) - */ - LocalRepositoryManager newLocalRepositoryManager(LocalRepository localRepository); + SessionBuilder withLocalRepository(File... basedir); /** * Shortcut method to shallow-copy passed in session into current builder. @@ -427,6 +416,17 @@ interface SessionBuilder { */ SessionBuilder withRepositorySystemSession(RepositorySystemSession session); + /** + * Factory method that creates local repository manager using configuration from this builder. The created + * manager may be chained, if more than one local repository is passed in. + * + * @param localRepositories The ordered local repositories to create manager for, must not be + * {@code null} nor empty, at least one member must be present. + * @return The local repository manager, never {@code null}. + * @throws IllegalArgumentException If the specified repository type is not recognized. + */ + LocalRepositoryManager newLocalRepositoryManager(LocalRepository... localRepositories); + /** * Creates a session instance. */ diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java index c22d514eb..f182e4e0c 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java @@ -20,7 +20,9 @@ import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; @@ -48,6 +50,7 @@ import org.eclipse.aether.resolution.ArtifactDescriptorPolicy; import org.eclipse.aether.resolution.ResolutionErrorPolicy; import org.eclipse.aether.transfer.TransferListener; +import org.eclipse.aether.util.repository.ChainedLocalRepositoryManager; import static java.util.Objects.requireNonNull; @@ -480,17 +483,18 @@ public DefaultSessionBuilder setCache(RepositoryCache cache) { } @Override - public SessionBuilder withLocalRepository(File basedir) { - LocalRepository localRepository = new LocalRepository(basedir, "default"); - this.localRepositoryManager = repositorySystem.newLocalRepositoryManager(this, localRepository); + public SessionBuilder withLocalRepository(File... basedir) { + if (basedir.length == 0) { + throw new IllegalArgumentException("empty basedir"); + } + ArrayList localRepositories = new ArrayList<>(basedir.length); + for (File b : basedir) { + localRepositories.add(new LocalRepository(b)); + } + this.localRepositoryManager = newLocalRepositoryManager(localRepositories.toArray(new LocalRepository[0])); return this; } - @Override - public LocalRepositoryManager newLocalRepositoryManager(LocalRepository localRepository) { - return repositorySystem.newLocalRepositoryManager(this, localRepository); - } - @Override public SessionBuilder withRepositorySystemSession(RepositorySystemSession session) { requireNonNull(session, "repository system session cannot be null"); @@ -522,6 +526,23 @@ public SessionBuilder withRepositorySystemSession(RepositorySystemSession sessio return this; } + @Override + public LocalRepositoryManager newLocalRepositoryManager(LocalRepository... localReposes) { + List localRepositories = Arrays.asList(localReposes); + if (localRepositories.isEmpty()) { + throw new IllegalArgumentException("empty local repositories"); + } else if (localRepositories.size() == 1) { + return repositorySystem.newLocalRepositoryManager(this, localRepositories.get(0)); + } else { + LocalRepositoryManager head = repositorySystem.newLocalRepositoryManager(this, localRepositories.get(0)); + ArrayList tail = new ArrayList<>(localRepositories.size() - 1); + for (LocalRepository localRepository : localRepositories.subList(1, localRepositories.size())) { + tail.add(repositorySystem.newLocalRepositoryManager(this, localRepository)); + } + return new ChainedLocalRepositoryManager(head, tail, this); + } + } + @Override public CloseableSession build() { CloseableSession result = new DefaultCloseableSession( diff --git a/maven-resolver-util/src/main/java/org/eclipse/aether/util/repository/ChainedLocalRepositoryManager.java b/maven-resolver-util/src/main/java/org/eclipse/aether/util/repository/ChainedLocalRepositoryManager.java index d53b560f0..f9a7d3baf 100644 --- a/maven-resolver-util/src/main/java/org/eclipse/aether/util/repository/ChainedLocalRepositoryManager.java +++ b/maven-resolver-util/src/main/java/org/eclipse/aether/util/repository/ChainedLocalRepositoryManager.java @@ -35,6 +35,7 @@ import org.eclipse.aether.repository.LocalRepository; import org.eclipse.aether.repository.LocalRepositoryManager; import org.eclipse.aether.repository.RemoteRepository; +import org.eclipse.aether.util.ConfigUtils; import static java.util.Objects.requireNonNull; import static java.util.stream.Collectors.toList; @@ -50,6 +51,10 @@ * @since 1.9.2 */ public final class ChainedLocalRepositoryManager implements LocalRepositoryManager { + public static final String IGNORE_TAIL_AVAILABILITY = "aether.chainedLocalRepository.ignoreTailAvailability"; + + private static final boolean DEFAULT_IGNORE_TAIL_AVAILABILITY = true; + private final LocalRepositoryManager head; private final List tail; @@ -63,6 +68,14 @@ public ChainedLocalRepositoryManager( this.ignoreTailAvailability = ignoreTailAvailability; } + public ChainedLocalRepositoryManager( + LocalRepositoryManager head, List tail, RepositorySystemSession session) { + this.head = requireNonNull(head, "head cannot be null"); + this.tail = requireNonNull(tail, "tail cannot be null"); + this.ignoreTailAvailability = + ConfigUtils.getBoolean(session, DEFAULT_IGNORE_TAIL_AVAILABILITY, IGNORE_TAIL_AVAILABILITY); + } + @Override public LocalRepository getRepository() { return head.getRepository(); diff --git a/src/site/markdown/configuration.md b/src/site/markdown/configuration.md index acd48b5f2..e34f4e343 100644 --- a/src/site/markdown/configuration.md +++ b/src/site/markdown/configuration.md @@ -26,7 +26,8 @@ Option | Type | Description | Default Value | Supports Repo ID Suffix `aether.artifactResolver.postProcessor.trustedChecksums.checksumAlgorithms` | String | Comma-separated list of checksum algorithms with which `trustedChecksums` should operate (validate or record). | `"SHA-1"` | no `aether.artifactResolver.postProcessor.trustedChecksums.failIfMissing` | boolean | Makes `trustedChecksums` fail validation if a trusted checksum for an artifact is missing. | `false` | no `aether.artifactResolver.postProcessor.trustedChecksums.record` | boolean | Makes `trustedChecksums` calculate and record checksums. | `false` | no -`aether.artifactResolver.postProcessor.trustedChecksums.snapshots` | boolean | Enables or disables snapshot processing in `trustedChecksums` post processor. | `false` | no +`aether.artifactResolver.postProcessor.trustedChecksums.snapshots` | boolean | Enables or disables snapshot processing in `trustedChecksums` post processor. | `false` | no +`aether.chainedLocalRepository.ignoreTailAvailability` | boolean | When chained local repository is used, whether the tail availability should be ignored or not. | `true` | no `aether.checksums.omitChecksumsForExtensions` | String | Comma-separated list of extensions with leading dot (example `.asc`) that should have checksums omitted. These are applied to sub-artifacts only. Note: to achieve 1.7.x `aether.checksums.forSignature=true` behaviour, pass empty string as value for this property. | `.asc,.sigstore` | no `aether.checksums.algorithms` | String | Comma-separated list of checksum algorithms with which checksums are validated (downloaded) and generated (uploaded). Resolver by default supports following algorithms: `MD5`, `SHA-1`, `SHA-256` and `SHA-512`. New algorithms can be added by implementing `ChecksumAlgorithmFactory` component. | `"SHA-1,MD5"` | yes `aether.conflictResolver.verbose` | boolean | Flag controlling the conflict resolver's verbose mode. | `false` | no From b01b50edb7e842f7de38ecc96b90d2131dd2d425 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Thu, 9 Nov 2023 18:32:15 +0100 Subject: [PATCH 05/17] Remove comment, is not true anymore --- .../java/org/eclipse/aether/RepositorySystemSession.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java b/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java index 4cefe0364..8c2316d3e 100644 --- a/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java +++ b/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java @@ -93,12 +93,6 @@ interface CloseableSession extends RepositorySystemSession, Closeable { /** * Builder for building {@link CloseableSession} instances. Builder instances can be created with * {@link RepositorySystem#createSessionBuilder()} method. - *

- * Note: while this interface extend {@link RepositorySystemSession}, it should NOT be used as such, it is just - * a helper ability, to make possible uses like {@link #withLocalRepository(File)} method is, where - * "chicken or egg" situation would appear (you need session for not-yet-built session). This class is NOT - * immutable nor thread safe. It is highly recommended that upon configuring builder is done, invoke - * {@link #build()} method and use resulting immutable session throughout your code. * * @noimplement This interface is not intended to be implemented by clients. * @noextend This interface is not intended to be extended by clients. From 40ba9d55e77c93d0534c78434e0de32aa8645ff9 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Thu, 9 Nov 2023 18:37:44 +0100 Subject: [PATCH 06/17] Fix up --- .../internal/impl/session/DefaultSessionBuilder.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java index f182e4e0c..da737194b 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java @@ -487,11 +487,11 @@ public SessionBuilder withLocalRepository(File... basedir) { if (basedir.length == 0) { throw new IllegalArgumentException("empty basedir"); } - ArrayList localRepositories = new ArrayList<>(basedir.length); - for (File b : basedir) { - localRepositories.add(new LocalRepository(b)); + LocalRepository[] localRepositories = new LocalRepository[basedir.length]; + for (int i = 0; i < basedir.length; i++) { + localRepositories[i] = new LocalRepository(basedir[i]); } - this.localRepositoryManager = newLocalRepositoryManager(localRepositories.toArray(new LocalRepository[0])); + this.localRepositoryManager = newLocalRepositoryManager(localRepositories); return this; } From 11192e5c0094a6134a8c3b1eb7cc100b4786f18e Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Thu, 9 Nov 2023 18:39:04 +0100 Subject: [PATCH 07/17] Remove double check --- .../aether/internal/impl/session/DefaultSessionBuilder.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java index da737194b..716fe3a4a 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java @@ -484,9 +484,6 @@ public DefaultSessionBuilder setCache(RepositoryCache cache) { @Override public SessionBuilder withLocalRepository(File... basedir) { - if (basedir.length == 0) { - throw new IllegalArgumentException("empty basedir"); - } LocalRepository[] localRepositories = new LocalRepository[basedir.length]; for (int i = 0; i < basedir.length; i++) { localRepositories[i] = new LocalRepository(basedir[i]); From 008763842a8afd4ffd214e1784295d0610c530d9 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Thu, 9 Nov 2023 19:01:14 +0100 Subject: [PATCH 08/17] A bit more needed --- .../aether/RepositorySystemSession.java | 23 +++++++++++++++++++ .../impl/session/DefaultSessionBuilder.java | 23 +++++++++++++------ 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java b/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java index 8c2316d3e..1a5957584 100644 --- a/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java +++ b/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java @@ -20,6 +20,7 @@ import java.io.Closeable; import java.io.File; +import java.util.List; import java.util.Map; import org.eclipse.aether.artifact.ArtifactTypeRegistry; @@ -402,6 +403,17 @@ interface SessionBuilder { */ SessionBuilder withLocalRepository(File... basedir); + /** + * Shortcut method to set up local repository manager directly onto builder. There must be at least one non-null + * {@link File} present in passed in list. In case multiple files, session builder will use chained local + * repository manager. + * + * @param basedir The local repository base directories. + * @return This session for chaining, never {@code null}. + * @see #newLocalRepositoryManager(LocalRepository...) + */ + SessionBuilder withLocalRepository(List basedir); + /** * Shortcut method to shallow-copy passed in session into current builder. * @@ -421,6 +433,17 @@ interface SessionBuilder { */ LocalRepositoryManager newLocalRepositoryManager(LocalRepository... localRepositories); + /** + * Factory method that creates local repository manager using configuration from this builder. The created + * manager may be chained, if more than one local repository is passed in. + * + * @param localRepositories The ordered local repositories to create manager for, must not be + * {@code null} nor empty, at least one member must be present. + * @return The local repository manager, never {@code null}. + * @throws IllegalArgumentException If the specified repository type is not recognized. + */ + LocalRepositoryManager newLocalRepositoryManager(List localRepositories); + /** * Creates a session instance. */ diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java index 716fe3a4a..8e3f3f004 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.stream.Collectors; import org.eclipse.aether.DefaultSessionData; import org.eclipse.aether.RepositoryCache; @@ -484,11 +485,14 @@ public DefaultSessionBuilder setCache(RepositoryCache cache) { @Override public SessionBuilder withLocalRepository(File... basedir) { - LocalRepository[] localRepositories = new LocalRepository[basedir.length]; - for (int i = 0; i < basedir.length; i++) { - localRepositories[i] = new LocalRepository(basedir[i]); - } - this.localRepositoryManager = newLocalRepositoryManager(localRepositories); + return withLocalRepository(Arrays.asList(basedir)); + } + + @Override + public SessionBuilder withLocalRepository(List basedir) { + requireNonNull(basedir, "null basedir list"); + this.localRepositoryManager = newLocalRepositoryManager( + basedir.stream().map(LocalRepository::new).collect(Collectors.toList())); return this; } @@ -524,8 +528,13 @@ public SessionBuilder withRepositorySystemSession(RepositorySystemSession sessio } @Override - public LocalRepositoryManager newLocalRepositoryManager(LocalRepository... localReposes) { - List localRepositories = Arrays.asList(localReposes); + public LocalRepositoryManager newLocalRepositoryManager(LocalRepository... localRepositories) { + return newLocalRepositoryManager(Arrays.asList(localRepositories)); + } + + @Override + public LocalRepositoryManager newLocalRepositoryManager(List localRepositories) { + requireNonNull(localRepositories, "null localRepositories"); if (localRepositories.isEmpty()) { throw new IllegalArgumentException("empty local repositories"); } else if (localRepositories.size() == 1) { From 3745d4f1e93192c4e6745d703f1c8b7d0d33507d Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Thu, 9 Nov 2023 19:12:39 +0100 Subject: [PATCH 09/17] Make it back --- .../main/java/org/eclipse/aether/RepositorySystemSession.java | 4 ++-- .../aether/internal/impl/session/DefaultSessionBuilder.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java b/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java index 1a5957584..e816a72d2 100644 --- a/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java +++ b/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java @@ -93,14 +93,14 @@ interface CloseableSession extends RepositorySystemSession, Closeable { /** * Builder for building {@link CloseableSession} instances. Builder instances can be created with - * {@link RepositorySystem#createSessionBuilder()} method. + * {@link RepositorySystem#createSessionBuilder()} method. Instances are not thread-safe nor immutable. * * @noimplement This interface is not intended to be implemented by clients. * @noextend This interface is not intended to be extended by clients. * * @since TBD */ - interface SessionBuilder { + interface SessionBuilder extends RepositorySystemSession { /** * Controls whether the repository system operates in offline mode and avoids/refuses any access to remote * repositories. diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java index 8e3f3f004..a854125a1 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java @@ -58,7 +58,7 @@ /** * A default implementation of session builder. Is not immutable nor thread-safe. */ -public final class DefaultSessionBuilder implements SessionBuilder, RepositorySystemSession { +public final class DefaultSessionBuilder implements SessionBuilder { private static final MirrorSelector NULL_MIRROR_SELECTOR = r -> null; private static final ProxySelector NULL_PROXY_SELECTOR = RemoteRepository::getProxy; From d24488871f9376257294c6119701fbe50c3d8051 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Thu, 9 Nov 2023 19:58:33 +0100 Subject: [PATCH 10/17] Simplify --- .../internal/impl/session/DefaultSessionBuilder.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java index a854125a1..f590b59f3 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java @@ -25,7 +25,6 @@ import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.stream.Collectors; import org.eclipse.aether.DefaultSessionData; import org.eclipse.aether.RepositoryCache; @@ -54,6 +53,7 @@ import org.eclipse.aether.util.repository.ChainedLocalRepositoryManager; import static java.util.Objects.requireNonNull; +import static java.util.stream.Collectors.toList; /** * A default implementation of session builder. Is not immutable nor thread-safe. @@ -492,7 +492,7 @@ public SessionBuilder withLocalRepository(File... basedir) { public SessionBuilder withLocalRepository(List basedir) { requireNonNull(basedir, "null basedir list"); this.localRepositoryManager = newLocalRepositoryManager( - basedir.stream().map(LocalRepository::new).collect(Collectors.toList())); + basedir.stream().map(LocalRepository::new).collect(toList())); return this; } @@ -541,10 +541,9 @@ public LocalRepositoryManager newLocalRepositoryManager(List lo return repositorySystem.newLocalRepositoryManager(this, localRepositories.get(0)); } else { LocalRepositoryManager head = repositorySystem.newLocalRepositoryManager(this, localRepositories.get(0)); - ArrayList tail = new ArrayList<>(localRepositories.size() - 1); - for (LocalRepository localRepository : localRepositories.subList(1, localRepositories.size())) { - tail.add(repositorySystem.newLocalRepositoryManager(this, localRepository)); - } + List tail = localRepositories.subList(1, localRepositories.size()).stream() + .map(l -> repositorySystem.newLocalRepositoryManager(this, l)) + .collect(toList()); return new ChainedLocalRepositoryManager(head, tail, this); } } From a7a9eaf3526fc0ab224089753312a88595b8f0a1 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Thu, 9 Nov 2023 21:29:23 +0100 Subject: [PATCH 11/17] Tidy up messages --- .../aether/internal/impl/session/DefaultSessionBuilder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java index f590b59f3..0e2033206 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java @@ -490,7 +490,7 @@ public SessionBuilder withLocalRepository(File... basedir) { @Override public SessionBuilder withLocalRepository(List basedir) { - requireNonNull(basedir, "null basedir list"); + requireNonNull(basedir, "null basedir"); this.localRepositoryManager = newLocalRepositoryManager( basedir.stream().map(LocalRepository::new).collect(toList())); return this; @@ -536,7 +536,7 @@ public LocalRepositoryManager newLocalRepositoryManager(LocalRepository... local public LocalRepositoryManager newLocalRepositoryManager(List localRepositories) { requireNonNull(localRepositories, "null localRepositories"); if (localRepositories.isEmpty()) { - throw new IllegalArgumentException("empty local repositories"); + throw new IllegalArgumentException("empty localRepositories"); } else if (localRepositories.size() == 1) { return repositorySystem.newLocalRepositoryManager(this, localRepositories.get(0)); } else { From 7fa0690c390e12fdcf290caee11c0f7512e9695c Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Thu, 9 Nov 2023 22:11:04 +0100 Subject: [PATCH 12/17] Add more helpers --- .../aether/RepositorySystemSession.java | 26 ++++++++++++-- .../impl/session/DefaultSessionBuilder.java | 34 +++++++++++++++---- 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java b/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java index e816a72d2..c45427253 100644 --- a/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java +++ b/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java @@ -401,7 +401,7 @@ interface SessionBuilder extends RepositorySystemSession { * @return This session for chaining, never {@code null}. * @see #newLocalRepositoryManager(LocalRepository...) */ - SessionBuilder withLocalRepository(File... basedir); + SessionBuilder withLocalRepositoryBasedir(File... basedir); /** * Shortcut method to set up local repository manager directly onto builder. There must be at least one non-null @@ -412,7 +412,29 @@ interface SessionBuilder extends RepositorySystemSession { * @return This session for chaining, never {@code null}. * @see #newLocalRepositoryManager(LocalRepository...) */ - SessionBuilder withLocalRepository(List basedir); + SessionBuilder withLocalRepositoryBasedir(List basedir); + + /** + * Shortcut method to set up local repository manager directly onto builder. There must be at least one non-null + * {@link LocalRepository} passed in this method. In case multiple local repositories, session builder will + * use chained local repository manager. + * + * @param localRepository The local repositories. + * @return This session for chaining, never {@code null}. + * @see #newLocalRepositoryManager(LocalRepository...) + */ + SessionBuilder withLocalRepository(LocalRepository... localRepository); + + /** + * Shortcut method to set up local repository manager directly onto builder. There must be at least one non-null + * {@link LocalRepository} present in passed in list. In case multiple local repositories, session builder will + * use chained local repository manager. + * + * @param basedir The local repository base directories. + * @return This session for chaining, never {@code null}. + * @see #newLocalRepositoryManager(LocalRepository...) + */ + SessionBuilder withLocalRepository(List basedir); /** * Shortcut method to shallow-copy passed in session into current builder. diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java index 0e2033206..2bf59ed5c 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java @@ -93,6 +93,8 @@ public final class DefaultSessionBuilder implements SessionBuilder { private LocalRepositoryManager localRepositoryManager; + private List localRepositories = new ArrayList<>(); + private WorkspaceReader workspaceReader; private RepositoryListener repositoryListener; @@ -484,15 +486,25 @@ public DefaultSessionBuilder setCache(RepositoryCache cache) { } @Override - public SessionBuilder withLocalRepository(File... basedir) { - return withLocalRepository(Arrays.asList(basedir)); + public SessionBuilder withLocalRepositoryBasedir(File... basedir) { + return withLocalRepositoryBasedir(Arrays.asList(basedir)); } @Override - public SessionBuilder withLocalRepository(List basedir) { + public SessionBuilder withLocalRepositoryBasedir(List basedir) { requireNonNull(basedir, "null basedir"); - this.localRepositoryManager = newLocalRepositoryManager( - basedir.stream().map(LocalRepository::new).collect(toList())); + return withLocalRepository(basedir.stream().map(LocalRepository::new).collect(toList())); + } + + @Override + public SessionBuilder withLocalRepository(LocalRepository... localRepository) { + return withLocalRepository(Arrays.asList(localRepository)); + } + + @Override + public SessionBuilder withLocalRepository(List localRepositories) { + requireNonNull(localRepositories, "null localRepositories"); + this.localRepositories = localRepositories; return this; } @@ -560,7 +572,7 @@ public CloseableSession build() { checksumPolicy, artifactUpdatePolicy, metadataUpdatePolicy, - localRepositoryManager, + getOrCreateLocalRepositoryManager(), workspaceReader, repositoryListener, transferListener, @@ -584,6 +596,16 @@ public CloseableSession build() { return result; } + private LocalRepositoryManager getOrCreateLocalRepositoryManager() { + if (localRepositoryManager != null) { + return localRepositoryManager; + } else if (localRepositories != null) { + return newLocalRepositoryManager(localRepositories); + } else { + throw new IllegalStateException("No local repository manager or local repositories set on session"); + } + } + @SuppressWarnings("checkstyle:magicnumber") private static Map copySafe(Map table, Class valueType) { Map map; From 288933316e2a75e98c0b7da074eb7b95d7c4f0f7 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Thu, 9 Nov 2023 22:14:03 +0100 Subject: [PATCH 13/17] Lower to 21 from 21.0.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c429416c2..0a0c11fc6 100644 --- a/pom.xml +++ b/pom.xml @@ -101,7 +101,7 @@ 4.0.0-alpha-8 [3.8.8,) - [21.0.1,) + [21,) 2023-11-02T11:01:10Z From 3f01183837d9df351840d6e5f0042cdb051b4fe8 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Thu, 9 Nov 2023 22:57:30 +0100 Subject: [PATCH 14/17] SessionBuilder is not session --- .../main/java/org/eclipse/aether/RepositorySystemSession.java | 2 +- .../aether/internal/impl/session/DefaultSessionBuilder.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java b/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java index c45427253..5e0d914eb 100644 --- a/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java +++ b/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java @@ -100,7 +100,7 @@ interface CloseableSession extends RepositorySystemSession, Closeable { * * @since TBD */ - interface SessionBuilder extends RepositorySystemSession { + interface SessionBuilder { /** * Controls whether the repository system operates in offline mode and avoids/refuses any access to remote * repositories. diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java index 2bf59ed5c..032bef8f5 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java @@ -58,7 +58,7 @@ /** * A default implementation of session builder. Is not immutable nor thread-safe. */ -public final class DefaultSessionBuilder implements SessionBuilder { +public final class DefaultSessionBuilder implements SessionBuilder, RepositorySystemSession { private static final MirrorSelector NULL_MIRROR_SELECTOR = r -> null; private static final ProxySelector NULL_PROXY_SELECTOR = RemoteRepository::getProxy; From e175baa5508753e57705c17074c2b41ddae606a3 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Thu, 9 Nov 2023 23:12:56 +0100 Subject: [PATCH 15/17] Session is not used, make it optional --- .../aether/repository/AuthenticationContext.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/maven-resolver-api/src/main/java/org/eclipse/aether/repository/AuthenticationContext.java b/maven-resolver-api/src/main/java/org/eclipse/aether/repository/AuthenticationContext.java index feaf052f8..28ea01879 100644 --- a/maven-resolver-api/src/main/java/org/eclipse/aether/repository/AuthenticationContext.java +++ b/maven-resolver-api/src/main/java/org/eclipse/aether/repository/AuthenticationContext.java @@ -142,7 +142,7 @@ public final class AuthenticationContext implements Closeable { /** * Gets an authentication context for the specified repository. * - * @param session The repository system session during which the repository is accessed, must not be {@code null}. + * @param session The repository system session during which the repository is accessed, may be {@code null}. * @param repository The repository for which to create an authentication context, must not be {@code null}. * @return An authentication context for the repository or {@code null} if no authentication is configured for it. */ @@ -153,7 +153,7 @@ public static AuthenticationContext forRepository(RepositorySystemSession sessio /** * Gets an authentication context for the proxy of the specified repository. * - * @param session The repository system session during which the repository is accessed, must not be {@code null}. + * @param session The repository system session during which the repository is accessed, may be {@code null}. * @param repository The repository for whose proxy to create an authentication context, must not be {@code null}. * @return An authentication context for the proxy or {@code null} if no proxy is set or no authentication is * configured for it. @@ -173,17 +173,17 @@ private static AuthenticationContext newInstance( private AuthenticationContext( RepositorySystemSession session, RemoteRepository repository, Proxy proxy, Authentication auth) { - this.session = requireNonNull(session, "repository system session cannot be null"); - this.repository = repository; + this.session = session; + this.repository = requireNonNull(repository, "null repository"); this.proxy = proxy; this.auth = auth; authData = new HashMap<>(); } /** - * Gets the repository system session during which the authentication happens. + * Gets the repository system session during which the authentication happens (if within session). * - * @return The repository system session, never {@code null}. + * @return The repository system session, may be {@code null} if context is created outside of session. */ public RepositorySystemSession getSession() { return session; From db68dd451e7f418b63c07ebe1e8376eb7943e625 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Thu, 9 Nov 2023 23:25:53 +0100 Subject: [PATCH 16/17] Apply PR comments --- .../aether/RepositorySystemSession.java | 38 +--- .../impl/session/DefaultCloseableSession.java | 29 ++- .../impl/session/DefaultSessionBuilder.java | 204 ++---------------- 3 files changed, 50 insertions(+), 221 deletions(-) diff --git a/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java b/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java index 5e0d914eb..bf7a8f52c 100644 --- a/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java +++ b/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java @@ -397,44 +397,44 @@ interface SessionBuilder { * {@link File} passed in this method. In case multiple files, session builder will use chained local repository * manager. * - * @param basedir The local repository base directories. + * @param baseDirectories The local repository base directories. * @return This session for chaining, never {@code null}. * @see #newLocalRepositoryManager(LocalRepository...) */ - SessionBuilder withLocalRepositoryBasedir(File... basedir); + SessionBuilder withLocalRepositoryBaseDirectories(File... baseDirectories); /** * Shortcut method to set up local repository manager directly onto builder. There must be at least one non-null * {@link File} present in passed in list. In case multiple files, session builder will use chained local * repository manager. * - * @param basedir The local repository base directories. + * @param baseDirectories The local repository base directories. * @return This session for chaining, never {@code null}. * @see #newLocalRepositoryManager(LocalRepository...) */ - SessionBuilder withLocalRepositoryBasedir(List basedir); + SessionBuilder withLocalRepositoryBaseDirectories(List baseDirectories); /** * Shortcut method to set up local repository manager directly onto builder. There must be at least one non-null * {@link LocalRepository} passed in this method. In case multiple local repositories, session builder will * use chained local repository manager. * - * @param localRepository The local repositories. + * @param localRepositories The local repositories. * @return This session for chaining, never {@code null}. * @see #newLocalRepositoryManager(LocalRepository...) */ - SessionBuilder withLocalRepository(LocalRepository... localRepository); + SessionBuilder withLocalRepositories(LocalRepository... localRepositories); /** * Shortcut method to set up local repository manager directly onto builder. There must be at least one non-null * {@link LocalRepository} present in passed in list. In case multiple local repositories, session builder will * use chained local repository manager. * - * @param basedir The local repository base directories. + * @param localRepositories The local repositories. * @return This session for chaining, never {@code null}. * @see #newLocalRepositoryManager(LocalRepository...) */ - SessionBuilder withLocalRepository(List basedir); + SessionBuilder withLocalRepositories(List localRepositories); /** * Shortcut method to shallow-copy passed in session into current builder. @@ -444,28 +444,6 @@ interface SessionBuilder { */ SessionBuilder withRepositorySystemSession(RepositorySystemSession session); - /** - * Factory method that creates local repository manager using configuration from this builder. The created - * manager may be chained, if more than one local repository is passed in. - * - * @param localRepositories The ordered local repositories to create manager for, must not be - * {@code null} nor empty, at least one member must be present. - * @return The local repository manager, never {@code null}. - * @throws IllegalArgumentException If the specified repository type is not recognized. - */ - LocalRepositoryManager newLocalRepositoryManager(LocalRepository... localRepositories); - - /** - * Factory method that creates local repository manager using configuration from this builder. The created - * manager may be chained, if more than one local repository is passed in. - * - * @param localRepositories The ordered local repositories to create manager for, must not be - * {@code null} nor empty, at least one member must be present. - * @return The local repository manager, never {@code null}. - * @throws IllegalArgumentException If the specified repository type is not recognized. - */ - LocalRepositoryManager newLocalRepositoryManager(List localRepositories); - /** * Creates a session instance. */ diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultCloseableSession.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultCloseableSession.java index bf842a901..da7b45e7e 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultCloseableSession.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultCloseableSession.java @@ -19,6 +19,7 @@ package org.eclipse.aether.internal.impl.session; import java.util.Collections; +import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; @@ -43,8 +44,10 @@ import org.eclipse.aether.resolution.ArtifactDescriptorPolicy; import org.eclipse.aether.resolution.ResolutionErrorPolicy; import org.eclipse.aether.transfer.TransferListener; +import org.eclipse.aether.util.repository.ChainedLocalRepositoryManager; import static java.util.Objects.requireNonNull; +import static java.util.stream.Collectors.toList; /** * A default implementation of repository system session that is immutable and thread-safe. @@ -120,6 +123,7 @@ public DefaultCloseableSession( String artifactUpdatePolicy, String metadataUpdatePolicy, LocalRepositoryManager localRepositoryManager, + List localRepositories, WorkspaceReader workspaceReader, RepositoryListener repositoryListener, TransferListener transferListener, @@ -148,7 +152,6 @@ public DefaultCloseableSession( this.checksumPolicy = checksumPolicy; this.artifactUpdatePolicy = artifactUpdatePolicy; this.metadataUpdatePolicy = metadataUpdatePolicy; - this.localRepositoryManager = requireNonNull(localRepositoryManager); this.workspaceReader = workspaceReader; this.repositoryListener = repositoryListener; this.transferListener = transferListener; @@ -170,11 +173,35 @@ public DefaultCloseableSession( this.repositorySystem = requireNonNull(repositorySystem); this.repositorySystemLifecycle = requireNonNull(repositorySystemLifecycle); + this.localRepositoryManager = getOrCreateLocalRepositoryManager(localRepositoryManager, localRepositories); + if (closed == null) { repositorySystemLifecycle.sessionStarted(this); } } + private LocalRepositoryManager getOrCreateLocalRepositoryManager( + LocalRepositoryManager localRepositoryManager, List localRepositories) { + if (localRepositoryManager != null) { + return localRepositoryManager; + } else if (localRepositories != null) { + if (localRepositories.isEmpty()) { + throw new IllegalArgumentException("empty localRepositories"); + } else if (localRepositories.size() == 1) { + return repositorySystem.newLocalRepositoryManager(this, localRepositories.get(0)); + } else { + LocalRepositoryManager head = + repositorySystem.newLocalRepositoryManager(this, localRepositories.get(0)); + List tail = localRepositories.subList(1, localRepositories.size()).stream() + .map(l -> repositorySystem.newLocalRepositoryManager(this, l)) + .collect(toList()); + return new ChainedLocalRepositoryManager(head, tail, this); + } + } else { + throw new IllegalStateException("No local repository manager or local repositories set on session"); + } + } + @Override public String sessionId() { return sessionId; diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java index 032bef8f5..4070fcff3 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java @@ -31,6 +31,7 @@ import org.eclipse.aether.RepositoryListener; import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.RepositorySystemSession.CloseableSession; import org.eclipse.aether.RepositorySystemSession.SessionBuilder; import org.eclipse.aether.SessionData; import org.eclipse.aether.artifact.ArtifactTypeRegistry; @@ -50,7 +51,6 @@ import org.eclipse.aether.resolution.ArtifactDescriptorPolicy; import org.eclipse.aether.resolution.ResolutionErrorPolicy; import org.eclipse.aether.transfer.TransferListener; -import org.eclipse.aether.util.repository.ChainedLocalRepositoryManager; import static java.util.Objects.requireNonNull; import static java.util.stream.Collectors.toList; @@ -58,7 +58,7 @@ /** * A default implementation of session builder. Is not immutable nor thread-safe. */ -public final class DefaultSessionBuilder implements SessionBuilder, RepositorySystemSession { +public final class DefaultSessionBuilder implements SessionBuilder { private static final MirrorSelector NULL_MIRROR_SELECTOR = r -> null; private static final ProxySelector NULL_PROXY_SELECTOR = RemoteRepository::getProxy; @@ -75,8 +75,6 @@ public final class DefaultSessionBuilder implements SessionBuilder, RepositorySy private final AtomicBoolean closed; - private final ArrayList onCloseHandler; - private boolean offline; private boolean ignoreArtifactDescriptorRepositories; @@ -138,149 +136,6 @@ public DefaultSessionBuilder( this.repositorySystemLifecycle = requireNonNull(repositorySystemLifecycle); this.sessionId = requireNonNull(sessionId); this.closed = closed; - this.onCloseHandler = new ArrayList<>(); - } - - @Override - public boolean isOffline() { - return offline; - } - - @Override - public boolean isIgnoreArtifactDescriptorRepositories() { - return ignoreArtifactDescriptorRepositories; - } - - @Override - public ResolutionErrorPolicy getResolutionErrorPolicy() { - return resolutionErrorPolicy; - } - - @Override - public ArtifactDescriptorPolicy getArtifactDescriptorPolicy() { - return artifactDescriptorPolicy; - } - - @Override - public String getChecksumPolicy() { - return checksumPolicy; - } - - @Override - public String getUpdatePolicy() { - return getArtifactUpdatePolicy(); - } - - @Override - public String getArtifactUpdatePolicy() { - return artifactUpdatePolicy; - } - - @Override - public String getMetadataUpdatePolicy() { - return metadataUpdatePolicy; - } - - @Override - public LocalRepository getLocalRepository() { - return localRepositoryManager.getRepository(); - } - - @Override - public LocalRepositoryManager getLocalRepositoryManager() { - return localRepositoryManager; - } - - @Override - public WorkspaceReader getWorkspaceReader() { - return workspaceReader; - } - - @Override - public RepositoryListener getRepositoryListener() { - return repositoryListener; - } - - @Override - public TransferListener getTransferListener() { - return transferListener; - } - - @Override - public Map getSystemProperties() { - return systemProperties; - } - - @Override - public Map getUserProperties() { - return userProperties; - } - - @Override - public Map getConfigProperties() { - return configProperties; - } - - @Override - public MirrorSelector getMirrorSelector() { - return mirrorSelector; - } - - @Override - public ProxySelector getProxySelector() { - return proxySelector; - } - - @Override - public AuthenticationSelector getAuthenticationSelector() { - return authenticationSelector; - } - - @Override - public ArtifactTypeRegistry getArtifactTypeRegistry() { - return artifactTypeRegistry; - } - - @Override - public DependencyTraverser getDependencyTraverser() { - return dependencyTraverser; - } - - @Override - public DependencyManager getDependencyManager() { - return dependencyManager; - } - - @Override - public DependencySelector getDependencySelector() { - return dependencySelector; - } - - @Override - public VersionFilter getVersionFilter() { - return versionFilter; - } - - @Override - public DependencyGraphTransformer getDependencyGraphTransformer() { - return dependencyGraphTransformer; - } - - @Override - public SessionData getData() { - return data; - } - - @Override - public RepositoryCache getCache() { - return cache; - } - - @Override - public boolean addOnSessionEndedHandler(Runnable handler) { - requireNonNull(handler, "null handler"); - onCloseHandler.add(handler); - return true; } @Override @@ -486,23 +341,24 @@ public DefaultSessionBuilder setCache(RepositoryCache cache) { } @Override - public SessionBuilder withLocalRepositoryBasedir(File... basedir) { - return withLocalRepositoryBasedir(Arrays.asList(basedir)); + public SessionBuilder withLocalRepositoryBaseDirectories(File... baseDirectories) { + return withLocalRepositoryBaseDirectories(Arrays.asList(baseDirectories)); } @Override - public SessionBuilder withLocalRepositoryBasedir(List basedir) { - requireNonNull(basedir, "null basedir"); - return withLocalRepository(basedir.stream().map(LocalRepository::new).collect(toList())); + public SessionBuilder withLocalRepositoryBaseDirectories(List baseDirectories) { + requireNonNull(baseDirectories, "null baseDirectories"); + return withLocalRepositories( + baseDirectories.stream().map(LocalRepository::new).collect(toList())); } @Override - public SessionBuilder withLocalRepository(LocalRepository... localRepository) { - return withLocalRepository(Arrays.asList(localRepository)); + public SessionBuilder withLocalRepositories(LocalRepository... localRepositories) { + return withLocalRepositories(Arrays.asList(localRepositories)); } @Override - public SessionBuilder withLocalRepository(List localRepositories) { + public SessionBuilder withLocalRepositories(List localRepositories) { requireNonNull(localRepositories, "null localRepositories"); this.localRepositories = localRepositories; return this; @@ -539,30 +395,9 @@ public SessionBuilder withRepositorySystemSession(RepositorySystemSession sessio return this; } - @Override - public LocalRepositoryManager newLocalRepositoryManager(LocalRepository... localRepositories) { - return newLocalRepositoryManager(Arrays.asList(localRepositories)); - } - - @Override - public LocalRepositoryManager newLocalRepositoryManager(List localRepositories) { - requireNonNull(localRepositories, "null localRepositories"); - if (localRepositories.isEmpty()) { - throw new IllegalArgumentException("empty localRepositories"); - } else if (localRepositories.size() == 1) { - return repositorySystem.newLocalRepositoryManager(this, localRepositories.get(0)); - } else { - LocalRepositoryManager head = repositorySystem.newLocalRepositoryManager(this, localRepositories.get(0)); - List tail = localRepositories.subList(1, localRepositories.size()).stream() - .map(l -> repositorySystem.newLocalRepositoryManager(this, l)) - .collect(toList()); - return new ChainedLocalRepositoryManager(head, tail, this); - } - } - @Override public CloseableSession build() { - CloseableSession result = new DefaultCloseableSession( + return new DefaultCloseableSession( sessionId, closed, offline, @@ -572,7 +407,8 @@ public CloseableSession build() { checksumPolicy, artifactUpdatePolicy, metadataUpdatePolicy, - getOrCreateLocalRepositoryManager(), + localRepositoryManager, + localRepositories, workspaceReader, repositoryListener, transferListener, @@ -592,18 +428,6 @@ public CloseableSession build() { cache, repositorySystem, repositorySystemLifecycle); - onCloseHandler.forEach(result::addOnSessionEndedHandler); - return result; - } - - private LocalRepositoryManager getOrCreateLocalRepositoryManager() { - if (localRepositoryManager != null) { - return localRepositoryManager; - } else if (localRepositories != null) { - return newLocalRepositoryManager(localRepositories); - } else { - throw new IllegalStateException("No local repository manager or local repositories set on session"); - } } @SuppressWarnings("checkstyle:magicnumber") From 51babbe14de9b1027749b775264977349dc44737 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Thu, 9 Nov 2023 23:30:44 +0100 Subject: [PATCH 17/17] Tidy up --- .../aether/internal/impl/session/DefaultSessionBuilder.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java index 4070fcff3..70911608f 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/session/DefaultSessionBuilder.java @@ -19,7 +19,6 @@ package org.eclipse.aether.internal.impl.session; import java.io.File; -import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -91,7 +90,7 @@ public final class DefaultSessionBuilder implements SessionBuilder { private LocalRepositoryManager localRepositoryManager; - private List localRepositories = new ArrayList<>(); + private List localRepositories; private WorkspaceReader workspaceReader;