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

feat: honor add-opens/exports from jar manifest #1899

Merged
merged 1 commit into from
Jan 16, 2025

Conversation

maxandersen
Copy link
Collaborator

fixes #1852

make it now trivial to run things like: fish.payara.extras:payara-micro:LATEST and com.google.googlejavaformat:google-java-format:RELEASE

opening in draft as I haven't figured a reliable way to avoid the add opens to be skipped when running on older than java 9.


// TODO: need to NOT add this if running on java 8
// https://openjdk.org/jeps/261#Breaking-encapsulation
String exports = attrs.getValue("Add-Exports");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@quintesse do you see an easy way we at this point know which java version will be used? or are we at the stage we want to add exports/opens as explicit values on project and only add to runtime options when rendering the launch and info ?

Copy link
Contributor

@quintesse quintesse Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, the Java version is determined after the importing of the meta data.

The possible solutions I can think of right now are:

  1. split the importing of metadata into 2 steps, one before and one after the java version has been determined
  2. filter those options after the java version has been determined

(*) The Java version gets determined in the updateProject() call here: https://github.com/jbangdev/jbang/blob/main/src/main/java/dev/jbang/source/ProjectBuilder.java#L287, the ordering of that and the call to importJarMetadata() can not be changed!

So solutions could either be something like:

return importMoreJarMetadata(prj, updateProject(importJarMetadata(prj, ...)));
return filterNonJava8Options(prj, updateProject(importJarMetadata(prj, ...)));

The downside of the second option is perhaps that it would also filter out options that a user has explicitly added (yes, they shouldn't do that on Java 8, but they asked for it so they perhaps expect an error).

Neither of the two options is particularly elegant.

Edit: btw, the filtering could also be done much later in the process, just before using them, like you said

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A third option I thought of is:

  1. simply import all manifest entries into the manifestOptions map that already exists and then do what you suggested "only add to runtime options when rendering the launch and info". (Not entirely sure where the best place for that would be)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

manifestOptions - thought that was used for when writing the end jar?
wouldnt it be probelmatic we copy these in ?

or maybe that is actually more what we actually want...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated code to put the values into manifestOptions and then put it on command line only when generating jar command.

}
String opens = attrs.getValue("Add-Opens");
if (opens != null) {
prj.getManifestAttributes().put("Add-Opens", exports);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. As an alternative , I don't know if it would be useful/better/easier to just blindly copy all options. But that's something we could change at any time in the future.

@quintesse
Copy link
Contributor

LGTM

@maxandersen maxandersen marked this pull request as ready for review January 16, 2025 11:23
@maxandersen maxandersen merged commit 723bdc3 into jbangdev:main Jan 16, 2025
10 checks passed
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

Successfully merging this pull request may close these issues.

Jbang ignores bundled MANIFEST.MF options in file of binary jar.
2 participants