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/04/13 17:51:42 UTC
svn commit: r528536 - in
/maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-common:
pom.xml src/main/java/org/apache/maven/archiva/common/utils/PathUtil.java
src/test/java/org/apache/maven/archiva/common/utils/PathUtilTest.java
Author: joakime
Date: Fri Apr 13 08:51:41 2007
New Revision: 528536
URL: http://svn.apache.org/viewvc?view=rev&rev=528536
Log:
Adding PathUtils.toURL() methods.
Modified:
maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-common/pom.xml
maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/utils/PathUtil.java
maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/utils/PathUtilTest.java
Modified: maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-common/pom.xml
URL: http://svn.apache.org/viewvc/maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-common/pom.xml?view=diff&rev=528536&r1=528535&r2=528536
==============================================================================
--- maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-common/pom.xml (original)
+++ maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-common/pom.xml Fri Apr 13 08:51:41 2007
@@ -50,38 +50,9 @@
</dependencies>
<build>
<plugins>
- <!--
- <plugin>
- <artifactId>maven-jar-plugin</artifactId>
- <executions>
- <execution>
- <id>test-jar</id>
- <goals>
- <goal>test-jar</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- -->
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-maven-plugin</artifactId>
- <!--
- <executions>
- <execution>
- <id>merge</id>
- <goals>
- <goal>merge-descriptors</goal>
- </goals>
- <configuration>
- <descriptors>
- <descriptor>${basedir}/src/main/resources/META-INF/plexus/components.xml</descriptor>
- <descriptor>${project.build.directory}/generated-resources/plexus/META-INF/plexus/components.xml</descriptor>
- </descriptors>
- </configuration>
- </execution>
- </executions>
- -->
</plugin>
</plugins>
</build>
Modified: maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/utils/PathUtil.java
URL: http://svn.apache.org/viewvc/maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/utils/PathUtil.java?view=diff&rev=528536&r1=528535&r2=528536
==============================================================================
--- maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/utils/PathUtil.java (original)
+++ maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/utils/PathUtil.java Fri Apr 13 08:51:41 2007
@@ -19,7 +19,10 @@
* under the License.
*/
+import org.apache.commons.lang.StringUtils;
+
import java.io.File;
+import java.net.MalformedURLException;
/**
* PathUtil - simple utility methods for path manipulation.
@@ -29,6 +32,35 @@
*/
public class PathUtil
{
+ public static String toUrl( String path )
+ {
+ // Is our work already done for us?
+ if ( path.startsWith( "file:/" ) )
+ {
+ return path;
+ }
+
+ return toUrl( new File( path ) );
+ }
+
+ public static String toUrl( File file )
+ {
+ try
+ {
+ return file.toURL().toExternalForm();
+ }
+ catch ( MalformedURLException e )
+ {
+ String pathCorrected = StringUtils.replaceChars( file.getAbsolutePath(), '\\', '/' );
+ if ( pathCorrected.startsWith( "file:/" ) )
+ {
+ return pathCorrected;
+ }
+
+ return "file://" + pathCorrected;
+ }
+ }
+
public static String getRelative( String basedir, File file )
{
return getRelative( basedir, file.getAbsolutePath() );
Modified: maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/utils/PathUtilTest.java
URL: http://svn.apache.org/viewvc/maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/utils/PathUtilTest.java?view=diff&rev=528536&r1=528535&r2=528536
==============================================================================
--- maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/utils/PathUtilTest.java (original)
+++ maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/utils/PathUtilTest.java Fri Apr 13 08:51:41 2007
@@ -19,7 +19,9 @@
* under the License.
*/
-import org.apache.maven.archiva.common.utils.PathUtil;
+import org.apache.commons.lang.StringUtils;
+
+import java.io.File;
import junit.framework.TestCase;
@@ -36,5 +38,41 @@
{
assertEquals( "path/to/resource.xml", PathUtil.getRelative( "/home/user/foo/repository",
"/home/user/foo/repository/path/to/resource.xml" ) );
+ }
+
+ public void testToUrlRelativePath()
+ {
+ File workingDir = new File( "." );
+
+ String workingDirname = StringUtils.replaceChars( workingDir.getAbsolutePath(), '\\', '/' );
+
+ // Some JVM's retain the "." at the end of the path. Drop it.
+ if ( workingDirname.endsWith( "/." ) )
+ {
+ workingDirname = workingDirname.substring( 0, workingDirname.length() - 2 );
+ }
+
+ String path = "path/to/resource.xml";
+ String expectedPath = "file:" + workingDirname + "/" + path;
+
+ assertEquals( expectedPath, PathUtil.toUrl( path ) );
+ }
+
+ public void testToUrlUsingFileUrl()
+ {
+ File workingDir = new File( "." );
+
+ String workingDirname = StringUtils.replaceChars( workingDir.getAbsolutePath(), '\\', '/' );
+
+ // Some JVM's retain the "." at the end of the path. Drop it.
+ if ( workingDirname.endsWith( "/." ) )
+ {
+ workingDirname = workingDirname.substring( 0, workingDirname.length() - 2 );
+ }
+
+ String path = "path/to/resource.xml";
+ String expectedPath = "file:" + workingDirname + "/" + path;
+
+ assertEquals( expectedPath, PathUtil.toUrl( expectedPath ) );
}
}