Skip to content

Commit

Permalink
Use ChainedLocalRepositoryManager
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagobento committed Sep 17, 2024
1 parent 286b75d commit 86a25e0
Showing 1 changed file with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.Set;
import java.util.function.Function;
Expand Down Expand Up @@ -61,13 +62,15 @@
import org.eclipse.aether.repository.ArtifactRepository;
import org.eclipse.aether.repository.Authentication;
import org.eclipse.aether.repository.LocalRepository;
import org.eclipse.aether.repository.LocalRepositoryManager;
import org.eclipse.aether.repository.Proxy;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.repository.RepositoryPolicy;
import org.eclipse.aether.resolution.ArtifactDescriptorException;
import org.eclipse.aether.resolution.ArtifactDescriptorRequest;
import org.eclipse.aether.transfer.TransferListener;
import org.eclipse.aether.util.repository.AuthenticationBuilder;
import org.eclipse.aether.util.repository.ChainedLocalRepositoryManager;
import org.eclipse.aether.util.repository.DefaultAuthenticationSelector;
import org.eclipse.aether.util.repository.DefaultMirrorSelector;
import org.eclipse.aether.util.repository.DefaultProxySelector;
Expand Down Expand Up @@ -350,6 +353,18 @@ public String getLocalRepo() throws BootstrapMavenException {
return localRepo == null ? localRepo = resolveLocalRepo(getEffectiveSettings()) : localRepo;
}

public String[] getLocalRepoTail() {
return resolveLocalRepoTail().split(",");
}

private boolean getLocalRepoTailIgnoreAvailability() {
final String ignoreAvailability = getProperty("maven.repo.local.tail.ignoreAvailability");
if (ignoreAvailability == null) {
return true;
}
return "false".equalsIgnoreCase(ignoreAvailability); // The only "falsy" value is `false` itself. All other strings are interpreted as `true`.
}

private LocalProject resolveCurrentProject(Function<Path, Model> modelProvider) throws BootstrapMavenException {
try {
return LocalProject.loadWorkspace(this, modelProvider);
Expand All @@ -371,6 +386,10 @@ private String resolveLocalRepo(Settings settings) {
return localRepo == null ? new File(getUserMavenConfigurationHome(), "repository").getAbsolutePath() : localRepo;
}

private String resolveLocalRepoTail() {
return Optional.ofNullable(getProperty("maven.repo.local.tail")).orElse("");
}

private File resolveSettingsFile(String settingsArg, Supplier<File> supplier) {
File userSettings;
if (settingsArg != null) {
Expand Down Expand Up @@ -447,9 +466,15 @@ private DefaultRepositorySystemSession newRepositorySystemSession() throws Boots
}
session.setMirrorSelector(ms);
}
final String localRepoPath = getLocalRepo();
session.setLocalRepositoryManager(
getRepositorySystem().newLocalRepositoryManager(session, new LocalRepository(localRepoPath)));

final LocalRepositoryManager head = getRepositorySystem().newLocalRepositoryManager(session,
new LocalRepository(getLocalRepo()));
final List<LocalRepositoryManager> tail = new ArrayList<>();
for (final String tailPath : getLocalRepoTail()) {
tail.add(getRepositorySystem().newLocalRepositoryManager(session, new LocalRepository(tailPath)));
}

session.setLocalRepositoryManager(new ChainedLocalRepositoryManager(head, tail, getLocalRepoTailIgnoreAvailability()));

session.setOffline(isOffline());

Expand Down

0 comments on commit 86a25e0

Please sign in to comment.