-
Notifications
You must be signed in to change notification settings - Fork 3k
Use existing Maven BootstrapSessionListener to hint Surefire about required JVM parameters #50915
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
Open
Sanne
wants to merge
2
commits into
quarkusio:main
Choose a base branch
from
Sanne:SurefireRequirements
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.
+83
−2
Open
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
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 |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package io.quarkus.maven.components; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Properties; | ||
|
|
||
| import javax.inject.Inject; | ||
| import javax.inject.Named; | ||
|
|
@@ -9,6 +10,9 @@ | |
| import org.apache.maven.AbstractMavenLifecycleParticipant; | ||
| import org.apache.maven.MavenExecutionException; | ||
| import org.apache.maven.execution.MavenSession; | ||
| import org.apache.maven.model.Plugin; | ||
| import org.apache.maven.project.MavenProject; | ||
| import org.codehaus.plexus.logging.Logger; | ||
|
|
||
| import io.quarkus.maven.BuildAnalyticsProvider; | ||
| import io.quarkus.maven.QuarkusBootstrapProvider; | ||
|
|
@@ -39,13 +43,73 @@ public void afterSessionEnd(MavenSession session) throws MavenExecutionException | |
| } | ||
|
|
||
| @Override | ||
| public void afterProjectsRead(MavenSession session) | ||
| throws MavenExecutionException { | ||
| public void afterProjectsRead(MavenSession session) { | ||
| // if this method is called then Maven plugin extensions are enabled | ||
| enabled = true; | ||
|
|
||
| // Now let's automatically apply the required JVM flags to Surefire; | ||
| // bear in mind that this is just a convenience: we can't rely on Maven | ||
| // extensions to be enabled - but when they are, we can make it more useful. | ||
| injectSurefireTuning(session); | ||
| } | ||
|
|
||
| private void injectSurefireTuning(MavenSession session) { | ||
| logDebug(session, "Quarkus Maven extension: injecting JVM args for Surefire"); | ||
| for (MavenProject project : session.getProjects()) { | ||
| if (isQuarkusPluginConfigured(project)) { | ||
| logDebug(session, | ||
| "Found quarkus-maven-plugin in " + project.getArtifactId() + ": injecting Surefire arguments"); | ||
| injectSurefireArgs(session, project); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void injectSurefireArgs(MavenSession session, MavenProject project) { | ||
| Properties props = project.getProperties(); | ||
| String existingArgLine = props.getProperty("argLine", ""); | ||
|
|
||
| String jvmArgsAdd = "--add-opens=java.base/java.lang.invoke=ALL-UNNAMED" | ||
| + " --add-opens=java.base/java.lang=ALL-UNNAMED" | ||
| + " --add-exports=java.base/jdk.internal.module=ALL-UNNAMED"; | ||
| String newArgLine = (existingArgLine.trim().isEmpty()) | ||
| ? jvmArgsAdd | ||
| : jvmArgsAdd + existingArgLine; | ||
|
|
||
| props.setProperty("argLine", newArgLine); | ||
| logDebug(session, "Quarkus Maven extension: injected 'argLine' for Surefire: " + newArgLine); | ||
| } | ||
|
|
||
| private boolean isQuarkusPluginConfigured(MavenProject project) { | ||
| if (project.getBuild() == null || project.getBuild().getPlugins() == null) { | ||
| return false; | ||
| } | ||
| for (Plugin plugin : project.getBuild().getPlugins()) { | ||
| if ("quarkus-maven-plugin".equals(plugin.getArtifactId())) { | ||
| return true; // it's enabled on this project | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public boolean isEnabled() { | ||
| return enabled; | ||
| } | ||
|
|
||
| //Injecting the Logger is apparently error-prone, it might fail in various conditions. | ||
| //It's tempting to rather not log at all, but let's have some output about this situation | ||
| //by falling back to a regular error stream rather than being fully unaware. | ||
| private void logDebug(MavenSession session, String message) { | ||
| Logger logger = null; | ||
| try { | ||
| logger = (Logger) session.getContainer().lookup(Logger.class.getName()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably cache the |
||
| } catch (Exception e) { | ||
| // Let's ignore the message in this case: while we don't want to fail just because | ||
| // we wanted to print some diagnostics message doesn't imply that the message was important. | ||
| // Not logging the message as it might confuse about its severity. | ||
| System.err.println("[Quarkus Maven extension: failed Logger Lookup, debug logging will not be available]"); | ||
| } | ||
| if (logger != null) { | ||
| logger.debug(message); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Once we introduce the
JvmOptionsconfig for test mode, I'd move these toquarkus-coremetadata.