mirror of https://github.com/apache/maven.git
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
This commit is contained in:
parent
860c7e04c0
commit
6ab1ab8389
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<Artifact> 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");
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() )
|
||||
;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<MetadataGraphNode> inNodes;
|
||||
List<MetadataGraphNode> exNodes;
|
||||
|
||||
public MetadataGraphNode()
|
||||
{
|
||||
inNodes = new ArrayList<MetadataGraphNode>(4);
|
||||
exNodes = new ArrayList<MetadataGraphNode>(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 )
|
||||
{
|
||||
|
|
|
@ -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<Artifact> artifactDependencies;
|
||||
|
@ -80,21 +80,21 @@ public class MetadataResolutionRequest
|
|||
{
|
||||
}
|
||||
|
||||
public MetadataResolutionRequest( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
|
||||
public MetadataResolutionRequest( MavenArtifactMetadata md, ArtifactRepository localRepository, List<ArtifactRepository> 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" )
|
||||
|
|
Loading…
Reference in New Issue