mirror of https://github.com/apache/druid.git
Properties module can now take multiple properties files
This commit is contained in:
parent
f7c4d6a24a
commit
8340a1b0a1
|
@ -85,6 +85,7 @@ import java.net.URI;
|
|||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
@ -351,7 +352,7 @@ public class Initialization
|
|||
return Guice.createInjector(
|
||||
new DruidGuiceExtensions(),
|
||||
new JacksonModule(),
|
||||
new PropertiesModule("runtime.properties"),
|
||||
new PropertiesModule(Arrays.asList("global.runtime.properties", "runtime.properties")),
|
||||
new ConfigModule(),
|
||||
new Module()
|
||||
{
|
||||
|
|
|
@ -33,6 +33,7 @@ import java.io.FileNotFoundException;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
|
@ -41,11 +42,11 @@ public class PropertiesModule implements Module
|
|||
{
|
||||
private static final Logger log = new Logger(PropertiesModule.class);
|
||||
|
||||
private final String propertiesFile;
|
||||
private final List<String> propertiesFiles;
|
||||
|
||||
public PropertiesModule(String propertiesFile)
|
||||
public PropertiesModule(List<String> propertiesFiles)
|
||||
{
|
||||
this.propertiesFile = propertiesFile;
|
||||
this.propertiesFiles = propertiesFiles;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -57,30 +58,32 @@ public class PropertiesModule implements Module
|
|||
Properties props = new Properties(fileProps);
|
||||
props.putAll(systemProps);
|
||||
|
||||
InputStream stream = ClassLoader.getSystemResourceAsStream(propertiesFile);
|
||||
try {
|
||||
if (stream == null) {
|
||||
File workingDirectoryFile = new File(systemProps.getProperty("druid.properties.file", propertiesFile));
|
||||
if (workingDirectoryFile.exists()) {
|
||||
stream = new BufferedInputStream(new FileInputStream(workingDirectoryFile));
|
||||
for (String propertiesFile : propertiesFiles) {
|
||||
InputStream stream = ClassLoader.getSystemResourceAsStream(propertiesFile);
|
||||
try {
|
||||
if (stream == null) {
|
||||
File workingDirectoryFile = new File(systemProps.getProperty("druid.properties.file", propertiesFile));
|
||||
if (workingDirectoryFile.exists()) {
|
||||
stream = new BufferedInputStream(new FileInputStream(workingDirectoryFile));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (stream != null) {
|
||||
log.info("Loading properties from %s", propertiesFile);
|
||||
try {
|
||||
fileProps.load(new InputStreamReader(stream, Charsets.UTF_8));
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw Throwables.propagate(e);
|
||||
if (stream != null) {
|
||||
log.info("Loading properties from %s", propertiesFile);
|
||||
try {
|
||||
fileProps.load(new InputStreamReader(stream, Charsets.UTF_8));
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException e) {
|
||||
log.wtf(e, "This can only happen if the .exists() call lied. That's f'd up.");
|
||||
}
|
||||
finally {
|
||||
Closeables.closeQuietly(stream);
|
||||
catch (FileNotFoundException e) {
|
||||
log.wtf(e, "This can only happen if the .exists() call lied. That's f'd up.");
|
||||
}
|
||||
finally {
|
||||
Closeables.closeQuietly(stream);
|
||||
}
|
||||
}
|
||||
|
||||
binder.bind(Properties.class).toInstance(props);
|
||||
|
|
Loading…
Reference in New Issue