[MNG-3849] modifying maven repo system tests

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@751124 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Gusakov 2009-03-06 23:09:23 +00:00
parent 131c9d1cf0
commit b7d67cd7e5
8 changed files with 581 additions and 9 deletions

View File

@ -45,5 +45,6 @@ extends AbstractMavenRepositorySystemTest
public void testRetrieve()
throws IOException
{
// super.testRetrieve();
}
}

View File

@ -105,6 +105,13 @@ under the License.
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.mercury</groupId>
<artifactId>mercury-repo-virtual</artifactId>
<version>${mercury.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.mercury</groupId>
<artifactId>mercury-artifact</artifactId>
@ -133,6 +140,11 @@ under the License.
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
</dependency>
<dependency>
<groupId>org.sonatype.plexus</groupId>

View File

@ -19,24 +19,27 @@ under the License.
package org.apache.maven.repository.mercury;
import java.util.ArrayList;
import java.util.List;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ResolutionGroup;
import org.apache.maven.artifact.repository.ArtifactRepository;
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.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.mercury.artifact.ArtifactBasicMetadata;
import org.apache.maven.mercury.artifact.ArtifactMetadata;
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.MavenRepositorySystem;
import org.apache.maven.repository.LegacyMavenRepositorySystem;
import org.apache.maven.repository.MavenRepositorySystem;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.lang.DefaultLanguage;
@ -74,8 +77,10 @@ public class MercuryRepositorySystem
ArtifactResolutionResult result = new ArtifactResolutionResult();
List<Repository> repos =
MercuryAdaptor.toMercuryRepos( request.getLocalRepository(), request.getRemoteRepostories(),
_dependencyProcessor );
MercuryAdaptor.toMercuryRepos( request.getLocalRepository()
, request.getRemoteRepostories()
, _dependencyProcessor
);
try
{
@ -97,4 +102,33 @@ public class MercuryRepositorySystem
return result;
}
// public List<ArtifactVersion> retrieveAvailableVersions( Artifact artifact, ArtifactRepository localRepository,
// List<ArtifactRepository> remoteRepositories )
// throws ArtifactMetadataRetrievalException
// {
//
// List<Repository> repos =
// MercuryAdaptor.toMercuryRepos( localRepository, remoteRepositories, _dependencyProcessor );
//
// try
// {
// List<ArtifactBasicMetadata> vl = _mercury.readVersions( repos, MercuryAdaptor.toMercuryBasicMetadata( artifact ) );
//
// if( Util.isEmpty( vl ) )
// return null;
//
// List<ArtifactVersion> res = new ArrayList<ArtifactVersion>( vl.size() );
//
// for( ArtifactBasicMetadata bmd : vl )
// res.add( new DefaultArtifactVersion(bmd.getVersion()) );
//
// return res;
// }
// catch ( RepositoryException e )
// {
// throw new ArtifactMetadataRetrievalException(e);
// }
// }
}

View File

