harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From regi...@apache.org
Subject svn commit: r826579 - in /harmony/enhanced/classlib/trunk/modules/prefs: make/ src/main/java/java/util/prefs/ src/main/java/org/apache/harmony/prefs/internal/nls/ src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/ src/test/resources/config/ ...
Date Mon, 19 Oct 2009 02:43:19 GMT
Author: regisxu
Date: Mon Oct 19 02:43:18 2009
New Revision: 826579

URL: http://svn.apache.org/viewvc?rev=826579&view=rev
Log:
Apply patch for HARMONY-6063: [classlib][prefs] implement mechanism of loading preference
service provider
    
Minor changes of patch HARMONY-6063.diff to make it work with latest build script.


Added:
    harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesProviderTest.java
  (with props)
    harmony/enhanced/classlib/trunk/modules/prefs/src/test/resources/config/
    harmony/enhanced/classlib/trunk/modules/prefs/src/test/resources/config/META-INF/
    harmony/enhanced/classlib/trunk/modules/prefs/src/test/resources/config/META-INF/services/
    harmony/enhanced/classlib/trunk/modules/prefs/src/test/resources/config/META-INF/services/java.util.prefs.PreferencesFactory
  (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/prefs/make/run-test.xml
    harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/Preferences.java
    harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/org/apache/harmony/prefs/internal/nls/messages.properties

Modified: harmony/enhanced/classlib/trunk/modules/prefs/make/run-test.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/prefs/make/run-test.xml?rev=826579&r1=826578&r2=826579&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/prefs/make/run-test.xml (original)
+++ harmony/enhanced/classlib/trunk/modules/prefs/make/run-test.xml Mon Oct 19 02:43:18 2009
@@ -36,6 +36,7 @@
         <run-selected-hdk-tests module="prefs" jar="prefs_tests.jar">
             <excludeorinclude>
                 <exclude name="org/apache/harmony/prefs/tests/java/util/prefs/FilePreferencesImplTest.class"
unless="test.case" />
+                <exclude name="org/apache/harmony/prefs/tests/java/util/prefs/PreferencesProviderTest.class"
unless="test.case" />
                 <include name="**/*Test.class" unless="test.case"/>
             </excludeorinclude>
         </run-selected-hdk-tests>
@@ -44,6 +45,14 @@
                 <include name="org/apache/harmony/prefs/tests/java/util/prefs/FilePreferencesImplTest.class"
unless="test.case" />
             </excludeorinclude>
         </run-selected-hdk-tests>
+        <run-selected-hdk-tests module="prefs" jar="prefs_tests.jar">
+            <excludeorinclude>
+                <include name="org/apache/harmony/prefs/tests/java/util/prefs/PreferencesProviderTest.class"
unless="test.case" />
+            </excludeorinclude>
+            <junit-elements>
+                <classpath location="resources/config" />
+            </junit-elements>
+        </run-selected-hdk-tests>
     </target>
     
 </project>

Modified: harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/Preferences.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/Preferences.java?rev=826579&r1=826578&r2=826579&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/Preferences.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/Preferences.java
Mon Oct 19 02:43:18 2009
@@ -16,8 +16,11 @@
 
 package java.util.prefs;
 
+import java.io.BufferedInputStream;
+import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.net.MalformedURLException;
 import java.security.AccessController;
@@ -124,6 +127,10 @@
             }
         });
 
+        if (factoryClassName == null) {
+            factoryClassName = readProviderFromFile();
+        }
+
         // set default provider
         if (factoryClassName == null) {
             String osName = AccessController.doPrivileged(new PrivilegedAction<String>()
{
@@ -154,6 +161,45 @@
         }
     }
 
+    private static String readProviderFromFile() throws InternalError {
+        ClassLoader systemLoader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
{
+            public ClassLoader run() {
+                return ClassLoader.getSystemClassLoader();
+            }
+        });
+
+        if (systemLoader != null) {
+            InputStream in = systemLoader.getResourceAsStream("META-INF/services/java.util.prefs.PreferencesFactory");
//$NON-NLS-1$
+            if (in != null) {
+                BufferedReader reader = new BufferedReader(new InputStreamReader(in));
+                String line = null;
+                try {
+                    while ((line = reader.readLine()) != null) {
+                        int index = line.indexOf("#"); //$NON-NLS-1$
+                        // Trim comments
+                        if (index != -1) {
+                            line = line.substring(0, index);
+                        }
+                        String trimedName = line.trim();
+                        if (!"".equals(trimedName)) { //$NON-NLS-1$
+                            return trimedName;
+                        }
+                    }
+                } catch (IOException e) {
+                    // prefs.11=Load provider configuration file faild: {0}
+                    throw new InternalError(Messages.getString("prefs.11", e));   //$NON-NLS-1$
+                } finally {
+                    try {
+                        reader.close();
+                    } catch (IOException e) {
+                        // ignore
+                    }
+                }
+            }
+        }
+        return null;
+    }
+
     /**
      * Default constructor, for use by subclasses only.
      */

Modified: harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/org/apache/harmony/prefs/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/org/apache/harmony/prefs/internal/nls/messages.properties?rev=826579&r1=826578&r2=826579&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/org/apache/harmony/prefs/internal/nls/messages.properties
(original)
+++ harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/org/apache/harmony/prefs/internal/nls/messages.properties
Mon Oct 19 02:43:18 2009
@@ -31,3 +31,4 @@
 prefs.D=Enumerate keys error
 prefs.E=Access denied
 prefs.F=Remove node error\!
+prefs.11=Load provider configuration file faild: {0}
\ No newline at end of file

Added: harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesProviderTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesProviderTest.java?rev=826579&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesProviderTest.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesProviderTest.java
Mon Oct 19 02:43:18 2009
@@ -0,0 +1,31 @@
+/* 
+ * 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.prefs.tests.java.util.prefs;
+
+import java.util.prefs.Preferences;
+
+import junit.framework.TestCase;
+
+public class PreferencesProviderTest extends TestCase {
+
+    public void testLoadProviderFromFile() {
+        System.clearProperty("java.util.prefs.PreferencesFactory");
+
+        assertEquals(MockAbstractPreferences.class, Preferences.systemRoot().getClass());
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesProviderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/prefs/src/test/resources/config/META-INF/services/java.util.prefs.PreferencesFactory
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/prefs/src/test/resources/config/META-INF/services/java.util.prefs.PreferencesFactory?rev=826579&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/prefs/src/test/resources/config/META-INF/services/java.util.prefs.PreferencesFactory
(added)
+++ harmony/enhanced/classlib/trunk/modules/prefs/src/test/resources/config/META-INF/services/java.util.prefs.PreferencesFactory
Mon Oct 19 02:43:18 2009
@@ -0,0 +1,6 @@
+              
+# It's comments
+
+org.apache.harmony.prefs.tests.java.util.prefs.MockPreferencesFactory # mock provider
+
+only first class name is loaded

Propchange: harmony/enhanced/classlib/trunk/modules/prefs/src/test/resources/config/META-INF/services/java.util.prefs.PreferencesFactory
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message