archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joak...@apache.org
Subject svn commit: r569758 - in /maven/archiva/trunk/archiva-base/archiva-common/src: main/java/org/apache/maven/archiva/common/utils/PathUtil.java test/java/org/apache/maven/archiva/common/utils/PathUtilTest.java
Date Sun, 26 Aug 2007 03:16:11 GMT
Author: joakime
Date: Sat Aug 25 20:16:11 2007
New Revision: 569758

URL: http://svn.apache.org/viewvc?rev=569758&view=rev
Log:
Fixing subtle bug in PathUtil.toRelative() encountered during Metadata work.

Modified:
    maven/archiva/trunk/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/utils/PathUtil.java
    maven/archiva/trunk/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/utils/PathUtilTest.java

Modified: maven/archiva/trunk/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/utils/PathUtil.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/utils/PathUtil.java?rev=569758&r1=569757&r2=569758&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/utils/PathUtil.java
(original)
+++ maven/archiva/trunk/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/utils/PathUtil.java
Sat Aug 25 20:16:11 2007
@@ -39,7 +39,7 @@
         {
             return path;
         }
-        
+
         return toUrl( new File( path ) );
     }
 
@@ -61,13 +61,32 @@
         }
     }
 
+    /**
+     * Given a basedir and a child file, return the relative path to the child.
+     * 
+     * @param basedir the basedir.
+     * @param file the file to get the relative path for.
+     * @return the relative path to the child. (NOTE: this path will NOT start with a {@link
File#separator} character)
+     */
     public static String getRelative( String basedir, File file )
     {
         return getRelative( basedir, file.getAbsolutePath() );
     }
 
+    /**
+     * Given a basedir and a child file, return the relative path to the child.
+     * 
+     * @param basedir the basedir.
+     * @param child the child path (can be a full path)
+     * @return the relative path to the child. (NOTE: this path will NOT start with a {@link
File#separator} character)
+     */
     public static String getRelative( String basedir, String child )
     {
+        if ( basedir.endsWith( File.separator ) )
+        {
+            basedir = basedir.substring( 0, basedir.length() - 1 );
+        }
+
         if ( child.startsWith( basedir ) )
         {
             // simple solution.

Modified: maven/archiva/trunk/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/utils/PathUtilTest.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/utils/PathUtilTest.java?rev=569758&r1=569757&r2=569758&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/utils/PathUtilTest.java
(original)
+++ maven/archiva/trunk/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/utils/PathUtilTest.java
Sat Aug 25 20:16:11 2007
@@ -34,9 +34,15 @@
 public class PathUtilTest
     extends TestCase
 {
-    public void testToRelative()
+    public void testToRelativeWithoutSlash()
     {
         assertEquals( "path/to/resource.xml", PathUtil.getRelative( "/home/user/foo/repository",
+                                                                    "/home/user/foo/repository/path/to/resource.xml"
) );
+    }
+    
+    public void testToRelativeWithSlash()
+    {
+        assertEquals( "path/to/resource.xml", PathUtil.getRelative( "/home/user/foo/repository/",
                                                                     "/home/user/foo/repository/path/to/resource.xml"
) );
     }
 



Mime
View raw message