/hg/icedtea-web: Fix for PR1292: Javaws does not resolve version...

adomurad at icedtea.classpath.org adomurad at icedtea.classpath.org
Wed Jan 30 09:01:16 PST 2013


changeset fd0e84ce013e in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=fd0e84ce013e
author: Adam Domurad <adomurad at redhat.com>
date: Wed Jan 30 12:01:11 2013 -0500

	Fix for PR1292: Javaws does not resolve versioned jar names with periods properly


diffstat:

 ChangeLog                                                                     |  18 ++
 NEWS                                                                          |   1 +
 netx/net/sourceforge/jnlp/cache/ResourceUrlCreator.java                       |  23 ++-
 tests/netx/unit/net/sourceforge/jnlp/cache/ResourceUrlCreatorTest.java        |  43 ++++++
 tests/reproducers/simple/VersionedJar__V1/resources/VersionedJarDisabled.jnlp |  52 ++++++++
 tests/reproducers/simple/VersionedJar__V1/resources/VersionedJarEnabled.jnlp  |  52 ++++++++
 tests/reproducers/simple/VersionedJar__V1/srcs/VersionedJar.java              |  46 +++++++
 tests/reproducers/simple/VersionedJar__V1/testcases/VersionedJarTest.java     |  64 ++++++++++
 8 files changed, 293 insertions(+), 6 deletions(-)

diffs (356 lines):

diff -r c6b48ce8f868 -r fd0e84ce013e ChangeLog
--- a/ChangeLog	Wed Jan 30 17:44:44 2013 +0100
+++ b/ChangeLog	Wed Jan 30 12:01:11 2013 -0500
@@ -1,3 +1,21 @@
+2013-01-30  Adam Domurad  <adomurad at redhat.com>
+
+	Fix for PR1292: Javaws does not resolve versioned jar names with 
+	periods correctly
+	* netx/net/sourceforge/jnlp/cache/ResourceUrlCreator.java
+	(getUrl): Fix versioning of jar names that have periods, eg 
+	'foo.bar.jar'. Make method static for testing.
+	* tests/netx/unit/net/sourceforge/jnlp/cache/ResourceUrlCreatorTest.java:
+	New, test version & pack URL encoding.
+	* tests/reproducers/simple/VersionedJar__V1/resources/VersionedJarDisabled.jnlp:
+	New, tries to use versioned jar with versioning not turned on.
+	* tests/reproducers/simple/VersionedJar__V1/resources/VersionedJarEnabled.jnlp:
+	New, tries to use versioned jar with versioning turned on.
+	* tests/reproducers/simple/VersionedJar__V1/srcs/VersionedJar.java:
+	New, prints simple message.
+	* tests/reproducers/simple/VersionedJar__V1/testcases/VersionedJarTest.java:
+	New, tests if VersionedJar has ran only with versioning turned on.
+
 2013-01-30  Jiri Vanek  <jvanek at redhat.com>
 
 	* netx/net/sourceforge/jnlp/splashscreen/parts/JEditorPaneBasedExceptionDialog.java:
diff -r c6b48ce8f868 -r fd0e84ce013e NEWS
--- a/NEWS	Wed Jan 30 17:44:44 2013 +0100
+++ b/NEWS	Wed Jan 30 12:01:11 2013 -0500
@@ -19,6 +19,7 @@
 * NetX
   - PR1027: DownloadService is not supported by IcedTea-Web
   - PR725: JNLP applications will prompt for creating desktop shortcuts every time they are run
+  - PR1292: Javaws does not resolve versioned jar names with periods correctly
 * Plugin
   - PR1106: Buffer overflow in plugin table-
   - PR1166: Embedded JNLP File is not supported in applet tag
diff -r c6b48ce8f868 -r fd0e84ce013e netx/net/sourceforge/jnlp/cache/ResourceUrlCreator.java
--- a/netx/net/sourceforge/jnlp/cache/ResourceUrlCreator.java	Wed Jan 30 17:44:44 2013 +0100
+++ b/netx/net/sourceforge/jnlp/cache/ResourceUrlCreator.java	Wed Jan 30 12:01:11 2013 -0500
@@ -102,9 +102,9 @@
      * @param resource the resource
      * @param usePack whether the URL should point to the pack200 file
      * @param useVersion whether the URL should be modified to include the version
