# HG changeset patch # User Jiri Vanek # Date 1382354366 -7200 # Node ID eafa63cec4ca195e580f0edb7705f359bcf0b3be # Parent 29c1c1f92e09e1c789ae637f2a2fc88162beaab4 Logic to extract main class attribute generalized to common methods. * netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java: (getMainClassName) is now calling (getManifestAttribute) (getManifestAttribute) new method, extract named attribute from url specified jar. Called by (checkForAttributeInJars) (checkForMain) is now calling (checkForAttributeInJars). Also logic of (checkForAttributeInJars) was taken from here. (checkForAttributeInJars) new method, read specific attribute from diff -r 29c1c1f92e09 -r eafa63cec4ca ChangeLog --- a/ChangeLog Thu Oct 17 11:09:51 2013 -0400 +++ b/ChangeLog Mon Oct 21 13:19:26 2013 +0200 @@ -1,3 +1,15 @@ +2013-10-21 Jiri Vanek + + Logic to extract main class attribute generalized to common methods. + * netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java: + (getMainClassName) is now calling (getManifestAttribute) + (getManifestAttribute) new method, extract named attribute from url + specified jar. Called by (checkForAttributeInJars) + (checkForMain) is now calling (checkForAttributeInJars). Also logic of + (checkForAttributeInJars) was taken from here. + (checkForAttributeInJars) new method, read specific attribute from + application jar(s) in specific order. + 2013-10-16 Andrew Azores Resolve deadlock issue when multiple applets are loaded simultaneously diff -r 29c1c1f92e09 -r eafa63cec4ca netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java --- a/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java Thu Oct 17 11:09:51 2013 -0400 +++ b/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java Mon Oct 21 13:19:26 2013 +0200 @@ -59,6 +59,7 @@ import java.util.TreeSet; import java.util.Vector; import java.util.concurrent.ConcurrentHashMap; +import java.util.jar.Attributes; import java.util.jar.JarEntry; import net.sourceforge.jnlp.util.JarFile; import java.util.jar.Manifest; @@ -794,6 +795,47 @@ activateJars(initialJars); } + /*** + * Checks for the jar that contains the attribute. + * + * @param jars Jars that are checked to see if they contain the main class + * @param name attribute to be found + * @throws LaunchException Thrown if the signed JNLP file, within the main jar, fails to be verified or does not match + */ + public String checkForAttributeInJars(List jars, Attributes.Name name) { + + String result = null; + + // Check main jar + JARDesc mainJarDesc = file.getResources().getMainJAR(); + result = getManifestAttribute(mainJarDesc.getLocation(), name); + + if (result != null) { + return result; + } + + // Check first jar + JARDesc firstJarDesc = jars.get(0); + result = getManifestAttribute(firstJarDesc.getLocation(),name); + + if (result != null) { + return result; + } + + // Still not found? Iterate and set if only 1 was found + for (JARDesc jarDesc: jars) { + String mainClassInThisJar = getManifestAttribute(jarDesc.getLocation(), name); + if (mainClassInThisJar != null) { + if (result == null) { // first main class + result = mainClassInThisJar; + } else { // There is more than one main class. Set to null and break. + result = null; + break; + } + } + } + return result; + } /*** * Checks for the jar that contains the main class. If the main class was * found, it checks to see if the jar is signed and whether it contains a @@ -816,34 +858,8 @@ // The main class may be specified in the manifest - // Check main jar if (mainClass == null) { - JARDesc mainJarDesc = file.getResources().getMainJAR(); - mainClass = getMainClassName(mainJarDesc.getLocation()); - } - - // Check first jar - if (mainClass == null) { - JARDesc firstJarDesc = jars.get(0); - mainClass = getMainClassName(firstJarDesc.getLocation()); - } - - // Still not found? Iterate and set if only 1 was found - if (mainClass == null) { - - for (JARDesc jarDesc: jars) { - String mainClassInThisJar = getMainClassName(jarDesc.getLocation()); - - if (mainClassInThisJar != null) { - - if (mainClass == null) { // first main class - mainClass = mainClassInThisJar; - } else { // There is more than one main class. Set to null and break. - mainClass = null; - break; - } - } - } + mainClass = checkForAttributeInJars(jars, Attributes.Name.MAIN_CLASS); } String desiredJarEntryName = mainClass + ".class"; @@ -891,24 +907,35 @@ * @return the main class name, null if there isn't one of if there was an error */ String getMainClassName(URL location) { + return getManifestAttribute(location, Attributes.Name.MAIN_CLASS); + } + + + /** + * Gets the name of the main method if specified in the manifest + * + * @param location The JAR location + * @return the attribute value, null if there isn't one of if there was an error + */ + public String getManifestAttribute(URL location, Attributes.Name attribute) { - String mainClass = null; + String attributeValue = null; File f = tracker.getCacheFile(location); if( f != null) { JarFile mainJar = null; try { mainJar = new JarFile(f); - mainClass = mainJar.getManifest(). - getMainAttributes().getValue("Main-Class"); + attributeValue = mainJar.getManifest(). + getMainAttributes().getValue(attribute); } catch (IOException ioe) { - mainClass = null; + attributeValue = null; } finally { StreamUtils.closeSilently(mainJar); } } - return mainClass; + return attributeValue; } /**