mirror of https://github.com/apache/maven.git
Mercury repo system impl does return a resolved tree as a graph. UT works
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@760981 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6ab1ab8389
commit
089f86d804
|
@ -141,6 +141,18 @@ public class MercuryAdaptor
|
|||
return toMavenArtifact( af, new ArtifactMetadata(name) );
|
||||
}
|
||||
|
||||
public static ArtifactMetadata toMercuryArtifactMetadata( MavenArtifactMetadata md )
|
||||
{
|
||||
ArtifactMetadata mmd = new ArtifactMetadata();
|
||||
mmd.setGroupId( md.getGroupId() );
|
||||
mmd.setArtifactId( md.getArtifactId() );
|
||||
mmd.setVersion( md.getVersion() );
|
||||
mmd.setClassifier( md.getClassifier() );
|
||||
mmd.setType( md.getType() );
|
||||
|
||||
return mmd;
|
||||
}
|
||||
|
||||
public static MavenArtifactMetadata toMavenArtifactMetadata( ArtifactMetadata md )
|
||||
{
|
||||
MavenArtifactMetadata mmd = new MavenArtifactMetadata();
|
||||
|
@ -153,6 +165,18 @@ public class MercuryAdaptor
|
|||
return mmd;
|
||||
}
|
||||
|
||||
public static MavenArtifactMetadata toMavenArtifactMetadata( Artifact 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 )
|
||||
|
@ -162,6 +186,8 @@ public class MercuryAdaptor
|
|||
|
||||
MetadataGraph graph = new MetadataGraph(entry);
|
||||
|
||||
graph.addNode( entry );
|
||||
|
||||
addKids( root, entry, graph );
|
||||
|
||||
return graph;
|
||||
|
|
|
@ -26,11 +26,15 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
|||
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.mercury.artifact.ArtifactQueryList;
|
||||
import org.apache.maven.mercury.artifact.ArtifactScopeEnum;
|
||||
import org.apache.maven.mercury.artifact.MetadataTreeNode;
|
||||
import org.apache.maven.mercury.builder.api.DependencyProcessor;
|
||||
import org.apache.maven.mercury.plexus.PlexusMercury;
|
||||
import org.apache.maven.mercury.repository.api.Repository;
|
||||
import org.apache.maven.mercury.repository.api.RepositoryException;
|
||||
import org.apache.maven.mercury.util.Util;
|
||||
import org.apache.maven.repository.MetadataGraph;
|
||||
import org.apache.maven.repository.MetadataResolutionRequest;
|
||||
import org.apache.maven.repository.MetadataResolutionResult;
|
||||
import org.apache.maven.repository.RepositorySystem;
|
||||
|
@ -39,6 +43,7 @@ import org.codehaus.plexus.component.annotations.Component;
|
|||
import org.codehaus.plexus.component.annotations.Requirement;
|
||||
import org.codehaus.plexus.lang.DefaultLanguage;
|
||||
import org.codehaus.plexus.lang.Language;
|
||||
import org.omg.CORBA._PolicyStub;
|
||||
|
||||
/**
|
||||
* @author Oleg Gusakov
|
||||
|
@ -131,7 +136,36 @@ public class MercuryRepositorySystem
|
|||
|
||||
public MetadataResolutionResult resolveMetadata( MetadataResolutionRequest request )
|
||||
{
|
||||
MetadataResolutionResult res = null;
|
||||
if ( request == null )
|
||||
throw new IllegalArgumentException( LANG.getMessage( "null.request" ) );
|
||||
|
||||
if ( request.getArtifactMetadata() == null )
|
||||
throw new IllegalArgumentException( LANG.getMessage( "null.request.artifact" ) );
|
||||
|
||||
List<Repository> repos =
|
||||
MercuryAdaptor.toMercuryRepos( request.getLocalRepository()
|
||||
, request.getRemoteRepostories()
|
||||
, _dependencyProcessor
|
||||
);
|
||||
|
||||
MetadataResolutionResult res = new MetadataResolutionResult();
|
||||
|
||||
ArtifactMetadata md = MercuryAdaptor.toMercuryArtifactMetadata( request.getArtifactMetadata() );
|
||||
|
||||
try
|
||||
{
|
||||
MetadataTreeNode root = _mercury.resolveAsTree( repos, ArtifactScopeEnum.valueOf( request.getScope() ), new ArtifactQueryList(md), null, null );
|
||||
if( root != null )
|
||||
{
|
||||
MetadataGraph resTree = MercuryAdaptor.resolvedTreeToGraph( root );
|
||||
|
||||
res.setResolvedTree( resTree );
|
||||
}
|
||||
}
|
||||
catch ( RepositoryException e )
|
||||
{
|
||||
res.addError( e );
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ 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.MetadataGraph;
|
||||
import org.apache.maven.repository.MetadataResolutionRequest;
|
||||
import org.apache.maven.repository.MetadataResolutionResult;
|
||||
import org.apache.maven.repository.RepositorySystem;
|
||||
|
@ -51,7 +52,8 @@ public class MercuryRepositorySystemTest
|
|||
}
|
||||
|
||||
|
||||
public void testRetrieve() throws IOException
|
||||
public void testResolveTree()
|
||||
throws IOException
|
||||
{
|
||||
MavenArtifactMetadata mad = MercuryAdaptor.toMavenArtifactMetadata( new ArtifactMetadata( "asm:asm-xml:3.0" ) );
|
||||
|
||||
|
@ -60,16 +62,19 @@ public class MercuryRepositorySystemTest
|
|||
request.setRemoteRepostories( _remoteRepos );
|
||||
request.setArtifactMetadata( mad );
|
||||
request.setAsResolvedTree( true );
|
||||
request.setScope( "compile" );
|
||||
|
||||
MetadataResolutionResult res = _mrs.resolveMetadata( request );
|
||||
|
||||
// assertNotNull( res );
|
||||
//
|
||||
// Set<Artifact> as = res.getArtifacts();
|
||||
//
|
||||
// assertNotNull( as );
|
||||
//
|
||||
// assertEquals( 4, as.size() );
|
||||
assertNotNull( res );
|
||||
|
||||
MetadataGraph resGraph = res.getResolvedTree();
|
||||
|
||||
assertNotNull( resGraph );
|
||||
|
||||
assertNotNull( resGraph.getNodes() );
|
||||
|
||||
assertEquals( 4, resGraph.getNodes().size() );
|
||||
//
|
||||
// assertTrue( checkExists( as, "asm:asm-xml:3.0" ) );
|
||||
//
|
||||
|
|
|
@ -62,4 +62,14 @@ public class MetadataGraph
|
|||
|
||||
return node;
|
||||
}
|
||||
|
||||
public MetadataGraphNode getEntry()
|
||||
{
|
||||
return entry;
|
||||
}
|
||||
|
||||
public Collection<MetadataGraphNode> getNodes()
|
||||
{
|
||||
return nodes;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,8 @@ public class MetadataResolutionRequest
|
|||
{
|
||||
private MavenArtifactMetadata mad;
|
||||
|
||||
private String scope;
|
||||
|
||||
// Needs to go away
|
||||
private Set<Artifact> artifactDependencies;
|
||||
|
||||
|
@ -48,22 +50,9 @@ public class MetadataResolutionRequest
|
|||
|
||||
private List<ArtifactRepository> remoteRepositories;
|
||||
|
||||
// Not sure what to do with this?
|
||||
// Scope
|
||||
// Lock down lists
|
||||
private ArtifactFilter filter;
|
||||
|
||||
// Needs to go away
|
||||
private List<ResolutionListener> listeners = new ArrayList<ResolutionListener>();
|
||||
|
||||
// This is like a filter but overrides all transitive versions
|
||||
private Map managedVersionMap;
|
||||
|
||||
// This should not be in here, it's a component
|
||||
private ArtifactMetadataSource metadataSource;
|
||||
|
||||
private boolean resolveRoot = true;
|
||||
|
||||
/** result type - flat list; the default */
|
||||
private boolean asList = true;
|
||||
|
||||
|
@ -87,7 +76,7 @@ public class MetadataResolutionRequest
|
|||
this.remoteRepositories = remoteRepositories;
|
||||
}
|
||||
|
||||
public MavenArtifactMetadata getArtifact()
|
||||
public MavenArtifactMetadata getArtifactMetadata()
|
||||
{
|
||||
return mad;
|
||||
}
|
||||
|
@ -135,53 +124,6 @@ public class MetadataResolutionRequest
|
|||
return this;
|
||||
}
|
||||
|
||||
public ArtifactFilter getFilter()
|
||||
{
|
||||
return filter;
|
||||
}
|
||||
|
||||
public MetadataResolutionRequest setFilter( ArtifactFilter filter )
|
||||
{
|
||||
this.filter = filter;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<ResolutionListener> getListeners()
|
||||
{
|
||||
return listeners;
|
||||
}
|
||||
|
||||
public MetadataResolutionRequest setListeners( List<ResolutionListener> listeners )
|
||||
{
|
||||
this.listeners = listeners;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public MetadataResolutionRequest addListener( ResolutionListener listener )
|
||||
{
|
||||
listeners.add( listener );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
//
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public ArtifactMetadataSource getMetadataSource()
|
||||
{
|
||||
return metadataSource;
|
||||
}
|
||||
|
||||
public MetadataResolutionRequest setMetadataSource( ArtifactMetadataSource metadataSource )
|
||||
{
|
||||
this.metadataSource = metadataSource;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Map getManagedVersionMap()
|
||||
{
|
||||
return managedVersionMap;
|
||||
|
@ -194,18 +136,6 @@ public class MetadataResolutionRequest
|
|||
return this;
|
||||
}
|
||||
|
||||
public MetadataResolutionRequest setResolveRoot( boolean resolveRoot )
|
||||
{
|
||||
this.resolveRoot = resolveRoot;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isResolveRoot()
|
||||
{
|
||||
return resolveRoot;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer()
|
||||
|
@ -214,7 +144,7 @@ public class MetadataResolutionRequest
|
|||
.append( artifactDependencies ).append( "\n" )
|
||||
.append( "localRepository: " ).append( localRepository ).append( "\n" )
|
||||
.append( "remoteRepositories: " ).append( remoteRepositories ).append( "\n" )
|
||||
.append( "metadataSource: " ).append( metadataSource ).append( "\n" );
|
||||
;
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
@ -262,4 +192,15 @@ public class MetadataResolutionRequest
|
|||
this.asGraph = asGraph;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MetadataResolutionRequest setScope( String scope )
|
||||
{
|
||||
this.scope = scope;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getScope()
|
||||
{
|
||||
return scope;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -233,13 +233,10 @@ public class MetadataResolutionResult
|
|||
return errorArtifactExceptions != null;
|
||||
}
|
||||
|
||||
public MetadataResolutionResult addErrorArtifactException( ArtifactResolutionException e )
|
||||
public MetadataResolutionResult addError( Exception e )
|
||||
{
|
||||
errorArtifactExceptions = initList( errorArtifactExceptions );
|
||||
|
||||
errorArtifactExceptions.add( e );
|
||||
|
||||
exceptions = initList( exceptions );
|
||||
if( exceptions == null )
|
||||
initList( exceptions );
|
||||
|
||||
exceptions.add( e );
|
||||
|
||||
|
|
Loading…
Reference in New Issue