archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1369471 - in /archiva/trunk/archiva-modules: archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/tags/ archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/tags/ plugins/maven2-repository/src/main/java/org/apache/arc...
Date Sat, 04 Aug 2012 21:27:44 GMT
Author: olamy
Date: Sat Aug  4 21:27:44 2012
New Revision: 1369471

URL: http://svn.apache.org/viewvc?rev=1369471&view=rev
Log:
use dependency tree with aether for old webapp too

Modified:
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/tags/DependencyTree.java
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/tags/DependencyTreeTest.java
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/Maven3DependencyTreeBuilder.java

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/tags/DependencyTree.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/tags/DependencyTree.java?rev=1369471&r1=1369470&r2=1369471&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/tags/DependencyTree.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/tags/DependencyTree.java
Sat Aug  4 21:27:44 2012
@@ -20,18 +20,18 @@ package org.apache.archiva.web.tags;
  */
 
 import com.opensymphony.xwork2.ActionContext;
-import org.apache.archiva.dependency.tree.maven2.DependencyTreeBuilder;
-import org.apache.commons.lang.StringUtils;
 import org.apache.archiva.common.ArchivaException;
+import org.apache.archiva.dependency.tree.maven2.Maven3DependencyTreeBuilder;
 import org.apache.archiva.model.Keys;
 import org.apache.archiva.security.ArchivaXworkUser;
 import org.apache.archiva.security.UserRepositories;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.shared.dependency.tree.DependencyNode;
+import org.apache.commons.lang.StringUtils;
 import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException;
-import org.apache.maven.shared.dependency.tree.traversal.DependencyNodeVisitor;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.sonatype.aether.artifact.Artifact;
+import org.sonatype.aether.graph.DependencyNode;
+import org.sonatype.aether.graph.DependencyVisitor;
 import org.springframework.stereotype.Service;
 
 import javax.inject.Inject;
@@ -40,8 +40,6 @@ import java.util.List;
 
 /**
  * DependencyTree
- *
- *
  */
 @Service( "dependencyTree" )
 public class DependencyTree
@@ -50,7 +48,7 @@ public class DependencyTree
 
 
     @Inject
-    private DependencyTreeBuilder dependencyTreeBuilder;
+    private Maven3DependencyTreeBuilder dependencyTreeBuilder;
 
     @Inject
     private UserRepositories userRepositories;
@@ -129,7 +127,7 @@ public class DependencyTree
             dependencyTreeBuilder.buildDependencyTree( userRepositories.getObservableRepositoryIds(
getPrincipal() ),
                                                        groupId, artifactId, modelVersion,
visitor );
         }
-        catch ( DependencyTreeBuilderException e )
+        catch ( Exception e )
         {
             throw new ArchivaException( "Unable to build dependency tree: " + e.getMessage(),
e );
         }
@@ -143,7 +141,7 @@ public class DependencyTree
     }
 
     private static class TreeListVisitor
-        implements DependencyNodeVisitor
+        implements DependencyVisitor
     {
         private List<TreeEntry> list;
 
@@ -163,7 +161,7 @@ public class DependencyTree
             return this.list;
         }
 
-        public boolean visit( DependencyNode node )
+        public boolean visitEnter( DependencyNode node )
         {
             if ( firstNode == null )
             {
@@ -178,7 +176,7 @@ public class DependencyTree
             }
 
             currentEntry.appendPre( "<li>" );
-            currentEntry.setArtifact( node.getArtifact() );
+            currentEntry.setArtifact( node.getDependency().getArtifact() );
             currentEntry.appendPost( "</li>" );
             this.list.add( currentEntry );
 
@@ -190,7 +188,7 @@ public class DependencyTree
             return true;
         }
 
-        public boolean endVisit( DependencyNode node )
+        public boolean visitLeave( org.sonatype.aether.graph.DependencyNode node )
         {
             firstChild = false;
 
@@ -206,5 +204,7 @@ public class DependencyTree
 
             return true;
         }
+
+
     }
 }

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/tags/DependencyTreeTest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/tags/DependencyTreeTest.java?rev=1369471&r1=1369470&r2=1369471&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/tags/DependencyTreeTest.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/tags/DependencyTreeTest.java
Sat Aug  4 21:27:44 2012
@@ -26,33 +26,33 @@ import com.opensymphony.xwork2.inject.Co
 import com.opensymphony.xwork2.util.ValueStack;
 import com.opensymphony.xwork2.util.ValueStackFactory;
 import junit.framework.TestCase;
+import org.apache.archiva.common.ArchivaException;
 import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
