From 6ab1ab838965c6e4a2591c20d4f6f0fa3a536e77 Mon Sep 17 00:00:00 2001 From: Oleg Gusakov Date: Wed, 1 Apr 2009 06:19:10 +0000 Subject: [PATCH] started adding tree resolution to Mercury repo system impl git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@760790 13f79535-47bb-0310-9956-ffa450edef68 --- .../repository/mercury/MercuryAdaptor.java | 49 ++++++++++++++++++ .../mercury/MercuryRepositorySystemTest.java | 50 +++++++++++++++++++ .../repository/MavenArtifactMetadata.java | 4 +- .../maven/repository/MetadataGraph.java | 12 +++++ .../maven/repository/MetadataGraphNode.java | 25 ++++++++++ .../repository/MetadataResolutionRequest.java | 16 +++--- 6 files changed, 146 insertions(+), 10 deletions(-) diff --git a/maven-repository-mercury/src/main/java/org/apache/maven/repository/mercury/MercuryAdaptor.java b/maven-repository-mercury/src/main/java/org/apache/maven/repository/mercury/MercuryAdaptor.java index 74bec5243d..a02d6bc0c6 100644 --- a/maven-repository-mercury/src/main/java/org/apache/maven/repository/mercury/MercuryAdaptor.java +++ b/maven-repository-mercury/src/main/java/org/apache/maven/repository/mercury/MercuryAdaptor.java @@ -29,12 +29,16 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.mercury.artifact.ArtifactMetadata; +import org.apache.maven.mercury.artifact.MetadataTreeNode; import org.apache.maven.mercury.builder.api.DependencyProcessor; import org.apache.maven.mercury.repository.api.Repository; import org.apache.maven.mercury.repository.local.m2.LocalRepositoryM2; import org.apache.maven.mercury.repository.remote.m2.RemoteRepositoryM2; import org.apache.maven.mercury.transport.api.Server; import org.apache.maven.mercury.util.Util; +import org.apache.maven.repository.MavenArtifactMetadata; +import org.apache.maven.repository.MetadataGraph; +import org.apache.maven.repository.MetadataGraphNode; /** * @author Oleg Gusakov @@ -136,5 +140,50 @@ public class MercuryAdaptor { return toMavenArtifact( af, new ArtifactMetadata(name) ); } + + public static MavenArtifactMetadata toMavenArtifactMetadata( ArtifactMetadata md ) + { + MavenArtifactMetadata mmd = new MavenArtifactMetadata(); + mmd.setGroupId( md.getGroupId() ); + mmd.setArtifactId( md.getArtifactId() ); + mmd.setVersion( md.getVersion() ); + mmd.setClassifier( md.getClassifier() ); + mmd.setType( md.getType() ); + + return mmd; + } + + public static MetadataGraph resolvedTreeToGraph( MetadataTreeNode root ) + { + if( root == null ) + return null; + + MetadataGraphNode entry = new MetadataGraphNode( toMavenArtifactMetadata( root.getMd() ) ); + + MetadataGraph graph = new MetadataGraph(entry); + + addKids( root, entry, graph ); + + return graph; + } + + private static final void addKids( MetadataTreeNode tParent, MetadataGraphNode gParent, MetadataGraph graph ) + { + if( !tParent.hasChildren() ) + return; + + for( MetadataTreeNode kid : tParent.getChildren() ) + { + MavenArtifactMetadata mmd = toMavenArtifactMetadata( kid.getMd() ); + + MetadataGraphNode node = graph.findNode( mmd ); + + node.addIncident( gParent ); + + gParent.addIncident( node ); + + addKids( kid, node, graph ); + } + } } diff --git a/maven-repository-mercury/src/test/java/org/apache/maven/repository/mercury/MercuryRepositorySystemTest.java b/maven-repository-mercury/src/test/java/org/apache/maven/repository/mercury/MercuryRepositorySystemTest.java index e487eb9114..8d24e8da6c 100644 --- a/maven-repository-mercury/src/test/java/org/apache/maven/repository/mercury/MercuryRepositorySystemTest.java +++ b/maven-repository-mercury/src/test/java/org/apache/maven/repository/mercury/MercuryRepositorySystemTest.java @@ -19,7 +19,17 @@ under the License. package org.apache.maven.repository.mercury; +import java.io.IOException; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; +import org.apache.maven.artifact.resolver.ArtifactResolutionResult; +import org.apache.maven.mercury.artifact.ArtifactMetadata; import org.apache.maven.repository.AbstractMavenRepositorySystemTest; +import org.apache.maven.repository.MavenArtifactMetadata; +import org.apache.maven.repository.MetadataResolutionRequest; +import org.apache.maven.repository.MetadataResolutionResult; import org.apache.maven.repository.RepositorySystem; /** @@ -39,4 +49,44 @@ public class MercuryRepositorySystemTest _mrs = getContainer().lookup( RepositorySystem.class, "mercury" ); } + + + public void testRetrieve() throws IOException + { + MavenArtifactMetadata mad = MercuryAdaptor.toMavenArtifactMetadata( new ArtifactMetadata( "asm:asm-xml:3.0" ) ); + + MetadataResolutionRequest request = new MetadataResolutionRequest(); + request.setLocalRepository( _localRepo ); + request.setRemoteRepostories( _remoteRepos ); + request.setArtifactMetadata( mad ); + request.setAsResolvedTree( true ); + + MetadataResolutionResult res = _mrs.resolveMetadata( request ); + +// assertNotNull( res ); +// +// Set as = res.getArtifacts(); +// +// assertNotNull( as ); +// +// assertEquals( 4, as.size() ); +// +// assertTrue( checkExists( as, "asm:asm-xml:3.0" ) ); +// +// assertTrue( checkExists( as, "asm:asm-util:3.0" ) ); +// +// assertTrue( checkExists( as, "asm:asm-tree:3.0" ) ); +// +// assertTrue( checkExists( as, "asm:asm:3.0" ) ); +// +// assertFalse( checkExists( as, "asm:asm-parent:3.0" ) ); +// +// for( Artifact a : as ) +// { +// assertTrue( a.getFile().exists() ); +// +// System.out.println( a.getFile().getCanonicalPath()+ " : "+ a.getFile().length()+" bytes"); +// } + + } } diff --git a/maven-repository/src/main/java/org/apache/maven/repository/MavenArtifactMetadata.java b/maven-repository/src/main/java/org/apache/maven/repository/MavenArtifactMetadata.java index df6eeb585c..44455ef58d 100644 --- a/maven-repository/src/main/java/org/apache/maven/repository/MavenArtifactMetadata.java +++ b/maven-repository/src/main/java/org/apache/maven/repository/MavenArtifactMetadata.java @@ -114,8 +114,8 @@ public class MavenArtifactMetadata public String toString() { return getGroupId()+":"+getArtifactId()+":"+getVersion() - +":" + (getClassifier() == null ? "" : getClassifier() ) - +":" + (getType() == null ? DEFAULT_TYPE : getType() ) + +":" + (getClassifier() == null ? "" : getClassifier() ) + +":" + (getType() == null ? DEFAULT_TYPE : getType() ) ; } diff --git a/maven-repository/src/main/java/org/apache/maven/repository/MetadataGraph.java b/maven-repository/src/main/java/org/apache/maven/repository/MetadataGraph.java index 7425e68da0..81c66c888f 100644 --- a/maven-repository/src/main/java/org/apache/maven/repository/MetadataGraph.java +++ b/maven-repository/src/main/java/org/apache/maven/repository/MetadataGraph.java @@ -50,4 +50,16 @@ public class MetadataGraph { nodes.add( node ); } + + public MetadataGraphNode findNode( MavenArtifactMetadata md ) + { + for( MetadataGraphNode mgn : nodes ) + if( mgn.metadata.equals( md ) ) + return mgn; + + MetadataGraphNode node = new MetadataGraphNode( md ); + addNode( node ); + + return node; + } } diff --git a/maven-repository/src/main/java/org/apache/maven/repository/MetadataGraphNode.java b/maven-repository/src/main/java/org/apache/maven/repository/MetadataGraphNode.java index a6c8625d1b..3f7bde8797 100644 --- a/maven-repository/src/main/java/org/apache/maven/repository/MetadataGraphNode.java +++ b/maven-repository/src/main/java/org/apache/maven/repository/MetadataGraphNode.java @@ -19,6 +19,7 @@ under the License. package org.apache.maven.repository; +import java.util.ArrayList; import java.util.List; /** @@ -35,6 +36,30 @@ public class MetadataGraphNode List inNodes; List exNodes; + public MetadataGraphNode() + { + inNodes = new ArrayList(4); + exNodes = new ArrayList(8); + } + + public MetadataGraphNode( MavenArtifactMetadata metadata ) + { + this(); + this.metadata = metadata; + } + + public MetadataGraphNode addIncident( MetadataGraphNode node ) + { + inNodes.add( node ); + return this; + } + + public MetadataGraphNode addExident( MetadataGraphNode node ) + { + exNodes.add( node ); + return this; + } + @Override public boolean equals( Object obj ) { diff --git a/maven-repository/src/main/java/org/apache/maven/repository/MetadataResolutionRequest.java b/maven-repository/src/main/java/org/apache/maven/repository/MetadataResolutionRequest.java index 8aa4c180dc..e3c463338a 100644 --- a/maven-repository/src/main/java/org/apache/maven/repository/MetadataResolutionRequest.java +++ b/maven-repository/src/main/java/org/apache/maven/repository/MetadataResolutionRequest.java @@ -39,7 +39,7 @@ import org.apache.maven.artifact.resolver.filter.ArtifactFilter; */ public class MetadataResolutionRequest { - private Artifact artifact; + private MavenArtifactMetadata mad; // Needs to go away private Set artifactDependencies; @@ -80,21 +80,21 @@ public class MetadataResolutionRequest { } - public MetadataResolutionRequest( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) + public MetadataResolutionRequest( MavenArtifactMetadata md, ArtifactRepository localRepository, List remoteRepositories ) { - this.artifact = artifact; + this.mad = md; this.localRepository = localRepository; this.remoteRepositories = remoteRepositories; } - public Artifact getArtifact() + public MavenArtifactMetadata getArtifact() { - return artifact; + return mad; } - public MetadataResolutionRequest setArtifact( Artifact artifact ) + public MetadataResolutionRequest setArtifactMetadata( MavenArtifactMetadata md ) { - this.artifact = artifact; + this.mad = md; return this; } @@ -210,7 +210,7 @@ public class MetadataResolutionRequest { StringBuffer sb = new StringBuffer() .append( "REQUEST: " ).append( "\n" ) - .append( "artifact: " ).append( artifact ).append( "\n" ) + .append( "artifact: " ).append( mad ).append( "\n" ) .append( artifactDependencies ).append( "\n" ) .append( "localRepository: " ).append( localRepository ).append( "\n" ) .append( "remoteRepositories: " ).append( remoteRepositories ).append( "\n" )