[MNG-3951] Hide drive-relative paths from plugins

o Merged from r739385

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@739735 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-02-01 10:44:19 +00:00
parent ed4f594ac4
commit 7397cc69d6
3 changed files with 38 additions and 23 deletions

View File

@ -35,8 +35,6 @@ public class DefaultPathTranslator
{
private static final String[] BASEDIR_EXPRESSIONS = {"${basedir}", "${pom.basedir}", "${project.basedir}"};
private String FILE_SEPARATOR = "/";
public void alignToBaseDirectory( Model model, File basedir )
{
Build build = model.getBuild();
@ -83,10 +81,27 @@ public class DefaultPathTranslator
public String alignToBaseDirectory( String path, File basedir )
{
if ( path == null )
{
return null;
}
String s = stripBasedirToken( path );
if ( requiresBaseDirectoryAlignment( s ) )
File file = new File( s );
if ( file.isAbsolute() )
{
// path was already absolute, just normalize file separator and we're done
s = file.getPath();
}
else if ( file.getPath().startsWith( File.separator ) )
{
// drive-relative Windows path, don't align with project directory but with drive root
s = file.getAbsolutePath();
}
else
{
// an ordinary relative path, align with project directory
s = new File( new File( basedir, s ).toURI().normalize() ).getAbsolutePath();
}
@ -147,25 +162,6 @@ public class DefaultPathTranslator
return path;
}
private boolean requiresBaseDirectoryAlignment( String s )
{
if ( s != null )
{
File f = new File( s );
if ( s.startsWith( FILE_SEPARATOR ) || f.isAbsolute() )
{
return false;
}
else
{
return true;
}
}
return false;
}
public void unalignFromBaseDirectory( Model model, File basedir )
{
Build build = model.getBuild();

View File

@ -102,6 +102,17 @@ public class DefaultMavenSettingsBuilder
userSettings = interpolate( userSettings, request );
// for the special case of a drive-relative Windows path, make sure it's absolute to save plugins from trouble
String localRepository = userSettings.getLocalRepository();
if ( localRepository != null && localRepository.length() > 0 )
{
File file = new File( localRepository );
if ( !file.isAbsolute() && file.getPath().startsWith( File.separator ) )
{
userSettings.setLocalRepository( file.getAbsolutePath() );
}
}
return userSettings;
}

View File

@ -116,7 +116,15 @@ public class MavenCli
{
CLIReportingUtils.showVersion();
}
// Make sure the Maven home directory is an absolute path to save us from confusion with say drive-relative
// Windows paths.
String mavenHome = System.getProperty( "maven.home" );
if ( mavenHome != null )
{
System.setProperty( "maven.home", new File( mavenHome ).getAbsolutePath() );
}
MavenExecutionRequest request = CLIRequestUtils.buildRequest( commandLine, debug, quiet, showErrors );
Configuration configuration = buildEmbedderConfiguration( request, commandLine, classWorld );