# HG changeset patch # User Jiri Vanek # Date 1416942350 -3600 # Node ID 052c53ca776ddddb1c403ab8c7bb2674916101ba # Parent 799b37e9186ae88ec60b11087f5bce78350875e8 Proeprties merged in advance diff -r 799b37e9186a -r 052c53ca776d ChangeLog --- a/ChangeLog Tue Nov 25 19:50:15 2014 +0100 +++ b/ChangeLog Tue Nov 25 20:05:50 2014 +0100 @@ -1,3 +1,15 @@ +2014-11-25 Jiri Vanek + + http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2014-June/028399.html (long thread) + * netx/net/sourceforge/jnlp/Launcher.java: using PropertyDesc.fromString to + add resources. + * netx/net/sourceforge/jnlp/PropertyDesc.java: New method fromString to handle + parsing + * netx/net/sourceforge/jnlp/runtime/Boot.java: is now merging the properties + to main configuration. + * tests/netx/unit/net/sourceforge/jnlp/PropertyDescTest.java: new file. Added + tests for fromString. + 2014-11-25 Jiri Vanek * netx/net/sourceforge/jnlp/Launcher.java: (fromUrl) file from href get diff -r 799b37e9186a -r 052c53ca776d netx/net/sourceforge/jnlp/Launcher.java --- a/netx/net/sourceforge/jnlp/Launcher.java Tue Nov 25 19:50:15 2014 +0100 +++ b/netx/net/sourceforge/jnlp/Launcher.java Tue Nov 25 20:05:50 2014 +0100 @@ -315,18 +315,12 @@ */ private void addProperties(JNLPFile file, String[] props) throws LaunchException { ResourcesDesc resources = file.getResources(); - - for (int i = 0; i < props.length; i++) { - // allows empty property, not sure about validity of that. - int equals = props[i].indexOf("="); - if (equals == -1) { - throw launchError(new LaunchException(R("BBadProp", props[i]))); + for (String prop : props) { + try{ + resources.addResource(PropertyDesc.fromString(prop, R("BBadProp", prop))); + }catch (LaunchException ex){ + throw launchError(ex); } - - String key = props[i].substring(0, equals); - String value = props[i].substring(equals + 1, props[i].length()); - - resources.addResource(new PropertyDesc(key, value)); } } diff -r 799b37e9186a -r 052c53ca776d netx/net/sourceforge/jnlp/PropertyDesc.java --- a/netx/net/sourceforge/jnlp/PropertyDesc.java Tue Nov 25 19:50:15 2014 +0100 +++ b/netx/net/sourceforge/jnlp/PropertyDesc.java Tue Nov 25 20:05:50 2014 +0100 @@ -24,11 +24,30 @@ */ public class PropertyDesc { + /** + * + * @param prop - the property to be parsed from format key=value + * @param errorMEssage - the message for error. We do not wont to bother PropertyDesc with localization overhead + * @return new PropertyDesc based on parsed key=value, though composed from key and value + */ + public static PropertyDesc fromString(String prop, String errorMEssage) throws LaunchException { + // allows empty property, not sure about validity of that. + int equals = prop.indexOf("="); + if (equals == -1) { + throw new LaunchException(errorMEssage); + } + String key = prop.substring(0, equals); + String value = prop.substring(equals + 1, prop.length()); + + return new PropertyDesc(key, value); + + } + /** the key name */ - private String key; + final private String key; /** the value */ - private String value; + final private String value; /** * Creates a property descriptor. diff -r 799b37e9186a -r 052c53ca776d netx/net/sourceforge/jnlp/runtime/Boot.java --- a/netx/net/sourceforge/jnlp/runtime/Boot.java Tue Nov 25 19:50:15 2014 +0100 +++ b/netx/net/sourceforge/jnlp/runtime/Boot.java Tue Nov 25 20:05:50 2014 +0100 @@ -33,6 +33,7 @@ import net.sourceforge.jnlp.LaunchException; import net.sourceforge.jnlp.Launcher; import net.sourceforge.jnlp.ParserSettings; +import net.sourceforge.jnlp.PropertyDesc; import net.sourceforge.jnlp.about.AboutDialog; import net.sourceforge.jnlp.cache.CacheUtil; import net.sourceforge.jnlp.cache.UpdatePolicy; @@ -138,6 +139,17 @@ if (null != getOption("-headless")) { JNLPRuntime.setHeadless(true); } + String[] properties = getOptions("-property"); + if (properties != null) { + for (String prop : properties) { + try { + PropertyDesc propDesc = PropertyDesc.fromString(prop, "Unlocalised error for parsing the property. It must be in fomrat key=value. It is: " + prop); + JNLPRuntime.getConfiguration().setProperty(propDesc.getKey(), propDesc.getValue()); + } catch (LaunchException ex) { + OutputController.getLogger().log(ex); + } + } + } DeploymentConfiguration.move14AndOlderFilesTo15StructureCatched(); diff -r 799b37e9186a -r 052c53ca776d tests/netx/unit/net/sourceforge/jnlp/PropertyDescTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/netx/unit/net/sourceforge/jnlp/PropertyDescTest.java Tue Nov 25 20:05:50 2014 +0100 @@ -0,0 +1,110 @@ +/* + Copyright (C) 2014 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. + */ +package net.sourceforge.jnlp; + +import org.junit.Assert; +import org.junit.Test; + + +public class PropertyDescTest { + + + @Test + public void regularValue() throws LaunchException{ + PropertyDesc p = PropertyDesc.fromString("key=value", "none"); + Assert.assertEquals("key", p.getKey()); + Assert.assertEquals("value", p.getValue()); + } + + @Test + public void correctEmptyValue() throws LaunchException{ + PropertyDesc p = PropertyDesc.fromString("key=", "none"); + Assert.assertEquals("key", p.getKey()); + Assert.assertEquals("", p.getValue()); + } + + @Test + public void strangeEmptyValue() throws LaunchException{ + PropertyDesc p = PropertyDesc.fromString("key= ", "none"); + Assert.assertEquals("key", p.getKey()); + Assert.assertEquals(" ", p.getValue()); + } + + @Test + public void emptyKey() throws LaunchException{ + PropertyDesc p = PropertyDesc.fromString("=value", "none"); + Assert.assertEquals("", p.getKey()); + Assert.assertEquals("value", p.getValue()); + } + + @Test + public void strangeEmptyKey() throws LaunchException{ + PropertyDesc p = PropertyDesc.fromString(" =value", "none"); + Assert.assertEquals(" ", p.getKey()); + Assert.assertEquals("value", p.getValue()); + } + + @Test + public void allEmpty() throws LaunchException{ + PropertyDesc p = PropertyDesc.fromString("=", "none"); + Assert.assertEquals("", p.getKey()); + Assert.assertEquals("", p.getValue()); + } + + @Test + public void allStarngeEmpty() throws LaunchException{ + PropertyDesc p = PropertyDesc.fromString(" = ", "none"); + Assert.assertEquals(" ", p.getKey()); + Assert.assertEquals(" ", p.getValue()); + } + + @Test(expected = LaunchException.class) + public void irregularValue() throws LaunchException{ + PropertyDesc p = PropertyDesc.fromString("key", "none"); + } + + @Test(expected = LaunchException.class) + public void empty() throws LaunchException{ + PropertyDesc p = PropertyDesc.fromString("", "none"); + } + + @Test(expected = NullPointerException.class) + public void nullValue() throws LaunchException{ + PropertyDesc p = PropertyDesc.fromString(null, "none"); + } + +}