You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2009/01/30 20:24:29 UTC

svn commit: r739385 - in /maven/components/branches/maven-2.1.x: maven-core/src/main/java/org/apache/maven/cli/ maven-project/src/main/java/org/apache/maven/project/path/ maven-settings/src/main/java/org/apache/maven/settings/

Author: bentmann
Date: Fri Jan 30 19:24:29 2009
New Revision: 739385

URL: http://svn.apache.org/viewvc?rev=739385&view=rev
Log:
[MNG-3951] Hide drive-relative paths from plugins

Modified:
    maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java
    maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java
    maven/components/branches/maven-2.1.x/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java

Modified: maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java?rev=739385&r1=739384&r2=739385&view=diff
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java (original)
+++ maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java Fri Jan 30 19:24:29 2009
@@ -156,6 +156,14 @@
 
         EventDispatcher eventDispatcher = new DefaultEventDispatcher();
 
+        // 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() );
+        }
+
         // ----------------------------------------------------------------------
         // Now that we have everything that we need we will fire up plexus and
         // bring the maven component to life for use.

Modified: maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java?rev=739385&r1=739384&r2=739385&view=diff
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java (original)
+++ maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java Fri Jan 30 19:24:29 2009
@@ -41,8 +41,6 @@
         "${project.basedir}"
     };
 
-    private static final String FILE_SEPARATOR = File.separator;
-
     public void alignToBaseDirectory( Model model, File basedir )
     {
         if ( basedir == null )
@@ -118,13 +116,22 @@
 
         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();
         }
-        
-        s = s.replace( '/', File.separatorChar );
-        s = s.replace( '\\', File.separatorChar );
 
         return s;
     }
@@ -183,25 +190,6 @@
         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;
-    }
-
     /**
      * {@inheritDoc}
      */

Modified: maven/components/branches/maven-2.1.x/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java?rev=739385&r1=739384&r2=739385&view=diff
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java (original)
+++ maven/components/branches/maven-2.1.x/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java Fri Jan 30 19:24:29 2009
@@ -231,6 +231,13 @@
             localRepository = new File( mavenUserConfigurationDirectory, "repository" ).getAbsolutePath();
         }
 
+        // for the special case of a drive-relative Windows path, make sure it's absolute to save plugins from trouble
+        File file = new File( localRepository );
+        if ( !file.isAbsolute() && file.getPath().startsWith( File.separator ) )
+        {
+            localRepository = file.getAbsolutePath();
+        }
+
         userSettings.setLocalRepository( localRepository );
     }