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

[FEATURE] Expose Public API for Running Delombok #3642

Open
EarthCitizen opened this issue Mar 27, 2024 · 9 comments
Open

[FEATURE] Expose Public API for Running Delombok #3642

EarthCitizen opened this issue Mar 27, 2024 · 9 comments

Comments

@EarthCitizen
Copy link

EarthCitizen commented Mar 27, 2024

I have a situation in which I need to generate Java source files that are based on files in a Java sources JAR. The issue is that this source code has Lombok annotations. I need to delombok the files in the sources JAR before I process them. I need to use Lombok API to do the delombok-ing myself programmatically.

From what I have been able to find so far, the only way to call delombok is by staring a new JVM process that is executing the Lombok JAR, passing it command line arguments. This is extremely inefficient. Basically treating the JAR as an RPC.

What is needed is to expose a public API to call the delombok functionality.

If there is already a way to do this, I have not found it. All of the related classes I have found to do this are package private.

UPDATE:

I see that the repository has these files, but they are not included in the JAR:

lombok-1.18.32/src/delombok/lombok/delombok/Delombok.java
lombok-1.18.32/src/delombok/lombok/delombok/DelombokApp.java
lombok-1.18.32/src/delombok/lombok/delombok/DelombokResult.java
@Rawi01
Copy link
Collaborator

Rawi01 commented Mar 28, 2024

The Delombok class is included in the jar. To get an idea of how to use it you can check out the lombok maven plugin.

@Rawi01 Rawi01 closed this as completed Mar 28, 2024
@EarthCitizen
Copy link
Author

EarthCitizen commented Mar 28, 2024

@Rawi01

Below is a listing of the files in the lombok-1.18.32.jar. That class is not present. Should I be using a different JAR or is it a mistake that it is not included?

$ unzip -l lombok-1.18.32.jar | grep class | grep -i delombok
     6870  03-20-2024 01:13   lombok/delombok/ant/Tasks$Delombok.class
     1387  03-20-2024 01:13   lombok/delombok/ant/Tasks$Format.class
      424  03-20-2024 01:13   lombok/delombok/ant/Tasks.class

$ unzip -l lombok-1.18.32.jar | grep class | grep Delombok   
     6870  03-20-2024 01:13   lombok/delombok/ant/Tasks$Delombok.class

@EarthCitizen
Copy link
Author

EarthCitizen commented Mar 28, 2024

@Rawi01 Can you re-open this ticket? As far as I can understand, I have demonstrated that the files originally mentioned are not in the JAR.

@Rawi01
Copy link
Collaborator

Rawi01 commented Mar 28, 2024

Most class files in the lombok.jar use its own file ending .SCL.lombok instead of .class, thats why it is not listed. Lombok uses a special classloader named shadow class loader (SCL) to load classes.

If you check the link above you will find a copy pasteable example class you can use.

@EarthCitizen
Copy link
Author

@Rawi01

Please see the screenshot below. I have the following dependency: implementation("org.projectlombok:lombok:1.18.32"). If the classes are somehow available, they should simply be importable when having the JAR on the class path. All of the classes we have discussed fail to import when the JAR is on the class path.

The example Maven plugin you have imports this class: lombok.launch.Delombok. That does not work when simply having the JAR on the class path. What I am asking for in the feature request is that the classes for delomboking be available by simple import. Public API.

Please re-open this issue. It is not possible to import the delombok classes by a normal means. It would be very useful if these classes are made available in the JARs public classes. If the answer is that the team does not ever intend to make the delomboking classes publicly available, and they have a reason for that as part of the design, that is totally fine. This is just a request after all. I just don't want to see this issue get closed because of misunderstandings.

image

@janrieke
Copy link
Contributor

The reason why it's shadowed is that Lombok's internal classes must not be found by regular class path scanning, e.g. because they should not show up in your IDE's autocompletion.

@EarthCitizen
Copy link
Author

@janrieke OK. So then my original request is a legitimate new feature request?

@Rawi01 Rawi01 reopened this Mar 29, 2024
@Rawi01
Copy link
Collaborator

Rawi01 commented Mar 29, 2024

The maven plugin uses the same package name and the imported Delombok class is part of the repository. It uses a bunch of reflection calls to load the lombok class and call the required methods.

Lombok is not usually used as a runtime dependency, so there is a limited amount of publicly available API. I have thought about this request again and think that there might be some value in a real public delombok API.

An additional (untested) way to call delombok is to use the public main method (lombok.launch.Main::main) and pass the normal delombok cli arguments .

@EarthCitizen
Copy link
Author

@Rawi01 The lombok.launch.Main class is package private, but as a workaround, I was able to create my own class in my project in the lombok.launch package, that was then able to call lombok.launch.Main with the same parameters as what can be used on the command line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants