Mercurial > hg > release > icedtea-web-1.6
changeset 1152:f150f0a8cfcc
Added better support for not-matching detected jdk when version forced.
* netx/net/sourceforge/jnlp/JREDesc.java: is using JreVersion instead of pure Version
* netx/net/sourceforge/jnlp/Parser.java: (getJRE) JREDesc is constructed with JreVersion
* netx/net/sourceforge/jnlp/Version.java: made immutable, added specialized inner class, tho handle JRE version.
* /tests/netx/unit/net/sourceforge/jnlp/VersionTest.java: added tests for main cases cornerCases, testMatchesMinus, multiplePossibilities and tests for new class jreVersionTestOk, jreVersionTestFails1, jreVersionTestFails2.
* netx/net/sourceforge/jnlp/resources/Messages.properties: added JRE family of warnings for JreVersion
author | Jiri Vanek <jvanek@redhat.com> |
---|---|
date | Fri, 13 Feb 2015 13:00:45 +0100 |
parents | 6d7f7e0e3829 |
children | 5e348bb0f43d |
files | ChangeLog netx/net/sourceforge/jnlp/JREDesc.java netx/net/sourceforge/jnlp/Parser.java netx/net/sourceforge/jnlp/Version.java netx/net/sourceforge/jnlp/resources/Messages.properties tests/netx/unit/net/sourceforge/jnlp/VersionTest.java |
diffstat | 6 files changed, 132 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Wed Feb 11 09:56:37 2015 +0100 +++ b/ChangeLog Fri Feb 13 13:00:45 2015 +0100 @@ -1,6 +1,19 @@ +2015-02-13 Jiri Vanek <jvanek@redhat.com> + + Added better support for not-matching detected jdk when version forced. + * netx/net/sourceforge/jnlp/JREDesc.java: is using JreVersion instead of pure Version + * netx/net/sourceforge/jnlp/Parser.java: (getJRE) JREDesc is constructed with JreVersion + * netx/net/sourceforge/jnlp/Version.java: made immutable, added specialized + inner class, tho handle JRE version. + * /tests/netx/unit/net/sourceforge/jnlp/VersionTest.java: added tests for + main cases cornerCases, testMatchesMinus, multiplePossibilities and tests for + new class jreVersionTestOk, jreVersionTestFails1, jreVersionTestFails2. + * netx/net/sourceforge/jnlp/resources/Messages.properties: added JRE family + of warnings for JreVersion + 2015-02-11 Jiri Vanek <jvanek@redhat.com> - Saving/Loading of icon made resistent against URLs with invalid/without target + Saving/Loading of icon made resistant against URLs with invalid/without target * netx/net/sourceforge/jnlp/cache/CacheUtil.java: getCachedResource split into getCachedResourceFile and getCachedResourceURL (which is jsut transforming file from getCachedResourceFile to URL)
--- a/netx/net/sourceforge/jnlp/JREDesc.java Wed Feb 11 09:56:37 2015 +0100 +++ b/netx/net/sourceforge/jnlp/JREDesc.java Fri Feb 13 13:00:45 2015 +0100 @@ -34,7 +34,7 @@ private static final Pattern heapPattern= Pattern.compile("\\d+[kmg]?"); /** the platform version or the product version if location is not null */ - final private Version version; + final private Version.JreVersion version; /** the location of a JRE product or null */ final private URL location; @@ -61,7 +61,7 @@ * @param maximumHeapSize maximum head size * @param resources list of ResourceDesc objects */ - public JREDesc(Version version, URL location, + public JREDesc(Version.JreVersion version, URL location, String vmArgs, String initialHeapSize, String maximumHeapSize, List<ResourcesDesc> resources) throws ParseException { this.version = version; @@ -77,7 +77,7 @@ * determine if this version corresponds to a platform or * product version. */ - public Version getVersion() { + public Version.JreVersion getVersion() { return version; }
--- a/netx/net/sourceforge/jnlp/Parser.java Wed Feb 11 09:56:37 2015 +0100 +++ b/netx/net/sourceforge/jnlp/Parser.java Fri Feb 13 13:00:45 2015 +0100 @@ -352,7 +352,7 @@ // require version attribute getRequiredAttribute(node, "version", null); - return new JREDesc(version, location, vmArgs, initialHeap, maxHeap, resources); + return new JREDesc(new Version.JreVersion(version.toString(), strict), location, vmArgs, initialHeap, maxHeap, resources); } /**
--- a/netx/net/sourceforge/jnlp/Version.java Wed Feb 11 09:56:37 2015 +0100 +++ b/netx/net/sourceforge/jnlp/Version.java Fri Feb 13 13:00:45 2015 +0100 @@ -17,6 +17,10 @@ package net.sourceforge.jnlp; import java.util.*; +import javax.swing.JOptionPane; +import net.sourceforge.jnlp.runtime.JNLPRuntime; +import net.sourceforge.jnlp.runtime.Translator; +import net.sourceforge.jnlp.util.logging.OutputController; /** * <p> @@ -39,6 +43,61 @@ * @version $Revision: 1.5 $ */ public class Version { + + /** + * This is special case of version, used only for checking jre version. If + * jre do not match, in strict not-headless mode the dialog with + * confirrmation appears If jre do not match, in strict headless mode the + * exception is thrown If jre match, or non-strict mode is run, then only + * message is printed + * + */ + public static class JreVersion extends Version { + + public static boolean warned = false; + + public JreVersion(String v, boolean strict) { + this(v, strict, JNLPRuntime.isHeadless()); + } + + /* + * for testing purposes + */ + JreVersion(String v, boolean strict, boolean headless) { + super(v); + boolean match = matchesJreVersion(); + if (!match) { + String s = Translator.R("JREversionDontMatch", getJreVersion(), v); + String e = "Strict run is deffined, and your JRE - " + getJreVersion() + " - dont match requested JRE(s) - " + v; + if (strict) { + if (!headless) { + if (!warned) { + int r = JOptionPane.showConfirmDialog(null, s + "\n" + Translator.R("JREContinueDialogSentence2"), Translator.R("JREContinueDialogSentenceTitle"), JOptionPane.YES_NO_OPTION); + if (r == JOptionPane.NO_OPTION) { + throw new RuntimeException(e); + } + warned = true; + } + } else { + throw new RuntimeException(e); + } + } else { + OutputController.getLogger().log(OutputController.Level.WARNING_ALL, s); + } + } else { + OutputController.getLogger().log("good - your JRE - " + getJreVersion() + " - match requested JRE - " + v); + } + } + + public boolean matchesJreVersion() { + return matches(getJreVersion()); + } + + private String getJreVersion() { + return System.getProperty("java.version"); + } + + } // to do: web start does not match versions with a "-" like // "1.4-beta1" using the + modifier, change to mimic that @@ -49,13 +108,13 @@ // "*" and "+" modifiers. /** separates parts of a version string */ - private static String seperators = ".-_"; + private static final String seperators = ".-_"; /** magic key for whether a version part was created due to normalization */ - private static String emptyString = new String("<EMPTY>"); // not intern'ed + private static final String emptyString = new String("<EMPTY>"); // not intern'ed /** contains all the versions matched */ - private String versionString; + private final String versionString; /** * Create a Version object based on a version string (ie,
--- a/netx/net/sourceforge/jnlp/resources/Messages.properties Wed Feb 11 09:56:37 2015 +0100 +++ b/netx/net/sourceforge/jnlp/resources/Messages.properties Fri Feb 13 13:00:45 2015 +0100 @@ -54,6 +54,11 @@ AboutDialogueTabNews=News AboutDialogueTabGPLv2=GPLv2 +# version check minidialogue +JREversionDontMatch=Warning - your JRE - {0} - don't match requested JRE - {1} +JREContinueDialogSentence2=Do you wont to continue in running? +JREContinueDialogSentenceTitle=Incompatible JRE + # missing permissions dialogue MissingPermissionsMainTitle=Application <span color='red'> {0} </span> \ from <span color='red'> {1} </span> is missing the permissions attribute. \
--- a/tests/netx/unit/net/sourceforge/jnlp/VersionTest.java Wed Feb 11 09:56:37 2015 +0100 +++ b/tests/netx/unit/net/sourceforge/jnlp/VersionTest.java Fri Feb 13 13:00:45 2015 +0100 @@ -95,4 +95,51 @@ } + + + @Test + public void cornerCases() { + Assert.assertTrue(new Version("1.5").matches("1.5")); + Assert.assertTrue(new Version("1.5+").matches("1.5")); + Assert.assertTrue(new Version("1.5+").matches("1.6")); + Assert.assertFalse(new Version("1.5+").matches("1.4")); + Assert.assertFalse(new Version("1.5").matches("1.4")); + Assert.assertFalse(new Version("1.5").matches("1.6")); + } + + @Test + public void testMatchesMinus() { + Assert.assertTrue(new Version("1.5-").matches("1.5")); + //this fails, do we need to patch it? + //Assert.assertTrue(new Version("1.5-").matches("1.4")); + //not until somebody complains + Assert.assertFalse(new Version("1.5-").matches("1.6")); + + } + + @Test + public void multiplePossibilities() { + Assert.assertTrue(new Version("1.4 1.5").matches("1.5")); + Assert.assertFalse(new Version("1.3 1.4").matches("1.5")); + } + + @Test + public void jreVersionTestOk() { + //no exception occures + //head support jdk 7+, so this statements should be always true + Version.JreVersion jreVersion = new Version.JreVersion("1.4 1.5+", true, true); + Version.JreVersion jreVersion1 = new Version.JreVersion("1.6+", true, true); + } + + @Test(expected = RuntimeException.class) + public void jreVersionTestFails1() { + //head support jdk 7+, so this statements should be always false + Version.JreVersion jreVersion = new Version.JreVersion("2", true, true); + } + + @Test(expected = RuntimeException.class) + public void jreVersionTestFails2() { + //head support jdk 7+, so this statements should be always false + Version.JreVersion jreVersion = new Version.JreVersion("1.4", true, true); + } }