From 1f2d92fe504ad3491ad98b8485405fb299c767be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lazar=20Mitrovi=C4=87?= Date: Thu, 9 Jun 2022 16:25:11 +0200 Subject: [PATCH] Fix review feedback --- docs/src/docs/asciidoc/index.adoc | 3 ++- .../main/java/org/graalvm/buildtools/Utils.java | 14 +++++++------- .../buildtools/maven/AbstractNativeMojo.java | 11 +++++++++-- .../buildtools/maven/MergeAgentFilesMojo.java | 8 +++++++- .../buildtools/maven/NativeExtension.java | 16 ++++++++++++---- 5 files changed, 37 insertions(+), 15 deletions(-) diff --git a/docs/src/docs/asciidoc/index.adoc b/docs/src/docs/asciidoc/index.adoc index 3d7129042..77781af30 100644 --- a/docs/src/docs/asciidoc/index.adoc +++ b/docs/src/docs/asciidoc/index.adoc @@ -28,8 +28,9 @@ If you are interested in contributing, please refer to our https://github.com/gr * Added `quickBuild` configuration option. ==== Maven plugin +* Added support for GraalVM Reachability Metadata Repository. * Completely reworked Maven plugin (should fix many of previous issues and inconsistencies between main and test builds). -* Added `classesDirectory`, `debug`, `fallback`, `verbose`, `sharedLibrary`, `configurationFileDirectories`, `excludeConfig`, `quickBuild`, and `jvmArgs` properties in order to match those present in the Gradle plugin. + +* Added `classesDirectory`, `debug`, `fallback`, `verbose`, `sharedLibrary`, `configurationFileDirectories`, `excludeConfig`, `quickBuild`, and `jvmArgs` properties in order to match those present in the Gradle plugin. + See <> for more information. * `useArgFile` is now set to true by default only on Windows. diff --git a/native-maven-plugin/src/main/java/org/graalvm/buildtools/Utils.java b/native-maven-plugin/src/main/java/org/graalvm/buildtools/Utils.java index 7536419ba..857aae419 100644 --- a/native-maven-plugin/src/main/java/org/graalvm/buildtools/Utils.java +++ b/native-maven-plugin/src/main/java/org/graalvm/buildtools/Utils.java @@ -42,6 +42,7 @@ package org.graalvm.buildtools; import org.apache.maven.plugin.MojoExecutionException; +import org.codehaus.plexus.logging.Logger; import org.graalvm.buildtools.utils.SharedConstants; import java.io.File; @@ -59,10 +60,9 @@ public abstract class Utils implements SharedConstants { public static final String NATIVE_TESTS_EXE = "native-tests" + EXECUTABLE_EXTENSION; public static final String MAVEN_GROUP_ID = "org.graalvm.buildtools"; - public static Path nativeImageCache; - public static Path getJavaHomeNativeImage(String javaHomeVariable, Boolean failFast) throws MojoExecutionException { + public static Path getJavaHomeNativeImage(String javaHomeVariable, Boolean failFast, Logger logger) throws MojoExecutionException { String graalHome = System.getenv(javaHomeVariable); if (graalHome == null) { return null; @@ -98,7 +98,7 @@ public static Path getJavaHomeNativeImage(String javaHomeVariable, Boolean failF return null; } } - System.out.println("Found GraalVM installation from " + javaHomeVariable + " variable."); + logger.info("Found GraalVM installation from " + javaHomeVariable + " variable."); return graalExe; } @@ -110,21 +110,21 @@ public static Path getNativeImageFromPath() { return exePath.map(path -> path.resolve(NATIVE_IMAGE_EXE)).orElse(null); } - public static Path getNativeImage() throws MojoExecutionException { + public static Path getNativeImage(Logger logger) throws MojoExecutionException { if (nativeImageCache != null) { return nativeImageCache; } - Path nativeImage = getJavaHomeNativeImage("GRAALVM_HOME", false); + Path nativeImage = getJavaHomeNativeImage("GRAALVM_HOME", false, logger); if (nativeImage == null) { - nativeImage = getJavaHomeNativeImage("JAVA_HOME", true); + nativeImage = getJavaHomeNativeImage("JAVA_HOME", true, logger); } if (nativeImage == null) { nativeImage = getNativeImageFromPath(); if (nativeImage != null) { - System.out.println("Found GraalVM installation from PATH variable."); + logger.info("Found GraalVM installation from PATH variable."); } } diff --git a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/AbstractNativeMojo.java b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/AbstractNativeMojo.java index 4abdc56c6..c2730ba30 100644 --- a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/AbstractNativeMojo.java +++ b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/AbstractNativeMojo.java @@ -88,7 +88,6 @@ */ public abstract class AbstractNativeMojo extends AbstractMojo { - protected static final String NATIVE_IMAGE_META_INF = "META-INF/native-image"; protected static final String NATIVE_IMAGE_PROPERTIES_FILENAME = "native-image.properties"; protected static final String NATIVE_IMAGE_DRY_RUN = "nativeDryRun"; @@ -219,6 +218,14 @@ protected List getBuildArgs() throws MojoExecutionException { if (sharedLibrary) { cliArgs.add("--shared"); } + + // Let's allow user to specify environment option to toggle quick build. + String quickBuildEnv = System.getenv("GRAALVM_QUICK_BUILD"); + if (quickBuildEnv != null) { + logger.info("Quick build environment variable is set."); + quickBuild = quickBuildEnv.isEmpty() || Boolean.parseBoolean(quickBuildEnv); + } + if (quickBuild) { cliArgs.add("-Ob"); } @@ -375,7 +382,7 @@ protected String getClasspath() throws MojoExecutionException { } protected void buildImage() throws MojoExecutionException { - Path nativeImageExecutable = Utils.getNativeImage(); + Path nativeImageExecutable = Utils.getNativeImage(logger); try { ProcessBuilder processBuilder = new ProcessBuilder(nativeImageExecutable.toString()); diff --git a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/MergeAgentFilesMojo.java b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/MergeAgentFilesMojo.java index a8aba158b..ad4707015 100644 --- a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/MergeAgentFilesMojo.java +++ b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/MergeAgentFilesMojo.java @@ -42,10 +42,12 @@ import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.FileUtils; import org.graalvm.buildtools.Utils; import org.graalvm.buildtools.utils.NativeImageUtils; @@ -73,12 +75,16 @@ public class MergeAgentFilesMojo extends AbstractMojo { @Parameter(property = "native.agent.merge.context", required = true) protected String context; + @Component + protected Logger logger; + + @Override public void execute() throws MojoExecutionException { String agentOutputDirectory = agentOutputDirectoryFor(target, NativeExtension.Context.valueOf(context)); File baseDir = new File(agentOutputDirectory); if (baseDir.exists()) { - Path nativeImageExecutable = Utils.getNativeImage(); + Path nativeImageExecutable = Utils.getNativeImage(logger); File mergerExecutable = tryInstall(nativeImageExecutable); List sessionDirectories = sessionDirectoriesFrom(baseDir.listFiles()).collect(Collectors.toList()); invokeMerge(mergerExecutable, sessionDirectories, baseDir); diff --git a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/NativeExtension.java b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/NativeExtension.java index 68ed32b57..1caf2a3d0 100644 --- a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/NativeExtension.java +++ b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/NativeExtension.java @@ -42,7 +42,6 @@ package org.graalvm.buildtools.maven; import org.apache.maven.AbstractMavenLifecycleParticipant; -import org.apache.maven.MavenExecutionException; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Build; import org.apache.maven.model.Plugin; @@ -50,6 +49,8 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.logging.LogEnabled; +import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.xml.Xpp3Dom; import org.graalvm.buildtools.Utils; import org.graalvm.buildtools.utils.SharedConstants; @@ -66,12 +67,19 @@ * the JUnit Platform test listener and registering the native dependency transparently. */ @Component(role = AbstractMavenLifecycleParticipant.class, hint = "native-build-tools") -public class NativeExtension extends AbstractMavenLifecycleParticipant { +public class NativeExtension extends AbstractMavenLifecycleParticipant implements LogEnabled { private static final String JUNIT_PLATFORM_LISTENERS_UID_TRACKING_ENABLED = "junit.platform.listeners.uid.tracking.enabled"; private static final String JUNIT_PLATFORM_LISTENERS_UID_TRACKING_OUTPUT_DIR = "junit.platform.listeners.uid.tracking.output.dir"; private static final String NATIVEIMAGE_IMAGECODE = "org.graalvm.nativeimage.imagecode"; + private Logger logger; + + @Override + public void enableLogging(Logger logger) { + this.logger = logger; + } + /** * Enumeration of execution contexts. *

Enum constants are intentionally lowercase for use as directory names @@ -106,7 +114,7 @@ static String agentOutputDirectoryFor(String baseDir, Context context) { } @Override - public void afterProjectsRead(MavenSession session) throws MavenExecutionException { + public void afterProjectsRead(MavenSession session) { for (MavenProject project : session.getProjects()) { Build build = project.getBuild(); withPlugin(build, "native-maven-plugin", nativePlugin -> { @@ -153,7 +161,7 @@ public void afterProjectsRead(MavenSession session) throws MavenExecutionExcepti } Xpp3Dom executable = findOrAppend(config, "executable"); try { - executable.setValue(Utils.getNativeImage().getParent().resolve("java").toString()); + executable.setValue(Utils.getNativeImage(logger).getParent().resolve("java").toString()); } catch (MojoExecutionException e) { throw new RuntimeException(e); }