diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionRequest.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionRequest.java index 7069cfa981..2ece31810c 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionRequest.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionRequest.java @@ -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(); } } diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionResult.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionResult.java index f814e70e1c..cfa268fb24 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionResult.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionResult.java @@ -49,12 +49,17 @@ public class ArtifactResolutionResult { private Artifact originatingArtifact; + + private List missingArtifacts; + + // Exceptions + + private List exceptions = new ArrayList(); + private List versionRangeViolations; private List metadataResolutionExceptions; - private List missingArtifacts; - private List circularDependencyExceptions; private List errorArtifactExceptions; @@ -129,7 +134,21 @@ public class ArtifactResolutionResult return this; } - + + // ------------------------------------------------------------------------ + // Exceptions + // ------------------------------------------------------------------------ + + public boolean hasExceptions() + { + return exceptions.size() > 0; + } + + public List 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; } diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java index 23938e6799..f267746227 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java @@ -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 ); diff --git a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index 1d75d915ae..9cafdca54e 100644 --- a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -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 ); diff --git a/maven-project/src/test/java/org/apache/maven/project/TestArtifactResolver.java b/maven-project/src/test/java/org/apache/maven/project/TestArtifactResolver.java index 5b233d1976..0f29622720 100644 --- a/maven-project/src/test/java/org/apache/maven/project/TestArtifactResolver.java +++ b/maven-project/src/test/java/org/apache/maven/project/TestArtifactResolver.java @@ -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 ) ); - } } \ No newline at end of file diff --git a/maven-project/src/test/java/org/apache/maven/project/TestProjectBuilder.java b/maven-project/src/test/java/org/apache/maven/project/TestProjectBuilder.java index 839093d34b..eeb855ccff 100644 --- a/maven-project/src/test/java/org/apache/maven/project/TestProjectBuilder.java +++ b/maven-project/src/test/java/org/apache/maven/project/TestProjectBuilder.java @@ -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; }