changeset 1458:289d66e891ce

Fixed issue, when some resources were not used, because of OS was reporting full name. Eg. "Windows 7" where just "windows" was expected * netx/net/sourceforge/jnlp/JNLPFile.java: (stringMatches) now compares only parts before first space (getResources) added brackets behind ifs * tests/netx/unit/net/sourceforge/jnlp/JNLPFileTest.java: added test
author Jiri Vanek <jvanek@redhat.com>
date Fri, 14 Jul 2017 12:34:53 +0200
parents 5f20a0216db3
children dc5771ad1a85
files ChangeLog netx/net/sourceforge/jnlp/JNLPFile.java tests/netx/unit/net/sourceforge/jnlp/JNLPFileTest.java
diffstat 3 files changed, 43 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Jul 12 18:19:47 2017 +0200
+++ b/ChangeLog	Fri Jul 14 12:34:53 2017 +0200
@@ -1,3 +1,10 @@
+2017-07-13  Jiri Vanek <jvanek@redhat.com>
+
+	Fixed issue, when some resources were not used, because of OS was reporting full name. Eg. "Windows 7" where just "windows" was expected
+	* netx/net/sourceforge/jnlp/JNLPFile.java: (stringMatches) now compares only parts before first space
+	(getResources) added brackets behind ifs
+	* tests/netx/unit/net/sourceforge/jnlp/JNLPFileTest.java: added test
+
 2017-07-12  Jiri Vanek <jvanek@redhat.com>
 
 	* netx/net/sourceforge/jnlp/security/dialogs/TemporaryPermissions.java: escaped windows path slash
--- a/netx/net/sourceforge/jnlp/JNLPFile.java	Wed Jul 12 18:19:47 2017 +0200
+++ b/netx/net/sourceforge/jnlp/JNLPFile.java	Fri Jul 14 12:34:53 2017 +0200
@@ -39,6 +39,7 @@
 import net.sourceforge.jnlp.util.ClasspathMatcher;
 import net.sourceforge.jnlp.util.UrlUtils;
 import net.sourceforge.jnlp.util.logging.OutputController;
+import static net.sourceforge.jnlp.runtime.Translator.R;
 
 /**
  * <p>
@@ -562,8 +563,12 @@
                     }
                     if (hasUsableLocale
                             && stringMatches(os, rescDesc.getOS())
-                            && stringMatches(arch, rescDesc.getArch()))
-                        result.addAll(rescDesc.getResources(launchType));
+                            && stringMatches(arch, rescDesc.getArch())) {
+                        List<T> ll = rescDesc.getResources(launchType);
+                        result.addAll(ll);
+                    } else {
+                        //those are skipped
+                    }
                 }
 
                 result.addAll(sharedResources.getResources(launchType));
@@ -774,12 +779,21 @@
      * @return true if prefixStr is a prefix of any strings in
      * available, or if available is empty or null.
      */
-    private boolean stringMatches(String prefixStr, String available[]) {
-        if (available == null || available.length == 0)
+    static boolean stringMatches(String prefixStr, String available[]) {
+        if (available == null || available.length == 0){
             return true;
+        }
 
-        for (String available1 : available) {
-            if (available1 != null && available1.startsWith(prefixStr)) {
+        for (String candidate : available) {
+            String trimmedPrefix = null;
+            if (prefixStr != null) {
+                trimmedPrefix = prefixStr.split("\\s+")[0];
+            }
+            String trimmedCandidate = null;
+            if (candidate != null) {
+                trimmedCandidate = candidate.split("\\s+")[0];
+            }
+            if (trimmedCandidate != null && trimmedCandidate.startsWith(trimmedPrefix)) {
                 return true;
             }
         }
--- a/tests/netx/unit/net/sourceforge/jnlp/JNLPFileTest.java	Wed Jul 12 18:19:47 2017 +0200
+++ b/tests/netx/unit/net/sourceforge/jnlp/JNLPFileTest.java	Fri Jul 14 12:34:53 2017 +0200
@@ -381,4 +381,20 @@
         Assert.assertArrayEquals(new String[]{"a.b.c", "cde"}, JNLPFile.splitEntryPoints("  a.b.c cde    "));
         Assert.assertArrayEquals(new String[]{"a.b.c", "cde"}, JNLPFile.splitEntryPoints("a.b.c         cde    "));
     }
+    
+    @Test
+    public void WindowsWithNameAreRecognized(){
+        boolean r = JNLPFile.stringMatches("Windows", new String[]{"Windows 7"});
+        Assert.assertTrue(r);
+        boolean rr = JNLPFile.stringMatches("Windows", new String[]{"Windows"});
+        Assert.assertTrue(rr);
+        boolean rrr = JNLPFile.stringMatches("Windows 7", new String[]{"Windows"});
+        Assert.assertTrue(rrr);
+        boolean rrrr = JNLPFile.stringMatches("CrapSystem", new String[]{null});
+        Assert.assertFalse(rrrr);
+        boolean rrrrr = JNLPFile.stringMatches("CrapSystem", new String[]{});
+        Assert.assertTrue(rrrrr);
+        boolean rrrrrr = JNLPFile.stringMatches("CrapSystem", null);
+        Assert.assertTrue(rrrrrr);
+    }
 }