Skip to content

Commit 7707c38

Browse files
authored
Merge pull request #959 from AdoptOpenJDK/local-deployment-properties
Local deployment properties
2 parents b3ffe05 + cfde1db commit 7707c38

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

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

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package net.sourceforge.jnlp.config;
1818

19+
import net.adoptopenjdk.icedteaweb.JavaSystemProperties;
1920
import net.adoptopenjdk.icedteaweb.config.validators.ValueValidator;
2021
import net.adoptopenjdk.icedteaweb.http.CloseableConnection;
2122
import net.adoptopenjdk.icedteaweb.http.ConnectionFactory;
@@ -35,11 +36,9 @@
3536
import java.io.InputStreamReader;
3637
import java.io.OutputStream;
3738
import java.io.PrintStream;
38-
import java.io.Reader;
3939
import java.net.ConnectException;
4040
import java.net.MalformedURLException;
4141
import java.net.URL;
42-
import java.net.URLConnection;
4342
import java.nio.charset.StandardCharsets;
4443
import java.text.SimpleDateFormat;
4544
import java.util.Date;
@@ -65,7 +64,9 @@ public final class DeploymentConfiguration {
6564

6665
private static final Logger LOG = LoggerFactory.getLogger(DeploymentConfiguration.class);
6766
public static final String LOCKED_POSTFIX = ".locked";
67+
public static final String LOCAL_DEPLOYMENT_PROPERTIES_FILE_PATH = "localDeploymentPropertiesFilePath";
6868

69+
public static final String USER_HOME_DIR_TOKEN = "#USER_HOME_DIR#";
6970
private String userComments;
7071

7172
private ConfigurationException loadingException = null;
@@ -185,9 +186,14 @@ public void load() throws ConfigurationException {
185186
* @throws ConfigurationException if it encounters a fatal error.
186187
*/
187188
public void load(final boolean fixIssues) throws ConfigurationException, MalformedURLException {
189+
final String localDeploymentPropertiesFilePath = System.getProperty(LOCAL_DEPLOYMENT_PROPERTIES_FILE_PATH);
188190
final SecurityManager sm = System.getSecurityManager();
189191
if (sm != null) {
190-
sm.checkRead(userDeploymentFileDescriptor.getFullPath());
192+
if (localDeploymentPropertiesFilePath != null) {
193+
sm.checkRead(localDeploymentPropertiesFilePath);
194+
} else {
195+
sm.checkRead(userDeploymentFileDescriptor.getFullPath());
196+
}
191197
}
192198

193199
final Map<String, Setting> properties = Defaults.getDefaults();
@@ -202,14 +208,16 @@ public void load(final boolean fixIssues) throws ConfigurationException, Malform
202208
}
203209

204210
/*
205-
* Third, read the user's subdirResult deployment.properties file
211+
* Third, read the user's subdirResult deployment.properties file or the custom config properties
206212
*/
207-
userPropertiesFile = userDeploymentFileDescriptor.getFile();
213+
userPropertiesFile = localDeploymentPropertiesFilePath != null ? new File(localDeploymentPropertiesFilePath) : userDeploymentFileDescriptor.getFile();
208214
final URL userPropertiesUrl = userPropertiesFile.toURI().toURL();
209215
final Map<String, Setting> userProperties = loadProperties(ConfigType.USER, userPropertiesUrl, false);
210216
userComments = loadComments(userPropertiesUrl);
211217
mergeMaps(properties, userProperties);
212218

219+
processPropertiesWithHomeDirToken(properties);
220+
213221
if (fixIssues) {
214222
checkAndFixConfiguration(properties);
215223
}
@@ -363,14 +371,27 @@ private void checkAndFixConfiguration(final Map<String, Setting> initial) {
363371
try {
364372
checker.validate(setting.getValue());
365373
} catch (final IllegalArgumentException e) {
366-
LOG.error("Property '{}' has incorrect value \"{}\". Possible values {}.", key, setting.getValue(), checker.getPossibleValues(), e);
374+
LOG.error("Property '{}' has incorrect value \"{}\". Possible values {}. Setting default {}", key, setting.getValue(), checker.getPossibleValues(), setting.getDefaultValue(), e);
367375
setting.setValue(setting.getDefaultValue());
368376
}
369377
}
370378
}
371379
}
372380
}
373381

382+
private void processPropertiesWithHomeDirToken(final Map<String, Setting> properties) {
383+
for (final Map.Entry<String, Setting> entry : properties.entrySet()) {
384+
final String key = entry.getKey();
385+
final Setting setting = entry.getValue();
386+
final String propertyValue = setting.getValue();
387+
if (propertyValue != null && propertyValue.contains(USER_HOME_DIR_TOKEN)) {
388+
final String newValue = propertyValue.replace(USER_HOME_DIR_TOKEN, JavaSystemProperties.getUserHome());
389+
setting.setValue(newValue);
390+
LOG.debug("Replaced USER_HOME_DIR_TOKEN in key {} value {} default {}", key, setting.getValue(), setting.getDefaultValue());
391+
}
392+
}
393+
}
394+
374395
/**
375396
* Looks in the following locations:
376397
* <pre>

0 commit comments

Comments
 (0)