@ -19,6 +19,18 @@ under the License.
package org.apache.maven.repository;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.ResolutionListener;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
/**
*
*
@ -28,5 +40,171 @@ package org.apache.maven.repository;
*/
public class MetadataResolutionRequest
{
private Artifact artifact;
// Needs to go away
private Set<Artifact> artifactDependencies;
private ArtifactRepository localRepository;
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;
public MetadataResolutionRequest()
{
}
public MetadataResolutionRequest( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
{
this.artifact = artifact;
this.localRepository = localRepository;
this.remoteRepositories = remoteRepositories;
}
public Artifact getArtifact()
{
return artifact;
}
public MetadataResolutionRequest setArtifact( Artifact artifact )
{
this.artifact = artifact;
return this;
}
public MetadataResolutionRequest setArtifactDependencies( Set<Artifact> artifactDependencies )
{
this.artifactDependencies = artifactDependencies;
return this;
}
public Set<Artifact> getArtifactDependencies()
{
return artifactDependencies;
}
public ArtifactRepository getLocalRepository()
{
return localRepository;
}
public MetadataResolutionRequest setLocalRepository( ArtifactRepository localRepository )
{
this.localRepository = localRepository;
return this;
}
public List<ArtifactRepository> getRemoteRepostories()
{
return remoteRepositories;
}
public MetadataResolutionRequest setRemoteRepostories( List<ArtifactRepository> remoteRepostories )
{
this.remoteRepositories = remoteRepostories;
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;
}
public MetadataResolutionRequest setManagedVersionMap( Map managedVersionMap )
{
this.managedVersionMap = managedVersionMap;
return this;
}
public MetadataResolutionRequest setResolveRoot( boolean resolveRoot )
{
this.resolveRoot = resolveRoot;
return this;
}
public boolean isResolveRoot()
{
return resolveRoot;
}
public String toString()
{
StringBuffer sb = new StringBuffer()
.append( "REQUEST: " ).append( "\n" )
.append( "artifact: " ).append( artifact ).append( "\n" )
.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();
}
}

View File

@ -19,6 +19,20 @@ under the License.
package org.apache.maven.repository;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.CyclicDependencyException;
import org.apache.maven.artifact.resolver.DefaultArtifactCollector;
import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
/**
*
*
@ -28,5 +42,302 @@ package org.apache.maven.repository;
*/
public class MetadataResolutionResult
{
private Artifact originatingArtifact;
private List<Artifact> missingArtifacts;
// Exceptions
private List<Exception> exceptions;
private List<Exception> versionRangeViolations;
private List<ArtifactResolutionException> metadataResolutionExceptions;
private List<CyclicDependencyException> circularDependencyExceptions;
private List<ArtifactResolutionException> errorArtifactExceptions;
// file system errors
private List<ArtifactRepository> repositories;
private Set<Artifact> requestedArtifacts;
private Set<Artifact> artifacts;
public Artifact getOriginatingArtifact()
{
return originatingArtifact;
}
public MetadataResolutionResult ListOriginatingArtifact( final Artifact originatingArtifact )
{
this.originatingArtifact = originatingArtifact;
return this;
}
public void addArtifact( Artifact artifact )
{
if ( artifacts == null )
{
artifacts = new LinkedHashSet<Artifact>();
}
artifacts.add( artifact );
}
public Set<Artifact> getArtifacts()
{
return artifacts;
}
public void addRequestedArtifact( Artifact artifact )
{
if ( requestedArtifacts == null )
{
requestedArtifacts = new LinkedHashSet<Artifact>();
}
requestedArtifacts.add( artifact );
}
public Set<Artifact> getRequestedArtifacts()
{
return requestedArtifacts;
}
public boolean hasMissingArtifacts()
{
return missingArtifacts != null && !missingArtifacts.isEmpty();
}
public List<Artifact> getMissingArtifacts()
{
return missingArtifacts == null ? Collections.<Artifact> emptyList() : missingArtifacts;
}
public MetadataResolutionResult addMissingArtifact( Artifact artifact )
{
missingArtifacts = initList( missingArtifacts );
missingArtifacts.add( artifact );
return this;
}
public MetadataResolutionResult setUnresolvedArtifacts( final List<Artifact> unresolvedArtifacts )
{
this.missingArtifacts = unresolvedArtifacts;
return this;
}
// ------------------------------------------------------------------------
// Exceptions
// ------------------------------------------------------------------------
public boolean hasExceptions()
{
return exceptions != null && !exceptions.isEmpty();
}
public List<Exception> getExceptions()
{
return exceptions == null ? Collections.<Exception> emptyList() : exceptions;
}
// ------------------------------------------------------------------------
// Version Range Violations
// ------------------------------------------------------------------------
public boolean hasVersionRangeViolations()
{
return versionRangeViolations != null;
}
/**
* @TODO this needs to accept a {@link OverConstrainedVersionException} as returned by
* {@link #getVersionRangeViolation(int)} but it's not used like that in
* {@link DefaultArtifactCollector}
*/
public MetadataResolutionResult addVersionRangeViolation( Exception e )
{
versionRangeViolations = initList( versionRangeViolations );
versionRangeViolations.add( e );
exceptions = initList( exceptions );
exceptions.add( e );
return this;
}
public OverConstrainedVersionException getVersionRangeViolation( int i )
{
return (OverConstrainedVersionException) versionRangeViolations.get( i );
}
public List<Exception> getVersionRangeViolations()
{
return versionRangeViolations == null ? Collections.<Exception> emptyList() : versionRangeViolations;
}
// ------------------------------------------------------------------------
// Metadata Resolution Exceptions: ArtifactResolutionExceptions
// ------------------------------------------------------------------------
public boolean hasMetadataResolutionExceptions()
{
return metadataResolutionExceptions != null;
}
public MetadataResolutionResult addMetadataResolutionException( ArtifactResolutionException e )
{
metadataResolutionExceptions = initList( metadataResolutionExceptions );
metadataResolutionExceptions.add( e );
exceptions = initList( exceptions );
exceptions.add( e );
return this;
}
public ArtifactResolutionException getMetadataResolutionException( int i )
{
return metadataResolutionExceptions.get( i );
}
public List<ArtifactResolutionException> getMetadataResolutionExceptions()
{
return metadataResolutionExceptions == null ? Collections.<ArtifactResolutionException> emptyList()
: metadataResolutionExceptions;
}
// ------------------------------------------------------------------------
// ErrorArtifactExceptions: ArtifactResolutionExceptions
// ------------------------------------------------------------------------
public boolean hasErrorArtifactExceptions()
{
return errorArtifactExceptions != null;
}
public MetadataResolutionResult addErrorArtifactException( ArtifactResolutionException e )
{
errorArtifactExceptions = initList( errorArtifactExceptions );
errorArtifactExceptions.add( e );
exceptions = initList( exceptions );
exceptions.add( e );
return this;
}
public List<ArtifactResolutionException> getErrorArtifactExceptions()
{
if ( errorArtifactExceptions == null )
{
return Collections.emptyList();
}
return errorArtifactExceptions;
}
// ------------------------------------------------------------------------
// Circular Dependency Exceptions
// ------------------------------------------------------------------------
public boolean hasCircularDependencyExceptions()
{
return circularDependencyExceptions != null;
}
public MetadataResolutionResult addCircularDependencyException( CyclicDependencyException e )
{
circularDependencyExceptions = initList( circularDependencyExceptions );
circularDependencyExceptions.add( e );
exceptions = initList( exceptions );
exceptions.add( e );
return this;
}
public CyclicDependencyException getCircularDependencyException( int i )
{
return circularDependencyExceptions.get( i );
}
public List<CyclicDependencyException> getCircularDependencyExceptions()
{
if ( circularDependencyExceptions == null )
{
return Collections.emptyList();
}
return circularDependencyExceptions;
}
// ------------------------------------------------------------------------
// Repositories
// ------------------------------------------------------------------------
public List<ArtifactRepository> getRepositories()
{
if ( repositories == null )
{
return Collections.emptyList();
}
return repositories;
}
public MetadataResolutionResult setRepositories( final List<ArtifactRepository> repositories )
{
this.repositories = repositories;
return this;
}
//
// Internal
//
private <T> List<T> initList( final List<T> l )
{
if ( l == null )
{
return new ArrayList<T>();
}
return l;
}
public String toString()
{
StringBuffer sb = new StringBuffer();
if ( artifacts != null )
{
int i = 1;
sb.append( "---------" ).append( "\n" );
sb.append( artifacts.size() ).append( "\n" );
for ( Artifact a : artifacts )
{
sb.append( i ).append( " " ).append( a ).append( "\n" );
i++;
}
sb.append( "---------" ).append( "\n" );
}
return sb.toString();
}
}

View File

@ -35,9 +35,14 @@ import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.mercury.util.FileUtil;
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Startable;
import org.sonatype.plexus.jetty.DefaultServletContainer;
import org.sonatype.plexus.webcontainer.ServletContainer;
/**
*
@ -61,6 +66,8 @@ public abstract class AbstractMavenRepositorySystemTest
protected MavenRepositorySystem _mrs;
protected Startable _server;
@Override
protected void setUp()
throws Exception
@ -87,6 +94,22 @@ public abstract class AbstractMavenRepositorySystemTest
_localRepo = new DefaultArtifactRepository("local", _localBase.getCanonicalPath(), new DefaultRepositoryLayout() );
_artifactFactory = getContainer().lookup( ArtifactFactory.class );
_server = (Startable) getContainer().lookup( ServletContainer.class );
_server.start();
}
@Override
protected void tearDown()
throws Exception
{
super.tearDown();
if( _server != null )
_server.stop();
_server = null;
}
protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration )
@ -123,6 +146,7 @@ public abstract class AbstractMavenRepositorySystemTest
request.setLocalRepository( _localRepo );
request.setRemoteRepostories( _remoteRepos );
request.setArtifact( artifact );
request.setResolveRoot( true );
ArtifactResolutionResult res = _mrs.resolve( request );
@ -154,4 +178,21 @@ public abstract class AbstractMavenRepositorySystemTest
}
// public void testRetrieveVersions() throws Exception
// {
// Artifact artifact = _artifactFactory.createArtifact( "asm", "asm", "[3.0,3.2)", "compile", "jar" );
//
// List<ArtifactVersion> res = _mrs.retrieveAvailableVersions( artifact, _localRepo, _remoteRepos );
//
// assertNotNull( res );
//
// assertEquals( 2, res.size() );
//
// assertTrue( res.contains( new DefaultArtifactVersion("3.0") ) );
//
// assertTrue( res.contains( new DefaultArtifactVersion("3.1") ) );
//
// }
}

View File

@ -1,9 +1,4 @@
<plexus>
<load-on-start>
<component>
<role>org.sonatype.plexus.webcontainer.ServletContainer</role>
</component>
</load-on-start>
<components>
<component>
<role>org.sonatype.plexus.webcontainer.ServletContainer</role>