From 9efa161dbe144a98f0838ae8a827e288c055dbc3 Mon Sep 17 00:00:00 2001 From: Vincent FUCHS Date: Sun, 21 Jul 2019 15:02:56 +0200 Subject: [PATCH 1/3] adding log statements to indicate whether archUnit property file is found or not Signed-off-by: Vincent FUCHS --- .../main/java/com/tngtech/archunit/ArchConfiguration.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/archunit/src/main/java/com/tngtech/archunit/ArchConfiguration.java b/archunit/src/main/java/com/tngtech/archunit/ArchConfiguration.java index 9b13f145c7..c6a7ac0fee 100644 --- a/archunit/src/main/java/com/tngtech/archunit/ArchConfiguration.java +++ b/archunit/src/main/java/com/tngtech/archunit/ArchConfiguration.java @@ -29,6 +29,8 @@ import com.google.common.collect.ImmutableMap; import com.tngtech.archunit.base.Optional; import com.tngtech.archunit.core.importer.resolvers.ClassResolver; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import static com.google.common.base.Preconditions.checkNotNull; import static com.tngtech.archunit.PublicAPI.Usage.ACCESS; @@ -47,6 +49,8 @@ public final class ArchConfiguration { public static final String ENABLE_MD5_IN_CLASS_SOURCES = "enableMd5InClassSources"; private static final String EXTENSION_PREFIX = "extension"; + private static final Logger LOG = LoggerFactory.getLogger(ArchConfiguration.class); + private static final Map PROPERTY_DEFAULTS = ImmutableMap.of( RESOLVE_MISSING_DEPENDENCIES_FROM_CLASS_PATH, Boolean.TRUE.toString(), ENABLE_MD5_IN_CLASS_SOURCES, Boolean.FALSE.toString() @@ -80,7 +84,10 @@ 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) { } From 5c15712cf2e952a56377bda95e87513605099bab Mon Sep 17 00:00:00 2001 From: Vincent FUCHS Date: Sun, 21 Jul 2019 15:11:31 +0200 Subject: [PATCH 2/3] adding a warn log statements to avoid failing silently in case of IOException while reading properties file Signed-off-by: Vincent FUCHS --- .../src/main/java/com/tngtech/archunit/ArchConfiguration.java | 1 + 1 file changed, 1 insertion(+) diff --git a/archunit/src/main/java/com/tngtech/archunit/ArchConfiguration.java b/archunit/src/main/java/com/tngtech/archunit/ArchConfiguration.java index c6a7ac0fee..a4b9f5328f 100644 --- a/archunit/src/main/java/com/tngtech/archunit/ArchConfiguration.java +++ b/archunit/src/main/java/com/tngtech/archunit/ArchConfiguration.java @@ -90,6 +90,7 @@ private void readProperties(String propertiesResourceName) { 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); } } From b8d95940fd789f5acc954bd5c590fa0edad62a4b Mon Sep 17 00:00:00 2001 From: Peter Gafert Date: Sun, 21 Jul 2019 18:28:46 +0200 Subject: [PATCH 3/3] 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); } }