You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by lv...@apache.org on 2009/01/07 10:07:28 UTC

svn commit: r732281 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/net/ test/impl/common/org/ test/impl/common/org/apache/ test/impl/common/org/apache/harmony/ test/impl/common/org/apache/harmony/luni/ test/impl/common/org/apach...

Author: lvjing
Date: Wed Jan  7 01:07:28 2009
New Revision: 732281

URL: http://svn.apache.org/viewvc?rev=732281&view=rev
Log:
Apply patch for HARMONY-6059 [classlib][luni] jar URL is created with wrong protocol for URLStreamHandler

Added:
    harmony/enhanced/classlib/trunk/modules/luni/src/test/impl/common/org/
    harmony/enhanced/classlib/trunk/modules/luni/src/test/impl/common/org/apache/
    harmony/enhanced/classlib/trunk/modules/luni/src/test/impl/common/org/apache/harmony/
    harmony/enhanced/classlib/trunk/modules/luni/src/test/impl/common/org/apache/harmony/luni/
    harmony/enhanced/classlib/trunk/modules/luni/src/test/impl/common/org/apache/harmony/luni/tests/
    harmony/enhanced/classlib/trunk/modules/luni/src/test/impl/common/org/apache/harmony/luni/tests/java/
    harmony/enhanced/classlib/trunk/modules/luni/src/test/impl/common/org/apache/harmony/luni/tests/java/net/
    harmony/enhanced/classlib/trunk/modules/luni/src/test/impl/common/org/apache/harmony/luni/tests/java/net/URLClassLoaderImplTest.java   (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLClassLoader.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLClassLoader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLClassLoader.java?rev=732281&r1=732280&r2=732281&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLClassLoader.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLClassLoader.java Wed Jan  7 01:07:28 2009
@@ -915,9 +915,10 @@
             return new URL("jar", "", //$NON-NLS-1$ //$NON-NLS-2$
                     -1, url.toString() + "!/"); //$NON-NLS-1$
         }
+        // use jar protocol as the stream handler protocol
         return new URL("jar", "", //$NON-NLS-1$ //$NON-NLS-2$
                 -1, url.toString() + "!/", //$NON-NLS-1$
-                factory.createURLStreamHandler(protocol));
+                factory.createURLStreamHandler("jar"));//$NON-NLS-1$
     }
 
     /**
@@ -1039,6 +1040,7 @@
                     jarURL.toExternalForm() + "!/").openConnection(); //$NON-NLS-1$
             JarFile jf = juc.getJarFile();
             URLJarHandler jarH = new URLJarHandler(url, jarURL, jf, prefixName);
+
             if (jarH.getIndex() == null) {
                 try {
                     Manifest manifest = jf.getManifest();

Added: harmony/enhanced/classlib/trunk/modules/luni/src/test/impl/common/org/apache/harmony/luni/tests/java/net/URLClassLoaderImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/impl/common/org/apache/harmony/luni/tests/java/net/URLClassLoaderImplTest.java?rev=732281&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/impl/common/org/apache/harmony/luni/tests/java/net/URLClassLoaderImplTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/impl/common/org/apache/harmony/luni/tests/java/net/URLClassLoaderImplTest.java Wed Jan  7 01:07:28 2009
@@ -0,0 +1,76 @@
+/*
+ *  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.
+ */
+
+package org.apache.harmony.luni.tests.java.net;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.net.URLStreamHandler;
+import java.net.URLStreamHandlerFactory;
+
+import org.apache.harmony.luni.internal.net.www.protocol.jar.Handler;
+
+import junit.framework.TestCase;
+
+import tests.support.Support_Configuration;
+import tests.support.resource.Support_Resources;
+
+/**
+ *  Depends on:
+ *    file://<basedir>/src/test/resources/org/apache/harmony/luni/tests/java/net/lf.jar
+ */
+public class URLClassLoaderImplTest extends TestCase {
+    
+    private static final char SEP = File.separatorChar;
+    private static final URL BASE = URLClassLoaderImplTest.class.getClassLoader().getResource(".."+SEP+URLClassLoaderImplTest.class.getPackage().getName().replace('.', SEP));
+
+    /**
+     * @tests java.net.URLClassLoader#URLClassLoader(java.net.URL[],
+     *        java.lang.ClassLoader, java.net.URLStreamHandlerFactory)
+     */
+    public void test_Constructor$Ljava_net_URLLjava_lang_ClassLoaderLjava_net_URLStreamHandlerFactory() {
+        class TestFactory implements URLStreamHandlerFactory {
+            public URLStreamHandler createURLStreamHandler(String protocol) {
+                if ("jar".equals(protocol)) {
+                    return new Handler();
+                } else {
+                    fail("Should be jar Handler. But " + protocol);
+                    return null;
+                }
+            }
+
+        }
+
+        URLClassLoader ucl = null;
+
+        URL[] u = new URL[1];
+        try {
+            u[0] = new URL(BASE.toString() + SEP + "lf.jar");
+            ucl = new URLClassLoader(u, null, new TestFactory());
+            URL res = null;
+            res = ucl.findResource("swt.dll");
+
+            assertNotNull(res);
+            assertEquals("Failed", BASE.toString()+SEP+"lf.jar!"+SEP+"swt.dll", res.getFile());
+        } catch (MalformedURLException e) {
+            fail("should not be here. " + e);
+        }
+    }
+
+}

Propchange: harmony/enhanced/classlib/trunk/modules/luni/src/test/impl/common/org/apache/harmony/luni/tests/java/net/URLClassLoaderImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native