+import org.apache.archiva.configuration.ArchivaConfiguration;
+import org.apache.archiva.configuration.Configuration;
+import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
 import org.apache.archiva.metadata.repository.RepositorySession;
+import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
 import org.apache.archiva.webtest.memory.TestMetadataResolver;
 import org.apache.archiva.webtest.memory.TestRepositorySessionFactory;
-import org.apache.archiva.common.ArchivaException;
-import org.apache.archiva.configuration.ArchivaConfiguration;
-import org.apache.archiva.configuration.Configuration;
-import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.sonatype.aether.artifact.Artifact;
+import org.sonatype.aether.util.artifact.DefaultArtifact;
 import org.springframework.context.ApplicationContext;
 import org.springframework.test.context.ContextConfiguration;
 
-import java.util.List;
 import javax.inject.Inject;
-import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
+import java.util.List;
 
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
-@ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml",
-    "classpath:/spring-context-DependencyTreeTest.xml"} )
+@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml",
+    "classpath:/spring-context-DependencyTreeTest.xml" } )
 public class DependencyTreeTest
     extends TestCase
 {
@@ -65,7 +65,6 @@ public class DependencyTreeTest
     @Inject
     private ApplicationContext applicationContext;
 
-    private ArtifactFactory artifactFactory;
 
     private static final String TEST_VERSION = "version";
 
@@ -103,8 +102,6 @@ public class DependencyTreeTest
         ArchivaConfiguration archivaConfiguration = applicationContext.getBean( ArchivaConfiguration.class
);
         archivaConfiguration.save( configuration );
 
-        artifactFactory = plexusSisuBridge.lookup( ArtifactFactory.class );
-
         TestMetadataResolver metadataResolver = applicationContext.getBean( TestMetadataResolver.class
);
         ProjectVersionMetadata metadata = new ProjectVersionMetadata();
         metadata.setId( TEST_VERSION );
@@ -126,52 +123,67 @@ public class DependencyTreeTest
 
         DependencyTree.TreeEntry artifactId = entries.get( 0 );
         assertEquals( "<ul><li>", artifactId.getPre() );
-        assertEquals( createPomArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ),
artifactId.getArtifact() );
+        // olamy tree with aether always create jar so createPomArtifact failed but it's
not used
+        assertTrue( assertArtifactsEquals( createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID,
TEST_VERSION ),
+                                           artifactId.getArtifact() ) );
         assertEquals( "</li>", artifactId.getPost() );
 
         DependencyTree.TreeEntry child1 = entries.get( 1 );
         assertEquals( "<ul><li>", child1.getPre() );
-        assertEquals( createArtifact( TEST_GROUP_ID, "child1", "1.0" ), child1.getArtifact()
);
+        assertTrue( assertArtifactsEquals( createArtifact( TEST_GROUP_ID, "child1", "1.0"
), child1.getArtifact() ) );
         assertEquals( "</li>", child1.getPost() );
 
         DependencyTree.TreeEntry grandchild = entries.get( 2 );
         assertEquals( "<ul><li>", grandchild.getPre() );
-        assertEquals( createArtifact( TEST_GROUP_ID, "grandchild1", "2.0" ), grandchild.getArtifact()
);
+        assertTrue(
+            assertArtifactsEquals( createArtifact( TEST_GROUP_ID, "grandchild1", "2.0" ),
grandchild.getArtifact() ) );
         assertEquals( "</li>", grandchild.getPost() );
 
         DependencyTree.TreeEntry greatGrandchild = entries.get( 3 );
         assertEquals( "<ul><li>", greatGrandchild.getPre() );
-        assertEquals( createArtifact( TEST_GROUP_ID, "great-grandchild", "3.0" ), greatGrandchild.getArtifact()
);
+        assertTrue( assertArtifactsEquals( createArtifact( TEST_GROUP_ID, "great-grandchild",
"3.0" ),
+                                           greatGrandchild.getArtifact() ) );
         assertEquals( "</li></ul></ul>", greatGrandchild.getPost() );
 
         DependencyTree.TreeEntry child2 = entries.get( 4 );
         assertEquals( "<li>", child2.getPre() );
-        assertEquals( createArtifact( TEST_GROUP_ID, "child2", "1.0" ), child2.getArtifact()
);
+        assertTrue( assertArtifactsEquals( createArtifact( TEST_GROUP_ID, "child2", "1.0"
), child2.getArtifact() ) );
         assertEquals( "</li>", child2.getPost() );
 
         DependencyTree.TreeEntry grandchild2 = entries.get( 5 );
         assertEquals( "<ul><li>", grandchild2.getPre() );
