o fixing failing project building tests as a result of consolidating the artifact resolution code

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@749460 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2009-03-02 22:40:17 +00:00
parent 92a962c9e1
commit 47971a16a1
6 changed files with 72 additions and 50 deletions

View File

@ -233,11 +233,16 @@ public class ArtifactResolutionRequest
public String toString() public String toString()
{ {
StringBuffer sb = new StringBuffer() StringBuffer sb = new StringBuffer()
.append( "REQUEST: " ).append( "\n" )
.append(getGroupId()) .append(getGroupId())
.append(":") .append(":")
.append(getArtifactId()) .append(getArtifactId())
.append(":") .append(":")
.append(getVersion()); .append(getVersion() ).append( "\n" )
.append( "artifact: " ).append( artifact ).append( "\n" )
.append( "localRepository: " ).append( localRepository ).append( "\n" )
.append( "remoteRepositories: " ).append( remoteRepositories ).append( "\n" )
.append( "metadataSource: " ).append( metadataSource ).append( "\n" );
return sb.toString(); return sb.toString();
} }

View File

@ -49,12 +49,17 @@ public class ArtifactResolutionResult
{ {
private Artifact originatingArtifact; private Artifact originatingArtifact;
private List<Artifact> missingArtifacts;
// Exceptions
private List<Exception> exceptions = new ArrayList<Exception>();
private List<Exception> versionRangeViolations; private List<Exception> versionRangeViolations;
private List<ArtifactResolutionException> metadataResolutionExceptions; private List<ArtifactResolutionException> metadataResolutionExceptions;
private List<Artifact> missingArtifacts;
private List<CyclicDependencyException> circularDependencyExceptions; private List<CyclicDependencyException> circularDependencyExceptions;
private List<ArtifactResolutionException> errorArtifactExceptions; private List<ArtifactResolutionException> errorArtifactExceptions;
@ -130,6 +135,20 @@ public class ArtifactResolutionResult
return this; return this;
} }
// ------------------------------------------------------------------------
// Exceptions
// ------------------------------------------------------------------------
public boolean hasExceptions()
{
return exceptions.size() > 0;
}
public List<Exception> getExceptions()
{
return exceptions;
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Version Range Violations // Version Range Violations
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@ -150,6 +169,8 @@ public class ArtifactResolutionResult
versionRangeViolations.add( e ); versionRangeViolations.add( e );
exceptions.add( e );
return this; return this;
} }
@ -178,6 +199,8 @@ public class ArtifactResolutionResult
metadataResolutionExceptions.add( e ); metadataResolutionExceptions.add( e );
exceptions.add( e );
return this; return this;
} }
@ -206,6 +229,8 @@ public class ArtifactResolutionResult
errorArtifactExceptions.add( e ); errorArtifactExceptions.add( e );
exceptions.add( e );
return this; return this;
} }
@ -233,6 +258,8 @@ public class ArtifactResolutionResult
circularDependencyExceptions.add( e ); circularDependencyExceptions.add( e );
exceptions.add( e );
return this; return this;
} }

View File

@ -376,6 +376,28 @@ public class DefaultArtifactResolver
listeners.add( new WarningResolutionListener( getLogger() ) ); listeners.add( new WarningResolutionListener( getLogger() ) );
} }
if ( request.getArtifactDependencies() == null || request.getArtifactDependencies().size() == 0 )
{
ArtifactResolutionResult result = new ArtifactResolutionResult();
try
{
resolve( request.getArtifact(), request.getRemoteRepostories(), request.getLocalRepository() );
result.addArtifact( request.getArtifact() );
}
catch ( ArtifactResolutionException e )
{
result.addErrorArtifactException( e );
}
catch ( ArtifactNotFoundException e )
{
result.addMissingArtifact( request.getArtifact() );
}
return result;
}
// After the collection we will have the artifact object in the result but they will not be resolved yet. // After the collection we will have the artifact object in the result but they will not be resolved yet.
ArtifactResolutionResult result = artifactCollector.collect( artifacts, originatingArtifact, managedVersions, localRepository, remoteRepositories, source, filter, listeners ); ArtifactResolutionResult result = artifactCollector.collect( artifacts, originatingArtifact, managedVersions, localRepository, remoteRepositories, source, filter, listeners );

View File

@ -314,6 +314,15 @@ public class DefaultMavenProjectBuilder
ArtifactResolutionResult result = repositorySystem.resolve( request ); ArtifactResolutionResult result = repositorySystem.resolve( request );
if ( result.hasExceptions() )
{
Exception e = result.getExceptions().get( 0 );
throw new ProjectBuildingException( safeVersionlessKey( project.getGroupId(), project.getArtifactId() ),
"Unable to build project due to an invalid dependency version: " +
e.getMessage(), projectDescriptor, e );
}
project.setArtifacts( result.getArtifacts() ); project.setArtifacts( result.getArtifacts() );
return new MavenProjectBuildingResult( project, result ); return new MavenProjectBuildingResult( project, result );

View File

@ -19,7 +19,6 @@ package org.apache.maven.project;
* under the License. * under the License.
*/ */
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.HashSet; import java.util.HashSet;
@ -33,15 +32,10 @@ import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.metadata.ResolutionGroup; import org.apache.maven.artifact.metadata.ResolutionGroup;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.artifact.resolver.DefaultArtifactResolver; import org.apache.maven.artifact.resolver.DefaultArtifactResolver;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.model.Dependency; import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
@ -125,8 +119,7 @@ public class TestArtifactResolver
List artifactRepositories; List artifactRepositories;
try try
{ {
artifactRepositories = artifactRepositories = repositorySystem.buildArtifactRepositories( model.getRepositories() );
repositorySystem.buildArtifactRepositories( model.getRepositories() );
} }
catch ( InvalidRepositoryException e ) catch ( InvalidRepositoryException e )
{ {
@ -199,34 +192,4 @@ public class TestArtifactResolver
{ {
return new Source( repositorySystem, container ); return new Source( repositorySystem, container );
} }
/**
* @noinspection RefusedBequest
*/
@Override
public void resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
throws ArtifactResolutionException
{
artifact.setFile( new File( "dummy" ) );
}
@Override
public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
ArtifactRepository localRepository, List remoteRepositories,
ArtifactMetadataSource source, ArtifactFilter filter )
throws ArtifactResolutionException, ArtifactNotFoundException
{
return super.resolveTransitively( artifacts, originatingArtifact, localRepository, remoteRepositories,
new Source( repositorySystem, container ), filter );
}
@Override
public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
List remoteRepositories, ArtifactRepository localRepository,
ArtifactMetadataSource source )
throws ArtifactResolutionException, ArtifactNotFoundException
{
return super.resolveTransitively( artifacts, originatingArtifact, remoteRepositories, localRepository,
new Source( repositorySystem, container ) );
}
} }

View File

@ -30,8 +30,4 @@ public class TestProjectBuilder
{ {
@Requirement(hint="test") @Requirement(hint="test")
private ArtifactResolver artifactResolver; private ArtifactResolver artifactResolver;
// Causing problems
//@Requirement(hint="test")
//private MavenRepositorySystem repositorySystem;
} }