Skip to content

Commit 50e0544

Browse files
Fix review feedback
1 parent ac68bce commit 50e0544

File tree

5 files changed

+34
-15
lines changed

5 files changed

+34
-15
lines changed

docs/src/docs/asciidoc/index.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ If you are interested in contributing, please refer to our https://github.com/gr
2828
* Added `quickBuild` configuration option.
2929

3030
==== Maven plugin
31+
* Added support for GraalVM Reachability Metadata Repository.
3132
* Completely reworked Maven plugin (should fix many of previous issues and inconsistencies between main and test builds).
32-
* Added `classesDirectory`, `debug`, `fallback`, `verbose`, `sharedLibrary`, `configurationFileDirectories`, `excludeConfig`, `quickBuild`, and `jvmArgs` properties in order to match those present in the Gradle plugin. +
33+
* Added `classesDirectory`, `debug`, `fallback`, `verbose`, `sharedLibrary`, `configurationFileDirectories`, `excludeConfig`, `quickBuild`, and `jvmArgs` properties in order to match those present in the Gradle plugin.
3334
+
3435
See <<maven-plugin.adoc#,docs>> for more information.
3536
* `useArgFile` is now set to true by default only on Windows.

native-maven-plugin/src/main/java/org/graalvm/buildtools/Utils.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
package org.graalvm.buildtools;
4343

4444
import org.apache.maven.plugin.MojoExecutionException;
45+
import org.codehaus.plexus.logging.Logger;
4546
import org.graalvm.buildtools.utils.SharedConstants;
4647

