From b8d95940fd789f5acc954bd5c590fa0edad62a4b Mon Sep 17 00:00:00 2001 From: Peter Gafert Date: Sun, 21 Jul 2019 18:28:46 +0200 Subject: [PATCH] Review: Might be useful to see the concrete URL that /archunit.properties has resolved to in the logging statement Signed-off-by: Peter Gafert --- .../tngtech/archunit/ArchConfiguration.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/archunit/src/main/java/com/tngtech/archunit/ArchConfiguration.java b/archunit/src/main/java/com/tngtech/archunit/ArchConfiguration.java index a4b9f5328f..deb1d1d965 100644 --- a/archunit/src/main/java/com/tngtech/archunit/ArchConfiguration.java +++ b/archunit/src/main/java/com/tngtech/archunit/ArchConfiguration.java @@ -17,6 +17,7 @@ import java.io.IOException; import java.io.InputStream; +import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -82,15 +83,18 @@ private ArchConfiguration(String propertiesResourceName) { private void readProperties(String propertiesResourceName) { properties.clear(); - try (InputStream inputStream = getClass().getResourceAsStream(propertiesResourceName)) { - if (inputStream != null) { - LOG.info("reading ArchUnit properties from " + propertiesResourceName); - properties.load(inputStream); - } else { - LOG.debug("no ArchUnit properties file found, therefore going with default behavior"); - } - } catch (IOException ignore) { - LOG.warn("problem while accessing/reading ArchUnit properties file " + propertiesResourceName,ignore); + + URL archUnitPropertiesUrl = getClass().getResource(propertiesResourceName); + if (archUnitPropertiesUrl == null) { + LOG.debug("No configuration found in classpath at {} => Using default configuration", propertiesResourceName); + return; + } + + try (InputStream inputStream = archUnitPropertiesUrl.openStream()) { + LOG.info("Reading ArchUnit properties from {}", archUnitPropertiesUrl); + properties.load(inputStream); + } catch (IOException e) { + LOG.warn("Error reading ArchUnit properties from " + archUnitPropertiesUrl, e); } }