Skip to content

Commit

Permalink
Match functionality
Browse files Browse the repository at this point in the history
If merged, this PR will match the functionality that was previously
provided by the old sonatype version.

Remove downloadable check
Move project builder instantiation to speed up resolution
  • Loading branch information
infvg committed Oct 28, 2024
1 parent 27b6996 commit 44f5481
Show file tree
Hide file tree
Showing 10 changed files with 1,116 additions and 85 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven

name: Java CI with Maven

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
show-progress: false
# needed for the git-commit-id-plugin to work
fetch-depth: 0
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
cache: maven
- name: Maven verify
run: mvn verify
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<groupId>io.airlift.resolver</groupId>
<artifactId>resolver-root</artifactId>
<version>1.7-SNAPSHOT</version>
<version>1.7</version>
<packaging>pom</packaging>

<description>Resolve the dependencies of Maven coordinates or POM file</description>
Expand Down
2 changes: 1 addition & 1 deletion resolver-integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>io.airlift.resolver</groupId>
<artifactId>resolver-root</artifactId>
<version>1.7-SNAPSHOT</version>
<version>1.7</version>
</parent>

<groupId>io.airlift.resolver</groupId>
Expand Down
7 changes: 6 additions & 1 deletion resolver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>io.airlift.resolver</groupId>
<artifactId>resolver-root</artifactId>
<version>1.7-SNAPSHOT</version>
<version>1.7</version>
</parent>

<groupId>io.airlift.resolver</groupId>
Expand All @@ -15,6 +15,11 @@
</properties>

<dependencies>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>

<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-spi</artifactId>
Expand Down
48 changes: 42 additions & 6 deletions resolver/src/main/java/io/airlift/resolver/ArtifactResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,19 @@
import com.google.common.collect.ImmutableSet;
import io.airlift.resolver.internal.ConsoleRepositoryListener;
import io.airlift.resolver.internal.ConsoleTransferListener;
import io.airlift.resolver.internal.DefaultArtifactResolver;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilder;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.project.ProjectBuildingResult;
import org.apache.maven.repository.internal.DefaultArtifactDescriptorReader;
import org.apache.maven.repository.internal.DefaultVersionRangeResolver;
import org.apache.maven.repository.internal.DefaultVersionResolver;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.apache.maven.repository.internal.SnapshotMetadataGeneratorFactory;
import org.apache.maven.repository.internal.VersionsMetadataGeneratorFactory;
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
Expand All @@ -40,7 +46,11 @@
import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory;
import org.eclipse.aether.graph.Dependency;
import org.eclipse.aether.graph.Exclusion;
import org.eclipse.aether.impl.DefaultServiceLocator;
import org.eclipse.aether.impl.ArtifactDescriptorReader;
import org.eclipse.aether.impl.MetadataGeneratorFactory;
import org.eclipse.aether.impl.ResolverArtifactResolver;
import org.eclipse.aether.impl.VersionRangeResolver;
import org.eclipse.aether.impl.VersionResolver;
import org.eclipse.aether.repository.LocalRepository;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.resolution.ArtifactResult;
Expand Down Expand Up @@ -84,6 +94,10 @@ public class ArtifactResolver
private final DefaultRepositorySystemSession repositorySystemSession;
private final List<RemoteRepository> repositories;

private ProjectBuilder projectBuilder;

private ProjectBuildingRequest builderRequest;

public ArtifactResolver(String localRepositoryDir, String... remoteRepositoryUris)
{
this(localRepositoryDir, Arrays.asList(remoteRepositoryUris));
Expand All @@ -92,9 +106,15 @@ public ArtifactResolver(String localRepositoryDir, String... remoteRepositoryUri
public ArtifactResolver(String localRepositoryDir, List<String> remoteRepositoryUris)
{
// TODO: move off deprecated ServiceLocator, use Sisu instead
DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
ResolverArtifactResolver locator = new ResolverArtifactResolver();
locator.addService(ArtifactDescriptorReader.class, DefaultArtifactDescriptorReader.class);
locator.addService(VersionResolver.class, DefaultVersionResolver.class);
locator.addService(VersionRangeResolver.class, DefaultVersionRangeResolver.class);
locator.addService(MetadataGeneratorFactory.class, SnapshotMetadataGeneratorFactory.class);
locator.addService(MetadataGeneratorFactory.class, VersionsMetadataGeneratorFactory.class);
locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
locator.addService( TransporterFactory.class, FileTransporterFactory.class);
locator.addService(org.eclipse.aether.impl.ArtifactResolver.class, DefaultArtifactResolver.class);
locator.addService(TransporterFactory.class, FileTransporterFactory.class);
locator.addService(TransporterFactory.class, HttpTransporterFactory.class);
repositorySystem = locator.getService(RepositorySystem.class);

Expand All @@ -105,6 +125,9 @@ public ArtifactResolver(String localRepositoryDir, List<String> remoteRepository
repositorySystemSession.setTransferListener(new ConsoleTransferListener());
repositorySystemSession.setRepositoryListener(new ConsoleRepositoryListener());

// Recreating ProjectBuilder & ProjectBuilderRequest caused major slowdowns
buildProjectBuilder();

List<RemoteRepository> repositories = new ArrayList<>(remoteRepositoryUris.size());
int index = 0;
for (String repositoryUri : remoteRepositoryUris) {
Expand Down Expand Up @@ -188,9 +211,8 @@ public List<Artifact> resolvePom(File pomFile)
.collect(toImmutableList());
}

private MavenProject getMavenProject(File pomFile)
private void buildProjectBuilder()
{
// TODO: move off deprecated org.apache.maven.repository.RepositorySystem (impl is in maven2 compat module)
try {
PlexusContainer container = container();
org.apache.maven.repository.RepositorySystem lrs = container.lookup(org.apache.maven.repository.RepositorySystem.class);
Expand All @@ -201,7 +223,21 @@ private MavenProject getMavenProject(File pomFile)
request.setProcessPlugins(false);
request.setLocalRepository(lrs.createDefaultLocalRepository());
request.setRemoteRepositories(Arrays.asList(new ArtifactRepository[] {lrs.createDefaultRemoteRepository()}.clone()));
ProjectBuildingResult result = projectBuilder.build(pomFile, request);
this.projectBuilder = projectBuilder;
this.builderRequest = request;
}catch (Exception e) {
throw new RuntimeException("Error initializing project builder: ", e);
}
}
private MavenProject getMavenProject(File pomFile)
{
// TODO: move off deprecated org.apache.maven.repository.RepositorySystem (impl is in maven2 compat module)
try {
if (projectBuilder == null || builderRequest == null)
{
buildProjectBuilder();
}
ProjectBuildingResult result = projectBuilder.build(pomFile, builderRequest);
return result.getProject();
}
catch (Exception e) {
Expand Down
Loading

0 comments on commit 44f5481

Please sign in to comment.