From ac0592826687235cea6f34f9c06edc7798bd5937 Mon Sep 17 00:00:00 2001 From: Rawi01 Date: Sun, 2 Apr 2023 14:49:53 +0200 Subject: [PATCH 1/3] [fixes #3389] Support multi-release jars in delombok --- .github/workflows/ant.yml | 22 +++++++++++++++++++ buildScripts/ivy.xml | 1 + src/delombok/lombok/delombok/Delombok.java | 15 ++++++++++--- test/manual/moduleBasedMultiProject/runTests | 1 + test/manual/multiReleaseJar/.gitignore | 1 + test/manual/multiReleaseJar/runTests | 13 +++++++++++ .../multiReleaseJar/src/module-info.java | 4 ++++ .../src/pkg/MultiReleaseJarTest.java | 10 +++++++++ 8 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 test/manual/multiReleaseJar/.gitignore create mode 100755 test/manual/multiReleaseJar/runTests create mode 100644 test/manual/multiReleaseJar/src/module-info.java create mode 100644 test/manual/multiReleaseJar/src/pkg/MultiReleaseJarTest.java diff --git a/.github/workflows/ant.yml b/.github/workflows/ant.yml index 576a3c65ce..f1c7697c2a 100644 --- a/.github/workflows/ant.yml +++ b/.github/workflows/ant.yml @@ -151,3 +151,25 @@ jobs: - name: Compile in container run: docker run --entrypoint="" -v $(pwd)/lombok.jar:/workspace/lombok.jar $IMAGE_NAME /bin/bash -c "cd classpath; ${{ matrix.tool.cmd }}" + + module-tests: + runs-on: ubuntu-latest + needs: build + strategy: + matrix: + jdk: [9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] + dir: [multiReleaseJar, moduleBasedMultiProject] + fail-fast: false + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - uses: actions/download-artifact@v3 + with: + name: lombok.jar + + - name: Run tests + working-directory: ./test/manual/${{ matrix.dir }}/ + run: ./runTests + diff --git a/buildScripts/ivy.xml b/buildScripts/ivy.xml index cb0065e76d..65e065f7c9 100644 --- a/buildScripts/ivy.xml +++ b/buildScripts/ivy.xml @@ -55,6 +55,7 @@ + diff --git a/src/delombok/lombok/delombok/Delombok.java b/src/delombok/lombok/delombok/Delombok.java index e4f1760222..0d26ca57ee 100755 --- a/src/delombok/lombok/delombok/Delombok.java +++ b/src/delombok/lombok/delombok/Delombok.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2019 The Project Lombok Authors. + * Copyright (C) 2009-2023 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -40,6 +40,7 @@ import java.nio.charset.Charset; import java.nio.charset.UnsupportedCharsetException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -323,7 +324,10 @@ public static void main(String[] rawArgs) { } } - delombok.delombok(); + boolean success = delombok.delombok(); + if (!success) { + System.exit(1); + } } catch (Exception e) { if (!args.quiet) { String msg = e.getMessage(); @@ -744,6 +748,11 @@ public boolean delombok() throws IOException { ((BaseFileManager) jfm_).setContext(context); // reinit with options ((BaseFileManager) jfm_).handleOptions(args.getDeferredFileManagerOptions()); } + + if (jfm_.isSupportedOption("--multi-release") == 1) { + List compilerVersionString = Arrays.asList(Integer.toString(Javac.getJavaCompilerVersion())); + jfm_.handleOption("--multi-release", compilerVersionString.iterator()); + } } if (Javac.getJavaCompilerVersion() < 9) { @@ -827,7 +836,7 @@ public boolean delombok() throws IOException { } delegate.close(); - return true; + return compiler.errorCount() == 0; } private String unpackClasspath(String cp) { diff --git a/test/manual/moduleBasedMultiProject/runTests b/test/manual/moduleBasedMultiProject/runTests index 48557b4394..67a0ae224c 100755 --- a/test/manual/moduleBasedMultiProject/runTests +++ b/test/manual/moduleBasedMultiProject/runTests @@ -1,4 +1,5 @@ #!/bin/sh +set -euo pipefail echo 'This will build, module-style, 2 modules with lombok dependencies. If the compilation works without error or warning, lombok is working as designed.' mkdir -p out/projA mkdir -p out/projB diff --git a/test/manual/multiReleaseJar/.gitignore b/test/manual/multiReleaseJar/.gitignore new file mode 100644 index 0000000000..e2e7327cde --- /dev/null +++ b/test/manual/multiReleaseJar/.gitignore @@ -0,0 +1 @@ +/out diff --git a/test/manual/multiReleaseJar/runTests b/test/manual/multiReleaseJar/runTests new file mode 100755 index 0000000000..6809d1fba0 --- /dev/null +++ b/test/manual/multiReleaseJar/runTests @@ -0,0 +1,13 @@ +#!/bin/sh +set -euo pipefail +echo 'This will build a project with a multi release jar dependency. If the compilation works without error or warning, lombok is working as designed.' +mkdir -p out/javac + +# We cannot use the link because javac can infer the module name +JAR=$(realpath ../../../lib/test/org.jetbrains-annotations.jar) + +javac --processor-path ../../../dist/lombok.jar -p ../../../dist/lombok.jar:$JAR -d out/javac src/module-info.java src/pkg/MultiReleaseJarTest.java + +echo Now we try to delombok and see if it works as designed. + +java -jar ../../../dist/lombok.jar delombok --module-path $JAR -d out/delombok src diff --git a/test/manual/multiReleaseJar/src/module-info.java b/test/manual/multiReleaseJar/src/module-info.java new file mode 100644 index 0000000000..d1304437c7 --- /dev/null +++ b/test/manual/multiReleaseJar/src/module-info.java @@ -0,0 +1,4 @@ +module pkg { + requires static org.jetbrains.annotations; + requires static lombok; +} \ No newline at end of file diff --git a/test/manual/multiReleaseJar/src/pkg/MultiReleaseJarTest.java b/test/manual/multiReleaseJar/src/pkg/MultiReleaseJarTest.java new file mode 100644 index 0000000000..7678439672 --- /dev/null +++ b/test/manual/multiReleaseJar/src/pkg/MultiReleaseJarTest.java @@ -0,0 +1,10 @@ +package pkg; + +import lombok.Getter; +import org.jetbrains.annotations.NotNull; + +@Getter +public class MultiReleaseJarTest { + @NotNull + private String test; +} \ No newline at end of file From dbde24f6953a7e4dffa188f72b6ab9943bb9397e Mon Sep 17 00:00:00 2001 From: Rawi01 Date: Sun, 2 Apr 2023 15:07:54 +0200 Subject: [PATCH 2/3] Use bash in test script --- test/manual/moduleBasedMultiProject/runTests | 2 +- test/manual/multiReleaseJar/runTests | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/manual/moduleBasedMultiProject/runTests b/test/manual/moduleBasedMultiProject/runTests index 67a0ae224c..c7976c31b2 100755 --- a/test/manual/moduleBasedMultiProject/runTests +++ b/test/manual/moduleBasedMultiProject/runTests @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -euo pipefail echo 'This will build, module-style, 2 modules with lombok dependencies. If the compilation works without error or warning, lombok is working as designed.' mkdir -p out/projA diff --git a/test/manual/multiReleaseJar/runTests b/test/manual/multiReleaseJar/runTests index 6809d1fba0..273db8bac5 100755 --- a/test/manual/multiReleaseJar/runTests +++ b/test/manual/multiReleaseJar/runTests @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -euo pipefail echo 'This will build a project with a multi release jar dependency. If the compilation works without error or warning, lombok is working as designed.' mkdir -p out/javac From 1235380e9fd35f1850e58e712322d1876ceb6e6f Mon Sep 17 00:00:00 2001 From: Rawi01 Date: Sun, 2 Apr 2023 15:23:37 +0200 Subject: [PATCH 3/3] Update ant.yml --- .github/workflows/ant.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/ant.yml b/.github/workflows/ant.yml index f1c7697c2a..1974a07ad2 100644 --- a/.github/workflows/ant.yml +++ b/.github/workflows/ant.yml @@ -165,9 +165,26 @@ jobs: - name: Checkout uses: actions/checkout@v3 + - name: Set up JDK ${{ matrix.jdk }} + uses: actions/setup-java@v3 + with: + java-version: ${{ matrix.jdk }} + distribution: 'zulu' + - uses: actions/download-artifact@v3 with: name: lombok.jar + path: dist + + - name: Cache dependencies + uses: actions/cache@v3 + with: + path: | + ivyCache + lib + key: ${{ runner.os }}-${{ hashFiles('**/ivy.xml') }} + restore-keys: | + ${{ runner.os }}- - name: Run tests working-directory: ./test/manual/${{ matrix.dir }}/