Skip to content

Commit

Permalink
Merge pull request #197 from societe-generale/addingLogStatementsForP…
Browse files Browse the repository at this point in the history
…ropertyFileLoading

adding log statements around archUnit property file
  • Loading branch information
codecholeric authored Jul 21, 2019
2 parents e06cab9 + b8d9594 commit 1d74f31
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions archunit/src/main/java/com/tngtech/archunit/ArchConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,6 +30,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;
Expand All @@ -47,6 +50,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<String, String> PROPERTY_DEFAULTS = ImmutableMap.of(
RESOLVE_MISSING_DEPENDENCIES_FROM_CLASS_PATH, Boolean.TRUE.toString(),
ENABLE_MD5_IN_CLASS_SOURCES, Boolean.FALSE.toString()
Expand Down Expand Up @@ -78,11 +83,18 @@ private ArchConfiguration(String propertiesResourceName) {

private void readProperties(String propertiesResourceName) {
properties.clear();
try (InputStream inputStream = getClass().getResourceAsStream(propertiesResourceName)) {
if (inputStream != null) {
properties.load(inputStream);
}
} catch (IOException 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);
}
}

Expand Down

0 comments on commit 1d74f31

Please sign in to comment.