-
Notifications
You must be signed in to change notification settings - Fork 3k
POC for a buildItem defining the add-opens needs #49920
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
Draft
Sanne
wants to merge
1
commit into
quarkusio:main
Choose a base branch
from
Sanne:AddOpens
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
core/deployment/src/main/java/io/quarkus/deployment/ResolvedJVMRequirements.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.quarkus.deployment; | ||
|
||
import java.util.List; | ||
import java.util.jar.Attributes; | ||
|
||
import org.jboss.logging.Logger; | ||
|
||
import io.quarkus.builder.item.SimpleBuildItem; | ||
import io.quarkus.deployment.builditem.ModuleOpenBuildItem; | ||
|
||
/** | ||
* Represents requirements and restrictions on the runtime. | ||
* Currently only used to track add-opens requirements; I'd like to eventually | ||
* support tracking, for example, the required JVM version as we start to see | ||
* some extensions having stronger opinions. | ||
* Another use could be, for example, to force enabling experimental features such | ||
* as needing jdk.incubator.vector (which would also inherently bump the minimum | ||
* JVM version). | ||
*/ | ||
public final class ResolvedJVMRequirements extends SimpleBuildItem { | ||
private static final Logger LOG = Logger.getLogger(ResolvedJVMRequirements.class); | ||
private static final Attributes.Name ADD_OPENS_JARATTRIBUTENAME = new Attributes.Name("Add-Opens"); | ||
private List<String> modulesToAddOpens; | ||
|
||
public ResolvedJVMRequirements(List<ModuleOpenBuildItem> addOpens) { | ||
this.modulesToAddOpens = addOpens.stream().map(ModuleOpenBuildItem::moduleName).distinct().sorted().toList(); | ||
Sanne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
public void renderAddOpensElementToJarManifest(Attributes attributes) { | ||
if (!modulesToAddOpens.isEmpty()) { | ||
if (attributes.getValue(ADD_OPENS_JARATTRIBUTENAME) != null) { | ||
LOG.warn( | ||
"An 'Add-Opens' entry was already defined in your MANIFEST.MF or using the property quarkus.package.jar.manifest.attributes.\"Add-Opens\". Quarkus has overwritten this existing entry."); | ||
} | ||
attributes.put(ADD_OPENS_JARATTRIBUTENAME, String.join(" ", modulesToAddOpens)); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
core/deployment/src/main/java/io/quarkus/deployment/builditem/ModuleOpenBuildItem.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.quarkus.deployment.builditem; | ||
|
||
import java.util.Objects; | ||
|
||
import io.quarkus.builder.item.MultiBuildItem; | ||
|
||
/** | ||
* This will generate the equivalent of "--add-opens [module-name]=ALL-UNNAMED" for | ||
* all runners of the generated application. | ||
* It's currently only possible to open a module to ALL-UNNAMED; this restriction is dictated | ||
* by the limitations of the specification of the Jar's manifest format. | ||
*/ | ||
public final class ModuleOpenBuildItem extends MultiBuildItem { | ||
private final String moduleName; | ||
|
||
public ModuleOpenBuildItem(String moduleName) { | ||
this.moduleName = Objects.requireNonNull(moduleName); | ||
} | ||
|
||
public String moduleName() { | ||
return moduleName; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
core/deployment/src/main/java/io/quarkus/deployment/steps/JvmRequirementsBuildStep.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.quarkus.deployment.steps; | ||
|
||
import java.util.List; | ||
|
||
import io.quarkus.deployment.ResolvedJVMRequirements; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.builditem.ModuleOpenBuildItem; | ||
|
||
public class JvmRequirementsBuildStep { | ||
|
||
@BuildStep | ||
ResolvedJVMRequirements resolveJVMRequirements(List<ModuleOpenBuildItem> addOpens) { | ||
return new ResolvedJVMRequirements(addOpens); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be two separate properties. Or maybe a set of packages to open. Plus the destination module as I said earlier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that the Jar's Manifest format doesn't allow to specify a destination module.
We could add it here as a hint for users of the new buildItem that they should specify it - in hope for us to being able to use it better in the future, but I'm concerned that since it won't have any effect there is no way to test that people are specifying the correct values.
Perhaps it's best to not have a misleading API and stick to offer what it can do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're thinking only of what it can do, today, this week. But I already have a parallel branch which modularizes the application fully. I'd rather only maybe have to rework one or two mistakes than have to rework everything. The JAR manifest is an edge case in the greater scheme; it just happens to be the first case we've encountered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok then! Sounds great, I just wasn't sure if you were aware of these limitations - sounds like you are :)