1616
1717package net .sourceforge .jnlp .runtime ;
1818
19+ import net .adoptopenjdk .icedteaweb .jnlp .element .resource .ExtensionDesc ;
1920import net .adoptopenjdk .icedteaweb .jnlp .element .resource .PropertyDesc ;
2021import net .adoptopenjdk .icedteaweb .jnlp .element .security .SecurityDesc ;
2122import net .adoptopenjdk .icedteaweb .logging .Logger ;
2223import net .adoptopenjdk .icedteaweb .logging .LoggerFactory ;
24+ import net .adoptopenjdk .icedteaweb .xmlparser .ParseException ;
2325import net .sourceforge .jnlp .JNLPFile ;
2426import net .sourceforge .jnlp .config .DeploymentConfiguration ;
2527import net .sourceforge .jnlp .runtime .classloader .JNLPClassLoader ;
3436import java .security .CodeSource ;
3537import java .security .PrivilegedAction ;
3638import java .security .ProtectionDomain ;
37-
39+ import java .util .ArrayList ;
40+ import java .util .Arrays ;
41+ import java .util .List ;
3842/**
3943 * Represents a running instance of an application described in a
4044 * JNLPFile. This class provides a way to track the application's
@@ -130,9 +134,9 @@ public void finalize() {
130134 * Install the environment variables.
131135 */
132136 private void installEnvironment () {
133- final PropertyDesc [] props = file . getResources (). getProperties ( );
137+ final List < PropertyDesc > props = collectPropertiesFromJnlpHierarchy ( new ArrayList <>(), file );
134138
135- if (!(props .length == 0 )) {
139+ if (!(props .size () == 0 )) {
136140 final CodeSource cs = new CodeSource (null , (java .security .cert .Certificate []) null );
137141
138142 final JNLPClassLoader loader = this .loader ;
@@ -142,6 +146,7 @@ private void installEnvironment() {
142146
143147 final PrivilegedAction <Object > setPropertiesAction = () -> {
144148 for (PropertyDesc propDesc : props ) {
149+ LOG .debug ("Setting Property {}" , propDesc .getKey ());
145150 System .setProperty (propDesc .getKey (), propDesc .getValue ());
146151 }
147152 return null ;
@@ -276,4 +281,29 @@ public boolean isSigned() {
276281 return isSigned ;
277282 }
278283
284+ /**
285+ * Collects properties from the full hierarchy of JNLP files
286+ *
287+ * @param props a list of all properties collected so far
288+ * @param jnlpFile the current tip of the jnlp hierarchy
289+ * @return a list of properties collected from the full hierarchy of JNLP files
290+ */
291+ private List <PropertyDesc > collectPropertiesFromJnlpHierarchy (List <PropertyDesc > props , JNLPFile jnlpFile ) {
292+ // Collect properties from the current jnlp file
293+ props .addAll (Arrays .asList (jnlpFile .getResources ().getProperties ()));
294+ for (ExtensionDesc ext : jnlpFile .getResources ().getExtensions ()) {
295+ // Recursively look for extension jnlp files to collect their properties
296+ try {
297+ ext .resolve ();
298+ JNLPFile extFile = ext .getJNLPFile ();
299+ if (extFile != null ) {
300+ collectPropertiesFromJnlpHierarchy (props , extFile );
301+ }
302+ } catch (ParseException | IOException e ) {
303+ LOG .debug ("Could not resolve JNLP file {} (declared properties won't be set): {} " , ext .getName (), e .getMessage ());
304+ }
305+ }
306+ return props ;
307+ }
308+
279309}
0 commit comments