You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by jd...@apache.org on 2005/07/23 00:07:54 UTC
svn commit: r224413 - in /maven/components/trunk:
maven-artifact/src/main/java/org/apache/maven/artifact/
maven-core/src/main/java/org/apache/maven/
maven-core/src/main/java/org/apache/maven/execution/
maven-core/src/main/java/org/apache/maven/plugin/ ...
Author: jdcasey
Date: Fri Jul 22 15:07:28 2005
New Revision: 224413
URL: http://svn.apache.org/viewcvs?rev=224413&view=rev
Log:
Working on MNG-607
o Changed MavenMetadataSource to a component, to avoid having to lookup artifactFactory and projectBuilder in order to
construct it.
o Added add(..) method to ScmBean in the release plugin to allow addition of release-pom.xml
o Changed the PrepareReleaseMojo to resolve ONLY version and parent-version for the normal pom.xml, and fully resolve all
artifacts used in the release-pom.xml, including version, parent-version, dependency closure (given by project.getArtifacts()), plugins, and reports. It will then add the release-pom.xml, and (attempt to) delete it before performing the final commit for next development version.
o Added some mapping methods to ArtifactUtils, to key by artifact.getId, and to create an Artifact.getId()-compatible string from parameters.
o Added TestProjectBuilder to remove the requirement in ProjectClasspathTest to modify the fields of the project builder directly.
o Cleaned up the AbstractReleaseMojo and PrepareReleaseMojo to avoid container lookups...they're now mojo parameters with the 'component.' prefix.
NOTE: Next step is to figure out how to use maven-scm to remove an SCM resource, to enable the prepare mojo to take the release-pom.xml back out of HEAD after the tag is complete.
Added:
maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/TestProjectBuilder.java (with props)
Modified:
maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java
maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java
maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java
maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java
maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionManager.java
maven/components/trunk/maven-core/src/main/resources/META-INF/plexus/components.xml
maven/components/trunk/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java
maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java
maven/components/trunk/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugin/release/AbstractReleaseMojo.java
maven/components/trunk/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugin/release/PrepareReleaseMojo.java
maven/components/trunk/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugin/scm/ScmBean.java
maven/components/trunk/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuilder.java
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
maven/components/trunk/maven-project/src/main/resources/META-INF/plexus/components.xml
maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/MavenProjectTestCase.java
maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/ProjectClasspathTest.java
maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/TestArtifactResolver.java
maven/components/trunk/maven-project/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml
Modified: maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java?rev=224413&r1=224412&r2=224413&view=diff
==============================================================================
--- maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java (original)
+++ maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java Fri Jul 22 15:07:28 2005
@@ -3,7 +3,6 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
public final class ArtifactUtils
@@ -23,7 +22,17 @@
return groupId + ":" + artifactId;
}
- public static Map artifactMap( Collection artifacts )
+ public static String artifactId( String groupId, String artifactId, String type, String version )
+ {
+ return artifactId( groupId, artifactId, type, version, null, version );
+ }
+
+ public static String artifactId( String groupId, String artifactId, String type, String version, String classifier, String baseVersion )
+ {
+ return groupId + ":" + artifactId + ":" + type + ( ( classifier != null ) ? ( ":" + classifier ) : ( "" ) ) + ":" + baseVersion;
+ }
+
+ public static Map artifactMapByVersionlessId( Collection artifacts )
{
Map artifactMap = new HashMap();
@@ -32,6 +41,20 @@
Artifact artifact = (Artifact) it.next();
artifactMap.put( versionlessKey( artifact ), artifact );
+ }
+
+ return artifactMap;
+ }
+
+ public static Map artifactMapByArtifactId( Collection artifacts )
+ {
+ Map artifactMap = new HashMap();
+
+ for ( Iterator it = artifacts.iterator(); it.hasNext(); )
+ {
+ Artifact artifact = (Artifact) it.next();
+
+ artifactMap.put( artifact.getId(), artifact );
}
return artifactMap;
Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java?rev=224413&r1=224412&r2=224413&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java (original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java Fri Jul 22 15:07:28 2005
@@ -177,6 +177,10 @@
try
{
+ MavenSession session = createSession( request, projects );
+
+ List goals = request.getGoals();
+
for ( Iterator iterator = projects.iterator(); iterator.hasNext(); )
{
MavenProject project = (MavenProject) iterator.next();
@@ -189,7 +193,7 @@
try
{
- MavenExecutionResponse response = processProject( request, project, dispatcher );
+ MavenExecutionResponse response = processProject( session, goals, project, dispatcher );
if ( response.isExecutionFailure() )
{
dispatcher.dispatchError( event, request.getBaseDirectory(), response.getException() );
@@ -262,14 +266,10 @@
return projects;
}
- private MavenExecutionResponse processProject( MavenExecutionRequest request, MavenProject project,
+ private MavenExecutionResponse processProject( MavenSession session, List goals, MavenProject project,
EventDispatcher dispatcher )
throws LifecycleExecutionException
{
- List goals = request.getGoals();
-
- MavenSession session = createSession( request, project );
-
// !! This is ripe for refactoring to an aspect.
// Event monitoring.
String event = MavenEvents.PROJECT_EXECUTION;
@@ -412,10 +412,10 @@
// the session type would be specific to the request i.e. having a project
// or not.
- protected MavenSession createSession( MavenExecutionRequest request, MavenProject project )
+ protected MavenSession createSession( MavenExecutionRequest request, List projects )
{
- return new MavenSession( project, container, request.getSettings(), request.getLocalRepository(),
- request.getEventDispatcher(), request.getGoals() );
+ return new MavenSession( container, request.getSettings(), request.getLocalRepository(),
+ request.getEventDispatcher(), projects, request.getGoals(), request.getBaseDirectory() );
}
/**
Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java?rev=224413&r1=224412&r2=224413&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java (original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java Fri Jul 22 15:07:28 2005
@@ -19,11 +19,9 @@
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.plugin.mapping.PluginMappingManager;
-import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
-import org.codehaus.plexus.context.Context;
import java.util.List;
import java.util.Map;
@@ -36,8 +34,6 @@
{
private PlexusContainer container;
- private MavenProject project;
-
private ArtifactRepository localRepository;
private List goals;
@@ -49,11 +45,14 @@
// TODO: make this the central one, get rid of build settings...
private final Settings settings;
- public MavenSession( MavenProject project, PlexusContainer container, Settings settings,
- ArtifactRepository localRepository, EventDispatcher eventDispatcher, List goals )
- {
- this.project = project;
+ private List sortedProjects;
+ private final String executionRootDir;
+
+ public MavenSession( PlexusContainer container, Settings settings,
+ ArtifactRepository localRepository, EventDispatcher eventDispatcher, List sortedProjects,
+ List goals, String executionRootDir )
+ {
this.container = container;
this.settings = settings;
@@ -61,26 +60,12 @@
this.localRepository = localRepository;
this.eventDispatcher = eventDispatcher;
-
- this.goals = goals;
- // TODO: Go back to this when we get the container ready to configure mojos...
- // NOTE: [jc] This is a possible way to add project, etc. to the container context to allow container-injected
- // mojo configuration.
-// initializeContainerContext();
- }
-
- private void initializeContainerContext()
- {
- Context context = container.getContext();
+ this.sortedProjects = sortedProjects;
- context.put( "project", project );
- context.put( "settings", settings );
- context.put( "basedir", project.getBasedir().getAbsolutePath() );
- context.put( "localRepository", localRepository );
+ this.goals = goals;
- // TODO: remove this alias...change to ${project.build.finalName}
- context.put( "maven.final.name", project.getBuild().getFinalName() );
+ this.executionRootDir = executionRootDir;
}
public PlexusContainer getContainer()
@@ -144,5 +129,15 @@
public PluginMappingManager getPluginMappingManager()
{
return pluginMappingManager;
+ }
+
+ public List getSortedProjects()
+ {
+ return sortedProjects;
+ }
+
+ public String getExecutionRootDirectory()
+ {
+ return executionRootDir;
}
}
Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java?rev=224413&r1=224412&r2=224413&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java (original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java Fri Jul 22 15:07:28 2005
@@ -17,6 +17,7 @@
*/
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
@@ -112,7 +113,7 @@
protected ArtifactResolver artifactResolver;
- protected ArtifactMetadataSource metadataSource;
+ protected ArtifactMetadataSource artifactMetadataSource;
protected MavenPluginMappingBuilder pluginMappingBuilder;
@@ -173,6 +174,15 @@
ArtifactRepository localRepository )
throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException
{
+ Artifact existingPluginArtifact = (Artifact) project.getPluginArtifactMap().get( plugin.getKey() );
+
+ return verifyPlugin( plugin, existingPluginArtifact, project, settings, localRepository );
+ }
+
+ private PluginDescriptor verifyPlugin( Plugin plugin, Artifact existingArtifact, MavenProject project, Settings settings,
+ ArtifactRepository localRepository )
+ throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException
+ {
// TODO: this should be possibly outside
// All version-resolution logic has been moved to DefaultPluginVersionManager.
if ( plugin.getVersion() == null )
@@ -189,6 +199,7 @@
{
VersionRange versionRange = VersionRange.createFromVersionSpec( plugin.getVersion() );
+
checkRequiredMavenVersion( plugin, localRepository, project.getPluginArtifactRepositories() );
Artifact pluginArtifact = artifactFactory.createPluginArtifact( plugin.getGroupId(),
@@ -382,17 +393,33 @@
}
}
- public List getReports( ReportPlugin reportPlugin, ReportSet reportSet, MavenProject project, MavenSession session,
- ArtifactRepository localRepository )
+ public List getReports( ReportPlugin reportPlugin, ReportSet reportSet, MavenProject project, MavenSession session )
throws PluginManagerException, PluginVersionResolutionException, PluginConfigurationException,
ArtifactResolutionException
{
Plugin forLookup = new Plugin();
- forLookup.setGroupId( reportPlugin.getGroupId() );
- forLookup.setArtifactId( reportPlugin.getArtifactId() );
- forLookup.setVersion( reportPlugin.getVersion() );
-
- PluginDescriptor pluginDescriptor = verifyPlugin( forLookup, project, session.getSettings(), localRepository );
+
+ String groupId = reportPlugin.getGroupId();
+ String artifactId = reportPlugin.getArtifactId();
+
+ forLookup.setGroupId( groupId );
+ forLookup.setArtifactId( artifactId );
+
+ String version = reportPlugin.getVersion();
+
+ Artifact existingPluginArtifact = (Artifact) project.getReportArtifactMap().get( reportPlugin.getKey() );
+
+ if ( existingPluginArtifact == null
+ || !reportPlugin.getKey().equals( ArtifactUtils.versionlessKey( existingPluginArtifact ) )
+ || version == null )
+ {
+ version = pluginVersionManager.resolvePluginVersion( groupId, artifactId, project, session.getSettings(), session.getLocalRepository(), true );
+ }
+
+ forLookup.setVersion( version );
+
+ PluginDescriptor pluginDescriptor = verifyPlugin( forLookup, existingPluginArtifact, project, session
+ .getSettings(), session.getLocalRepository() );
List reports = new ArrayList();
for ( Iterator i = pluginDescriptor.getMojos().iterator(); i.hasNext(); )
@@ -516,7 +543,7 @@
{
ArtifactRepository localRepository = session.getLocalRepository();
- ResolutionGroup resolutionGroup = metadataSource.retrieve( pluginArtifact, localRepository,
+ ResolutionGroup resolutionGroup = artifactMetadataSource.retrieve( pluginArtifact, localRepository,
project.getPluginArtifactRepositories() );
Set dependencies = resolutionGroup.getArtifacts();
@@ -524,7 +551,7 @@
ArtifactResolutionResult result = artifactResolver.resolveTransitively( dependencies, pluginArtifact,
localRepository,
resolutionGroup.getResolutionRepositories(),
- metadataSource,
+ artifactMetadataSource,
artifactFilter );
Set resolved = result.getArtifacts();
@@ -1015,7 +1042,7 @@
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getDependencyArtifacts(),
artifact, context.getLocalRepository(),
project.getRemoteArtifactRepositories(),
- metadataSource, filter );
+ artifactMetadataSource, filter );
project.setArtifacts( result.getArtifacts() );
}
Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java?rev=224413&r1=224412&r2=224413&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java (original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java Fri Jul 22 15:07:28 2005
@@ -51,8 +51,7 @@
ArtifactRepository localRepository )
throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException;
- List getReports( ReportPlugin reportPlugin, ReportSet reportSet, MavenProject project, MavenSession session,
- ArtifactRepository localRepository )
+ List getReports( ReportPlugin reportPlugin, ReportSet reportSet, MavenProject project, MavenSession session )
throws PluginManagerException, PluginVersionResolutionException, PluginConfigurationException,
ArtifactResolutionException;
Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java?rev=224413&r1=224412&r2=224413&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java (original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java Fri Jul 22 15:07:28 2005
@@ -21,7 +21,6 @@
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.artifact.transform.LatestArtifactTransformation;
import org.apache.maven.artifact.transform.ReleaseArtifactTransformation;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
@@ -61,17 +60,15 @@
{
private MavenPluginRegistryBuilder mavenPluginRegistryBuilder;
- private ArtifactResolver artifactResolver;
-
private ArtifactFactory artifactFactory;
private InputHandler inputHandler;
+ private ArtifactMetadataSource artifactMetadataSource;
+
// calculated.
private PluginRegistry pluginRegistry;
- private ArtifactMetadataSource metadataSource;
-
private MavenProjectBuilder mavenProjectBuilder;
private RuntimeInformation runtimeInformation;
@@ -80,8 +77,15 @@
ArtifactRepository localRepository )
throws PluginVersionResolutionException
{
+ return resolvePluginVersion( groupId, artifactId, project, settings, localRepository, false );
+ }
+
+ public String resolvePluginVersion( String groupId, String artifactId, MavenProject project, Settings settings,
+ ArtifactRepository localRepository, boolean resolveAsReportPlugin )
+ throws PluginVersionResolutionException
+ {
// first pass...if the plugin is specified in the pom, try to retrieve the version from there.
- String version = getVersionFromPluginConfig( groupId, artifactId, project );
+ String version = getVersionFromPluginConfig( groupId, artifactId, project, resolveAsReportPlugin );
// we're NEVER going to persist POM-derived plugin versions.
String updatedVersion = null;
@@ -474,33 +478,33 @@
return groupId + ":" + artifactId;
}
- private String getVersionFromPluginConfig( String groupId, String artifactId, MavenProject project )
+ private String getVersionFromPluginConfig( String groupId, String artifactId, MavenProject project, boolean resolveAsReportPlugin )
{
String version = null;
- for ( Iterator it = project.getBuildPlugins().iterator(); it.hasNext(); )
+ if ( resolveAsReportPlugin )
{
- Plugin plugin = (Plugin) it.next();
-
- if ( groupId.equals( plugin.getGroupId() ) && artifactId.equals( plugin.getArtifactId() ) )
+ for ( Iterator it = project.getReportPlugins().iterator(); it.hasNext(); )
{
- version = plugin.getVersion();
+ ReportPlugin plugin = (ReportPlugin) it.next();
+
+ if ( groupId.equals( plugin.getGroupId() ) && artifactId.equals( plugin.getArtifactId() ) )
+ {
+ version = plugin.getVersion();
- break;
+ break;
+ }
}
}
-
- // won't this overwrite the above loop if it exists in both places (unlikely, I know)??
- // maybe that's the idea...?
- if ( project.getReportPlugins() != null )
+ else
{
- for ( Iterator it = project.getReportPlugins().iterator(); it.hasNext(); )
+ for ( Iterator it = project.getBuildPlugins().iterator(); it.hasNext(); )
{
- ReportPlugin reportPlugin = (ReportPlugin) it.next();
+ Plugin plugin = (Plugin) it.next();
- if ( groupId.equals( reportPlugin.getGroupId() ) && artifactId.equals( reportPlugin.getArtifactId() ) )
+ if ( groupId.equals( plugin.getGroupId() ) && artifactId.equals( plugin.getArtifactId() ) )
{
- version = reportPlugin.getVersion();
+ version = plugin.getVersion();
break;
}
@@ -620,7 +624,7 @@
String version = null;
try
{
- metadataSource.retrieve( artifact, localRepository, remoteRepositories );
+ artifactMetadataSource.retrieve( artifact, localRepository, remoteRepositories );
MavenProject project = mavenProjectBuilder.buildFromRepository( artifact, remoteRepositories,
localRepository );
Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionManager.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionManager.java?rev=224413&r1=224412&r2=224413&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionManager.java (original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionManager.java Fri Jul 22 15:07:28 2005
@@ -28,4 +28,7 @@
String resolvePluginVersion( String groupId, String artifactId, MavenProject project, Settings settings, ArtifactRepository localRepository )
throws PluginVersionResolutionException;
+ String resolvePluginVersion( String groupId, String artifactId, MavenProject project, Settings settings, ArtifactRepository localRepository, boolean resolveAsReportPlugin )
+ throws PluginVersionResolutionException;
+
}
Modified: maven/components/trunk/maven-core/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/resources/META-INF/plexus/components.xml?rev=224413&r1=224412&r2=224413&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/resources/META-INF/plexus/components.xml (original)
+++ maven/components/trunk/maven-core/src/main/resources/META-INF/plexus/components.xml Fri Jul 22 15:07:28 2005
@@ -230,9 +230,6 @@
<role>org.apache.maven.plugin.registry.MavenPluginRegistryBuilder</role>
</requirement>
<requirement>
- <role>org.apache.maven.artifact.resolver.ArtifactResolver</role>
- </requirement>
- <requirement>
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
</requirement>
<requirement>
Modified: maven/components/trunk/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java?rev=224413&r1=224412&r2=224413&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java (original)
+++ maven/components/trunk/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java Fri Jul 22 15:07:28 2005
@@ -66,11 +66,11 @@
assertEquals( expected, actual );
}
- private static MavenSession createSession( MavenProject project, PlexusContainer container,
+ private static MavenSession createSession( PlexusContainer container,
ArtifactRepository repo )
{
- return new MavenSession( project, container, new Settings(), repo, new DefaultEventDispatcher(),
- Collections.EMPTY_LIST );
+ return new MavenSession( container, new Settings(), repo, new DefaultEventDispatcher(),
+ Collections.EMPTY_LIST, Collections.EMPTY_LIST, "." );
}
public void testLocalRepositoryExtraction()
@@ -137,7 +137,7 @@
ArtifactRepository repo = new DefaultArtifactRepository( "local", "target/repo", repoLayout );
PlexusContainer container = getContainer();
- MavenSession session = createSession( project, container, repo );
+ MavenSession session = createSession( container, repo );
return (ExpressionEvaluator) new PluginParameterExpressionEvaluator( session, pluginDescriptor, null,
container.getLogger(), project );
Modified: maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java?rev=224413&r1=224412&r2=224413&view=diff
==============================================================================
--- maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java (original)
+++ maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java Fri Jul 22 15:07:28 2005
@@ -223,7 +223,7 @@
{
if ( artifactMap == null )
{
- artifactMap = ArtifactUtils.artifactMap( getArtifacts() );
+ artifactMap = ArtifactUtils.artifactMapByVersionlessId( getArtifacts() );
}
return artifactMap;
Modified: maven/components/trunk/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugin/release/AbstractReleaseMojo.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugin/release/AbstractReleaseMojo.java?rev=224413&r1=224412&r2=224413&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugin/release/AbstractReleaseMojo.java (original)
+++ maven/components/trunk/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugin/release/AbstractReleaseMojo.java Fri Jul 22 15:07:28 2005
@@ -21,16 +21,11 @@
import org.apache.maven.plugin.scm.ScmBean;
import org.apache.maven.project.MavenProject;
import org.apache.maven.scm.manager.ScmManager;
-import org.codehaus.plexus.PlexusConstants;
-import org.codehaus.plexus.PlexusContainer;
-import org.codehaus.plexus.context.Context;
-import org.codehaus.plexus.context.ContextException;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
-import java.util.Properties;
+import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
-import java.io.File;
+import java.util.Properties;
/**
*
@@ -39,7 +34,6 @@
*/
public abstract class AbstractReleaseMojo
extends AbstractMojo
- implements Contextualizable
{
public static final String RELEASE_PROPS = "release.properties";
@@ -88,8 +82,11 @@
*/
protected MavenProject project;
- private PlexusContainer container;
-
+ /**
+ * @parameter expression="${org.apache.maven.scm.manager.ScmManager}"
+ * @required
+ * @readonly
+ */
protected ScmManager scmManager;
private Properties releaseProperties;
@@ -130,18 +127,11 @@
return scm;
}
- public PlexusContainer getContainer()
- {
- return container;
- }
-
public void execute()
throws MojoExecutionException
{
try
{
- initScmManager();
-
if ( username == null )
{
username = System.getProperty( "user.name" );
@@ -169,40 +159,10 @@
throw new MojoExecutionException( "Can't initialize ReleaseMojo.", e );
}
- try
- {
- executeTask();
- }
- finally
- {
- releaseScmManager();
- }
+ executeTask();
}
protected abstract void executeTask()
throws MojoExecutionException;
- private void initScmManager()
- throws Exception
- {
- scmManager = (ScmManager) container.lookup( ScmManager.ROLE );
- }
-
- private void releaseScmManager()
- {
- try
- {
- container.release( scmManager );
- }
- catch ( Exception e )
- {
- getLog().warn( "Error releasing component - ignoring", e );
- }
- }
-
- public void contextualize( Context context )
- throws ContextException
- {
- container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
- }
}
Modified: maven/components/trunk/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugin/release/PrepareReleaseMojo.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugin/release/PrepareReleaseMojo.java?rev=224413&r1=224412&r2=224413&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugin/release/PrepareReleaseMojo.java (original)
+++ maven/components/trunk/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugin/release/PrepareReleaseMojo.java Fri Jul 22 15:07:28 2005
@@ -17,9 +17,14 @@
*/
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.ArtifactUtils;
+import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
+import org.apache.maven.model.ReportPlugin;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.scm.ScmBean;
import org.apache.maven.plugin.transformer.PomTransformer;
@@ -27,16 +32,21 @@
import org.apache.maven.project.MavenProject;
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.ScmFile;
+import org.apache.maven.scm.ScmFileStatus;
import org.codehaus.plexus.components.inputhandler.InputHandler;
+import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;
import java.io.File;
import java.io.FileOutputStream;
+import java.io.FileWriter;
import java.io.IOException;
+import java.io.Writer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
/**
@@ -64,9 +74,32 @@
* @readonly
*/
private boolean interactive = true;
+
+ /**
+ * @parameter expression="${component.org.apache.maven.artifact.metadata.ArtifactMetadataSource}"
+ * @required
+ * @readonly
+ */
+ private ArtifactMetadataSource artifactMetadataSource;
+
+ /**
+ * @parameter expression="${component.org.codehaus.plexus.components.inputhandler.InputHandler}"
+ * @required
+ * @readonly
+ */
+ private InputHandler inputHandler;
+
+ /**
+ * @parameter expression="${localRepository}"
+ * @required
+ * @readonly
+ */
+ private ArtifactRepository localRepository;
private static final String SNAPSHOT = "-SNAPSHOT";
+ private static final String RELEASE_POM = "release-pom.xml";
+
private String projectVersion;
private Model model;
@@ -89,16 +122,48 @@
checkForPresenceOfSnapshots();
transformPomToReleaseVersionPom();
-
+
+ generateReleasePropertiesFile();
+
+ generateReleasePom();
+
checkInReleaseVersionPom();
tagRelease();
transformPomToSnapshotVersionPom();
+
+ new File( basedir, RELEASE_POM ).delete();
checkInSnapshotVersionPom();
}
+ private void generateReleasePropertiesFile() throws MojoExecutionException
+ {
+ try
+ {
+ Properties releaseProperties = new Properties();
+
+ releaseProperties.setProperty( "version", projectVersion );
+
+ releaseProperties.setProperty( USERNAME, username );
+
+ releaseProperties.setProperty( TAG, getTagLabel() );
+
+ releaseProperties.setProperty( SCM_URL, urlScm );
+
+ FileOutputStream os = new FileOutputStream( new File( project.getFile().getParentFile(), RELEASE_PROPS ) );
+
+ releaseProperties.store( os, "maven release plugin info" );
+
+ os.close();
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( "Cannote write release-version file.", e );
+ }
+ }
+
private boolean isSnapshot( String version )
{
return version.endsWith( SNAPSHOT );
@@ -250,9 +315,7 @@
{
getLog().info( "What is the new version? [" + projectVersion + "]" );
- InputHandler handler = (InputHandler) getContainer().lookup( InputHandler.ROLE );
-
- String inputVersion = handler.readLine();
+ String inputVersion = inputHandler.readLine();
if ( !StringUtils.isEmpty( inputVersion ) )
{
@@ -282,97 +345,201 @@
rewriteScmConnection( model.getScm().getDeveloperConnection(), getTagLabel() ) );
}
+ //Rewrite parent version
+ if ( project.hasParent() )
+ {
+ Artifact parentArtifact = project.getParentArtifact();
+
+ if ( isSnapshot( parentArtifact.getBaseVersion() ) )
+ {
+ String version = resolveVersion( parentArtifact, "parent" );
+
+ model.getParent().setVersion( version );
+ }
+ }
+
+ //Rewrite dependencies section
+ Map artifactMap = ArtifactUtils.artifactMapByArtifactId( project.getArtifacts() );
+
+ for ( Iterator i = model.getDependencies().iterator(); i.hasNext(); )
+ {
+ Dependency dep = (Dependency) i.next();
+
+ String conflictId = ArtifactUtils.artifactId( dep.getGroupId(), dep.getArtifactId(), dep.getType(), dep.getVersion() );
+
+ Artifact artifact = (Artifact) artifactMap.get( conflictId );
+
+ dep.setVersion( artifact.getVersion() );
+ }
+
try
{
- Properties releaseProperties = new Properties();
-
- releaseProperties.setProperty( "version", projectVersion );
-
- releaseProperties.setProperty( USERNAME, username );
+ PomTransformer transformer = new VersionTransformer();
- releaseProperties.setProperty( TAG, getTagLabel() );
+ transformer.setOutputFile( project.getFile() );
- releaseProperties.setProperty( SCM_URL, urlScm );
+ transformer.setProject( project.getFile() );
- FileOutputStream os = new FileOutputStream( new File( project.getFile().getParentFile(), RELEASE_PROPS ) );
+ transformer.setUpdatedModel( model );
- releaseProperties.store( os, "maven release plugin info" );
+ transformer.transformNodes();
- os.close();
+ transformer.write();
}
- catch ( IOException e )
+ catch ( Exception e )
{
- throw new MojoExecutionException( "Cannote write release-version file.", e );
+ throw new MojoExecutionException( "Can't transform pom to its release version form.", e );
}
-
+ }
+
+ private void generateReleasePom() throws MojoExecutionException
+ {
+ MavenProject releaseProject = new MavenProject( project );
+ Model releaseModel = releaseProject.getModel();
+
//Rewrite parent version
if ( project.hasParent() )
{
- if ( isSnapshot( project.getParentArtifact().getBaseVersion() ) )
+ Artifact parentArtifact = project.getParentArtifact();
+
+ if ( isSnapshot( parentArtifact.getBaseVersion() ) )
{
- model.getParent().setVersion( project.getParentArtifact().getVersion() );
+ String version = resolveVersion( parentArtifact, "parent" );
+
+ model.getParent().setVersion( version );
}
}
- //Rewrite dependencies version
- for ( Iterator i = project.getArtifacts().iterator(); i.hasNext(); )
+ //Rewrite dependencies section
+ List newdeps = new ArrayList();
+
+ for ( Iterator i = releaseProject.getArtifacts().iterator(); i.hasNext(); )
+ {
+ Artifact artifact = (Artifact) i.next();
+
+ Dependency newdep = new Dependency();
+
+ newdep.setArtifactId( artifact.getArtifactId() );
+ newdep.setGroupId( artifact.getGroupId() );
+ newdep.setVersion( artifact.getVersion() );
+ newdep.setType( artifact.getType() );
+ newdep.setScope( artifact.getScope() );
+
+ newdeps.add( newdep );
+ }
+
+ releaseModel.setDependencies( newdeps );
+
+ //Rewrite plugins version
+ for ( Iterator i = releaseProject.getPluginArtifacts().iterator(); i.hasNext(); )
{
Artifact artifact = (Artifact) i.next();
if ( isSnapshot( artifact.getBaseVersion() ) )
{
- for ( Iterator j = model.getDependencies().iterator(); j.hasNext(); )
+ for ( Iterator j = releaseModel.getBuild().getPlugins().iterator(); j.hasNext(); )
{
- Dependency dependency = (Dependency) j.next();
- if ( artifact.getGroupId().equals( dependency.getGroupId() ) &&
- artifact.getArtifactId().equals( dependency.getArtifactId() ) &&
- artifact.getBaseVersion().equals( dependency.getVersion() ) &&
- artifact.getType().equals( dependency.getType() ) )
+ Plugin plugin = (Plugin) j.next();
+ if ( ArtifactUtils.versionlessKey(artifact).equals( plugin.getKey() ) )
{
- dependency.setVersion( artifact.getVersion() );
+ String version = resolveVersion( artifact, "plugin" );
+
+ plugin.setGroupId( artifact.getGroupId() );
+ plugin.setVersion( version );
}
}
}
}
-
- //Rewrite plugins version
- for ( Iterator i = project.getPluginArtifacts().iterator(); i.hasNext(); )
+
+ //Rewrite report version
+ for ( Iterator i = releaseProject.getReportArtifacts().iterator(); i.hasNext(); )
{
Artifact artifact = (Artifact) i.next();
if ( isSnapshot( artifact.getBaseVersion() ) )
{
- for ( Iterator j = model.getBuild().getPlugins().iterator(); j.hasNext(); )
+ List reportPlugins = releaseProject.getReportPlugins();
+
+ if ( reportPlugins != null )
{
- Plugin plugin = (Plugin) j.next();
- if ( artifact.getGroupId().equals( plugin.getGroupId() ) &&
- artifact.getArtifactId().equals( plugin.getArtifactId() ) )
+ for ( Iterator j = reportPlugins.iterator(); j.hasNext(); )
{
- plugin.setGroupId( artifact.getGroupId() );
- plugin.setVersion( artifact.getVersion() );
+ ReportPlugin plugin = (ReportPlugin) j.next();
+ if ( ArtifactUtils.versionlessKey(artifact).equals( plugin.getKey() ) )
+ {
+ String version = resolveVersion( artifact, "report" );
+
+ plugin.setGroupId( artifact.getGroupId() );
+ plugin.setVersion( version );
+ }
}
}
}
}
-
+
+ File releasePomFile = new File( basedir, RELEASE_POM );
+
+ Writer writer = null;
+
try
{
- PomTransformer transformer = new VersionTransformer();
-
- transformer.setOutputFile( project.getFile() );
-
- transformer.setProject( project.getFile() );
-
- transformer.setUpdatedModel( model );
+ writer = new FileWriter( releasePomFile );
+
+ releaseProject.writeModel( writer );
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( "Cannot write release-pom to: " + releasePomFile, e );
+ }
+ finally
+ {
+ IOUtil.close( writer );
+ }
+
+ try
+ {
+ ScmBean scm = getScm();
- transformer.transformNodes();
+ scm.setWorkingDirectory( basedir );
- transformer.write();
+ List scmChanges = scm.getStatus();
+
+ for ( Iterator i = scmChanges.iterator(); i.hasNext(); )
+ {
+ ScmFile f = (ScmFile) i.next();
+
+ if ( f.getPath().equals( "release-pom.xml" ) && f.getStatus() != ScmFileStatus.MODIFIED )
+ {
+ getScm().add( RELEASE_POM );
+ }
+ }
}
- catch ( Exception e )
+ catch ( ScmException e )
{
- throw new MojoExecutionException( "Can't transform pom to its release version form.", e );
+ throw new MojoExecutionException( "Error updating the release-pom.xml.", e );
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( "Error updating the release-pom.xml.", e );
}
}
+ private String resolveVersion( Artifact artifact, String artifactUsage )
+ throws MojoExecutionException
+ {
+ if ( artifact.getFile() == null )
+ {
+ try
+ {
+ artifactMetadataSource.retrieve(artifact, localRepository, project.getPluginArtifactRepositories() );
+ }
+ catch ( ArtifactMetadataRetrievalException e )
+ {
+ throw new MojoExecutionException( "Cannot resolve " + artifactUsage + ": " + artifact.getId(), e );
+ }
+ }
+
+ return artifact.getVersion();
+ }
+
private void transformPomToSnapshotVersionPom()
throws MojoExecutionException
{
@@ -401,9 +568,7 @@
{
getLog().info( "What is the new version? [" + projectVersion + "]" );
- InputHandler handler = (InputHandler) getContainer().lookup( InputHandler.ROLE );
-
- String inputVersion = handler.readLine();
+ String inputVersion = inputHandler.readLine();
if ( !StringUtils.isEmpty( inputVersion ) )
{
@@ -449,16 +614,16 @@
private void checkInReleaseVersionPom()
throws MojoExecutionException
{
- checkInPom( "[maven-release-plugin] prepare release " + projectVersion );
+ checkIn( "pom.xml,release-pom.xml", "[maven-release-plugin] prepare release " + projectVersion );
}
private void checkInSnapshotVersionPom()
throws MojoExecutionException
{
- checkInPom( "[maven-release-plugin] prepare for development " + projectVersion );
+ checkIn( "pom.xml", "[maven-release-plugin] prepare for development " + projectVersion );
}
- private void checkInPom( String message )
+ private void checkIn( String includePattern, String message )
throws MojoExecutionException
{
try
@@ -472,7 +637,7 @@
// No tag here - we suppose user works on correct branch
scm.setTag( null );
- scm.checkin( message, "pom.xml", null );
+ scm.checkin( message, includePattern, null );
scm.setTag( tag );
}
@@ -508,9 +673,7 @@
{
getLog().info( "What tag name should be used? [ " + tag + " ]" );
- InputHandler handler = (InputHandler) getContainer().lookup( InputHandler.ROLE );
-
- String inputTag = handler.readLine();
+ String inputTag = inputHandler.readLine();
if ( !StringUtils.isEmpty( inputTag ) )
{
Modified: maven/components/trunk/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugin/scm/ScmBean.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugin/scm/ScmBean.java?rev=224413&r1=224412&r2=224413&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugin/scm/ScmBean.java (original)
+++ maven/components/trunk/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugin/scm/ScmBean.java Fri Jul 22 15:07:28 2005
@@ -21,6 +21,7 @@
import org.apache.maven.scm.ScmFileSet;
import org.apache.maven.scm.ScmResult;
import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
+import org.apache.maven.scm.command.add.AddScmResult;
import org.apache.maven.scm.command.checkin.CheckInScmResult;
import org.apache.maven.scm.command.checkout.CheckOutScmResult;
import org.apache.maven.scm.command.status.StatusScmResult;
@@ -173,6 +174,17 @@
changedFiles = result.getChangedFiles();
return changedFiles;
+ }
+
+ public void add( String file ) throws ScmException, IOException
+ {
+ ScmRepository repository = getScmRepository();
+
+ ScmFileSet fs = new ScmFileSet( new File( workingDirectory ), file, null );
+
+ AddScmResult result = getScmManager().add(repository, fs);
+
+ checkResult( result );
}
public void checkin( String message, String includes, String excludes )
Modified: maven/components/trunk/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java?rev=224413&r1=224412&r2=224413&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java (original)
+++ maven/components/trunk/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java Fri Jul 22 15:07:28 2005
@@ -16,7 +16,6 @@
* limitations under the License.
*/
-import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.ReportPlugin;
@@ -30,7 +29,6 @@
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.MavenReport;
import org.apache.maven.reporting.MavenReportException;
-import org.apache.maven.settings.Settings;
import org.codehaus.plexus.i18n.I18N;
import org.codehaus.plexus.siterenderer.Renderer;
import org.codehaus.plexus.siterenderer.RendererException;
@@ -101,13 +99,6 @@
"**/.DS_Store"};
/**
- * @parameter expression="${settings}"
- * @required
- * @readonly
- */
- private Settings settings;
-
- /**
* @parameter expression="${basedir}/src/site"
* @required
*/
@@ -180,13 +171,6 @@
private PluginManager pluginManager;
/**
- * @parameter expression="${localRepository}"
- * @required
- * @readonly
- */
- private ArtifactRepository localRepository;
-
- /**
* @parameter expression="${session}"
* @required
* @readonly
@@ -916,7 +900,7 @@
if ( reportSets == null || reportSets.isEmpty() )
{
- reportsList = pluginManager.getReports( reportPlugin, null, project, session, localRepository );
+ reportsList = pluginManager.getReports( reportPlugin, null, project, session );
}
else
@@ -925,8 +909,7 @@
{
ReportSet reportSet = (ReportSet) j.next();
- reportsList = pluginManager.getReports( reportPlugin, reportSet, project, session,
- localRepository );
+ reportsList = pluginManager.getReports( reportPlugin, reportSet, project, session );
}
}
Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java?rev=224413&r1=224412&r2=224413&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java Fri Jul 22 15:07:28 2005
@@ -34,6 +34,7 @@
import org.apache.maven.model.Parent;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.Profile;
+import org.apache.maven.model.ReportPlugin;
import org.apache.maven.model.Repository;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.profiles.activation.ProfileActivationCalculator;
@@ -85,14 +86,16 @@
// TODO: remove
private PlexusContainer container;
- private ArtifactResolver artifactResolver;
+ protected ArtifactResolver artifactResolver;
+
+ protected ArtifactMetadataSource artifactMetadataSource;
private ArtifactFactory artifactFactory;
private ModelInheritanceAssembler modelInheritanceAssembler;
private ModelValidator validator;
-
+
// TODO: make it a component
private MavenXpp3Reader modelReader;
@@ -126,22 +129,6 @@
List externalProfiles )
throws ProjectBuildingException, ArtifactResolutionException
{
- ArtifactMetadataSource source;
- try
- {
- source = (ArtifactMetadataSource) container.lookup( ArtifactMetadataSource.ROLE );
- }
- catch ( ComponentLookupException e )
- {
- throw new ProjectBuildingException( "Unable to get the artifact metadata source component", e );
- }
- return buildWithDependencies( projectDescriptor, localRepository, source, externalProfiles );
- }
-
- public MavenProject buildWithDependencies( File projectDescriptor, ArtifactRepository localRepository,
- ArtifactMetadataSource artifactMetadataSource, List externalProfiles )
- throws ProjectBuildingException, ArtifactResolutionException
- {
MavenProject project = buildFromSourceFile( projectDescriptor, localRepository, externalProfiles );
// ----------------------------------------------------------------------
@@ -160,6 +147,9 @@
Artifact projectArtifact = project.getArtifact();
Map managedVersions = createManagedVersionMap( project.getDependencyManagement() );
+
+ ensureMetadataSourceIsInitialized();
+
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getDependencyArtifacts(),
projectArtifact, managedVersions,
localRepository,
@@ -169,6 +159,22 @@
project.setArtifacts( result.getArtifacts() );
return project;
}
+
+ private void ensureMetadataSourceIsInitialized()
+ throws ProjectBuildingException
+ {
+ if ( artifactMetadataSource == null )
+ {
+ try
+ {
+ artifactMetadataSource = (ArtifactMetadataSource) container.lookup( ArtifactMetadataSource.ROLE );
+ }
+ catch ( ComponentLookupException e )
+ {
+ throw new ProjectBuildingException( "Cannot lookup metadata source for building the project.", e );
+ }
+ }
+ }
private Map createManagedVersionMap( DependencyManagement dependencyManagement )
throws ProjectBuildingException
@@ -330,10 +336,14 @@
}
}
+ Model originalModel = ModelUtils.cloneModel( model );
+
List repositories = new ArrayList( aggregatedRemoteWagonRepositories );
-
+
MavenProject project = assembleLineage( model, lineage, repositories, localRepository );
+ project.setOriginalModel( originalModel );
+
// we don't have to force the collision exception for superModel here, it's already been done in getSuperModel()
Model previous = superModel;
@@ -630,6 +640,48 @@
if ( artifact != null )
{
pluginArtifacts.add( artifact );
+ }
+ }
+
+ return pluginArtifacts;
+ }
+
+ protected Set createReportArtifacts( List reports )
+ throws ProjectBuildingException
+ {
+ Set pluginArtifacts = new HashSet();
+
+ if ( reports != null )
+ {
+ for ( Iterator i = reports.iterator(); i.hasNext(); )
+ {
+ ReportPlugin p = (ReportPlugin) i.next();
+
+ String version;
+ if ( StringUtils.isEmpty( p.getVersion() ) )
+ {
+ version = "RELEASE";
+ }
+ else
+ {
+ version = p.getVersion();
+ }
+
+ Artifact artifact = null;
+ try
+ {
+ artifact = artifactFactory.createPluginArtifact( p.getGroupId(), p.getArtifactId(), VersionRange
+ .createFromVersionSpec( version ) );
+ }
+ catch ( InvalidVersionSpecificationException e )
+ {
+ throw new ProjectBuildingException( "Unable to parse plugin version", e );
+ }
+
+ if ( artifact != null )
+ {
+ pluginArtifacts.add( artifact );
+ }
}
}
Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/MavenProject.java?rev=224413&r1=224412&r2=224413&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/MavenProject.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/MavenProject.java Fri Jul 22 15:07:28 2005
@@ -111,6 +111,14 @@
// calculated.
private Map artifactMap;
+ private Model originalModel;
+
+ private Map pluginArtifactMap;
+
+ private Set reportArtifacts;
+
+ private Map reportArtifactMap;
+
public MavenProject( Model model )
{
this.model = model;
@@ -810,7 +818,7 @@
{
if ( artifactMap == null )
{
- artifactMap = ArtifactUtils.artifactMap( getArtifacts() );
+ artifactMap = ArtifactUtils.artifactMapByVersionlessId( getArtifacts() );
}
return artifactMap;
@@ -825,6 +833,36 @@
{
return pluginArtifacts;
}
+
+ public Map getPluginArtifactMap()
+ {
+ if ( pluginArtifactMap == null )
+ {
+ pluginArtifactMap = ArtifactUtils.artifactMapByVersionlessId( getPluginArtifacts() );
+ }
+
+ return pluginArtifactMap;
+ }
+
+ public void setReportArtifacts( Set reportArtifacts )
+ {
+ this.reportArtifacts = reportArtifacts;
+ }
+
+ public Set getReportArtifacts()
+ {
+ return reportArtifacts;
+ }
+
+ public Map getReportArtifactMap()
+ {
+ if ( reportArtifactMap == null )
+ {
+ reportArtifactMap = ArtifactUtils.artifactMapByVersionlessId( getReportArtifacts() );
+ }
+
+ return reportArtifactMap;
+ }
public void setParentArtifact( Artifact parentArtifact )
{
@@ -1096,6 +1134,14 @@
pomWriter.write( writer, getModel() );
}
+ public void writeOriginalModel( Writer writer )
+ throws IOException
+ {
+ MavenXpp3Writer pomWriter = new MavenXpp3Writer();
+
+ pomWriter.write( writer, getOriginalModel() );
+ }
+
public Set getDependencyArtifacts()
{
return dependencyArtifacts;
@@ -1105,4 +1151,38 @@
{
this.dependencyArtifacts = dependencyArtifacts;
}
+
+ public void setOriginalModel( Model originalModel )
+ {
+ this.originalModel = originalModel;
+ }
+
+ public Model getOriginalModel()
+ {
+ return originalModel;
+ }
+
+ public boolean equals( Object other )
+ {
+ if ( other == this )
+ {
+ return true;
+ }
+ else if ( !( other instanceof MavenProject ) )
+ {
+ return false;
+ }
+ else
+ {
+ MavenProject otherProject = (MavenProject) other;
+
+ return getId().equals( otherProject.getId() );
+ }
+ }
+
+ public int hashCode()
+ {
+ return getId().hashCode();
+ }
+
}
Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuilder.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuilder.java?rev=224413&r1=224412&r2=224413&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuilder.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuilder.java Fri Jul 22 15:07:28 2005
@@ -17,7 +17,6 @@
*/
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
@@ -36,10 +35,6 @@
MavenProject build( File project, ArtifactRepository localRepository, List profiles )
throws ProjectBuildingException;
-
- MavenProject buildWithDependencies( File project, ArtifactRepository localRepository,
- ArtifactMetadataSource artifactMetadataSource, List externalProfiles )
- throws ProjectBuildingException, ArtifactResolutionException;
MavenProject buildWithDependencies( File project, ArtifactRepository localRepository, List externalProfiles )
throws ProjectBuildingException, ArtifactResolutionException;
Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java?rev=224413&r1=224412&r2=224413&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java Fri Jul 22 15:07:28 2005
@@ -49,6 +49,9 @@
extends AbstractLogEnabled
implements ArtifactMetadataSource
{
+
+ public static final String ROLE_HINT = "maven";
+
private MavenProjectBuilder mavenProjectBuilder;
private ArtifactFactory artifactFactory;
Modified: maven/components/trunk/maven-project/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-project/src/main/resources/META-INF/plexus/components.xml?rev=224413&r1=224412&r2=224413&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/resources/META-INF/plexus/components.xml (original)
+++ maven/components/trunk/maven-project/src/main/resources/META-INF/plexus/components.xml Fri Jul 22 15:07:28 2005
@@ -114,6 +114,7 @@
<role>org.apache.maven.project.inheritance.ModelInheritanceAssembler</role>
<implementation>org.apache.maven.project.inheritance.DefaultModelInheritanceAssembler</implementation>
</component>
+
<!--
|
|
@@ -124,8 +125,28 @@
<implementation>org.apache.maven.project.validation.DefaultModelValidator</implementation>
</component>
+<!-- ********************* FIXME *******************************************
+| I realize this is duplicated but allows the project builder to work by itself
+-->
+ <component>
+ <role>org.apache.maven.project.path.PathTranslator</role>
+ <implementation>org.apache.maven.project.path.DefaultPathTranslator</implementation>
+ </component>
+
+ <component>
+ <role>org.apache.maven.project.ModelResolver</role>
+ <role-hint>default</role-hint>
+ <implementation>org.apache.maven.project.ModelResolver</implementation>
+ <requirements>
+ <requirement>
+ <role>org.apache.maven.artifact.resolver.ArtifactResolver</role>
+ </requirement>
+ </requirements>
+ </component>
+
<component>
<role>org.apache.maven.artifact.metadata.ArtifactMetadataSource</role>
+ <role-hint>maven</role-hint>
<implementation>org.apache.maven.project.artifact.MavenMetadataSource</implementation>
<requirements>
<requirement>
@@ -135,14 +156,6 @@
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
</requirement>
</requirements>
- </component>
-
-<!-- ********************* FIXME *******************************************
-| I realize this is duplicated but allows the project builder to work by itself
--->
- <component>
- <role>org.apache.maven.project.path.PathTranslator</role>
- <implementation>org.apache.maven.project.path.DefaultPathTranslator</implementation>
</component>
</components>
</component-set>
Modified: maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/MavenProjectTestCase.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/MavenProjectTestCase.java?rev=224413&r1=224412&r2=224413&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/MavenProjectTestCase.java (original)
+++ maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/MavenProjectTestCase.java Fri Jul 22 15:07:28 2005
@@ -16,12 +16,11 @@
* limitations under the License.
*/
-import org.apache.maven.artifact.factory.ArtifactFactory;
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.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import java.io.File;
import java.io.FileNotFoundException;
@@ -37,18 +36,22 @@
{
protected MavenProjectBuilder projectBuilder;
- private ArtifactFactory artifactFactory;
-
- private ArtifactRepositoryFactory artifactRepositoryFactory;
-
protected void setUp()
throws Exception
{
super.setUp();
- projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
- artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
- artifactRepositoryFactory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
+ try
+ {
+ projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE, "test" );
+ }
+ catch ( ComponentLookupException e )
+ {
+ // default over to the main project builder...
+ projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
+ }
+
+ System.out.println("Using project builder: " + projectBuilder.getClass().getName() + " for tests in: " + getClass().getName());
}
// ----------------------------------------------------------------------
@@ -103,8 +106,7 @@
protected MavenProject getProjectWithDependencies( File pom )
throws Exception
{
- return projectBuilder.buildWithDependencies( pom, getLocalRepository(), new TestArtifactResolver.Source(
- artifactFactory, artifactRepositoryFactory, getContainer() ), Collections.EMPTY_LIST );
+ return projectBuilder.buildWithDependencies( pom, getLocalRepository(), Collections.EMPTY_LIST );
}
protected MavenProject getProject( File pom )
Modified: maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/ProjectClasspathTest.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/ProjectClasspathTest.java?rev=224413&r1=224412&r2=224413&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/ProjectClasspathTest.java (original)
+++ maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/ProjectClasspathTest.java Fri Jul 22 15:07:28 2005
@@ -19,7 +19,6 @@
import org.apache.maven.artifact.Artifact;
import java.io.File;
-import java.lang.reflect.Field;
import java.util.Iterator;
/**
@@ -35,16 +34,14 @@
{
File f = getFileForClasspathResource( dir + "project-with-scoped-dependencies.xml" );
- // XXX: Because this test fails, we resort to crude reflection hacks, see PLX-108 for the solution
// assertEquals( TestArtifactResolver.class, getContainer().lookup( ArtifactResolver.ROLE ).getClass() );
- MavenProjectBuilder builder = (MavenProjectBuilder) getContainer().lookup( MavenProjectBuilder.ROLE );
- Field declaredField = builder.getClass().getDeclaredField( "artifactResolver" );
- boolean acc = declaredField.isAccessible();
- declaredField.setAccessible( true );
- declaredField.set( builder, getContainer().lookup( TestArtifactResolver.class.getName() ) );
- declaredField.setAccessible( acc );
- // XXX: end hack
-
+ TestProjectBuilder builder = (TestProjectBuilder) getContainer().lookup( MavenProjectBuilder.ROLE, "test" );
+
+ TestArtifactResolver testArtifactResolver = (TestArtifactResolver) getContainer().lookup( TestArtifactResolver.class.getName() );
+
+ builder.setArtifactResolver( testArtifactResolver );
+ builder.setArtifactMetadataSource( testArtifactResolver.source() );
+
MavenProject project = getProjectWithDependencies( f );
Artifact artifact;
Modified: maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/TestArtifactResolver.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/TestArtifactResolver.java?rev=224413&r1=224412&r2=224413&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/TestArtifactResolver.java (original)
+++ maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/TestArtifactResolver.java Fri Jul 22 15:07:28 2005
@@ -52,6 +52,8 @@
extends DefaultArtifactResolver
implements Contextualizable
{
+ public static final String ROLE = TestArtifactResolver.class.getName();
+
private ArtifactRepositoryFactory repositoryFactory;
private PlexusContainer container;
@@ -154,6 +156,11 @@
return projectArtifacts;
}
+ }
+
+ public Source source()
+ {
+ return new Source( artifactFactory, repositoryFactory, container );
}
/**
Added: maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/TestProjectBuilder.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/TestProjectBuilder.java?rev=224413&view=auto
==============================================================================
--- maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/TestProjectBuilder.java (added)
+++ maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/TestProjectBuilder.java Fri Jul 22 15:07:28 2005
@@ -0,0 +1,18 @@
+package org.apache.maven.project;
+
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+
+public class TestProjectBuilder extends DefaultMavenProjectBuilder
+{
+
+ public void setArtifactResolver( ArtifactResolver resolver )
+ {
+ artifactResolver = resolver;
+ }
+
+ public void setArtifactMetadataSource( ArtifactMetadataSource metadataSource )
+ {
+ artifactMetadataSource = metadataSource;
+ }
+}
Propchange: maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/TestProjectBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/TestProjectBuilder.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Modified: maven/components/trunk/maven-project/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-project/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml?rev=224413&r1=224412&r2=224413&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml (original)
+++ maven/components/trunk/maven-project/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml Fri Jul 22 15:07:28 2005
@@ -32,5 +32,39 @@
</requirement>
</requirements>
</component>
+ <component>
+ <role>org.apache.maven.project.MavenProjectBuilder</role>
+ <role-hint>test</role-hint>
+ <implementation>org.apache.maven.project.TestProjectBuilder</implementation>
+ <requirements>
+ <requirement>
+ <role>org.apache.maven.project.injection.ModelDefaultsInjector</role>
+ </requirement>
+ <requirement>
+ <role>org.apache.maven.project.interpolation.ModelInterpolator</role>
+ </requirement>
+ <requirement>
+ <role>org.apache.maven.project.inheritance.ModelInheritanceAssembler</role>
+ </requirement>
+ <requirement>
+ <role>org.apache.maven.project.validation.ModelValidator</role>
+ </requirement>
+ <requirement>
+ <role>org.apache.maven.project.path.PathTranslator</role>
+ </requirement>
+ <requirement>
+ <role>org.apache.maven.artifact.factory.ArtifactFactory</role>
+ </requirement>
+ <requirement>
+ <role>org.apache.maven.artifact.resolver.ArtifactResolver</role>
+ </requirement>
+ <requirement>
+ <role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
+ </requirement>
+ <requirement>
+ <role>org.apache.maven.profiles.activation.ProfileActivationCalculator</role>
+ </requirement>
+ </requirements>
+ </component>
</components>
</plexus>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org