mirror of https://github.com/apache/maven.git
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:
parent
92a962c9e1
commit
47971a16a1
|
@ -233,12 +233,17 @@ public class ArtifactResolutionRequest
|
|||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer()
|
||||
.append( "REQUEST: " ).append( "\n" )
|
||||
.append(getGroupId())
|
||||
.append(":")
|
||||
.append(getArtifactId())
|
||||
.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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,12 +49,17 @@ public class ArtifactResolutionResult
|
|||
{
|
||||
private Artifact originatingArtifact;
|
||||
|
||||
|
||||
private List<Artifact> missingArtifacts;
|
||||
|
||||
// Exceptions
|
||||
|
||||
private List<Exception> exceptions = new ArrayList<Exception>();
|
||||
|
||||
private List<Exception> versionRangeViolations;
|
||||
|
||||
private List<ArtifactResolutionException> metadataResolutionExceptions;
|
||||
|
||||
private List<Artifact> missingArtifacts;
|
||||
|
||||
private List<CyclicDependencyException> circularDependencyExceptions;
|
||||
|
||||
private List<ArtifactResolutionException> errorArtifactExceptions;
|
||||
|
@ -129,7 +134,21 @@ public class ArtifactResolutionResult
|
|||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Exceptions
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public boolean hasExceptions()
|
||||
{
|
||||
return exceptions.size() > 0;
|
||||
}
|
||||
|
||||
public List<Exception> getExceptions()
|
||||
{
|
||||
return exceptions;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Version Range Violations
|
||||
// ------------------------------------------------------------------------
|
||||
|
@ -149,6 +168,8 @@ public class ArtifactResolutionResult
|
|||
versionRangeViolations = initList( versionRangeViolations );
|
||||
|
||||
versionRangeViolations.add( e );
|
||||
|
||||
exceptions.add( e );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
@ -177,6 +198,8 @@ public class ArtifactResolutionResult
|
|||
metadataResolutionExceptions = initList( metadataResolutionExceptions );
|
||||
|
||||
metadataResolutionExceptions.add( e );
|
||||
|
||||
exceptions.add( e );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
@ -205,6 +228,8 @@ public class ArtifactResolutionResult
|
|||
errorArtifactExceptions = initList( errorArtifactExceptions );
|
||||
|
||||
errorArtifactExceptions.add( e );
|
||||
|
||||
exceptions.add( e );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
@ -232,6 +257,8 @@ public class ArtifactResolutionResult
|
|||
circularDependencyExceptions = initList( circularDependencyExceptions );
|
||||
|
||||
circularDependencyExceptions.add( e );
|
||||
|
||||
exceptions.add( e );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -376,6 +376,28 @@ public class DefaultArtifactResolver
|
|||
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.
|
||||
ArtifactResolutionResult result = artifactCollector.collect( artifacts, originatingArtifact, managedVersions, localRepository, remoteRepositories, source, filter, listeners );
|
||||
|
||||
|
|
|
@ -303,7 +303,7 @@ public class DefaultMavenProjectBuilder
|
|||
"Unable to build project due to an invalid dependency version: " +
|
||||
e.getMessage(), projectDescriptor, ee );
|
||||
}
|
||||
|
||||
|
||||
ArtifactResolutionRequest request = new ArtifactResolutionRequest()
|
||||
.setArtifact( project.getArtifact() )
|
||||
.setArtifactDependencies( project.getDependencyArtifacts() )
|
||||
|
@ -311,9 +311,18 @@ public class DefaultMavenProjectBuilder
|
|||
.setRemoteRepostories( project.getRemoteArtifactRepositories() )
|
||||
.setManagedVersionMap( project.getManagedVersionMap() )
|
||||
.setMetadataSource( repositorySystem );
|
||||
|
||||
|
||||
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() );
|
||||
|
||||
return new MavenProjectBuildingResult( project, result );
|
||||
|
|
|
@ -19,7 +19,6 @@ package org.apache.maven.project;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
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.ResolutionGroup;
|
||||
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.DefaultArtifactResolver;
|
||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||
import org.apache.maven.artifact.versioning.ArtifactVersion;
|
||||
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.Model;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||
|
@ -125,8 +119,7 @@ public class TestArtifactResolver
|
|||
List artifactRepositories;
|
||||
try
|
||||
{
|
||||
artifactRepositories =
|
||||
repositorySystem.buildArtifactRepositories( model.getRepositories() );
|
||||
artifactRepositories = repositorySystem.buildArtifactRepositories( model.getRepositories() );
|
||||
}
|
||||
catch ( InvalidRepositoryException e )
|
||||
{
|
||||
|
@ -199,34 +192,4 @@ public class TestArtifactResolver
|
|||
{
|
||||
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 ) );
|
||||
}
|
||||
}
|
|
@ -29,9 +29,5 @@ public class TestProjectBuilder
|
|||
extends DefaultMavenProjectBuilder
|
||||
{
|
||||
@Requirement(hint="test")
|
||||
private ArtifactResolver artifactResolver;
|
||||
|
||||
// Causing problems
|
||||
//@Requirement(hint="test")
|
||||
//private MavenRepositorySystem repositorySystem;
|
||||
private ArtifactResolver artifactResolver;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue