Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding log statements around archUnit property file #197

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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