_darwin.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #*****************************************************************************
  2. # Copyright 2004-2008 Steve Menard
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. #*****************************************************************************
  17. # Reuse the Linux code
  18. from ._linux import LinuxJVMFinder
  19. # ------------------------------------------------------------------------------
  20. class DarwinJVMFinder(LinuxJVMFinder):
  21. """
  22. Mac OS X JVM library finder class
  23. """
  24. def __init__(self):
  25. """
  26. Sets up members
  27. """
  28. # Call the parent constructor
  29. LinuxJVMFinder.__init__(self)
  30. # Library file name
  31. self._libfile = "libjvm.dylib"
  32. self._methods = list(self._methods)
  33. self._methods.append(self._pre_vm7_path)
  34. self._methods.append(self._javahome_binary)
  35. # Predefined locations
  36. self._locations = ('/Library/Java/JavaVirtualMachines',)
  37. def _pre_vm7_path(self):
  38. """
  39. Returns the previous constant JVM library path:
  40. '/System/Library/Frameworks/JavaVM.framework/JavaVM'
  41. """
  42. return '/System/Library/Frameworks/JavaVM.framework/JavaVM'
  43. def _javahome_binary(self):
  44. """
  45. for osx > 10.5 we have the nice util /usr/libexec/java_home available. Invoke it and
  46. return its output. It seems this tool has been removed in osx 10.9.
  47. """
  48. import platform
  49. import subprocess
  50. from distutils.version import StrictVersion
  51. current = StrictVersion(platform.mac_ver()[0][:4])
  52. if current >= StrictVersion('10.6') and current < StrictVersion('10.9'):
  53. if hasattr(subprocess, 'check_output'):
  54. java_home = subprocess.check_output(['/usr/libexec/java_home']).strip()
  55. else:
  56. java_home = subprocess.Popen(['/usr/libexec/java_home'], stdout=subprocess.PIPE).communicate()[0]
  57. return java_home
  58. # ------------------------------------------------------------------------------
  59. # Alias
  60. JVMFinder = DarwinJVMFinder