maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bentm...@apache.org
Subject svn commit: r1054712 - in /maven/maven-3/trunk/maven-compat/src: main/java/org/apache/maven/project/path/DefaultPathTranslator.java test/java/org/apache/maven/project/path/DefaultPathTranslatorTest.java
Date Mon, 03 Jan 2011 19:11:36 GMT
Author: bentmann
Date: Mon Jan  3 19:11:36 2011
New Revision: 1054712

URL: http://svn.apache.org/viewvc?rev=1054712&view=rev
Log:
[MNG-4933] With a resource directory as . maven raise an java.lang.StringIndexOutOfBoundsException:217

o Aligned code with r1050425 of https://svn.apache.org/repos/asf/maven/maven-2/branches/maven-2.2.x/maven-project/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java
o Fixed special case of path=${basedir} to yield valid/non-empty path "."

Modified:
    maven/maven-3/trunk/maven-compat/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java
    maven/maven-3/trunk/maven-compat/src/test/java/org/apache/maven/project/path/DefaultPathTranslatorTest.java

Modified: maven/maven-3/trunk/maven-compat/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-compat/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java?rev=1054712&r1=1054711&r2=1054712&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-compat/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java
(original)
+++ maven/maven-3/trunk/maven-compat/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java
Mon Jan  3 19:11:36 2011
@@ -38,6 +38,11 @@ public class DefaultPathTranslator
 
     public void alignToBaseDirectory( Model model, File basedir )
     {
+        if ( basedir == null )
+        {
+            return;
+        }
+
         Build build = model.getBuild();
 
         if ( build != null )
@@ -83,6 +88,11 @@ public class DefaultPathTranslator
 
     public String alignToBaseDirectory( String path, File basedir )
     {
+        if ( basedir == null )
+        {
+            return path;
+        }
+
         if ( path == null )
         {
             return null;
@@ -166,6 +176,11 @@ public class DefaultPathTranslator
 
     public void unalignFromBaseDirectory( Model model, File basedir )
     {
+        if ( basedir == null )
+        {
+            return;
+        }
+
         Build build = model.getBuild();
 
         if ( build != null )
@@ -209,14 +224,37 @@ public class DefaultPathTranslator
         }
     }
 
-    public String unalignFromBaseDirectory( String directory, File basedir )
+    public String unalignFromBaseDirectory( String path, File basedir )
     {
-        String path = basedir.getPath();
-        if ( directory.startsWith( path ) )
+        if ( basedir == null )
+        {
+            return path;
+        }
+
+        if ( path == null )
         {
-            directory = directory.substring( path.length() + 1 ).replace( '\\', '/' );
+            return null;
         }
-        return directory;
+
+        path = path.trim();
+
+        String base = basedir.getAbsolutePath();
+        if ( path.startsWith( base ) )
+        {
+            path = chopLeadingFileSeparator( path.substring( base.length() ) );
+        }
+
+        if ( path.length() <= 0 )
+        {
+            path = ".";
+        }
+
+        if ( !new File( path ).isAbsolute() )
+        {
+            path = path.replace( '\\', '/' );
+        }
+
+        return path;
     }
 
 }

Modified: maven/maven-3/trunk/maven-compat/src/test/java/org/apache/maven/project/path/DefaultPathTranslatorTest.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-compat/src/test/java/org/apache/maven/project/path/DefaultPathTranslatorTest.java?rev=1054712&r1=1054711&r2=1054712&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-compat/src/test/java/org/apache/maven/project/path/DefaultPathTranslatorTest.java
(original)
+++ maven/maven-3/trunk/maven-compat/src/test/java/org/apache/maven/project/path/DefaultPathTranslatorTest.java
Mon Jan  3 19:11:36 2011
@@ -1,3 +1,5 @@
+package org.apache.maven.project.path;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -17,12 +19,11 @@
  * under the License.
  */
 
-package org.apache.maven.project.path;
-
 import java.io.File;
 
 import junit.framework.TestCase;
 
+@SuppressWarnings( "deprecation" )
 public class DefaultPathTranslatorTest
     extends TestCase
 {
@@ -45,4 +46,13 @@ public class DefaultPathTranslatorTest
         assertEquals( new File( basedir, "dir" ).getAbsolutePath(), aligned );
     }
 
+    public void testUnalignToBasedirWherePathEqualsBasedir()
+    {
+        File basedir = new File( System.getProperty( "java.io.tmpdir" ), "test" ).getAbsoluteFile();
+
+        String unaligned = new DefaultPathTranslator().unalignFromBaseDirectory( basedir.getAbsolutePath(),
basedir );
+
+        assertEquals( ".", unaligned );
+    }
+
 }



Mime
View raw message