[icedtea-web] RFC: Patch to check the manifest file for main class

Deepak Bhole dbhole at redhat.com
Tue Feb 28 08:04:42 PST 2012


* Deepak Bhole <dbhole at redhat.com> [2012-02-28 11:02]:
> * Jiri Vanek <jvanek at redhat.com> [2012-02-28 11:00]:
> > On 02/28/2012 04:44 PM, Deepak Bhole wrote:
> > >* Jiri Vanek<jvanek at redhat.com>  [2012-02-28 03:16]:
> > >>On 02/28/2012 02:01 AM, Omair Majid wrote:
> > >
> > >Hi Jiri,
> > >
> > >Sorry I missed the second part.
> > >
> > >>
> > >>The same fix should be also aplied for to applet loading (Does not look like this patch do.....):
> > >>
> > >
> > >What do you mean by it does not apply for applet loading? There is an if
> > >check in checkForMain that checks in the AppletDesc.
> > 
> > Sorry - my overlook :((
> > But - btw - have you tested it fro applet? O:)
> 
> If it is in the list here:
> http://icedtea.classpath.org/wiki/IcedTea-Web-Tests
> 
> If not, please add one.
> 
> > 
> > One more question - in case you will want to check first jar (or iterate through jars until first one with manifest and main class in)  is in, isn't better to do this AFTER the jars re downloaded?
> 
> tracker.getCacheFile blocks till download is done according to the
> javadocs.
> 

New patch attached.

> Cheers,
> Deepak
> 
> > >
> > >Cheers,
> > >Deepak
> > 
-------------- next part --------------
diff -r d3b97728550a 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:04:09 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