From 0cc781808c42321f2cf70039da331a6deaf0889d Mon Sep 17 00:00:00 2001 From: Lilianne-Blaze <39486911+Lilianne-Blaze@users.noreply.github.com> Date: Sun, 9 Jun 2024 05:35:58 +0200 Subject: [PATCH 1/3] Added skipIfNativeImage parameter --- .../maven/plugins/launch4j/Launch4jMojo.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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..11d3db1 100644 --- a/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java +++ b/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java @@ -343,6 +343,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 +371,10 @@ private void doExecute() throws MojoExecutionException { return; } + if (this.skipIfNativeImage()) { + getLog().debug("Parameter 'skipIfNativeImage' not implemented yet."); + } + processRequireAdminRights(); fillSensibleJreDefaults(); @@ -932,6 +943,14 @@ private boolean skipExecution() { getLog().debug("skipLaunch4j = " + System.getProperty("skipLaunch4j")); return skip || System.getProperty("skipLaunch4j") != null; } + + private boolean skipIfNativeImage() { + getLog().debug("skipIfNativeImage = " + this.skipIfNativeImage); + String sysProp = System.getProperty("skipLaunch4jIfNativeImage"); + getLog().debug("skipLaunch4jIfNativeImage = " + sysProp); + + return skipIfNativeImage || (sysProp != null && !sysProp.equalsIgnoreCase("false")); + } @Override public String toString() { From f8d11a79e7f58e45661ec40e7ac518ce47bbc7b7 Mon Sep 17 00:00:00 2001 From: Lilianne-Blaze <39486911+Lilianne-Blaze@users.noreply.github.com> Date: Sun, 9 Jun 2024 05:43:27 +0200 Subject: [PATCH 2/3] Make 'skip' param recognize "false" value too --- .../com/akathist/maven/plugins/launch4j/Launch4jMojo.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 11d3db1..8345897 100644 --- a/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java +++ b/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java @@ -940,8 +940,11 @@ 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 skipIfNativeImage() { From 346c122b199e57151b5a43c9542b3cc3b72ecfc3 Mon Sep 17 00:00:00 2001 From: Lilianne-Blaze <39486911+Lilianne-Blaze@users.noreply.github.com> Date: Sun, 9 Jun 2024 08:25:46 +0200 Subject: [PATCH 3/3] Work in progress --- .../maven/plugins/launch4j/Launch4jMojo.java | 55 ++++++++++++++++++- 1 file changed, 52 insertions(+), 3 deletions(-) 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 8345897..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. @@ -371,8 +374,12 @@ private void doExecute() throws MojoExecutionException { return; } - if (this.skipIfNativeImage()) { - getLog().debug("Parameter 'skipIfNativeImage' not implemented yet."); + 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(); @@ -947,13 +954,55 @@ private boolean skipExecution() { } - private boolean skipIfNativeImage() { + 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() {