Resolving: MNG-878, MNG-880 (again)

o Added full resolution of plugins listed in the project hierarchy
o Added better resolution of snapshots within the reactor, and resolution of ${finalName}
o Added usage of fully inherited model for release-pom.xml, to enable convergence of all POM inheritance to a single POM with no parent.
o Improved handling of SCM info in a reactored situation.



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@290221 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-09-19 17:58:46 +00:00
parent 3ff84a5786
commit 23af50ef4a
14 changed files with 344 additions and 72 deletions

View File

@ -3,6 +3,12 @@
<groupId>org.apache.maven.it2002</groupId> <groupId>org.apache.maven.it2002</groupId>
<artifactId>project</artifactId> <artifactId>project</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>subproject</module>
<module>subproject2</module>
</modules>
<dependencies> <dependencies>
<dependency> <dependency>
@ -11,18 +17,6 @@
<version>1.0-alpha-6</version> <version>1.0-alpha-6</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>2.0-beta-1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact-manager</artifactId>
<version>2.0-beta-1</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<repositories> <repositories>
@ -56,20 +50,21 @@
<tagBase>file://${project.file.parentFile.parentFile}/target/svnroot/project/tags</tagBase> <tagBase>file://${project.file.parentFile.parentFile}/target/svnroot/project/tags</tagBase>
</properties> </properties>
<!-- build> <build>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>2.0-beta-1-SNAPSHOT</version> <version>2.0-beta-1</version>
</plugin> </plugin>
</plugins> </plugins>
</build --> </build>
<reporting> <reporting>
<plugins> <plugins>
<plugin> <plugin>
<artifactId>maven-project-info-reports-plugin</artifactId> <artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.0-alpha-1</version>
</plugin> </plugin>
</plugins> </plugins>
</reporting> </reporting>

View File

@ -0,0 +1,26 @@
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.maven.it2002</groupId>
<artifactId>project</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>project-sub1</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>2.0-beta-1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact-manager</artifactId>
<version>2.0-beta-1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,31 @@
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.maven.it2002</groupId>
<artifactId>project</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>project-sub2</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.maven.it2002</groupId>
<artifactId>project-sub1</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>2.0-beta-1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact-manager</artifactId>
<version>2.0-beta-1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,9 @@
package org.apache.maven.it2002;
public class Thing
{
public static final String ROLE = Thing.class.getName();
private String type;
}

View File

@ -0,0 +1,8 @@
<component-set>
<components>
<component>
<role>org.apache.maven.it2002.Thing</role>
<implementation>org.apache.maven.it2002.Thing</implementation>
</component>
</components>
</component-set>

View File

@ -0,0 +1,20 @@
package org.apache.maven.it2002;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.codehaus.plexus.PlexusTestCase;
public class ContainerDependentTest extends PlexusTestCase
{
public void testOne() throws Exception
{
ArtifactResolver resolver = (ArtifactResolver) lookup( ArtifactResolver.ROLE );
assertNotNull( resolver );
Thing thing = (Thing) lookup( Thing.ROLE );
assertNotNull( thing );
}
}

View File

