From b7d67cd7e5fe88858b07745e4de28a26ca98752b Mon Sep 17 00:00:00 2001 From: Oleg Gusakov Date: Fri, 6 Mar 2009 23:09:23 +0000 Subject: [PATCH] [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 --- .../LegacyMavenRepositorySystemTest.java | 1 + maven-repository-mercury/pom.xml | 12 + .../mercury/MercuryRepositorySystem.java | 42 ++- .../repository/MetadataResolutionRequest.java | 178 ++++++++++ .../repository/MetadataResolutionResult.java | 311 ++++++++++++++++++ .../AbstractMavenRepositorySystemTest.java | 41 +++ .../src/test/resources/remoteRepo.jar | Bin 138691 -> 139619 bytes .../src/test/resources/webdav.xml | 5 - 8 files changed, 581 insertions(+), 9 deletions(-) diff --git a/maven-project/src/test/java/org/apache/maven/repository/LegacyMavenRepositorySystemTest.java b/maven-project/src/test/java/org/apache/maven/repository/LegacyMavenRepositorySystemTest.java index 1da02b78eb..619796ea80 100644 --- a/maven-project/src/test/java/org/apache/maven/repository/LegacyMavenRepositorySystemTest.java +++ b/maven-project/src/test/java/org/apache/maven/repository/LegacyMavenRepositorySystemTest.java @@ -45,5 +45,6 @@ extends AbstractMavenRepositorySystemTest public void testRetrieve() throws IOException { +// super.testRetrieve(); } } diff --git a/maven-repository-mercury/pom.xml b/maven-repository-mercury/pom.xml index 10b7e538e3..0b3cf1f20b 100644 --- a/maven-repository-mercury/pom.xml +++ b/maven-repository-mercury/pom.xml @@ -105,6 +105,13 @@ under the License. compile + + org.apache.maven.mercury + mercury-repo-virtual + ${mercury.version} + compile + + org.apache.maven.mercury mercury-artifact @@ -133,6 +140,11 @@ under the License. test-jar test + + + org.apache.maven + maven-compat + org.sonatype.plexus diff --git a/maven-repository-mercury/src/main/java/org/apache/maven/repository/mercury/MercuryRepositorySystem.java b/maven-repository-mercury/src/main/java/org/apache/maven/repository/mercury/MercuryRepositorySystem.java index 5b716b1ac0..009b7808e9 100644 --- a/maven-repository-mercury/src/main/java/org/apache/maven/repository/mercury/MercuryRepositorySystem.java +++ b/maven-repository-mercury/src/main/java/org/apache/maven/repository/mercury/MercuryRepositorySystem.java @@ -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 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 retrieveAvailableVersions( Artifact artifact, ArtifactRepository localRepository, +// List remoteRepositories ) +// throws ArtifactMetadataRetrievalException +// { +// +// List repos = +// MercuryAdaptor.toMercuryRepos( localRepository, remoteRepositories, _dependencyProcessor ); +// +// try +// { +// List vl = _mercury.readVersions( repos, MercuryAdaptor.toMercuryBasicMetadata( artifact ) ); +// +// if( Util.isEmpty( vl ) ) +// return null; +// +// List res = new ArrayList( vl.size() ); +// +// for( ArtifactBasicMetadata bmd : vl ) +// res.add( new DefaultArtifactVersion(bmd.getVersion()) ); +// +// return res; +// } +// catch ( RepositoryException e ) +// { +// throw new ArtifactMetadataRetrievalException(e); +// } +// } + } 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 7db6cd9ed3..216c2e44f7 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 @@ -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 artifactDependencies; + + private ArtifactRepository localRepository; + + private List remoteRepositories; + + // Not sure what to do with this? + // Scope + // Lock down lists + private ArtifactFilter filter; + + // Needs to go away + private List listeners = new ArrayList(); + + // 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 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 artifactDependencies ) + { + this.artifactDependencies = artifactDependencies; + + return this; + } + + public Set getArtifactDependencies() + { + return artifactDependencies; + } + + public ArtifactRepository getLocalRepository() + { + return localRepository; + } + + public MetadataResolutionRequest setLocalRepository( ArtifactRepository localRepository ) + { + this.localRepository = localRepository; + + return this; + } + + public List getRemoteRepostories() + { + return remoteRepositories; + } + + public MetadataResolutionRequest setRemoteRepostories( List remoteRepostories ) + { + this.remoteRepositories = remoteRepostories; + + return this; + } + + public ArtifactFilter getFilter() + { + return filter; + } + + public MetadataResolutionRequest setFilter( ArtifactFilter filter ) + { + this.filter = filter; + + return this; + } + + public List getListeners() + { + return listeners; + } + + public MetadataResolutionRequest setListeners( List 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(); + } } diff --git a/maven-repository/src/main/java/org/apache/maven/repository/MetadataResolutionResult.java b/maven-repository/src/main/java/org/apache/maven/repository/MetadataResolutionResult.java index a462045764..90406b9a51 100644 --- a/maven-repository/src/main/java/org/apache/maven/repository/MetadataResolutionResult.java +++ b/maven-repository/src/main/java/org/apache/maven/repository/MetadataResolutionResult.java @@ -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 missingArtifacts; + + // Exceptions + + private List exceptions; + + private List versionRangeViolations; + + private List metadataResolutionExceptions; + + private List circularDependencyExceptions; + + private List errorArtifactExceptions; + + // file system errors + + private List repositories; + + private Set requestedArtifacts; + + private Set 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(); + } + + artifacts.add( artifact ); + } + + public Set getArtifacts() + { + return artifacts; + } + + public void addRequestedArtifact( Artifact artifact ) + { + if ( requestedArtifacts == null ) + { + requestedArtifacts = new LinkedHashSet(); + } + + requestedArtifacts.add( artifact ); + } + + public Set getRequestedArtifacts() + { + return requestedArtifacts; + } + + public boolean hasMissingArtifacts() + { + return missingArtifacts != null && !missingArtifacts.isEmpty(); + } + + public List getMissingArtifacts() + { + return missingArtifacts == null ? Collections. emptyList() : missingArtifacts; + } + + public MetadataResolutionResult addMissingArtifact( Artifact artifact ) + { + missingArtifacts = initList( missingArtifacts ); + + missingArtifacts.add( artifact ); + + return this; + } + + public MetadataResolutionResult setUnresolvedArtifacts( final List unresolvedArtifacts ) + { + this.missingArtifacts = unresolvedArtifacts; + + return this; + } + + // ------------------------------------------------------------------------ + // Exceptions + // ------------------------------------------------------------------------ + + public boolean hasExceptions() + { + return exceptions != null && !exceptions.isEmpty(); + } + + public List getExceptions() + { + return exceptions == null ? Collections. 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 getVersionRangeViolations() + { + return versionRangeViolations == null ? Collections. 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 getMetadataResolutionExceptions() + { + return metadataResolutionExceptions == null ? Collections. 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 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 getCircularDependencyExceptions() + { + if ( circularDependencyExceptions == null ) + { + return Collections.emptyList(); + } + + return circularDependencyExceptions; + } + + // ------------------------------------------------------------------------ + // Repositories + // ------------------------------------------------------------------------ + + public List getRepositories() + { + if ( repositories == null ) + { + return Collections.emptyList(); + } + + return repositories; + } + + public MetadataResolutionResult setRepositories( final List repositories ) + { + this.repositories = repositories; + + return this; + } + + // + // Internal + // + + private List initList( final List l ) + { + if ( l == null ) + { + return new ArrayList(); + } + 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(); + } } diff --git a/maven-repository/src/test/java/org/apache/maven/repository/AbstractMavenRepositorySystemTest.java b/maven-repository/src/test/java/org/apache/maven/repository/AbstractMavenRepositorySystemTest.java index 1c4000105a..f23425e670 100644 --- a/maven-repository/src/test/java/org/apache/maven/repository/AbstractMavenRepositorySystemTest.java +++ b/maven-repository/src/test/java/org/apache/maven/repository/AbstractMavenRepositorySystemTest.java @@ -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 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") ) ); +// +// } + + } diff --git a/maven-repository/src/test/resources/remoteRepo.jar b/maven-repository/src/test/resources/remoteRepo.jar index 697239dbbfe36e4764013112043854520db3a56f..86fad8d8f6621a3b554567f6904361704c62a399 100644 GIT binary patch delta 1246 zcmX@So8$2z4&DH7W)=|!4j{Y~mpYNxiWx+CU1lzbOWmx%ICTN@=D5`9x6>F^g!GN| z4D}Jpm&T<|wqBraY^a}DoU03z)5}UM^42-`^ifg+GedwkJI8j$_}`oi3=I50jL?@k zIT)m`9-*%wKR0#4S*}9{0xj=b_c_NMShnc6s=_>*FDe!BwY);QuB0kQ%e$4 z5=#>GDsppTC;0L;D+suKpVzcueZ$=wDMw-_zkAK7=G5D{fbrIsA6LV)b}3fwsrk(Q z^)}CwrE}lAM+Z(U_S%x`e)aacMQ8t3X=Umf8(1wk)L^8{Vr6c(eD(23RkeoX99)iIR$tb%P=Z*>`Fv)+;Rr>J}5ijIQYg zB1|#@(kP1gmjD%uPQM_=#4){Jj7f{h11@03)Cy z(`|_0192t;CZQEz1wc02WQAoc(+wqnx_nUtMW*+F1fRY~Rw*+5xdhOt><`F-g410j znRJ;Zenb_VFUe%YB=HF>I6<0;ZTdS&pn3jq0j}wmQb2(&xPbU{H&G_x=}V-Tq?mrE zO;?m*5}O{7$|yGdehMSU^fwYr0@GQfnWPw-rYp!WiG!phr~69-jaZ!lS1dVwl{Awe zC#dlz~Ba3 q$|ehxG!lVII><6vGDnFbl!{DWE6c>er^2AZkjKrya9@-O7<&NyeTd!w delta 475 zcmY+9-z!657{|}~&e|bcXZ8bU+c{^EkR=bPww5`FBo}UxfPPj(}AL16Y_>ra_1#-IN$GvEw7@&tb zG#Y(o6?G_RMlNNf%rGr0Xhrydag1IVi+OS@P>n0oZ|oi0DG^}(#Y00Z1!$e~DQAtI zIKOjlr?w#DwNJ*Kw8_~~VBAKzAR>qqElz|G#YK_r@zY}ncG?Ot@#8m$p{exKtfW;H zGR1ZF^{Y@oQ*^Dt8nk)|sMBRhRz)`kX8tEKB{jIM+i5|A3mHpLXjfy4D`vSph+eCz z^s1wpx^zTrLvGN73Lj-X2=a4eI?|!oGG)1!@?8C@`BS~L?}J1mVMs1r(1mD~AS`(x G2*Nk0rIiH$ diff --git a/maven-repository/src/test/resources/webdav.xml b/maven-repository/src/test/resources/webdav.xml index ae56ab4192..1a5fcab0f4 100644 --- a/maven-repository/src/test/resources/webdav.xml +++ b/maven-repository/src/test/resources/webdav.xml @@ -1,9 +1,4 @@ - - - org.sonatype.plexus.webcontainer.ServletContainer - - org.sonatype.plexus.webcontainer.ServletContainer