deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From johndam...@apache.org
Subject deltaspike git commit: DELTASPIKE-1278: Added an additonal check to ensure local resources do exist to respect optional flag.
Date Sat, 12 Aug 2017 22:27:12 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 7594ba6e3 -> 6befd1231


DELTASPIKE-1278: Added an additonal check to ensure local resources do exist to respect optional
flag.


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/6befd123
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/6befd123
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/6befd123

Branch: refs/heads/master
Commit: 6befd1231ca07059d8d02158c91c6ddf9ffa481d
Parents: 7594ba6
Author: Dennis Rippinger <dennis.rippinger@gmail.com>
Authored: Sun Jul 2 14:43:31 2017 +0200
Committer: John D. Ament <johndament@apache.org>
Committed: Sat Aug 12 18:26:07 2017 -0400

----------------------------------------------------------------------
 .../deltaspike/core/util/PropertyFileUtils.java  | 19 +++++++++++++++++--
 .../core/util/PropertyFileUtilsTest.java         | 14 +++++++++++++-
 .../EnvironmentPropertyConfigSourceProvider.java |  6 ++++++
 3 files changed, 36 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6befd123/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/PropertyFileUtils.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/PropertyFileUtils.java
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/PropertyFileUtils.java
index ad9e10b..813b988 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/PropertyFileUtils.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/PropertyFileUtils.java
@@ -22,6 +22,7 @@ import javax.enterprise.inject.Typed;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.Collections;
 import java.util.Enumeration;
@@ -41,13 +42,27 @@ public abstract class PropertyFileUtils
         // prevent instantiation
     }
 
-    public static Enumeration<URL> resolvePropertyFiles(String propertyFileName) throws
IOException
+    public static Enumeration<URL> resolvePropertyFiles(String propertyFileName) throws
IOException, URISyntaxException
     {
         if (propertyFileName != null && (propertyFileName.contains("://") || propertyFileName.startsWith("file:")))
         {
             // the given string is actually already an URL
             Vector<URL> propertyFileUrls = new Vector<URL>();
-            propertyFileUrls.add(new URL(propertyFileName));
+            URL url = new URL(propertyFileName);
+
+            if (propertyFileName.startsWith("file:"))
+            {
+                File file = new File(url.toURI());
+                if (file.exists())
+                {
+                    propertyFileUrls.add(url);
+                }
+            }
+            else
+            {
+                propertyFileUrls.add(url);
+            }
+
             return propertyFileUrls.elements();
         }
 

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6befd123/deltaspike/core/api/src/test/java/org/apache/deltaspike/core/util/PropertyFileUtilsTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/test/java/org/apache/deltaspike/core/util/PropertyFileUtilsTest.java
b/deltaspike/core/api/src/test/java/org/apache/deltaspike/core/util/PropertyFileUtilsTest.java
index cde3d5b..6c8c021 100644
--- a/deltaspike/core/api/src/test/java/org/apache/deltaspike/core/util/PropertyFileUtilsTest.java
+++ b/deltaspike/core/api/src/test/java/org/apache/deltaspike/core/util/PropertyFileUtilsTest.java
@@ -25,6 +25,7 @@ import org.junit.runners.Parameterized;
 import java.io.File;
 import java.io.IOException;
 import java.net.MalformedURLException;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.Arrays;
 import java.util.Enumeration;
@@ -77,6 +78,17 @@ public class PropertyFileUtilsTest
                                         assertFalse(result.hasMoreElements());
                                     }
                                 }
+                        },
+                new Object[] // url not existent
+                        {
+                                new Case(new File("src/test/resources/test_not_existent.properties").toURI().toURL().toExternalForm())
+                                {
+                                    @Override
+                                    public void run()
+                                    {
+                                        assertFalse(result.hasMoreElements());
+                                    }
+                                }
                         });
     }
 
@@ -88,7 +100,7 @@ public class PropertyFileUtilsTest
     }
 
     @Test
-    public void run() throws IOException
+    public void run() throws IOException, URISyntaxException
     {
         test.result = PropertyFileUtils.resolvePropertyFiles(test.file);
         test.run();

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6befd123/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/EnvironmentPropertyConfigSourceProvider.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/EnvironmentPropertyConfigSourceProvider.java
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/EnvironmentPropertyConfigSourceProvider.java
index b5daeb4..64d9cdd 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/EnvironmentPropertyConfigSourceProvider.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/EnvironmentPropertyConfigSourceProvider.java
@@ -19,6 +19,7 @@
 package org.apache.deltaspike.core.impl.config;
 
 import java.io.IOException;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Enumeration;
@@ -54,6 +55,7 @@ class EnvironmentPropertyConfigSourceProvider implements ConfigSourceProvider
             while (propertyFileUrls.hasMoreElements())
             {
                 URL propertyFileUrl = propertyFileUrls.nextElement();
+
                 LOG.log(Level.INFO,
                         "Custom config found by DeltaSpike. Name: ''{0}'', URL: ''{1}''",
                         new Object[] {propertyFileName, propertyFileUrl});
@@ -64,6 +66,10 @@ class EnvironmentPropertyConfigSourceProvider implements ConfigSourceProvider
         {
             throw new IllegalStateException("problem while loading DeltaSpike property files",
ioe);
         }
+        catch (URISyntaxException ue)
+        {
+            throw new IllegalStateException("Property file URL is malformed", ue);
+        }
 
     }
 


Mime
View raw message