« Return to Thread: [icedtea-web][rfc] Fix for PR1011 w/ reproducer

[icedtea-web][rfc] Fix for PR1011 w/ reproducer

by Adam Domurad :: Rate this Message:

| View in Thread

So finally I got the custom makefile system working with my reproducer,
with many thanks to Jiri.

This reproducer & patch addresses the issue that folders may be included
in archive tags as well as jars.

Note this patch was already posted with a review from Pavel and only
requires an OK for head. Included is minor refactoring that was done
during the patch, that needs a separate review.

Changelog for bugfix:
2012-05-29  Adam Domurad  <adomurad@...>

        Allow for folders in archive tag.
        * netx/net/sourceforge/jnlp/PluginBridge.java:
        (PluginBridge) Changes jar -> archive, parse contents with
        addArchiveEntries.
        (addArchiveEntries) New method. Adds entries ending with / to the list
        of folders.
        (getCodeBaseFolders) Returns the folders collected by addArchiveEntries
        * netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java:
        (initializeResources) If ran as plugin, add archive tag folders to the
        code base loader.


Changelog for reproducers:
2012-06-27  Adam Domurad  <adomurad@...>

        Tests folders in archive tag
        *
tests/jnlp_tests/custom/AppletFolderInArchiveTag/testcases/AppletFolderInArchiveTagTests.java: Runs html file in browser
        * tests/jnlp_tests/custom/AppletFolderInArchiveTag/srcs/Makefile:
        packages compiled source files in folder  
        *
tests/jnlp_tests/custom/AppletFolderInArchiveTag/srcs/AppletFolderInArchiveTag.java:
        Simple output to confirm it is running
        *
tests/jnlp_tests/custom/AppletFolderInArchiveTag/resources/AppletFolderInArchiveTag.html:
        Has folder in its archive tag that contains a class file



[folders-in-archive-tag2.patch]

diff --git a/netx/net/sourceforge/jnlp/PluginBridge.java b/netx/net/sourceforge/jnlp/PluginBridge.java
--- a/netx/net/sourceforge/jnlp/PluginBridge.java
+++ b/netx/net/sourceforge/jnlp/PluginBridge.java
@@ -22,6 +22,7 @@
 
 package net.sourceforge.jnlp;
 
+import java.io.File;
 import java.net.URL;
 import java.net.MalformedURLException;
 import java.util.HashSet;
@@ -38,6 +39,8 @@ public class PluginBridge extends JNLPFi
 
     String name;
     HashSet<String> jars = new HashSet<String>();
+    //Folders can be added to the code-base through the archive tag
+    private List<String> codeBaseFolders = new ArrayList<String>();
     String[] cacheJars = new String[0];
     String[] cacheExJars = new String[0];
     Hashtable<String, String> atts;
@@ -46,7 +49,25 @@ public class PluginBridge extends JNLPFi
     private boolean codeBaseLookup;
     private boolean useJNLPHref;
 
