Skip to content
Permalink
Browse files

Merge pull request #370 from marscher/add_jvm_path

[jvmfinder] add registry HKLM/JavaSoft/JRE to searched places
  • Loading branch information...
marscher committed Nov 11, 2018
2 parents 580285d + a3e3179 commit 3ce953ae7b35244077249ce650b9acd0a7010d17
Showing with 53 additions and 71 deletions.
  1. +2 −1 .travis.yml
  2. +1 −1 MANIFEST.in
  3. +5 −3 appveyor.yml
  4. +2 −3 appveyor/install.ps1
  5. +5 −5 appveyor/install.sh
  6. +15 −39 jpype/_cygwin.py
  7. +23 −19 jpype/_windows.py
@@ -40,7 +40,8 @@ matrix:
env: NUMPY="--global-option=--disable-numpy"

install:
- pip install . $NUMPY
- python setup.py sdist
- pip install dist/* $NUMPY
- pip install -r test-requirements.txt
- ant -f test/build.xml

@@ -1,4 +1,4 @@
recursive-include native *.h
recursive-include native *.h *.xml *.java
recursive-include examples *
include *.rst doc/* LICENSE
# include everything under test/
@@ -6,7 +6,8 @@ environment:
CMD_IN_ENV: "cmd /E:ON /V:ON /C .\\appveyor\\run_with_env.cmd"
ANT_HOME: "C:\\ProgramData\\chocolatey\\lib\\ant\\apache-ant-1.10.5"
NUMPY_: "numpy x.x"
JAVA_HOME: "C:\\jdk8"
#JAVA_HOME: "C:\\jdk8"
JAVA_HOME: "C:\\Program Files\\Java\\jdk1.8.0"
CINST_OPTS:

matrix:
@@ -72,11 +73,12 @@ install:
# - We will need to figure out how to run nose multiple times on the same run so that
# we can get the result from each of the java version runs.
#
- cinst jdk8 -params 'installdir=C:\\jdk8' %CINST_OPTS%
#- cinst jdk8 -params 'installdir=C:\\jdk8' %CINST_OPTS%

# - cinst jdk7 -params 'installdir=C:\\jdk7'
# - cinst jdk9 -version 9.0.4.11 -params 'installdir=C:\\jdk9'
- cinst ant %CINST_OPTS%
- cinst ant %CINST_OPTS% --ignore-dependencies
- refreshenv

# Add thinges to path
- "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%ANT_HOME%\\bin;%PATH%"
@@ -7,9 +7,8 @@ python.exe -c "import struct; print(struct.calcsize('P') * 8)"
# compiled extensions and are not provided as pre-built wheel packages,
# pip will build them from source using the MSVC compiler matching the
# target Python version and architecture
conda.exe update --all -y
conda.exe install nose setuptools -y
pip.exe install -r "test-requirements.txt" # -r dev-requirements.txt
pip.exe install nose setuptools -r test-requirements.txt
#pip.exe install -r "test-requirements.txt" # -r dev-requirements.txt

ant.exe -f test\\build.xml

@@ -39,14 +39,14 @@ $EASYINSTALL mock

# Check versions
echo "==== Check versions"
"$ANT_HOME"/bin/ant -version
"$ANT_HOME/bin/ant" -version
$PYTHON --version
$JAVA_HOME/bin/java.exe -version
"$JAVA_HOME/bin/java.exe" -version

echo "==== Check architectures"
file -L `which $PYTHON`
file -L $JAVA_HOME/bin/java.exe
file -L `find $JAVA_HOME -name "jvm.dll"`
file -L "$JAVA_HOME/bin/java.exe"
file -L `find "$JAVA_HOME" -name "jvm.dll"`

echo "==== Check modules"
$PYTHON -c 'import pip; print(sorted(["%s==%s" % (i.key, i.version) for i in pip.get_installed_distributions()]))'
@@ -57,7 +57,7 @@ $PYTHON -c "import struct; print(struct.calcsize('P') * 8)"

# Build the test harness
echo "==== Build test"
"$ANT_HOME"/bin/ant -f test/build.xml
"$ANT_HOME/bin/ant" -f test/build.xml

# Install the package
echo "==== Build module"
@@ -16,38 +16,9 @@
#*****************************************************************************

from . import _jvmfinder
from ._jvmfinder import JVMNotSupportedException
import struct as _struct
import sys as _sys

# ------------------------------------------------------------------------------

def _checkJVMArch(jvmPath):
IMAGE_FILE_MACHINE_I386=332
IMAGE_FILE_MACHINE_IA64=512
IMAGE_FILE_MACHINE_AMD64=34404

is64 = _sys.maxsize > 2**32
with open(jvmPath, "rb") as f:
s=f.read(2)
if s!=b"MZ":
raise JVMNotSupportedException("JVM not valid")
else:
f.seek(60)
s=f.read(4)
header_offset=_struct.unpack("<L", s)[0]
f.seek(header_offset+4)
s=f.read(2)
machine=_struct.unpack("<H", s)[0]

if machine==IMAGE_FILE_MACHINE_I386:
if is64:
raise JVMNotSupportedException("JVM mismatch, python is 64 bit and JVM is 32 bit.")
elif machine==IMAGE_FILE_MACHINE_IA64 or machine==IMAGE_FILE_MACHINE_AMD64:
if not is64:
raise JVMNotSupportedException("JVM mismatch, python is 32 bit and JVM is 64 bit.")
else:
raise JVMNotSupportedException("Unable to deterime JVM Type")

class WindowsJVMFinder(_jvmfinder.JVMFinder):
"""
@@ -67,6 +38,7 @@ def __init__(self):
self._methods = (self._get_from_java_home, self._get_from_registry)

def check(self, jvm):
from ._windows import _checkJVMArch
_checkJVMArch(jvm)

def _get_from_registry(self):
@@ -76,16 +48,20 @@ def _get_from_registry(self):
:return: The path found in the registry, or None
"""
try:
jreKey = "/proc/registry/HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java Runtime Environment"
with open(jreKey + "/CurrentVersion") as f:
cv = f.read().split('\x00')
versionKey = jreKey + "/" + cv[0]
from ._windows import reg_keys
for location in reg_keys:
location = location.replace('\\', '/')
jreKey = "/proc/registry/HKEY_LOCAL_MACHINE/{}".format(location)
try:
with open(jreKey + "/CurrentVersion") as f:
cv = f.read().split('\x00')
versionKey = jreKey + "/" + cv[0]

with open(versionKey + "/RunTimeLib") as f:
cv = f.read().split('\x00')
with open(versionKey + "/RunTimeLib") as f:
cv = f.read().split('\x00')

return cv[0]
return cv[0]

except OSError:
return None
except OSError:
pass
return None
@@ -49,6 +49,12 @@ def _checkJVMArch(jvmPath):
else:
raise JVMNotSupportedException("Unable to deterime JVM Type")


reg_keys = [r"SOFTWARE\JavaSoft\Java Runtime Environment",
r"SOFTWARE\JavaSoft\JRE",
]


class WindowsJVMFinder(_jvmfinder.JVMFinder):
"""
Windows JVM library finder class
@@ -65,7 +71,7 @@ def __init__(self):

# Search methods
winreg = self._get_winreg()
if winreg!=None:
if winreg is not None:
self._methods = (self._get_from_java_home, self._get_from_registry)
else:
self._methods = (self._get_from_java_home, )
@@ -97,23 +103,21 @@ def _get_from_registry(self):
:return: The path found in the registry, or None
"""
try:
# Winreg is an optional package in cygwin
winreg = self._get_winreg()
if not winreg:
return None

jreKey = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
r"SOFTWARE\JavaSoft\Java Runtime Environment")
cv = winreg.QueryValueEx(jreKey, "CurrentVersion")
versionKey = winreg.OpenKey(jreKey, cv[0])
winreg.CloseKey(jreKey)

cv = winreg.QueryValueEx(versionKey, "RuntimeLib")
winreg.CloseKey(versionKey)

return cv[0]

except WindowsError:
# Winreg is an optional package in cygwin
winreg = self._get_winreg()
if not winreg:
return None
for location in reg_keys:
try:
jreKey = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, location)
cv = winreg.QueryValueEx(jreKey, "CurrentVersion")
versionKey = winreg.OpenKey(jreKey, cv[0])
winreg.CloseKey(jreKey)

cv = winreg.QueryValueEx(versionKey, "RuntimeLib")
winreg.CloseKey(versionKey)

return cv[0]
except WindowsError:
pass

0 comments on commit 3ce953a

Please sign in to comment.
You can’t perform that action at this time.