diff --git a/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java b/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java index ed8c48b..4d66e81 100644 --- a/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java +++ b/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java @@ -61,6 +61,9 @@ import java.util.jar.JarEntry; import java.util.jar.JarFile; import java.util.stream.Collectors; +import org.apache.maven.model.Build; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginExecution; /** * Wraps a jar in a Windows executable. @@ -343,6 +346,13 @@ public class Launch4jMojo extends AbstractMojo { @Parameter(defaultValue = "false") private boolean skip = false; + /** + * If set to true, make best effort to skip execution if other plugins are + * generating native image / exe file + */ + @Parameter(defaultValue = "false") + private boolean skipIfNativeImage = false; + private File getJar() { return new File(jar); } @@ -364,6 +374,14 @@ private void doExecute() throws MojoExecutionException { return; } + if (this.skipIfNativeImageParam()) { + getLog().info("skipIfNativeImage enabled. Consider rewriting your pom with profiles"); + getLog().debug("Checking if any other plugin generates a native image / exe file"); + if (isNativeImageGenerationActive()) { + return; + } + } + processRequireAdminRights(); fillSensibleJreDefaults(); @@ -929,9 +947,62 @@ private String getLaunch4jVersion() throws MojoExecutionException { */ private boolean skipExecution() { getLog().debug("skip = " + this.skip); - getLog().debug("skipLaunch4j = " + System.getProperty("skipLaunch4j")); - return skip || System.getProperty("skipLaunch4j") != null; + String sysProp = System.getProperty("skipLaunch4j"); + getLog().debug("skipLaunch4j = " + sysProp); + + return skip || (sysProp != null && !sysProp.equalsIgnoreCase("false")); + } + + private boolean skipIfNativeImageParam() { + getLog().debug("skipIfNativeImage = " + this.skipIfNativeImage); + String sysProp = System.getProperty("skipLaunch4jIfNativeImage"); + getLog().debug("skipLaunch4jIfNativeImage = " + sysProp); + + return skipIfNativeImage || (sysProp != null && !sysProp.equalsIgnoreCase("false")); + } + + private boolean isNativeImageGenerationActive() { + String graalKey = "org.graalvm.buildtools:native-maven-plugin"; + Log log = getLog(); + MavenProject curProj = session.getCurrentProject(); + Build build = curProj.getBuild(); + String packaging = curProj.getPackaging(); + + if (packaging.equalsIgnoreCase("native-image")) { + log.info("Current project's packaging is set to native-image, skipping."); + return true; + } + + // check if there's a Graal plugin and if it has any enabled compile executions + Plugin graalPlugin = build.getPluginsAsMap().get(graalKey); + + // check if 1) there's a goal with "compile", 2) with no skip params, 3) and no skip sysprops + if (graalPlugin != null) { + for (PluginExecution pe : graalPlugin.getExecutions()) { + String goalsStr = pe.getGoals().toString().toLowerCase(); + String confStr = pe.getConfiguration().toString().toLowerCase(); + + if (!goalsStr.contains("compile") || pe.getPhase() == null) { + continue; + } + if (confStr.contains("true") || confStr.contains("true")) + { + continue; + } + String sysProp = System.getProperty("skipNativeBuild"); + if (sysProp != null && !sysProp.equalsIgnoreCase("false")) { + continue; + } + + log.info("There is an active Graal plugin execution, skipping."); + return true; + } + } + + return false; + } + @Override public String toString() {