Philip Jenvey  committed 16e5d86

require a min. of Java 6, skip the jvm tests otherwise

  • Participants
  • Parent commits 075b5c1
  • Branches default

Comments (0)

Files changed (2)

File pypy/doc/getting-started-dev.rst

 To translate and run for the CLI you must have the SDK installed: Windows
 users need the `.NET Framework SDK`_, while Linux and Mac users
 can use Mono_.  To translate and run for the JVM you must have a JDK 
-installed (at least version 5) and ``java``/``javac`` on your path.
+installed (at least version 6) and ``java``/``javac`` on your path.
 A slightly larger example

File pypy/translator/jvm/

 Backend for the JVM.
+import os
+import re
+import subprocess
 import sys
-import os
 import py
-import subprocess
 from pypy.tool.udir import udir
 from pypy.translator.translator import TranslationContext
 from pypy.translator.oosupport.genoo import GenOO
 from pypy.translator.jvm.prebuiltnodes import create_interlink_node
 class JvmError(Exception):
     """ Indicates an error occurred in JVM backend """
     jvm = GenJvm(tmpdir, t, EntryPoint(main_graph, True, True))
     return jvm.generate_source()
+_missing_support_programs = None
 def detect_missing_support_programs():
-    def check(exechelper):
-        if py.path.local.sysfind(exechelper) is None:
-            py.test.skip("%s is not on your path" % exechelper)
-    check(getoption('javac'))
-    check(getoption('java'))
+    global _missing_support_programs
+    if _missing_support_programs is not None:
+        if _missing_support_programs:
+            py.test.skip(_missing_support_programs)
+        return
+    def missing(msg):
+        global _missing_support_programs
+        _missing_support_programs = msg
+        py.test.skip(msg)
+    for cmd in 'javac', 'java':
+        if py.path.local.sysfind(getoption(cmd)) is None:
+            missing("%s is not on your path" % cmd)
+    if not _check_java_version(MIN_JAVA_VERSION):
+        missing('Minimum of Java %s required' % MIN_JAVA_VERSION)
+    _missing_support_programs = False
+def _check_java_version(version):
+    """Determine if java meets the specified version"""
+    cmd = [getoption('java'), '-version']
+    with open(os.devnull, 'w') as devnull:
+        stderr = subprocess.Popen(cmd, stdout=devnull,
+                                  stderr=subprocess.PIPE).communicate()[1]
+    search ='[\.0-9]+', stderr)
+    return search and >= version
 class GenJvm(GenOO):