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

Conditionally set a) System properties from property resources specif… #941

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
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 @@ -7,6 +7,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -374,7 +375,7 @@ public static String[] getValidStartingJavaModuleVMArguments() {
* Defined in itw-modularjdk.args. Required for running ITW with jdk 9 or higher
*/
static Map<String, Set<String>> getPredefinedJavaModulesVMArgumentsMap() {
return new HashMap<String, Set<String>>() {{
return new LinkedHashMap<String, Set<String>>() {{
put("--add-reads=java.base", moduleArgs("ALL-UNNAMED", "java.desktop"));
put("--add-reads=java.desktop", moduleArgs("ALL-UNNAMED", "java.naming"));
put("--add-reads=java.naming", moduleArgs("ALL-UNNAMED", "java.desktop"));
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/java/net/sourceforge/jnlp/JNLPFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import net.adoptopenjdk.icedteaweb.xmlparser.XMLParser;
import net.adoptopenjdk.icedteaweb.xmlparser.XmlNode;
import net.adoptopenjdk.icedteaweb.xmlparser.XmlParserFactory;
import net.sourceforge.jnlp.runtime.ApplicationInstance;
import net.sourceforge.jnlp.runtime.JNLPRuntime;
import net.sourceforge.jnlp.util.UrlUtils;
import sun.net.www.protocol.http.HttpURLConnection;
Expand Down Expand Up @@ -259,7 +260,8 @@ protected JNLPFile() {
parse(input, location, null);

final String httpAgent = getResources().getPropertiesMap().get(HTTP_AGENT);
if (! StringUtils.isBlank(httpAgent)) {
// Do not set http.agent in stage 2 as it can be set from the vmarg to the jvm
if (! StringUtils.isBlank(httpAgent) && !"true".equalsIgnoreCase(System.getenv(ApplicationInstance.IGNORE_JNLP_RESOURCE_PROPERTIES))) {
System.setProperty(HTTP_AGENT, httpAgent);
if (!HttpURLConnection.userAgent.contains(httpAgent)) {
LOG.warn("Cannot set HTTP User-Agent as a connection has been opened before reading the JNLP file");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class ApplicationInstance {

private static final String DEPLOYMENT_SYSPROP = "deployment.javaws";
private static final String DEPLOYMENT_SYSPROP_VALUE = "IcedTea-Web";
public static final String IGNORE_JNLP_RESOURCE_PROPERTIES = "ignoreJnlpResourceProperties";

// todo: should attempt to unload the environment variables
// installed by the application.
Expand Down Expand Up @@ -134,6 +135,17 @@ public void finalize() {
* Install the environment variables.
*/
private void installEnvironment() {
setSystemPropertiesFromJnlp();

// The "deployment.javaws" flag is always set to "IcedTea-Web" to make it possible
// for the started application to detect the execution context.
System.setProperty(DEPLOYMENT_SYSPROP, DEPLOYMENT_SYSPROP_VALUE);
}

private void setSystemPropertiesFromJnlp() {
if ("true".equalsIgnoreCase(System.getenv(IGNORE_JNLP_RESOURCE_PROPERTIES))) {
return;
}
final List<PropertyDesc> props = collectPropertiesFromJnlpHierarchy(new ArrayList<>(), file);

if (!(props.size() == 0)) {
Expand All @@ -146,19 +158,15 @@ private void installEnvironment() {

final PrivilegedAction<Object> setPropertiesAction = () -> {
for (PropertyDesc propDesc : props) {
LOG.debug("Setting Property {}", propDesc.getKey());
LOG.debug("Setting System Property {} with value {}", propDesc.getKey(), propDesc.getValue());
System.setProperty(propDesc.getKey(), propDesc.getValue());
}
return null;
};

LOG.info("about to set system properties");
LOG.info("About to set system properties");
AccessController.doPrivileged(setPropertiesAction, acc);
}

// The "deployment.javaws" flag is always set to "IcedTea-Web" to make it possible
// for the started application to detect the execution context.
System.setProperty(DEPLOYMENT_SYSPROP, DEPLOYMENT_SYSPROP_VALUE);
}

/**
Expand Down Expand Up @@ -305,5 +313,4 @@ private List<PropertyDesc> collectPropertiesFromJnlpHierarchy(List<PropertyDesc>
}
return props;
}

}
Loading