*/
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;
/**
* DependencyTree
- *
- *
*/
@Service( "dependencyTree" )
public class DependencyTree
@Inject
- private DependencyTreeBuilder dependencyTreeBuilder;
+ private Maven3DependencyTreeBuilder dependencyTreeBuilder;
@Inject
private UserRepositories userRepositories;
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 );
}
}
private static class TreeListVisitor
- implements DependencyNodeVisitor
+ implements DependencyVisitor
{
private List<TreeEntry> list;
return this.list;
}
- public boolean visit( DependencyNode node )
+ public boolean visitEnter( DependencyNode node )
{
if ( firstNode == null )
{
}
currentEntry.appendPre( "<li>" );
- currentEntry.setArtifact( node.getArtifact() );
+ currentEntry.setArtifact( node.getDependency().getArtifact() );
currentEntry.appendPost( "</li>" );
this.list.add( currentEntry );
return true;
}
- public boolean endVisit( DependencyNode node )
+ public boolean visitLeave( org.sonatype.aether.graph.DependencyNode node )
{
firstChild = false;
return true;
}
+
+
}
}
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
{
@Inject
private ApplicationContext applicationContext;
- private ArtifactFactory artifactFactory;
private static final String TEST_VERSION = "version";
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 );
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() );
+ }
+
}
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;
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 );
if ( repository == null )
{
// metadata could not be resolved
- return Collections.emptyList();
+ return;
}
// MRM-1411
}
}
+ // 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;