mirror of https://github.com/apache/maven.git
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. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@224413 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
22282d4f24
commit
701ef520a3
|
@ -3,7 +3,6 @@ package org.apache.maven.artifact;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public final class ArtifactUtils
|
public final class ArtifactUtils
|
||||||
|
@ -23,7 +22,17 @@ public final class ArtifactUtils
|
||||||
return groupId + ":" + artifactId;
|
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();
|
Map artifactMap = new HashMap();
|
||||||
|
|
||||||
|
@ -37,4 +46,18 @@ public final class ArtifactUtils
|
||||||
return artifactMap;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,6 +177,10 @@ public class DefaultMaven
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
MavenSession session = createSession( request, projects );
|
||||||
|
|
||||||
|
List goals = request.getGoals();
|
||||||
|
|
||||||
for ( Iterator iterator = projects.iterator(); iterator.hasNext(); )
|
for ( Iterator iterator = projects.iterator(); iterator.hasNext(); )
|
||||||
{
|
{
|
||||||
MavenProject project = (MavenProject) iterator.next();
|
MavenProject project = (MavenProject) iterator.next();
|
||||||
|
@ -189,7 +193,7 @@ public class DefaultMaven
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
MavenExecutionResponse response = processProject( request, project, dispatcher );
|
MavenExecutionResponse response = processProject( session, goals, project, dispatcher );
|
||||||
if ( response.isExecutionFailure() )
|
if ( response.isExecutionFailure() )
|
||||||
{
|
{
|
||||||
dispatcher.dispatchError( event, request.getBaseDirectory(), response.getException() );
|
dispatcher.dispatchError( event, request.getBaseDirectory(), response.getException() );
|
||||||
|
@ -262,14 +266,10 @@ public class DefaultMaven
|
||||||
return projects;
|
return projects;
|
||||||
}
|
}
|
||||||
|
|
||||||
private MavenExecutionResponse processProject( MavenExecutionRequest request, MavenProject project,
|
private MavenExecutionResponse processProject( MavenSession session, List goals, MavenProject project,
|
||||||
EventDispatcher dispatcher )
|
EventDispatcher dispatcher )
|
||||||
throws LifecycleExecutionException
|
throws LifecycleExecutionException
|
||||||
{
|
{
|
||||||
List goals = request.getGoals();
|
|
||||||
|
|
||||||
MavenSession session = createSession( request, project );
|
|
||||||
|
|
||||||
// !! This is ripe for refactoring to an aspect.
|
// !! This is ripe for refactoring to an aspect.
|
||||||
// Event monitoring.
|
// Event monitoring.
|
||||||
String event = MavenEvents.PROJECT_EXECUTION;
|
String event = MavenEvents.PROJECT_EXECUTION;
|
||||||
|
@ -412,10 +412,10 @@ public class DefaultMaven
|
||||||
// the session type would be specific to the request i.e. having a project
|
// the session type would be specific to the request i.e. having a project
|
||||||
// or not.
|
// 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(),
|
return new MavenSession( container, request.getSettings(), request.getLocalRepository(),
|
||||||
request.getEventDispatcher(), request.getGoals() );
|
request.getEventDispatcher(), projects, request.getGoals(), request.getBaseDirectory() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -19,11 +19,9 @@ package org.apache.maven.execution;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.monitor.event.EventDispatcher;
|
import org.apache.maven.monitor.event.EventDispatcher;
|
||||||
import org.apache.maven.plugin.mapping.PluginMappingManager;
|
import org.apache.maven.plugin.mapping.PluginMappingManager;
|
||||||
import org.apache.maven.project.MavenProject;
|
|
||||||
import org.apache.maven.settings.Settings;
|
import org.apache.maven.settings.Settings;
|
||||||
import org.codehaus.plexus.PlexusContainer;
|
import org.codehaus.plexus.PlexusContainer;
|
||||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||||
import org.codehaus.plexus.context.Context;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -36,8 +34,6 @@ public class MavenSession
|
||||||
{
|
{
|
||||||
private PlexusContainer container;
|
private PlexusContainer container;
|
||||||
|
|
||||||
private MavenProject project;
|
|
||||||
|
|
||||||
private ArtifactRepository localRepository;
|
private ArtifactRepository localRepository;
|
||||||
|
|
||||||
private List goals;
|
private List goals;
|
||||||
|
@ -49,11 +45,14 @@ public class MavenSession
|
||||||
// TODO: make this the central one, get rid of build settings...
|
// TODO: make this the central one, get rid of build settings...
|
||||||
private final Settings settings;
|
private final Settings settings;
|
||||||
|
|
||||||
public MavenSession( MavenProject project, PlexusContainer container, Settings settings,
|
private List sortedProjects;
|
||||||
ArtifactRepository localRepository, EventDispatcher eventDispatcher, List goals )
|
|
||||||
{
|
|
||||||
this.project = project;
|
|
||||||
|
|
||||||
|
private final String executionRootDir;
|
||||||
|
|
||||||
|
public MavenSession( PlexusContainer container, Settings settings,
|
||||||
|
ArtifactRepository localRepository, EventDispatcher eventDispatcher, List sortedProjects,
|
||||||
|
List goals, String executionRootDir )
|
||||||
|
{
|
||||||
this.container = container;
|
this.container = container;
|
||||||
|
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
|
@ -61,26 +60,12 @@ public class MavenSession
|
||||||
this.localRepository = localRepository;
|
this.localRepository = localRepository;
|
||||||
|
|
||||||
this.eventDispatcher = eventDispatcher;
|
this.eventDispatcher = eventDispatcher;
|
||||||
|
|
||||||
|
this.sortedProjects = sortedProjects;
|
||||||
|
|
||||||
this.goals = goals;
|
this.goals = goals;
|
||||||
|
|
||||||
// TODO: Go back to this when we get the container ready to configure mojos...
|
this.executionRootDir = executionRootDir;
|
||||||
// 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();
|
|
||||||
|
|
||||||
context.put( "project", project );
|
|
||||||
context.put( "settings", settings );
|
|
||||||
context.put( "basedir", project.getBasedir().getAbsolutePath() );
|
|
||||||
context.put( "localRepository", localRepository );
|
|
||||||
|
|
||||||
// TODO: remove this alias...change to ${project.build.finalName}
|
|
||||||
context.put( "maven.final.name", project.getBuild().getFinalName() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlexusContainer getContainer()
|
public PlexusContainer getContainer()
|
||||||
|
@ -145,4 +130,14 @@ public class MavenSession
|
||||||
{
|
{
|
||||||
return pluginMappingManager;
|
return pluginMappingManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List getSortedProjects()
|
||||||
|
{
|
||||||
|
return sortedProjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExecutionRootDirectory()
|
||||||
|
{
|
||||||
|
return executionRootDir;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -17,6 +17,7 @@ package org.apache.maven.plugin;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
|
import org.apache.maven.artifact.ArtifactUtils;
|
||||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||||
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
||||||
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
||||||
|
@ -112,7 +113,7 @@ public class DefaultPluginManager
|
||||||
|
|
||||||
protected ArtifactResolver artifactResolver;
|
protected ArtifactResolver artifactResolver;
|
||||||
|
|
||||||
protected ArtifactMetadataSource metadataSource;
|
protected ArtifactMetadataSource artifactMetadataSource;
|
||||||
|
|
||||||
protected MavenPluginMappingBuilder pluginMappingBuilder;
|
protected MavenPluginMappingBuilder pluginMappingBuilder;
|
||||||
|
|
||||||
|
@ -172,6 +173,15 @@ public class DefaultPluginManager
|
||||||
public PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings,
|
public PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings,
|
||||||
ArtifactRepository localRepository )
|
ArtifactRepository localRepository )
|
||||||
throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException
|
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
|
// TODO: this should be possibly outside
|
||||||
// All version-resolution logic has been moved to DefaultPluginVersionManager.
|
// All version-resolution logic has been moved to DefaultPluginVersionManager.
|
||||||
|
@ -189,6 +199,7 @@ public class DefaultPluginManager
|
||||||
{
|
{
|
||||||
VersionRange versionRange = VersionRange.createFromVersionSpec( plugin.getVersion() );
|
VersionRange versionRange = VersionRange.createFromVersionSpec( plugin.getVersion() );
|
||||||
|
|
||||||
|
|
||||||
checkRequiredMavenVersion( plugin, localRepository, project.getPluginArtifactRepositories() );
|
checkRequiredMavenVersion( plugin, localRepository, project.getPluginArtifactRepositories() );
|
||||||
|
|
||||||
Artifact pluginArtifact = artifactFactory.createPluginArtifact( plugin.getGroupId(),
|
Artifact pluginArtifact = artifactFactory.createPluginArtifact( plugin.getGroupId(),
|
||||||
|
@ -382,17 +393,33 @@ public class DefaultPluginManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List getReports( ReportPlugin reportPlugin, ReportSet reportSet, MavenProject project, MavenSession session,
|
public List getReports( ReportPlugin reportPlugin, ReportSet reportSet, MavenProject project, MavenSession session )
|
||||||
ArtifactRepository localRepository )
|
|
||||||
throws PluginManagerException, PluginVersionResolutionException, PluginConfigurationException,
|
throws PluginManagerException, PluginVersionResolutionException, PluginConfigurationException,
|
||||||
ArtifactResolutionException
|
ArtifactResolutionException
|
||||||
{
|
{
|
||||||
Plugin forLookup = new Plugin();
|
Plugin forLookup = new Plugin();
|
||||||
forLookup.setGroupId( reportPlugin.getGroupId() );
|
|
||||||
forLookup.setArtifactId( reportPlugin.getArtifactId() );
|
String groupId = reportPlugin.getGroupId();
|
||||||
forLookup.setVersion( reportPlugin.getVersion() );
|
String artifactId = reportPlugin.getArtifactId();
|
||||||
|
|
||||||
|
forLookup.setGroupId( groupId );
|
||||||
|
forLookup.setArtifactId( artifactId );
|
||||||
|
|
||||||
PluginDescriptor pluginDescriptor = verifyPlugin( forLookup, project, session.getSettings(), localRepository );
|
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();
|
List reports = new ArrayList();
|
||||||
for ( Iterator i = pluginDescriptor.getMojos().iterator(); i.hasNext(); )
|
for ( Iterator i = pluginDescriptor.getMojos().iterator(); i.hasNext(); )
|
||||||
|
@ -516,7 +543,7 @@ public class DefaultPluginManager
|
||||||
{
|
{
|
||||||
ArtifactRepository localRepository = session.getLocalRepository();
|
ArtifactRepository localRepository = session.getLocalRepository();
|
||||||
|
|
||||||
ResolutionGroup resolutionGroup = metadataSource.retrieve( pluginArtifact, localRepository,
|
ResolutionGroup resolutionGroup = artifactMetadataSource.retrieve( pluginArtifact, localRepository,
|
||||||
project.getPluginArtifactRepositories() );
|
project.getPluginArtifactRepositories() );
|
||||||
|
|
||||||
Set dependencies = resolutionGroup.getArtifacts();
|
Set dependencies = resolutionGroup.getArtifacts();
|
||||||
|
@ -524,7 +551,7 @@ public class DefaultPluginManager
|
||||||
ArtifactResolutionResult result = artifactResolver.resolveTransitively( dependencies, pluginArtifact,
|
ArtifactResolutionResult result = artifactResolver.resolveTransitively( dependencies, pluginArtifact,
|
||||||
localRepository,
|
localRepository,
|
||||||
resolutionGroup.getResolutionRepositories(),
|
resolutionGroup.getResolutionRepositories(),
|
||||||
metadataSource,
|
artifactMetadataSource,
|
||||||
artifactFilter );
|
artifactFilter );
|
||||||
|
|
||||||
Set resolved = result.getArtifacts();
|
Set resolved = result.getArtifacts();
|
||||||
|
@ -1015,7 +1042,7 @@ public class DefaultPluginManager
|
||||||
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getDependencyArtifacts(),
|
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getDependencyArtifacts(),
|
||||||
artifact, context.getLocalRepository(),
|
artifact, context.getLocalRepository(),
|
||||||
project.getRemoteArtifactRepositories(),
|
project.getRemoteArtifactRepositories(),
|
||||||
metadataSource, filter );
|
artifactMetadataSource, filter );
|
||||||
|
|
||||||
project.setArtifacts( result.getArtifacts() );
|
project.setArtifacts( result.getArtifacts() );
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,8 +51,7 @@ public interface PluginManager
|
||||||
ArtifactRepository localRepository )
|
ArtifactRepository localRepository )
|
||||||
throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException;
|
throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException;
|
||||||
|
|
||||||
List getReports( ReportPlugin reportPlugin, ReportSet reportSet, MavenProject project, MavenSession session,
|
List getReports( ReportPlugin reportPlugin, ReportSet reportSet, MavenProject project, MavenSession session )
|
||||||
ArtifactRepository localRepository )
|
|
||||||
throws PluginManagerException, PluginVersionResolutionException, PluginConfigurationException,
|
throws PluginManagerException, PluginVersionResolutionException, PluginConfigurationException,
|
||||||
ArtifactResolutionException;
|
ArtifactResolutionException;
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@ import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||||
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
||||||
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
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.LatestArtifactTransformation;
|
||||||
import org.apache.maven.artifact.transform.ReleaseArtifactTransformation;
|
import org.apache.maven.artifact.transform.ReleaseArtifactTransformation;
|
||||||
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
||||||
|
@ -61,17 +60,15 @@ public class DefaultPluginVersionManager
|
||||||
{
|
{
|
||||||
private MavenPluginRegistryBuilder mavenPluginRegistryBuilder;
|
private MavenPluginRegistryBuilder mavenPluginRegistryBuilder;
|
||||||
|
|
||||||
private ArtifactResolver artifactResolver;
|
|
||||||
|
|
||||||
private ArtifactFactory artifactFactory;
|
private ArtifactFactory artifactFactory;
|
||||||
|
|
||||||
private InputHandler inputHandler;
|
private InputHandler inputHandler;
|
||||||
|
|
||||||
|
private ArtifactMetadataSource artifactMetadataSource;
|
||||||
|
|
||||||
// calculated.
|
// calculated.
|
||||||
private PluginRegistry pluginRegistry;
|
private PluginRegistry pluginRegistry;
|
||||||
|
|
||||||
private ArtifactMetadataSource metadataSource;
|
|
||||||
|
|
||||||
private MavenProjectBuilder mavenProjectBuilder;
|
private MavenProjectBuilder mavenProjectBuilder;
|
||||||
|
|
||||||
private RuntimeInformation runtimeInformation;
|
private RuntimeInformation runtimeInformation;
|
||||||
|
@ -79,9 +76,16 @@ public class DefaultPluginVersionManager
|
||||||
public String resolvePluginVersion( String groupId, String artifactId, MavenProject project, Settings settings,
|
public String resolvePluginVersion( String groupId, String artifactId, MavenProject project, Settings settings,
|
||||||
ArtifactRepository localRepository )
|
ArtifactRepository localRepository )
|
||||||
throws PluginVersionResolutionException
|
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.
|
// 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.
|
// we're NEVER going to persist POM-derived plugin versions.
|
||||||
String updatedVersion = null;
|
String updatedVersion = null;
|
||||||
|
@ -474,33 +478,33 @@ public class DefaultPluginVersionManager
|
||||||
return groupId + ":" + artifactId;
|
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;
|
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() ) )
|
|
||||||
{
|
|
||||||
version = plugin.getVersion();
|
|
||||||
|
|
||||||
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 )
|
|
||||||
{
|
{
|
||||||
for ( Iterator it = project.getReportPlugins().iterator(); it.hasNext(); )
|
for ( Iterator it = project.getReportPlugins().iterator(); it.hasNext(); )
|
||||||
{
|
{
|
||||||
ReportPlugin reportPlugin = (ReportPlugin) it.next();
|
ReportPlugin plugin = (ReportPlugin) 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for ( Iterator it = project.getBuildPlugins().iterator(); it.hasNext(); )
|
||||||
|
{
|
||||||
|
Plugin plugin = (Plugin) it.next();
|
||||||
|
|
||||||
|
if ( groupId.equals( plugin.getGroupId() ) && artifactId.equals( plugin.getArtifactId() ) )
|
||||||
|
{
|
||||||
|
version = plugin.getVersion();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -620,7 +624,7 @@ public class DefaultPluginVersionManager
|
||||||
String version = null;
|
String version = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
metadataSource.retrieve( artifact, localRepository, remoteRepositories );
|
artifactMetadataSource.retrieve( artifact, localRepository, remoteRepositories );
|
||||||
|
|
||||||
MavenProject project = mavenProjectBuilder.buildFromRepository( artifact, remoteRepositories,
|
MavenProject project = mavenProjectBuilder.buildFromRepository( artifact, remoteRepositories,
|
||||||
localRepository );
|
localRepository );
|
||||||
|
|
|
@ -28,4 +28,7 @@ public interface PluginVersionManager
|
||||||
String resolvePluginVersion( String groupId, String artifactId, MavenProject project, Settings settings, ArtifactRepository localRepository )
|
String resolvePluginVersion( String groupId, String artifactId, MavenProject project, Settings settings, ArtifactRepository localRepository )
|
||||||
throws PluginVersionResolutionException;
|
throws PluginVersionResolutionException;
|
||||||
|
|
||||||
|
String resolvePluginVersion( String groupId, String artifactId, MavenProject project, Settings settings, ArtifactRepository localRepository, boolean resolveAsReportPlugin )
|
||||||
|
throws PluginVersionResolutionException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -229,9 +229,6 @@
|
||||||
<requirement>
|
<requirement>
|
||||||
<role>org.apache.maven.plugin.registry.MavenPluginRegistryBuilder</role>
|
<role>org.apache.maven.plugin.registry.MavenPluginRegistryBuilder</role>
|
||||||
</requirement>
|
</requirement>
|
||||||
<requirement>
|
|
||||||
<role>org.apache.maven.artifact.resolver.ArtifactResolver</role>
|
|
||||||
</requirement>
|
|
||||||
<requirement>
|
<requirement>
|
||||||
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
|
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
|
||||||
</requirement>
|
</requirement>
|
||||||
|
|
|
@ -66,11 +66,11 @@ public class PluginParameterExpressionEvaluatorTest
|
||||||
assertEquals( expected, actual );
|
assertEquals( expected, actual );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MavenSession createSession( MavenProject project, PlexusContainer container,
|
private static MavenSession createSession( PlexusContainer container,
|
||||||
ArtifactRepository repo )
|
ArtifactRepository repo )
|
||||||
{
|
{
|
||||||
return new MavenSession( project, container, new Settings(), repo, new DefaultEventDispatcher(),
|
return new MavenSession( container, new Settings(), repo, new DefaultEventDispatcher(),
|
||||||
Collections.EMPTY_LIST );
|
Collections.EMPTY_LIST, Collections.EMPTY_LIST, "." );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLocalRepositoryExtraction()
|
public void testLocalRepositoryExtraction()
|
||||||
|
@ -137,7 +137,7 @@ public class PluginParameterExpressionEvaluatorTest
|
||||||
ArtifactRepository repo = new DefaultArtifactRepository( "local", "target/repo", repoLayout );
|
ArtifactRepository repo = new DefaultArtifactRepository( "local", "target/repo", repoLayout );
|
||||||
|
|
||||||
PlexusContainer container = getContainer();
|
PlexusContainer container = getContainer();
|
||||||
MavenSession session = createSession( project, container, repo );
|
MavenSession session = createSession( container, repo );
|
||||||
|
|
||||||
return (ExpressionEvaluator) new PluginParameterExpressionEvaluator( session, pluginDescriptor, null,
|
return (ExpressionEvaluator) new PluginParameterExpressionEvaluator( session, pluginDescriptor, null,
|
||||||
container.getLogger(), project );
|
container.getLogger(), project );
|
||||||
|
|
|
@ -223,7 +223,7 @@ public class PluginDescriptor
|
||||||
{
|
{
|
||||||
if ( artifactMap == null )
|
if ( artifactMap == null )
|
||||||
{
|
{
|
||||||
artifactMap = ArtifactUtils.artifactMap( getArtifacts() );
|
artifactMap = ArtifactUtils.artifactMapByVersionlessId( getArtifacts() );
|
||||||
}
|
}
|
||||||
|
|
||||||
return artifactMap;
|
return artifactMap;
|
||||||
|
|
|
@ -21,16 +21,11 @@ import org.apache.maven.plugin.MojoExecutionException;
|
||||||
import org.apache.maven.plugin.scm.ScmBean;
|
import org.apache.maven.plugin.scm.ScmBean;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
import org.apache.maven.scm.manager.ScmManager;
|
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.FileInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.File;
|
import java.util.Properties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -39,7 +34,6 @@ import java.io.File;
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractReleaseMojo
|
public abstract class AbstractReleaseMojo
|
||||||
extends AbstractMojo
|
extends AbstractMojo
|
||||||
implements Contextualizable
|
|
||||||
{
|
{
|
||||||
public static final String RELEASE_PROPS = "release.properties";
|
public static final String RELEASE_PROPS = "release.properties";
|
||||||
|
|
||||||
|
@ -88,8 +82,11 @@ public abstract class AbstractReleaseMojo
|
||||||
*/
|
*/
|
||||||
protected MavenProject project;
|
protected MavenProject project;
|
||||||
|
|
||||||
private PlexusContainer container;
|
/**
|
||||||
|
* @parameter expression="${org.apache.maven.scm.manager.ScmManager}"
|
||||||
|
* @required
|
||||||
|
* @readonly
|
||||||
|
*/
|
||||||
protected ScmManager scmManager;
|
protected ScmManager scmManager;
|
||||||
|
|
||||||
private Properties releaseProperties;
|
private Properties releaseProperties;
|
||||||
|
@ -130,18 +127,11 @@ public abstract class AbstractReleaseMojo
|
||||||
return scm;
|
return scm;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlexusContainer getContainer()
|
|
||||||
{
|
|
||||||
return container;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void execute()
|
public void execute()
|
||||||
throws MojoExecutionException
|
throws MojoExecutionException
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
initScmManager();
|
|
||||||
|
|
||||||
if ( username == null )
|
if ( username == null )
|
||||||
{
|
{
|
||||||
username = System.getProperty( "user.name" );
|
username = System.getProperty( "user.name" );
|
||||||
|
@ -169,40 +159,10 @@ public abstract class AbstractReleaseMojo
|
||||||
throw new MojoExecutionException( "Can't initialize ReleaseMojo.", e );
|
throw new MojoExecutionException( "Can't initialize ReleaseMojo.", e );
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
executeTask();
|
||||||
{
|
|
||||||
executeTask();
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
releaseScmManager();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void executeTask()
|
protected abstract void executeTask()
|
||||||
throws MojoExecutionException;
|
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 );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,14 @@ package org.apache.maven.plugin.release;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
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.Dependency;
|
||||||
import org.apache.maven.model.Model;
|
import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
|
import org.apache.maven.model.ReportPlugin;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.plugin.MojoExecutionException;
|
||||||
import org.apache.maven.plugin.scm.ScmBean;
|
import org.apache.maven.plugin.scm.ScmBean;
|
||||||
import org.apache.maven.plugin.transformer.PomTransformer;
|
import org.apache.maven.plugin.transformer.PomTransformer;
|
||||||
|
@ -27,16 +32,21 @@ import org.apache.maven.plugin.transformer.VersionTransformer;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
import org.apache.maven.scm.ScmException;
|
import org.apache.maven.scm.ScmException;
|
||||||
import org.apache.maven.scm.ScmFile;
|
import org.apache.maven.scm.ScmFile;
|
||||||
|
import org.apache.maven.scm.ScmFileStatus;
|
||||||
import org.codehaus.plexus.components.inputhandler.InputHandler;
|
import org.codehaus.plexus.components.inputhandler.InputHandler;
|
||||||
|
import org.codehaus.plexus.util.IOUtil;
|
||||||
import org.codehaus.plexus.util.StringUtils;
|
import org.codehaus.plexus.util.StringUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.Writer;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,9 +74,32 @@ public class PrepareReleaseMojo
|
||||||
* @readonly
|
* @readonly
|
||||||
*/
|
*/
|
||||||
private boolean interactive = true;
|
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 SNAPSHOT = "-SNAPSHOT";
|
||||||
|
|
||||||
|
private static final String RELEASE_POM = "release-pom.xml";
|
||||||
|
|
||||||
private String projectVersion;
|
private String projectVersion;
|
||||||
|
|
||||||
private Model model;
|
private Model model;
|
||||||
|
@ -89,16 +122,48 @@ public class PrepareReleaseMojo
|
||||||
checkForPresenceOfSnapshots();
|
checkForPresenceOfSnapshots();
|
||||||
|
|
||||||
transformPomToReleaseVersionPom();
|
transformPomToReleaseVersionPom();
|
||||||
|
|
||||||
|
generateReleasePropertiesFile();
|
||||||
|
|
||||||
|
generateReleasePom();
|
||||||
|
|
||||||
checkInReleaseVersionPom();
|
checkInReleaseVersionPom();
|
||||||
|
|
||||||
tagRelease();
|
tagRelease();
|
||||||
|
|
||||||
transformPomToSnapshotVersionPom();
|
transformPomToSnapshotVersionPom();
|
||||||
|
|
||||||
|
new File( basedir, RELEASE_POM ).delete();
|
||||||
|
|
||||||
checkInSnapshotVersionPom();
|
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 )
|
private boolean isSnapshot( String version )
|
||||||
{
|
{
|
||||||
return version.endsWith( SNAPSHOT );
|
return version.endsWith( SNAPSHOT );
|
||||||
|
@ -250,9 +315,7 @@ public class PrepareReleaseMojo
|
||||||
{
|
{
|
||||||
getLog().info( "What is the new version? [" + projectVersion + "]" );
|
getLog().info( "What is the new version? [" + projectVersion + "]" );
|
||||||
|
|
||||||
InputHandler handler = (InputHandler) getContainer().lookup( InputHandler.ROLE );
|
String inputVersion = inputHandler.readLine();
|
||||||
|
|
||||||
String inputVersion = handler.readLine();
|
|
||||||
|
|
||||||
if ( !StringUtils.isEmpty( inputVersion ) )
|
if ( !StringUtils.isEmpty( inputVersion ) )
|
||||||
{
|
{
|
||||||
|
@ -282,77 +345,33 @@ public class PrepareReleaseMojo
|
||||||
rewriteScmConnection( model.getScm().getDeveloperConnection(), getTagLabel() ) );
|
rewriteScmConnection( model.getScm().getDeveloperConnection(), getTagLabel() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
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 );
|
|
||||||
}
|
|
||||||
|
|
||||||
//Rewrite parent version
|
//Rewrite parent version
|
||||||
if ( project.hasParent() )
|
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
|
//Rewrite dependencies section
|
||||||
for ( Iterator i = project.getArtifacts().iterator(); i.hasNext(); )
|
Map artifactMap = ArtifactUtils.artifactMapByArtifactId( project.getArtifacts() );
|
||||||
|
|
||||||
|
for ( Iterator i = model.getDependencies().iterator(); i.hasNext(); )
|
||||||
{
|
{
|
||||||
Artifact artifact = (Artifact) i.next();
|
Dependency dep = (Dependency) i.next();
|
||||||
if ( isSnapshot( artifact.getBaseVersion() ) )
|
|
||||||
{
|
String conflictId = ArtifactUtils.artifactId( dep.getGroupId(), dep.getArtifactId(), dep.getType(), dep.getVersion() );
|
||||||
for ( Iterator j = model.getDependencies().iterator(); j.hasNext(); )
|
|
||||||
{
|
Artifact artifact = (Artifact) artifactMap.get( conflictId );
|
||||||
Dependency dependency = (Dependency) j.next();
|
|
||||||
if ( artifact.getGroupId().equals( dependency.getGroupId() ) &&
|
dep.setVersion( artifact.getVersion() );
|
||||||
artifact.getArtifactId().equals( dependency.getArtifactId() ) &&
|
|
||||||
artifact.getBaseVersion().equals( dependency.getVersion() ) &&
|
|
||||||
artifact.getType().equals( dependency.getType() ) )
|
|
||||||
{
|
|
||||||
dependency.setVersion( artifact.getVersion() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Rewrite plugins version
|
|
||||||
for ( Iterator i = project.getPluginArtifacts().iterator(); i.hasNext(); )
|
|
||||||
{
|
|
||||||
Artifact artifact = (Artifact) i.next();
|
|
||||||
if ( isSnapshot( artifact.getBaseVersion() ) )
|
|
||||||
{
|
|
||||||
for ( Iterator j = model.getBuild().getPlugins().iterator(); j.hasNext(); )
|
|
||||||
{
|
|
||||||
Plugin plugin = (Plugin) j.next();
|
|
||||||
if ( artifact.getGroupId().equals( plugin.getGroupId() ) &&
|
|
||||||
artifact.getArtifactId().equals( plugin.getArtifactId() ) )
|
|
||||||
{
|
|
||||||
plugin.setGroupId( artifact.getGroupId() );
|
|
||||||
plugin.setVersion( artifact.getVersion() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PomTransformer transformer = new VersionTransformer();
|
PomTransformer transformer = new VersionTransformer();
|
||||||
|
@ -372,6 +391,154 @@ public class PrepareReleaseMojo
|
||||||
throw new MojoExecutionException( "Can't transform pom to its release version form.", 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() )
|
||||||
|
{
|
||||||
|
Artifact parentArtifact = project.getParentArtifact();
|
||||||
|
|
||||||
|
if ( isSnapshot( parentArtifact.getBaseVersion() ) )
|
||||||
|
{
|
||||||
|
String version = resolveVersion( parentArtifact, "parent" );
|
||||||
|
|
||||||
|
model.getParent().setVersion( version );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//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 = releaseModel.getBuild().getPlugins().iterator(); j.hasNext(); )
|
||||||
|
{
|
||||||
|
Plugin plugin = (Plugin) j.next();
|
||||||
|
if ( ArtifactUtils.versionlessKey(artifact).equals( plugin.getKey() ) )
|
||||||
|
{
|
||||||
|
String version = resolveVersion( artifact, "plugin" );
|
||||||
|
|
||||||
|
plugin.setGroupId( artifact.getGroupId() );
|
||||||
|
plugin.setVersion( version );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Rewrite report version
|
||||||
|
for ( Iterator i = releaseProject.getReportArtifacts().iterator(); i.hasNext(); )
|
||||||
|
{
|
||||||
|
Artifact artifact = (Artifact) i.next();
|
||||||
|
if ( isSnapshot( artifact.getBaseVersion() ) )
|
||||||
|
{
|
||||||
|
List reportPlugins = releaseProject.getReportPlugins();
|
||||||
|
|
||||||
|
if ( reportPlugins != null )
|
||||||
|
{
|
||||||
|
for ( Iterator j = reportPlugins.iterator(); j.hasNext(); )
|
||||||
|
{
|
||||||
|
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
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
|
||||||
|
scm.setWorkingDirectory( basedir );
|
||||||
|
|
||||||
|
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 ( ScmException 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()
|
private void transformPomToSnapshotVersionPom()
|
||||||
throws MojoExecutionException
|
throws MojoExecutionException
|
||||||
|
@ -401,9 +568,7 @@ public class PrepareReleaseMojo
|
||||||
{
|
{
|
||||||
getLog().info( "What is the new version? [" + projectVersion + "]" );
|
getLog().info( "What is the new version? [" + projectVersion + "]" );
|
||||||
|
|
||||||
InputHandler handler = (InputHandler) getContainer().lookup( InputHandler.ROLE );
|
String inputVersion = inputHandler.readLine();
|
||||||
|
|
||||||
String inputVersion = handler.readLine();
|
|
||||||
|
|
||||||
if ( !StringUtils.isEmpty( inputVersion ) )
|
if ( !StringUtils.isEmpty( inputVersion ) )
|
||||||
{
|
{
|
||||||
|
@ -449,16 +614,16 @@ public class PrepareReleaseMojo
|
||||||
private void checkInReleaseVersionPom()
|
private void checkInReleaseVersionPom()
|
||||||
throws MojoExecutionException
|
throws MojoExecutionException
|
||||||
{
|
{
|
||||||
checkInPom( "[maven-release-plugin] prepare release " + projectVersion );
|
checkIn( "pom.xml,release-pom.xml", "[maven-release-plugin] prepare release " + projectVersion );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkInSnapshotVersionPom()
|
private void checkInSnapshotVersionPom()
|
||||||
throws MojoExecutionException
|
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
|
throws MojoExecutionException
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -472,7 +637,7 @@ public class PrepareReleaseMojo
|
||||||
// No tag here - we suppose user works on correct branch
|
// No tag here - we suppose user works on correct branch
|
||||||
scm.setTag( null );
|
scm.setTag( null );
|
||||||
|
|
||||||
scm.checkin( message, "pom.xml", null );
|
scm.checkin( message, includePattern, null );
|
||||||
|
|
||||||
scm.setTag( tag );
|
scm.setTag( tag );
|
||||||
}
|
}
|
||||||
|
@ -508,9 +673,7 @@ public class PrepareReleaseMojo
|
||||||
{
|
{
|
||||||
getLog().info( "What tag name should be used? [ " + tag + " ]" );
|
getLog().info( "What tag name should be used? [ " + tag + " ]" );
|
||||||
|
|
||||||
InputHandler handler = (InputHandler) getContainer().lookup( InputHandler.ROLE );
|
String inputTag = inputHandler.readLine();
|
||||||
|
|
||||||
String inputTag = handler.readLine();
|
|
||||||
|
|
||||||
if ( !StringUtils.isEmpty( inputTag ) )
|
if ( !StringUtils.isEmpty( inputTag ) )
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,6 +21,7 @@ import org.apache.maven.scm.ScmException;
|
||||||
import org.apache.maven.scm.ScmFileSet;
|
import org.apache.maven.scm.ScmFileSet;
|
||||||
import org.apache.maven.scm.ScmResult;
|
import org.apache.maven.scm.ScmResult;
|
||||||
import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
|
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.checkin.CheckInScmResult;
|
||||||
import org.apache.maven.scm.command.checkout.CheckOutScmResult;
|
import org.apache.maven.scm.command.checkout.CheckOutScmResult;
|
||||||
import org.apache.maven.scm.command.status.StatusScmResult;
|
import org.apache.maven.scm.command.status.StatusScmResult;
|
||||||
|
@ -174,6 +175,17 @@ public class ScmBean
|
||||||
|
|
||||||
return changedFiles;
|
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 )
|
public void checkin( String message, String includes, String excludes )
|
||||||
throws Exception
|
throws Exception
|
||||||
|
|
|
@ -16,7 +16,6 @@ package org.apache.maven.doxia;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.model.ReportPlugin;
|
import org.apache.maven.model.ReportPlugin;
|
||||||
|
@ -30,7 +29,6 @@ import org.apache.maven.plugin.version.PluginVersionResolutionException;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
import org.apache.maven.reporting.MavenReport;
|
import org.apache.maven.reporting.MavenReport;
|
||||||
import org.apache.maven.reporting.MavenReportException;
|
import org.apache.maven.reporting.MavenReportException;
|
||||||
import org.apache.maven.settings.Settings;
|
|
||||||
import org.codehaus.plexus.i18n.I18N;
|
import org.codehaus.plexus.i18n.I18N;
|
||||||
import org.codehaus.plexus.siterenderer.Renderer;
|
import org.codehaus.plexus.siterenderer.Renderer;
|
||||||
import org.codehaus.plexus.siterenderer.RendererException;
|
import org.codehaus.plexus.siterenderer.RendererException;
|
||||||
|
@ -100,13 +98,6 @@ public class DoxiaMojo
|
||||||
// Mac
|
// Mac
|
||||||
"**/.DS_Store"};
|
"**/.DS_Store"};
|
||||||
|
|
||||||
/**
|
|
||||||
* @parameter expression="${settings}"
|
|
||||||
* @required
|
|
||||||
* @readonly
|
|
||||||
*/
|
|
||||||
private Settings settings;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @parameter expression="${basedir}/src/site"
|
* @parameter expression="${basedir}/src/site"
|
||||||
* @required
|
* @required
|
||||||
|
@ -179,13 +170,6 @@ public class DoxiaMojo
|
||||||
*/
|
*/
|
||||||
private PluginManager pluginManager;
|
private PluginManager pluginManager;
|
||||||
|
|
||||||
/**
|
|
||||||
* @parameter expression="${localRepository}"
|
|
||||||
* @required
|
|
||||||
* @readonly
|
|
||||||
*/
|
|
||||||
private ArtifactRepository localRepository;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @parameter expression="${session}"
|
* @parameter expression="${session}"
|
||||||
* @required
|
* @required
|
||||||
|
@ -916,7 +900,7 @@ public class DoxiaMojo
|
||||||
|
|
||||||
if ( reportSets == null || reportSets.isEmpty() )
|
if ( reportSets == null || reportSets.isEmpty() )
|
||||||
{
|
{
|
||||||
reportsList = pluginManager.getReports( reportPlugin, null, project, session, localRepository );
|
reportsList = pluginManager.getReports( reportPlugin, null, project, session );
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -925,8 +909,7 @@ public class DoxiaMojo
|
||||||
{
|
{
|
||||||
ReportSet reportSet = (ReportSet) j.next();
|
ReportSet reportSet = (ReportSet) j.next();
|
||||||
|
|
||||||
reportsList = pluginManager.getReports( reportPlugin, reportSet, project, session,
|
reportsList = pluginManager.getReports( reportPlugin, reportSet, project, session );
|
||||||
localRepository );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.model.Parent;
|
import org.apache.maven.model.Parent;
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
import org.apache.maven.model.Profile;
|
import org.apache.maven.model.Profile;
|
||||||
|
import org.apache.maven.model.ReportPlugin;
|
||||||
import org.apache.maven.model.Repository;
|
import org.apache.maven.model.Repository;
|
||||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||||
import org.apache.maven.profiles.activation.ProfileActivationCalculator;
|
import org.apache.maven.profiles.activation.ProfileActivationCalculator;
|
||||||
|
@ -85,14 +86,16 @@ public class DefaultMavenProjectBuilder
|
||||||
// TODO: remove
|
// TODO: remove
|
||||||
private PlexusContainer container;
|
private PlexusContainer container;
|
||||||
|
|
||||||
private ArtifactResolver artifactResolver;
|
protected ArtifactResolver artifactResolver;
|
||||||
|
|
||||||
|
protected ArtifactMetadataSource artifactMetadataSource;
|
||||||
|
|
||||||
private ArtifactFactory artifactFactory;
|
private ArtifactFactory artifactFactory;
|
||||||
|
|
||||||
private ModelInheritanceAssembler modelInheritanceAssembler;
|
private ModelInheritanceAssembler modelInheritanceAssembler;
|
||||||
|
|
||||||
private ModelValidator validator;
|
private ModelValidator validator;
|
||||||
|
|
||||||
// TODO: make it a component
|
// TODO: make it a component
|
||||||
private MavenXpp3Reader modelReader;
|
private MavenXpp3Reader modelReader;
|
||||||
|
|
||||||
|
@ -125,22 +128,6 @@ public class DefaultMavenProjectBuilder
|
||||||
public MavenProject buildWithDependencies( File projectDescriptor, ArtifactRepository localRepository,
|
public MavenProject buildWithDependencies( File projectDescriptor, ArtifactRepository localRepository,
|
||||||
List externalProfiles )
|
List externalProfiles )
|
||||||
throws ProjectBuildingException, ArtifactResolutionException
|
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 );
|
MavenProject project = buildFromSourceFile( projectDescriptor, localRepository, externalProfiles );
|
||||||
|
|
||||||
|
@ -160,6 +147,9 @@ public class DefaultMavenProjectBuilder
|
||||||
Artifact projectArtifact = project.getArtifact();
|
Artifact projectArtifact = project.getArtifact();
|
||||||
|
|
||||||
Map managedVersions = createManagedVersionMap( project.getDependencyManagement() );
|
Map managedVersions = createManagedVersionMap( project.getDependencyManagement() );
|
||||||
|
|
||||||
|
ensureMetadataSourceIsInitialized();
|
||||||
|
|
||||||
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getDependencyArtifacts(),
|
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getDependencyArtifacts(),
|
||||||
projectArtifact, managedVersions,
|
projectArtifact, managedVersions,
|
||||||
localRepository,
|
localRepository,
|
||||||
|
@ -169,6 +159,22 @@ public class DefaultMavenProjectBuilder
|
||||||
project.setArtifacts( result.getArtifacts() );
|
project.setArtifacts( result.getArtifacts() );
|
||||||
return project;
|
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 )
|
private Map createManagedVersionMap( DependencyManagement dependencyManagement )
|
||||||
throws ProjectBuildingException
|
throws ProjectBuildingException
|
||||||
|
@ -330,10 +336,14 @@ public class DefaultMavenProjectBuilder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Model originalModel = ModelUtils.cloneModel( model );
|
||||||
|
|
||||||
List repositories = new ArrayList( aggregatedRemoteWagonRepositories );
|
List repositories = new ArrayList( aggregatedRemoteWagonRepositories );
|
||||||
|
|
||||||
MavenProject project = assembleLineage( model, lineage, repositories, localRepository );
|
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()
|
// we don't have to force the collision exception for superModel here, it's already been done in getSuperModel()
|
||||||
Model previous = superModel;
|
Model previous = superModel;
|
||||||
|
|
||||||
|
@ -636,6 +646,48 @@ public class DefaultMavenProjectBuilder
|
||||||
return pluginArtifacts;
|
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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return pluginArtifacts;
|
||||||
|
}
|
||||||
|
|
||||||
public MavenProject buildStandaloneSuperProject( ArtifactRepository localRepository, List externalProfiles )
|
public MavenProject buildStandaloneSuperProject( ArtifactRepository localRepository, List externalProfiles )
|
||||||
throws ProjectBuildingException
|
throws ProjectBuildingException
|
||||||
{
|
{
|
||||||
|
|
|
@ -111,6 +111,14 @@ public class MavenProject
|
||||||
// calculated.
|
// calculated.
|
||||||
private Map artifactMap;
|
private Map artifactMap;
|
||||||
|
|
||||||
|
private Model originalModel;
|
||||||
|
|
||||||
|
private Map pluginArtifactMap;
|
||||||
|
|
||||||
|
private Set reportArtifacts;
|
||||||
|
|
||||||
|
private Map reportArtifactMap;
|
||||||
|
|
||||||
public MavenProject( Model model )
|
public MavenProject( Model model )
|
||||||
{
|
{
|
||||||
this.model = model;
|
this.model = model;
|
||||||
|
@ -810,7 +818,7 @@ public class MavenProject
|
||||||
{
|
{
|
||||||
if ( artifactMap == null )
|
if ( artifactMap == null )
|
||||||
{
|
{
|
||||||
artifactMap = ArtifactUtils.artifactMap( getArtifacts() );
|
artifactMap = ArtifactUtils.artifactMapByVersionlessId( getArtifacts() );
|
||||||
}
|
}
|
||||||
|
|
||||||
return artifactMap;
|
return artifactMap;
|
||||||
|
@ -825,6 +833,36 @@ public class MavenProject
|
||||||
{
|
{
|
||||||
return pluginArtifacts;
|
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 )
|
public void setParentArtifact( Artifact parentArtifact )
|
||||||
{
|
{
|
||||||
|
@ -1096,6 +1134,14 @@ public class MavenProject
|
||||||
pomWriter.write( writer, getModel() );
|
pomWriter.write( writer, getModel() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void writeOriginalModel( Writer writer )
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
MavenXpp3Writer pomWriter = new MavenXpp3Writer();
|
||||||
|
|
||||||
|
pomWriter.write( writer, getOriginalModel() );
|
||||||
|
}
|
||||||
|
|
||||||
public Set getDependencyArtifacts()
|
public Set getDependencyArtifacts()
|
||||||
{
|
{
|
||||||
return dependencyArtifacts;
|
return dependencyArtifacts;
|
||||||
|
@ -1105,4 +1151,38 @@ public class MavenProject
|
||||||
{
|
{
|
||||||
this.dependencyArtifacts = dependencyArtifacts;
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ package org.apache.maven.project;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
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.repository.ArtifactRepository;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||||
|
|
||||||
|
@ -37,10 +36,6 @@ public interface MavenProjectBuilder
|
||||||
MavenProject build( File project, ArtifactRepository localRepository, List profiles )
|
MavenProject build( File project, ArtifactRepository localRepository, List profiles )
|
||||||
throws ProjectBuildingException;
|
throws ProjectBuildingException;
|
||||||
|
|
||||||
MavenProject buildWithDependencies( File project, ArtifactRepository localRepository,
|
|
||||||
ArtifactMetadataSource artifactMetadataSource, List externalProfiles )
|
|
||||||
throws ProjectBuildingException, ArtifactResolutionException;
|
|
||||||
|
|
||||||
MavenProject buildWithDependencies( File project, ArtifactRepository localRepository, List externalProfiles )
|
MavenProject buildWithDependencies( File project, ArtifactRepository localRepository, List externalProfiles )
|
||||||
throws ProjectBuildingException, ArtifactResolutionException;
|
throws ProjectBuildingException, ArtifactResolutionException;
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,9 @@ public class MavenMetadataSource
|
||||||
extends AbstractLogEnabled
|
extends AbstractLogEnabled
|
||||||
implements ArtifactMetadataSource
|
implements ArtifactMetadataSource
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public static final String ROLE_HINT = "maven";
|
||||||
|
|
||||||
private MavenProjectBuilder mavenProjectBuilder;
|
private MavenProjectBuilder mavenProjectBuilder;
|
||||||
|
|
||||||
private ArtifactFactory artifactFactory;
|
private ArtifactFactory artifactFactory;
|
||||||
|
|
|
@ -114,6 +114,7 @@
|
||||||
<role>org.apache.maven.project.inheritance.ModelInheritanceAssembler</role>
|
<role>org.apache.maven.project.inheritance.ModelInheritanceAssembler</role>
|
||||||
<implementation>org.apache.maven.project.inheritance.DefaultModelInheritanceAssembler</implementation>
|
<implementation>org.apache.maven.project.inheritance.DefaultModelInheritanceAssembler</implementation>
|
||||||
</component>
|
</component>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
|
|
|
|
||||||
|
|
|
|
||||||
|
@ -124,8 +125,28 @@
|
||||||
<implementation>org.apache.maven.project.validation.DefaultModelValidator</implementation>
|
<implementation>org.apache.maven.project.validation.DefaultModelValidator</implementation>
|
||||||
</component>
|
</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>
|
<component>
|
||||||
<role>org.apache.maven.artifact.metadata.ArtifactMetadataSource</role>
|
<role>org.apache.maven.artifact.metadata.ArtifactMetadataSource</role>
|
||||||
|
<role-hint>maven</role-hint>
|
||||||
<implementation>org.apache.maven.project.artifact.MavenMetadataSource</implementation>
|
<implementation>org.apache.maven.project.artifact.MavenMetadataSource</implementation>
|
||||||
<requirements>
|
<requirements>
|
||||||
<requirement>
|
<requirement>
|
||||||
|
@ -136,13 +157,5 @@
|
||||||
</requirement>
|
</requirement>
|
||||||
</requirements>
|
</requirements>
|
||||||
</component>
|
</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>
|
</components>
|
||||||
</component-set>
|
</component-set>
|
||||||
|
|
|
@ -16,12 +16,11 @@ package org.apache.maven.project;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
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.DefaultArtifactRepository;
|
||||||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
|
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
|
||||||
import org.codehaus.plexus.PlexusTestCase;
|
import org.codehaus.plexus.PlexusTestCase;
|
||||||
|
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
@ -37,18 +36,22 @@ public abstract class MavenProjectTestCase
|
||||||
{
|
{
|
||||||
protected MavenProjectBuilder projectBuilder;
|
protected MavenProjectBuilder projectBuilder;
|
||||||
|
|
||||||
private ArtifactFactory artifactFactory;
|
|
||||||
|
|
||||||
private ArtifactRepositoryFactory artifactRepositoryFactory;
|
|
||||||
|
|
||||||
protected void setUp()
|
protected void setUp()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
|
try
|
||||||
artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
|
{
|
||||||
artifactRepositoryFactory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
|
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 @@ public abstract class MavenProjectTestCase
|
||||||
protected MavenProject getProjectWithDependencies( File pom )
|
protected MavenProject getProjectWithDependencies( File pom )
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
return projectBuilder.buildWithDependencies( pom, getLocalRepository(), new TestArtifactResolver.Source(
|
return projectBuilder.buildWithDependencies( pom, getLocalRepository(), Collections.EMPTY_LIST );
|
||||||
artifactFactory, artifactRepositoryFactory, getContainer() ), Collections.EMPTY_LIST );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MavenProject getProject( File pom )
|
protected MavenProject getProject( File pom )
|
||||||
|
|
|
@ -19,7 +19,6 @@ package org.apache.maven.project;
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,16 +34,14 @@ public class ProjectClasspathTest
|
||||||
{
|
{
|
||||||
File f = getFileForClasspathResource( dir + "project-with-scoped-dependencies.xml" );
|
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() );
|
// assertEquals( TestArtifactResolver.class, getContainer().lookup( ArtifactResolver.ROLE ).getClass() );
|
||||||
MavenProjectBuilder builder = (MavenProjectBuilder) getContainer().lookup( MavenProjectBuilder.ROLE );
|
TestProjectBuilder builder = (TestProjectBuilder) getContainer().lookup( MavenProjectBuilder.ROLE, "test" );
|
||||||
Field declaredField = builder.getClass().getDeclaredField( "artifactResolver" );
|
|
||||||
boolean acc = declaredField.isAccessible();
|
TestArtifactResolver testArtifactResolver = (TestArtifactResolver) getContainer().lookup( TestArtifactResolver.class.getName() );
|
||||||
declaredField.setAccessible( true );
|
|
||||||
declaredField.set( builder, getContainer().lookup( TestArtifactResolver.class.getName() ) );
|
builder.setArtifactResolver( testArtifactResolver );
|
||||||
declaredField.setAccessible( acc );
|
builder.setArtifactMetadataSource( testArtifactResolver.source() );
|
||||||
// XXX: end hack
|
|
||||||
|
|
||||||
MavenProject project = getProjectWithDependencies( f );
|
MavenProject project = getProjectWithDependencies( f );
|
||||||
|
|
||||||
Artifact artifact;
|
Artifact artifact;
|
||||||
|
|
|
@ -52,6 +52,8 @@ public class TestArtifactResolver
|
||||||
extends DefaultArtifactResolver
|
extends DefaultArtifactResolver
|
||||||
implements Contextualizable
|
implements Contextualizable
|
||||||
{
|
{
|
||||||
|
public static final String ROLE = TestArtifactResolver.class.getName();
|
||||||
|
|
||||||
private ArtifactRepositoryFactory repositoryFactory;
|
private ArtifactRepositoryFactory repositoryFactory;
|
||||||
|
|
||||||
private PlexusContainer container;
|
private PlexusContainer container;
|
||||||
|
@ -155,6 +157,11 @@ public class TestArtifactResolver
|
||||||
return projectArtifacts;
|
return projectArtifacts;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Source source()
|
||||||
|
{
|
||||||
|
return new Source( artifactFactory, repositoryFactory, container );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @noinspection RefusedBequest
|
* @noinspection RefusedBequest
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -32,5 +32,39 @@
|
||||||
</requirement>
|
</requirement>
|
||||||
</requirements>
|
</requirements>
|
||||||
</component>
|
</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>
|
</components>
|
||||||
</plexus>
|
</plexus>
|
Loading…
Reference in New Issue