You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2006/04/26 05:35:15 UTC

svn commit: r397070 - in /maven/plugins/trunk/maven-release-plugin: ./ src/main/java/org/apache/maven/plugins/release/config/ src/main/java/org/apache/maven/plugins/release/phase/ src/test/java/org/apache/maven/plugins/release/phase/ src/test/resources...

Author: brett
Date: Tue Apr 25 20:35:12 2006
New Revision: 397070

URL: http://svn.apache.org/viewcvs?rev=397070&view=rev
Log:
[MRELEASE-98] beginnings of transform phase

Added:
    maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/phase/RewritePomsForReleasePhaseTest.java   (with props)
    maven/plugins/trunk/maven-release-plugin/src/test/resources/projects/rewrite-for-release/
    maven/plugins/trunk/maven-release-plugin/src/test/resources/projects/rewrite-for-release/basic-pom.xml   (with props)
Modified:
    maven/plugins/trunk/maven-release-plugin/pom.xml
    maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/config/ReleaseConfiguration.java
    maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/phase/RewritePomsForReleasePhase.java

Modified: maven/plugins/trunk/maven-release-plugin/pom.xml
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-release-plugin/pom.xml?rev=397070&r1=397069&r2=397070&view=diff
==============================================================================
--- maven/plugins/trunk/maven-release-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-release-plugin/pom.xml Tue Apr 25 20:35:12 2006
@@ -104,6 +104,20 @@
       <version>1.0-beta-3</version>
       <scope>test</scope>
     </dependency>
-    
+    <dependency>
+      <groupId>dom4j</groupId>
+      <artifactId>dom4j</artifactId>
+      <version>1.6.1</version>
+    </dependency>
   </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <childDelegation>false</childDelegation>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
 </project>

Modified: maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/config/ReleaseConfiguration.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/config/ReleaseConfiguration.java?rev=397070&r1=397069&r2=397070&view=diff
==============================================================================
--- maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/config/ReleaseConfiguration.java (original)
+++ maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/config/ReleaseConfiguration.java Tue Apr 25 20:35:12 2006
@@ -78,6 +78,28 @@
      */
     private List reactorProjects;
 
+    /**
+     * Whether to use edit mode when making SCM modifications. This setting is disregarded if the SCM does not support
+     * edit mode, or if edit mode is compulsory for the given SCM.
+     */
+    private boolean useEditMode;
+
+    /**
+     * Whether to add the model schema to the top of the rewritten POM if it wasn't there already. If <code>false</code>
+     * then the root element will remain untouched.
+     */
+    private boolean addSchema;
+
+    /**
+     * Whether to generate release POMs.
+     */
+    private boolean generateReleasePoms;
+
+    public boolean isGenerateReleasePoms()
+    {
+        return generateReleasePoms;
+    }
+
     public String getCompletedPhase()
     {
         return completedPhase;
@@ -178,6 +200,31 @@
         this.reactorProjects = reactorProjects;
     }
 
