Skip to content

Commit

Permalink
Merge pull request #941 from AdoptOpenJDK/jnlp-specific-vmargs
Browse files Browse the repository at this point in the history
Conditionally set a) System properties from property resources specif…
  • Loading branch information
sclassen authored Apr 30, 2024
2 parents 7a8acf1 + 3621f33 commit 952462f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
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;
}

}

0 comments on commit 952462f

Please sign in to comment.