runtime_java.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import os
  2. import tarfile
  3. import contextlib
  4. from . import runtime
  5. _JAVA_DIR = []
  6. def get_java_path(jdk_dir):
  7. # deprecated - to be deleted
  8. java_paths = (os.path.join(jdk_dir, 'bin', 'java'), os.path.join(jdk_dir, 'bin', 'java.exe'))
  9. for p in java_paths:
  10. if os.path.exists(p):
  11. return p
  12. for f in os.listdir(jdk_dir):
  13. if f.endswith('.tar'):
  14. with contextlib.closing(tarfile.open(os.path.join(jdk_dir, f))) as tf:
  15. tf.extractall(jdk_dir)
  16. for p in java_paths:
  17. if os.path.exists(p):
  18. return p
  19. return ''
  20. def get_build_java_dir(jdk_dir):
  21. versions = [8, 10, 11, 12, 13, 14, 15, 16, 17]
  22. if not _JAVA_DIR:
  23. for version in versions:
  24. jdk_tar_path = os.path.join(jdk_dir, "jdk{}.tar".format(version))
  25. if os.path.exists(jdk_tar_path):
  26. jdk_dir = runtime.build_path('jdk4test')
  27. with contextlib.closing(tarfile.open(jdk_tar_path)) as tf:
  28. tf.extractall(jdk_dir)
  29. assert os.path.exists(os.path.join(jdk_dir, "bin", "java"))
  30. _JAVA_DIR.append(jdk_dir)
  31. break
  32. else:
  33. _JAVA_DIR.append(None)
  34. return _JAVA_DIR[0]