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

View File

@ -31,7 +31,10 @@ import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginManagement;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.model.Reporting;
import org.apache.maven.model.Resource;
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.ProjectVersionResolver;
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.scm.ScmException;
import org.apache.maven.scm.ScmFile;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.components.inputhandler.InputHandler;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;
@ -90,12 +94,15 @@ public class PrepareReleaseMojo
private boolean interactive;
/**
* @parameter expression="${component.org.apache.maven.artifact.metadata.ArtifactMetadataSource}"
* @required
* @readonly
* @component role="org.apache.maven.artifact.metadata.ArtifactMetadataSource"
*/
private ArtifactMetadataSource artifactMetadataSource;
/**
* @component role="org.apache.maven.plugin.version.PluginVersionManager"
*/
private PluginVersionManager pluginVersionManager;
/**
* @parameter expression="${component.org.codehaus.plexus.components.inputhandler.InputHandler}"
* @required
@ -110,6 +117,13 @@ public class PrepareReleaseMojo
*/
private ArtifactRepository localRepository;
/**
* @parameter expression="${settings}"
* @required
* @readonly
*/
private Settings settings;
/**
* @parameter expression="${reactorProjects}"
* @required
@ -239,7 +253,7 @@ public class PrepareReleaseMojo
}
}
removeReleasePoms();
// removeReleasePoms();
checkInNextSnapshot();
@ -819,17 +833,37 @@ public class PrepareReleaseMojo
MavenProject project = (MavenProject) it.next();
MavenProject releaseProject = new MavenProject( project );
Model releaseModel = releaseProject.getOriginalModel();
fixNullValueInModel( releaseModel, project.getOriginalModel() );
Model releaseModel = releaseProject.getModel();
fixNullValueInModel( releaseModel, project.getModel() );
// Remove parent
/* TODO: put this back after it is properly resolved again
if ( releaseModel.getParent() != null )
String projectVersion = releaseModel.getVersion();
if ( ArtifactUtils.isSnapshot( projectVersion ) )
{
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();
if ( artifacts != null )
@ -845,7 +879,19 @@ public class PrepareReleaseMojo
newdep.setArtifactId( artifact.getArtifactId() );
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.setScope( artifact.getScope() );
newdep.setClassifier( artifact.getClassifier() );
@ -858,21 +904,30 @@ public class PrepareReleaseMojo
// Use original - don't want the lifecycle introduced ones
// TODO: but is it the right settings?
Build originalModel = releaseProject.getOriginalModel().getBuild();
List plugins = originalModel != null ? originalModel.getPlugins() : null;
Build model = releaseProject.getModel().getBuild();
List plugins = model != null ? model.getPlugins() : null;
if ( plugins != null )
{
//Rewrite plugins version
Map pluginArtifacts = releaseProject.getPluginArtifactMap();
for ( Iterator i = plugins.iterator(); i.hasNext(); )
{
Plugin plugin = (Plugin) i.next();
Artifact artifact = (Artifact) pluginArtifacts.get( plugin.getKey() );
String version;
try
{
version = pluginVersionManager.resolvePluginVersion( plugin.getGroupId(), plugin.getArtifactId(), project, settings, localRepository );
}
catch ( PluginVersionResolutionException e )
{
throw new MojoExecutionException( "Cannot resolve version for plugin: " + plugin );
}
String version = resolveVersion( artifact, "plugin", releaseProject );
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 );
}
@ -883,21 +938,25 @@ public class PrepareReleaseMojo
if ( reports != null )
{
//Rewrite report version
Map reportArtifacts = releaseProject.getReportArtifactMap();
getLog().info( "Using report-artifact map with " + reportArtifacts.size() + " entries." );
for ( Iterator i = reports.iterator(); i.hasNext(); )
{
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 + "\'" );
Artifact artifact = (Artifact) reportArtifacts.get( pluginKey );
String version = resolveVersion( artifact, "report", releaseProject );
if ( ArtifactUtils.isSnapshot(version))
{
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" );
}
plugin.setVersion( version );
}
@ -924,6 +983,15 @@ public class PrepareReleaseMojo
}
}
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 );
Writer writer = null;
@ -932,7 +1000,7 @@ public class PrepareReleaseMojo
{
writer = new FileWriter( releasePomFile );
releaseProject.writeOriginalModel( writer );
releaseProject.writeModel( writer );
}
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 )
{
if ( modelToFix.getModelVersion() != null )
@ -1054,7 +1193,6 @@ public class PrepareReleaseMojo
private String resolveVersion( Artifact artifact, String artifactUsage, MavenProject project )
throws MojoExecutionException
{
getLog().info( "Resolving version for: " + artifact );
String resolvedVersion = getVersionResolver().getResolvedVersion( artifact.getGroupId(),
artifact.getArtifactId() );

View File

@ -37,12 +37,6 @@ public class ProjectScmRewriter
{
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();
Scm scm = model.getScm();
@ -75,8 +69,18 @@ public class ProjectScmRewriter
if ( scmConnection != null && scmConnection.startsWith( "scm:svn" ) )
{
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 )
{
releaseProperties.setProperty( SCM_INFO_PREFIX + projectId + ".connection", scm.getConnection() );
releaseProperties.setProperty( SCM_INFO_PREFIX + projectId + ".developerConnection",
scm.getDeveloperConnection() );
releaseProperties.setProperty( SCM_INFO_PREFIX + projectId + ".url", scm.getUrl() );
releaseProperties.setProperty( SCM_INFO_PREFIX + projectId + ".tag", scm.getTag() );
String connection = scm.getConnection();
if ( connection != null )
{
releaseProperties.setProperty( SCM_INFO_PREFIX + projectId + ".connection", connection );
}
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 )
{
String connection = releaseProperties.getProperty( SCM_INFO_PREFIX + projectId + ".connection" );
if ( connection == null )
if ( connection != null )
{
throw new IllegalArgumentException(
"Project \'" + projectId + "\' has not had its SCM info cached. Cannot restore uncached SCM info." );
scm.setConnection( connection );
}
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-checkstyle-plugin</module>
<module>maven-clean-plugin</module>
<module>maven-clover-plugin</module>
<!-- module>maven-clover-plugin</module -->
<module>maven-compiler-plugin</module>
<module>maven-deploy-plugin</module>
<module>maven-eclipse-plugin</module>