-        assertEquals( createArtifact( TEST_GROUP_ID, "grandchild2", "2.0" ), grandchild2.getArtifact()
);
+        assertTrue(
+            assertArtifactsEquals( createArtifact( TEST_GROUP_ID, "grandchild2", "2.0" ),
grandchild2.getArtifact() ) );
         assertEquals( "</li>", grandchild2.getPost() );
 
         DependencyTree.TreeEntry grandchild3 = entries.get( 6 );
         assertEquals( "<li>", grandchild3.getPre() );
-        assertEquals( createArtifact( TEST_GROUP_ID, "grandchild3", "2.0" ), grandchild3.getArtifact()
);
+        assertTrue(
+            assertArtifactsEquals( createArtifact( TEST_GROUP_ID, "grandchild3", "2.0" ),
grandchild3.getArtifact() ) );
         assertEquals( "</li></ul>", grandchild3.getPost() );
 
         DependencyTree.TreeEntry child3 = entries.get( 7 );
         assertEquals( "<li>", child3.getPre() );
-        assertEquals( createArtifact( TEST_GROUP_ID, "child3", "1.0" ), child3.getArtifact()
);
+        assertTrue( assertArtifactsEquals( createArtifact( TEST_GROUP_ID, "child3", "1.0"
), child3.getArtifact() ) );
         assertEquals( "</li></ul></ul>", child3.getPost() );
     }
 
     private Artifact createPomArtifact( String groupId, String artifactId, String version
)
     {
-        return artifactFactory.createProjectArtifact( groupId, artifactId, version );
+        return new DefaultArtifact( groupId + ":" + artifactId + ":" + version );
     }
 
     private Artifact createArtifact( String groupId, String artifactId, String version )
     {
-        return artifactFactory.createBuildArtifact( groupId, artifactId, version, "jar" );
+        return new DefaultArtifact( groupId, artifactId, "jar", version );
     }
+
+
+    public boolean assertArtifactsEquals( Artifact a, Artifact b )
+    {
+        return a.getArtifactId().equals( b.getArtifactId() ) && a.getGroupId().equals(
b.getGroupId() )
+            && a.getVersion().equals( b.getVersion() ) && a.getExtension().equals(
b.getExtension() )
+            && a.getClassifier().equals( b.getClassifier() );
+    }
+
 }

Modified: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/Maven3DependencyTreeBuilder.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/Maven3DependencyTreeBuilder.java?rev=1369471&r1=1369470&r2=1369471&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/Maven3DependencyTreeBuilder.java
(original)
+++ archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/Maven3DependencyTreeBuilder.java
Sat Aug  4 21:27:44 2012
@@ -68,7 +68,6 @@ import javax.inject.Inject;
 import javax.inject.Named;
 import java.io.File;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -122,8 +121,8 @@ public class Maven3DependencyTreeBuilder
         builder = defaultModelBuilderFactory.newInstance();
     }
 
-    public List<TreeEntry> buildDependencyTree( List<String> repositoryIds, String
groupId, String artifactId,
-                                                String version )
+    public void buildDependencyTree( List<String> repositoryIds, String groupId, String
artifactId, String version,
+                                     DependencyVisitor dependencyVisitor )
         throws Exception
     {
         Artifact projectArtifact = factory.createProjectArtifact( groupId, artifactId, version
);
@@ -141,7 +140,7 @@ public class Maven3DependencyTreeBuilder
         if ( repository == null )
         {
             // metadata could not be resolved
-            return Collections.emptyList();
+            return;
         }
 
         // MRM-1411
@@ -168,11 +167,20 @@ public class Maven3DependencyTreeBuilder
             }
         }
 
+        // FIXME take care of relative path
+        resolve( repository.getLocation(), groupId, artifactId, version, dependencyVisitor
);
+    }
+
+
+    public List<TreeEntry> buildDependencyTree( List<String> repositoryIds, String
groupId, String artifactId,
+                                                String version )
+        throws Exception
+    {
+
         List<TreeEntry> treeEntries = new ArrayList<TreeEntry>();
         TreeDependencyNodeVisitor treeDependencyNodeVisitor = new TreeDependencyNodeVisitor(
treeEntries );
 
-        // FIXME take care of relative path
-        resolve( repository.getLocation(), groupId, artifactId, version, treeDependencyNodeVisitor
);
+        buildDependencyTree( repositoryIds, groupId, artifactId, version, treeDependencyNodeVisitor
);
 
         log.debug( "treeEntrie: {}", treeEntries );
         return treeEntries;



Mime
View raw message