changeset 449:88d309e7d3eb

Fixes PR1011 w/ reproducer, folders now allowed in archive tag. Previously folders in the archive tag were treated as jars. They are now correctly treated as resource folders.
author Adam Domurad <adomurad@redhat.com>
date Thu, 28 Jun 2012 10:51:30 -0400
parents ee7c412bbd8f
children 3bb15c661b24
files ChangeLog Makefile.am NEWS netx/net/sourceforge/jnlp/PluginBridge.java netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java tests/jnlp_tests/custom/AppletFolderInArchiveTag/resources/AppletFolderInArchiveTag.html tests/jnlp_tests/custom/AppletFolderInArchiveTag/srcs/AppletFolderInArchiveTag.java tests/jnlp_tests/custom/AppletFolderInArchiveTag/srcs/Makefile tests/jnlp_tests/custom/AppletFolderInArchiveTag/testcases/AppletFolderInArchiveTagTests.java
diffstat 9 files changed, 269 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Jun 26 12:41:49 2012 +0200
+++ b/ChangeLog	Thu Jun 28 10:51:30 2012 -0400
@@ -1,3 +1,28 @@
+2012-05-29  Adam Domurad  <adomurad@redhat.com>
+
+	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.
+
+2012-06-27  Adam Domurad  <adomurad@redhat.com>
+
+	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
+
 2012-06-26  Jiri Vanek  <jvanek@redhat.com>
 
 	Added slipped midori and epiphany to recognized browsers.
--- a/Makefile.am	Tue Jun 26 12:41:49 2012 +0200
+++ b/Makefile.am	Thu Jun 28 10:51:30 2012 -0400
@@ -155,6 +155,10 @@
 export REPRODUCERS_DPARAMETERS= $(DTEST_SERVER) $(DJAVAWS_BUILD) $(DBROWSERS) $(BROWSER_TESTS_MODIFICATION)
 # end of `D`shortcuts
 
+#exported autoconf copies
+export EXPORTED_JAVAC=$(BOOT_DIR)/bin/javac
+#end of exported autoconf copies
+
 # binary names
 javaws:= $(shell echo javaws | sed '@program_transform_name@')
 itweb_settings:= $(shell echo itweb-settings | sed '@program_transform_name@')
--- a/NEWS	Tue Jun 26 12:41:49 2012 +0200
+++ b/NEWS	Thu Jun 28 10:51:30 2012 -0400
@@ -20,6 +20,7 @@
   - PR518: NPString.utf8characters not guaranteed to be nul-terminated
   - PR722: META-INF/ unsigned entries should be ignored in signing
   - PR855: AppletStub getDocumentBase() doesn't return full URL
+  - PR1011: Folders treated as jar files in archive tag
 * Common
   - PR918: java applet windows uses a low resulution black/white icon
 
--- a/netx/net/sourceforge/jnlp/PluginBridge.java	Tue Jun 26 12:41:49 2012 +0200
+++ b/netx/net/sourceforge/jnlp/PluginBridge.java	Thu Jun 28 10:51:30 2012 -0400
@@ -22,15 +22,15 @@
 
 package net.sourceforge.jnlp;
 
+import java.io.File;
 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;
 
@@ -40,11 +40,13 @@
  */
 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>();
+    //Folders can be added to the code-base through the archive tag
+    private List<String> codeBaseFolders = new ArrayList<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;
@@ -54,14 +56,32 @@
      * Creates a new PluginBridge using a default JNLPCreator.
      */
     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 {
         this(codebase, documentBase, jar, main, width, height, atts, uKey, new JNLPCreator());
     }
 
-    public PluginBridge(URL codebase, URL documentBase, String jar, String main,
-                        int width, int height, Hashtable<String, String> atts,
+    /**
+     * 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, Map<String, String> atts,
                         String uKey, JNLPCreator jnlpCreator)
             throws Exception {
         specVersion = new Version("1.0");
@@ -131,19 +151,14 @@
             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);
             }
         }
 
@@ -232,9 +247,9 @@
                         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;
@@ -250,12 +265,12 @@
                                     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;
@@ -305,6 +320,13 @@
     }
 
     /**
+     * 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.
      */
--- a/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java	Tue Jun 26 12:41:49 2012 +0200
+++ b/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java	Thu Jun 28 10:51:30 2012 -0400
@@ -443,6 +443,19 @@
      * 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;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/jnlp_tests/custom/AppletFolderInArchiveTag/resources/AppletFolderInArchiveTag.html	Thu Jun 28 10:51:30 2012 -0400
@@ -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>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/jnlp_tests/custom/AppletFolderInArchiveTag/srcs/AppletFolderInArchiveTag.java	Thu Jun 28 10:51:30 2012 -0400
@@ -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.");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/jnlp_tests/custom/AppletFolderInArchiveTag/srcs/Makefile	Thu Jun 28 10:51:30 2012 -0400
@@ -0,0 +1,18 @@
+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)
+INDEX_HTML_BODY="<html><body><h1>Required to recognize folder structure</h1></body></html>"
+
+prepare-reproducer:
+	echo PREPARING REPRODUCER $(TESTNAME)
+	mkdir -p $(DEPLOY_SUBDIR)
+	echo INDEX_HTML_BODY > $(DEPLOY_SUBDIR)/index.html
+	$(EXPORTED_JAVAC) -classpath $(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)
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/jnlp_tests/custom/AppletFolderInArchiveTag/testcases/AppletFolderInArchiveTagTests.java	Thu Jun 28 10:51:30 2012 -0400
@@ -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