harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r986247 - in /harmony/enhanced/java/branches/java6: ./ classlib/ classlib/depends/libs/ classlib/modules/imageio/ classlib/modules/imageio/src/main/java/javax/imageio/ classlib/modules/imageio/src/main/java/javax/imageio/spi/ classlib/modul...
Date Tue, 17 Aug 2010 09:23:33 GMT
Author: hindessm
Date: Tue Aug 17 09:23:32 2010
New Revision: 986247

URL: http://svn.apache.org/viewvc?rev=986247&view=rev
Log:
Merge change from /harmony/enhanced/java/trunk@986136:

  r986136 | hindessm | 2010-08-16 22:59:27 +0100 (Mon, 16 Aug 2010) | 6 lines
  
  Apply patch from "[#HARMONY-6553] Implement
  ServiceRegistry.lookupProviders(class)".
  
  Add a <metainf> line to test jar ant task so that the test passes when
  run from the hdk.
  


Added:
    harmony/enhanced/java/branches/java6/classlib/modules/imageio/src/test/java/META-INF/
      - copied from r986136, harmony/enhanced/java/trunk/classlib/modules/imageio/src/test/java/META-INF/
    harmony/enhanced/java/branches/java6/classlib/modules/imageio/src/test/java/META-INF/services/
      - copied from r986136, harmony/enhanced/java/trunk/classlib/modules/imageio/src/test/java/META-INF/services/
    harmony/enhanced/java/branches/java6/classlib/modules/imageio/src/test/java/META-INF/services/javax.imageio.spi.CorrectProviderConfiguration
      - copied unchanged from r986136, harmony/enhanced/java/trunk/classlib/modules/imageio/src/test/java/META-INF/services/javax.imageio.spi.CorrectProviderConfiguration
    harmony/enhanced/java/branches/java6/classlib/modules/imageio/src/test/java/META-INF/services/javax.imageio.spi.IncorrectProviderConfiguration
      - copied unchanged from r986136, harmony/enhanced/java/trunk/classlib/modules/imageio/src/test/java/META-INF/services/javax.imageio.spi.IncorrectProviderConfiguration
    harmony/enhanced/java/branches/java6/classlib/modules/imageio/src/test/java/javax/imageio/spi/CorrectProviderConfiguration.java
      - copied unchanged from r986136, harmony/enhanced/java/trunk/classlib/modules/imageio/src/test/java/javax/imageio/spi/CorrectProviderConfiguration.java
    harmony/enhanced/java/branches/java6/classlib/modules/imageio/src/test/java/javax/imageio/spi/IncorrectProviderConfiguration.java
      - copied unchanged from r986136, harmony/enhanced/java/trunk/classlib/modules/imageio/src/test/java/javax/imageio/spi/IncorrectProviderConfiguration.java
Modified:
    harmony/enhanced/java/branches/java6/   (props changed)
    harmony/enhanced/java/branches/java6/classlib/   (props changed)
    harmony/enhanced/java/branches/java6/classlib/depends/libs/   (props changed)
    harmony/enhanced/java/branches/java6/classlib/modules/imageio/build.xml
    harmony/enhanced/java/branches/java6/classlib/modules/imageio/src/main/java/javax/imageio/ImageIO.java
    harmony/enhanced/java/branches/java6/classlib/modules/imageio/src/main/java/javax/imageio/spi/IIORegistry.java
    harmony/enhanced/java/branches/java6/classlib/modules/imageio/src/main/java/javax/imageio/spi/ServiceRegistry.java
    harmony/enhanced/java/branches/java6/classlib/modules/imageio/src/main/java/org/apache/harmony/x/imageio/internal/nls/messages.properties
    harmony/enhanced/java/branches/java6/classlib/modules/imageio/src/test/java/javax/imageio/spi/ServiceRegistryTest.java
    harmony/enhanced/java/branches/java6/drlvm/   (props changed)
    harmony/enhanced/java/branches/java6/jdktools/   (props changed)

