Skip to content

Commit 27eb656

Browse files
authored
Merge pull request #903 from AdoptOpenJDK/extension-properties
Set properties specified in extension jnlp
2 parents fc63218 + b5552ed commit 27eb656

File tree

2 files changed

+76
-4
lines changed

2 files changed

+76
-4
lines changed

core/src/main/java/net/adoptopenjdk/icedteaweb/jnlp/element/resource/ExtensionDesc.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@
1818
package net.adoptopenjdk.icedteaweb.jnlp.element.resource;
1919

2020
import net.adoptopenjdk.icedteaweb.jnlp.version.VersionString;
21-
21+
import net.adoptopenjdk.icedteaweb.logging.Logger;
22+
import net.adoptopenjdk.icedteaweb.logging.LoggerFactory;
23+
import net.adoptopenjdk.icedteaweb.xmlparser.ParseException;
24+
import net.sourceforge.jnlp.JNLPFile;
25+
import net.sourceforge.jnlp.JNLPFileFactory;
26+
import net.adoptopenjdk.icedteaweb.i18n.Translator;
27+
28+
import java.io.IOException;
2229
import java.net.URL;
2330
import java.util.ArrayList;
2431
import java.util.HashMap;
@@ -32,6 +39,8 @@
3239
* @version $Revision: 1.8 $
3340
*/
3441
public class ExtensionDesc {
42+
43+
private static final Logger LOG = LoggerFactory.getLogger(ExtensionDesc.class);
3544
public static final String EXT_DOWNLOAD_ELEMENT = "ext-download";
3645
public static final String HREF_ATTRIBUTE = "href";
3746
public static final String DOWNLOAD_ATTRIBUTE = "download";
@@ -58,6 +67,9 @@ public class ExtensionDesc {
5867
/** eager ext parts */
5968
private final List<String> eagerExtParts = new ArrayList<>();
6069

70+
/** the JNLPFile the extension refers to */
71+
private JNLPFile file;
72+
6173
/**
6274
* Create an extension descriptor.
6375
*
@@ -108,4 +120,34 @@ public VersionString getVersion() {
108120
public URL getLocation() {
109121
return location;
110122
}
123+
124+
/**
125+
* Resolves the extension by creating a JNLPFile from the file
126+
* specified by the extension's location property.
127+
*
128+
* @throws IOException if the extension JNLPFile could not be resolved.
129+
* @throws ParseException if the extension JNLPFile could not be
130+
* parsed or was not a component or installer descriptor.
131+
*/
132+
public void resolve() throws ParseException, IOException {
133+
if (file == null) {
134+
file = new JNLPFileFactory().create(location);
135+
136+
LOG.debug("Resolve: {}", file.getInformation().getTitle());
137+
138+
// check for it being an extension descriptor
139+
if (!file.isComponent() && !file.isInstaller()) {
140+
throw new ParseException(Translator.R("JInvalidExtensionDescriptor", name, location));
141+
}
142+
}
143+
144+
}
145+
146+
/**
147+
* @return a JNLPFile for the extension, or null if the JNLP
148+
* file has not been resolved.
149+
*/
150+
public JNLPFile getJNLPFile() {
151+
return file;
152+
}
111153
}

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

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616

1717
package net.sourceforge.jnlp.runtime;
1818

19+
import net.adoptopenjdk.icedteaweb.jnlp.element.resource.ExtensionDesc;
1920
import net.adoptopenjdk.icedteaweb.jnlp.element.resource.PropertyDesc;
2021
import net.adoptopenjdk.icedteaweb.jnlp.element.security.SecurityDesc;
2122
import net.adoptopenjdk.icedteaweb.logging.Logger;
2223
import net.adoptopenjdk.icedteaweb.logging.LoggerFactory;
24+
import net.adoptopenjdk.icedteaweb.xmlparser.ParseException;
2325
import net.sourceforge.jnlp.JNLPFile;
2426
import net.sourceforge.jnlp.config.DeploymentConfiguration;
2527
import net.sourceforge.jnlp.runtime.classloader.JNLPClassLoader;
@@ -34,7 +36,9 @@
3436
import java.security.CodeSource;
3537
import java.security.PrivilegedAction;
3638
import 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

Comments
 (0)