You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by jo...@apache.org on 2007/08/26 05:16:11 UTC

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

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" ) );
     }
 



Re: 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

Posted by Brett Porter <br...@apache.org>.
And/or a comment in the test case would be a good way to identify it.  
I need to learn to write those more.

On 30/08/2007, at 2:17 PM, Wendy Smoak wrote:

> Joakim, can you do me a favor and explain what the bug was?  I read
> commit messages from lots of projects, and it's helpful to see the
> problem and fix described in the commit message, and then see the
> actual solution in the code.  I'm sure I'm not alone. :)
>
> -- 
> Wendy
>
> On 8/25/07, joakime@apache.org <jo...@apache.org> wrote:
>> 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.

Re: 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

Posted by Wendy Smoak <ws...@gmail.com>.
Joakim, can you do me a favor and explain what the bug was?  I read
commit messages from lots of projects, and it's helpful to see the
problem and fix described in the commit message, and then see the
actual solution in the code.  I'm sure I'm not alone. :)

-- 
Wendy

On 8/25/07, joakime@apache.org <jo...@apache.org> wrote:
> 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.