Gentoo Archives: gentoo-commits

From: "Miroslav Šulc" <fordfrog@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/
Date: Thu, 24 Jun 2021 16:22:09
Message-Id: 1624551719.4419bceb0833e2b9ae045d9392f201ee359a84b7.fordfrog@gentoo
1 commit: 4419bceb0833e2b9ae045d9392f201ee359a84b7
2 Author: Miroslav Šulc <fordfrog <AT> gentoo <DOT> org>
3 AuthorDate: Thu Jun 24 16:21:37 2021 +0000
4 Commit: Miroslav Šulc <fordfrog <AT> gentoo <DOT> org>
5 CommitDate: Thu Jun 24 16:21:59 2021 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=4419bceb
7
8 java-pkg-simple.eclass: added support for module-info.java compilation
9
10 for more info see https://bugs.gentoo.org/796875
11
12 Bug: https://bugs.gentoo.org/796875
13 Signed-off-by: Miroslav Šulc <fordfrog <AT> gentoo.org>
14
15 eclass/java-pkg-simple.eclass | 57 ++++++++++++++++++++++++++++++++++++++++---
16 1 file changed, 53 insertions(+), 4 deletions(-)
17
18 diff --git a/eclass/java-pkg-simple.eclass b/eclass/java-pkg-simple.eclass
19 index 0c3e1af7036..408e1aac44f 100644
20 --- a/eclass/java-pkg-simple.eclass
21 +++ b/eclass/java-pkg-simple.eclass
22 @@ -326,7 +326,7 @@ java-pkg-simple_prepend_resources() {
23 # If USE FLAG 'binary' exists and is set, it will just copy
24 # ${JAVA_BINJAR_FILENAME} to ${S} and skip the rest of src_compile.
25 java-pkg-simple_src_compile() {
26 - local sources=sources.lst classes=target/classes apidoc=target/api
27 + local sources=sources.lst classes=target/classes apidoc=target/api moduleinfo
28
29 # auto generate classpath
30 java-pkg_gen-cp JAVA_GENTOO_CLASSPATH
31 @@ -344,7 +344,14 @@ java-pkg-simple_src_compile() {
32 fi
33
34 # gather sources
35 - find "${JAVA_SRC_DIR[@]}" -name \*.java > ${sources}
36 + # if target < 9, we need to compile module-info.java separately
37 + # as this feature is not supported before Java 9
38 + if [[ java-pkg_get-target -lt 9 ]]; then
39 + find "${JAVA_SRC_DIR[@]}" -name \*.java ! -name module-info.java > ${sources}
40 + moduleinfo=$(find "${JAVA_SRC_DIR[@]}" -name module-info.java)
41 + else
42 + find "${JAVA_SRC_DIR[@]}" -name \*.java > ${sources}
43 + fi
44
45 # create the target directory
46 mkdir -p ${classes} || die "Could not create target directory"
47 @@ -358,6 +365,23 @@ java-pkg-simple_src_compile() {
48 ${classpath:+-classpath ${classpath}} ${JAVAC_ARGS}\
49 @${sources}
50
51 + # handle module-info.java separately as it needs at least JDK 9
52 + if [[ -n ${moduleinfo} ]]; then
53 + if java-pkg_is-vm-version-ge "9" ; then
54 + local tmp_source=${JAVA_PKG_WANT_SOURCE} tmp_target=${JAVA_PKG_WANT_TARGET}
55 +
56 + JAVA_PKG_WANT_SOURCE="9"
57 + JAVA_PKG_WANT_TARGET="9"
58 + ejavac -d ${classes} -encoding ${JAVA_ENCODING} ${JAVAC_ARGS} "${moduleinfo}"
59 +
60 + JAVA_PKG_WANT_SOURCE=${tmp_source}
61 + JAVA_PKG_WANT_TARGET=${tmp_target}
62 + else
63 + ewarn "Need at least JDK 9 to compile module-info.java in src_compile,"
64 + ewarn "see https://bugs.gentoo.org/796875"
65 + fi
66 + fi
67 +
68 # javadoc
69 if has doc ${JAVA_PKG_IUSE} && use doc; then
70 mkdir -p ${apidoc}
71 @@ -422,7 +446,7 @@ java-pkg-simple_src_install() {
72 # It will perform test with frameworks that are defined in
73 # ${JAVA_TESTING_FRAMEWORKS}.
74 java-pkg-simple_src_test() {
75 - local test_sources=test_sources.lst classes=target/test-classes
76 + local test_sources=test_sources.lst classes=target/test-classes moduleinfo
77 local tests_to_run classpath
78
79 # do not continue if the USE FLAG 'test' is explicitly unset
80 @@ -444,13 +468,38 @@ java-pkg-simple_src_test() {
81 java-pkg-simple_prepend_resources ${classes} "${JAVA_TEST_RESOURCE_DIRS[@]}"
82
83 # gathering sources for testing
84 - find "${JAVA_TEST_SRC_DIR[@]}" -name \*.java > ${test_sources}
85 + # if target < 9, we need to compile module-info.java separately
86 + # as this feature is not supported before Java 9
87 + if [[ java-pkg_get-target -lt 9 ]]; then
88 + find "${JAVA_TEST_SRC_DIR[@]}" -name \*.java ! -name module-info.java > ${test_sources}
89 + moduleinfo=$(find "${JAVA_TEST_SRC_DIR[@]}" -name module-info.java)
90 + else
91 + find "${JAVA_TEST_SRC_DIR[@]}" -name \*.java > ${test_sources}
92 + fi
93 +
94
95 # compile
96 [[ -s ${test_sources} ]] && ejavac -d ${classes} ${JAVAC_ARGS} \
97 -encoding ${JAVA_ENCODING} ${classpath:+-classpath ${classpath}} \
98 @${test_sources}
99
100 + # handle module-info.java separately as it needs at least JDK 9
101 + if [[ -n ${moduleinfo} ]]; then
102 + if java-pkg_is-vm-version-ge "9" ; then
103 + local tmp_source=${JAVA_PKG_WANT_SOURCE} tmp_target=${JAVA_PKG_WANT_TARGET}
104 +
105 + JAVA_PKG_WANT_SOURCE="9"
106 + JAVA_PKG_WANT_TARGET="9"
107 + ejavac -d ${classes} -encoding ${JAVA_ENCODING} ${JAVAC_ARGS} "${moduleinfo}"
108 +
109 + JAVA_PKG_WANT_SOURCE=${tmp_source}
110 + JAVA_PKG_WANT_TARGET=${tmp_target}
111 + else
112 + ewarn "Need at least JDK 9 to compile module-info.java in src_test,"
113 + ewarn "see https://bugs.gentoo.org/796875"
114 + fi
115 + fi
116 +
117 # grab a set of tests that testing framework will run
118 tests_to_run=$(find "${classes}" -type f\
119 \( -name "*Test.class"\