+    public boolean isUseEditMode()
+    {
+        return useEditMode;
+    }
+
+    public boolean isAddSchema()
+    {
+        return addSchema;
+    }
+
+    public void setUseEditMode( boolean useEditMode )
+    {
+        this.useEditMode = useEditMode;
+    }
+
+    public void setAddSchema( boolean addSchema )
+    {
+        this.addSchema = addSchema;
+    }
+
+    public void setGenerateReleasePoms( boolean generateReleasePoms )
+    {
+        this.generateReleasePoms = generateReleasePoms;
+    }
+
     /**
      * Merge two configurations together. All SCM settings are overridden by the merge configuration, as are the
      * <code>settings</code> and <code>workingDirectory</code> fields. The <code>completedPhase</code> field is used as
@@ -195,6 +242,9 @@
         this.password = mergeOverride( this.password, mergeConfiguration.password );
         this.privateKey = mergeOverride( this.privateKey, mergeConfiguration.privateKey );
         this.passphrase = mergeOverride( this.passphrase, mergeConfiguration.passphrase );
+        this.useEditMode = mergeConfiguration.useEditMode;
+        this.addSchema = mergeConfiguration.addSchema;
+        this.generateReleasePoms = mergeConfiguration.generateReleasePoms;
 
         // These must be overridden, as they are not stored
         this.settings = mergeOverride( this.settings, mergeConfiguration.settings );
@@ -242,6 +292,9 @@
         result = 29 * result + ( passphrase != null ? passphrase.hashCode() : 0 );
         result = 29 * result + ( workingDirectory != null ? workingDirectory.hashCode() : 0 );
         result = 29 * result + ( reactorProjects != null ? reactorProjects.hashCode() : 0 );
+        result = 29 * result + ( useEditMode ? 1 : 0 );
+        result = 29 * result + ( addSchema ? 1 : 0 );
+        result = 29 * result + ( generateReleasePoms ? 1 : 0 );
         return result;
     }
 
@@ -258,6 +311,18 @@
 
         ReleaseConfiguration that = (ReleaseConfiguration) obj;
 
+        if ( addSchema != that.addSchema )
+        {
+            return false;
+        }
+        if ( useEditMode != that.useEditMode )
+        {
+            return false;
+        }
+        if ( generateReleasePoms != that.generateReleasePoms )
+        {
+            return false;
+        }
         if ( completedPhase != null ? !completedPhase.equals( that.completedPhase ) : that.completedPhase != null )
         {
             return false;
@@ -274,6 +339,10 @@
         {
             return false;
         }
+        if ( reactorProjects != null ? !reactorProjects.equals( that.reactorProjects ) : that.reactorProjects != null )
+        {
+            return false;
+        }
         if ( settings != null ? !settings.equals( that.settings ) : that.settings != null )
         {
             return false;
@@ -287,10 +356,6 @@
             return false;
         }
         if ( username != null ? !username.equals( that.username ) : that.username != null )
-        {
-            return false;
-        }
-        if ( reactorProjects != null ? !reactorProjects.equals( that.reactorProjects ) : that.reactorProjects != null )
         {
             return false;
         }

Modified: maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/phase/RewritePomsForReleasePhase.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/phase/RewritePomsForReleasePhase.java?rev=397070&r1=397069&r2=397070&view=diff
==============================================================================
--- maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/phase/RewritePomsForReleasePhase.java (original)
+++ maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/phase/RewritePomsForReleasePhase.java Tue Apr 25 20:35:12 2006
@@ -16,24 +16,735 @@
  * limitations under the License.
  */
 
+import org.apache.maven.artifact.ArtifactUtils;
+import org.apache.maven.plugins.release.ReleaseExecutionException;
 import org.apache.maven.plugins.release.config.ReleaseConfiguration;
+import org.apache.maven.plugins.release.scm.ReleaseScmCommandException;
+import org.apache.maven.plugins.release.scm.ReleaseScmRepositoryException;
+import org.apache.maven.plugins.release.scm.ScmRepositoryConfigurator;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.scm.ScmException;
+import org.apache.maven.scm.ScmFileSet;
+import org.apache.maven.scm.command.edit.EditScmResult;
+import org.apache.maven.scm.manager.NoSuchScmProviderException;
+import org.apache.maven.scm.provider.ScmProvider;
+import org.apache.maven.scm.repository.ScmRepository;
+import org.apache.maven.scm.repository.ScmRepositoryException;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.util.IOUtil;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.Element;
+import org.dom4j.Namespace;
+import org.dom4j.QName;
+import org.dom4j.io.SAXReader;
+import org.dom4j.io.XMLWriter;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Iterator;
 
 /**
- * TODO: Description.
+ * Rewrite POMs for release.
  *
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
  */
 public class RewritePomsForReleasePhase