Propchange: harmony/enhanced/java/branches/java6/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Aug 17 09:23:32 2010
@@ -1,4 +1,4 @@
 /harmony/enhanced/java/branches/mrh:935751-941490
-/harmony/enhanced/java/trunk:929253-979569,979593,979613,979615,979647,979659,979682,979897,980326,980632,981356,981763,981811,981820,982146,982148,982183,982250,982377,982498,982614,982650,982777,982887,983879,983902,984367,984577,984597-984598,984613,984682,984708,984731,984779,984784,984798,985098,985141
+/harmony/enhanced/java/trunk:929253-979569,979593,979613,979615,979647,979659,979682,979897,980326,980632,981356,981763,981811,981820,982146,982148,982183,982250,982377,982498,982614,982650,982777,982887,983879,983902,984367,984577,984597-984598,984613,984682,984708,984731,984779,984784,984798,985098,985141,986136
 /harmony/enhanced/trunk:476395-929252
 /incubator/harmony/enhanced/trunk:292550-476394

Propchange: harmony/enhanced/java/branches/java6/classlib/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Aug 17 09:23:32 2010
@@ -1,7 +1,7 @@
 /harmony/enhanced/classlib/trunk:713674-735919,765923-926091,926318-926838
 /harmony/enhanced/classlib/trunk/working_classlib:884014-884286
 /harmony/enhanced/java/branches/mrh/classlib:935751-941490
-/harmony/enhanced/java/trunk/classlib:929253-979569,979593,979613,979615,979647,979659,979682,979897,980326,980632,981356,981763,981811,981820,982146,982148,982183,982250,982377,982498,982614,982650,982777,982887,983879,983902,984367,984577,984597-984598,984613,984682,984708,984731,984779,984784,984798,985098,985141
+/harmony/enhanced/java/trunk/classlib:929253-979569,979593,979613,979615,979647,979659,979682,979897,980326,980632,981356,981763,981811,981820,982146,982148,982183,982250,982377,982498,982614,982650,982777,982887,983879,983902,984367,984577,984597-984598,984613,984682,984708,984731,984779,984784,984798,985098,985141,986136
 /harmony/enhanced/trunk/classlib:476395-929252
 /harmony/enhanced/trunk/working_classlib:476396-920147
 /incubator/harmony/enhanced/trunk/classlib:292550-476394

Propchange: harmony/enhanced/java/branches/java6/classlib/depends/libs/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Aug 17 09:23:32 2010
@@ -1,4 +1,4 @@
 /harmony/enhanced/classlib/trunk/depends/libs:544451-926091
-/harmony/enhanced/java/trunk/classlib/depends/libs:929253-979569,979593,979613,979615,979647,979659,979682,979897,980326,980632,981356,981763,981811,981820,982146,982148,982183,982250,982377,982498,982614,982650,982777,982887,983879,983902,984367,984577,984597-984598,984613,984682,984708,984731,984779,984784,984798,985098,985141
+/harmony/enhanced/java/trunk/classlib/depends/libs:929253-979569,979593,979613,979615,979647,979659,979682,979897,980326,980632,981356,981763,981811,981820,982146,982148,982183,982250,982377,982498,982614,982650,982777,982887,983879,983902,984367,984577,984597-984598,984613,984682,984708,984731,984779,984784,984798,985098,985141,986136
 /harmony/enhanced/trunk/classlib/depends/libs:476395-929252
 /incubator/harmony/enhanced/trunk/classlib/depends/libs:292550-476394

