Blob Blame History Raw
# HG changeset patch
# User Omair Majid <omajid@redhat.com>
# Date 1458765800 14400
#      Wed Mar 23 16:43:20 2016 -0400
# Node ID e4ce6c525f5363fdb42856ba26d49c2132c075d9
# Parent  0ddda6dcf48b900ece48532c34c7e24719e3241f
Add support for OpenJDK 9

JEP 220 (Modular Run-Time Images) completely changes the layout of the
JDK/JRE files and directories. Specifically:

"The bin directory will contain any command-line launchers defined by
the modules linked into the image."

And:

"A JDK image will [...] no longer contain a jre subdirectory."

This change updates the code to accept a JDK directory without a jre
subdirectory.

diff -r 0ddda6dcf48b -r e4ce6c525f53 ChangeLog
--- a/ChangeLog	Tue Nov 24 14:56:19 2015 +0100
+++ b/ChangeLog	Wed Mar 23 16:43:20 2016 -0400
@@ -1,3 +1,16 @@
+2016-03-23  Omair Majid  <omajid@redhat.com>
+
+	* po/system-switch-java.pot: Regenerated.
+	* switch_java_functions.py (get_java_identifiers)
+	(initialize_alternatives_dictionaries): Accept JDK directories without a
+	'jre' sub-directory.
+	* tests/test_switch_java_functions.py:
+	(test_get_java_identifiers_finds_jre_in_jdk_without_jre_subdir)
+	(test_initialize_alternative_dictionaries_picks_up_java_with_jre_subdir)
+	(test_initialize_alternative_dictionaries_picks_up_java_without_jre_subdir)
+	(test_initialize_alternative_dictionaries_picks_up_jre_without_jre_subdir):
+	New tests.
+
 2015-11-23  Jiri Vanek <jvanek@redhat.com>
 
 	Added support for family flag of future alternatives
diff -r 0ddda6dcf48b -r e4ce6c525f53 switch_java_functions.py
--- a/switch_java_functions.py	Tue Nov 24 14:56:19 2015 +0100
+++ b/switch_java_functions.py	Wed Mar 23 16:43:20 2016 -0400
@@ -160,14 +160,17 @@
 def version_sort_wrapper(i, j):
     return version_sort(i[0],j[0])
 
-def get_java_identifiers():
+def get_java_identifiers(get_alternatives_func=None):
+    if get_alternatives_func is None:
+        get_alternatives_func = get_alternatives
     java_identifiers = []
     # indicates whether each java_identifier is a jdk or jre
     jdks = []
     best_identifier = None
-    alternatives, best = get_alternatives('java')
+    alternatives, best = get_alternatives_func('java')
     jre_expression = re.compile('/usr/lib/jvm/jre-([^/]+)/bin/java')
-    jdk_expression = re.compile('/usr/lib/jvm/java-([^/]+)/jre/bin/java')
+    # Since Java 9, there's no separate jre dir
+    jdk_expression = re.compile('/usr/lib/jvm/java-([^/]+)/(jre/)?bin/java')
     best_identifier_index = -1
     for i in range(len(alternatives)):
         alternative = alternatives[i]
@@ -329,25 +332,37 @@
         raise JavaParseError
     return alternatives, best
 
-def initialize_alternatives_dictionaries(java_identifiers_and_jdks):
+def initialize_alternatives_dictionaries(java_identifiers_and_jdks, path_exists=None):
+    if path_exists is None:
+        path_exists = os.path.exists
     plugin_alternatives = get_plugin_alternatives({}, '')
     javadocdir_alternatives = get_javadocdir_alternatives()
     arch_found = False
     for (java, is_jdk) in java_identifiers_and_jdks:
         vendor, version, arch = get_java_split(java)
         if is_jdk:
-            JAVA[java] = '/usr/lib/jvm/java-' + java + '/jre/bin/java'
+            # since Java 9, there's no separate jre subdir
+            candidate = '/usr/lib/jvm/java-' + java + '/jre/bin/java'
+            if path_exists(candidate):
+                JAVA[java] = candidate
+            else:
+                JAVA[java] = '/usr/lib/jvm/java-' + java + '/bin/java'
         else:
             JAVA[java] = '/usr/lib/jvm/jre-' + java + '/bin/java'
         # Command-to-alternative-name map to set default alternative.
         ALTERNATIVES[JAVA[java]] = java
         if is_jdk:
-            JRE[java] = '/usr/lib/jvm/java-' + java + '/jre'
+            # since Java 9, there's no separate jre subdir
+            candidate = '/usr/lib/jvm/java-' + java + '/jre'
+            if path_exists(candidate):
+                JRE[java] = candidate
+            else:
+                JRE[java] = '/usr/lib/jvm/java-' + java
         else:
             JRE[java] = '/usr/lib/jvm/jre-' + java
         jce = '/usr/lib/jvm-private/java-' + java\
               + '/jce/vanilla/local_policy.jar'
-        if os.path.exists(jce):
+        if path_exists(jce):
             JCE[java] = jce
         else:
             JCE[java] = None