@ -10,6 +10,16 @@
<name>Maven Release plugin</name> <name>Maven Release plugin</name>
<version>2.0-beta-2-SNAPSHOT</version> <version>2.0-beta-2-SNAPSHOT</version>
<dependencies> <dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>2.0-beta-1</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>2.0-beta-1</version>
</dependency>
<dependency> <dependency>
<groupId>org.apache.maven.scm</groupId> <groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-api</artifactId> <artifactId>maven-scm-api</artifactId>
@ -50,4 +60,4 @@
<version>1.0-alpha-2</version> <version>1.0-alpha-2</version>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -31,7 +31,10 @@ import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginManagement; import org.apache.maven.model.PluginManagement;
import org.apache.maven.model.ReportPlugin; import org.apache.maven.model.ReportPlugin;
import org.apache.maven.model.Reporting; import org.apache.maven.model.Reporting;
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.version.PluginVersionManager;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.plugins.release.helpers.ProjectScmRewriter; import org.apache.maven.plugins.release.helpers.ProjectScmRewriter;
import org.apache.maven.plugins.release.helpers.ProjectVersionResolver; import org.apache.maven.plugins.release.helpers.ProjectVersionResolver;
import org.apache.maven.plugins.release.helpers.ReleaseProgressTracker; import org.apache.maven.plugins.release.helpers.ReleaseProgressTracker;
@ -39,6 +42,7 @@ import org.apache.maven.plugins.release.helpers.ScmHelper;
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.settings.Settings;
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.IOUtil;
import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.StringUtils;
@ -90,12 +94,15 @@ public class PrepareReleaseMojo
private boolean interactive; private boolean interactive;
/** /**
* @parameter expression="${component.org.apache.maven.artifact.metadata.ArtifactMetadataSource}" * @component role="org.apache.maven.artifact.metadata.ArtifactMetadataSource"
* @required
* @readonly
*/ */
private ArtifactMetadataSource artifactMetadataSource; private ArtifactMetadataSource artifactMetadataSource;
/**
* @component role="org.apache.maven.plugin.version.PluginVersionManager"
*/
private PluginVersionManager pluginVersionManager;
/** /**
* @parameter expression="${component.org.codehaus.plexus.components.inputhandler.InputHandler}" * @parameter expression="${component.org.codehaus.plexus.components.inputhandler.InputHandler}"
* @required * @required
@ -109,6 +116,13 @@ public class PrepareReleaseMojo
* @readonly * @readonly
*/ */
private ArtifactRepository localRepository; private ArtifactRepository localRepository;
/**
* @parameter expression="${settings}"
* @required
* @readonly
*/
private Settings settings;
/** /**
* @parameter expression="${reactorProjects}" * @parameter expression="${reactorProjects}"
@ -239,7 +253,7 @@ public class PrepareReleaseMojo
} }
} }
removeReleasePoms(); // removeReleasePoms();
checkInNextSnapshot(); checkInNextSnapshot();
@ -819,17 +833,37 @@ public class PrepareReleaseMojo
MavenProject project = (MavenProject) it.next(); MavenProject project = (MavenProject) it.next();
MavenProject releaseProject = new MavenProject( project ); MavenProject releaseProject = new MavenProject( project );
Model releaseModel = releaseProject.getOriginalModel(); Model releaseModel = releaseProject.getModel();
fixNullValueInModel( releaseModel, project.getOriginalModel() ); fixNullValueInModel( releaseModel, project.getModel() );
// Remove parent String projectVersion = releaseModel.getVersion();
/* TODO: put this back after it is properly resolved again if ( ArtifactUtils.isSnapshot( projectVersion ) )
if ( releaseModel.getParent() != null )
{ {
releaseModel.setParent( null ); String snapshotVersion = projectVersion;
projectVersion = getVersionResolver().getResolvedVersion( releaseModel.getGroupId(), releaseModel.getArtifactId() );
if ( ArtifactUtils.isSnapshot( projectVersion ) )
{
throw new MojoExecutionException( "MAJOR PROBLEM!!! Cannot find resolved version to be used in releasing project: " + releaseProject.getId() );
}
releaseModel.setVersion( projectVersion );
String finalName = releaseModel.getBuild().getFinalName();
if ( finalName.equals( releaseModel.getArtifactId() + "-" + snapshotVersion ) )
{
releaseModel.getBuild().setFinalName( releaseModel.getArtifactId() + "-" + projectVersion );
}
else if ( finalName.indexOf( "SNAPSHOT" ) > -1 )
{
throw new MojoExecutionException( "Cannot reliably adjust the finalName of project: " + releaseProject.getId() );
}
} }
releaseModel.setParent( null );
*/
Set artifacts = releaseProject.getArtifacts(); Set artifacts = releaseProject.getArtifacts();
if ( artifacts != null ) if ( artifacts != null )
@ -840,12 +874,24 @@ public class PrepareReleaseMojo
for ( Iterator i = releaseProject.getArtifacts().iterator(); i.hasNext(); ) for ( Iterator i = releaseProject.getArtifacts().iterator(); i.hasNext(); )
{ {
Artifact artifact = (Artifact) i.next(); Artifact artifact = (Artifact) i.next();
Dependency newdep = new Dependency(); Dependency newdep = new Dependency();
newdep.setArtifactId( artifact.getArtifactId() ); newdep.setArtifactId( artifact.getArtifactId() );
newdep.setGroupId( artifact.getGroupId() ); newdep.setGroupId( artifact.getGroupId() );
newdep.setVersion( artifact.getVersion() );
String version = artifact.getVersion();
if ( artifact.isSnapshot() )
{
version = getVersionResolver().getResolvedVersion(artifact.getGroupId(), artifact.getArtifactId() );
if ( ArtifactUtils.isSnapshot( version ) )
{
throw new MojoExecutionException( "Unresolved SNAPSHOT version of: " + artifact.getId() + ". Cannot proceed with release." );
}
}
newdep.setVersion( version );
newdep.setType( artifact.getType() ); newdep.setType( artifact.getType() );
newdep.setScope( artifact.getScope() ); newdep.setScope( artifact.getScope() );
newdep.setClassifier( artifact.getClassifier() ); newdep.setClassifier( artifact.getClassifier() );
@ -858,21 +904,30 @@ public class PrepareReleaseMojo
// Use original - don't want the lifecycle introduced ones // Use original - don't want the lifecycle introduced ones
// TODO: but is it the right settings? // TODO: but is it the right settings?
Build originalModel = releaseProject.getOriginalModel().getBuild(); Build model = releaseProject.getModel().getBuild();
List plugins = originalModel != null ? originalModel.getPlugins() : null; List plugins = model != null ? model.getPlugins() : null;
if ( plugins != null ) if ( plugins != null )
{ {
//Rewrite plugins version //Rewrite plugins version
Map pluginArtifacts = releaseProject.getPluginArtifactMap();
for ( Iterator i = plugins.iterator(); i.hasNext(); ) for ( Iterator i = plugins.iterator(); i.hasNext(); )
{ {
Plugin plugin = (Plugin) i.next(); Plugin plugin = (Plugin) i.next();
Artifact artifact = (Artifact) pluginArtifacts.get( plugin.getKey() ); String version;
try
String version = resolveVersion( artifact, "plugin", releaseProject ); {
version = pluginVersionManager.resolvePluginVersion( plugin.getGroupId(), plugin.getArtifactId(), project, settings, localRepository );
}
catch ( PluginVersionResolutionException e )
{
throw new MojoExecutionException( "Cannot resolve version for plugin: " + plugin );
}
if ( ArtifactUtils.isSnapshot(version))
{
throw new MojoExecutionException( "Resolved version of plugin is a snapshot. Please release this plugin before releasing this project.\n\nGroupId: " + plugin.getGroupId() + "\nArtifactId: " + plugin.getArtifactId() + "\nResolved Version: " + version + "\n\n" );
}
plugin.setVersion( version ); plugin.setVersion( version );
} }
@ -883,21 +938,25 @@ public class PrepareReleaseMojo
if ( reports != null ) if ( reports != null )
{ {
//Rewrite report version //Rewrite report version
Map reportArtifacts = releaseProject.getReportArtifactMap();
getLog().info( "Using report-artifact map with " + reportArtifacts.size() + " entries." );
for ( Iterator i = reports.iterator(); i.hasNext(); ) for ( Iterator i = reports.iterator(); i.hasNext(); )
{ {
ReportPlugin plugin = (ReportPlugin) i.next(); ReportPlugin plugin = (ReportPlugin) i.next();
String pluginKey = plugin.getKey(); String version;
try
{
version = pluginVersionManager.resolvePluginVersion( plugin.getGroupId(), plugin
.getArtifactId(), project, settings, localRepository, true );
}
catch ( PluginVersionResolutionException e )
{
throw new MojoExecutionException( "Cannot resolve version for report plugin: " + plugin );
}
getLog().info( "Looking up report artifact for: \'" + pluginKey + "\'" ); if ( ArtifactUtils.isSnapshot(version))
{
Artifact artifact = (Artifact) reportArtifacts.get( pluginKey ); throw new MojoExecutionException( "Resolved version of plugin is a snapshot. Please release this report plugin before releasing this project.\n\nGroupId: " + plugin.getGroupId() + "\nArtifactId: " + plugin.getArtifactId() + "\nResolved Version: " + version + "\n\n" );
}
String version = resolveVersion( artifact, "report", releaseProject );
plugin.setVersion( version ); plugin.setVersion( version );
} }
@ -923,6 +982,15 @@ public class PrepareReleaseMojo
ext.setVersion( version ); ext.setVersion( version );
} }
} }
try
{
relativizeBuildPaths( model, project.getFile().getParentFile().getCanonicalPath() );
}
catch ( IOException e )
{
throw new MojoExecutionException( "Cannot relativize build paths for: " + project.getId(), e );
}
File releasePomFile = new File( releaseProject.getFile().getParentFile(), RELEASE_POM ); File releasePomFile = new File( releaseProject.getFile().getParentFile(), RELEASE_POM );
@ -932,7 +1000,7 @@ public class PrepareReleaseMojo
{ {
writer = new FileWriter( releasePomFile ); writer = new FileWriter( releasePomFile );
releaseProject.writeOriginalModel( writer ); releaseProject.writeModel( writer );
} }
catch ( IOException e ) catch ( IOException e )
{ {
@ -974,6 +1042,77 @@ public class PrepareReleaseMojo
} }
} }
private void relativizeBuildPaths( Build build, String canonicalBasedir )
{
int basePathLength = canonicalBasedir.length() + 1;
String directory = build.getDirectory();
if ( directory.startsWith( canonicalBasedir ) )
{
build.setDirectory( directory.substring( basePathLength ) );
}
String outDir = build.getOutputDirectory();
if ( outDir.startsWith( canonicalBasedir ) )
{
build.setOutputDirectory( outDir.substring( basePathLength ) );
}
String testOutDir = build.getTestOutputDirectory();
if ( testOutDir.startsWith( canonicalBasedir ) )
{
build.setTestOutputDirectory( testOutDir.substring( basePathLength ) );
}
String srcDir = build.getSourceDirectory();
if ( srcDir.startsWith( canonicalBasedir ) )
{
build.setSourceDirectory( srcDir.substring( basePathLength ) );
}
String scriptSrcDir = build.getScriptSourceDirectory();
if ( scriptSrcDir.startsWith( canonicalBasedir ) )
{
build.setScriptSourceDirectory( scriptSrcDir.substring( basePathLength ) );
}
String testSrcDir = build.getTestSourceDirectory();
if ( testSrcDir.startsWith( canonicalBasedir ) )
{
build.setTestSourceDirectory( testSrcDir.substring( basePathLength ) );
}
List resources = build.getResources();
if ( resources != null )
{
for ( Iterator it = resources.iterator(); it.hasNext(); )
{
Resource resource = (Resource) it.next();
String dir = resource.getDirectory();
if ( dir.startsWith( canonicalBasedir ) )
{
resource.setDirectory( dir.substring( basePathLength ) );
}
}
}
List testResources = build.getTestResources();
if ( testResources != null )
{
for ( Iterator it = testResources.iterator(); it.hasNext(); )
{
Resource resource = (Resource) it.next();
String dir = resource.getDirectory();
if ( dir.startsWith( canonicalBasedir ) )
{
resource.setDirectory( dir.substring( basePathLength ) );
}
}
}
}
private void fixNullValueInModel( Model modelToFix, Model correctModel ) private void fixNullValueInModel( Model modelToFix, Model correctModel )
{ {
if ( modelToFix.getModelVersion() != null ) if ( modelToFix.getModelVersion() != null )
@ -1054,7 +1193,6 @@ public class PrepareReleaseMojo
private String resolveVersion( Artifact artifact, String artifactUsage, MavenProject project ) private String resolveVersion( Artifact artifact, String artifactUsage, MavenProject project )
throws MojoExecutionException throws MojoExecutionException
{ {
getLog().info( "Resolving version for: " + artifact );
String resolvedVersion = getVersionResolver().getResolvedVersion( artifact.getGroupId(), String resolvedVersion = getVersionResolver().getResolvedVersion( artifact.getGroupId(),
artifact.getArtifactId() ); artifact.getArtifactId() );

View File

@ -37,12 +37,6 @@ public class ProjectScmRewriter
{ {
String projectId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() ); String projectId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
if ( project.getScm() == null )
{
throw new MojoExecutionException(
"Project: " + projectId + " does not have a SCM section! Cannot proceed with release." );
}
Model model = project.getOriginalModel(); Model model = project.getOriginalModel();
Scm scm = model.getScm(); Scm scm = model.getScm();
@ -75,8 +69,18 @@ public class ProjectScmRewriter
if ( scmConnection != null && scmConnection.startsWith( "scm:svn" ) ) if ( scmConnection != null && scmConnection.startsWith( "scm:svn" ) )
{ {
scm.setConnection( convertSvnConnectionString( scmConnection, tag ) ); scm.setConnection( convertSvnConnectionString( scmConnection, tag ) );
scm.setDeveloperConnection( convertSvnConnectionString( scm.getDeveloperConnection(), tag ) );
scm.setUrl( convertSvnConnectionString( scm.getUrl(), tag ) ); String devConnection = scm.getDeveloperConnection();
if ( devConnection != null )
{
scm.setDeveloperConnection( convertSvnConnectionString( devConnection, tag ) );
}
String url = scm.getUrl();
if ( url != null )
{
scm.setUrl( convertSvnConnectionString( url, tag ) );
}
} }
} }
} }

View File

@ -198,25 +198,56 @@ public class ReleaseProgressTracker
public void addOriginalScmInfo( String projectId, Scm scm ) public void addOriginalScmInfo( String projectId, Scm scm )
{ {
releaseProperties.setProperty( SCM_INFO_PREFIX + projectId + ".connection", scm.getConnection() ); String connection = scm.getConnection();
releaseProperties.setProperty( SCM_INFO_PREFIX + projectId + ".developerConnection", if ( connection != null )
scm.getDeveloperConnection() ); {
releaseProperties.setProperty( SCM_INFO_PREFIX + projectId + ".url", scm.getUrl() ); releaseProperties.setProperty( SCM_INFO_PREFIX + projectId + ".connection", connection );
releaseProperties.setProperty( SCM_INFO_PREFIX + projectId + ".tag", scm.getTag() ); }
String devConnection = scm.getDeveloperConnection();
if ( devConnection != null )
{
releaseProperties.setProperty( SCM_INFO_PREFIX + projectId + ".developerConnection",
devConnection );
}
String url = scm.getUrl();
if ( url != null )
{
releaseProperties.setProperty( SCM_INFO_PREFIX + projectId + ".url", url );
}
String tag = scm.getTag();
if ( tag != null )
{
releaseProperties.setProperty( SCM_INFO_PREFIX + projectId + ".tag", tag );
}
} }
public void restoreScmInfo( String projectId, Scm scm ) public void restoreScmInfo( String projectId, Scm scm )
{ {
String connection = releaseProperties.getProperty( SCM_INFO_PREFIX + projectId + ".connection" ); String connection = releaseProperties.getProperty( SCM_INFO_PREFIX + projectId + ".connection" );
if ( connection == null ) if ( connection != null )
{ {
throw new IllegalArgumentException( scm.setConnection( connection );
"Project \'" + projectId + "\' has not had its SCM info cached. Cannot restore uncached SCM info." ); }
String devConnection = releaseProperties.getProperty( SCM_INFO_PREFIX + projectId + ".connection" );
if ( devConnection != null )
{
scm.setDeveloperConnection( devConnection );
}
String url = releaseProperties.getProperty( SCM_INFO_PREFIX + projectId + ".url" );
if ( url != null )
{
scm.setUrl( url );
}
String tag = releaseProperties.getProperty( SCM_INFO_PREFIX + projectId + ".tag" );
if ( tag != null )
{
scm.setTag( tag );
} }
scm.setConnection( connection );
scm.setDeveloperConnection(
releaseProperties.getProperty( SCM_INFO_PREFIX + projectId + ".developerConnection" ) );
scm.setUrl( releaseProperties.getProperty( SCM_INFO_PREFIX + projectId + ".url" ) );
scm.setTag( releaseProperties.getProperty( SCM_INFO_PREFIX + projectId + ".tag" ) );
} }
} }

View File

@ -152,7 +152,7 @@
<module>maven-assembly-plugin</module> <module>maven-assembly-plugin</module>
<module>maven-checkstyle-plugin</module> <module>maven-checkstyle-plugin</module>
<module>maven-clean-plugin</module> <module>maven-clean-plugin</module>
<module>maven-clover-plugin</module> <!-- module>maven-clover-plugin</module -->
<module>maven-compiler-plugin</module> <module>maven-compiler-plugin</module>
<module>maven-deploy-plugin</module> <module>maven-deploy-plugin</module>
<module>maven-eclipse-plugin</module> <module>maven-eclipse-plugin</module>