tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ple...@apache.org
Subject [9/9] incubator-tamaya git commit: TAMAYA-57 resolved possible performance issue by storing URLs in collections
Date Tue, 10 Feb 2015 06:35:23 GMT
TAMAYA-57 resolved possible performance issue by storing URLs in collections


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/61753ed7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/61753ed7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/61753ed7

Branch: refs/heads/master
Commit: 61753ed7e4fcf979d445340d64995bdf46b72a4d
Parents: 1ad0d58
Author: Reinhard Sandtner <rsandtner@apache.org>
Authored: Sat Jan 17 12:35:11 2015 +0100
Committer: Oliver B. Fischer <plexus@apache.org>
Committed: Tue Feb 10 07:34:21 2015 +0100

----------------------------------------------------------------------
 .../resources/findbugs/findbugs-exclude.xml     |  3 ---
 .../core/internal/PropertiesFileLoader.java     | 16 +++-----------
 .../provider/JavaConfigurationProvider.java     | 12 +++++------
 .../core/internal/PropetiesFileLoaderTest.java  | 22 ++++++++++++--------
 4 files changed, 22 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/61753ed7/buildconfigurations/src/main/resources/findbugs/findbugs-exclude.xml
----------------------------------------------------------------------
diff --git a/buildconfigurations/src/main/resources/findbugs/findbugs-exclude.xml b/buildconfigurations/src/main/resources/findbugs/findbugs-exclude.xml
index 7098b8e..0c4acdd 100644
--- a/buildconfigurations/src/main/resources/findbugs/findbugs-exclude.xml
+++ b/buildconfigurations/src/main/resources/findbugs/findbugs-exclude.xml
@@ -75,9 +75,6 @@ under the License.
         <Package name="org.apache.tamaya.core.internal"/>
     </Match>
 
-    <Match>
-        <Class name="org.apache.tamaya.core.internal.PropertiesFileLoader"/>
-    </Match>
     <!--<Match>-->
         <!--<Class name="org.apache.tamaya.resolver.internal.ResourceResolver" />-->
     <!--</Match>-->

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/61753ed7/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertiesFileLoader.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertiesFileLoader.java
b/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertiesFileLoader.java
index f1abdd7..becb4bb 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertiesFileLoader.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertiesFileLoader.java
@@ -22,10 +22,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
 import java.util.Enumeration;
-import java.util.HashSet;
 import java.util.Objects;
 import java.util.Properties;
-import java.util.Set;
 
 /**
  * Minimalistic loader for property files from the classpath.
@@ -44,26 +42,18 @@ public final class PropertiesFileLoader {
      *
      * @param name of the properties file
      *
-     * @return URLs of properties-files or
-     *         an empty {@link Set} if no files has been found
+     * @return {@link Enumeration} of {@link URL}s for properties-files
      *
      * @throws IOException in case of problems loading the properties-files
      */
-    public static Set<URL> resolvePropertiesFiles(String name) throws IOException {
+    public static Enumeration<URL> resolvePropertiesFiles(String name) throws IOException
{
         Objects.requireNonNull(name);
 
         if (!name.endsWith(".properties")) {
             name = name + ".properties";
         }
 
-        Set<URL> urls = new HashSet<>();
-
-        Enumeration<URL> files = Thread.currentThread().getContextClassLoader().getResources(name);
-        while (files.hasMoreElements()) {
-            urls.add(files.nextElement());
-        }
-
-        return urls;
+        return Thread.currentThread().getContextClassLoader().getResources(name);
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/61753ed7/java8/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java
b/java8/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java
index 3cca3eb..e1ef5de 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java
@@ -25,11 +25,12 @@ import org.apache.tamaya.spi.PropertySource;
 import org.apache.tamaya.spi.PropertySourceProvider;
 
 import java.io.IOException;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Enumeration;
 import java.util.List;
-import java.util.stream.Collectors;
 
 /**
  * Provider which reads all {@code javaconfiguration.properties} files from classpath
@@ -45,12 +46,11 @@ public class JavaConfigurationProvider implements PropertySourceProvider
{
         //X TODO maybe put javaconf... in META-INF
 
         try {
-            propertySources.addAll(
-                    PropertiesFileLoader.resolvePropertiesFiles("javaconfiguration.properties")
-                            .stream()
-                            .map(PropertiesFilePropertySource::new)
-                            .collect(Collectors.toList()));
 
+            Enumeration<URL> urls = PropertiesFileLoader.resolvePropertiesFiles("javaconfiguration.properties");
+            while (urls.hasMoreElements()) {
+                propertySources.add(new PropertiesFilePropertySource(urls.nextElement()));
+            }
 
         } catch (IOException e) {
             throw new ConfigException("Error while loading javaconfiguration.properties",
e);

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/61753ed7/java8/core/src/test/java/org/apache/tamaya/core/internal/PropetiesFileLoaderTest.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/internal/PropetiesFileLoaderTest.java
b/java8/core/src/test/java/org/apache/tamaya/core/internal/PropetiesFileLoaderTest.java
index c125641..a86473e 100644
--- a/java8/core/src/test/java/org/apache/tamaya/core/internal/PropetiesFileLoaderTest.java
+++ b/java8/core/src/test/java/org/apache/tamaya/core/internal/PropetiesFileLoaderTest.java
@@ -22,8 +22,8 @@ import org.junit.Assert;
 import org.junit.Test;
 
 import java.net.URL;
+import java.util.Enumeration;
 import java.util.Properties;
-import java.util.Set;
 
 public class PropetiesFileLoaderTest {
 
@@ -34,29 +34,33 @@ public class PropetiesFileLoaderTest {
 
         {
             // with .properties
-            Set<URL> urls = PropertiesFileLoader.resolvePropertiesFiles("testfile.properties");
+            Enumeration<URL> urls = PropertiesFileLoader.resolvePropertiesFiles("testfile.properties");
             Assert.assertNotNull(urls);
-            Assert.assertFalse(urls.isEmpty());
+            Assert.assertTrue(urls.hasMoreElements());
 
-            Properties properties = PropertiesFileLoader.load(urls.iterator().next());
+            Properties properties = PropertiesFileLoader.load(urls.nextElement());
             Assert.assertEquals(expectedProperties.size(), properties.size());
+
+            Assert.assertFalse(urls.hasMoreElements());
         }
 
         {
             // without .properties
-            Set<URL> urls = PropertiesFileLoader.resolvePropertiesFiles("testfile");
+            Enumeration<URL> urls = PropertiesFileLoader.resolvePropertiesFiles("testfile");
             Assert.assertNotNull(urls);
-            Assert.assertFalse(urls.isEmpty());
+            Assert.assertTrue(urls.hasMoreElements());
 
-            Properties properties = PropertiesFileLoader.load(urls.iterator().next());
+            Properties properties = PropertiesFileLoader.load(urls.nextElement());
             Assert.assertEquals(expectedProperties.size(), properties.size());
+
+            Assert.assertFalse(urls.hasMoreElements());
         }
 
         {
             // with a while which doesn't exist
-            Set<URL> urls = PropertiesFileLoader.resolvePropertiesFiles("nonexistingfile.properties");
+            Enumeration<URL> urls = PropertiesFileLoader.resolvePropertiesFiles("nonexistingfile.properties");
             Assert.assertNotNull(urls);
-            Assert.assertTrue(urls.isEmpty());
+            Assert.assertFalse(urls.hasMoreElements());
         }
 
     }


Mime
View raw message