From 161ad8065bd4d9a1d9403afc378dc6ea74c58671 Mon Sep 17 00:00:00 2001 From: Adam Domurad Date: Thu, 28 Jun 2012 10:51:30 -0400 Subject: 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. --- netx/net/sourceforge/jnlp/PluginBridge.java | 72 +++++++++++++++++++---------- 1 file changed, 47 insertions(+), 25 deletions(-) (limited to 'netx/net/sourceforge/jnlp/PluginBridge.java') diff --git a/netx/net/sourceforge/jnlp/PluginBridge.java b/netx/net/sourceforge/jnlp/PluginBridge.java index 87f9f06..188a70d 100644 --- a/netx/net/sourceforge/jnlp/PluginBridge.java +++ b/netx/net/sourceforge/jnlp/PluginBridge.java @@ -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 @@ import net.sourceforge.jnlp.runtime.JNLPRuntime; */ public class PluginBridge extends JNLPFile { - String name; - HashSet jars = new HashSet(); - String[] cacheJars = new String[0]; - String[] cacheExJars = new String[0]; - Hashtable atts; + private String name; + private Set jars = new HashSet(); + //Folders can be added to the code-base through the archive tag + private List codeBaseFolders = new ArrayList(); + private String[] cacheJars = new String[0]; + private String[] cacheExJars = new String[0]; + private Map atts; private boolean usePack; private boolean useVersion; private boolean codeBaseLookup; @@ -54,14 +56,32 @@ public class PluginBridge extends JNLPFile { * Creates a new PluginBridge using a default JNLPCreator. */ public PluginBridge(URL codebase, URL documentBase, String jar, String main, - int width, int height, Hashtable atts, + int width, int height, Map 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 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 atts, String uKey, JNLPCreator jnlpCreator) throws Exception { specVersion = new Version("1.0"); @@ -131,19 +151,14 @@ public class PluginBridge extends JNLPFile { 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 @@ public class PluginBridge extends JNLPFile { 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 @@ public class PluginBridge extends JNLPFile { 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; @@ -304,6 +319,13 @@ public class PluginBridge extends JNLPFile { }; } + /** + * Returns the list of folders to be added to the codebase + */ + public List getCodeBaseFolders() { + return new ArrayList(codeBaseFolders); + } + /** * Returns the resources section of the JNLP file for the * specified locale, os, and arch. -- cgit v1.2.3