From 7397cc69d6208b05f77ba48cb8b4e178b2777915 Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Sun, 1 Feb 2009 10:44:19 +0000 Subject: [PATCH] [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 --- .../project/path/DefaultPathTranslator.java | 40 +++++++++---------- .../settings/DefaultMavenSettingsBuilder.java | 11 +++++ .../java/org/apache/maven/cli/MavenCli.java | 10 ++++- 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/maven-compat/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java b/maven-compat/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java index f54541d3b9..3621d5b29f 100644 --- a/maven-compat/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java +++ b/maven-compat/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java @@ -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(); diff --git a/maven-core/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java b/maven-core/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java index 4cc05ae2b6..cf9ff48bf1 100644 --- a/maven-core/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java @@ -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; } diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java index 0757148fab..d39f33c507 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java @@ -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 );