Bug#1040512: javatools: Please support Java 21

Vladimir Petko vladimir.petko at canonical.com
Fri Jul 7 03:17:04 BST 2023


Package: javatools
Severity: wishlist
Tags: patch
User: ubuntu-devel at lists.ubuntu.com
Usertags: origin-ubuntu mantic ubuntu-patch
X-Debbugs-Cc: vladimir.petko at canonical.com

Dear Maintainer,

Java 21 retires release level 7 and requires release level 8. This patch allows
to set release level to 8 if Java is 21 or later.

Changes:
  * jh_build: check Java version to set the minimum release level.
  * d/control: javahelper now depends on jarwrapper to check Java version.
  * d/rules: use release level 8.


Thanks for considering the patch.


-- System Information:
Debian Release: bookworm/sid
  APT prefers lunar-updates
  APT policy: (500, 'lunar-updates'), (500, 'lunar-security'), (500, 'lunar'), (100, 'lunar-backports')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 6.2.0-24-generic (SMP w/32 CPU threads; PREEMPT)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE=en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
-------------- next part --------------
diff -Nru javatools-0.78/debian/control javatools-0.78ubuntu1/debian/control
--- javatools-0.78/debian/control	2021-02-05 00:05:53.000000000 +1300
+++ javatools-0.78ubuntu1/debian/control	2023-05-04 19:27:54.000000000 +1200
@@ -36,6 +36,7 @@
 Package: javahelper
 Architecture: all
 Depends:
+ jarwrapper,
  bsdextrautils | bsdmainutils,
  dctrl-tools,
  debhelper-compat (= 13),
diff -Nru javatools-0.78/debian/rules javatools-0.78ubuntu1/debian/rules
--- javatools-0.78/debian/rules	2021-02-05 00:05:53.000000000 +1300
+++ javatools-0.78ubuntu1/debian/rules	2023-05-04 19:27:54.000000000 +1200
@@ -14,7 +14,7 @@
 
 override_dh_auto_build: jh_lib.sh
 	mkdir -p target/classes
