You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by bm...@apache.org on 2024/03/03 12:09:22 UTC

(maven-scripting-plugin) 01/02: [MSCRIPTING-11] Enhanced script context by MavenSession, MojoExecution, PluginDescriptor and Settings

This is an automated email from the ASF dual-hosted git repository.

bmarwell pushed a commit to branch test_bindings_and_romains_script
in repository https://gitbox.apache.org/repos/asf/maven-scripting-plugin.git

commit ac112f5b1137907ea7633a22d72b971be71dd012
Author: XKartalH <xk...@hdpgmbh.de>
AuthorDate: Thu Jan 26 16:14:24 2023 +0100

    [MSCRIPTING-11] Enhanced script context by MavenSession, MojoExecution, PluginDescriptor and Settings
---
 .../org/apache/maven/plugins/scripting/EvalMojo.java | 20 ++++++++++++++++++++
 src/site/markdown/script-context.md                  |  6 +++++-
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/maven/plugins/scripting/EvalMojo.java b/src/main/java/org/apache/maven/plugins/scripting/EvalMojo.java
index ec55f24..63fec56 100644
--- a/src/main/java/org/apache/maven/plugins/scripting/EvalMojo.java
+++ b/src/main/java/org/apache/maven/plugins/scripting/EvalMojo.java
@@ -24,12 +24,16 @@ import javax.script.SimpleBindings;
 
 import java.io.File;
 
+import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecution;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.descriptor.PluginDescriptor;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.project.MavenProject;
+import org.apache.maven.settings.Settings;
 
 /**
  * Evaluate the specified script or scriptFile
@@ -64,14 +68,30 @@ public class EvalMojo extends AbstractMojo {
     @Parameter(defaultValue = "${project}", readonly = true)
     private MavenProject project;
 
+    @Parameter(defaultValue = "${mojoExecution}", readonly = true)
+    MojoExecution mojoExecution;
+
+    @Parameter(defaultValue = "${pluginDescriptor}", readonly = true)
+    private PluginDescriptor pluginDescriptor;
+
+    @Parameter(defaultValue = "${session}", readonly = true)
+    private MavenSession session;
+
+    @Parameter(defaultValue = "${settings}", readonly = true)
+    private Settings settings;
+
     @Override
     public void execute() throws MojoExecutionException, MojoFailureException {
         try {
             AbstractScriptEvaluator execute = constructExecute();
 
             Bindings bindings = new SimpleBindings();
+            bindings.put("session", session);
             bindings.put("project", project);
+            bindings.put("pluginDescriptor", pluginDescriptor);
             bindings.put("log", getLog());
+            bindings.put("mojoExecution", mojoExecution);
+            bindings.put("settings", settings);
 
             Object result = execute.eval(bindings, getLog());
 
diff --git a/src/site/markdown/script-context.md b/src/site/markdown/script-context.md
index 03ed850..5425422 100644
--- a/src/site/markdown/script-context.md
+++ b/src/site/markdown/script-context.md
@@ -20,5 +20,9 @@ under the License.
 
 The following variables are available in the script context
 
+ * `org.apache.maven.execution.MavenSession session`
  * `org.apache.maven.project.MavenProject project`
- * `org.apache.maven.plugin.logging.Log log`
\ No newline at end of file
+ * `org.apache.maven.plugin.descriptor.PluginDescriptor pluginDescriptor`
+ * `org.apache.maven.plugin.logging.Log log`
+ * `org.apache.maven.plugin.MojoExecution mojoExecution`
+ * `org.apache.maven.settings.Settings settings`