Skip to content

Commit

Permalink
[fixes projectlombok#3389] Support multi-release jars in delombok
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawi01 committed Apr 2, 2023
1 parent b80ff39 commit ac05928
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 3 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/ant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

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
1 change: 1 addition & 0 deletions test/manual/moduleBasedMultiProject/runTests
Original file line number Diff line number Diff line change
@@ -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
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/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
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;
}

0 comments on commit ac05928

Please sign in to comment.