-    public PluginBridge(URL codebase, URL documentBase, String jar, String main,
+    /**
+     * Handles archive tag entries, which may be folders or jar files
+     * @param archives the components of the archive tag
+     */
+    private void addArchiveEntries(String[] archives) {
+        for (String archiveEntry : archives){
+            // trim white spaces
+            archiveEntry = archiveEntry.trim();
+
+            /*Only '/' on linux, '/' or '\\' on windows*/
+            if (archiveEntry.endsWith("/") || archiveEntry.endsWith(File.pathSeparator)) {
+                this.codeBaseFolders.add(archiveEntry);
+            } else {
+                this.jars.add(archiveEntry);
+            }
+        }
+    }
+
+    public PluginBridge(URL codebase, URL documentBase, String archive, String main,
                         int width, int height, Hashtable<String, String> atts,
                         String uKey)
             throws Exception {
@@ -115,19 +136,14 @@ public class PluginBridge extends JNLPFi
             cacheExJars = cacheArchiveEx.split(",");
         }
 
-        if (jar != null && jar.length() > 0) {
-            String[] jars = jar.split(",");
+        if (archive != null && archive.length() > 0) {
+            String[] archives = archive.split(",");
 
-            // trim white spaces
-            for (int i = 0; i < jars.length; i++) {
-                String jarName = jars[i].trim();
-                if (jarName.length() > 0)
-                    this.jars.add(jarName);
-            }
+            addArchiveEntries(archives);
 
             if (JNLPRuntime.isDebug()) {
-                System.err.println("Jar string: " + jar);
-                System.err.println("jars length: " + jars.length);
+                System.err.println("Jar string: " + archive);
+                System.err.println("jars length: " + archives.length);
             }
         }
 
@@ -289,6 +305,13 @@ public class PluginBridge extends JNLPFi
     }
 
     /**
+     * Returns the list of folders to be added to the codebase
+     */
+    public List<String> getCodeBaseFolders() {
+        return new ArrayList<String>(codeBaseFolders);
+    }
+
+    /**
      * Returns the resources section of the JNLP file for the
      * specified locale, os, and arch.
      */
diff --git a/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java b/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java
--- a/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java
+++ b/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java
@@ -435,6 +435,19 @@ public class JNLPClassLoader extends URL
      * ResourceTracker for downloading.
      */
     void initializeResources() throws LaunchException {
+        if (file instanceof PluginBridge){
+            PluginBridge bridge = (PluginBridge)file;
+
+            for (String codeBaseFolder : bridge.getCodeBaseFolders()){
+                try {
+                    addToCodeBaseLoader(new URL(file.getCodeBase(), codeBaseFolder));
+                } catch (MalformedURLException mfe) {
+                    System.err.println("Problem trying to add folder to code base:");
+                    System.err.println(mfe.getMessage());
+                }
+            }
+        }
+
         JARDesc jars[] = resources.getJARs();
         if (jars == null || jars.length == 0)
             return;


[minor-refactor-pluginbridge.patch]

diff --git a/netx/net/sourceforge/jnlp/PluginBridge.java b/netx/net/sourceforge/jnlp/PluginBridge.java
--- a/netx/net/sourceforge/jnlp/PluginBridge.java
+++ b/netx/net/sourceforge/jnlp/PluginBridge.java
@@ -26,28 +26,28 @@ import java.net.URL;
 import java.net.MalformedURLException;
 import java.util.HashSet;
 import java.util.Hashtable;
-import java.util.Iterator;
 import java.util.Locale;
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Map;
+import java.util.Set;
 
 import net.sourceforge.jnlp.runtime.JNLPRuntime;
 
 public class PluginBridge extends JNLPFile {
 
-    String name;
-    HashSet<String> jars = new HashSet<String>();
-    String[] cacheJars = new String[0];
-    String[] cacheExJars = new String[0];
-    Hashtable<String, String> atts;
+    private String name;
+    private Set<String> jars = new HashSet<String>();
+    private String[] cacheJars = new String[0];
+    private String[] cacheExJars = new String[0];
+    private Map<String, String> atts;
     private boolean usePack;
     private boolean useVersion;
     private boolean codeBaseLookup;
     private boolean useJNLPHref;
 
     public PluginBridge(URL codebase, URL documentBase, String jar, String main,
-                        int width, int height, Hashtable<String, String> atts,
+                        int width, int height, Map<String, String> atts,
                         String uKey)
             throws Exception {
         specVersion = new Version("1.0");
@@ -216,9 +216,9 @@ public class PluginBridge extends JNLPFi
                         if (cacheOption != null && cacheOption.equalsIgnoreCase("no"))
                             cacheable = false;
 
-                        for (int i = 0; i < cacheJars.length; i++) {
+                        for (String cacheJar : cacheJars) {
 
-                            String[] jarAndVer = cacheJars[i].split(";");
+                            String[] jarAndVer = cacheJar.split(";");
 
                             String jar = jarAndVer[0];
                             Version version = null;
@@ -234,12 +234,12 @@ public class PluginBridge extends JNLPFi
                                     version, null, false, true, false, cacheable));
                         }
 
-                        for (int i = 0; i < cacheExJars.length; i++) {
+                        for (String cacheExJar : cacheExJars) {
 
-                            if (cacheExJars[i].length() == 0)
+                            if (cacheExJar.length() == 0)
                                 continue;
 
-                            String[] jarInfo = cacheExJars[i].split(";");
+                            String[] jarInfo = cacheExJar.split(";");
 
                             String jar = jarInfo[0].trim();
                             Version version = null;


[folder-archive-reproducer.patch]

diff --git a/tests/jnlp_tests/custom/AppletFolderInArchiveTag/resources/AppletFolderInArchiveTag.html b/tests/jnlp_tests/custom/AppletFolderInArchiveTag/resources/AppletFolderInArchiveTag.html
new file mode 100644
--- /dev/null
+++ b/tests/jnlp_tests/custom/AppletFolderInArchiveTag/resources/AppletFolderInArchiveTag.html
@@ -0,0 +1,42 @@
+<!--
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+IcedTea is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version.
+
+ -->
+<html><head></head><body bgcolor="blue">
+<p><applet code="AppletFolderInArchiveTag.class" archive="archive_tag_folder_test/">
+</applet></p>
+</body>
+</html>
diff --git a/tests/jnlp_tests/custom/AppletFolderInArchiveTag/srcs/AppletFolderInArchiveTag.java b/tests/jnlp_tests/custom/AppletFolderInArchiveTag/srcs/AppletFolderInArchiveTag.java
new file mode 100644
--- /dev/null
+++ b/tests/jnlp_tests/custom/AppletFolderInArchiveTag/srcs/AppletFolderInArchiveTag.java
@@ -0,0 +1,58 @@
+import java.applet.Applet;
+
+/*
+Copyright (C) 2011 Red Hat, Inc.
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published by
+the Free Software Foundation, version 2.
+
+IcedTea is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING.  If not, write to
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version.
+ */
+public class AppletFolderInArchiveTag extends Applet {
+
+    private static class Killer extends Thread {
+        @Override
+        public void run() {
+            try {
+                int n = 2000;
+                Thread.sleep(n);
+                System.exit(0);
+            } catch (Exception ex) {
+            }
+        }
+    }
+
+    @Override
+    public void init() {
+        new Killer().start();
+        System.out.println("This was ran from a folder specified in the archive tag.");
+    }
+}
diff --git a/tests/jnlp_tests/custom/AppletFolderInArchiveTag/srcs/Makefile b/tests/jnlp_tests/custom/AppletFolderInArchiveTag/srcs/Makefile
new file mode 100644
--- /dev/null
+++ b/tests/jnlp_tests/custom/AppletFolderInArchiveTag/srcs/Makefile
@@ -0,0 +1,17 @@
+TESTNAME=AppletFolderInArchiveTag
+ARCHIVE_TEST_FOLDER=archive_tag_folder_test
+JAVAC_CLASSPATH=$(JNLP_TESTS_ENGINE_DIR):$(NETX_DIR)/lib/classes.jar
+DEPLOY_SUBDIR=$(JNLP_TESTS_SERVER_DEPLOYDIR)/$(ARCHIVE_TEST_FOLDER)
+
+prepare-reproducer:
+ echo PREPARING REPRODUCER $(TESTNAME)
+ mkdir -p $(DEPLOY_SUBDIR)
+ echo "" > $(DEPLOY_SUBDIR)/index.html
+ $(EXPORTED_JAVAC) -cp $(JAVAC_CLASSPATH) -d $(DEPLOY_SUBDIR) $(TESTNAME).java
+ echo PREPARED REPRODUCER $(TESTNAME)
+
+clean-reproducer:
+ echo CLEANING REPRODUCER $(TESTNAME)
+ rm -rf $(DEPLOY_SUBDIR)
+ echo CLEANED REPRODUCER $(TESTNAME)
+
diff --git a/tests/jnlp_tests/custom/AppletFolderInArchiveTag/testcases/AppletFolderInArchiveTagTests.java b/tests/jnlp_tests/custom/AppletFolderInArchiveTag/testcases/AppletFolderInArchiveTagTests.java
new file mode 100644
--- /dev/null
+++ b/tests/jnlp_tests/custom/AppletFolderInArchiveTag/testcases/AppletFolderInArchiveTagTests.java
@@ -0,0 +1,61 @@
+/* AppletFolderInArchiveTagTests.java
+Copyright (C) 2011 Red Hat, Inc.
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published by
+the Free Software Foundation, version 2.
+
+IcedTea is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING.  If not, write to
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version.
+ */
+
+import net.sourceforge.jnlp.ServerAccess.ProcessResult;
+import net.sourceforge.jnlp.annotations.Bug;
+import net.sourceforge.jnlp.annotations.NeedsDisplay;
+import net.sourceforge.jnlp.annotations.TestInBrowsers;
+import net.sourceforge.jnlp.browsertesting.BrowserTest;
+import net.sourceforge.jnlp.browsertesting.Browsers;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class AppletFolderInArchiveTagTests extends BrowserTest{
+
+
+    @NeedsDisplay
+    @Test
+    @TestInBrowsers(testIn={Browsers.all})
+    @Bug(id="PR1011")
+    public void testClassInAppletFolder() throws Exception {
+        ProcessResult pr = server.executeBrowser("/AppletFolderInArchiveTag.html");
+
+        String s0 = "This was ran from a folder specified in the archive tag.";
+        Assert.assertTrue("Expected '"+s0+"', stdout was: " + pr.stdout, pr.stdout.contains(s0));
+    }
+}
\ No newline at end of file

 « Return to Thread: [icedtea-web][rfc] Fix for PR1011 w/ reproducer