diff options
author | Deepak Bhole <[email protected]> | 2012-02-28 11:35:41 -0500 |
---|---|---|
committer | Deepak Bhole <[email protected]> | 2012-02-28 11:35:41 -0500 |
commit | f1cd5727f6e4fec7dea99c8f779e22d1f9a83e17 (patch) | |
tree | 532d4c0d2f04edf7a12384a4a7e5b703e62a7df4 | |
parent | f7c2d6d53a4546b367fb8834b50a60edfc6dc7ff (diff) |
Added check for main class in jar manifest(s)
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java | 57 |
2 files changed, 64 insertions, 0 deletions
@@ -1,5 +1,12 @@ 2012-02-28 Deepak Bhole <[email protected]> + * netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java + (checkForMain): Also check manifest file of main jar. + (getMainClassName): New method. Looks in a jar manifest to see if there is + a Main-Class specified. + +2012-02-28 Deepak Bhole <[email protected]> + * plugin/icedteanp/IcedTeaPluginRequestProcessor.cc (_eval): Return 0 id to Java side if eval fails. (_call): Return 0 id to Java side if call fails. diff --git a/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java b/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java index 290902a..1a1be71 100644 --- a/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java +++ b/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java @@ -593,6 +593,39 @@ public class JNLPClassLoader extends URLClassLoader { mainClass = ad.getMainClass(); } else return; + + // 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; + } + } + } + } + String desiredJarEntryName = mainClass + ".class"; for (int i = 0; i < jars.size(); i++) { @@ -630,6 +663,30 @@ public class JNLPClassLoader extends URLClassLoader { } /** + * Gets the name of the main method if specified in the manifest + * + * @param location The JAR location + * @return the main class name, null if there isn't one of if there was an error + */ + private String getMainClassName(URL location) { + + String mainClass = null; + File f = tracker.getCacheFile(location); + + if( f != null) { + try { + JarFile mainJar = new JarFile(f); + mainClass = mainJar.getManifest(). + getMainAttributes().getValue("Main-Class"); + } catch (IOException ioe) { + mainClass = null; + } + } + + return mainClass; + } + + /** * Is called by checkForMain() to check if the jar file is signed and if it * contains a signed JNLP file. * |