Repository: deltaspike Updated Branches: refs/heads/master 6befd1231 -> c7b5471c2 (forced update)
DELTASPIKE-1278: Added an additonal check to ensure local resources do exist to respect optional flag. This closes #74 Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/c7b5471c Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/c7b5471c Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/c7b5471c Branch: refs/heads/master Commit: c7b5471c2912b68775ae887ab99d3e6cac57a053 Parents: 7594ba6 Author: Dennis Rippinger <dennis.rippin...@gmail.com> Authored: Sun Jul 2 14:43:31 2017 +0200 Committer: John D. Ament <johndam...@apache.org> Committed: Sat Aug 12 18:26:53 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/c7b5471c/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/c7b5471c/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/c7b5471c/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); + } }