diff --git a/maven-plugins/maven-release-plugin/pom.xml b/maven-plugins/maven-release-plugin/pom.xml
index ab5aeba143..bfb17ff07f 100644
--- a/maven-plugins/maven-release-plugin/pom.xml
+++ b/maven-plugins/maven-release-plugin/pom.xml
@@ -2,13 +2,16 @@
maven-plugin-parent
org.apache.maven.plugins
- 2.0-beta-1
+ 2.0-beta-3-SNAPSHOT
4.0.0
maven-release-plugin
maven-plugin
Maven Release plugin
2.0-beta-2-SNAPSHOT
+
+ 2.0-beta-3-SNAPSHOT
+
org.apache.maven
diff --git a/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PrepareReleaseMojo.java b/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PrepareReleaseMojo.java
index 34839a3a2a..061ca738a0 100644
--- a/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PrepareReleaseMojo.java
+++ b/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PrepareReleaseMojo.java
@@ -31,7 +31,6 @@ 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.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.version.PluginVersionManager;
@@ -41,6 +40,8 @@ import org.apache.maven.plugins.release.helpers.ProjectVersionResolver;
import org.apache.maven.plugins.release.helpers.ReleaseProgressTracker;
import org.apache.maven.plugins.release.helpers.ScmHelper;
import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ModelUtils;
+import org.apache.maven.project.path.PathTranslator;
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.ScmFile;
import org.apache.maven.settings.Settings;
@@ -164,6 +165,11 @@ public class PrepareReleaseMojo
*/
private boolean resume;
+ /**
+ * @component
+ */
+ private PathTranslator pathTranslator;
+
private String userTag;
private ReleaseProgressTracker releaseProgress;
@@ -206,9 +212,7 @@ public class PrepareReleaseMojo
getVersionResolver().resolveVersion( project.getOriginalModel(), projectId );
- MavenProject clonedProject = new MavenProject( project );
-
- Model model = clonedProject.getOriginalModel();
+ Model model = ModelUtils.cloneModel( project.getOriginalModel() );
transformPomToReleaseVersionPom( model, projectId, project.getFile(), project.getParentArtifact(),
project.getPluginArtifactRepositories() );
@@ -237,10 +241,7 @@ public class PrepareReleaseMojo
{
MavenProject project = (MavenProject) it.next();
- // TODO: use clone model instead... (requires beta-3)
- project = new MavenProject( project );
-
- Model model = project.getOriginalModel();
+ Model model = ModelUtils.cloneModel( project.getOriginalModel() );
String projectId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
getVersionResolver().incrementVersion( model, projectId );
@@ -1009,15 +1010,7 @@ public class PrepareReleaseMojo
}
}
- try
- {
- relativizeBuildPaths( releaseProject.getModel().getBuild(),
- project.getFile().getParentFile().getCanonicalPath() );
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Cannot relativize build paths for: " + project.getId(), e );
- }
+ pathTranslator.unalignFromBaseDirectory( releaseProject.getModel(), project.getFile().getParentFile() );
File releasePomFile = new File( releaseProject.getFile().getParentFile(), RELEASE_POM );
@@ -1069,77 +1062,6 @@ 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 )
diff --git a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
index 1ce8313d77..f5decadc32 100644
--- a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
+++ b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
@@ -18,8 +18,8 @@ package org.apache.maven.project;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactStatus;
-import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
@@ -151,8 +151,7 @@ public class DefaultMavenProjectBuilder
// MavenProjectBuilder Implementation
// ----------------------------------------------------------------------
- public MavenProject buildWithDependencies( File projectDescriptor,
- ArtifactRepository localRepository,
+ public MavenProject buildWithDependencies( File projectDescriptor, ArtifactRepository localRepository,
ProfileManager profileManager )
throws ProjectBuildingException, ArtifactResolutionException
{
@@ -162,10 +161,8 @@ public class DefaultMavenProjectBuilder
/**
* @todo move to metadatasource itself?
*/
- public MavenProject buildWithDependencies( File projectDescriptor,
- ArtifactRepository localRepository,
- ProfileManager profileManager,
- TransferListener transferListener )
+ public MavenProject buildWithDependencies( File projectDescriptor, ArtifactRepository localRepository,
+ ProfileManager profileManager, TransferListener transferListener )
throws ProjectBuildingException, ArtifactResolutionException
{
MavenProject project = buildFromSourceFile( projectDescriptor, localRepository, profileManager );
@@ -315,7 +312,7 @@ public class DefaultMavenProjectBuilder
}
// Only translate the base directory for files in the source tree
- pathTranslator.alignToBaseDirectory( project.getModel(), projectDescriptor );
+ pathTranslator.alignToBaseDirectory( project.getModel(), projectDescriptor.getParentFile() );
Build build = project.getBuild();
project.addCompileSourceRoot( build.getSourceDirectory() );
diff --git a/maven-project/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java b/maven-project/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java
index 75e89d3125..d846af8592 100644
--- a/maven-project/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java
+++ b/maven-project/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java
@@ -21,21 +21,19 @@ import org.apache.maven.model.Model;
import org.apache.maven.model.Resource;
import java.io.File;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.ArrayList;
public class DefaultPathTranslator
implements PathTranslator
{
private String FILE_SEPARATOR = "/";
- public void alignToBaseDirectory( Model model, File projectFile )
+ public void alignToBaseDirectory( Model model, File basedir )
{
Build build = model.getBuild();
- File basedir = projectFile.getParentFile();
-
if ( build != null )
{
build.setDirectory( alignToBaseDirectory( build.getDirectory(), basedir ) );
@@ -122,5 +120,60 @@ public class DefaultPathTranslator
return false;
}
+
+ public void unalignFromBaseDirectory( Model model, File basedir )
+ {
+ Build build = model.getBuild();
+
+ if ( build != null )
+ {
+ build.setDirectory( unalignFromBaseDirectory( build.getDirectory(), basedir ) );
+
+ build.setSourceDirectory( unalignFromBaseDirectory( build.getSourceDirectory(), basedir ) );
+
+ build.setTestSourceDirectory( unalignFromBaseDirectory( build.getTestSourceDirectory(), basedir ) );
+
+ for ( Iterator i = build.getResources().iterator(); i.hasNext(); )
+ {
+ Resource resource = (Resource) i.next();
+
+ resource.setDirectory( unalignFromBaseDirectory( resource.getDirectory(), basedir ) );
+ }
+
+ for ( Iterator i = build.getTestResources().iterator(); i.hasNext(); )
+ {
+ Resource resource = (Resource) i.next();
+
+ resource.setDirectory( unalignFromBaseDirectory( resource.getDirectory(), basedir ) );
+ }
+
+ if ( build.getFilters() != null )
+ {
+ List filters = new ArrayList();
+ for ( Iterator i = build.getFilters().iterator(); i.hasNext(); )
+ {
+ String filter = (String) i.next();
+
+ filters.add( unalignFromBaseDirectory( filter, basedir ) );
+ }
+ build.setFilters( filters );
+ }
+
+ build.setOutputDirectory( unalignFromBaseDirectory( build.getOutputDirectory(), basedir ) );
+
+ build.setTestOutputDirectory( unalignFromBaseDirectory( build.getTestOutputDirectory(), basedir ) );
+ }
+ }
+
+ public String unalignFromBaseDirectory( String directory, File basedir )
+ {
+ String path = basedir.getPath();
+ if ( directory.startsWith( path ) )
+ {
+ directory = directory.substring( path.length() + 1 ).replace( '\\', '/' );
+ }
+ return directory;
+ }
+
}
diff --git a/maven-project/src/main/java/org/apache/maven/project/path/PathTranslator.java b/maven-project/src/main/java/org/apache/maven/project/path/PathTranslator.java
index a271c563a1..745752f276 100644
--- a/maven-project/src/main/java/org/apache/maven/project/path/PathTranslator.java
+++ b/maven-project/src/main/java/org/apache/maven/project/path/PathTranslator.java
@@ -26,9 +26,13 @@ import java.io.File;
*/
public interface PathTranslator
{
- static final String ROLE = PathTranslator.class.getName();
+ String ROLE = PathTranslator.class.getName();
- void alignToBaseDirectory( Model model, File projectFile );
+ void alignToBaseDirectory( Model model, File basedir );
String alignToBaseDirectory( String path, File basedir );
+
+ void unalignFromBaseDirectory( Model model, File basedir );
+
+ String unalignFromBaseDirectory( String directory, File basedir );
}