maven-surefire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hbout...@apache.org
Subject svn commit: r635738 - in /maven/surefire/trunk/surefire-api/src: main/java/org/apache/maven/surefire/util/UrlUtils.java test/java/org/apache/maven/surefire/util/UrlUtilsTest.java
Date Mon, 10 Mar 2008 22:36:30 GMT
Author: hboutemy
Date: Mon Mar 10 15:36:24 2008
New Revision: 635738

URL: http://svn.apache.org/viewvc?rev=635738&view=rev
Log:
[SUREFIRE-467] restore JDK1.3 compatibility: revert r597766 and fix umlaut handling without
JDK1.4 API

Modified:
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/UrlUtils.java
    maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/UrlUtilsTest.java

Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/UrlUtils.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/UrlUtils.java?rev=635738&r1=635737&r2=635738&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/UrlUtils.java
(original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/UrlUtils.java
Mon Mar 10 15:36:24 2008
@@ -20,22 +20,76 @@
  */
 
 import java.io.File;
+import java.io.UnsupportedEncodingException;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.BitSet;
 
 /**
  * Utility for dealing with URLs in pre-JDK 1.4.
  */
 public class UrlUtils
 {
+    private static final BitSet UNRESERVED = new BitSet( Byte.MAX_VALUE - Byte.MIN_VALUE
+ 1 );
+
+    private static final int RADIX = 16;
+
+    private static final int MASK = 0xf;
+
+    private UrlUtils()
+    {
+    }
+
+    private static final String ENCODING = "UTF-8";
+
+    static
+    {
+        try
+        {
+            byte[] bytes =
+                "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.!~*'():/".getBytes(
ENCODING );
+            for ( int i = 0; i < bytes.length; i++ )
+            {
+                UNRESERVED.set( bytes[i] );
+            }
+        }
+        catch ( UnsupportedEncodingException e )
+        {
+            // can't happen as UTF-8 must be present
+        }
+    }
 
     public static URL getURL( File file )
         throws MalformedURLException
     {
-        
+        // with JDK 1.4+, code would be: return new URL( file.toURI().toASCIIString() );
+        URL url = file.toURL();
         // encode any characters that do not comply with RFC 2396
         // this is primarily to handle Windows where the user's home directory contains spaces
-        
-        return new URL( file.toURI().toASCIIString() );
+        try
+        {
+            byte[] bytes = url.toString().getBytes( ENCODING );
+            StringBuffer buf = new StringBuffer( bytes.length );
+            for ( int i = 0; i < bytes.length; i++ )
+            {
+                byte b = bytes[i];
+                if ( b > 0 && UNRESERVED.get( b ) )
+                {
+                    buf.append( (char) b );
+                }
+                else
+                {
+                    buf.append( '%' );
+                    buf.append( Character.forDigit( b >>> 4 & MASK, RADIX )
);
+                    buf.append( Character.forDigit( b & MASK, RADIX ) );
+                }
+            }
+            return new URL( buf.toString() );
+        }
+        catch ( UnsupportedEncodingException e )
+        {
+            // should not happen as UTF-8 must be present
+            throw new NestedRuntimeException( e );
+        }
     }
 }

Modified: maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/UrlUtilsTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/UrlUtilsTest.java?rev=635738&r1=635737&r2=635738&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/UrlUtilsTest.java
(original)
+++ maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/UrlUtilsTest.java
Mon Mar 10 15:36:24 2008
@@ -70,7 +70,7 @@
         throws IOException
     {
         File f = new File( homeDir, "fo\u00DC.txt" );
-        assertEquals( new URL( "file:" + homeDir + "/fo%C3%9C.txt" ), UrlUtils.getURL( f
) );
+        assertEquals( new URL( "file:" + homeDir + "/fo%c3%9c.txt" ), UrlUtils.getURL( f
) );
     }
 
 }



Mime
View raw message