-	javac -d target/classes -source 7 -target 7 src/main/java/org/debian/javatools/CheckProperty.java
+	javac -d target/classes -source 8 -target 8 src/main/java/org/debian/javatools/*.java
 	jar -cvf target/javatools.jar -C target/classes/ .
 
 	mkdir tmp tmp.jarwrapper
diff -Nru javatools-0.78/jh_build javatools-0.78ubuntu1/jh_build
--- javatools-0.78/jh_build	2021-02-05 00:07:26.000000000 +1300
+++ javatools-0.78ubuntu1/jh_build	2023-05-04 19:27:54.000000000 +1200
@@ -10,9 +10,7 @@
 use warnings;
 use Cwd qw(realpath);
 use List::Util qw(any);
-
-# Value to pass to -source/-target by default
-use constant DEFAULT_JAVA_RELEASE => '1.7';
+use File::Temp qw(tempfile);
 
 use Debian::Debhelper::Dh_Lib;
 use Debian::Javahelper::Java qw(write_manifest_fd);
@@ -115,7 +113,7 @@
 my @JH_JAR_EXTRA;
 my $build_javadoc = 1;
 my (@javac_opts, @javadoc_opts, $main_class, $do_clean);
-my (@JAVAC, @JAVADOC, @JAR, @builds);
+my (@JAVAC, @JAVA, @JAVADOC, @JAR, @builds);
 
 $CLASSPATH =~ tr/:/ /;
 @JH_JAR_EXTRA = split(' ', $ENV{'JH_JAR_EXTRA'}) if defined $ENV{'JH_JAR_EXTRA'};
@@ -150,6 +148,17 @@
 	exit(0);
 }
 
+# Value to pass to -source/-target by default
+sub get_min_release {
+	if (doit_noerror(@JAVA, "-cp", "/usr/share/java/javatools.jar", "org.debian.javatools.CheckIntProperty", "java.specification.version", "gte", "21")) {
+		warning('Java machine does not support --release 7, using --release 8');
+		return "8";
+	}
+	# when the specification version is less than 21 or an error occured
+	# default to 7
+	return "7";
+}
+
 sub _has_java_option {
 	my ($opt_ref, $option_name) = @_;
 	for my $arg (@{$opt_ref}) {
@@ -171,27 +180,6 @@
 	return;
 }
 
-# Use ISO8859-1 as the default encoding to avoid unmappable character errors
-_default_java_option(\@javac_opts, '-encoding', 'ISO8859-1');
-_default_java_option(\@javadoc_opts, '-encoding', 'ISO8859-1');
-
-if (not _has_java_option(\@javac_opts, '--release') and not _has_java_option(\@javac_opts, '-source')) {
-	# If neither --release nor -source is set, then set -source (and -target if also absent)
-	if (not _has_java_option(\@javac_opts, '-target')) {
-		push(@javac_opts, '-source', DEFAULT_JAVA_RELEASE, '-target', DEFAULT_JAVA_RELEASE);
-	} else {
-		push(@javac_opts, '-source', DEFAULT_JAVA_RELEASE);
-	}
-}
-
-if (not _has_java_option(\@javadoc_opts, '--release')) {
-	_default_java_option(\@javadoc_opts, '-source', DEFAULT_JAVA_RELEASE);
-}
-
-_default_java_option(\@javadoc_opts, '-notimestamp');
-_default_java_option(\@javadoc_opts, '-Xdoclint:none');
-
-
 sub do_build {
 	my ($jarfile, @sources) = @_;
 	my (@srcdirs, @srcfiles);
@@ -275,8 +263,33 @@
 		error('Cannot find any JAVA_HOME: aborting');
 	}
 	@JAVAC = ("${JAVA_HOME}/bin/javac");
+	@JAVA = ("${JAVA_HOME}/bin/java");
+
 	@JAVADOC = ("${JAVA_HOME}/bin/javadoc", '-locale', 'en_US');
 	@JAR = ("${JAVA_HOME}/bin/jar");
+
+	my $default_java_release = get_min_release();
+
+	# Use ISO8859-1 as the default encoding to avoid unmappable character errors
+	_default_java_option(\@javac_opts, '-encoding', 'ISO8859-1');
+	_default_java_option(\@javadoc_opts, '-encoding', 'ISO8859-1');
+
+	if (not _has_java_option(\@javac_opts, '--release') and not _has_java_option(\@javac_opts, '-source')) {
+		# If neither --release nor -source is set, then set -source (and -target if also absent)
+		if (not _has_java_option(\@javac_opts, '-target')) {
+			push(@javac_opts, '-source', $default_java_release, '-target', $default_java_release);
+		} else {
+			push(@javac_opts, '-source', $default_java_release);
+		}
+	}
+
+	if (not _has_java_option(\@javadoc_opts, '--release')) {
+		_default_java_option(\@javadoc_opts, '-source', $default_java_release);
+	}
+
+	_default_java_option(\@javadoc_opts, '-notimestamp');
+	_default_java_option(\@javadoc_opts, '-Xdoclint:none');
+
 	for my $build (@builds) {
 		do_build(@{$build});
 	}
diff -Nru javatools-0.78/src/main/java/org/debian/javatools/CheckIntProperty.java javatools-0.78ubuntu1/src/main/java/org/debian/javatools/CheckIntProperty.java
--- javatools-0.78/src/main/java/org/debian/javatools/CheckIntProperty.java	1970-01-01 12:00:00.000000000 +1200
+++ javatools-0.78ubuntu1/src/main/java/org/debian/javatools/CheckIntProperty.java	2023-05-04 19:27:54.000000000 +1200
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2023 Canonical Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.debian.javatools;
+
+/**
+ * Check the value of a system property from the command line.
+ *
+ * Syntax:
+ *
+ *   java org.debian.javatools.CheckIntProperty <propertyName> <condition> <expectedValue>
+ *
+ *   <condition>:
+ *          - gte - greater or equal 
+ *          - lte - less than or equal
+ *          - gt  - greater than
+ *          - lt  - less than
+ *
+ * The program exits with the status code 0 if the condition is true, and 1 otherwise.
+ */
+public class CheckIntProperty {
+
+    private static boolean check(String operation, int actualValue, int expectedValue){
+        switch (operation) {
+            case "gt": return actualValue > expectedValue;
+            case "gte": return actualValue >= expectedValue;
+            case "lte": return actualValue <= expectedValue;
+            case "lt": return actualValue < expectedValue;
+            default: return false;
+        }
+    }
+
+    private static boolean IsVerbose() {
+        try 
+        {
+            return Integer.parseInt(System.getenv("DH_VERBOSE")) != 0;
+        } 
+        catch (NumberFormatException ex)
+        {
+        }
+        return false;
+    }
+
+    public static void main(String[] args) {
+        boolean verbose = IsVerbose();
+        String propertyName = args[0];
+        String operation = args[1];
+        try {
+            int expectedValue = Integer.parseInt(args[2]);
+            int actualValue = Integer.parseInt(System.getProperty(propertyName));
+            if (check(operation, actualValue, expectedValue)) {
+                if (IsVerbose())
+                    System.out.println("OK: " + propertyName + " " + actualValue + " " + operation + " " + expectedValue);
+                System.exit(0);
+            }
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+        }
+        if (IsVerbose())
+            System.out.println("FAILED: " + propertyName + " " + System.getProperty(propertyName) + " " + operation + " " + args[2]);
+        System.exit(1);
+    }
+}


More information about the pkg-java-maintainers mailing list