db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r1372345 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/compatibility/ClientCompatibilityRunControl.java functionTests/tests/compatibility/VersionCombinationConfigurator.java junit/DerbyDistribution.java
Date Mon, 13 Aug 2012 09:53:42 GMT
Author: kristwaa
Date: Mon Aug 13 09:53:41 2012
New Revision: 1372345

URL: http://svn.apache.org/viewvc?rev=1372345&view=rev
Log:
DERBY-5897: Broken handling of paths with special characters in compatibility/VersionCombinationConfigurator

Fixes URL to File conversion by going via URI and using the new File(URI) ctor.
As an example, URLs containing '%20' for spaces will now result in valid files.

Patch file: derby-5897-1a-url_handling.diff (with formatting modifications)

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/ClientCompatibilityRunControl.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/VersionCombinationConfigurator.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DerbyDistribution.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/ClientCompatibilityRunControl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/ClientCompatibilityRunControl.java?rev=1372345&r1=1372344&r2=1372345&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/ClientCompatibilityRunControl.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/ClientCompatibilityRunControl.java
Mon Aug 13 09:53:41 2012
@@ -21,7 +21,7 @@
 package org.apache.derbyTesting.functionTests.tests.compatibility;
 
 import java.io.File;
-import java.net.URL;
+import java.net.URI;
 
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import org.apache.derbyTesting.junit.DerbyDistribution;
@@ -84,7 +84,7 @@ public class ClientCompatibilityRunContr
         // Fork the client test with a minimal classpath.
         String classpath = clientDist.getDerbyClientJarPath() +
                 File.pathSeparator + testingPath +
-                File.pathSeparator + getJUnitURL().getPath();
+                File.pathSeparator + getJUnitPath();
         // If we are running the LOB tests we also need derby.jar, because the
         // test code being run references classes from the iapi package.
         // This may also happen for the non-LOB tests in the future.
@@ -113,13 +113,15 @@ public class ClientCompatibilityRunContr
         println(spawned.getFullServerOutput());
     }
 
-	/**
-	 * Returns the URL of the JUnit classes.
+    /**
+     * Returns the path of the JUnit classes.
      *
-     * @return A URL.
-	 */
-    private static URL getJUnitURL() {
-        return VersionCombinationConfigurator.getClassURL(
+     * @return A path.
+     */
+    private static String getJUnitPath() {
+        URI uri = VersionCombinationConfigurator.getClassURI(
                 junit.framework.TestCase.class);
-	}
+        return new File(uri).getPath();
+    }
 }
+

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/VersionCombinationConfigurator.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/VersionCombinationConfigurator.java?rev=1372345&r1=1372344&r2=1372345&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/VersionCombinationConfigurator.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/VersionCombinationConfigurator.java
Mon Aug 13 09:53:41 2012
@@ -21,8 +21,10 @@
 package org.apache.derbyTesting.functionTests.tests.compatibility;
 
 import java.io.File;
-import java.net.URL;
+import java.net.URISyntaxException;
+import java.net.URI;
 import java.security.AccessController;
+import java.security.CodeSource;
 import java.security.PrivilegedAction;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -253,8 +255,7 @@ public class VersionCombinationConfigura
      *      if trunk is run off the classes directory
      */
     private DerbyDistribution getRunningDistribution() {
-        URL testingURL = getClassURL(getClass());
-        File libDir = new File(testingURL.getPath());
+        File libDir = new File(getClassURI(getClass()));
         if (libDir.isDirectory()) {
             throw new IllegalStateException("only running off jars is " +
                     "supported, currently running off " + libDir);
@@ -263,7 +264,12 @@ public class VersionCombinationConfigura
         libDir = libDir.getParentFile();
         DerbyVersion version = DerbyVersion.parseVersionString(
                 sysinfo.getVersionString());
-        return DerbyDistribution.getInstance(libDir, version);
+        DerbyDistribution dist = DerbyDistribution.getInstance(libDir, version);
+        if (dist == null) {
+            throw new IllegalStateException(
+                    "failed to get running distribution (programming error?)");
+        }
+        return dist;
     }
 
     /**
@@ -305,19 +311,25 @@ public class VersionCombinationConfigura
     }
 
     /**
-     * Returns the URL of the source for the specified class.
+     * Returns the URI of the source for the specified class.
      *
      * @param cl class to find the source for
-     * @return A {@code URL} pointing to the source, or {@code null} it cannot
+     * @return A {@code URI} pointing to the source, or {@code null} it cannot
      *      be obtained.
      */
-    static URL getClassURL(final Class cl) {
-        return AccessController.doPrivileged(new PrivilegedAction<URL>() {
-            public URL run() {
-                if (cl.getProtectionDomain().getCodeSource() == null) {
-                    return null;
+    static URI getClassURI(final Class cl) {
+        return AccessController.doPrivileged(new PrivilegedAction<URI>() {
+            public URI run() {
+                CodeSource cs = cl.getProtectionDomain().getCodeSource();
+                if (cs != null) {
+                    try {
+                        return cs.getLocation().toURI();
+                    } catch (URISyntaxException use) {
+                        // Shouldn't happen, fall through and return null.
+                        BaseTestCase.alarm("bad URI: " + use.getMessage());
+                    }
                 }
-                return cl.getProtectionDomain().getCodeSource().getLocation();
+                return null;
             }
         });
     }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DerbyDistribution.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DerbyDistribution.java?rev=1372345&r1=1372344&r2=1372345&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DerbyDistribution.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DerbyDistribution.java
Mon Aug 13 09:53:41 2012
@@ -201,6 +201,7 @@ public class DerbyDistribution
                 }
             }
             if (!hasJar) {
+                BaseTestCase.println("missing jar: " + REQUIRED_JARS[i]);
                 return false;
             }
         }



Mime
View raw message