Skip to content

Commit 3621f33

Browse files
committed
Conditionally set a) System properties from property resources specified in the Jnlp file. b) http.agent
1 parent 7a8acf1 commit 3621f33

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

core/src/main/java/net/adoptopenjdk/icedteaweb/jvm/JvmUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.ArrayList;
88
import java.util.HashMap;
99
import java.util.HashSet;
10+
import java.util.LinkedHashMap;
1011
import java.util.LinkedHashSet;
1112
import java.util.List;
1213
import java.util.Map;
@@ -374,7 +375,7 @@ public static String[] getValidStartingJavaModuleVMArguments() {
374375
* Defined in itw-modularjdk.args. Required for running ITW with jdk 9 or higher
375376
*/
376377
static Map<String, Set<String>> getPredefinedJavaModulesVMArgumentsMap() {
377-
return new HashMap<String, Set<String>>() {{
378+
return new LinkedHashMap<String, Set<String>>() {{
378379
put("--add-reads=java.base", moduleArgs("ALL-UNNAMED", "java.desktop"));
379380
put("--add-reads=java.desktop", moduleArgs("ALL-UNNAMED", "java.naming"));
380381
put("--add-reads=java.naming", moduleArgs("ALL-UNNAMED", "java.desktop"));

core/src/main/java/net/sourceforge/jnlp/JNLPFile.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import net.adoptopenjdk.icedteaweb.xmlparser.XMLParser;
4444
import net.adoptopenjdk.icedteaweb.xmlparser.XmlNode;
4545
import net.adoptopenjdk.icedteaweb.xmlparser.XmlParserFactory;
46+
import net.sourceforge.jnlp.runtime.ApplicationInstance;
4647
import net.sourceforge.jnlp.runtime.JNLPRuntime;
4748
import net.sourceforge.jnlp.util.UrlUtils;
4849
import sun.net.www.protocol.http.HttpURLConnection;
@@ -259,7 +260,8 @@ protected JNLPFile() {
259260
parse(input, location, null);
260261

261262
final String httpAgent = getResources().getPropertiesMap().get(HTTP_AGENT);
262-
if (! StringUtils.isBlank(httpAgent)) {
263+
// Do not set http.agent in stage 2 as it can be set from the vmarg to the jvm
264+
if (! StringUtils.isBlank(httpAgent) && !"true".equalsIgnoreCase(System.getenv(ApplicationInstance.IGNORE_JNLP_RESOURCE_PROPERTIES))) {
263265
System.setProperty(HTTP_AGENT, httpAgent);
264266
if (!HttpURLConnection.userAgent.contains(httpAgent)) {
265267
LOG.warn("Cannot set HTTP User-Agent as a connection has been opened before reading the JNLP file");

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class ApplicationInstance {
5353

5454
private static final String DEPLOYMENT_SYSPROP = "deployment.javaws";
5555
private static final String DEPLOYMENT_SYSPROP_VALUE = "IcedTea-Web";
56+
public static final String IGNORE_JNLP_RESOURCE_PROPERTIES = "ignoreJnlpResourceProperties";
5657

5758
// todo: should attempt to unload the environment variables
5859
// installed by the application.
@@ -134,6 +135,17 @@ public void finalize() {
134135
* Install the environment variables.
135136
*/
136137
private void installEnvironment() {
138+
setSystemPropertiesFromJnlp();
139+
140+
// The "deployment.javaws" flag is always set to "IcedTea-Web" to make it possible
141+
// for the started application to detect the execution context.
142+
System.setProperty(DEPLOYMENT_SYSPROP, DEPLOYMENT_SYSPROP_VALUE);
143+
}
144+
145+
private void setSystemPropertiesFromJnlp() {
146+
if ("true".equalsIgnoreCase(System.getenv(IGNORE_JNLP_RESOURCE_PROPERTIES))) {
147+
return;
148+
}
137149
final List<PropertyDesc> props = collectPropertiesFromJnlpHierarchy(new ArrayList<>(), file);
138150

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

147159
final PrivilegedAction<Object> setPropertiesAction = () -> {
148160
for (PropertyDesc propDesc : props) {
149-
LOG.debug("Setting Property {}", propDesc.getKey());
161+
LOG.debug("Setting System Property {} with value {}", propDesc.getKey(), propDesc.getValue());
150162
System.setProperty(propDesc.getKey(), propDesc.getValue());
151163
}
152164
return null;
153165
};
154166

155-
LOG.info("about to set system properties");
167+
LOG.info("About to set system properties");
156168
AccessController.doPrivileged(setPropertiesAction, acc);
157169
}
158-
159-
// The "deployment.javaws" flag is always set to "IcedTea-Web" to make it possible
160-
// for the started application to detect the execution context.
161-
System.setProperty(DEPLOYMENT_SYSPROP, DEPLOYMENT_SYSPROP_VALUE);
162170
}
163171

164172
/**
@@ -305,5 +313,4 @@ private List<PropertyDesc> collectPropertiesFromJnlpHierarchy(List<PropertyDesc>
305313
}
306314
return props;
307315
}
308-
309316
}

0 commit comments

Comments
 (0)