aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/plugins
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2012-08-02 16:22:37 +0000
committerOlivier Lamy <olamy@apache.org>2012-08-02 16:22:37 +0000
commit4c24639c91c228a9068791a6b4de4feb681c22e2 (patch)
tree5aba64747d67548190465b70288703959118a548 /archiva-modules/plugins
parent9f3790a8221f611779bc79145ce547e69514048f (diff)
downloadarchiva-4c24639c91c228a9068791a6b4de4feb681c22e2.tar.gz
archiva-4c24639c91c228a9068791a6b4de4feb681c22e2.zip
use directly aether api to get dependency tree rather than passing tru maven resolution mechanism
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1368579 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/plugins')
-rw-r--r--archiva-modules/plugins/maven2-repository/pom.xml26
-rw-r--r--archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/Maven3DependencyTreeBuilder.java136
-rw-r--r--archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/dependency/tree/maven2/DependencyTreeBuilderTestMaven3.java14
3 files changed, 174 insertions, 2 deletions
diff --git a/archiva-modules/plugins/maven2-repository/pom.xml b/archiva-modules/plugins/maven2-repository/pom.xml
index d22ad884d..49fb07e4b 100644
--- a/archiva-modules/plugins/maven2-repository/pom.xml
+++ b/archiva-modules/plugins/maven2-repository/pom.xml
@@ -89,6 +89,32 @@
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-aether-provider</artifactId>
+ <version>${maven3x.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.sonatype.aether</groupId>
+ <artifactId>aether-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.sonatype.aether</groupId>
+ <artifactId>aether-impl</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.sonatype.aether</groupId>
+ <artifactId>aether-util</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.sonatype.aether</groupId>
+ <artifactId>aether-connector-file</artifactId>
+ <version>${aether.version}</version>
+ </dependency>
+
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-dependency-tree</artifactId>
diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/Maven3DependencyTreeBuilder.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/Maven3DependencyTreeBuilder.java
index 30822d244..0b99194d2 100644
--- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/Maven3DependencyTreeBuilder.java
+++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/Maven3DependencyTreeBuilder.java
@@ -51,6 +51,10 @@ import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.DependencyResolutionException;
import org.apache.maven.project.DependencyResolutionResult;
import org.apache.maven.project.MavenProject;
+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.MavenRepositorySystemSession;
import org.codehaus.plexus.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -60,14 +64,30 @@ import org.sonatype.aether.RequestTrace;
import org.sonatype.aether.artifact.ArtifactType;
import org.sonatype.aether.artifact.ArtifactTypeRegistry;
import org.sonatype.aether.collection.CollectRequest;
+import org.sonatype.aether.collection.CollectResult;
import org.sonatype.aether.collection.DependencyCollectionException;
+import org.sonatype.aether.connector.file.FileRepositoryConnectorFactory;
import org.sonatype.aether.graph.Dependency;
import org.sonatype.aether.graph.DependencyFilter;
+import org.sonatype.aether.graph.DependencyVisitor;
+import org.sonatype.aether.impl.ArtifactDescriptorReader;
+import org.sonatype.aether.impl.VersionRangeResolver;
+import org.sonatype.aether.impl.VersionResolver;
+import org.sonatype.aether.impl.internal.DefaultServiceLocator;
import org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager;
+import org.sonatype.aether.repository.LocalRepository;
import org.sonatype.aether.resolution.DependencyRequest;
+import org.sonatype.aether.spi.connector.ArtifactDownload;
+import org.sonatype.aether.spi.connector.ArtifactUpload;
+import org.sonatype.aether.spi.connector.MetadataDownload;
+import org.sonatype.aether.spi.connector.MetadataUpload;
+import org.sonatype.aether.spi.connector.RepositoryConnector;
+import org.sonatype.aether.spi.connector.RepositoryConnectorFactory;
+import org.sonatype.aether.transfer.NoRepositoryConnectorException;
import org.sonatype.aether.util.DefaultRepositorySystemSession;
import org.sonatype.aether.util.DefaultRequestTrace;
import org.sonatype.aether.util.artifact.ArtifacIdUtils;
+import org.sonatype.aether.util.artifact.DefaultArtifact;
import org.sonatype.aether.util.artifact.JavaScopes;
import org.sonatype.aether.version.VersionConstraint;
import org.springframework.stereotype.Service;
@@ -133,7 +153,8 @@ public class Maven3DependencyTreeBuilder
}
public DependencyResolutionResult buildDependencyTree( List<String> repositoryIds, String groupId,
- String artifactId, String version )
+ String artifactId, String version,
+ DependencyVisitor dependencyVisitor )
throws Exception
{
Artifact projectArtifact = factory.createProjectArtifact( groupId, artifactId, version );
@@ -217,6 +238,9 @@ public class Maven3DependencyTreeBuilder
log.debug( "dependency graph build" );
+ // FIXME take care of relative path
+ test( repository.getLocation(), groupId, artifactId, version, dependencyVisitor );
+
return resolutionResult;
}
@@ -296,6 +320,10 @@ public class Maven3DependencyTreeBuilder
}
}
+ collect.setRoot( new org.sonatype.aether.graph.Dependency(
+ new org.sonatype.aether.util.artifact.DefaultArtifact( project.getGroupId(), project.getArtifactId(), null,
+ project.getVersion() ), "compile" ) );
+
DependencyRequest depRequest = new DependencyRequest( collect, filter );
depRequest.setTrace( trace );
@@ -321,6 +349,112 @@ public class Maven3DependencyTreeBuilder
return result;
}
+ private void test( String localRepoDir, String groupId, String artifactId, String version,
+ DependencyVisitor dependencyVisitor )
+ {
+
+ RepositorySystem system = newRepositorySystem();
+
+ RepositorySystemSession session = newRepositorySystemSession( system, localRepoDir );
+
+ org.sonatype.aether.artifact.Artifact artifact =
+ new DefaultArtifact( groupId + ":" + artifactId + ":" + version );
+
+ //RemoteRepository repo = Booter.newCentralRepository();
+
+ CollectRequest collectRequest = new CollectRequest();
+ collectRequest.setRoot( new Dependency( artifact, "" ) );
+ //collectRequest.addRepository( repo );
+
+ try
+ {
+ CollectResult collectResult = system.collectDependencies( session, collectRequest );
+ collectResult.getRoot().accept( dependencyVisitor );
+ log.debug( "test" );
+ }
+ catch ( DependencyCollectionException e )
+ {
+ log.error( e.getMessage(), e );
+ }
+
+
+ }
+
+ public static class MyFileRepositoryConnectorFactory
+ extends FileRepositoryConnectorFactory
+ {
+
+ public MyFileRepositoryConnectorFactory()
+ {
+
+ }
+
+ public RepositoryConnector newInstance( RepositorySystemSession session,
+ org.sonatype.aether.repository.RemoteRepository repository )
+ throws NoRepositoryConnectorException
+ {
+
+ try
+ {
+ return super.newInstance( session, repository );
+ }
+ catch ( NoRepositoryConnectorException e )
+ {
+
+ }
+
+ return new RepositoryConnector()
+ {
+
+ private Logger log = LoggerFactory.getLogger( getClass() );
+
+ public void get( Collection<? extends ArtifactDownload> artifactDownloads,
+ Collection<? extends MetadataDownload> metadataDownloads )
+ {
+ log.debug( "get" );
+ }
+
+ public void put( Collection<? extends ArtifactUpload> artifactUploads,
+ Collection<? extends MetadataUpload> metadataUploads )
+ {
+ log.debug( "put" );
+ }
+
+ public void close()
+ {
+ log.debug( "close" );
+ }
+ };
+ }
+ }
+
+ public static RepositorySystem newRepositorySystem()
+ {
+ DefaultServiceLocator locator = new DefaultServiceLocator();
+ locator.addService( RepositoryConnectorFactory.class,
+ MyFileRepositoryConnectorFactory.class );// FileRepositoryConnectorFactory.class );
+ locator.addService( VersionResolver.class, DefaultVersionResolver.class );
+ locator.addService( VersionRangeResolver.class, DefaultVersionRangeResolver.class );
+ locator.addService( ArtifactDescriptorReader.class, DefaultArtifactDescriptorReader.class );
+ //locator.addService( RepositoryConnectorFactory.class, WagonRepositoryConnectorFactory.class );
+ //locator.setServices( WagonProvider.class, );
+
+ return locator.getService( RepositorySystem.class );
+ }
+
+ public static RepositorySystemSession newRepositorySystemSession( RepositorySystem system, String localRepoDir )
+ {
+ MavenRepositorySystemSession session = new MavenRepositorySystemSession();
+
+ LocalRepository localRepo = new LocalRepository( localRepoDir );
+ session.setLocalRepositoryManager( system.newLocalRepositoryManager( localRepo ) );
+
+ //session.setTransferListener( new ConsoleTransferListener() );
+ //session.setRepositoryListener( new ConsoleRepositoryListener() );
+
+ return session;
+ }
+
private String getVersionSelectedFromRange( VersionConstraint constraint )
{
if ( ( constraint == null ) || ( constraint.getVersion() != null ) )
diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/dependency/tree/maven2/DependencyTreeBuilderTestMaven3.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/dependency/tree/maven2/DependencyTreeBuilderTestMaven3.java
index 168854b6f..fe4089b11 100644
--- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/dependency/tree/maven2/DependencyTreeBuilderTestMaven3.java
+++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/dependency/tree/maven2/DependencyTreeBuilderTestMaven3.java
@@ -37,6 +37,7 @@ import org.sonatype.aether.collection.CollectResult;
import org.sonatype.aether.collection.DependencyCollectionException;
import org.sonatype.aether.graph.Dependency;
import org.sonatype.aether.graph.DependencyNode;
+import org.sonatype.aether.graph.DependencyVisitor;
import org.sonatype.aether.impl.DependencyCollector;
import org.sonatype.aether.impl.internal.DefaultRepositorySystem;
import org.sonatype.aether.util.artifact.DefaultArtifact;
@@ -301,7 +302,18 @@ public class DependencyTreeBuilderTestMaven3
DependencyResolutionResult resolutionResult =
builder.buildDependencyTree( Collections.singletonList( TEST_REPO_ID ), TEST_GROUP_ID, TEST_ARTIFACT_ID,
- TEST_VERSION );
+ TEST_VERSION, new DependencyVisitor()
+ {
+ public boolean visitEnter( DependencyNode dependencyNode )
+ {
+ return true;
+ }
+
+ public boolean visitLeave( DependencyNode dependencyNode )
+ {
+ return true;
+ }
+ } );
assertNotNull( resolutionResult );
assertEquals( 10, resolutionResult.getDependencies().size() );