mirror of https://github.com/apache/maven.git
PR: MNG-1060, 1061
corrections to the model used for the release plugin git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@293076 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ad0d7ac805
commit
9382b9c8d9
|
@ -30,8 +30,8 @@ public final class ArtifactUtils
|
||||||
|
|
||||||
public static boolean isSnapshot( String version )
|
public static boolean isSnapshot( String version )
|
||||||
{
|
{
|
||||||
return version != null
|
return version != null &&
|
||||||
&& ( version.toUpperCase().endsWith( "SNAPSHOT" ) || Artifact.VERSION_FILE_PATTERN.matcher( version )
|
( version.toUpperCase().endsWith( "SNAPSHOT" ) || Artifact.VERSION_FILE_PATTERN.matcher( version )
|
||||||
.matches() );
|
.matches() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +42,14 @@ public final class ArtifactUtils
|
||||||
|
|
||||||
public static String versionlessKey( String groupId, String artifactId )
|
public static String versionlessKey( String groupId, String artifactId )
|
||||||
{
|
{
|
||||||
|
if ( groupId == null )
|
||||||
|
{
|
||||||
|
throw new NullPointerException( "groupId was null" );
|
||||||
|
}
|
||||||
|
if ( artifactId == null )
|
||||||
|
{
|
||||||
|
throw new NullPointerException( "artifactId was null" );
|
||||||
|
}
|
||||||
return groupId + ":" + artifactId;
|
return groupId + ":" + artifactId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.maven</groupId>
|
<groupId>org.apache.maven</groupId>
|
||||||
<artifactId>maven-core</artifactId>
|
<artifactId>maven-core</artifactId>
|
||||||
<version>2.0-beta-1</version>
|
<version>2.0-beta-2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.maven</groupId>
|
<groupId>org.apache.maven</groupId>
|
||||||
|
|
|
@ -32,6 +32,7 @@ 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.model.Resource;
|
||||||
|
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
|
||||||
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.PluginVersionManager;
|
||||||
import org.apache.maven.plugin.version.PluginVersionResolutionException;
|
import org.apache.maven.plugin.version.PluginVersionResolutionException;
|
||||||
|
@ -189,22 +190,28 @@ public class PrepareReleaseMojo
|
||||||
|
|
||||||
if ( !getReleaseProgress().verifyCheckpoint( ReleaseProgressTracker.CP_POM_TRANSFORMED_FOR_RELEASE ) )
|
if ( !getReleaseProgress().verifyCheckpoint( ReleaseProgressTracker.CP_POM_TRANSFORMED_FOR_RELEASE ) )
|
||||||
{
|
{
|
||||||
for ( Iterator it = reactorProjects.iterator(); it.hasNext(); )
|
|
||||||
{
|
|
||||||
MavenProject project = (MavenProject) it.next();
|
|
||||||
|
|
||||||
getVersionResolver().resolveVersion( project );
|
|
||||||
|
|
||||||
getScmRewriter().rewriteScmInfo( project, getTagLabel() );
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( Iterator it = reactorProjects.iterator(); it.hasNext(); )
|
for ( Iterator it = reactorProjects.iterator(); it.hasNext(); )
|
||||||
{
|
{
|
||||||
MavenProject project = (MavenProject) it.next();
|
MavenProject project = (MavenProject) it.next();
|
||||||
|
|
||||||
checkForPresenceOfSnapshots( project );
|
checkForPresenceOfSnapshots( project );
|
||||||
|
|
||||||
transformPomToReleaseVersionPom( project );
|
String projectId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
|
||||||
|
|
||||||
|
if ( !ArtifactUtils.isSnapshot( project.getVersion() ) )
|
||||||
|
{
|
||||||
|
throw new MojoExecutionException( "The project " + project.getGroupId() + ":" +
|
||||||
|
project.getArtifactId() + " isn't a snapshot (" + project.getVersion() + ")." );
|
||||||
|
}
|
||||||
|
|
||||||
|
getVersionResolver().resolveVersion( project.getOriginalModel(), projectId );
|
||||||
|
|
||||||
|
MavenProject clonedProject = new MavenProject( project );
|
||||||
|
|
||||||
|
Model model = clonedProject.getOriginalModel();
|
||||||
|
|
||||||
|
transformPomToReleaseVersionPom( model, projectId, project.getFile(), project.getParentArtifact(),
|
||||||
|
project.getPluginArtifactRepositories() );
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -230,16 +237,17 @@ public class PrepareReleaseMojo
|
||||||
{
|
{
|
||||||
MavenProject project = (MavenProject) it.next();
|
MavenProject project = (MavenProject) it.next();
|
||||||
|
|
||||||
getVersionResolver().incrementVersion( project );
|
// TODO: use clone model instead... (requires beta-3)
|
||||||
|
project = new MavenProject( project );
|
||||||
|
|
||||||
getScmRewriter().restoreScmInfo( project );
|
Model model = project.getOriginalModel();
|
||||||
}
|
|
||||||
|
|
||||||
for ( Iterator it = reactorProjects.iterator(); it.hasNext(); )
|
String projectId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
|
||||||
{
|
getVersionResolver().incrementVersion( model, projectId );
|
||||||
MavenProject project = (MavenProject) it.next();
|
|
||||||
|
|
||||||
transformPomToSnapshotVersionPom( project );
|
getScmRewriter().restoreScmInfo( model );
|
||||||
|
|
||||||
|
transformPomToSnapshotVersionPom( model, project.getFile() );
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -268,11 +276,9 @@ public class PrepareReleaseMojo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void transformPomToSnapshotVersionPom( MavenProject project )
|
private void transformPomToSnapshotVersionPom( Model model, File file )
|
||||||
throws MojoExecutionException
|
throws MojoExecutionException
|
||||||
{
|
{
|
||||||
Model model = project.getOriginalModel();
|
|
||||||
|
|
||||||
ProjectVersionResolver versionResolver = getVersionResolver();
|
ProjectVersionResolver versionResolver = getVersionResolver();
|
||||||
|
|
||||||
Parent parent = model.getParent();
|
Parent parent = model.getParent();
|
||||||
|
@ -369,19 +375,21 @@ public class PrepareReleaseMojo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Writer writer = null;
|
|
||||||
|
|
||||||
File file = new File( project.getFile().getParentFile(), POM );
|
File pomFile = new File( file.getParentFile(), POM );
|
||||||
|
Writer writer = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
writer = new FileWriter( file );
|
writer = new FileWriter( pomFile );
|
||||||
|
|
||||||
project.writeOriginalModel( writer );
|
MavenXpp3Writer pomWriter = new MavenXpp3Writer();
|
||||||
|
|
||||||
|
pomWriter.write( writer, model );
|
||||||
}
|
}
|
||||||
catch ( IOException e )
|
catch ( IOException e )
|
||||||
{
|
{
|
||||||
throw new MojoExecutionException( "Cannot write development version of pom to: " + file, e );
|
throw new MojoExecutionException( "Cannot write development version of pom to: " + pomFile, e );
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -515,7 +523,7 @@ public class PrepareReleaseMojo
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new MojoExecutionException(
|
throw new MojoExecutionException(
|
||||||
"Cannot prepare the release because you have local modifications : \n" + message.toString() );
|
"Cannot prepare the release because you have local modifications : \n" + message );
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -549,7 +557,7 @@ public class PrepareReleaseMojo
|
||||||
{
|
{
|
||||||
MavenProject parentProject = currentProject.getParent();
|
MavenProject parentProject = currentProject.getParent();
|
||||||
|
|
||||||
String parentVersion = null;
|
String parentVersion;
|
||||||
|
|
||||||
if ( ArtifactUtils.isSnapshot( parentProject.getVersion() ) )
|
if ( ArtifactUtils.isSnapshot( parentProject.getVersion() ) )
|
||||||
{
|
{
|
||||||
|
@ -632,30 +640,22 @@ public class PrepareReleaseMojo
|
||||||
message.append( "\n" );
|
message.append( "\n" );
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new MojoExecutionException(
|
throw new MojoExecutionException( "Can't release project due to non released dependencies :\n" + message );
|
||||||
"Can't release project due to non released dependencies :\n" + message.toString() );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void transformPomToReleaseVersionPom( MavenProject project )
|
private void transformPomToReleaseVersionPom( Model model, String projectId, File file, Artifact parentArtifact,
|
||||||
|
List pluginArtifactRepositories )
|
||||||
throws MojoExecutionException
|
throws MojoExecutionException
|
||||||
{
|
{
|
||||||
if ( !ArtifactUtils.isSnapshot( project.getVersion() ) )
|
getScmRewriter().rewriteScmInfo( model, projectId, getTagLabel() );
|
||||||
{
|
|
||||||
throw new MojoExecutionException( "The project " + project.getGroupId() + ":" + project.getArtifactId() +
|
|
||||||
" isn't a snapshot (" + project.getVersion() + ")." );
|
|
||||||
}
|
|
||||||
|
|
||||||
Model model = project.getOriginalModel();
|
|
||||||
|
|
||||||
//Rewrite parent version
|
//Rewrite parent version
|
||||||
if ( model.getParent() != null )
|
if ( model.getParent() != null )
|
||||||
{
|
{
|
||||||
Artifact parentArtifact = project.getParentArtifact();
|
|
||||||
|
|
||||||
if ( ArtifactUtils.isSnapshot( parentArtifact.getBaseVersion() ) )
|
if ( ArtifactUtils.isSnapshot( parentArtifact.getBaseVersion() ) )
|
||||||
{
|
{
|
||||||
String version = resolveVersion( parentArtifact, "parent", project );
|
String version = resolveVersion( parentArtifact, "parent", pluginArtifactRepositories );
|
||||||
|
|
||||||
model.getParent().setVersion( version );
|
model.getParent().setVersion( version );
|
||||||
}
|
}
|
||||||
|
@ -795,16 +795,18 @@ public class PrepareReleaseMojo
|
||||||
|
|
||||||
Writer writer = null;
|
Writer writer = null;
|
||||||
|
|
||||||
File file = new File( project.getFile().getParentFile(), POM );
|
File pomFile = new File( file.getParentFile(), POM );
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
writer = new FileWriter( file );
|
writer = new FileWriter( pomFile );
|
||||||
|
|
||||||
project.writeOriginalModel( writer );
|
MavenXpp3Writer pomWriter = new MavenXpp3Writer();
|
||||||
|
|
||||||
|
pomWriter.write( writer, model );
|
||||||
}
|
}
|
||||||
catch ( IOException e )
|
catch ( IOException e )
|
||||||
{
|
{
|
||||||
throw new MojoExecutionException( "Cannot write released version of pom to: " + file, e );
|
throw new MojoExecutionException( "Cannot write released version of pom to: " + pomFile, e );
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -840,15 +842,15 @@ public class PrepareReleaseMojo
|
||||||
// we don't need these polluting the POM.
|
// we don't need these polluting the POM.
|
||||||
releaseModel.setProfiles( Collections.EMPTY_LIST );
|
releaseModel.setProfiles( Collections.EMPTY_LIST );
|
||||||
releaseModel.setDependencyManagement( null );
|
releaseModel.setDependencyManagement( null );
|
||||||
releaseModel.getBuild().setPluginManagement( null );
|
releaseProject.getBuild().setPluginManagement( null );
|
||||||
|
|
||||||
String projectVersion = releaseModel.getVersion();
|
String projectVersion = releaseModel.getVersion();
|
||||||
if ( ArtifactUtils.isSnapshot( projectVersion ) )
|
if ( ArtifactUtils.isSnapshot( projectVersion ) )
|
||||||
{
|
{
|
||||||
String snapshotVersion = projectVersion;
|
String snapshotVersion = projectVersion;
|
||||||
|
|
||||||
projectVersion = getVersionResolver().getResolvedVersion( releaseModel.getGroupId(),
|
projectVersion = getVersionResolver().getResolvedVersion( project.getGroupId(),
|
||||||
releaseModel.getArtifactId() );
|
project.getArtifactId() );
|
||||||
|
|
||||||
if ( ArtifactUtils.isSnapshot( projectVersion ) )
|
if ( ArtifactUtils.isSnapshot( projectVersion ) )
|
||||||
{
|
{
|
||||||
|
@ -929,12 +931,12 @@ public class PrepareReleaseMojo
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
version = pluginVersionManager.resolvePluginVersion( plugin.getGroupId(),
|
version = pluginVersionManager.resolvePluginVersion( plugin.getGroupId(),
|
||||||
plugin.getArtifactId(), project,
|
plugin.getArtifactId(), releaseProject,
|
||||||
settings, localRepository );
|
settings, localRepository );
|
||||||
}
|
}
|
||||||
catch ( PluginVersionResolutionException e )
|
catch ( PluginVersionResolutionException e )
|
||||||
{
|
{
|
||||||
throw new MojoExecutionException( "Cannot resolve version for plugin: " + plugin );
|
throw new MojoExecutionException( "Cannot resolve version for plugin: " + plugin, e );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ArtifactUtils.isSnapshot( version ) )
|
if ( ArtifactUtils.isSnapshot( version ) )
|
||||||
|
@ -949,7 +951,8 @@ public class PrepareReleaseMojo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List reports = releaseProject.getReportPlugins();
|
Reporting reporting = releaseModel.getReporting();
|
||||||
|
List reports = reporting != null ? reporting.getPlugins() : null;
|
||||||
|
|
||||||
if ( reports != null )
|
if ( reports != null )
|
||||||
{
|
{
|
||||||
|
@ -961,12 +964,15 @@ public class PrepareReleaseMojo
|
||||||
String version;
|
String version;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
version = pluginVersionManager.resolvePluginVersion( plugin.getGroupId(), plugin
|
version = pluginVersionManager.resolveReportPluginVersion( plugin.getGroupId(),
|
||||||
.getArtifactId(), project, settings, localRepository, true );
|
plugin.getArtifactId(),
|
||||||
|
releaseProject, settings,
|
||||||
|
localRepository );
|
||||||
}
|
}
|
||||||
catch ( PluginVersionResolutionException e )
|
catch ( PluginVersionResolutionException e )
|
||||||
{
|
{
|
||||||
throw new MojoExecutionException( "Cannot resolve version for report plugin: " + plugin );
|
throw new MojoExecutionException( "Cannot resolve version for report plugin: " + plugin,
|
||||||
|
e );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ArtifactUtils.isSnapshot( version ) )
|
if ( ArtifactUtils.isSnapshot( version ) )
|
||||||
|
@ -981,7 +987,7 @@ public class PrepareReleaseMojo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List extensions = releaseProject.getBuildExtensions();
|
List extensions = build != null ? build.getExtensions() : null;
|
||||||
|
|
||||||
if ( extensions != null )
|
if ( extensions != null )
|
||||||
{
|
{
|
||||||
|
@ -996,7 +1002,8 @@ public class PrepareReleaseMojo
|
||||||
|
|
||||||
Artifact artifact = (Artifact) extensionArtifacts.get( extensionId );
|
Artifact artifact = (Artifact) extensionArtifacts.get( extensionId );
|
||||||
|
|
||||||
String version = resolveVersion( artifact, "extension", releaseProject );
|
String version = resolveVersion( artifact, "extension",
|
||||||
|
releaseProject.getPluginArtifactRepositories() );
|
||||||
|
|
||||||
ext.setVersion( version );
|
ext.setVersion( version );
|
||||||
}
|
}
|
||||||
|
@ -1210,7 +1217,7 @@ public class PrepareReleaseMojo
|
||||||
return newParent;
|
return newParent;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String resolveVersion( Artifact artifact, String artifactUsage, MavenProject project )
|
private String resolveVersion( Artifact artifact, String artifactUsage, List pluginArtifactRepositories )
|
||||||
throws MojoExecutionException
|
throws MojoExecutionException
|
||||||
{
|
{
|
||||||
String resolvedVersion = getVersionResolver().getResolvedVersion( artifact.getGroupId(),
|
String resolvedVersion = getVersionResolver().getResolvedVersion( artifact.getGroupId(),
|
||||||
|
@ -1222,8 +1229,7 @@ public class PrepareReleaseMojo
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
artifactMetadataSource.retrieve( artifact, localRepository,
|
artifactMetadataSource.retrieve( artifact, localRepository, pluginArtifactRepositories );
|
||||||
project.getPluginArtifactRepositories() );
|
|
||||||
}
|
}
|
||||||
catch ( ArtifactMetadataRetrievalException e )
|
catch ( ArtifactMetadataRetrievalException e )
|
||||||
{
|
{
|
||||||
|
@ -1347,23 +1353,23 @@ public class PrepareReleaseMojo
|
||||||
private void checkIn( String message )
|
private void checkIn( String message )
|
||||||
throws MojoExecutionException
|
throws MojoExecutionException
|
||||||
{
|
{
|
||||||
|
ScmHelper scm = getScm( basedir );
|
||||||
|
|
||||||
|
String tag = scm.getTag();
|
||||||
|
|
||||||
|
// No tag here - we suppose user works on correct branch
|
||||||
|
scm.setTag( null );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ScmHelper scm = getScm( basedir );
|
|
||||||
|
|
||||||
String tag = scm.getTag();
|
|
||||||
|
|
||||||
// No tag here - we suppose user works on correct branch
|
|
||||||
scm.setTag( null );
|
|
||||||
|
|
||||||
scm.checkin( message );
|
scm.checkin( message );
|
||||||
|
|
||||||
scm.setTag( tag );
|
|
||||||
}
|
}
|
||||||
catch ( Exception e )
|
catch ( ScmException e )
|
||||||
{
|
{
|
||||||
throw new MojoExecutionException( "An error is occurred in the checkin process.", e );
|
throw new MojoExecutionException( "An error is occurred in the checkin process.", e );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scm.setTag( tag );
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getTagLabel()
|
private String getTagLabel()
|
||||||
|
@ -1389,7 +1395,7 @@ public class PrepareReleaseMojo
|
||||||
userTag = tag;
|
userTag = tag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch ( Exception e )
|
catch ( IOException e )
|
||||||
{
|
{
|
||||||
throw new MojoExecutionException( "An error is occurred in the tag process.", e );
|
throw new MojoExecutionException( "An error is occurred in the tag process.", e );
|
||||||
}
|
}
|
||||||
|
@ -1436,7 +1442,7 @@ public class PrepareReleaseMojo
|
||||||
|
|
||||||
scm.tag();
|
scm.tag();
|
||||||
}
|
}
|
||||||
catch ( Exception e )
|
catch ( ScmException e )
|
||||||
{
|
{
|
||||||
throw new MojoExecutionException( "An error is occurred in the tag process.", e );
|
throw new MojoExecutionException( "An error is occurred in the tag process.", e );
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,11 +20,6 @@ import org.apache.maven.artifact.ArtifactUtils;
|
||||||
import org.apache.maven.model.Model;
|
import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.model.Scm;
|
import org.apache.maven.model.Scm;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.plugin.MojoExecutionException;
|
||||||
import org.apache.maven.project.MavenProject;
|
|
||||||
import org.codehaus.plexus.util.StringUtils;
|
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class ProjectScmRewriter
|
public class ProjectScmRewriter
|
||||||
{
|
{
|
||||||
|
@ -35,13 +30,9 @@ public class ProjectScmRewriter
|
||||||
this.releaseProgress = releaseProgress;
|
this.releaseProgress = releaseProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void rewriteScmInfo( MavenProject project, String tagLabel )
|
public void rewriteScmInfo( Model model, String projectId, String tagLabel )
|
||||||
throws MojoExecutionException
|
throws MojoExecutionException
|
||||||
{
|
{
|
||||||
String projectId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
|
|
||||||
|
|
||||||
Model model = project.getOriginalModel();
|
|
||||||
|
|
||||||
Scm scm = model.getScm();
|
Scm scm = model.getScm();
|
||||||
// If SCM is null in original model, it is inherited, no mods needed
|
// If SCM is null in original model, it is inherited, no mods needed
|
||||||
if ( scm != null )
|
if ( scm != null )
|
||||||
|
@ -52,12 +43,12 @@ public class ProjectScmRewriter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void restoreScmInfo( MavenProject project )
|
public void restoreScmInfo( Model model )
|
||||||
{
|
{
|
||||||
Scm scm = project.getOriginalModel().getScm();
|
Scm scm = model.getScm();
|
||||||
if ( scm != null )
|
if ( scm != null )
|
||||||
{
|
{
|
||||||
String projectId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
|
String projectId = ArtifactUtils.versionlessKey( model.getGroupId(), model.getArtifactId() );
|
||||||
|
|
||||||
releaseProgress.restoreScmInfo( projectId, scm );
|
releaseProgress.restoreScmInfo( projectId, scm );
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,25 @@
|
||||||
package org.apache.maven.plugins.release.helpers;
|
package org.apache.maven.plugins.release.helpers;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2001-2005 The Apache Software Foundation.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
import org.apache.maven.artifact.ArtifactUtils;
|
import org.apache.maven.artifact.ArtifactUtils;
|
||||||
import org.apache.maven.model.Model;
|
import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.plugin.MojoExecutionException;
|
||||||
import org.apache.maven.plugin.logging.Log;
|
import org.apache.maven.plugin.logging.Log;
|
||||||
import org.apache.maven.project.MavenProject;
|
|
||||||
import org.codehaus.plexus.components.inputhandler.InputHandler;
|
import org.codehaus.plexus.components.inputhandler.InputHandler;
|
||||||
import org.codehaus.plexus.util.StringUtils;
|
import org.codehaus.plexus.util.StringUtils;
|
||||||
|
|
||||||
|
@ -14,7 +29,6 @@ import java.util.Map;
|
||||||
|
|
||||||
public class ProjectVersionResolver
|
public class ProjectVersionResolver
|
||||||
{
|
{
|
||||||
|
|
||||||
private static final String SNAPSHOT_CLASSIFIER = "-SNAPSHOT";
|
private static final String SNAPSHOT_CLASSIFIER = "-SNAPSHOT";
|
||||||
|
|
||||||
private Map resolvedVersions = new HashMap();
|
private Map resolvedVersions = new HashMap();
|
||||||
|
@ -32,11 +46,9 @@ public class ProjectVersionResolver
|
||||||
this.interactive = interactive;
|
this.interactive = interactive;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resolveVersion( MavenProject project )
|
public void resolveVersion( Model model, String projectId )
|
||||||
throws MojoExecutionException
|
throws MojoExecutionException
|
||||||
{
|
{
|
||||||
String projectId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
|
|
||||||
|
|
||||||
if ( resolvedVersions.containsKey( projectId ) )
|
if ( resolvedVersions.containsKey( projectId ) )
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
|
@ -44,7 +56,7 @@ public class ProjectVersionResolver
|
||||||
}
|
}
|
||||||
|
|
||||||
//Rewrite project version
|
//Rewrite project version
|
||||||
String projectVersion = project.getVersion();
|
String projectVersion = model.getVersion();
|
||||||
|
|
||||||
projectVersion = projectVersion.substring( 0, projectVersion.length() - SNAPSHOT_CLASSIFIER.length() );
|
projectVersion = projectVersion.substring( 0, projectVersion.length() - SNAPSHOT_CLASSIFIER.length() );
|
||||||
|
|
||||||
|
@ -67,8 +79,6 @@ public class ProjectVersionResolver
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Model model = project.getOriginalModel();
|
|
||||||
|
|
||||||
model.setVersion( projectVersion );
|
model.setVersion( projectVersion );
|
||||||
|
|
||||||
resolvedVersions.put( projectId, projectVersion );
|
resolvedVersions.put( projectId, projectVersion );
|
||||||
|
@ -81,14 +91,13 @@ public class ProjectVersionResolver
|
||||||
return (String) resolvedVersions.get( projectId );
|
return (String) resolvedVersions.get( projectId );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void incrementVersion( MavenProject project )
|
public void incrementVersion( Model model, String projectId )
|
||||||
throws MojoExecutionException
|
throws MojoExecutionException
|
||||||
{
|
{
|
||||||
String projectVersion = project.getOriginalModel().getVersion();
|
String projectVersion = model.getVersion();
|
||||||
|
|
||||||
if ( ArtifactUtils.isSnapshot( projectVersion ) )
|
if ( ArtifactUtils.isSnapshot( projectVersion ) )
|
||||||
{
|
{
|
||||||
String projectId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
|
|
||||||
throw new MojoExecutionException( "The project " + projectId + " is a snapshot (" + projectVersion +
|
throw new MojoExecutionException( "The project " + projectId + " is a snapshot (" + projectVersion +
|
||||||
"). It appears that the release version has not been committed." );
|
"). It appears that the release version has not been committed." );
|
||||||
}
|
}
|
||||||
|
@ -136,7 +145,6 @@ public class ProjectVersionResolver
|
||||||
projectVersion = "";
|
projectVersion = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
String projectId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
|
|
||||||
if ( interactive )
|
if ( interactive )
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -160,7 +168,7 @@ public class ProjectVersionResolver
|
||||||
throw new MojoExecutionException( "Cannot determine incremented development version for: " + projectId );
|
throw new MojoExecutionException( "Cannot determine incremented development version for: " + projectId );
|
||||||
}
|
}
|
||||||
|
|
||||||
project.getOriginalModel().setVersion( projectVersion );
|
model.setVersion( projectVersion );
|
||||||
|
|
||||||
resolvedVersions.put( projectId, projectVersion );
|
resolvedVersions.put( projectId, projectVersion );
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,7 +205,7 @@ public class ScmHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkin( String message )
|
public void checkin( String message )
|
||||||
throws Exception
|
throws ScmException
|
||||||
{
|
{
|
||||||
ScmRepository repository = getScmRepository();
|
ScmRepository repository = getScmRepository();
|
||||||
|
|
||||||
|
|
|
@ -160,6 +160,7 @@ public class MavenProject
|
||||||
this.pluginArtifacts = Collections.unmodifiableSet( project.pluginArtifacts );
|
this.pluginArtifacts = Collections.unmodifiableSet( project.pluginArtifacts );
|
||||||
this.reportArtifacts = Collections.unmodifiableSet( project.reportArtifacts );
|
this.reportArtifacts = Collections.unmodifiableSet( project.reportArtifacts );
|
||||||
this.extensionArtifacts = Collections.unmodifiableSet( project.extensionArtifacts );
|
this.extensionArtifacts = Collections.unmodifiableSet( project.extensionArtifacts );
|
||||||
|
this.parentArtifact = project.parentArtifact;
|
||||||
|
|
||||||
this.remoteArtifactRepositories = Collections.unmodifiableList( project.remoteArtifactRepositories );
|
this.remoteArtifactRepositories = Collections.unmodifiableList( project.remoteArtifactRepositories );
|
||||||
this.pluginArtifactRepositories = Collections.unmodifiableList( project.pluginArtifactRepositories );
|
this.pluginArtifactRepositories = Collections.unmodifiableList( project.pluginArtifactRepositories );
|
||||||
|
|
|
@ -55,7 +55,7 @@ import java.util.TreeMap;
|
||||||
public final class ModelUtils
|
public final class ModelUtils
|
||||||
{
|
{
|
||||||
public static void mergePluginLists( PluginContainer childContainer, PluginContainer parentContainer,
|
public static void mergePluginLists( PluginContainer childContainer, PluginContainer parentContainer,
|
||||||
boolean handleAsInheritance )
|
boolean handleAsInheritance )
|
||||||
{
|
{
|
||||||
if ( childContainer == null || parentContainer == null )
|
if ( childContainer == null || parentContainer == null )
|
||||||
{
|
{
|
||||||
|
@ -77,8 +77,8 @@ public final class ModelUtils
|
||||||
|
|
||||||
String parentInherited = parentPlugin.getInherited();
|
String parentInherited = parentPlugin.getInherited();
|
||||||
|
|
||||||
if ( !handleAsInheritance || parentInherited == null
|
if ( !handleAsInheritance || parentInherited == null ||
|
||||||
|| Boolean.valueOf( parentInherited ).booleanValue() )
|
Boolean.valueOf( parentInherited ).booleanValue() )
|
||||||
{
|
{
|
||||||
|
|
||||||
Plugin assembledPlugin = parentPlugin;
|
Plugin assembledPlugin = parentPlugin;
|
||||||
|
@ -139,8 +139,8 @@ public final class ModelUtils
|
||||||
|
|
||||||
String parentInherited = parentPlugin.getInherited();
|
String parentInherited = parentPlugin.getInherited();
|
||||||
|
|
||||||
if ( !handleAsInheritance || parentInherited == null
|
if ( !handleAsInheritance || parentInherited == null ||
|
||||||
|| Boolean.valueOf( parentInherited ).booleanValue() )
|
Boolean.valueOf( parentInherited ).booleanValue() )
|
||||||
{
|
{
|
||||||
|
|
||||||
ReportPlugin assembledPlugin = parentPlugin;
|
ReportPlugin assembledPlugin = parentPlugin;
|
||||||
|
@ -258,7 +258,7 @@ public final class ModelUtils
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void mergeReportPluginDefinitions( ReportPlugin child, ReportPlugin parent,
|
public static void mergeReportPluginDefinitions( ReportPlugin child, ReportPlugin parent,
|
||||||
boolean handleAsInheritance )
|
boolean handleAsInheritance )
|
||||||
{
|
{
|
||||||
if ( child == null || parent == null )
|
if ( child == null || parent == null )
|
||||||
{
|
{
|
||||||
|
@ -471,7 +471,7 @@ public final class ModelUtils
|
||||||
child.setConfiguration( childConfiguration );
|
child.setConfiguration( childConfiguration );
|
||||||
}
|
}
|
||||||
|
|
||||||
static Model cloneModel( Model model )
|
public static Model cloneModel( Model model )
|
||||||
{
|
{
|
||||||
// TODO: would be nice for the modello:java code to generate this as a copy constructor
|
// TODO: would be nice for the modello:java code to generate this as a copy constructor
|
||||||
Model newModel = new Model();
|
Model newModel = new Model();
|
||||||
|
|
|
@ -96,7 +96,7 @@ public class ProjectSorter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: can this be removed?
|
// TODO: this MUST be fixed before beta-3, but it is required for a sane release plugin.
|
||||||
MavenProject parent = project.getParent();
|
MavenProject parent = project.getParent();
|
||||||
if ( parent != null )
|
if ( parent != null )
|
||||||
{
|
{
|
||||||
|
@ -106,7 +106,6 @@ public class ProjectSorter
|
||||||
dag.addEdge( id, parentId );
|
dag.addEdge( id, parentId );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
List buildPlugins = project.getBuildPlugins();
|
List buildPlugins = project.getBuildPlugins();
|
||||||
if ( buildPlugins != null )
|
if ( buildPlugins != null )
|
||||||
|
|
Loading…
Reference in New Issue