-     * @return a URL for the resource or null if an appropraite URL can not be found
+     * @return a URL for the resource or null if an appropriate URL can not be found
      */
-    protected URL getUrl(Resource resource, boolean usePack, boolean useVersion) {
+    static URL getUrl(Resource resource, boolean usePack, boolean useVersion) {
         if (!(usePack || useVersion)) {
             throw new IllegalArgumentException("either pack200 or version required");
         }
@@ -116,10 +116,21 @@
         }
         String filename = location.substring(lastSlash + 1);
         if (useVersion && resource.requestVersion != null) {
-            String parts[] = filename.split("\\.", 2);
-            String name = parts[0];
-            String extension = parts[1];
-            filename = name + "__V" + resource.requestVersion + "." + extension;
+            // With 'useVersion', j2-commons-cli.jar becomes, for example, j2-commons-cli__V1.0.jar
+            String parts[] = filename.split("\\.", -1 /* Keep blank strings*/);
+
+            StringBuilder sb = new StringBuilder();
+            for (int i = 0; i < parts.length; i++) {
+                sb.append(parts[i]);
+                // Append __V<number> before last '.'
+                if (i == parts.length -2) {
+                    sb.append("__V" + resource.requestVersion);
+                }
+                sb.append('.');
+            }
+            sb.setLength(sb.length() - 1); // remove last '.'
+
+            filename = sb.toString();
         }
         if (usePack) {
             filename = filename + ".pack.gz";
diff -r c6b48ce8f868 -r fd0e84ce013e tests/netx/unit/net/sourceforge/jnlp/cache/ResourceUrlCreatorTest.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/netx/unit/net/sourceforge/jnlp/cache/ResourceUrlCreatorTest.java	Wed Jan 30 12:01:11 2013 -0500
@@ -0,0 +1,43 @@
+package net.sourceforge.jnlp.cache;
+
+import static org.junit.Assert.assertEquals;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import net.sourceforge.jnlp.Version;
+
+import org.junit.Test;
+
+public class ResourceUrlCreatorTest {
+
+    @Test
+    public void testVersionEncode() throws MalformedURLException {
+        Resource resource = Resource.getResource(new URL("http://test.jar"), new Version("1.1"), null);
+        URL result = ResourceUrlCreator.getUrl(resource, false /*don't use pack suffix*/, true /*use version suffix*/);
+        assertEquals("http://test__V1.1.jar", result.toString());
+    }
+
+    @Test
+    public void testVersionWithPeriods() throws MalformedURLException {
+        Resource resource = Resource.getResource(new URL("http://test.with.periods.jar"), new Version("1.1"), null);
+        URL result = ResourceUrlCreator.getUrl(resource, false /*don't use pack suffix*/, true /*use version suffix*/);
+
+        // A previous bug had this as "test__V1.1.with.periods.jar"
+        assertEquals("http://test.with.periods__V1.1.jar", result.toString());
+    }
+
+    @Test
+    public void testPackEncode() throws MalformedURLException {
+        Resource resource = Resource.getResource(new URL("http://test.jar"), new Version("1.1"), null);
+        URL result = ResourceUrlCreator.getUrl(resource, true /*use pack suffix*/, false /*don't use version suffix*/);
+        assertEquals("http://test.jar.pack.gz", result.toString());
+    }
+
+    @Test
+    public void testVersionAndPackEncode() throws MalformedURLException {
+        Resource resource = Resource.getResource(new URL("http://test.jar"), new Version("1.1"), null);
+        URL result = ResourceUrlCreator.getUrl(resource, true /*use pack suffix*/, true/*use version suffix*/);
+        assertEquals("http://test__V1.1.jar.pack.gz", result.toString());
+    }
+}
diff -r c6b48ce8f868 -r fd0e84ce013e tests/reproducers/simple/VersionedJar__V1/resources/VersionedJarDisabled.jnlp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/reproducers/simple/VersionedJar__V1/resources/VersionedJarDisabled.jnlp	Wed Jan 30 12:01:11 2013 -0500
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+
+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.
+ -->
+
+<jnlp spec="1.0"
+      codebase="./"
+      href="VersionedJarDisabled.jnlp">
+   <information> 
+      <title>Test versioned jars</title>
+      <vendor>IcedTea</vendor>
+   </information> 
+   <resources>
+      <jar href="VersionedJar.jar" main="true" version="1"/>
+      <property name="jnlp.versionEnabled" value="false"/>
+   </resources>
+   <application-desc main-class="VersionedJar"/>
+</jnlp> 
diff -r c6b48ce8f868 -r fd0e84ce013e tests/reproducers/simple/VersionedJar__V1/resources/VersionedJarEnabled.jnlp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/reproducers/simple/VersionedJar__V1/resources/VersionedJarEnabled.jnlp	Wed Jan 30 12:01:11 2013 -0500
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+
+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.
+ -->
+
+<jnlp spec="1.0"
+      codebase="./"
+      href="VersionedJarEnabled.jnlp">
+   <information> 
+      <title>Test replacing security manager</title> 
+      <vendor>IcedTea</vendor>
+   </information> 
+   <resources>
+      <jar href="VersionedJar.jar" main="true" version="1"/>
+      <property name="jnlp.versionEnabled" value="true"/>
+   </resources>
+   <application-desc main-class="VersionedJar"/>
+</jnlp> 
diff -r c6b48ce8f868 -r fd0e84ce013e tests/reproducers/simple/VersionedJar__V1/srcs/VersionedJar.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/reproducers/simple/VersionedJar__V1/srcs/VersionedJar.java	Wed Jan 30 12:01:11 2013 -0500
@@ -0,0 +1,46 @@
+/* Copyright (C) 2012 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 java.applet.*;
+import java.awt.*;
+import java.lang.reflect.Array;
+import java.lang.reflect.Field;
+
+public class VersionedJar {
+    static public void main(String[] args) {
+        System.out.println("Versioned jar was accessed.");
+    }
+}
\ No newline at end of file
diff -r c6b48ce8f868 -r fd0e84ce013e tests/reproducers/simple/VersionedJar__V1/testcases/VersionedJarTest.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/reproducers/simple/VersionedJar__V1/testcases/VersionedJarTest.java	Wed Jan 30 12:01:11 2013 -0500
@@ -0,0 +1,64 @@
+/* Copyright (C) 2012 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 junit.framework.Assert;
+
+import net.sourceforge.jnlp.ProcessResult;
+import net.sourceforge.jnlp.ServerAccess;
+
+import org.junit.Test;
+
+public class VersionedJarTest {
+
+    private static final ServerAccess server = new ServerAccess();
+    private static final String VERSIONED = "Versioned jar was accessed.";
+    private static final String FAILURE = "net.sourceforge.jnlp.LaunchException";
+
+    @Test
+    public void testDisabledVersionParameter() throws Exception {
+        ProcessResult pr = server.executeJavawsHeadless("/VersionedJarDisabled.jnlp");
+        Assert.assertFalse("Stdout should NOT contain '" + VERSIONED + "', but did.", pr.stdout.contains(VERSIONED));
+        Assert.assertTrue("Stderr should contain '" +FAILURE + "', but did not.", pr.stderr.contains(FAILURE));
+    }
+
+    @Test
+    public void testEnabledVersionParameter() throws Exception {
+        ProcessResult pr = server.executeJavawsHeadless("/VersionedJarEnabled.jnlp");
+        Assert.assertTrue("Stdout should contain '" + VERSIONED + "', but did not.", pr.stdout.contains(VERSIONED));
+        Assert.assertFalse("Stderr should NOT contain '" +FAILURE + "', but did.", pr.stderr.contains(FAILURE));
+    }
+}
\ No newline at end of file



More information about the distro-pkg-dev mailing list