/hg/release/icedtea-web-1.2: Added check for main class in jar m...
dbhole at icedtea.classpath.org
dbhole at icedtea.classpath.org
Tue Feb 28 08:36:23 PST 2012
changeset e21f13506c3c in /hg/release/icedtea-web-1.2
details: http://icedtea.classpath.org/hg/release/icedtea-web-1.2?cmd=changeset;node=e21f13506c3c
author: Deepak Bhole <dbhole at redhat.com>
date: Tue Feb 28 11:35:41 2012 -0500
Added check for main class in jar manifest(s)
diffstat:
ChangeLog | 7 ++
netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java | 57 ++++++++++++++++++
2 files changed, 64 insertions(+), 0 deletions(-)
diffs (88 lines):
diff -r d3b97728550a -r e21f13506c3c ChangeLog
--- a/ChangeLog Tue Feb 28 10:05:57 2012 -0500
+++ b/ChangeLog Tue Feb 28 11:35:41 2012 -0500
@@ -1,3 +1,10 @@
+2012-02-28 Deepak Bhole <dbhole at redhat.com>
+
+ * 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 <dbhole at redhat.com>
* plugin/icedteanp/IcedTeaPluginRequestProcessor.cc
diff -r d3b97728550a -r e21f13506c3c netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java
--- a/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java Tue Feb 28 10:05:57 2012 -0500
+++ b/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java Tue Feb 28 11:35:41 2012 -0500
@@ -593,6 +593,39 @@
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 @@
}
/**
+ * 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.
*
More information about the distro-pkg-dev
mailing list