Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ public abstract class QuarkusBootstrapMojo extends AbstractMojo {

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
hintEnableExtensions();
if (!beforeExecute()) {
return;
}
Expand All @@ -199,6 +200,22 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
}

private void hintEnableExtensions() {
if (!bootstrapSessionListener.isEnabled()) {
super.getLog().warn("The Maven extensions for the Quarkus Maven plugin are not enabled for this build. " +
"We recommend enabling this, so that the plugin can verify essential build settings have been configured as required. "
+
"Please enable by adding \"<extensions>true</extensions>\" in your quarkus-maven-plugin declaration; it should look like:\n"
+
"\n\t<plugin>\n" +
"\t\t<groupId>${quarkus.platform.group-id}</groupId>\n" +
"\t\t<artifactId>quarkus-maven-plugin</artifactId>\n" +
"\t\t<version>${quarkus.platform.version}</version>\n" +
"\t\t<extensions>true</extensions> <!-- THIS ONE -->\n" +
"\t\t...\n");
}
}

@Override
public void setLog(Log log) {
super.setLog(log);
Expand Down
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;
Expand All @@ -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;
Expand Down Expand Up @@ -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";
Copy link
Member

Choose a reason for hiding this comment

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

Once we introduce the JvmOptions config for test mode, I'd move these to quarkus-core metadata.

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());
Copy link
Member

Choose a reason for hiding this comment

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

We should probably cache the logger just to avoid the lookup on every invocation.

} 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);
}
}
}
Loading