|
|
|
@ -142,48 +142,64 @@ public class PropertiesLauncher extends Launcher { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected File getHomeDirectory() { |
|
|
|
protected File getHomeDirectory() { |
|
|
|
return new File(SystemPropertyUtils |
|
|
|
try { |
|
|
|
.resolvePlaceholders(System.getProperty(HOME, "${user.dir}"))); |
|
|
|
return new File(getPropertyWithDefault(HOME, "${user.dir}")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception ex) { |
|
|
|
|
|
|
|
throw new IllegalStateException(ex); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void initializeProperties() throws Exception, IOException { |
|
|
|
private void initializeProperties() throws Exception, IOException { |
|
|
|
String config = "classpath:BOOT-INF/classes/" |
|
|
|
List<String> configs = new ArrayList<String>(); |
|
|
|
+ SystemPropertyUtils.resolvePlaceholders( |
|
|
|
if (getProperty(CONFIG_LOCATION) != null) { |
|
|
|
SystemPropertyUtils.getProperty(CONFIG_NAME, "application")) |
|
|
|
configs.add(getProperty(CONFIG_LOCATION)); |
|
|
|
+ ".properties"; |
|
|
|
} |
|
|
|
config = SystemPropertyUtils.resolvePlaceholders( |
|
|
|
else { |
|
|
|
SystemPropertyUtils.getProperty(CONFIG_LOCATION, config)); |
|
|
|
String[] names = getPropertyWithDefault(CONFIG_NAME, "loader,application") |
|
|
|
InputStream resource = getResource(config); |
|
|
|
.split(","); |
|
|
|
if (resource != null) { |
|
|
|
for (String name : names) { |
|
|
|
log("Found: " + config); |
|
|
|
configs.add("file:" + getHomeDirectory() + "/" + name + ".properties"); |
|
|
|
try { |
|
|
|
configs.add("classpath:" + name + ".properties"); |
|
|
|
this.properties.load(resource); |
|
|
|
configs.add("classpath:BOOT-INF/classes/" + name + ".properties"); |
|
|
|
} |
|
|
|
|
|
|
|
finally { |
|
|
|
|
|
|
|
resource.close(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
for (Object key : Collections.list(this.properties.propertyNames())) { |
|
|
|
} |
|
|
|
String text = this.properties.getProperty((String) key); |
|
|
|
for (String config : configs) { |
|
|
|
String value = SystemPropertyUtils.resolvePlaceholders(this.properties, |
|
|
|
InputStream resource = getResource(config); |
|
|
|
text); |
|
|
|
if (resource != null) { |
|
|
|
if (value != null) { |
|
|
|
debug("Found: " + config); |
|
|
|
this.properties.put(key, value); |
|
|
|
try { |
|
|
|
|
|
|
|
this.properties.load(resource); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
finally { |
|
|
|
|
|
|
|
resource.close(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (SystemPropertyUtils |
|
|
|
|
|
|
|
.resolvePlaceholders("${" + SET_SYSTEM_PROPERTIES + ":false}") |
|
|
|
|
|
|
|
.equals("true")) { |
|
|
|
|
|
|
|
log("Adding resolved properties to System properties"); |
|
|
|
|
|
|
|
for (Object key : Collections.list(this.properties.propertyNames())) { |
|
|
|
for (Object key : Collections.list(this.properties.propertyNames())) { |
|
|
|
String value = this.properties.getProperty((String) key); |
|
|
|
if (config.endsWith("application.properties") |
|
|
|
System.setProperty((String) key, value); |
|
|
|
&& ((String) key).startsWith("loader.")) { |
|
|
|
|
|
|
|
warn("Use of application.properties for PropertiesLauncher is deprecated"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
String text = this.properties.getProperty((String) key); |
|
|
|
|
|
|
|
String value = SystemPropertyUtils |
|
|
|
|
|
|
|
.resolvePlaceholders(this.properties, text); |
|
|
|
|
|
|
|
if (value != null) { |
|
|
|
|
|
|
|
this.properties.put(key, value); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if ("true".equals(getProperty(SET_SYSTEM_PROPERTIES))) { |
|
|
|
|
|
|
|
debug("Adding resolved properties to System properties"); |
|
|
|
|
|
|
|
for (Object key : Collections.list(this.properties.propertyNames())) { |
|
|
|
|
|
|
|
String value = this.properties.getProperty((String) key); |
|
|
|
|
|
|
|
System.setProperty((String) key, value); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Load the first one we find
|
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
debug("Not found: " + config); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
|
|
|
|
log("Not found: " + config); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private InputStream getResource(String config) throws Exception { |
|
|
|
private InputStream getResource(String config) throws Exception { |
|
|
|
@ -216,13 +232,13 @@ public class PropertiesLauncher extends Launcher { |
|
|
|
config = config.substring(1); |
|
|
|
config = config.substring(1); |
|
|
|
} |
|
|
|
} |
|
|
|
config = "/" + config; |
|
|
|
config = "/" + config; |
|
|
|
log("Trying classpath: " + config); |
|
|
|
debug("Trying classpath: " + config); |
|
|
|
return getClass().getResourceAsStream(config); |
|
|
|
return getClass().getResourceAsStream(config); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private InputStream getFileResource(String config) throws Exception { |
|
|
|
private InputStream getFileResource(String config) throws Exception { |
|
|
|
File file = new File(config); |
|
|
|
File file = new File(config); |
|
|
|
log("Trying file: " + config); |
|
|
|
debug("Trying file: " + config); |
|
|
|
if (file.canRead()) { |
|
|
|
if (file.canRead()) { |
|
|
|
return new FileInputStream(file); |
|
|
|
return new FileInputStream(file); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -278,7 +294,7 @@ public class PropertiesLauncher extends Launcher { |
|
|
|
if (path != null) { |
|
|
|
if (path != null) { |
|
|
|
this.paths = parsePathsProperty(path); |
|
|
|
this.paths = parsePathsProperty(path); |
|
|
|
} |
|
|
|
} |
|
|
|
log("Nested archive paths: " + this.paths); |
|
|
|
debug("Nested archive paths: " + this.paths); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private List<String> parsePathsProperty(String commaSeparatedPaths) { |
|
|
|
private List<String> parsePathsProperty(String commaSeparatedPaths) { |
|
|
|
@ -326,7 +342,7 @@ public class PropertiesLauncher extends Launcher { |
|
|
|
String customLoaderClassName = getProperty("loader.classLoader"); |
|
|
|
String customLoaderClassName = getProperty("loader.classLoader"); |
|
|
|
if (customLoaderClassName != null) { |
|
|
|
if (customLoaderClassName != null) { |
|
|
|
loader = wrapWithCustomClassLoader(loader, customLoaderClassName); |
|
|
|
loader = wrapWithCustomClassLoader(loader, customLoaderClassName); |
|
|
|
log("Using custom class loader: " + customLoaderClassName); |
|
|
|
debug("Using custom class loader: " + customLoaderClassName); |
|
|
|
} |
|
|
|
} |
|
|
|
return loader; |
|
|
|
return loader; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -354,34 +370,50 @@ public class PropertiesLauncher extends Launcher { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String getProperty(String propertyKey) throws Exception { |
|
|
|
private String getProperty(String propertyKey) throws Exception { |
|
|
|
return getProperty(propertyKey, null); |
|
|
|
return getProperty(propertyKey, null, null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String getProperty(String propertyKey, String manifestKey) throws Exception { |
|
|
|
private String getProperty(String propertyKey, String manifestKey) throws Exception { |
|
|
|
|
|
|
|
return getProperty(propertyKey, manifestKey, null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String getPropertyWithDefault(String propertyKey, String defaultValue) |
|
|
|
|
|
|
|
throws Exception { |
|
|
|
|
|
|
|
return getProperty(propertyKey, null, defaultValue); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String getProperty(String propertyKey, String manifestKey, |
|
|
|
|
|
|
|
String defaultValue) throws Exception { |
|
|
|
if (manifestKey == null) { |
|
|
|
if (manifestKey == null) { |
|
|
|
manifestKey = propertyKey.replace('.', '-'); |
|
|
|
manifestKey = propertyKey.replace('.', '-'); |
|
|
|
manifestKey = toCamelCase(manifestKey); |
|
|
|
manifestKey = toCamelCase(manifestKey); |
|
|
|
} |
|
|
|
} |
|
|
|
String property = SystemPropertyUtils.getProperty(propertyKey); |
|
|
|
String property = SystemPropertyUtils.getProperty(propertyKey); |
|
|
|
if (property != null) { |
|
|
|
if (property != null) { |
|
|
|
String value = SystemPropertyUtils.resolvePlaceholders(property); |
|
|
|
String value = SystemPropertyUtils.resolvePlaceholders(this.properties, |
|
|
|
log("Property '" + propertyKey + "' from environment: " + value); |
|
|
|
property); |
|
|
|
|
|
|
|
debug("Property '" + propertyKey + "' from environment: " + value); |
|
|
|
return value; |
|
|
|
return value; |
|
|
|
} |
|
|
|
} |
|
|
|
if (this.properties.containsKey(propertyKey)) { |
|
|
|
if (this.properties.containsKey(propertyKey)) { |
|
|
|
String value = SystemPropertyUtils |
|
|
|
String value = SystemPropertyUtils.resolvePlaceholders(this.properties, |
|
|
|
.resolvePlaceholders(this.properties.getProperty(propertyKey)); |
|
|
|
this.properties.getProperty(propertyKey)); |
|
|
|
log("Property '" + propertyKey + "' from properties: " + value); |
|
|
|
debug("Property '" + propertyKey + "' from properties: " + value); |
|
|
|
return value; |
|
|
|
return value; |
|
|
|
} |
|
|
|
} |
|
|
|
try { |
|
|
|
try { |
|
|
|
// Prefer home dir for MANIFEST if there is one
|
|
|
|
if (this.home != null) { |
|
|
|
Manifest manifest = new ExplodedArchive(this.home, false).getManifest(); |
|
|
|
// Prefer home dir for MANIFEST if there is one
|
|
|
|
if (manifest != null) { |
|
|
|
Manifest manifest = new ExplodedArchive(this.home, false).getManifest(); |
|
|
|
String value = manifest.getMainAttributes().getValue(manifestKey); |
|
|
|
if (manifest != null) { |
|
|
|
log("Property '" + manifestKey + "' from home directory manifest: " |
|
|
|
String value = manifest.getMainAttributes().getValue(manifestKey); |
|
|
|
+ value); |
|
|
|
if (value != null) { |
|
|
|
return value; |
|
|
|
debug("Property '" + manifestKey |
|
|
|
|
|
|
|
+ "' from home directory manifest: " + value); |
|
|
|
|
|
|
|
return SystemPropertyUtils.resolvePlaceholders(this.properties, |
|
|
|
|
|
|
|
value); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
catch (IllegalStateException ex) { |
|
|
|
catch (IllegalStateException ex) { |
|
|
|
@ -392,11 +424,12 @@ public class PropertiesLauncher extends Launcher { |
|
|
|
if (manifest != null) { |
|
|
|
if (manifest != null) { |
|
|
|
String value = manifest.getMainAttributes().getValue(manifestKey); |
|
|
|
String value = manifest.getMainAttributes().getValue(manifestKey); |
|
|
|
if (value != null) { |
|
|
|
if (value != null) { |
|
|
|
log("Property '" + manifestKey + "' from archive manifest: " + value); |
|
|
|
debug("Property '" + manifestKey + "' from archive manifest: " + value); |
|
|
|
return value; |
|
|
|
return SystemPropertyUtils.resolvePlaceholders(this.properties, value); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return null; |
|
|
|
return defaultValue == null ? defaultValue |
|
|
|
|
|
|
|
: SystemPropertyUtils.resolvePlaceholders(this.properties, defaultValue); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@ -427,18 +460,18 @@ public class PropertiesLauncher extends Launcher { |
|
|
|
file = new File(this.home, root); |
|
|
|
file = new File(this.home, root); |
|
|
|
} |
|
|
|
} |
|
|
|
if (file.isDirectory()) { |
|
|
|
if (file.isDirectory()) { |
|
|
|
log("Adding classpath entries from " + file); |
|
|
|
debug("Adding classpath entries from " + file); |
|
|
|
Archive archive = new ExplodedArchive(file, false); |
|
|
|
Archive archive = new ExplodedArchive(file, false); |
|
|
|
lib.add(archive); |
|
|
|
lib.add(archive); |
|
|
|
} |
|
|
|
} |
|
|
|
Archive archive = getArchive(file); |
|
|
|
Archive archive = getArchive(file); |
|
|
|
if (archive != null) { |
|
|
|
if (archive != null) { |
|
|
|
log("Adding classpath entries from archive " + archive.getUrl() + root); |
|
|
|
debug("Adding classpath entries from archive " + archive.getUrl() + root); |
|
|
|
lib.add(archive); |
|
|
|
lib.add(archive); |
|
|
|
} |
|
|
|
} |
|
|
|
Archive nested = getNestedArchive(root); |
|
|
|
Archive nested = getNestedArchive(root); |
|
|
|
if (nested != null) { |
|
|
|
if (nested != null) { |
|
|
|
log("Adding classpath entries from nested " + nested.getUrl() + root); |
|
|
|
debug("Adding classpath entries from nested " + root); |
|
|
|
lib.add(nested); |
|
|
|
lib.add(nested); |
|
|
|
} |
|
|
|
} |
|
|
|
return lib; |
|
|
|
return lib; |
|
|
|
@ -540,14 +573,21 @@ public class PropertiesLauncher extends Launcher { |
|
|
|
return Character.toUpperCase(str.charAt(0)) + str.substring(1); |
|
|
|
return Character.toUpperCase(str.charAt(0)) + str.substring(1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void log(String message) { |
|
|
|
private void debug(String message) { |
|
|
|
if (Boolean.getBoolean(DEBUG)) { |
|
|
|
if (Boolean.getBoolean(DEBUG)) { |
|
|
|
// We shouldn't use java.util.logging because of classpath issues so we
|
|
|
|
log(message); |
|
|
|
// just sysout log messages when "loader.debug" is true
|
|
|
|
|
|
|
|
System.out.println(message); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void warn(String message) { |
|
|
|
|
|
|
|
log("WARNING: " + message); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void log(String message) { |
|
|
|
|
|
|
|
// We shouldn't use java.util.logging because of classpath issues
|
|
|
|
|
|
|
|
System.out.println(message); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Convenience class for finding nested archives that have a prefix in their file path |
|
|
|
* Convenience class for finding nested archives that have a prefix in their file path |
|
|
|
* (e.g. "lib/"). |
|
|
|
* (e.g. "lib/"). |
|
|
|
|