Modified: harmony/enhanced/java/branches/java6/classlib/modules/imageio/build.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/imageio/build.xml?rev=986247&r1=986246&r2=986247&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/imageio/build.xml (original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/imageio/build.xml Tue Aug 17 09:23:32
2010
@@ -178,6 +178,7 @@ ${line.separator}For Fedora try: yum ins
         <copy file="make/run-test.xml" tofile="${tests.hdk.dir}/build.xml" />
         
         <hy.jar.bin destfile="${tests.hdk.dir}/${hy.module}_tests.jar">
+            <metainf dir="src/test/java/META-INF" />
             <fileset dir="bin/test" />
         </hy.jar.bin>
 

Modified: harmony/enhanced/java/branches/java6/classlib/modules/imageio/src/main/java/javax/imageio/ImageIO.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/imageio/src/main/java/javax/imageio/ImageIO.java?rev=986247&r1=986246&r2=986247&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/imageio/src/main/java/javax/imageio/ImageIO.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/imageio/src/main/java/javax/imageio/ImageIO.java
Tue Aug 17 09:23:32 2010
@@ -44,9 +44,8 @@ public final class ImageIO {
     private ImageIO() {}
     
 
-    public static void scanForPlugins() throws NotImplementedException {
-        // TODO: implement
-        throw new NotImplementedException();
+    public static void scanForPlugins() {
+        registry.registerApplicationClasspathSpis();
     }
 
     public static void setUseCache(boolean useCache) {

Modified: harmony/enhanced/java/branches/java6/classlib/modules/imageio/src/main/java/javax/imageio/spi/IIORegistry.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/imageio/src/main/java/javax/imageio/spi/IIORegistry.java?rev=986247&r1=986246&r2=986247&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/imageio/src/main/java/javax/imageio/spi/IIORegistry.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/imageio/src/main/java/javax/imageio/spi/IIORegistry.java
Tue Aug 17 09:23:32 2010
@@ -19,7 +19,10 @@
  */
 package javax.imageio.spi;
 
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.Arrays;
+import java.util.Iterator;
 
 import org.apache.harmony.x.imageio.plugins.gif.GIFImageReaderSpi;
 import org.apache.harmony.x.imageio.plugins.jpeg.JPEGImageReaderSpi;
@@ -75,7 +78,17 @@ public final class IIORegistry extends S
         }
     }
 
-    public void registerApplicationClasspathSpis() {
-        // -- TODO implement for non-builtin plugins
+    @SuppressWarnings("unchecked")
+	public void registerApplicationClasspathSpis() {
+        AccessController.doPrivileged(new PrivilegedAction() {
+			public Object run() {
+				Iterator<Class<?>> categories = getCategories();
+				while (categories.hasNext()) {
+					Iterator providers = lookupProviders(categories.next());
+					registerServiceProviders(providers);
+				}
+				return this;
+			}
+        });
     }
 }

Modified: harmony/enhanced/java/branches/java6/classlib/modules/imageio/src/main/java/javax/imageio/spi/ServiceRegistry.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/imageio/src/main/java/javax/imageio/spi/ServiceRegistry.java?rev=986247&r1=986246&r2=986247&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/imageio/src/main/java/javax/imageio/spi/ServiceRegistry.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/imageio/src/main/java/javax/imageio/spi/ServiceRegistry.java
Tue Aug 17 09:23:32 2010
@@ -19,6 +19,11 @@
  */
 package javax.imageio.spi;
 
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
 import java.util.*;
 import java.util.Map.Entry;
 
@@ -42,9 +47,8 @@ public class ServiceRegistry {
         }
     }
 
-    public static <T> Iterator<T> lookupProviders(Class<T> providerClass,
ClassLoader loader) throws NotImplementedException {
-        // TODO: implement
-        throw new NotImplementedException();
+    public static <T> Iterator<T> lookupProviders(Class<T> providerClass,
ClassLoader loader) {
+        return new LookupProvidersIterator(providerClass, loader);
     }
 
     public static <T> Iterator<T> lookupProviders(Class<T> providerClass)
{
@@ -549,4 +553,133 @@ public class ServiceRegistry {
             throw new UnsupportedOperationException();
         }
     }
+    
+    static class LookupProvidersIterator<T> implements Iterator {
+
+        private Set<String> providerNames = new HashSet<String>();
+        private Iterator<String> it = null;
+        private ClassLoader loader = null;
+        
+        public LookupProvidersIterator(Class<T> providerClass, ClassLoader loader)
{
+            this.loader = loader;
+            
+            Enumeration<URL> e = null;
+            try {
+                e = loader.getResources("META-INF/services/"+providerClass.getName()); //$NON-NLS-1$
+                while (e.hasMoreElements()) {
+                    Set<String> names = parse((URL)e.nextElement());
+                    providerNames.addAll(names);
+                }
+            } catch (IOException e1) {
+                // Ignored
+            }
+
+            it = providerNames.iterator();
+        }
+        
+        /*
+         * Parse the provider-configuration file as specified 
+         * @see <a href="http://java.sun.com/j2se/1.5.0/docs/guide/jar/jar.html#Provider
Configuration File">JAR File Specification</a>
+         */
+        private Set<String> parse(URL u) {
+            InputStream input = null;
+            BufferedReader reader = null;
+            Set<String> names = new HashSet<String>();
+            try {
+                input = u.openStream();
+                reader = new BufferedReader(new InputStreamReader(input, "utf-8")); //$NON-NLS-1$
+                
+                String line;
+                while ((line = reader.readLine()) != null) {
+                    // The comment character is '#' (0x23)
+                    // on each line all characters following the first comment character
are ignored
+                    int sharpIndex = line.indexOf('#');
+                    if (sharpIndex>=0) {
+                        line = line.substring(0, sharpIndex);
+                    }
+                    
+                    // Whitespaces are ignored
+                    line = line.trim();
+                    
+                    if (line.length()>0) {
+                        // a java class name, check if identifier correct
+                        char[] namechars = line.toCharArray();
+                        for (int i = 0; i < namechars.length; i++) {
+                            if (!(Character.isJavaIdentifierPart(namechars[i]) || namechars[i]
== '.')) {
+                                throw new ServiceConfigurationError(Messages.getString("imageio.99",
line));
+                            }
+                        }
+                        names.add(line);
+                    }
+                }
+            } catch (IOException e) {
+                throw new ServiceConfigurationError(e.toString());
+            } finally {
+                try {
+                    if (reader != null) {
+                        reader.close();
+                    }
+                    if (input != null) {
+                        input.close();
+                    }
+                } catch (IOException e) {
+                    throw new ServiceConfigurationError(e.toString());
+                }
+            }
+            
+            return names;
+        }
+        
+        public boolean hasNext() {
+            return it.hasNext();
+        }
+
+        public Object next() {
+            if (!hasNext()) {
+                throw new NoSuchElementException();
+            }
+            
+            String name = (String)it.next();
+            try {
+                return Class.forName(name, true, loader).newInstance();
+            } catch (Exception e) {
+                throw new ServiceConfigurationError(e.toString());
+            }
+        }
+
+        public void remove() {
+            throw new UnsupportedOperationException();   
+        }
+    }
+    
+    /**
+     * An Error that can be thrown when something wrong occurs in loading a service
+     * provider.
+     */
+    static class ServiceConfigurationError extends Error {
+        
+        private static final long serialVersionUID = 74132770414881L;
+
+        /**
+         * The constructor
+         * 
+         * @param msg
+         *            the message of this error
+         */
+        public ServiceConfigurationError(String msg) {
+            super(msg);
+        }
+
+        /**
+         * The constructor
+         * 
+         * @param msg
+         *            the message of this error
+         * @param cause 
+         *            the cause of this error
+         */
+        public ServiceConfigurationError(String msg, Throwable cause) {
+            super(msg, cause);
+        }
+    }
 }

Modified: harmony/enhanced/java/branches/java6/classlib/modules/imageio/src/main/java/org/apache/harmony/x/imageio/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/imageio/src/main/java/org/apache/harmony/x/imageio/internal/nls/messages.properties?rev=986247&r1=986246&r2=986247&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/imageio/src/main/java/org/apache/harmony/x/imageio/internal/nls/messages.properties
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/imageio/src/main/java/org/apache/harmony/x/imageio/internal/nls/messages.properties
Tue Aug 17 09:23:32 2010
@@ -167,4 +167,5 @@ imageio.95=Input is not an instance of j
 imageio.96=Writer cannot be null
 imageio.97=Reader cannot be null
 imageio.98=Ordered providers cannot be equal
+imageio.99=Illegal provider-class name: {0}
 

Modified: harmony/enhanced/java/branches/java6/classlib/modules/imageio/src/test/java/javax/imageio/spi/ServiceRegistryTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/imageio/src/test/java/javax/imageio/spi/ServiceRegistryTest.java?rev=986247&r1=986246&r2=986247&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/imageio/src/test/java/javax/imageio/spi/ServiceRegistryTest.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/imageio/src/test/java/javax/imageio/spi/ServiceRegistryTest.java
Tue Aug 17 09:23:32 2010
@@ -31,6 +31,22 @@ import javax.imageio.spi.ImageWriterSpi;
 
 public class ServiceRegistryTest extends TestCase {
 
+    public void testLookupProviders() {
+        // lookup from a correct provider-configuration file
+        Iterator it = ServiceRegistry.lookupProviders(CorrectProviderConfiguration.class);

+        assertEquals("Failed to find provider and instantiate it",
+                "class javax.imageio.spi.CorrectProviderConfiguration", 
+                it.next().getClass().toString());
+       
+        // lookup from incorrect provider-configuration file
+        try {
+            it = ServiceRegistry.lookupProviders(IncorrectProviderConfiguration.class);
+            fail("ServiceConfigurationError expected");
+        } catch (Error e) {
+            // Ok
+        }
+    }
+    
     public void testDeregisterAll() {
         Class[] CATEGORIES = new Class[] {
                 ImageReaderSpi.class };

Propchange: harmony/enhanced/java/branches/java6/drlvm/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Aug 17 09:23:32 2010
@@ -1,5 +1,5 @@
 /harmony/enhanced/java/branches/mrh/drlvm:935751-941490
-/harmony/enhanced/java/trunk/drlvm:929253-979569,979593,979613,979615,979647,979659,979682,979897,980326,980632,981356,981763,981811,981820,982146,982148,982183,982250,982377,982498,982614,982650,982777,982887,983879,983902,984367,984577,984597-984598,984613,984682,984708,984731,984779,984784,984798,985098,985141
+/harmony/enhanced/java/trunk/drlvm:929253-979569,979593,979613,979615,979647,979659,979682,979897,980326,980632,981356,981763,981811,981820,982146,982148,982183,982250,982377,982498,982614,982650,982777,982887,983879,983902,984367,984577,984597-984598,984613,984682,984708,984731,984779,984784,984798,985098,985141,986136
 /harmony/enhanced/trunk/drlvm:476395-929252
 /harmony/enhanced/trunk/working_vm:476396-920147
 /incubator/harmony/enhanced/trunk/drlvm:292550-476394

Propchange: harmony/enhanced/java/branches/java6/jdktools/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Aug 17 09:23:32 2010
@@ -1,4 +1,4 @@
-/harmony/enhanced/java/trunk/jdktools:929253-979569,979593,979613,979615,979647,979659,979682,979897,980326,980632,981356,981763,981811,981820,982146,982148,982183,982250,982377,982498,982614,982650,982777,982887,983879,983902,984367,984577,984597-984598,984613,984682,984708,984731,984779,984784,984798,985098,985141
+/harmony/enhanced/java/trunk/jdktools:929253-979569,979593,979613,979615,979647,979659,979682,979897,980326,980632,981356,981763,981811,981820,982146,982148,982183,982250,982377,982498,982614,982650,982777,982887,983879,983902,984367,984577,984597-984598,984613,984682,984708,984731,984779,984784,984798,985098,985141,986136
 /harmony/enhanced/jdktools/trunk:630107-925933
 /harmony/enhanced/trunk/jdktools:476395-929252
 /harmony/enhanced/trunk/working_jdktools:476396-920147



Mime
View raw message