From 810d4a3276877581779fa122b5df6ce4f0a5c0b1 Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Tue, 19 Jul 2005 05:04:39 +0000 Subject: [PATCH] PR: MNG-505 artifact refactoring to facilitate version ranges git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@219616 13f79535-47bb-0310-9956-ffa450edef68 --- .../artifact/ant/AbstractArtifactTask.java | 54 ++++++------- .../maven/artifact/ant/DependenciesTask.java | 6 +- .../artifact/ArtifactComponentTestCase.java | 39 ++++----- .../resolver/ArtifactResolverTest.java | 22 ++++- .../maven/artifact/DefaultArtifact.java | 6 +- .../artifact/factory/ArtifactFactory.java | 35 +++++++- .../factory/DefaultArtifactFactory.java | 62 +++++++++++++- .../artifact/versioning/VersionRange.java | 47 +++++++++++ .../maven/plugin/DefaultPluginManager.java | 58 +++++++------- .../version/DefaultPluginVersionManager.java | 7 +- ...luginParameterExpressionEvaluatorTest.java | 25 ++++-- .../InvalidArtifactDiagnoserTest.java | 16 +++- .../plugin/descriptor/PluginDescriptor.java | 23 +++--- .../project/DefaultMavenProjectBuilder.java | 80 +++++++++---------- .../project/artifact/MavenMetadataSource.java | 20 ++--- .../ProjectClasspathArtifactResolver.java | 27 ++++--- 16 files changed, 346 insertions(+), 181 deletions(-) create mode 100644 maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java diff --git a/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactTask.java b/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactTask.java index ec27252e58..14679ac608 100755 --- a/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactTask.java +++ b/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactTask.java @@ -16,21 +16,21 @@ package org.apache.maven.artifact.ant; * limitations under the License. */ -import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.repository.DefaultArtifactRepository; -import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.settings.Mirror; -import org.apache.maven.settings.Server; -import org.apache.maven.settings.Settings; -import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader; +import org.apache.maven.artifact.manager.WagonManager; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.DefaultArtifactRepository; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.model.Model; import org.apache.maven.profiles.activation.ProfileActivationUtils; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectBuilder; +import org.apache.maven.settings.Mirror; +import org.apache.maven.settings.Server; +import org.apache.maven.settings.Settings; +import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; @@ -104,20 +104,20 @@ public abstract class AbstractArtifactTask manager.addProxy( proxy.getType(), proxy.getHost(), proxy.getPort(), proxy.getUserName(), proxy.getPassword(), proxy.getNonProxyHosts() ); } - + ArtifactRepositoryFactory repositoryFactory = null; - + ArtifactRepository artifactRepository; - + try { repositoryFactory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); - + String snapshotPolicy = repository.getSnapshotPolicy(); String checksumPolicy = repository.getChecksumPolicy(); - - artifactRepository = repositoryFactory.createArtifactRepository( "remote", repository.getUrl(), - repositoryLayout, snapshotPolicy, + + artifactRepository = repositoryFactory.createArtifactRepository( "remote", repository.getUrl(), + repositoryLayout, snapshotPolicy, checksumPolicy ); } finally @@ -260,9 +260,9 @@ public abstract class AbstractArtifactTask try { ClassWorld classWorld = new ClassWorld(); - - ClassRealm classRealm = classWorld.newRealm( "plexus.core", getClass().getClassLoader() ); - + + classWorld.newRealm( "plexus.core", getClass().getClassLoader() ); + embedder.start( classWorld ); } catch ( PlexusContainerException e ) @@ -273,7 +273,7 @@ public abstract class AbstractArtifactTask { throw new BuildException( "Unable to create embedder ClassRealm", e ); } - + getProject().addReference( Embedder.class.getName(), embedder ); } } @@ -307,18 +307,18 @@ public abstract class AbstractArtifactTask protected Pom createDummyPom() { Model mavenModel = new Model(); - + mavenModel.setGroupId( "unspecified" ); mavenModel.setArtifactId( "unspecified" ); mavenModel.setVersion( "0.0" ); mavenModel.setPackaging( "jar" ); - + MavenProject mavenProject = new MavenProject( mavenModel ); - + Pom pom = new Pom(); - + pom.setMavenProject( mavenProject ); - + return pom; } @@ -360,8 +360,6 @@ public abstract class AbstractArtifactTask { ArtifactFactory factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); // TODO: maybe not strictly correct, while we should enfore that packaging has a type handler of the same id, we don't - Artifact artifact = factory.createArtifact( pom.getGroupId(), pom.getArtifactId(), pom.getVersion(), null, - pom.getPackaging() ); - return artifact; + return factory.createBuildArtifact( pom.getGroupId(), pom.getArtifactId(), pom.getVersion(), pom.getPackaging() ); } } diff --git a/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java b/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java index 6ac913b56a..c324d92362 100755 --- a/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java +++ b/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java @@ -63,7 +63,7 @@ public class DependenciesTask ArtifactResolver resolver = (ArtifactResolver) lookup( ArtifactResolver.ROLE ); MavenProjectBuilder projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE ); ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); - MavenMetadataSource metadataSource = new MavenMetadataSource( resolver, projectBuilder, artifactFactory ); + MavenMetadataSource metadataSource = new MavenMetadataSource( projectBuilder, artifactFactory ); List dependencies = this.dependencies; @@ -101,8 +101,8 @@ public class DependenciesTask ArtifactResolutionResult result; try { - Artifact pomArtifact = artifactFactory.createArtifact( pom.getGroupId(), pom.getArtifactId(), - pom.getVersion(), null, pom.getPackaging() ); + Artifact pomArtifact = artifactFactory.createBuildArtifact( pom.getGroupId(), pom.getArtifactId(), + pom.getVersion(), pom.getPackaging() ); List listeners = Collections.EMPTY_LIST; if ( verbose ) diff --git a/maven-artifact-manager/src/test/java/org/apache/maven/artifact/ArtifactComponentTestCase.java b/maven-artifact-manager/src/test/java/org/apache/maven/artifact/ArtifactComponentTestCase.java index d2118177e8..78738529c4 100644 --- a/maven-artifact-manager/src/test/java/org/apache/maven/artifact/ArtifactComponentTestCase.java +++ b/maven-artifact-manager/src/test/java/org/apache/maven/artifact/ArtifactComponentTestCase.java @@ -16,7 +16,7 @@ package org.apache.maven.artifact; -import org.apache.maven.artifact.handler.DefaultArtifactHandler; +import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.DefaultArtifactRepository; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; @@ -56,10 +56,7 @@ public abstract class ArtifactComponentTestCase ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" ); - ArtifactRepository localRepository = new DefaultArtifactRepository( "test", "file://" + f.getPath(), - repoLayout ); - - return localRepository; + return (ArtifactRepository) new DefaultArtifactRepository( "test", "file://" + f.getPath(), repoLayout ); } protected String getRepositoryLayout() @@ -77,10 +74,7 @@ public abstract class ArtifactComponentTestCase ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" ); - ArtifactRepository localRepository = new DefaultArtifactRepository( "local", "file://" + f.getPath(), - repoLayout ); - - return localRepository; + return (ArtifactRepository) new DefaultArtifactRepository( "local", "file://" + f.getPath(), repoLayout ); } protected ArtifactRepository remoteRepository() @@ -93,11 +87,9 @@ public abstract class ArtifactComponentTestCase ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" ); - ArtifactRepository repository = new DefaultArtifactRepository( "test", "file://" + f.getPath(), repoLayout, - ArtifactRepository.SNAPSHOT_POLICY_NEVER, - ArtifactRepository.CHECKSUM_POLICY_WARN ); - - return repository; + return (ArtifactRepository) new DefaultArtifactRepository( "test", "file://" + f.getPath(), repoLayout, + ArtifactRepository.SNAPSHOT_POLICY_NEVER, + ArtifactRepository.CHECKSUM_POLICY_WARN ); } protected ArtifactRepository badRemoteRepository() @@ -106,10 +98,7 @@ public abstract class ArtifactComponentTestCase ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" ); - ArtifactRepository repository = new DefaultArtifactRepository( "test", "http://foo.bar/repository", - repoLayout ); - - return repository; + return (ArtifactRepository) new DefaultArtifactRepository( "test", "http://foo.bar/repository", repoLayout ); } protected void assertRemoteArtifactPresent( Artifact artifact ) @@ -242,22 +231,24 @@ public abstract class ArtifactComponentTestCase } protected Artifact createArtifact( String artifactId, String version ) + throws Exception { return createArtifact( artifactId, version, "jar" ); } protected Artifact createArtifact( String artifactId, String version, String type ) + throws Exception { - // TODO: fix handler instantiation - return new DefaultArtifact( "org.apache.maven", artifactId, version, null, type, null, - new DefaultArtifactHandler( type ) ); + return createArtifact( "org.apache.maven", artifactId, version, type ); } protected Artifact createArtifact( String groupId, String artifactId, String version, String type ) + throws Exception { - // TODO: fix handler instantiation - return new DefaultArtifact( groupId, artifactId, version, Artifact.SCOPE_COMPILE, type, null, - new DefaultArtifactHandler( type ) ); + ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); + + // TODO: used to be SCOPE_COMPILE, check + return artifactFactory.createBuildArtifact( groupId, artifactId, version, type ); } protected void deleteLocalArtifact( Artifact artifact ) diff --git a/maven-artifact-manager/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java b/maven-artifact-manager/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java index 494e2b18f9..ebbf5191cf 100644 --- a/maven-artifact-manager/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java +++ b/maven-artifact-manager/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java @@ -20,6 +20,7 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.ArtifactComponentTestCase; import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.metadata.ResolutionGroup; +import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.repository.ArtifactRepository; import java.util.ArrayList; @@ -82,6 +83,7 @@ public class ArtifactResolverTest } protected Artifact createArtifact( String groupId, String artifactId, String version, String type ) + throws Exception { // for the anonymous classes return super.createArtifact( groupId, artifactId, version, type ); @@ -97,12 +99,20 @@ public class ArtifactResolverTest ArtifactMetadataSource mds = new ArtifactMetadataSource() { public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) + throws ArtifactMetadataRetrievalException { Set dependencies = new HashSet(); if ( artifact.getArtifactId().equals( "g" ) ) { - dependencies.add( createArtifact( "org.apache.maven", "h", "1.0", "jar" ) ); + try + { + dependencies.add( createArtifact( "org.apache.maven", "h", "1.0", "jar" ) ); + } + catch ( Exception e ) + { + throw new ArtifactMetadataRetrievalException( e ); + } } return new ResolutionGroup( dependencies, remoteRepositories ); @@ -136,12 +146,20 @@ public class ArtifactResolverTest ArtifactMetadataSource mds = new ArtifactMetadataSource() { public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) + throws ArtifactMetadataRetrievalException { Set dependencies = new HashSet(); if ( artifact.getArtifactId().equals( "i" ) ) { - dependencies.add( createArtifact( "org.apache.maven", "j", "1.0", "jar" ) ); + try + { + dependencies.add( createArtifact( "org.apache.maven", "j", "1.0", "jar" ) ); + } + catch ( Exception e ) + { + throw new ArtifactMetadataRetrievalException( e ); + } } return new ResolutionGroup( dependencies, remoteRepositories ); diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java b/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java index 6f64a851a6..d76efff780 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java @@ -20,6 +20,7 @@ import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.artifact.versioning.VersionRange; import org.codehaus.plexus.util.StringUtils; import java.io.File; @@ -71,8 +72,7 @@ public class DefaultArtifact private List dependencyTrail; - // TODO: direct all through the artifact factory - public DefaultArtifact( String groupId, String artifactId, String version, String scope, String type, + public DefaultArtifact( String groupId, String artifactId, VersionRange versionRange, String scope, String type, String classifier, ArtifactHandler artifactHandler ) { this.groupId = groupId; @@ -80,7 +80,7 @@ public class DefaultArtifact this.artifactId = artifactId; // TODO: this would be where we might have a min/max instead - this.version = version; + this.version = versionRange.getVersion(); this.artifactHandler = artifactHandler; diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/factory/ArtifactFactory.java b/maven-artifact/src/main/java/org/apache/maven/artifact/factory/ArtifactFactory.java index e9e35b99ed..6cd9cf1a87 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/factory/ArtifactFactory.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/factory/ArtifactFactory.java @@ -17,16 +17,43 @@ package org.apache.maven.artifact.factory; */ import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.versioning.VersionRange; public interface ArtifactFactory { static String ROLE = ArtifactFactory.class.getName(); + /** + * @deprecated + */ Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type, String inheritedScope ); - Artifact createArtifact( String groupId, String artifactId, String knownVersion, String scope, String type ); - - Artifact createArtifactWithClassifier( String groupId, String artifactId, String version, String scope, - String type, String classifier ); + // TODO: deprecate and chase down (probably used for copying only) + Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type ); + + /** + * @deprecated + */ + Artifact createArtifactWithClassifier( String groupId, String artifactId, String version, String scope, String type, + String classifier ); + + Artifact createArtifactWithClassifier( String groupId, String artifactId, String version, String type, + String classifier ); + + Artifact createDependencyArtifact( String groupId, String artifactId, VersionRange versionRange, String type, + String scope ); + + Artifact createDependencyArtifact( String groupId, String artifactId, VersionRange versionRange, String type, + String scope, String inheritedScope ); + + Artifact createBuildArtifact( String groupId, String artifactId, String version, String packaging ); + + Artifact createProjectArtifact( String groupId, String artifactId, String version ); + + Artifact createParentArtifact( String groupId, String artifactId, String version ); + + Artifact createPluginArtifact( String groupId, String artifactId, VersionRange versionRange ); + + Artifact createProjectArtifact( String groupId, String artifactId, String version, String scope ); } diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java b/maven-artifact/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java index c6fe010a69..f9864e609b 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java @@ -20,6 +20,7 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; +import org.apache.maven.artifact.versioning.VersionRange; public class DefaultArtifactFactory implements ArtifactFactory @@ -47,6 +48,49 @@ public class DefaultArtifactFactory return createArtifact( groupId, artifactId, version, scope, type, classifier, null ); } + public Artifact createArtifactWithClassifier( String groupId, String artifactId, String version, String type, + String classifier ) + { + return createArtifact( groupId, artifactId, version, null, type, classifier, null ); + } + + public Artifact createDependencyArtifact( String groupId, String artifactId, VersionRange versionRange, String type, + String scope ) + { + return createArtifact( groupId, artifactId, versionRange, null, type, null, null ); + } + + public Artifact createDependencyArtifact( String groupId, String artifactId, VersionRange versionRange, String type, + String scope, String inheritedScope ) + { + return createArtifact( groupId, artifactId, versionRange, scope, type, null, inheritedScope ); + } + + public Artifact createBuildArtifact( String groupId, String artifactId, String version, String packaging ) + { + return createArtifact( groupId, artifactId, version, null, packaging, null, null ); + } + + public Artifact createProjectArtifact( String groupId, String artifactId, String version ) + { + return createProjectArtifact( groupId, artifactId, version, null ); + } + + public Artifact createParentArtifact( String groupId, String artifactId, String version ) + { + return createProjectArtifact( groupId, artifactId, version ); + } + + public Artifact createPluginArtifact( String groupId, String artifactId, VersionRange versionRange ) + { + return createArtifact( groupId, artifactId, versionRange, Artifact.SCOPE_RUNTIME, "maven-plugin", null, null ); + } + + public Artifact createProjectArtifact( String groupId, String artifactId, String version, String scope ) + { + return createArtifact( groupId, artifactId, version, scope, "pom" ); + } + public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type, String inheritedScope ) { @@ -55,6 +99,22 @@ public class DefaultArtifactFactory private Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type, String classifier, String inheritedScope ) + { + // TODO: better constructor + VersionRange versionRange; + if ( version != null ) + { + versionRange = new VersionRange( "[" + version + "]" ); + } + else + { + versionRange = new VersionRange( null ); + } + return createArtifact( groupId, artifactId, versionRange, scope, type, classifier, inheritedScope ); + } + + private Artifact createArtifact( String groupId, String artifactId, VersionRange versionRange, String scope, + String type, String classifier, String inheritedScope ) { // TODO: can refactor - inherited scope calculation belongs in the collector, use scope handler @@ -87,6 +147,6 @@ public class DefaultArtifactFactory ArtifactHandler handler = artifactHandlerManager.getArtifactHandler( type ); - return new DefaultArtifact( groupId, artifactId, version, desiredScope, type, classifier, handler ); + return new DefaultArtifact( groupId, artifactId, versionRange, desiredScope, type, classifier, handler ); } } diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java b/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java new file mode 100644 index 0000000000..1883dd440e --- /dev/null +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java @@ -0,0 +1,47 @@ +package org.apache.maven.artifact.versioning; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Construct a version range from a specification. + * + * @author Brett Porter + * @version $Id$ + */ +public class VersionRange +{ + private String version; + + public VersionRange( String spec ) + { + if ( spec != null ) + { + // temporary! + if ( spec.startsWith( "[" ) ) + { + spec = spec.substring( 1, spec.length() - 1 ); + } + } + + this.version = spec; + } + + public String getVersion() + { + return version; + } +} diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java index c26848eef9..67ded47f0c 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java @@ -29,6 +29,7 @@ import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter; import org.apache.maven.artifact.resolver.filter.InversionArtifactFilter; import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; +import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Plugin; import org.apache.maven.model.ReportPlugin; @@ -165,8 +166,8 @@ public class DefaultPluginManager String groupId = plugin.getGroupId(); String artifactId = plugin.getArtifactId(); - plugin.setVersion( pluginVersionManager.resolvePluginVersion( groupId, artifactId, project, settings, - localRepository ) ); + plugin.setVersion( + pluginVersionManager.resolvePluginVersion( groupId, artifactId, project, settings, localRepository ) ); } // TODO: this might result in an artifact "RELEASE" being resolved continuously @@ -174,14 +175,13 @@ public class DefaultPluginManager { try { - Artifact pluginArtifact = artifactFactory.createArtifact( plugin.getGroupId(), - plugin.getArtifactId(), - plugin.getVersion(), - Artifact.SCOPE_RUNTIME, - MojoDescriptor.MAVEN_PLUGIN ); + VersionRange versionRange = new VersionRange( plugin.getVersion() ); + Artifact pluginArtifact = artifactFactory.createPluginArtifact( plugin.getGroupId(), + plugin.getArtifactId(), versionRange ); - // TODO: [jc; 2005-july-06] what's this for? - //plugin.setVersion( pluginArtifact.getBaseVersion() ); + // I think this ensures the plugin is not resolved multiple times + // TODO: put it back +// plugin.setVersion( pluginArtifact.getBaseVersion() ); addPlugin( plugin, pluginArtifact, project, localRepository ); @@ -198,10 +198,9 @@ public class DefaultPluginManager String artifactId = plugin.getArtifactId(); String version = plugin.getVersion(); - if ( - ( groupId == null || artifactId == null || version == null || - ( groupId.equals( e.getGroupId() ) && artifactId.equals( e.getArtifactId() ) && - version.equals( e.getVersion() ) ) ) && "maven-plugin".equals( e.getType() ) ) + if ( ( groupId == null || artifactId == null || version == null || ( groupId.equals( e.getGroupId() ) && + artifactId.equals( e.getArtifactId() ) && version.equals( e.getVersion() ) ) ) && + "maven-plugin".equals( e.getType() ) ) { throw new PluginNotFoundException( e ); } @@ -222,7 +221,8 @@ public class DefaultPluginManager artifactResolver.resolve( pluginArtifact, project.getPluginArtifactRepositories(), localRepository ); PlexusContainer child = container.createChildContainer( plugin.getKey(), Collections - .singletonList( pluginArtifact.getFile() ), Collections.EMPTY_MAP, Collections.singletonList( pluginCollector ) ); + .singletonList( pluginArtifact.getFile() ), Collections.EMPTY_MAP, + Collections.singletonList( pluginCollector ) ); // this plugin's descriptor should have been discovered in the child creation, so we should be able to // circle around and set the artifacts and class realm @@ -328,10 +328,9 @@ public class DefaultPluginManager } } - public List getReports( ReportPlugin reportPlugin, ReportSet reportSet, MavenProject project, - MavenSession session, ArtifactRepository localRepository ) - throws PluginManagerException, PluginVersionResolutionException, PluginConfigurationException, - ArtifactResolutionException + public List getReports( ReportPlugin reportPlugin, ReportSet reportSet, MavenProject project, MavenSession session, + ArtifactRepository localRepository ) + throws PluginManagerException, PluginVersionResolutionException, PluginConfigurationException, ArtifactResolutionException { Plugin forLookup = new Plugin(); forLookup.setGroupId( reportPlugin.getGroupId() ); @@ -360,7 +359,8 @@ public class DefaultPluginManager MojoExecution mojoExecution = new MojoExecution( mojoDescriptor, id ); String executionId = mojoExecution.getExecutionId(); - Xpp3Dom dom = project.getReportConfiguration( reportPlugin.getGroupId(), reportPlugin.getArtifactId(), executionId ); + Xpp3Dom dom = project.getReportConfiguration( reportPlugin.getGroupId(), + reportPlugin.getArtifactId(), executionId ); reports.add( getConfiguredMojo( mojoDescriptor, session, dom, project ) ); } @@ -451,8 +451,7 @@ public class DefaultPluginManager try { - MavenMetadataSource metadataSource = new MavenMetadataSource( artifactResolver, mavenProjectBuilder, - artifactFactory ); + MavenMetadataSource metadataSource = new MavenMetadataSource( mavenProjectBuilder, artifactFactory ); List remoteRepositories = new ArrayList(); @@ -543,9 +542,8 @@ public class DefaultPluginManager // ideally, this would be elevated above the true debug output, but below the default INFO level... // [BP] (2004-07-18): need to understand the context more but would prefer this could be either WARN or // removed - shouldn't need DEBUG to diagnose a problem most of the time. - getLogger().debug( - "*** WARNING: Configuration \'" + child.getName() + "\' is not used in goal \'" + - mojoDescriptor.getFullGoalName() + "; this may indicate a typo... ***" ); + getLogger().debug( "*** WARNING: Configuration \'" + child.getName() + "\' is not used in goal \'" + + mojoDescriptor.getFullGoalName() + "; this may indicate a typo... ***" ); } } @@ -631,9 +629,8 @@ public class DefaultPluginManager } if ( fieldValue != null ) { - getLogger().warn( - "DEPRECATED: using default-value to set the default value of field '" + - parameter.getName() + "'" ); + getLogger().warn( "DEPRECATED: using default-value to set the default value of field '" + + parameter.getName() + "'" ); } } catch ( NoSuchFieldException e ) @@ -920,14 +917,13 @@ public class DefaultPluginManager ArtifactFactory artifactFactory, MavenProject project ) throws ArtifactResolutionException { - MavenMetadataSource sourceReader = new MavenMetadataSource( artifactResolver, mavenProjectBuilder, - artifactFactory ); + MavenMetadataSource sourceReader = new MavenMetadataSource( mavenProjectBuilder, artifactFactory ); ArtifactFilter filter = new ScopeArtifactFilter( scope ); // TODO: such a call in MavenMetadataSource too - packaging not really the intention of type - Artifact artifact = artifactFactory.createArtifact( project.getGroupId(), project.getArtifactId(), - project.getVersion(), null, project.getPackaging() ); + Artifact artifact = artifactFactory.createBuildArtifact( project.getGroupId(), project.getArtifactId(), + project.getVersion(), project.getPackaging() ); // TODO: we don't need to resolve over and over again, as long as we are sure that the parameters are the same // check this with yourkit as a hot spot. diff --git a/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java b/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java index d1c0ec6865..05e602652e 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java @@ -601,11 +601,10 @@ public class DefaultPluginVersionManager private String resolveMetaVersion( String groupId, String artifactId, List remoteRepositories, ArtifactRepository localRepository, String metaVersionId ) { - Artifact artifact = artifactFactory.createArtifact( groupId, artifactId, metaVersionId, Artifact.SCOPE_RUNTIME, - "pom" ); + // TODO: check - this was SCOPE_RUNTIME before, now is null + Artifact artifact = artifactFactory.createProjectArtifact( groupId, artifactId, metaVersionId ); - MavenMetadataSource metadataSource = new MavenMetadataSource( artifactResolver, projectBuilder, - artifactFactory ); + MavenMetadataSource metadataSource = new MavenMetadataSource( projectBuilder, artifactFactory ); String version = null; try diff --git a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java index 274e683166..5e27e24a4f 100644 --- a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java +++ b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java @@ -17,9 +17,9 @@ package org.apache.maven.plugin; */ import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.DefaultArtifact; -import org.apache.maven.artifact.repository.DefaultArtifactRepository; +import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.DefaultArtifactRepository; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Build; @@ -66,7 +66,8 @@ public class PluginParameterExpressionEvaluatorTest assertEquals( expected, actual ); } - private static MavenSession createSession( MavenProject project, PlexusContainer container, ArtifactRepository repo ) + private static MavenSession createSession( MavenProject project, PlexusContainer container, + ArtifactRepository repo ) { return new MavenSession( project, container, new Settings(), repo, new DefaultEventDispatcher(), Collections.EMPTY_LIST ); @@ -103,7 +104,7 @@ public class PluginParameterExpressionEvaluatorTest { PluginDescriptor pd = new PluginDescriptor(); - Artifact artifact = new DefaultArtifact( "testGroup", "testArtifact", "1.0", Artifact.SCOPE_COMPILE, "jar", null, null ); + Artifact artifact = createArtifact( "testGroup", "testArtifact", "1.0" ); pd.setArtifacts( Collections.singletonList( artifact ) ); @@ -138,9 +139,17 @@ public class PluginParameterExpressionEvaluatorTest PlexusContainer container = getContainer(); MavenSession session = createSession( project, container, repo ); - ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, pluginDescriptor, - null, container.getLogger(), - project ); - return expressionEvaluator; + return (ExpressionEvaluator) new PluginParameterExpressionEvaluator( session, pluginDescriptor, null, + container.getLogger(), project ); } + + protected Artifact createArtifact( String groupId, String artifactId, String version ) + throws Exception + { + ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); + + // TODO: used to be SCOPE_COMPILE, check + return artifactFactory.createBuildArtifact( groupId, artifactId, version, "jar" ); + } + } \ No newline at end of file diff --git a/maven-core/src/test/java/org/apache/maven/usability/InvalidArtifactDiagnoserTest.java b/maven-core/src/test/java/org/apache/maven/usability/InvalidArtifactDiagnoserTest.java index ca862e529a..8b22484642 100644 --- a/maven-core/src/test/java/org/apache/maven/usability/InvalidArtifactDiagnoserTest.java +++ b/maven-core/src/test/java/org/apache/maven/usability/InvalidArtifactDiagnoserTest.java @@ -1,6 +1,9 @@ package org.apache.maven.usability; import org.apache.maven.artifact.DefaultArtifact; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.codehaus.plexus.PlexusTestCase; import junit.framework.TestCase; @@ -21,9 +24,8 @@ import junit.framework.TestCase; */ public class InvalidArtifactDiagnoserTest - extends TestCase + extends PlexusTestCase { - private InvalidArtifactDiagnoser diagnoser = new InvalidArtifactDiagnoser(); public void testShouldDiagnoseArtifactWithMissingGroupId() throws Throwable @@ -61,7 +63,7 @@ public class InvalidArtifactDiagnoserTest try { - new DefaultArtifact( groupId, artifactId, version, null, type, null, null ); + createArtifact( groupId, artifactId, version, type ); fail( "artifact creation did not fail; nothing to diagnose." ); } @@ -79,4 +81,12 @@ public class InvalidArtifactDiagnoserTest } } } + + private Artifact createArtifact( String groupId, String artifactId, String version, String type ) + throws Exception + { + ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); + return artifactFactory.createBuildArtifact( groupId, artifactId, version, type ); + } + } diff --git a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java index ce232a6b33..b76e8e0c4a 100644 --- a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java +++ b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java @@ -16,24 +16,23 @@ package org.apache.maven.plugin.descriptor; * limitations under the License. */ +import org.apache.maven.artifact.ArtifactUtils; +import org.apache.maven.plugin.lifecycle.Lifecycle; +import org.apache.maven.plugin.lifecycle.LifecycleConfiguration; +import org.apache.maven.plugin.lifecycle.io.xpp3.LifecycleMappingsXpp3Reader; +import org.codehaus.classworlds.ClassRealm; import org.codehaus.plexus.component.repository.ComponentSetDescriptor; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; -import org.codehaus.classworlds.ClassRealm; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.ArtifactUtils; -import org.apache.maven.plugin.lifecycle.LifecycleConfiguration; -import org.apache.maven.plugin.lifecycle.Lifecycle; -import org.apache.maven.plugin.lifecycle.io.xpp3.LifecycleMappingsXpp3Reader; -import java.util.List; -import java.util.Iterator; -import java.util.Map; -import java.util.HashMap; -import java.io.InputStreamReader; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import java.io.FileNotFoundException; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; /** * @author Jason van Zyl 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 a818fe1c96..760353ccb1 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 @@ -24,6 +24,7 @@ import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; 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.versioning.VersionRange; import org.apache.maven.model.Build; import org.apache.maven.model.Dependency; import org.apache.maven.model.DependencyManagement; @@ -120,7 +121,7 @@ public class DefaultMavenProjectBuilder List externalProfiles ) throws ProjectBuildingException, ArtifactResolutionException { - ArtifactMetadataSource source = new MavenMetadataSource( artifactResolver, this, artifactFactory ); + ArtifactMetadataSource source = new MavenMetadataSource( this, artifactFactory ); return buildWithDependencies( projectDescriptor, localRepository, source, externalProfiles ); } @@ -144,7 +145,7 @@ public class DefaultMavenProjectBuilder // TODO: such a call in MavenMetadataSource too - packaging not really the intention of type Artifact projectArtifact = project.getArtifact(); - + Map managedVersions = createManagedVersionMap( project.getDependencyManagement() ); ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getDependencyArtifacts(), projectArtifact, managedVersions, @@ -166,8 +167,9 @@ public class DefaultMavenProjectBuilder { Dependency d = (Dependency) i.next(); - Artifact artifact = artifactFactory.createArtifact( d.getGroupId(), d.getArtifactId(), d.getVersion(), - d.getScope(), d.getType(), null ); + Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(), + new VersionRange( d.getVersion() ), + d.getType(), d.getScope() ); map.put( d.getManagementKey(), artifact ); } @@ -194,7 +196,8 @@ public class DefaultMavenProjectBuilder // Always cache files in the source tree over those in the repository modelCache.put( createCacheKey( model.getGroupId(), model.getArtifactId(), model.getVersion() ), model ); - MavenProject project = build( projectDescriptor.getAbsolutePath(), model, localRepository, Collections.EMPTY_LIST, externalProfiles ); + MavenProject project = build( projectDescriptor.getAbsolutePath(), model, localRepository, + Collections.EMPTY_LIST, externalProfiles ); // Only translate the base directory for files in the source tree pathTranslator.alignToBaseDirectory( project.getModel(), projectDescriptor ); @@ -216,7 +219,8 @@ public class DefaultMavenProjectBuilder { Model model = findModelFromRepository( artifact, remoteArtifactRepositories, localRepository ); - return build( "Artifact [" + artifact.getId() + "]", model, localRepository, remoteArtifactRepositories, Collections.EMPTY_LIST ); + return build( "Artifact [" + artifact.getId() + "]", model, localRepository, remoteArtifactRepositories, + Collections.EMPTY_LIST ); } private Model findModelFromRepository( Artifact artifact, List remoteArtifactRepositories, @@ -274,14 +278,14 @@ public class DefaultMavenProjectBuilder if ( remoteArtifactRepositories == null || remoteArtifactRepositories.isEmpty() ) { aggregatedRemoteWagonRepositories = ProjectUtils.buildArtifactRepositories( superModel.getRepositories(), - artifactRepositoryFactory, - container ); + artifactRepositoryFactory, + container ); } else { aggregatedRemoteWagonRepositories = remoteArtifactRepositories; } - + for ( Iterator i = externalProfiles.iterator(); i.hasNext(); ) { Profile externalProfile = (Profile) i.next(); @@ -379,16 +383,16 @@ public class DefaultMavenProjectBuilder project.addProfileProperties( profileProperties ); project.setActiveProfiles( activeProfiles ); - + // TODO: maybe not strictly correct, while we should enfore that packaging has a type handler of the same id, we don't - Artifact projectArtifact = artifactFactory.createArtifact( project.getGroupId(), project.getArtifactId(), - project.getVersion(), null, project.getPackaging() ); - + Artifact projectArtifact = artifactFactory.createBuildArtifact( project.getGroupId(), project.getArtifactId(), + project.getVersion(), project.getPackaging() ); + project.setArtifact( projectArtifact ); - project.setPluginArtifactRepositories( - ProjectUtils.buildArtifactRepositories( model.getPluginRepositories(), artifactRepositoryFactory, - container ) ); + project.setPluginArtifactRepositories( ProjectUtils.buildArtifactRepositories( model.getPluginRepositories(), + artifactRepositoryFactory, + container ) ); DistributionManagement dm = model.getDistributionManagement(); if ( dm != null ) @@ -401,9 +405,9 @@ public class DefaultMavenProjectBuilder if ( parentProject != null ) { - Artifact parentArtifact = artifactFactory.createArtifact( parentProject.getGroupId(), - parentProject.getArtifactId(), - parentProject.getVersion(), null, "pom" ); + Artifact parentArtifact = artifactFactory.createProjectArtifact( parentProject.getGroupId(), + parentProject.getArtifactId(), + parentProject.getVersion() ); project.setParentArtifact( parentArtifact ); } @@ -415,9 +419,8 @@ public class DefaultMavenProjectBuilder if ( validationResult.getMessageCount() > 0 ) { - throw new ProjectBuildingException( - "Failed to validate POM for \'" + pomLocation + "\'.\n\n Reason(s):\n" + - validationResult.render( " " ) ); + throw new ProjectBuildingException( "Failed to validate POM for \'" + pomLocation + + "\'.\n\n Reason(s):\n" + validationResult.render( " " ) ); } return project; @@ -431,11 +434,11 @@ public class DefaultMavenProjectBuilder { List respositories = ProjectUtils.buildArtifactRepositories( model.getRepositories(), artifactRepositoryFactory, container ); - + for ( Iterator it = respositories.iterator(); it.hasNext(); ) { ArtifactRepository repository = (ArtifactRepository) it.next(); - + if ( !aggregatedRemoteWagonRepositories.contains( repository ) ) { aggregatedRemoteWagonRepositories.add( repository ); @@ -473,8 +476,9 @@ public class DefaultMavenProjectBuilder // as we go in order to do this. // ---------------------------------------------------------------------- - Artifact artifact = artifactFactory.createArtifact( parentModel.getGroupId(), parentModel.getArtifactId(), - parentModel.getVersion(), null, "pom" ); + Artifact artifact = artifactFactory.createParentArtifact( parentModel.getGroupId(), + parentModel.getArtifactId(), + parentModel.getVersion() ); model = findModelFromRepository( artifact, aggregatedRemoteWagonRepositories, localRepository ); @@ -504,15 +508,13 @@ public class DefaultMavenProjectBuilder } catch ( IOException e ) { - throw new ProjectBuildingException( - "Failed to build model from file '" + file.getAbsolutePath() + "'.\nError: \'" + - e.getLocalizedMessage() + "\'", e ); + throw new ProjectBuildingException( "Failed to build model from file '" + file.getAbsolutePath() + + "'.\nError: \'" + e.getLocalizedMessage() + "\'", e ); } catch ( XmlPullParserException e ) { - throw new ProjectBuildingException( - "Failed to parse model from file '" + file.getAbsolutePath() + "'.\nError: \'" + - e.getLocalizedMessage() + "\'", e ); + throw new ProjectBuildingException( "Failed to parse model from file '" + file.getAbsolutePath() + + "'.\nError: \'" + e.getLocalizedMessage() + "\'", e ); } finally { @@ -531,15 +533,13 @@ public class DefaultMavenProjectBuilder } catch ( IOException e ) { - throw new ProjectBuildingException( - "Failed build model from URL \'" + url.toExternalForm() + "\'\nError: \'" + e.getLocalizedMessage() + - "\'", e ); + throw new ProjectBuildingException( "Failed build model from URL \'" + url.toExternalForm() + + "\'\nError: \'" + e.getLocalizedMessage() + "\'", e ); } catch ( XmlPullParserException e ) { - throw new ProjectBuildingException( - "Failed to parse model from URL \'" + url.toExternalForm() + "\'\nError: \'" + e.getLocalizedMessage() + - "\'", e ); + throw new ProjectBuildingException( "Failed to parse model from URL \'" + url.toExternalForm() + + "\'\nError: \'" + e.getLocalizedMessage() + "\'", e ); } finally { @@ -580,8 +580,8 @@ public class DefaultMavenProjectBuilder version = p.getVersion(); } - Artifact artifact = artifactFactory.createArtifact( p.getGroupId(), p.getArtifactId(), version, null, - "maven-plugin" ); + Artifact artifact = artifactFactory.createPluginArtifact( p.getGroupId(), p.getArtifactId(), + new VersionRange( version ) ); if ( artifact != null ) { pluginArtifacts.add( artifact ); diff --git a/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java b/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java index d1751126bc..d4105d3cb2 100644 --- a/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java +++ b/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java @@ -26,6 +26,7 @@ import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.resolver.filter.AndArtifactFilter; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter; +import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.model.Dependency; import org.apache.maven.model.Exclusion; import org.apache.maven.project.MavenProject; @@ -50,8 +51,7 @@ public class MavenMetadataSource private ArtifactFactory artifactFactory; // TODO: Remove resolver from params list. - public MavenMetadataSource( ArtifactResolver artifactResolver, MavenProjectBuilder projectBuilder, - ArtifactFactory artifactFactory ) + public MavenMetadataSource( MavenProjectBuilder projectBuilder, ArtifactFactory artifactFactory ) { this.mavenProjectBuilder = projectBuilder; this.artifactFactory = artifactFactory; @@ -61,8 +61,8 @@ public class MavenMetadataSource throws ArtifactMetadataRetrievalException { // TODO: only metadata is really needed - resolve as metadata - Artifact pomArtifact = artifactFactory.createArtifact( artifact.getGroupId(), artifact.getArtifactId(), - artifact.getVersion(), artifact.getScope(), "pom" ); + Artifact pomArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), + artifact.getVersion(), artifact.getScope() ); // TODO: this a very thin wrapper around a project builder - is it needed? List dependencies = null; @@ -75,9 +75,10 @@ public class MavenMetadataSource localRepository ); dependencies = p.getDependencies(); artifact.setDownloadUrl( pomArtifact.getDownloadUrl() ); - - Set artifacts = createArtifacts( artifactFactory, dependencies, artifact.getScope(), artifact.getDependencyFilter() ); - + + Set artifacts = createArtifacts( artifactFactory, dependencies, artifact.getScope(), + artifact.getDependencyFilter() ); + return new ResolutionGroup( artifacts, p.getRemoteArtifactRepositories() ); } catch ( ProjectBuildingException e ) @@ -95,8 +96,9 @@ public class MavenMetadataSource { Dependency d = (Dependency) i.next(); - Artifact artifact = artifactFactory.createArtifact( d.getGroupId(), d.getArtifactId(), d.getVersion(), - d.getScope(), d.getType(), inheritedScope ); + Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(), + new VersionRange( d.getVersion() ), + d.getType(), d.getScope(), inheritedScope ); if ( artifact != null && ( dependencyFilter == null || dependencyFilter.include( artifact ) ) ) { diff --git a/maven-project/src/test/java/org/apache/maven/project/ProjectClasspathArtifactResolver.java b/maven-project/src/test/java/org/apache/maven/project/ProjectClasspathArtifactResolver.java index a5d318df45..dcc7ea3747 100644 --- a/maven-project/src/test/java/org/apache/maven/project/ProjectClasspathArtifactResolver.java +++ b/maven-project/src/test/java/org/apache/maven/project/ProjectClasspathArtifactResolver.java @@ -27,6 +27,7 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.artifact.resolver.DefaultArtifactResolver; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +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; @@ -51,23 +52,28 @@ public class ProjectClasspathArtifactResolver implements Contextualizable { private ArtifactRepositoryFactory repositoryFactory; + private PlexusContainer container; public static class Source implements ArtifactMetadataSource { private ArtifactFactory artifactFactory; + private final ArtifactRepositoryFactory repositoryFactory; + private final PlexusContainer container; - public Source( ArtifactFactory artifactFactory, ArtifactRepositoryFactory repositoryFactory, PlexusContainer container ) + public Source( ArtifactFactory artifactFactory, ArtifactRepositoryFactory repositoryFactory, + PlexusContainer container ) { this.artifactFactory = artifactFactory; this.repositoryFactory = repositoryFactory; this.container = container; } - public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) + public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, + List remoteRepositories ) throws ArtifactMetadataRetrievalException { Model model = null; @@ -101,19 +107,20 @@ public class ProjectClasspathArtifactResolver { IOUtil.close( r ); } - + Set artifacts = createArtifacts( model.getDependencies(), artifact.getScope() ); - + List artifactRepositories; try { - artifactRepositories = ProjectUtils.buildArtifactRepositories( model.getRepositories(), repositoryFactory, container ); + artifactRepositories = ProjectUtils.buildArtifactRepositories( model.getRepositories(), + repositoryFactory, container ); } catch ( ProjectBuildingException e ) { throw new ArtifactMetadataRetrievalException( e ); } - + return new ResolutionGroup( artifacts, artifactRepositories ); } @@ -125,8 +132,10 @@ public class ProjectClasspathArtifactResolver { Dependency d = (Dependency) i.next(); - Artifact artifact = artifactFactory.createArtifact( d.getGroupId(), d.getArtifactId(), d.getVersion(), - d.getScope(), d.getType(), inheritedScope ); + Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(), + new VersionRange( d.getVersion() ), + d.getType(), d.getScope(), + inheritedScope ); if ( artifact != null ) { projectArtifacts.add( artifact ); @@ -136,7 +145,7 @@ public class ProjectClasspathArtifactResolver return projectArtifacts; } } - + public void resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository ) throws ArtifactResolutionException {