Permalink
Browse files

custom config supported

guava removed
  • Loading branch information...
hendrikebbers committed Feb 18, 2018
1 parent 1d80607 commit f12b6e9f6add6293a6c6d70c3b407d80f0671b36
@@ -35,7 +35,6 @@ jmockitVersion=1.38
#Dependencies for samples
javaxInjectVersion=1
guavaVersion=23.2-jre
jacocoVersion=0.7.9
rxjavaVersion=1.3.2
javaeeApiVersion=6.0
@@ -32,15 +32,17 @@
private static final Logger LOG = LoggerFactory.getLogger(ConfigurationFileLoader.class);
private static final String PLATFORM_LOCATION = "platform.properties";
private static final String DEFAULT_LOCATION = "dolphin.properties";
private static final String JAR_LOCATION = "META-INF/dolphin.properties";
private ConfigurationFileLoader() {
}
public static DefaultClientConfiguration loadConfiguration() {
final DefaultClientConfiguration configuration = createConfiguration();
public static DefaultClientConfiguration loadConfiguration(final String... additionalLocations) {
final DefaultClientConfiguration configuration = createConfiguration(additionalLocations);
Assert.requireNonNull(configuration, "configuration");
LOG.debug("Configuration created with {} properties", configuration.getPropertyKeys().size());
@@ -49,28 +51,55 @@ public static DefaultClientConfiguration loadConfiguration() {
LOG.debug("Dolphin Platform configured with '{}'='{}'", key, configuration.getProperty(key, null));
}
}
return configuration;
}
private static DefaultClientConfiguration createConfiguration() {
private static DefaultClientConfiguration createConfiguration(final String... additionalLocations) {
try {
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if(additionalLocations != null) {
for(String location : additionalLocations) {
LOG.trace("Trying to load configuration at '" + location + "'");
try (final InputStream inputStream = classLoader.getResourceAsStream(location)) {
if (inputStream != null) {
return readConfig(inputStream);
}
} catch (Exception e) {
LOG.trace("No config found at '" + location + "'");
}
}
}
try (final InputStream inputStream = classLoader.getResourceAsStream(PLATFORM_LOCATION)) {
LOG.trace("Trying to load configuration at '" + PLATFORM_LOCATION + "'");
if (inputStream != null) {
return readConfig(inputStream);
}
} catch (Exception e) {
LOG.trace("No config found at '" + PLATFORM_LOCATION + "'");
}
try (final InputStream inputStream = classLoader.getResourceAsStream(DEFAULT_LOCATION)) {
LOG.trace("Trying to load configuration at '" + DEFAULT_LOCATION + "'");
if (inputStream != null) {
return readConfig(inputStream);
}
} catch (Exception e) {
LOG.trace("No config found at '" + DEFAULT_LOCATION + "'");
}
try (final InputStream inputStream = classLoader.getResourceAsStream(JAR_LOCATION)) {
LOG.trace("Trying to load configuration at '" + JAR_LOCATION + "'");
if (inputStream != null) {
return readConfig(inputStream);
}
} catch (Exception e) {
LOG.trace("No config found at '" + JAR_LOCATION + "'");
}
return new DefaultClientConfiguration();
} catch (IOException e) {
} catch (Exception e) {
throw new RuntimeException("Can not create configuration!", e);
}
}
@@ -35,6 +35,8 @@
@API(since = "0.19.0", status = EXPERIMENTAL)
public class PlatformClient {
private static final String DEFAULT_LOCATION = "application.properties";
private static PlatformClient INSTANCE;
private final Map<Class<?>, ServiceProvider> providers = new ConcurrentHashMap<>();
@@ -47,7 +49,7 @@
private PlatformClient() {
PlatformLogo.printLogo();
this.clientConfiguration = ConfigurationFileLoader.loadConfiguration();
this.clientConfiguration = ConfigurationFileLoader.loadConfiguration(DEFAULT_LOCATION);
final ServiceLoader<ServiceProvider> loader = ServiceLoader.load(ServiceProvider.class);
final Iterator<ServiceProvider> iterator = loader.iterator();
@@ -16,7 +16,6 @@
dependencies {
compile "org.slf4j:slf4j-api:$slf4jVersion"
compile "com.google.guava:guava:$guavaVersion"
compile "org.apiguardian:apiguardian-api:$apiguardianVersion"
}

0 comments on commit f12b6e9

Please sign in to comment.