mirror of https://github.com/apache/maven.git
PR: MNG-1060
fix basedir translation on windows git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@293190 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f2fea7422b
commit
09a35f3c38
|
@ -2,13 +2,16 @@
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>maven-plugin-parent</artifactId>
|
<artifactId>maven-plugin-parent</artifactId>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<version>2.0-beta-1</version>
|
<version>2.0-beta-3-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>maven-release-plugin</artifactId>
|
<artifactId>maven-release-plugin</artifactId>
|
||||||
<packaging>maven-plugin</packaging>
|
<packaging>maven-plugin</packaging>
|
||||||
<name>Maven Release plugin</name>
|
<name>Maven Release plugin</name>
|
||||||
<version>2.0-beta-2-SNAPSHOT</version>
|
<version>2.0-beta-2-SNAPSHOT</version>
|
||||||
|
<prerequisites>
|
||||||
|
<maven>2.0-beta-3-SNAPSHOT</maven>
|
||||||
|
</prerequisites>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.maven</groupId>
|
<groupId>org.apache.maven</groupId>
|
||||||
|
|
|
@ -31,7 +31,6 @@ import org.apache.maven.model.Plugin;
|
||||||
import org.apache.maven.model.PluginManagement;
|
import org.apache.maven.model.PluginManagement;
|
||||||
import org.apache.maven.model.ReportPlugin;
|
import org.apache.maven.model.ReportPlugin;
|
||||||
import org.apache.maven.model.Reporting;
|
import org.apache.maven.model.Reporting;
|
||||||
import org.apache.maven.model.Resource;
|
|
||||||
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
|
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;
|
||||||
|
@ -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.ReleaseProgressTracker;
|
||||||
import org.apache.maven.plugins.release.helpers.ScmHelper;
|
import org.apache.maven.plugins.release.helpers.ScmHelper;
|
||||||
import org.apache.maven.project.MavenProject;
|
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.ScmException;
|
||||||
import org.apache.maven.scm.ScmFile;
|
import org.apache.maven.scm.ScmFile;
|
||||||
import org.apache.maven.settings.Settings;
|
import org.apache.maven.settings.Settings;
|
||||||
|
@ -164,6 +165,11 @@ public class PrepareReleaseMojo
|
||||||
*/
|
*/
|
||||||
private boolean resume;
|
private boolean resume;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @component
|
||||||
|
*/
|
||||||
|
private PathTranslator pathTranslator;
|
||||||
|
|
||||||
private String userTag;
|
private String userTag;
|
||||||
|
|
||||||
private ReleaseProgressTracker releaseProgress;
|
private ReleaseProgressTracker releaseProgress;
|
||||||
|
@ -206,9 +212,7 @@ public class PrepareReleaseMojo
|
||||||
|
|
||||||
getVersionResolver().resolveVersion( project.getOriginalModel(), projectId );
|
getVersionResolver().resolveVersion( project.getOriginalModel(), projectId );
|
||||||
|
|
||||||
MavenProject clonedProject = new MavenProject( project );
|
Model model = ModelUtils.cloneModel( project.getOriginalModel() );
|
||||||
|
|
||||||
Model model = clonedProject.getOriginalModel();
|
|
||||||
|
|
||||||
transformPomToReleaseVersionPom( model, projectId, project.getFile(), project.getParentArtifact(),
|
transformPomToReleaseVersionPom( model, projectId, project.getFile(), project.getParentArtifact(),
|
||||||
project.getPluginArtifactRepositories() );
|
project.getPluginArtifactRepositories() );
|
||||||
|
@ -237,10 +241,7 @@ public class PrepareReleaseMojo
|
||||||
{
|
{
|
||||||
MavenProject project = (MavenProject) it.next();
|
MavenProject project = (MavenProject) it.next();
|
||||||
|
|
||||||
// TODO: use clone model instead... (requires beta-3)
|
Model model = ModelUtils.cloneModel( project.getOriginalModel() );
|
||||||
project = new MavenProject( project );
|
|
||||||
|
|
||||||
Model model = project.getOriginalModel();
|
|
||||||
|
|
||||||
String projectId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
|
String projectId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
|
||||||
getVersionResolver().incrementVersion( model, projectId );
|
getVersionResolver().incrementVersion( model, projectId );
|
||||||
|
@ -1009,15 +1010,7 @@ public class PrepareReleaseMojo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
pathTranslator.unalignFromBaseDirectory( releaseProject.getModel(), project.getFile().getParentFile() );
|
||||||
{
|
|
||||||
relativizeBuildPaths( releaseProject.getModel().getBuild(),
|
|
||||||
project.getFile().getParentFile().getCanonicalPath() );
|
|
||||||
}
|
|
||||||
catch ( IOException e )
|
|
||||||
{
|
|
||||||
throw new MojoExecutionException( "Cannot relativize build paths for: " + project.getId(), e );
|
|
||||||
}
|
|
||||||
|
|
||||||
File releasePomFile = new File( releaseProject.getFile().getParentFile(), RELEASE_POM );
|
File releasePomFile = new File( releaseProject.getFile().getParentFile(), RELEASE_POM );
|
||||||
|
|
||||||
|
@ -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 )
|
private void fixNullValueInModel( Model modelToFix, Model correctModel )
|
||||||
{
|
{
|
||||||
if ( modelToFix.getModelVersion() != null )
|
if ( modelToFix.getModelVersion() != null )
|
||||||
|
|
|
@ -18,8 +18,8 @@ package org.apache.maven.project;
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
import org.apache.maven.artifact.ArtifactStatus;
|
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.factory.ArtifactFactory;
|
||||||
|
import org.apache.maven.artifact.manager.WagonManager;
|
||||||
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
|
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
|
||||||
|
@ -151,8 +151,7 @@ public class DefaultMavenProjectBuilder
|
||||||
// MavenProjectBuilder Implementation
|
// MavenProjectBuilder Implementation
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
public MavenProject buildWithDependencies( File projectDescriptor,
|
public MavenProject buildWithDependencies( File projectDescriptor, ArtifactRepository localRepository,
|
||||||
ArtifactRepository localRepository,
|
|
||||||
ProfileManager profileManager )
|
ProfileManager profileManager )
|
||||||
throws ProjectBuildingException, ArtifactResolutionException
|
throws ProjectBuildingException, ArtifactResolutionException
|
||||||
{
|
{
|
||||||
|
@ -162,10 +161,8 @@ public class DefaultMavenProjectBuilder
|
||||||
/**
|
/**
|
||||||
* @todo move to metadatasource itself?
|
* @todo move to metadatasource itself?
|
||||||
*/
|
*/
|
||||||
public MavenProject buildWithDependencies( File projectDescriptor,
|
public MavenProject buildWithDependencies( File projectDescriptor, ArtifactRepository localRepository,
|
||||||
ArtifactRepository localRepository,
|
ProfileManager profileManager, TransferListener transferListener )
|
||||||
ProfileManager profileManager,
|
|
||||||
TransferListener transferListener )
|
|
||||||
throws ProjectBuildingException, ArtifactResolutionException
|
throws ProjectBuildingException, ArtifactResolutionException
|
||||||
{
|
{
|
||||||
MavenProject project = buildFromSourceFile( projectDescriptor, localRepository, profileManager );
|
MavenProject project = buildFromSourceFile( projectDescriptor, localRepository, profileManager );
|
||||||
|
@ -315,7 +312,7 @@ public class DefaultMavenProjectBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only translate the base directory for files in the source tree
|
// 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();
|
Build build = project.getBuild();
|
||||||
project.addCompileSourceRoot( build.getSourceDirectory() );
|
project.addCompileSourceRoot( build.getSourceDirectory() );
|
||||||
|
|
|
@ -21,21 +21,19 @@ import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.model.Resource;
|
import org.apache.maven.model.Resource;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class DefaultPathTranslator
|
public class DefaultPathTranslator
|
||||||
implements PathTranslator
|
implements PathTranslator
|
||||||
{
|
{
|
||||||
private String FILE_SEPARATOR = "/";
|
private String FILE_SEPARATOR = "/";
|
||||||
|
|
||||||
public void alignToBaseDirectory( Model model, File projectFile )
|
public void alignToBaseDirectory( Model model, File basedir )
|
||||||
{
|
{
|
||||||
Build build = model.getBuild();
|
Build build = model.getBuild();
|
||||||
|
|
||||||
File basedir = projectFile.getParentFile();
|
|
||||||
|
|
||||||
if ( build != null )
|
if ( build != null )
|
||||||
{
|
{
|
||||||
build.setDirectory( alignToBaseDirectory( build.getDirectory(), basedir ) );
|
build.setDirectory( alignToBaseDirectory( build.getDirectory(), basedir ) );
|
||||||
|
@ -122,5 +120,60 @@ public class DefaultPathTranslator
|
||||||
|
|
||||||
return false;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,9 +26,13 @@ import java.io.File;
|
||||||
*/
|
*/
|
||||||
public interface PathTranslator
|
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 );
|
String alignToBaseDirectory( String path, File basedir );
|
||||||
|
|
||||||
|
void unalignFromBaseDirectory( Model model, File basedir );
|
||||||
|
|
||||||
|
String unalignFromBaseDirectory( String directory, File basedir );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue