Author: ltheussl
Date: Mon Jul 27 14:19:43 2009
New Revision: 798148
URL: http://svn.apache.org/viewvc?rev=798148&view=rev
Log:
[DOXIASITETOOLS-29] PathUtils.getRelativePath returns different results on
Windows and Linux
Added:
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/PathUtilsTest.java
(with props)
Modified:
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/PathUtils.java
Modified:
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/PathUtils.java
URL:
http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/PathUtils.java?rev=798148&r1=798147&r2=798148&view=diff
==============================================================================
---
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/PathUtils.java
(original)
+++
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/PathUtils.java
Mon Jul 27 14:19:43 2009
@@ -90,6 +90,15 @@
// The old path is not relative. Bail out.
return null;
}
+ else
+ {
+ // both are files, if either of them is relative, bail out
+ // see DOXIASITETOOLS-29, MSITE-404, PLXUTILS-116
+ if ( oldPathDescriptor.isRelative() ||
newPathDescriptor.isRelative() )
+ {
+ return null;
+ }
+ }
}
// Don't optimize to else. This might also be old.isFile && new.isFile
...
@@ -121,7 +130,7 @@
return null;
}
- // Both Descriptors point to a path. We can build a relative path.
+ // Both Descriptors point to an absolute path. We can build a relative
path.
String oldPath = oldPathDescriptor.getPath();
String newPath = newPathDescriptor.getPath();
Added:
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/PathUtilsTest.java
URL:
http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/PathUtilsTest.java?rev=798148&view=auto
==============================================================================
---
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/PathUtilsTest.java
(added)
+++
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/PathUtilsTest.java
Mon Jul 27 14:19:43 2009
@@ -0,0 +1,63 @@
+package org.apache.maven.doxia.site.decoration.inheritance;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author ltheussl
+ * @version $Id$
+ */
+public class PathUtilsTest
+ extends TestCase
+{
+ private static final String SLASH = File.separator;
+
+ /** @throws Exception */
+ public void testConvertPath()
+ throws Exception
+ {
+ PathDescriptor oldPath = new PathDescriptor( (String) null, "base" );
+ PathDescriptor newPath = new PathDescriptor( "/tmp", "target" );
+ assertEquals( oldPath, PathUtils.convertPath( oldPath, newPath ) );
+ assertEquals( newPath, PathUtils.convertPath( newPath, oldPath ) );
+ }
+
+ /** @throws Exception */
+ public void testGetRelativePath()
+ throws Exception
+ {
+ PathDescriptor oldPath = new PathDescriptor( "/tmp/foo", "base" );
+ PathDescriptor newPath = new PathDescriptor( "/tmp", "target" );
+ assertEquals( ".." + SLASH + ".." + SLASH + "target",
+ PathUtils.getRelativePath( oldPath, newPath ) );
+
+ oldPath = new PathDescriptor( (String) null, "base" );
+ assertNull( PathUtils.getRelativePath( oldPath, newPath ) );
+ assertNull( PathUtils.getRelativePath( newPath, oldPath ) );
+
+ oldPath = new PathDescriptor( "/tmp/foo", null );
+ assertEquals( ".." + SLASH + "target", PathUtils.getRelativePath(
oldPath, newPath ) );
+ assertEquals( ".." + SLASH + "foo", PathUtils.getRelativePath(
newPath, oldPath ) );
+ }
+}
Propchange:
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/PathUtilsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/PathUtilsTest.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"