+    extends AbstractLogEnabled
     implements ReleasePhase
 {
-    // TODO: separate release POM generation?    
+    /**
+     * Tool that gets a configured SCM repository from release configuration.
+     */
+    private ScmRepositoryConfigurator scmRepositoryConfigurator;
+
+    // TODO: separate release POM generation?
 
     public void execute( ReleaseConfiguration releaseConfiguration )
+        throws ReleaseExecutionException
+    {
+        for ( Iterator it = releaseConfiguration.getReactorProjects().iterator(); it.hasNext(); )
+        {
+            MavenProject project = (MavenProject) it.next();
+
+            String projectId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
+
+            getLogger().info( "Transforming " + projectId + " to release" );
+
+            Document document = readPom( project.getFile() );
+
+            transformPomToReleaseVersionPom();
+
+            writePom( project.getFile(), releaseConfiguration, document, project.getModelVersion() );
+        }
+
+        if ( releaseConfiguration.isGenerateReleasePoms() )
+        {
+            generateReleasePoms();
+        }
+
+    }
+
+    private Document readPom( File file )
+        throws ReleaseExecutionException
     {
-        // TODO: implement
+        Document document;
 
+        SAXReader reader = new SAXReader();
+        try
+        {
+            document = reader.read( file );
+        }
+        catch ( DocumentException e )
+        {
+            throw new ReleaseExecutionException( "Error reading POM: " + e.getMessage(), e );
+        }
+
+        return document;
     }
 
+    private void transformPomToReleaseVersionPom()
+    {
+        // TODO: rewrite parent
+        // TODO: rewrite SCM
+        // TODO: rewrite dependencies
+        // TODO: rewrite dependency management
+        // TODO: rewrite extensions
+        // TODO: rewrite plugins, plugin management
+        // TODO: rewrite reporting plugins
+
+/*
+        ProjectScmRewriter scmRewriter = getScmRewriter();
+        scmRewriter.rewriteScmInfo( model, projectId, getTagLabel() );
+
+        //Rewrite parent version
+        if ( model.getParent() != null )
+        {
+            if ( ArtifactUtils.isSnapshot( parentArtifact.getBaseVersion() ) )
+            {
+                String version = resolveVersion( parentArtifact, "parent", pluginArtifactRepositories );
+
+                model.getParent().setVersion( version );
+            }
+        }
+
+        //Rewrite dependencies section
+        List dependencies = model.getDependencies();
+
+        ProjectVersionResolver versionResolver = getVersionResolver();
+        if ( dependencies != null )
+        {
+            for ( Iterator i = dependencies.iterator(); i.hasNext(); )
+            {
+                Dependency dep = (Dependency) i.next();
+                // Avoid in dep mgmt
+                if ( dep.getVersion() != null )
+                {
+                    String resolvedVersion =
+                        versionResolver.getResolvedVersion( dep.getGroupId(), dep.getArtifactId() );
+
+                    if ( resolvedVersion != null )
+                    {
+                        getLog().info( "Updating " + dep.getArtifactId() + " to " + resolvedVersion );
+                        dep.setVersion( resolvedVersion );
+                    }
+                }
+            }
+        }
+
+        Build build = model.getBuild();
+
+        if ( build != null )
+        {
+            //Rewrite plugins section
+            List plugins = build.getPlugins();
+
+            if ( plugins != null )
+            {
+                for ( Iterator i = plugins.iterator(); i.hasNext(); )
+                {
+                    Plugin plugin = (Plugin) i.next();
+
+                    // Avoid in plugin mgmt
+                    if ( plugin.getVersion() != null )
+                    {
+                        String resolvedVersion =
+                            versionResolver.getResolvedVersion( plugin.getGroupId(), plugin.getArtifactId() );
+
+                        if ( resolvedVersion != null )
+                        {
+                            plugin.setVersion( resolvedVersion );
+                        }
+                    }
+                }
+            }
+
+            PluginManagement pluginManagement = build.getPluginManagement();
+            plugins = pluginManagement != null ? pluginManagement.getPlugins() : null;
+
+            if ( plugins != null )
+            {
+                for ( Iterator i = plugins.iterator(); i.hasNext(); )
+                {
+                    Plugin plugin = (Plugin) i.next();
+
+                    if ( plugin.getVersion() != null )
+                    {
+                        String resolvedVersion =
+                            versionResolver.getResolvedVersion( plugin.getGroupId(), plugin.getArtifactId() );
+
+                        if ( resolvedVersion != null )
+                        {
+                            plugin.setVersion( resolvedVersion );
+                        }
+                    }
+                }
+            }
+
+            //Rewrite extensions section
+            List extensions = build.getExtensions();
+
+            for ( Iterator i = extensions.iterator(); i.hasNext(); )
+            {
+                Extension ext = (Extension) i.next();
+
+                String resolvedVersion = versionResolver
+                    .getResolvedVersion( ext.getGroupId(), ext.getArtifactId() );
+
+                if ( resolvedVersion != null )
+                {
+                    ext.setVersion( resolvedVersion );
+                }
+            }
+        }
+
+        Reporting reporting = model.getReporting();
+
+        if ( reporting != null )
+        {
+            //Rewrite reports section
+            List reports = reporting.getPlugins();
+
+            for ( Iterator i = reports.iterator(); i.hasNext(); )
+            {
+                ReportPlugin plugin = (ReportPlugin) i.next();
+
+                String resolvedVersion =
+                    versionResolver.getResolvedVersion( plugin.getGroupId(), plugin.getArtifactId() );
+
+                if ( resolvedVersion != null )
+                {
+                    plugin.setVersion( resolvedVersion );
+                }
+            }
+        }
+            //Rewrite dependencyManagement section
+            List dependencies =
+                model.getDependencyManagement() != null ? model.getDependencyManagement().getDependencies() : null;
+
+            if ( dependencies != null )
+            {
+                for ( Iterator i = dependencies.iterator(); i.hasNext(); )
+                {
+                    Dependency dep = (Dependency) i.next();
+
+                    // If our dependency specifies an explicit released version, do NOT update
+                    // it to the latest released version.  If we depend on a SNAPSHOT that is
+                    // being released, we update the version to reflect the newly released version.
+                    // TODO Cleaner way to determine snapshot?
+                    if ( dep.getVersion() != null && dep.getVersion().endsWith( "-SNAPSHOT" ) )
+                    {
+                        String version = versionResolver.getResolvedVersion( dep.getGroupId(), dep.getArtifactId() );
+
+                        if ( version != null )
+                        {
+                            getLog().info( "Updating DepMgmt " + dep.getArtifactId() + " to " + version );
+                            dep.setVersion( version );
+                        }
+                    }
+                }
+            }
+
+*/
+
+    }
+
+    private void writePom( File pomFile, ReleaseConfiguration releaseConfiguration, Document document,
+                           String modelVersion )
+        throws ReleaseExecutionException
+    {
+        ScmRepository repository;
+        ScmProvider provider;
+        try
+        {
+            repository = scmRepositoryConfigurator.getConfiguredRepository( releaseConfiguration );
+
+            provider = scmRepositoryConfigurator.getRepositoryProvider( repository );
+        }
+        catch ( ScmRepositoryException e )
+        {
+            throw new ReleaseScmRepositoryException( e.getMessage(), e.getValidationMessages() );
+        }
+        catch ( NoSuchScmProviderException e )
+        {
+            throw new ReleaseExecutionException( "Unable to configure SCM repository: " + e.getMessage(), e );
+        }
+
+        try
+        {
+            if ( releaseConfiguration.isUseEditMode() || provider.requiresEditMode() )
+            {
+                EditScmResult result =
+                    provider.edit( repository, new ScmFileSet( releaseConfiguration.getWorkingDirectory(), pomFile ) );
+
+                if ( !result.isSuccess() )
+                {
+                    throw new ReleaseScmCommandException( "Unable to enable editing on the POM", result );
+                }
+            }
+        }
+        catch ( ScmException e )
+        {
+            throw new ReleaseExecutionException( "An error occurred enabling edit mode: " + e.getMessage(), e );
+        }
+
+        Element rootElement = document.getRootElement();
+
+        if ( releaseConfiguration.isAddSchema() )
+        {
+            rootElement.setQName( QName.get( "project", Namespace.get( "", "http://maven.apache.org/POM/4.0.0" ) ) );
+
+            rootElement.addNamespace( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );
+
+            if ( rootElement.attributeValue( "schemaLocation" ) == null )
+            {
+                rootElement.addAttribute( "xsi:schemaLocation", "http://maven.apache.org/POM/" + modelVersion +
+                    " http://maven.apache.org/maven-v" + modelVersion.replace( '.', '_' ) + ".xsd" );
+            }
+        }
+
+        Writer writer = null;
+        try
+        {
+            writer = new FileWriter( pomFile );
+
+            XMLWriter xmlWriter = new XMLWriter( writer );
+            xmlWriter.write( document );
+        }
+        catch ( IOException e )
+        {
+            throw new ReleaseExecutionException( "Error writing POM: " + e.getMessage(), e );
+        }
+        finally
+        {
+            IOUtil.close( writer );
+        }
+    }
+
+    private void generateReleasePoms()
+    {
+/*
+        String canonicalBasedir;
+
+        try
+        {
+            canonicalBasedir = trimPathForScmCalculation( basedir );
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( "Cannot canonicalize basedir: " + basedir.getAbsolutePath(), e );
+        }
+
+        ProjectVersionResolver versionResolver = getVersionResolver();
+        for ( Iterator it = reactorProjects.iterator(); it.hasNext(); )
+        {
+            MavenProject project = (MavenProject) it.next();
+
+            MavenProject releaseProject = new MavenProject( project );
+            Model releaseModel = releaseProject.getModel();
+            fixNullValueInModel( releaseModel, project.getModel() );
+
+            // the release POM should reflect bits of these which were injected at build time...
+            // we don't need these polluting the POM.
+            releaseModel.setProfiles( Collections.EMPTY_LIST );
+            releaseModel.setDependencyManagement( null );
+            releaseProject.getBuild().setPluginManagement( null );
+
+            String projectVersion = releaseModel.getVersion();
+            if ( ArtifactUtils.isSnapshot( projectVersion ) )
+            {
+                String snapshotVersion = projectVersion;
+
+                projectVersion = versionResolver.getResolvedVersion( project.getGroupId(), project.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( null );
+                }
+                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 )
+            {
+                //Rewrite dependencies section
+                List newdeps = new ArrayList();
+
+                Map oldDeps = new HashMap();
+
+                List deps = releaseProject.getDependencies();
+                if ( deps != null )
+                {
+                    for ( Iterator depIterator = deps.iterator(); depIterator.hasNext(); )
+                    {
+                        Dependency dep = (Dependency) depIterator.next();
+
+                        oldDeps.put( ArtifactUtils.artifactId( dep.getGroupId(), dep.getArtifactId(), dep.getType(),
+                                                               dep.getVersion() ), dep );
+                    }
+                }
+
+                for ( Iterator i = releaseProject.getArtifacts().iterator(); i.hasNext(); )
+                {
+                    Artifact artifact = (Artifact) i.next();
+
+                    String key = artifact.getId();
+
+                    Dependency newdep = new Dependency();
+
+                    newdep.setArtifactId( artifact.getArtifactId() );
+                    newdep.setGroupId( artifact.getGroupId() );
+
+                    String version = artifact.getVersion();
+                    if ( artifact.isSnapshot() )
+                    {
+                        version = versionResolver.getResolvedVersion( artifact.getGroupId(), artifact.getArtifactId() );
+
+                        if ( ArtifactUtils.isSnapshot( version ) )
+                        {
+                            throw new MojoExecutionException(
+                                "Unresolved SNAPSHOT version of: " + artifact + ". Cannot proceed with release." );
+                        }
+                    }
+
+                    newdep.setVersion( version );
+                    newdep.setType( artifact.getType() );
+                    newdep.setScope( artifact.getScope() );
+                    newdep.setClassifier( artifact.getClassifier() );
+
+                    Dependency old = (Dependency) oldDeps.get( key );
+
+                    if ( old != null )
+                    {
+                        newdep.setSystemPath( old.getSystemPath() );
+                        newdep.setExclusions( old.getExclusions() );
+                        newdep.setOptional( old.isOptional() );
+                    }
+
+                    newdeps.add( newdep );
+                }
+
+                releaseModel.setDependencies( newdeps );
+            }
+
+            // Use original - don't want the lifecycle introduced ones
+            Build build = releaseProject.getOriginalModel().getBuild();
+            List plugins = build != null ? build.getPlugins() : null;
+
+            if ( plugins != null )
+            {
+                //Rewrite plugins version
+                for ( Iterator i = plugins.iterator(); i.hasNext(); )
+                {
+                    Plugin plugin = (Plugin) i.next();
+
+                    String version;
+                    try
+                    {
+                        version = pluginVersionManager.resolvePluginVersion( plugin.getGroupId(), plugin
+                            .getArtifactId(), releaseProject, getSettings(), localRepository );
+                    }
+                    catch ( PluginVersionResolutionException e )
+                    {
+                        throw new MojoExecutionException(
+                            "Cannot resolve version for plugin '" + plugin.getKey() + "': " + e.getMessage(), e );
+                    }
+                    catch ( InvalidPluginException e )
+                    {
+                        throw new MojoExecutionException(
+                            "Cannot resolve version for plugin '" + plugin.getKey() + "': " + e.getMessage(), e );
+                    }
+                    catch ( PluginVersionNotFoundException e )
+                    {
+                        throw new MojoFailureException( e.getMessage() );
+                    }
+
+                    if ( ArtifactUtils.isSnapshot( version ) )
+                    {
+                        throw new MojoFailureException(
+                            "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 );
+                }
+            }
+
+            Reporting reporting = releaseModel.getReporting();
+            List reports = reporting != null ? reporting.getPlugins() : null;
+
+            if ( reports != null )
+            {
+                //Rewrite report version
+                for ( Iterator i = reports.iterator(); i.hasNext(); )
+                {
+                    ReportPlugin plugin = (ReportPlugin) i.next();
+
+                    String version;
+                    try
+                    {
+                        version = pluginVersionManager.resolveReportPluginVersion( plugin.getGroupId(), plugin
+                            .getArtifactId(), releaseProject, getSettings(), localRepository );
+                    }
+                    catch ( PluginVersionResolutionException e )
+                    {
+                        throw new MojoExecutionException(
+                            "Cannot resolve version for report '" + plugin.getKey() + "': " + e.getMessage(), e );
+                    }
+                    catch ( InvalidPluginException e )
+                    {
+                        throw new MojoExecutionException(
+                            "Cannot resolve version for plugin '" + plugin.getKey() + "': " + e.getMessage(), e );
+                    }
+                    catch ( PluginVersionNotFoundException e )
+                    {
+                        throw new MojoFailureException( e.getMessage() );
+                    }
+
+                    if ( ArtifactUtils.isSnapshot( version ) )
+                    {
+                        throw new MojoFailureException(
+                            "Resolved version of report 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 );
+                }
+            }
+
+            List extensions = build != null ? build.getExtensions() : null;
+
+            if ( extensions != null )
+            {
+                //Rewrite extension version
+                Map extensionArtifacts = releaseProject.getExtensionArtifactMap();
+
+                for ( Iterator i = extensions.iterator(); i.hasNext(); )
+                {
+                    Extension ext = (Extension) i.next();
+
+                    String extensionId = ArtifactUtils.versionlessKey( ext.getGroupId(), ext.getArtifactId() );
+
+                    Artifact artifact = (Artifact) extensionArtifacts.get( extensionId );
+
+                    String version = resolveVersion( artifact, "extension", releaseProject
+                        .getPluginArtifactRepositories() );
+
+                    ext.setVersion( version );
+                }
+            }
+
+            pathTranslator.unalignFromBaseDirectory( releaseProject.getModel(), project.getFile().getParentFile() );
+
+            File releasePomFile = new File( releaseProject.getFile().getParentFile(), RELEASE_POM );
+
+            Writer writer = null;
+
+            try
+            {
+                writePom( releasePomFile, releaseProject.getModel(), rootElement );
+
+                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
+            {
+                String releasePomPath = trimPathForScmCalculation( releasePomFile );
+
+                releasePomPath = releasePomPath.substring( canonicalBasedir.length() + 1 );
+
+                ScmHelper scm = getScm( basedir.getAbsolutePath() );
+
+                if ( !testmode )
+                {
+                    scm.add( releasePomPath );
+                }
+                else
+                {
+                    getLog().info( "[TESTMODE] adding file: " + releasePomPath );
+                }
+            }
+            catch ( ScmException e )
+            {
+                throw new MojoExecutionException( "Error adding the release-pom.xml: " + releasePomFile, e );
+            }
+            catch ( IOException e )
+            {
+                throw new MojoExecutionException( "Error adding the release-pom.xml: " + releasePomFile, e );
+            }
+        }
+*/
+    }
+
+    /*
+    private String resolveVersion( Artifact artifact, String artifactUsage, List pluginArtifactRepositories )
+        throws MojoExecutionException
+    {
+        ProjectVersionResolver versionResolver = getVersionResolver();
+        String resolvedVersion = versionResolver.getResolvedVersion( artifact.getGroupId(), artifact.getArtifactId() );
+
+        if ( resolvedVersion == null )
+        {
+            if ( artifact.getFile() == null )
+            {
+                try
+                {
+                    artifactMetadataSource.retrieve( artifact, localRepository, pluginArtifactRepositories );
+                }
+                catch ( ArtifactMetadataRetrievalException e )
+                {
+                    throw new MojoExecutionException( "Cannot resolve " + artifactUsage + ": " + artifact, e );
+                }
+            }
+
+            resolvedVersion = artifact.getVersion();
+        }
+
+        return resolvedVersion;
+    }
+
+    private String trimPathForScmCalculation( File file )
+        throws IOException
+    {
+        String path = file.getCanonicalPath();
+
+        path = path.replace( File.separatorChar, '/' );
+
+        if ( path.endsWith( "/" ) )
+        {
+            path = path.substring( path.length() - 1 );
+        }
+
+        return path;
+    }
+*/
+
+    /**
+     * Returns the tag name to be used when tagging the release in the scm repository.
+     * <p/>
+     * If the userTag is already assigned, that value is returned.
+     * Else if the releaseProperties already has the value, then use that value.
+     * Else if we are interactive then prompt the user for a tag name.
+     */
+/*
+    private String getTagLabel()
+        throws MojoExecutionException
+    {
+        if ( userTag == null )
+        {
+            if ( StringUtils.isNotEmpty( releaseProgress.getScmTag() ) )
+            {
+                userTag = releaseProgress.getScmTag();
+            }
+            else
+            {
+                try
+                {
+                    if ( tag == null && interactive )
+                    {
+                        String prompt = "What tag name should be used? ";
+
+                        String defaultTag = getDefaultReleaseTag();
+
+                        if ( defaultTag != null )
+                        {
+                            prompt = prompt + "[" + defaultTag + "]";
+                        }
+
+                        getLog().info( prompt );
+
+                        String inputTag = getInputHandler().readLine();
+
+                        userTag = ( StringUtils.isEmpty( inputTag ) ) ? defaultTag : inputTag;
+                    }
+                    else
+                    {
+                        userTag = tag;
+                    }
+                }
+                catch ( IOException e )
+                {
+                    throw new MojoExecutionException( "An error has occurred while reading user input.", e );
+                }
+
+                // If we were able to get a userTag from the user, save it to our release.properties file
+                if ( userTag != null )
+                {
+                    ReleaseProgressTracker releaseProgress = getReleaseProgress();
+                    releaseProgress.setScmTag( userTag );
+                    try
+                    {
+                        releaseProgress.store();
+                    }
+                    catch ( IOException e )
+                    {
+                        getLog().warn( "An error occurred while saving the release progress file", e );
+                    }
+
+                }
+            }
+        }
+
+        if ( userTag == null )
+        {
+            throw new MojoExecutionException( "A release tag must be specified" );
+        }
+
+        return userTag;
+    }
+*/
     public void simulate( ReleaseConfiguration releaseConfiguration )
     {
         // TODO: implement

Added: maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/phase/RewritePomsForReleasePhaseTest.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/phase/RewritePomsForReleasePhaseTest.java?rev=397070&view=auto
==============================================================================
--- maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/phase/RewritePomsForReleasePhaseTest.java (added)
+++ maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/phase/RewritePomsForReleasePhaseTest.java Tue Apr 25 20:35:12 2006
@@ -0,0 +1,111 @@
+package org.apache.maven.plugins.release.phase;
+
+/*
+ * Copyright 2005-2006 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.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.DefaultArtifactRepository;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+import org.apache.maven.plugins.release.ReleaseExecutionException;
+import org.apache.maven.plugins.release.config.ReleaseConfiguration;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectBuilder;
+import org.apache.maven.project.ProjectBuildingException;
+import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.util.FileUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Test the SCM modification check phase.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ */
+public class RewritePomsForReleasePhaseTest
+    extends PlexusTestCase
+{
+    private ReleasePhase phase;
+
+    private MavenProjectBuilder projectBuilder;
+
+    private ArtifactRepository localRepository;
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        phase = (ReleasePhase) lookup( ReleasePhase.ROLE, "rewrite-poms-for-release" );
+
+        projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
+
+        ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
+        String localRepoPath = getTestFile( "target/local-repository" ).getAbsolutePath().replace( '\\', '/' );
+        localRepository = new DefaultArtifactRepository( "local", "file://" + localRepoPath, layout );
+    }
+
+    public void testRewriteBasicPom()
+        throws ReleaseExecutionException, ProjectBuildingException, IOException
+    {
+        File testFile = getCopiedTestFile( "rewrite-for-release/basic-pom.xml" );
+        MavenProject project = projectBuilder.build( testFile, localRepository, null );
+        ReleaseConfiguration config = createReleaseConfiguration( Collections.singletonList( project ) );
+
+        phase.execute( config );
+
+        // TODO: assertions
+    }
+
+    public void testRewriteAddSchema()
+        throws ReleaseExecutionException, ProjectBuildingException, IOException
+    {
+        File testFile = getCopiedTestFile( "rewrite-for-release/basic-pom.xml" );
+        MavenProject project = projectBuilder.build( testFile, localRepository, null );
+        ReleaseConfiguration config = createReleaseConfiguration( Collections.singletonList( project ) );
+        config.setAddSchema( true );
+
+        // Run a second time to check they are not duplicated
+        for ( int i = 0; i < 2; i++ )
+        {
+            phase.execute( config );
+
+            String content = FileUtils.fileRead( testFile ).replace( '\n', ' ' );
+            Matcher m = Pattern.compile( "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" ).matcher( content );
+            assertTrue( "check for schema location", m.find() );
+            assertFalse( "check schema location is not duplicated", m.find() );
+
+            m = Pattern.compile(
+                "xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\"" ).matcher(
+                content );
+            assertTrue( "check for schema", m.find() );
+            assertFalse( "check for duplicated schema", m.find() );
+
+            m = Pattern.compile( "xmlns=\"http://maven.apache.org/POM/4.0.0\"" ).matcher( content );
+            assertTrue( "check for namespace", m.find() );
+            assertFalse( "check for duplicated namespace", m.find() );
+        }
+    }
+
+    private static File getCopiedTestFile( String fileName )
+        throws IOException
+    {
+        File testFile = getTestFile( "target/test-classes/projects/" + fileName );
+        FileUtils.copyFile( getTestFile( "src/test/resources/projects/" + fileName ), testFile );
+        return testFile;
+    }
+
+    private static ReleaseConfiguration createReleaseConfiguration( List reactorProjects )
+    {
+        ReleaseConfiguration releaseConfiguration = new ReleaseConfiguration();
+        releaseConfiguration.setUrl( "scm:svn:file://localhost/tmp/scm-repo" );
+        releaseConfiguration.setWorkingDirectory( getTestFile( "target/test/checkout" ) );
+        releaseConfiguration.setReactorProjects( reactorProjects );
+        return releaseConfiguration;
+    }
+}

Propchange: maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/phase/RewritePomsForReleasePhaseTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/phase/RewritePomsForReleasePhaseTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/plugins/trunk/maven-release-plugin/src/test/resources/projects/rewrite-for-release/basic-pom.xml
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-release-plugin/src/test/resources/projects/rewrite-for-release/basic-pom.xml?rev=397070&view=auto
==============================================================================
--- maven/plugins/trunk/maven-release-plugin/src/test/resources/projects/rewrite-for-release/basic-pom.xml (added)
+++ maven/plugins/trunk/maven-release-plugin/src/test/resources/projects/rewrite-for-release/basic-pom.xml Tue Apr 25 20:35:12 2006
@@ -0,0 +1,22 @@
+<!--
+  ~ Copyright 2005-2006 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.
+  -->
+
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>groupId</groupId>
+  <artifactId>artifactId</artifactId>
+  <version>1.0-SNAPSHOT</version>
+</project>
\ No newline at end of file

Propchange: maven/plugins/trunk/maven-release-plugin/src/test/resources/projects/rewrite-for-release/basic-pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-release-plugin/src/test/resources/projects/rewrite-for-release/basic-pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision