refactoring of the resolveTransitiveDependencies call.

simplified by removing a bunch of duplicated code in addArtifacts - no need to merge, you have the full list. 
separated the original artifacts (dependency artifacts) from the resolved artifacts (getArtifacts)


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@191667 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-06-21 15:32:02 +00:00
parent 4ce86c9b87
commit 6cd2e31078
27 changed files with 273 additions and 225 deletions

View File

@ -92,8 +92,12 @@ public class DependenciesTask
ArtifactResolutionResult result;
try
{
Artifact pomArtifact = artifactFactory.createArtifact( pom.getGroupId(), pom.getArtifactId(),
pom.getVersion(), null, pom.getPackaging() );
List remoteArtifactRepositories = createRemoteArtifactRepositories( getRemoteRepositories() );
result = resolver.resolveTransitively( artifacts, remoteArtifactRepositories, localRepo, metadataSource );
result = resolver.resolveTransitively( artifacts, pomArtifact, remoteArtifactRepositories, localRepo,
metadataSource );
}
catch ( ArtifactResolutionException e )
{

View File

@ -130,19 +130,32 @@ public class DefaultArtifactResolver
}
}
// ----------------------------------------------------------------------
// Transitive modes
// ----------------------------------------------------------------------
public ArtifactResolutionResult resolveTransitively( Set artifacts, List remoteRepositories,
public ArtifactResolutionResult resolveTransitively( Artifact artifact, List remoteRepositories,
ArtifactRepository localRepository,
ArtifactMetadataSource source )
throws ArtifactResolutionException
{
return resolveTransitively( artifact, remoteRepositories, localRepository, source, null );
}
public ArtifactResolutionResult resolveTransitively( Artifact artifact, List remoteRepositories,
ArtifactRepository localRepository,
ArtifactMetadataSource source, ArtifactFilter filter )
throws ArtifactResolutionException
{
return resolveTransitively( Collections.singleton( artifact ), null, remoteRepositories, localRepository,
source, filter );
}
public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
List remoteRepositories, ArtifactRepository localRepository,
ArtifactMetadataSource source, ArtifactFilter filter )
throws ArtifactResolutionException
{
ArtifactResolutionResult artifactResolutionResult;
artifactResolutionResult = artifactCollector.collect( artifacts, localRepository, remoteRepositories, source,
filter, artifactFactory );
artifactResolutionResult = artifactCollector.collect( artifacts, originatingArtifact, localRepository,
remoteRepositories, source, filter, artifactFactory );
for ( Iterator i = artifactResolutionResult.getArtifacts().values().iterator(); i.hasNext(); )
{
@ -153,19 +166,12 @@ public class DefaultArtifactResolver
return artifactResolutionResult;
}
public ArtifactResolutionResult resolveTransitively( Set artifacts, List remoteRepositories,
ArtifactRepository localRepository,
public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
List remoteRepositories, ArtifactRepository localRepository,
ArtifactMetadataSource source )
throws ArtifactResolutionException
{
return resolveTransitively( artifacts, remoteRepositories, localRepository, source, null );
return resolveTransitively( artifacts, originatingArtifact, remoteRepositories, localRepository, source, null );
}
public ArtifactResolutionResult resolveTransitively( Artifact artifact, List remoteRepositories,
ArtifactRepository localRepository,
ArtifactMetadataSource source )
throws ArtifactResolutionException
{
return resolveTransitively( Collections.singleton( artifact ), remoteRepositories, localRepository, source );
}
}

View File

@ -22,6 +22,7 @@ import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@ -41,12 +42,16 @@ public class ArtifactResolverTest
{
private ArtifactResolver artifactResolver;
private Artifact projectArtifact;
protected void setUp()
throws Exception
{
super.setUp();
artifactResolver = (ArtifactResolver) lookup( ArtifactResolver.ROLE );
projectArtifact = createLocalArtifact( "project", "3.0" );
}
protected String component()
@ -103,7 +108,8 @@ public class ArtifactResolverTest
}
};
ArtifactResolutionResult result = artifactResolver.resolveTransitively( g, remoteRepositories(),
ArtifactResolutionResult result = artifactResolver.resolveTransitively( Collections.singleton( g ),
projectArtifact, remoteRepositories(),
localRepository(), mds );
assertEquals( 2, result.getArtifacts().size() );
@ -141,7 +147,8 @@ public class ArtifactResolverTest
}
};
ArtifactResolutionResult result = artifactResolver.resolveTransitively( i, remoteRepositories(),
ArtifactResolutionResult result = artifactResolver.resolveTransitively( Collections.singleton( i ),
projectArtifact, remoteRepositories(),
localRepository(), mds );
assertEquals( 2, result.getArtifacts().size() );

View File

@ -1,19 +1,22 @@
package org.apache.maven.artifact.resolver;/*
* 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.
*/
package org.apache.maven.artifact.resolver;
/*
* 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.
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
@ -23,15 +26,16 @@ import java.util.List;
import java.util.Set;
/**
* TODO: describe
* Artifact collector - takes a set of original artifacts and resolves all of the best versions to use
* along with their metadata. No artifacts are downloaded.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
public interface ArtifactCollector
{
ArtifactResolutionResult collect( Set artifacts, ArtifactRepository localRepository, List remoteRepositories,
ArtifactMetadataSource source, ArtifactFilter filter,
ArtifactResolutionResult collect( Set artifacts, Artifact originatingArtifact, ArtifactRepository localRepository,
List remoteRepositories, ArtifactMetadataSource source, ArtifactFilter filter,
ArtifactFactory artifactFactory )
throws ArtifactResolutionException;
}

View File

@ -43,11 +43,16 @@ public interface ArtifactResolver
ArtifactRepository localRepository, ArtifactMetadataSource source )
throws ArtifactResolutionException;
ArtifactResolutionResult resolveTransitively( Set artifacts, List remoteRepositories,
ArtifactResolutionResult resolveTransitively( Artifact artifact, List remoteRepositories,
ArtifactRepository localRepository, ArtifactMetadataSource source,
ArtifactFilter filter )
throws ArtifactResolutionException;
ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact, List remoteRepositories,
ArtifactRepository localRepository, ArtifactMetadataSource source )
throws ArtifactResolutionException;
ArtifactResolutionResult resolveTransitively( Set artifacts, List remoteRepositories,
ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact, List remoteRepositories,
ArtifactRepository localRepository, ArtifactMetadataSource source,
ArtifactFilter filter )
throws ArtifactResolutionException;

View File

@ -31,7 +31,7 @@ import java.util.Map;
import java.util.Set;
/**
* TODO: describe
* Default implementation of the artifact collector.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
@ -39,7 +39,8 @@ import java.util.Set;
public class DefaultArtifactCollector
implements ArtifactCollector
{
public ArtifactResolutionResult collect( Set artifacts, ArtifactRepository localRepository, List remoteRepositories,
public ArtifactResolutionResult collect( Set artifacts, Artifact originatingArtifact,
ArtifactRepository localRepository, List remoteRepositories,
ArtifactMetadataSource source, ArtifactFilter filter,
ArtifactFactory artifactFactory )
throws ArtifactResolutionException
@ -91,12 +92,10 @@ public class DefaultArtifactCollector
if ( updateScope )
{
// TODO: Artifact factory?
// TODO: [jc] Is this a better way to centralize artifact construction here?
Artifact artifact = artifactFactory.createArtifact(
knownArtifact.getGroupId(), knownArtifact.getArtifactId(), knownVersion,
newArtifact.getScope(), knownArtifact.getType() );
Artifact artifact = artifactFactory.createArtifact( knownArtifact.getGroupId(),
knownArtifact.getArtifactId(), knownVersion,
newArtifact.getScope(),
knownArtifact.getType() );
resolvedArtifacts.put( artifact.getDependencyConflictId(), artifact );
}
}

View File

@ -0,0 +1,48 @@
package org.apache.maven.artifact.resolver;
/*
* 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.
*/
import junit.framework.TestCase;
/**
* Test the default artifact collector.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
public class DefaultArtifactCollectorTest
extends TestCase
{
private ArtifactCollector artifactCollector;
protected void setUp()
throws Exception
{
super.setUp();
this.artifactCollector = new DefaultArtifactCollector();
}
public void testCircularDependencyNotIncludingCurrentProject()
{
}
public void testCircularDependencyIncludingCurrentProject()
{
}
}

View File

@ -90,11 +90,6 @@ public class MavenSession
return localRepository;
}
public List getRemoteRepositories()
{
return project.getRemoteArtifactRepositories();
}
public List getGoals()
{
return goals;

View File

@ -173,7 +173,7 @@ public class DefaultPluginManager
}
public PluginDescriptor verifyPlugin( String groupId, String artifactId, String version, MavenProject project,
Settings settings, ArtifactRepository localRepository )
Settings settings, ArtifactRepository localRepository )
throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException
{
String pluginKey = groupId + ":" + artifactId;
@ -222,14 +222,15 @@ public class DefaultPluginManager
catch ( PlexusContainerException e )
{
throw new PluginManagerException(
"Error occurred in the artifact container attempting to download plugin "
+ groupId + ":" + artifactId, e );
"Error occurred in the artifact container attempting to download plugin " + groupId + ":" +
artifactId, e );
}
catch ( ArtifactResolutionException e )
{
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 );
}
@ -240,8 +241,8 @@ public class DefaultPluginManager
}
catch ( ComponentLookupException e )
{
throw new PluginManagerException( "Internal configuration error while retrieving " + groupId + ":"
+ artifactId, e );
throw new PluginManagerException(
"Internal configuration error while retrieving " + groupId + ":" + artifactId, e );
}
finally
{
@ -256,7 +257,7 @@ public class DefaultPluginManager
}
protected void addPlugin( String pluginKey, Artifact pluginArtifact, MavenProject project,
ArtifactRepository localRepository )
ArtifactRepository localRepository )
throws ArtifactResolutionException, ComponentLookupException, PlexusContainerException
{
ArtifactResolver artifactResolver = null;
@ -277,7 +278,7 @@ public class DefaultPluginManager
addedPlugin.setClassRealm( child.getContainerRealm() );
// we're only setting the plugin's artifact itself as the artifact list, to allow it to be retrieved
// later when the plugin is first invoked. Retrieving this artifact will in turn allow us to
// later when the plugin is first invoked. Retrieving this artifact will in turn allow us to
// transitively resolve its dependencies, and add them to the plugin container...
addedPlugin.setArtifacts( Collections.singletonList( pluginArtifact ) );
}
@ -425,7 +426,7 @@ public class DefaultPluginManager
}
public List getReports( String groupId, String artifactId, String version, ReportSet reportSet,
MavenSession session, MavenProject project )
MavenSession session, MavenProject project )
throws PluginManagerException, PluginVersionResolutionException, PluginConfigurationException
{
PluginDescriptor pluginDescriptor = getPluginDescriptor( groupId, artifactId, version );
@ -478,14 +479,14 @@ public class DefaultPluginManager
}
private Mojo getConfiguredMojo( MojoDescriptor mojoDescriptor, MavenSession session, Xpp3Dom dom,
MavenProject project )
MavenProject project )
throws ComponentLookupException, PluginConfigurationException, PluginManagerException
{
PlexusContainer pluginContainer = getPluginContainer( mojoDescriptor.getPluginDescriptor() );
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
// if this is the first time this plugin has been used, the plugin's container will only
// if this is the first time this plugin has been used, the plugin's container will only
// contain the plugin's artifact in isolation; we need to finish resolving the plugin's
// dependencies, and add them to the container.
ensurePluginContainerIsComplete( pluginDescriptor, pluginContainer, project, session );
@ -519,11 +520,13 @@ public class DefaultPluginManager
pathTranslator, getLogger(),
project );
PlexusConfiguration extractedMojoConfiguration = extractMojoConfiguration( mergedConfiguration, mojoDescriptor );
PlexusConfiguration extractedMojoConfiguration = extractMojoConfiguration( mergedConfiguration,
mojoDescriptor );
checkRequiredParameters( mojoDescriptor, extractedMojoConfiguration, expressionEvaluator, plugin );
populatePluginFields( plugin, mojoDescriptor, extractedMojoConfiguration, pluginContainer, expressionEvaluator );
populatePluginFields( plugin, mojoDescriptor, extractedMojoConfiguration, pluginContainer,
expressionEvaluator );
return plugin;
}
@ -551,10 +554,12 @@ public class DefaultPluginManager
MavenMetadataSource metadataSource = new MavenMetadataSource( artifactResolver, mavenProjectBuilder,
artifactFactory );
ArtifactResolutionResult result = artifactResolver.resolveTransitively( Collections
.singleton( pluginArtifact ), project.getRemoteArtifactRepositories(),
List remoteArtifactRepositories = project.getRemoteArtifactRepositories();
ArtifactResolutionResult result = artifactResolver.resolveTransitively( pluginArtifact,
remoteArtifactRepositories,
session.getLocalRepository(),
metadataSource, artifactFilter );
metadataSource,
artifactFilter );
Map resolved = result.getArtifacts();
@ -577,9 +582,8 @@ public class DefaultPluginManager
ArtifactFilter distroProvidedFilter = new InversionArtifactFilter( artifactFilter );
ArtifactResolutionResult distroProvidedResult = artifactResolver
.resolveTransitively( Collections.singleton( pluginArtifact ), project
.getRemoteArtifactRepositories(), session.getLocalRepository(), metadataSource,
distroProvidedFilter );
.resolveTransitively( pluginArtifact, remoteArtifactRepositories, session.getLocalRepository(),
metadataSource, distroProvidedFilter );
Map distroProvided = distroProvidedResult.getArtifacts();
@ -617,7 +621,7 @@ public class DefaultPluginManager
}
private PlexusConfiguration extractMojoConfiguration( PlexusConfiguration mergedConfiguration,
MojoDescriptor mojoDescriptor )
MojoDescriptor mojoDescriptor )
{
Map parameterMap = mojoDescriptor.getParameterMap();
@ -638,8 +642,8 @@ public class DefaultPluginManager
// TODO: I defy anyone to find these messages in the '-X' output! Do we need a new log level?
// ideally, this would be elevated above the true debug output, but below the default INFO level...
getLogger().debug(
"*** WARNING: Configuration \'" + child.getName() + "\' is not used in goal \'"
+ mojoDescriptor.getFullGoalName() + "; this may indicate a typo... ***" );
"*** WARNING: Configuration \'" + child.getName() + "\' is not used in goal \'" +
mojoDescriptor.getFullGoalName() + "; this may indicate a typo... ***" );
}
}
@ -647,7 +651,7 @@ public class DefaultPluginManager
}
private void checkRequiredParameters( MojoDescriptor goal, PlexusConfiguration configuration,
ExpressionEvaluator expressionEvaluator, Mojo plugin )
ExpressionEvaluator expressionEvaluator, Mojo plugin )
throws PluginConfigurationException
{
// TODO: this should be built in to the configurator, as we presently double process the expressions
@ -720,8 +724,8 @@ public class DefaultPluginManager
if ( fieldValue != null )
{
getLogger().warn(
"DEPRECATED: using default-value to set the default value of field '"
+ parameter.getName() + "'" );
"DEPRECATED: using default-value to set the default value of field '" +
parameter.getName() + "'" );
}
}
catch ( NoSuchFieldException e )
@ -837,7 +841,7 @@ public class DefaultPluginManager
// ----------------------------------------------------------------------
private void populatePluginFields( Mojo plugin, MojoDescriptor mojoDescriptor, PlexusConfiguration configuration,
PlexusContainer pluginContainer, ExpressionEvaluator expressionEvaluator )
PlexusContainer pluginContainer, ExpressionEvaluator expressionEvaluator )
throws PluginConfigurationException
{
ComponentConfigurator configurator = null;
@ -869,8 +873,7 @@ public class DefaultPluginManager
catch ( ComponentLookupException e )
{
throw new PluginConfigurationException(
"Unable to retrieve component configurator for plugin configuration",
e );
"Unable to retrieve component configurator for plugin configuration", e );
}
finally
{
@ -910,7 +913,7 @@ public class DefaultPluginManager
}
public static String createPluginParameterRequiredMessage( MojoDescriptor mojo, Parameter parameter,
String expression )
String expression )
{
StringBuffer message = new StringBuffer();
@ -966,25 +969,27 @@ public class DefaultPluginManager
public void initialize()
{
// TODO: configure this from bootstrap or scan lib
Set artifacts = new HashSet();
artifacts.add( "classworlds" );
artifacts.add( "maven-artifact" );
artifacts.add( "maven-artifact-manager" );
artifacts.add( "maven-core" );
artifacts.add( "maven-model" );
artifacts.add( "maven-monitor" );
artifacts.add( "maven-plugin-api" );
artifacts.add( "maven-plugin-descriptor" );
artifacts.add( "maven-project" );
artifacts.add( "maven-settings" );
artifacts.add( "plexus-container-default" );
artifacts.add( "plexus-utils" );
artifacts.add( "wagon-provider-api" );
artifacts.add( "wagon-ssh" );
artifacts.add( "wagon-http-lightweight" );
artifacts.add( "wagon-file" );
// TODO: remove doxia
artifactFilter = new ExclusionSetFilter( new String[] {
"classworlds",
"maven-artifact",
"maven-core",
"maven-model",
"maven-monitor",
"maven-plugin-api",
"maven-plugin-descriptor",
"maven-project",
"maven-settings",
"plexus-container-default",
"plexus-utils",
"wagon-provider-api",
"wagon-ssh",
"wagon-http-lightweight",
"wagon-file",
"doxia-core",
"maven-reporting-api" } );
artifacts.add( "doxia-core" );
artifacts.add( "maven-reporting-api" );
artifactFilter = new ExclusionSetFilter( artifacts );
}
// ----------------------------------------------------------------------
@ -992,8 +997,8 @@ public class DefaultPluginManager
// ----------------------------------------------------------------------
private void resolveTransitiveDependencies( MavenSession context, ArtifactResolver artifactResolver,
MavenProjectBuilder mavenProjectBuilder, String scope,
ArtifactFactory artifactFactory, MavenProject project )
MavenProjectBuilder mavenProjectBuilder, String scope,
ArtifactFactory artifactFactory, MavenProject project )
throws ArtifactResolutionException
{
MavenMetadataSource sourceReader = new MavenMetadataSource( artifactResolver, mavenProjectBuilder,
@ -1003,10 +1008,19 @@ public class DefaultPluginManager
boolean systemOnline = !context.getSettings().isOffline();
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getArtifacts(), context
.getRemoteRepositories(), context.getLocalRepository(), sourceReader, filter );
// 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() );
project.addArtifacts( result.getArtifacts().values(), artifactFactory );
// 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.
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getDependencyArtifacts(),
artifact,
project.getRemoteArtifactRepositories(),
context.getLocalRepository(),
sourceReader, filter );
project.setArtifacts( new HashSet( result.getArtifacts().values() ) );
}
// ----------------------------------------------------------------------
@ -1016,27 +1030,26 @@ public class DefaultPluginManager
private void downloadDependencies( MavenProject project, MavenSession context, ArtifactResolver artifactResolver )
throws ArtifactResolutionException
{
ArtifactRepository localRepository = context.getLocalRepository();
List remoteArtifactRepositories = project.getRemoteArtifactRepositories();
for ( Iterator it = project.getArtifacts().iterator(); it.hasNext(); )
{
Artifact artifact = (Artifact) it.next();
// TODO: should I get the modified artifacts back into the project?
artifactResolver.resolve( artifact, context.getRemoteRepositories(), context.getLocalRepository() );
artifactResolver.resolve( artifact, remoteArtifactRepositories, localRepository );
}
Set pluginArtifacts = new HashSet();
// TODO: is this really necessary?
for ( Iterator it = project.getPluginArtifacts().iterator(); it.hasNext(); )
{
Artifact artifact = (Artifact) it.next();
artifactResolver.resolve( artifact, context.getRemoteRepositories(), context.getLocalRepository() );
pluginArtifacts.add( artifact );
artifactResolver.resolve( artifact, remoteArtifactRepositories, localRepository );
}
project.setPluginArtifacts( pluginArtifacts );
artifactResolver.resolve( project.getParentArtifact(), context.getRemoteRepositories(), context
.getLocalRepository() );
// TODO: is this really necessary?
artifactResolver.resolve( project.getParentArtifact(), remoteArtifactRepositories, localRepository );
}
}

View File

@ -13,7 +13,7 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>2.0-alpha-2</version>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>plexus</groupId>

View File

@ -14,12 +14,17 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.0-alpha-2</version>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>2.0-alpha-2</version>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact-manager</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@ -17,7 +17,7 @@
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact-test</artifactId>
<artifactId>maven-artifact-manager</artifactId>
<version>2.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>

View File

@ -17,11 +17,14 @@ package org.apache.maven.plugin.eclipse;
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
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.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.artifact.MavenMetadataSource;
import org.codehaus.plexus.PlexusTestCase;
import java.io.BufferedReader;
@ -72,7 +75,7 @@ public class EclipsePluginTest
ArtifactRepository localRepository = new DefaultArtifactRepository( "local", "file://" + repo.getAbsolutePath(),
localRepositoryLayout );
MavenProject project = builder.build( new File( basedir, "project.xml" ), localRepository, Collections.EMPTY_LIST );
MavenProject project = builder.buildWithDependencies( new File( basedir, "project.xml" ), localRepository, Collections.EMPTY_LIST );
for ( Iterator it = project.getArtifacts().iterator(); it.hasNext(); )
{

View File

@ -2,5 +2,5 @@
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="output" path="target/classes"/>
<classpathentry kind="var" rootpath="JRE_SRCROOT" path="JRE_LIB" sourcepath="JRE_SRC"/>
<classpathentry kind="var" path="M2_REPO/maven/jars/maven-core-2.0-SNAPSHOT.jar"/>
<classpathentry kind="var" path="M2_REPO/maven/jars/maven-core-98.0.jar"/>
</classpath>

View File

@ -11,7 +11,7 @@
<dependency>
<groupId>maven</groupId>
<artifactId>maven-core</artifactId>
<version>2.0-SNAPSHOT</version>
<version>98.0</version>
</dependency>
</dependencies>

View File

@ -2,5 +2,5 @@
<modelVersion>4.0.0</modelVersion>
<groupId>maven</groupId>
<artifactId>maven-core</artifactId>
<version>2.0-SNAPSHOT</version>
<version>98.0</version>
</project>

View File

@ -13,7 +13,7 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.0-alpha-2</version>
<version>2.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@ -14,12 +14,17 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.0-alpha-2</version>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>2.0-alpha-2</version>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact-manager</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@ -18,7 +18,7 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.0-alpha-2</version>
<version>2.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@ -13,7 +13,7 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>2.0-alpha-2</version>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>

View File

@ -33,12 +33,5 @@
<version>3.8.1</version>
<scope>runtime</scope>
</dependency>
<!-- TODO: would like to remove -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>2.0-alpha-2</version>
</dependency>
</dependencies>
</project>

View File

@ -124,11 +124,6 @@ public class SurefirePlugin
public void execute()
throws MojoExecutionException
{
if ( "pom".equals( project.getPackaging() ) )
{
return;
}
// ----------------------------------------------------------------------
// Setup the surefire booter
// ----------------------------------------------------------------------

View File

@ -114,6 +114,14 @@ public class DefaultMavenProjectBuilder
// MavenProjectBuilder Implementation
// ----------------------------------------------------------------------
public MavenProject buildWithDependencies( File projectDescriptor, ArtifactRepository localRepository,
List externalProfiles )
throws ProjectBuildingException, ArtifactResolutionException
{
ArtifactMetadataSource source = new MavenMetadataSource( artifactResolver, this, artifactFactory );
return buildWithDependencies( projectDescriptor, localRepository, source, externalProfiles );
}
public MavenProject buildWithDependencies( File projectDescriptor, ArtifactRepository localRepository,
ArtifactMetadataSource artifactMetadataSource, List externalProfiles )
throws ProjectBuildingException, ArtifactResolutionException
@ -132,12 +140,17 @@ public class DefaultMavenProjectBuilder
// this snippet of code here.
// ----------------------------------------------------------------------
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getArtifacts(),
// 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() );
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getDependencyArtifacts(),
artifact,
project.getRemoteArtifactRepositories(),
localRepository,
artifactMetadataSource );
project.addArtifacts( result.getArtifacts().values(), artifactFactory );
project.setArtifacts( new HashSet( result.getArtifacts().values() ) );
return project;
}
@ -248,10 +261,10 @@ public class DefaultMavenProjectBuilder
}
MavenProject project = assembleLineage( model, lineage, aggregatedRemoteWagonRepositories, localRepository );
// we don't have to force the collision exception for superModel here, it's already been done in getSuperModel()
Model previous = superModel;
for ( Iterator i = lineage.iterator(); i.hasNext(); )
{
Model current = ( (MavenProject) i.next() ).getModel();
@ -278,24 +291,24 @@ public class DefaultMavenProjectBuilder
private void forcePluginExecutionIdCollision( Model model )
{
Build build = model.getBuild();
if ( build != null )
{
List plugins = build.getPlugins();
if ( plugins != null )
{
for ( Iterator it = plugins.iterator(); it.hasNext(); )
{
Plugin plugin = (Plugin) it.next();
// this will force an IllegalStateException, even if we don't have to do inheritance assembly.
plugin.getExecutionsAsMap();
}
}
}
}
/**
* @todo can this take in a model instead of a project and still be successful?
@ -370,7 +383,7 @@ public class DefaultMavenProjectBuilder
}
project.setRemoteArtifactRepositories( remoteRepositories );
project.setArtifacts( createArtifacts( project.getDependencies() ) );
project.setDependencyArtifacts( createArtifacts( project.getDependencies() ) );
project.setPluginArtifacts( createPluginArtifacts( project.getBuildPlugins() ) );
ModelValidationResult validationResult = validator.validate( model );
@ -586,7 +599,7 @@ public class DefaultMavenProjectBuilder
URL url = DefaultMavenProjectBuilder.class.getResource( "pom-" + MAVEN_MODEL_VERSION + ".xml" );
Model superModel = readModel( url );
forcePluginExecutionIdCollision( superModel );
return superModel;

View File

@ -18,7 +18,6 @@ package org.apache.maven.project;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Build;
import org.apache.maven.model.CiManagement;
@ -47,13 +46,9 @@ import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
@ -106,6 +101,8 @@ public class MavenProject
private List activeProfiles = new ArrayList();
private Set dependencyArtifacts;
public MavenProject( Model model )
{
this.model = model;
@ -119,7 +116,11 @@ public class MavenProject
this.file = project.file;
// don't need a deep copy, they don't get modified or added/removed to/from - but make them unmodifiable to be sure!
this.artifacts = Collections.unmodifiableSet( project.artifacts );
this.dependencyArtifacts = Collections.unmodifiableSet( project.dependencyArtifacts );
if ( project.artifacts != null )
{
this.artifacts = Collections.unmodifiableSet( project.artifacts );
}
this.pluginArtifacts = Collections.unmodifiableSet( project.pluginArtifacts );
this.remoteArtifactRepositories = Collections.unmodifiableList( project.remoteArtifactRepositories );
this.pluginArtifactRepositories = Collections.unmodifiableList( project.pluginArtifactRepositories );
@ -805,59 +806,6 @@ public class MavenProject
this.collectedProjects = collectedProjects;
}
public void addArtifacts( Collection newArtifacts, ArtifactFactory artifactFactory )
{
// project.getArtifacts().addAll( result.getArtifacts().values() );
// We need to override the scope if one declared it higher
// TODO: could surely be more efficient, and use the scope handler, be part of maven-artifact...
Map artifacts = new HashMap();
for ( Iterator i = getArtifacts().iterator(); i.hasNext(); )
{
Artifact a = (Artifact) i.next();
artifacts.put( a.getId(), a );
}
for ( Iterator i = newArtifacts.iterator(); i.hasNext(); )
{
Artifact a = (Artifact) i.next();
String id = a.getId();
if ( artifacts.containsKey( id ) )
{
Artifact existing = (Artifact) artifacts.get( id );
boolean updateScope = false;
if ( Artifact.SCOPE_RUNTIME.equals( a.getScope() ) &&
Artifact.SCOPE_TEST.equals( existing.getScope() ) )
{
updateScope = true;
}
if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) &&
!Artifact.SCOPE_COMPILE.equals( existing.getScope() ) )
{
updateScope = true;
}
if ( updateScope )
{
// TODO: Artifact factory?
// TODO: [jc] Is this a better way to centralize artifact construction here?
Artifact artifact = artifactFactory.createArtifact( existing.getGroupId(), existing.getArtifactId(),
existing.getVersion(), a.getScope(), existing
.getType() );
artifact.setFile( existing.getFile() );
artifact.setBaseVersion( existing.getBaseVersion() );
artifacts.put( id, artifact );
}
}
else
{
artifacts.put( id, a );
}
}
setArtifacts( new HashSet( artifacts.values() ) );
}
public void setPluginArtifactRepositories( List pluginArtifactRepositories )
{
this.pluginArtifactRepositories = pluginArtifactRepositories;
@ -1044,4 +992,14 @@ public class MavenProject
pomWriter.write( writer, getModel() );
}
public Set getDependencyArtifacts()
{
return dependencyArtifacts;
}
public void setDependencyArtifacts( Set dependencyArtifacts )
{
this.dependencyArtifacts = dependencyArtifacts;
}
}

View File

@ -41,6 +41,9 @@ public interface MavenProjectBuilder
ArtifactMetadataSource artifactMetadataSource, List externalProfiles )
throws ProjectBuildingException, ArtifactResolutionException;
MavenProject buildWithDependencies( File project, ArtifactRepository localRepository, List externalProfiles )
throws ProjectBuildingException, ArtifactResolutionException;
/**
* Build the artifact from the local repository, resolving it if necessary.
*

View File

@ -106,30 +106,22 @@ public class ProjectClasspathArtifactResolver
artifact.setFile( new File( "dummy" ) );
}
public ArtifactResolutionResult resolveTransitively( Set artifacts, List remoteRepositories,
ArtifactRepository localRepository,
public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
List remoteRepositories, ArtifactRepository localRepository,
ArtifactMetadataSource source, ArtifactFilter filter )
throws ArtifactResolutionException
{
return super.resolveTransitively( artifacts, remoteRepositories, localRepository, new Source( artifactFactory ),
filter );
return super.resolveTransitively( artifacts, originatingArtifact, remoteRepositories, localRepository,
new Source( artifactFactory ), filter );
}
public ArtifactResolutionResult resolveTransitively( Set artifacts, List remoteRepositories,
ArtifactRepository localRepository,
public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
List remoteRepositories, ArtifactRepository localRepository,
ArtifactMetadataSource source )
throws ArtifactResolutionException
{
return super.resolveTransitively( artifacts, remoteRepositories, localRepository,
return super.resolveTransitively( artifacts, originatingArtifact, remoteRepositories, localRepository,
new Source( artifactFactory ) );
}
public ArtifactResolutionResult resolveTransitively( Artifact artifact, List remoteRepositories,
ArtifactRepository localRepository,
ArtifactMetadataSource source )
throws ArtifactResolutionException
{
return super.resolveTransitively( artifact, remoteRepositories, localRepository,
new Source( artifactFactory ) );
}
}