diff --git a/enterprise/micronaut/nbproject/project.xml b/enterprise/micronaut/nbproject/project.xml
index 51121c770ca6..74638ab53ab9 100644
--- a/enterprise/micronaut/nbproject/project.xml
+++ b/enterprise/micronaut/nbproject/project.xml
@@ -74,7 +74,7 @@
2
- 2.156
+ 2.157
diff --git a/enterprise/micronaut/src/org/netbeans/modules/micronaut/maven/MicronautPackagingArtifactsImpl.java b/enterprise/micronaut/src/org/netbeans/modules/micronaut/maven/MicronautPackagingArtifactsImpl.java
index b6d8fda6bb7f..4f28b7f07a95 100644
--- a/enterprise/micronaut/src/org/netbeans/modules/micronaut/maven/MicronautPackagingArtifactsImpl.java
+++ b/enterprise/micronaut/src/org/netbeans/modules/micronaut/maven/MicronautPackagingArtifactsImpl.java
@@ -40,6 +40,8 @@
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectActionContext;
import org.netbeans.modules.maven.api.NbMavenProject;
+import org.netbeans.modules.maven.api.execute.RunConfig;
+import org.netbeans.modules.maven.api.execute.RunUtils;
import org.netbeans.modules.micronaut.AbstractMicronautArtifacts;
import org.netbeans.modules.project.dependency.ArtifactSpec;
import org.netbeans.modules.project.dependency.ProjectArtifactsQuery;
@@ -62,8 +64,13 @@ public class MicronautPackagingArtifactsImpl implements ProjectArtifactsImplemen
/**
* sharedLibrary plugin parameter. Will build a DLL or .so
*/
- public static final String PLUGIN_PARAM_SHAREDLIBRARY = "sharedLibrary";
+ public static final String PLUGIN_PARAM_SHAREDLIBRARY = "sharedLibrary"; // NOI18N
+ /**
+ * Maven goal that does the native-image compilation.
+ */
+ private static final String GOAL_NATIVE_COMPILE = "native:compile"; // NOI18N
+
private static final Set SUPPORTED_ARTIFACT_TYPES = new HashSet<>(Arrays.asList(
MicronautMavenConstants.TYPE_DYNAMIC_LIBRARY, MicronautMavenConstants.TYPE_EXECUTABLE
));
@@ -116,7 +123,8 @@ public boolean computeSupportsChanges(R r) {
return true;
}
- static class R extends AbstractMicronautArtifacts {
+ static class R extends AbstractMicronautArtifacts {
+
private final NbMavenProject mavenProject;
public R(Project project, NbMavenProject mavenProject, ProjectArtifactsQuery.Filter query) {
@@ -137,11 +145,11 @@ protected void detach(PropertyChangeListener l) {
protected boolean accept(PropertyChangeEvent e) {
return NbMavenProject.PROP_PROJECT.equals(e.getPropertyName());
}
-
+
@Override
protected List compute() {
ProjectActionContext buildCtx;
-
+
if (query.getBuildContext() != null) {
if (query.getBuildContext().getProjectAction() == null) {
buildCtx = query.getBuildContext().newDerivedBuilder().forProjectAction(ActionProvider.COMMAND_BUILD).context();
@@ -152,7 +160,7 @@ protected List compute() {
buildCtx = ProjectActionContext.newBuilder(getProject()).forProjectAction(ActionProvider.COMMAND_BUILD).context();
}
if (query.getArtifactType() != null &&
- !SUPPORTED_ARTIFACT_TYPES.contains(query.getArtifactType()) &&
+ !SUPPORTED_ARTIFACT_TYPES.contains(query.getArtifactType()) &&
!ProjectArtifactsQuery.Filter.TYPE_ALL.equals(query.getArtifactType())) {
LOG.log(Level.FINE, "Unsupported type: {0}", query.getArtifactType());
return Collections.emptyList();
@@ -162,7 +170,15 @@ protected List compute() {
return Collections.emptyList();
}
MavenProject model = mavenProject.getEvaluatedProject(buildCtx);
- if (!MicronautMavenConstants.PACKAGING_NATIVE.equals(model.getPackaging())) {
+ boolean explicitGraalvmGoal = false;
+ if (buildCtx.getProjectAction() != null) {
+ RunConfig cfg = RunUtils.createRunConfig(buildCtx.getProjectAction(), getProject(), null, Lookup.EMPTY);
+ if (cfg != null && cfg.getGoals().contains(GOAL_NATIVE_COMPILE)) {
+ LOG.log(Level.FINE, "Go explicit native compilation goal from the action");
+ explicitGraalvmGoal = true;
+ }
+ }
+ if (!explicitGraalvmGoal && !MicronautMavenConstants.PACKAGING_NATIVE.equals(model.getPackaging())) {
LOG.log(Level.FINE, "Unsupported packaging: {0}", model.getPackaging());
return Collections.emptyList();
}
@@ -170,6 +186,8 @@ protected List compute() {
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "Configured build plugins: {0}", model.getBuild().getPlugins());
}
+ boolean foundExecution = false;
+
for (Plugin p : model.getBuild().getPlugins()) {
if (!(MicronautMavenConstants.NATIVE_BUILD_PLUGIN_GROUP.equals(p.getGroupId()) && MicronautMavenConstants.NATIVE_BUILD_PLUGIN_ID.equals(p.getArtifactId()))) {
continue;
@@ -179,32 +197,49 @@ protected List compute() {
if (pe.getGoals().contains(MicronautMavenConstants.PLUGIN_GOAL_COMPILE_NOFORK)) { // NOI18N
Xpp3Dom dom = model.getGoalConfiguration(MicronautMavenConstants.NATIVE_BUILD_PLUGIN_GROUP, MicronautMavenConstants.NATIVE_BUILD_PLUGIN_ID, pe.getId(), MicronautMavenConstants.PLUGIN_GOAL_COMPILE_NOFORK); // NOI18N
if (dom != null) {
- Xpp3Dom imageName = dom.getChild(PLUGIN_PARAM_IMAGENAME); // NOI18N
- Xpp3Dom sharedLib = dom.getChild(PLUGIN_PARAM_SHAREDLIBRARY); // NOI18N
-
- String name;
- if (imageName == null) {
- // project default, but should be injected / interpolated by Maven already.
- name = model.getArtifactId();
- } else {
- name = imageName.getValue();
- }
-
- Path full = Paths.get(model.getBuild().getDirectory()).resolve(name);
- nativeStuff.add(ArtifactSpec.builder(model.getGroupId(), model.getArtifactId(), model.getVersion(), pe)
- .type(sharedLib != null && Boolean.parseBoolean(sharedLib.getValue()) ? MicronautMavenConstants.TYPE_DYNAMIC_LIBRARY : MicronautMavenConstants.TYPE_EXECUTABLE)
- .location(full.toUri())
- .forceLocalFile(FileUtil.toFileObject(full.toFile()))
- .build()
- );
+ LOG.log(Level.FINE, "Found bound execution for goals {0}", pe.getGoals());
+ addNativeExecutable(nativeStuff, model, dom, pe);
+ foundExecution = true;
}
}
}
}
+
+ if (!foundExecution && explicitGraalvmGoal) {
+ LOG.log(Level.FINE, "No bound execution found, but explicit native compilation requested, trying to search for plugin base config");
+ // try to get the configuration from PluginManagement, since the plugin is not directly in the build sequence.
+ Plugin p = model.getPluginManagement().getPluginsAsMap().get(MicronautMavenConstants.NATIVE_BUILD_PLUGIN_GROUP + ":" + MicronautMavenConstants.NATIVE_BUILD_PLUGIN_ID);
+ if (p != null && p.getConfiguration() != null) {
+ LOG.log(Level.FINE, "Found plugin configuration");
+ Xpp3Dom dom = (Xpp3Dom) p.getConfiguration();
+ addNativeExecutable(nativeStuff, model, dom, p);
+ }
+ }
return nativeStuff;
}
+
+ private void addNativeExecutable(List nativeStuff, MavenProject model, Xpp3Dom dom, Object data) {
+ Xpp3Dom imageName = dom.getChild(PLUGIN_PARAM_IMAGENAME); // NOI18N
+ Xpp3Dom sharedLib = dom.getChild(PLUGIN_PARAM_SHAREDLIBRARY); // NOI18N
+
+ String name;
+ if (imageName == null) {
+ // project default, but should be injected / interpolated by Maven already.
+ name = model.getArtifactId();
+ } else {
+ name = imageName.getValue();
+ }
+
+ Path full = Paths.get(model.getBuild().getDirectory()).resolve(name);
+ nativeStuff.add(ArtifactSpec.builder(model.getGroupId(), model.getArtifactId(), model.getVersion(), data)
+ .type(sharedLib != null && Boolean.parseBoolean(sharedLib.getValue()) ? MicronautMavenConstants.TYPE_DYNAMIC_LIBRARY : MicronautMavenConstants.TYPE_EXECUTABLE)
+ .location(full.toUri())
+ .forceLocalFile(FileUtil.toFileObject(full.toFile()))
+ .build()
+ );
+ }
}
-
+
@NbBundle.Messages({
"DN_MicronautArtifacts=Micronaut artifact support"
})
diff --git a/enterprise/micronaut/src/org/netbeans/modules/micronaut/resources/layer.xml b/enterprise/micronaut/src/org/netbeans/modules/micronaut/resources/layer.xml
index 6c8642547844..444894eeb188 100644
--- a/enterprise/micronaut/src/org/netbeans/modules/micronaut/resources/layer.xml
+++ b/enterprise/micronaut/src/org/netbeans/modules/micronaut/resources/layer.xml
@@ -80,6 +80,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/enterprise/micronaut/src/org/netbeans/modules/micronaut/resources/spring-actions-maven.xml b/enterprise/micronaut/src/org/netbeans/modules/micronaut/resources/spring-actions-maven.xml
new file mode 100644
index 000000000000..52f1d71def3b
--- /dev/null
+++ b/enterprise/micronaut/src/org/netbeans/modules/micronaut/resources/spring-actions-maven.xml
@@ -0,0 +1,32 @@
+
+
+
+
+
+ native-build
+
+ *
+
+
+ native:compile
+
+
+ native
+
+
+
diff --git a/java/maven/apichanges.xml b/java/maven/apichanges.xml
index 3b2f5a33aaf1..8854fb3799e7 100644
--- a/java/maven/apichanges.xml
+++ b/java/maven/apichanges.xml
@@ -83,6 +83,21 @@ is the proper place.
+
+
+
+
+
+
+
+
+ Added a
+ RunUtils.createRunConfig() variant that allows to create a RunConfig for a project-defined action.
+ Clients can use this function to use all user customizations that may have been configured for the project action before executing it using
+ RunUtils.run.
+
+
+
LifecycleParticipants can be ignored
diff --git a/java/maven/nbproject/project.properties b/java/maven/nbproject/project.properties
index eaeea266d4d7..40de3798717b 100644
--- a/java/maven/nbproject/project.properties
+++ b/java/maven/nbproject/project.properties
@@ -22,7 +22,7 @@ javadoc.apichanges=${basedir}/apichanges.xml
javadoc.arch=${basedir}/arch.xml
javahelp.hs=maven.hs
extra.module.files=maven-nblib/
-spec.version.base: 2.156
+spec.version.base=2.157.0
# The CPExtender test fails in library processing (not randomly) since NetBeans 8.2; disabling.
test.excludes=**/CPExtenderTest.class
diff --git a/java/maven/src/org/netbeans/modules/maven/api/execute/RunUtils.java b/java/maven/src/org/netbeans/modules/maven/api/execute/RunUtils.java
index a007d79b57da..a8d81316bfcb 100644
--- a/java/maven/src/org/netbeans/modules/maven/api/execute/RunUtils.java
+++ b/java/maven/src/org/netbeans/modules/maven/api/execute/RunUtils.java
@@ -28,11 +28,15 @@
import org.netbeans.api.annotations.common.CheckForNull;
import org.netbeans.api.java.source.BuildArtifactMapper;
import org.netbeans.api.project.Project;
+import org.netbeans.modules.maven.NbMavenProjectImpl;
import org.netbeans.modules.maven.api.Constants;
+import org.netbeans.modules.maven.execute.ActionToGoalUtils;
import org.netbeans.modules.maven.execute.BeanRunConfig;
import org.netbeans.modules.maven.execute.MavenCommandLineExecutor;
import org.netbeans.spi.project.AuxiliaryProperties;
+import org.netbeans.spi.project.ProjectConfiguration;
import org.openide.execution.ExecutorTask;
+import org.openide.util.Lookup;
import org.openide.util.NbBundle;
import org.openide.windows.WindowManager;
@@ -98,6 +102,27 @@ public void run() {
public static ExecutorTask executeMaven(final RunConfig config) {
return MavenCommandLineExecutor.executeMaven(config, null, null);
}
+
+ /**
+ * Creates a {@link RunConfig} for the specified project action. Project configuration to be used can be also specified, which
+ * affects potentially the action's mapping and/or properties. If {@code null} is passed, the current/active configuration is used.
+ * If applied on non-Maven project, the method returns {@code null}, as well as if the requested action does not exist in the project
+ * or its requested (or active) configuration.
+ *
+ * @param action project action name
+ * @param prj the project
+ * @param c the configuration to use, use {@code null} for the active one.
+ * @param lookup lookup that becomes available to the action provider for possible further data / options
+ * @return configured {@link RunConfig} suitable for execution or {@code null} if the project is not maven, or action is unavailable.
+ * @since 2.157
+ */
+ public static RunConfig createRunConfig(String action, Project prj, ProjectConfiguration c, Lookup lookup) {
+ NbMavenProjectImpl impl = prj.getLookup().lookup(NbMavenProjectImpl.class);
+ if (impl == null) {
+ return null;
+ }
+ return ActionToGoalUtils.createRunConfig(action, impl, c, lookup);
+ }
public static RunConfig createRunConfig(File execDir, Project prj, String displayName, List goals)
{