Skip to content

Commit 02d17ed

Browse files
committed
OWS-634: Allow deployment config to load a custom properties file
1 parent e8f02c4 commit 02d17ed

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

core/src/main/java/net/sourceforge/jnlp/config/DeploymentConfiguration.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,10 @@ static boolean checkUrl(final URL file) {
165165
*
166166
* @throws ConfigurationException if it encounters a fatal error.
167167
*/
168-
public void load() throws ConfigurationException {
168+
public void load(File... propFile) throws ConfigurationException {
169169
LOG.debug("Start DeploymentConfiguration.load()");
170170
try {
171-
load(true);
171+
load(true, propFile);
172172
} catch (final MalformedURLException ex) {
173173
throw new ConfigurationException(ex.toString());
174174
} finally {
@@ -184,10 +184,14 @@ public void load() throws ConfigurationException {
184184
* resorting to the default values
185185
* @throws ConfigurationException if it encounters a fatal error.
186186
*/
187-
public void load(final boolean fixIssues) throws ConfigurationException, MalformedURLException {
187+
public void load(final boolean fixIssues, File... propFile ) throws ConfigurationException, MalformedURLException {
188188
final SecurityManager sm = System.getSecurityManager();
189189
if (sm != null) {
190-
sm.checkRead(userDeploymentFileDescriptor.getFullPath());
190+
if (propFile.length > 0) {
191+
sm.checkRead(clean(propFile[0].getAbsolutePath()));
192+
} else {
193+
sm.checkRead(userDeploymentFileDescriptor.getFullPath());
194+
}
191195
}
192196

193197
final Map<String, Setting> properties = Defaults.getDefaults();
@@ -202,9 +206,9 @@ public void load(final boolean fixIssues) throws ConfigurationException, Malform
202206
}
203207

204208
/*
205-
* Third, read the user's subdirResult deployment.properties file
209+
* Third, read the user's subdirResult deployment.properties file or the custom config properties
206210
*/
207-
userPropertiesFile = userDeploymentFileDescriptor.getFile();
211+
userPropertiesFile = propFile.length > 0 ? propFile[0] : userDeploymentFileDescriptor.getFile();
208212
final URL userPropertiesUrl = userPropertiesFile.toURI().toURL();
209213
final Map<String, Setting> userProperties = loadProperties(ConfigType.USER, userPropertiesUrl, false);
210214
userComments = loadComments(userPropertiesUrl);
@@ -697,4 +701,11 @@ public static String VVPossibleBrowserValues() {
697701
ConfigurationConstants.KEY_BROWSER_PATH
698702
);
699703
}
704+
705+
private static String clean(String s) {
706+
while (s.contains(File.separator + File.separator)) {
707+
s = s.replace(File.separator + File.separator, File.separator);
708+
}
709+
return s;
710+
}
700711
}

core/src/main/java/net/sourceforge/jnlp/runtime/JNLPRuntime.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,13 @@ private static class DeploymentConfigurationHolder {
459459
static {
460460
DeploymentConfiguration config = new DeploymentConfiguration();
461461
try {
462-
config.load();
462+
final String owsUserPropertiesFilename = System.getProperty("owsUserPropertiesFilename");
463+
if (owsUserPropertiesFilename != null) {
464+
LOG.debug("Loading config from file {} ", owsUserPropertiesFilename);
465+
config.load(new File(owsUserPropertiesFilename));
466+
} else {
467+
config.load();
468+
}
463469
config.copyTo(System.getProperties());
464470
} catch (ConfigurationException ex) {
465471
LOG.info("Fatal error while reading the configuration, continuing with empty. Please fix");

0 commit comments

Comments
 (0)