From f468270aa85f983c6e60fca7e08125a374746788 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Fri, 17 Feb 2023 15:02:40 +0100 Subject: [PATCH] support Java 20, which is already in Debian/unstable, closes #1070 --- fdroidserver/common.py | 35 ++++++++++++++++++----------------- tests/common.TestCase | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/fdroidserver/common.py b/fdroidserver/common.py index 1354fd1f..65b19db4 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -197,18 +197,18 @@ def _add_java_paths_to_config(pathlist, thisconfig): j = os.path.basename(d) # the last one found will be the canonical one, so order appropriately for regex in [ - r'^1\.([16-9][0-9]?)\.0\.jdk$', # OSX - r'^jdk1\.([16-9][0-9]?)\.0_[0-9]+.jdk$', # OSX and Oracle tarball - r'^jdk1\.([16-9][0-9]?)\.0_[0-9]+$', # Oracle Windows - r'^jdk([16-9][0-9]?)-openjdk$', # Arch - r'^java-([16-9][0-9]?)-openjdk$', # Arch - r'^java-([16-9][0-9]?)-jdk$', # Arch (oracle) - r'^java-1\.([16-9][0-9]?)\.0-.*$', # RedHat - r'^java-([16-9][0-9]?)-oracle$', # Debian WebUpd8 - r'^jdk-([16-9][0-9]?)-oracle-.*$', # Debian make-jpkg - r'^java-([16-9][0-9]?)-openjdk-[^c][^o][^m].*$', # Debian - r'^oracle-jdk-bin-1\.([17-9][0-9]?).*$', # Gentoo (oracle) - r'^icedtea-bin-([17-9][0-9]?).*$', # Gentoo (openjdk) + r'^1\.([126-9][0-9]?)\.0\.jdk$', # OSX + r'^jdk1\.([126-9][0-9]?)\.0_[0-9]+.jdk$', # OSX and Oracle tarball + r'^jdk1\.([126-9][0-9]?)\.0_[0-9]+$', # Oracle Windows + r'^jdk([126-9][0-9]?)-openjdk$', # Arch + r'^java-([126-9][0-9]?)-openjdk$', # Arch + r'^java-([126-9][0-9]?)-jdk$', # Arch (oracle) + r'^java-1\.([126-9][0-9]?)\.0-.*$', # RedHat + r'^java-([126-9][0-9]?)-oracle$', # Debian WebUpd8 + r'^jdk-([126-9][0-9]?)-oracle-.*$', # Debian make-jpkg + r'^java-([126-9][0-9]?)-openjdk-[^c][^o][^m].*$', # Debian + r'^oracle-jdk-bin-1\.([126-9][0-9]?).*$', # Gentoo (oracle) + r'^icedtea-bin-([126-9][0-9]?).*$', # Gentoo (openjdk) ]: m = re.match(regex, j) if not m: @@ -256,19 +256,20 @@ def fill_config_defaults(thisconfig): if thisconfig['java_paths'] is None: thisconfig['java_paths'] = dict() pathlist = [] - pathlist += glob.glob('/usr/lib/jvm/j*[16-9]*') - pathlist += glob.glob('/usr/java/jdk1.[16-9]*') - pathlist += glob.glob('/System/Library/Java/JavaVirtualMachines/1.[16-9][0-9]?.0.jdk') + pathlist += glob.glob('/usr/lib/jvm/j*[126-9]*') + pathlist += glob.glob('/usr/java/jdk1.[126-9]*') + pathlist += glob.glob('/System/Library/Java/JavaVirtualMachines/1.[126-9][0-9]?.0.jdk') pathlist += glob.glob('/Library/Java/JavaVirtualMachines/*jdk*[0-9]*') pathlist += glob.glob('/opt/oracle-jdk-*1.[0-9]*') pathlist += glob.glob('/opt/icedtea-*[0-9]*') if os.getenv('JAVA_HOME') is not None: pathlist.append(os.getenv('JAVA_HOME')) if os.getenv('PROGRAMFILES') is not None: - pathlist += glob.glob(os.path.join(os.getenv('PROGRAMFILES'), 'Java', 'jdk1.[16-9][0-9]?.*')) + pathlist += glob.glob(os.path.join(os.getenv('PROGRAMFILES'), 'Java', 'jdk1.[126-9][0-9]?.*')) _add_java_paths_to_config(pathlist, thisconfig) - for java_version in ('14', '13', '12', '11', '10', '9', '8', '7'): + for java_version in range(29, 6, -1): + java_version = str(java_version) if java_version not in thisconfig['java_paths']: continue java_home = thisconfig['java_paths'][java_version] diff --git a/tests/common.TestCase b/tests/common.TestCase index 9db6a56f..d2e9adb9 100755 --- a/tests/common.TestCase +++ b/tests/common.TestCase @@ -2262,6 +2262,24 @@ class CommonTest(unittest.TestCase): {'r10e': r10e, 'r17c': ndk_bundle, 'r21e': r21e}, config['ndk_paths'] ) + @unittest.skipIf(not os.path.isdir('/usr/lib/jvm/default-java'), 'uses Debian path') + def test_fill_config_defaults_java(self): + """Test the auto-detection of Java installed in standard paths""" + config = {'sdk_path': self.tmpdir} + fdroidserver.common.fill_config_defaults(config) + java_paths = [] + # use presence of javac to make sure its JDK not just JRE + for f in glob.glob('/usr/lib/jvm/java-*-openjdk-amd64/bin/javac'): + jdk = os.path.dirname(os.path.dirname(f)) + if not os.path.islink(jdk): + java_paths.append(jdk) + self.assertEqual( + len(java_paths), + len(config['java_paths']) + ) + for f in config['java_paths'].values(): + self.assertTrue(f in java_paths) + def test_vcs_git_latesttags(self): tags = [ "1.1.1",