Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make user-defined repository parameter of ArtifactResolver constructor work #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
25 changes: 21 additions & 4 deletions resolver/src/main/java/io/airlift/resolver/ArtifactResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.airlift.resolver.internal.ConsoleTransferListener;
import io.airlift.resolver.internal.Slf4jLoggerManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilder;
Expand All @@ -43,6 +44,7 @@
import org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager;
import org.sonatype.aether.repository.LocalRepositoryManager;
import org.sonatype.aether.repository.RemoteRepository;
import org.sonatype.aether.repository.RepositoryPolicy;
import org.sonatype.aether.resolution.ArtifactResult;
import org.sonatype.aether.resolution.DependencyRequest;
import org.sonatype.aether.resolution.DependencyResolutionException;
Expand All @@ -60,6 +62,7 @@
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static com.google.common.collect.ImmutableList.toImmutableList;
Expand Down Expand Up @@ -151,13 +154,14 @@ public List<Artifact> resolvePom(File pomFile)
// Hack: avoid using deprecated Maven Central URLs. The Central Repository no longer supports insecure
// communication over plain HTTP.
ImmutableList.Builder<RemoteRepository> allRepositories = ImmutableList.builder();
for (RemoteRepository repository : pom.getRemoteProjectRepositories()) {
// Ensure that custom repositories are used first.
for (RemoteRepository repository : repositories) {
if (DEPRECATED_MAVEN_CENTRAL_URIS.contains(repository.getUrl())) {
repository = new RemoteRepository(repository.getId(), repository.getContentType(), MAVEN_CENTRAL_URI);
}
allRepositories.add(repository);
}
for (RemoteRepository repository : repositories) {
for (RemoteRepository repository : pom.getRemoteProjectRepositories()) {
if (DEPRECATED_MAVEN_CENTRAL_URIS.contains(repository.getUrl())) {
repository = new RemoteRepository(repository.getId(), repository.getContentType(), MAVEN_CENTRAL_URI);
}
Expand Down Expand Up @@ -195,8 +199,21 @@ private MavenProject getMavenProject(File pomFile)
request.setSystemProperties(requiredSystemProperties());
request.setRepositorySession(repositorySystemSession);
request.setProcessPlugins(false);
request.setLocalRepository(lrs.createDefaultLocalRepository());
request.setRemoteRepositories(Arrays.asList(new ArtifactRepository[] {lrs.createDefaultRemoteRepository()}.clone()));
request.setLocalRepository(lrs.createLocalRepository(repositorySystemSession.getLocalRepository().getBasedir()));
List<ArtifactRepository> remoteRepositories = repositories.stream()
.map(repo->{
RepositoryPolicy snp = repo.getPolicy(true);
RepositoryPolicy rel = repo.getPolicy(false);

return lrs.createArtifactRepository(
repo.getId(),
repo.getUrl(),
null,
new ArtifactRepositoryPolicy(snp.isEnabled(),snp.getUpdatePolicy(),snp.getChecksumPolicy()),
new ArtifactRepositoryPolicy(rel.isEnabled(),rel.getUpdatePolicy(),rel.getChecksumPolicy()));
})
.collect(Collectors.toList());
request.setRemoteRepositories(remoteRepositories);
ProjectBuildingResult result = projectBuilder.build(pomFile, request);
return result.getProject();
}
Expand Down