Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local deployment properties #959

Merged
merged 5 commits into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package net.sourceforge.jnlp.config;

import net.adoptopenjdk.icedteaweb.JavaSystemProperties;
import net.adoptopenjdk.icedteaweb.config.validators.ValueValidator;
import net.adoptopenjdk.icedteaweb.http.CloseableConnection;
import net.adoptopenjdk.icedteaweb.http.ConnectionFactory;
Expand All @@ -35,11 +36,9 @@
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.Reader;
import java.net.ConnectException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Date;
Expand All @@ -65,7 +64,9 @@ public final class DeploymentConfiguration {

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

public static final String USER_HOME_DIR_TOKEN = "#USER_HOME_DIR#";
private String userComments;

private ConfigurationException loadingException = null;
Expand Down Expand Up @@ -185,9 +186,14 @@ public void load() throws ConfigurationException {
* @throws ConfigurationException if it encounters a fatal error.
*/
public void load(final boolean fixIssues) throws ConfigurationException, MalformedURLException {
final String localDeploymentPropertiesFilePath = System.getProperty(LOCAL_DEPLOYMENT_PROPERTIES_FILE_PATH);
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkRead(userDeploymentFileDescriptor.getFullPath());
if (localDeploymentPropertiesFilePath != null) {
sm.checkRead(localDeploymentPropertiesFilePath);
} else {
sm.checkRead(userDeploymentFileDescriptor.getFullPath());
}
}

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

/*
* Third, read the user's subdirResult deployment.properties file
* Third, read the user's subdirResult deployment.properties file or the custom config properties
*/
userPropertiesFile = userDeploymentFileDescriptor.getFile();
userPropertiesFile = localDeploymentPropertiesFilePath != null ? new File(localDeploymentPropertiesFilePath) : userDeploymentFileDescriptor.getFile();
final URL userPropertiesUrl = userPropertiesFile.toURI().toURL();
final Map<String, Setting> userProperties = loadProperties(ConfigType.USER, userPropertiesUrl, false);
userComments = loadComments(userPropertiesUrl);
mergeMaps(properties, userProperties);

processPropertiesWithHomeDirToken(properties);

if (fixIssues) {
checkAndFixConfiguration(properties);
}
Expand Down Expand Up @@ -363,14 +371,27 @@ private void checkAndFixConfiguration(final Map<String, Setting> initial) {
try {
checker.validate(setting.getValue());
} catch (final IllegalArgumentException e) {
LOG.error("Property '{}' has incorrect value \"{}\". Possible values {}.", key, setting.getValue(), checker.getPossibleValues(), e);
LOG.error("Property '{}' has incorrect value \"{}\". Possible values {}. Setting default {}", key, setting.getValue(), checker.getPossibleValues(), setting.getDefaultValue(), e);
setting.setValue(setting.getDefaultValue());
}
}
}
}
}

private void processPropertiesWithHomeDirToken(final Map<String, Setting> properties) {
for (final Map.Entry<String, Setting> entry : properties.entrySet()) {
final String key = entry.getKey();
final Setting setting = entry.getValue();
final String propertyValue = setting.getValue();
if (propertyValue != null && propertyValue.contains(USER_HOME_DIR_TOKEN)) {
final String newValue = propertyValue.replace(USER_HOME_DIR_TOKEN, JavaSystemProperties.getUserHome());
setting.setValue(newValue);
LOG.debug("Replaced USER_HOME_DIR_TOKEN in key {} value {} default {}", key, setting.getValue(), setting.getDefaultValue());
}
}
}

/**
* Looks in the following locations:
* <pre>
Expand Down
Loading