summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java18
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/TreeDependencyNodeVisitor.java28
-rw-r--r--archiva-modules/archiva-web/archiva-webapp-js/pom.xml14
-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
-rw-r--r--pom.xml19
7 files changed, 252 insertions, 3 deletions
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java
index 7896ec50c..67397616f 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java
@@ -21,6 +21,7 @@ package org.apache.archiva.rest.services;
import org.apache.archiva.admin.model.beans.ManagedRepository;
import org.apache.archiva.common.utils.VersionComparator;
import org.apache.archiva.dependency.tree.maven2.DependencyTreeBuilder;
+import org.apache.archiva.dependency.tree.maven2.Maven3DependencyTreeBuilder;
import org.apache.archiva.metadata.generic.GenericMetadataFacet;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.MetadataFacet;
@@ -56,6 +57,7 @@ import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
+import org.apache.maven.project.DependencyResolutionResult;
import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException;
import org.springframework.stereotype.Service;
@@ -92,6 +94,9 @@ public class DefaultBrowseService
private DependencyTreeBuilder dependencyTreeBuilder;
@Inject
+ private Maven3DependencyTreeBuilder maven3DependencyTreeBuilder;
+
+ @Inject
private RepositoryContentFactory repositoryContentFactory;
public BrowseResult getRootGroups( String repositoryId )
@@ -426,6 +431,7 @@ public class DefaultBrowseService
List<TreeEntry> treeEntries = new ArrayList<TreeEntry>();
TreeDependencyNodeVisitor treeDependencyNodeVisitor = new TreeDependencyNodeVisitor( treeEntries );
+ /*
try
{
dependencyTreeBuilder.buildDependencyTree( selectedRepos, groupId, artifactId, version,
@@ -436,6 +442,18 @@ public class DefaultBrowseService
throw new ArchivaRestServiceException( e.getMessage(),
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
}
+ */
+ try
+ {
+ DependencyResolutionResult result =
+ maven3DependencyTreeBuilder.buildDependencyTree( selectedRepos, groupId, artifactId, version, treeDependencyNodeVisitor );
+ log.debug( "result: {}", result );
+ }
+ catch ( Exception e )
+ {
+ log.error( e.getMessage(), e );
+ }
+
return treeEntries;
}
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/TreeDependencyNodeVisitor.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/TreeDependencyNodeVisitor.java
index 13cd7760b..22e4b0af2 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/TreeDependencyNodeVisitor.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/TreeDependencyNodeVisitor.java
@@ -23,6 +23,7 @@ import org.apache.archiva.rest.api.model.Artifact;
import org.apache.archiva.rest.api.model.TreeEntry;
import org.apache.maven.shared.dependency.tree.DependencyNode;
import org.apache.maven.shared.dependency.tree.traversal.DependencyNodeVisitor;
+import org.sonatype.aether.graph.DependencyVisitor;
import java.util.List;
@@ -31,7 +32,7 @@ import java.util.List;
* @since 1.4-M3
*/
public class TreeDependencyNodeVisitor
- implements DependencyNodeVisitor
+ implements DependencyNodeVisitor, DependencyVisitor
{
final List<TreeEntry> treeEntries;
@@ -40,6 +41,8 @@ public class TreeDependencyNodeVisitor
private DependencyNode firstNode;
+ private org.sonatype.aether.graph.DependencyNode firstDependencyNode;
+
public TreeDependencyNodeVisitor( List<TreeEntry> treeEntries )
{
this.treeEntries = treeEntries;
@@ -69,4 +72,27 @@ public class TreeDependencyNodeVisitor
return true;
}
+ public boolean visitEnter( org.sonatype.aether.graph.DependencyNode dependencyNode )
+ {
+ TreeEntry entry = new TreeEntry( new BeanReplicator().replicateBean( dependencyNode.getDependency().getArtifact(), Artifact.class ) );
+ entry.setParent( currentEntry );
+ currentEntry = entry;
+
+ if ( firstDependencyNode == null )
+ {
+ firstDependencyNode = dependencyNode;
+ treeEntries.add( currentEntry );
+ }
+ else
+ {
+ currentEntry.getParent().getChilds().add( currentEntry );
+ }
+ return true;
+ }
+
+ public boolean visitLeave( org.sonatype.aether.graph.DependencyNode dependencyNode )
+ {
+ currentEntry = currentEntry.getParent();
+ return true;
+ }
}
diff --git a/archiva-modules/archiva-web/archiva-webapp-js/pom.xml b/archiva-modules/archiva-web/archiva-webapp-js/pom.xml
index b8ff66907..b30f8a57c 100644
--- a/archiva-modules/archiva-web/archiva-webapp-js/pom.xml
+++ b/archiva-modules/archiva-web/archiva-webapp-js/pom.xml
@@ -258,6 +258,20 @@
<artifactId>wagon-file</artifactId>
<scope>runtime</scope>
</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.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
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() );
diff --git a/pom.xml b/pom.xml
index d2276113f..427e4bb99 100644
--- a/pom.xml
+++ b/pom.xml
@@ -62,6 +62,8 @@
<struts.version>2.2.3.1</struts.version>
<maven3x.version>3.0.4</maven3x.version>
<maven.version>2.0.8</maven.version>
+ <aether.version>1.13.1</aether.version>
+
<maven-dependency-tree.version>2.0-SNAPSHOT</maven-dependency-tree.version>
<maven-model-converter.version>2.1</maven-model-converter.version>
<maven.indexer.version>4.1.3-SNAPSHOT</maven.indexer.version>
@@ -777,6 +779,23 @@
</exclusion>
</exclusions>
</dependency>
+
+ <dependency>
+ <groupId>org.sonatype.aether</groupId>
+ <artifactId>aether-api</artifactId>
+ <version>${aether.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.sonatype.aether</groupId>
+ <artifactId>aether-impl</artifactId>
+ <version>${aether.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.sonatype.aether</groupId>
+ <artifactId>aether-util</artifactId>
+ <version>${aether.version}</version>
+ </dependency>
+
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-repository-metadata</artifactId>