4748
import java.io.File;
@@ -59,10 +60,9 @@
5960
public abstract class Utils implements SharedConstants {
6061
public static final String NATIVE_TESTS_EXE = "native-tests" + EXECUTABLE_EXTENSION;
6162
public static final String MAVEN_GROUP_ID = "org.graalvm.buildtools";
62-
6363
public static Path nativeImageCache;
6464

65-
public static Path getJavaHomeNativeImage(String javaHomeVariable, Boolean failFast) throws MojoExecutionException {
65+
public static Path getJavaHomeNativeImage(String javaHomeVariable, Boolean failFast, Logger logger) throws MojoExecutionException {
6666
String graalHome = System.getenv(javaHomeVariable);
6767
if (graalHome == null) {
6868
return null;
@@ -98,7 +98,7 @@ public static Path getJavaHomeNativeImage(String javaHomeVariable, Boolean failF
9898
return null;
9999
}
100100
}
101-
System.out.println("Found GraalVM installation from " + javaHomeVariable + " variable.");
101+
logger.info("Found GraalVM installation from " + javaHomeVariable + " variable.");
102102
return graalExe;
103103
}
104104

@@ -110,21 +110,21 @@ public static Path getNativeImageFromPath() {
110110
return exePath.map(path -> path.resolve(NATIVE_IMAGE_EXE)).orElse(null);
111111
}
112112

113-
public static Path getNativeImage() throws MojoExecutionException {
113+
public static Path getNativeImage(Logger logger) throws MojoExecutionException {
114114
if (nativeImageCache != null) {
115115
return nativeImageCache;
116116
}
117117

118-
Path nativeImage = getJavaHomeNativeImage("GRAALVM_HOME", false);
118+
Path nativeImage = getJavaHomeNativeImage("GRAALVM_HOME", false, logger);
119119

120120
if (nativeImage == null) {
121-
nativeImage = getJavaHomeNativeImage("JAVA_HOME", true);
121+
nativeImage = getJavaHomeNativeImage("JAVA_HOME", true, logger);
122122
}
123123

124124
if (nativeImage == null) {
125125
nativeImage = getNativeImageFromPath();
126126
if (nativeImage != null) {
127-
System.out.println("Found GraalVM installation from PATH variable.");
127+
logger.info("Found GraalVM installation from PATH variable.");
128128
}
129129
}
130130

native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/AbstractNativeMojo.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@
8888
*/
8989

9090
public abstract class AbstractNativeMojo extends AbstractMojo {
91-
9291
protected static final String NATIVE_IMAGE_META_INF = "META-INF/native-image";
9392
protected static final String NATIVE_IMAGE_PROPERTIES_FILENAME = "native-image.properties";
9493
protected static final String NATIVE_IMAGE_DRY_RUN = "nativeDryRun";
@@ -219,6 +218,11 @@ protected List<String> getBuildArgs() throws MojoExecutionException {
219218
if (sharedLibrary) {
220219
cliArgs.add("--shared");
221220
}
221+
222+
// Let's allow user to specify environment option to enable quick build.
223+
String quickBuildEnv = System.getenv("GRAALVM_QUICK_BUILD");
224+
quickBuild |= quickBuildEnv != null && (quickBuildEnv.isEmpty() || Boolean.parseBoolean(quickBuildEnv));
225+
222226
if (quickBuild) {
223227
cliArgs.add("-Ob");
224228
}
@@ -375,7 +379,7 @@ protected String getClasspath() throws MojoExecutionException {
375379
}
376380

377381
protected void buildImage() throws MojoExecutionException {
378-
Path nativeImageExecutable = Utils.getNativeImage();
382+
Path nativeImageExecutable = Utils.getNativeImage(logger);
379383

380384
try {
381385
ProcessBuilder processBuilder = new ProcessBuilder(nativeImageExecutable.toString());

native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/MergeAgentFilesMojo.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@
4242

4343
import org.apache.maven.plugin.AbstractMojo;
4444
import org.apache.maven.plugin.MojoExecutionException;
45+
import org.apache.maven.plugins.annotations.Component;
4546
import org.apache.maven.plugins.annotations.LifecyclePhase;
4647
import org.apache.maven.plugins.annotations.Mojo;
4748
import org.apache.maven.plugins.annotations.Parameter;
4849
import org.apache.maven.project.MavenProject;
50+
import org.codehaus.plexus.logging.Logger;
4951
import org.codehaus.plexus.util.FileUtils;
5052
import org.graalvm.buildtools.Utils;
5153
import org.graalvm.buildtools.utils.NativeImageUtils;
@@ -73,12 +75,16 @@ public class MergeAgentFilesMojo extends AbstractMojo {
7375
@Parameter(property = "native.agent.merge.context", required = true)
7476
protected String context;
7577

78+
@Component
79+
protected Logger logger;
80+
81+
7682
@Override
7783
public void execute() throws MojoExecutionException {
7884
String agentOutputDirectory = agentOutputDirectoryFor(target, NativeExtension.Context.valueOf(context));
7985
File baseDir = new File(agentOutputDirectory);
8086
if (baseDir.exists()) {
81-
Path nativeImageExecutable = Utils.getNativeImage();
87+
Path nativeImageExecutable = Utils.getNativeImage(logger);
8288
File mergerExecutable = tryInstall(nativeImageExecutable);
8389
List<File> sessionDirectories = sessionDirectoriesFrom(baseDir.listFiles()).collect(Collectors.toList());
8490
invokeMerge(mergerExecutable, sessionDirectories, baseDir);

native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/NativeExtension.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,15 @@
4242
package org.graalvm.buildtools.maven;
4343

4444
import org.apache.maven.AbstractMavenLifecycleParticipant;
45-
import org.apache.maven.MavenExecutionException;
4645
import org.apache.maven.execution.MavenSession;
4746
import org.apache.maven.model.Build;
4847
import org.apache.maven.model.Plugin;
4948
import org.apache.maven.model.PluginExecution;
5049
import org.apache.maven.plugin.MojoExecutionException;
5150
import org.apache.maven.project.MavenProject;
5251
import org.codehaus.plexus.component.annotations.Component;
52+
import org.codehaus.plexus.logging.LogEnabled;
53+
import org.codehaus.plexus.logging.Logger;
5354
import org.codehaus.plexus.util.xml.Xpp3Dom;
5455
import org.graalvm.buildtools.Utils;
5556
import org.graalvm.buildtools.utils.SharedConstants;
@@ -66,12 +67,19 @@
6667
* the JUnit Platform test listener and registering the native dependency transparently.
6768
*/
6869
@Component(role = AbstractMavenLifecycleParticipant.class, hint = "native-build-tools")
69-
public class NativeExtension extends AbstractMavenLifecycleParticipant {
70+
public class NativeExtension extends AbstractMavenLifecycleParticipant implements LogEnabled {
7071

7172
private static final String JUNIT_PLATFORM_LISTENERS_UID_TRACKING_ENABLED = "junit.platform.listeners.uid.tracking.enabled";
7273
private static final String JUNIT_PLATFORM_LISTENERS_UID_TRACKING_OUTPUT_DIR = "junit.platform.listeners.uid.tracking.output.dir";
7374
private static final String NATIVEIMAGE_IMAGECODE = "org.graalvm.nativeimage.imagecode";
7475

76+
private Logger logger;
77+
78+
@Override
79+
public void enableLogging(Logger logger) {
80+
this.logger = logger;
81+
}
82+
7583
/**
7684
* Enumeration of execution contexts.
7785
* <p>Enum constants are intentionally lowercase for use as directory names
@@ -106,7 +114,7 @@ static String agentOutputDirectoryFor(String baseDir, Context context) {
106114
}
107115

108116
@Override
109-
public void afterProjectsRead(MavenSession session) throws MavenExecutionException {
117+
public void afterProjectsRead(MavenSession session) {
110118
for (MavenProject project : session.getProjects()) {
111119
Build build = project.getBuild();
112120
withPlugin(build, "native-maven-plugin", nativePlugin -> {
@@ -153,7 +161,7 @@ public void afterProjectsRead(MavenSession session) throws MavenExecutionExcepti
153161
}
154162
Xpp3Dom executable = findOrAppend(config, "executable");
155163
try {
156-
executable.setValue(Utils.getNativeImage().getParent().resolve("java").toString());
164+
executable.setValue(Utils.getNativeImage(logger).getParent().resolve("java").toString());
157165
} catch (MojoExecutionException e) {
158166
throw new RuntimeException(e);
159167
}

0 commit comments

Comments
 (0)