Skip to content

Commit a81a1ee

Browse files
authored
Make WrapperDownloader work for java >= 11 (#15400)
* Try to check the bootstrap script with the lowest supported jdk (11). * Add repo clone on gradleScriptBootstrapCheck. Run remaining jobs only if the boostrap passes. * Don't fail on ./gradlew, capture stderr too. * One more try. * Add the check and inline suppress forbidden apis. * Remove status code check as we can't rely on jdk returning a constant value. * Remove unused status variable. Add timeout. * Tidy. * Allow inner classes to serve as forbidden api suppressors.
1 parent 09979f2 commit a81a1ee

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

.github/workflows/run-checks-gradle-upgrade.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,38 @@ env:
2525
DEVELOCITY_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }}
2626

2727
jobs:
28+
gradleScriptBootstrapCheck:
29+
name: "Check gradle boostrap script sanity on old JVMs."
30+
timeout-minutes: 30
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
34+
with:
35+
distribution: 'temurin'
36+
java-version: 11
37+
java-package: jdk
38+
39+
- name: Checkout repository
40+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
41+
with:
42+
persist-credentials: false
43+
44+
- shell: bash
45+
run: |
46+
set +e
47+
output=$(./gradlew 2>&1)
48+
if [[ "$output" == *"ERROR: java version must be"* ]]; then
49+
echo "Passed."
50+
else
51+
echo "Something is not right: gradlew command returned suspicious output or status code on JDK 11"
52+
echo -e "gradlew output echoed below:\n\n$output\n\n---(end of output)"
53+
exit 1
54+
fi
55+
2856
gradleSanityCheck:
2957
name: "Run tasks (java: ${{ matrix.java-version }}, alt-java: ${{ matrix.uses-alt-java }})"
3058
timeout-minutes: 30
59+
needs: gradleScriptBootstrapCheck
3160

3261
strategy:
3362
matrix:

build-tools/build-infra/src/main/java/org/apache/lucene/gradle/WrapperDownloader.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
import java.io.IOException;
2222
import java.io.InputStream;
2323
import java.io.OutputStream;
24+
import java.lang.annotation.ElementType;
25+
import java.lang.annotation.Retention;
26+
import java.lang.annotation.RetentionPolicy;
27+
import java.lang.annotation.Target;
2428
import java.net.HttpURLConnection;
2529
import java.net.URI;
2630
import java.net.URL;
@@ -41,6 +45,18 @@
4145
* <p>Ensure this class has no dependencies outside of standard java libraries as it's used direct
4246
*/
4347
public class WrapperDownloader {
48+
/**
49+
* Copied to keep the class isolated from any other classes.
50+
*
51+
* @see "https://github.com/apache/lucene/issues/15399"
52+
*/
53+
@Retention(RetentionPolicy.CLASS)
54+
@Target({ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD, ElementType.TYPE})
55+
private @interface SuppressForbidden {
56+
/** A reason for suppressing should always be given. */
57+
String reason();
58+
}
59+
4460
public static void main(String[] args) {
4561
if (args.length != 1) {
4662
System.err.println("Usage: java WrapperDownloader.java <destination>");

build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/ApplyForbiddenApisPlugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ public void apply(Project project) {
6969
.addAll(
7070
List.of("jdk-unsafe", "jdk-deprecated", "jdk-non-portable", "jdk-reflection"));
7171

72-
task.getSuppressAnnotations().add("**.SuppressForbidden");
72+
task.getSuppressAnnotations()
73+
.addAll(List.of("**.SuppressForbidden", "**.*$SuppressForbidden"));
7374

7475
// apply logger restrictions to all modules except Luke.
7576
if (!project.getPath().equals(":lucene:luke")) {

0 commit comments

Comments
 (0)