Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multi-release jars in delombok #3392

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/ant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,42 @@ 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

- 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 }}/
run: ./runTests

1 change: 1 addition & 0 deletions buildScripts/ivy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<dependency org="org.springframework" name="spring-core" rev="5.3.4" conf="test->master" />
<dependency org="com.fasterxml.jackson.core" name="jackson-databind" rev="2.10.0" conf="test->master" />
<dependency org="com.fasterxml.jackson.core" name="jackson-annotations" rev="2.10.0" conf="test->master" />
<dependency org="org.jetbrains" name="annotations" rev="24.0.1" conf="test->master" />

<!-- build tooling -->
<dependency org="com.hierynomus" name="sshj" rev="0.26.0" conf="buildtools->default" />
Expand Down
15 changes: 12 additions & 3 deletions src/delombok/lombok/delombok/Delombok.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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<String> compilerVersionString = Arrays.asList(Integer.toString(Javac.getJavaCompilerVersion()));
jfm_.handleOption("--multi-release", compilerVersionString.iterator());
}
}

if (Javac.getJavaCompilerVersion() < 9) {
Expand Down Expand Up @@ -827,7 +836,7 @@ public boolean delombok() throws IOException {
}
delegate.close();

return true;
return compiler.errorCount() == 0;
}

private String unpackClasspath(String cp) {
Expand Down
3 changes: 2 additions & 1 deletion test/manual/moduleBasedMultiProject/runTests
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/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
mkdir -p out/projB
Expand Down
1 change: 1 addition & 0 deletions test/manual/multiReleaseJar/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/out
13 changes: 13 additions & 0 deletions test/manual/multiReleaseJar/runTests
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/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

# 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
4 changes: 4 additions & 0 deletions test/manual/multiReleaseJar/src/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module pkg {
requires static org.jetbrains.annotations;
requires static lombok;
}
10 changes: 10 additions & 0 deletions test/manual/multiReleaseJar/src/pkg/MultiReleaseJarTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package pkg;

import lombok.Getter;
import org.jetbrains.annotations.NotNull;

@Getter
public class MultiReleaseJarTest {
@NotNull
private String test;
}