You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2026/09/25 14:58:40 UTC

(maven-invoker-plugin) branch master updated: Warn when a hook or selector script is BeanShell

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

slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-invoker-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new 2c1615b  Warn when a hook or selector script is BeanShell
2c1615b is described below

commit 2c1615b4393e11e7a53d95bc73c33b2c572a571d
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Mon Sep 21 11:30:43 2026 +0200

    Warn when a hook or selector script is BeanShell
    
    BeanShell scripts are deprecated (apache/maven#13207); the plugin now says so
    for every .bsh file it runs, once per file, in its own log and in the build log
    of the IT, and the site examples use Groovy throughout.
---
 src/it/script-context/verify.groovy                |  9 +++++++
 .../maven/plugins/invoker/AbstractInvokerMojo.java | 31 ++++++++++++++++++++++
 .../markdown/examples/pre-post-build-script.md.vm  |  4 +--
 src/site/markdown/examples/selector-scripts.md.vm  |  8 +++---
 src/site/markdown/usage.md.vm                      |  4 +--
 5 files changed, 48 insertions(+), 8 deletions(-)

diff --git a/src/it/script-context/verify.groovy b/src/it/script-context/verify.groovy
index c4c5149..35c3dd3 100644
--- a/src/it/script-context/verify.groovy
+++ b/src/it/script-context/verify.groovy
@@ -37,4 +37,13 @@ if ( !touchFile.exists() )
     throw new FileNotFoundException( "Did not find marker file: " + touchFile );
 }
 
+// the outer build log carries the deprecation warning for the BeanShell scripts, once per file, and none for Groovy
+File buildLog = new File( basedir, "build.log" )
+String log = buildLog.text
+['setup.bsh', 'verify.bsh'].each { name ->
+    File script = new File( basedir, "target/its/beanshell/" + name )
+    assert log.count( "BeanShell scripts are deprecated, port " + script + " to Groovy" ) == 1 : "expected one warning for " + script
+}
+assert !log.contains( "target/its/groovy/setup.groovy to Groovy" ) && !log.contains( "target/its/groovy/verify.groovy to Groovy" )
+
 return true;
diff --git a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
index 7096a20..e70fcdd 100644
--- a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
+++ b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
@@ -50,6 +50,7 @@ import java.util.Optional;
 import java.util.Properties;
 import java.util.Set;
 import java.util.TreeSet;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
 
 import org.apache.maven.artifact.Artifact;
@@ -637,6 +638,11 @@ public abstract class AbstractInvokerMojo extends AbstractMojo {
      */
     private ScriptRunner scriptRunner;
 
+    /**
+     * The BeanShell scripts already reported as deprecated, so that each file is reported once.
+     */
+    private final Set<File> reportedBeanShellScripts = ConcurrentHashMap.newKeySet();
+
     /**
      * A string used to prefix the file name of the filtered POMs in case the POMs couldn't be filtered in-place (i.e.
      * the projects were not cloned to a temporary directory), can be <code>null</code>. This will be set to
@@ -1955,9 +1961,32 @@ public abstract class AbstractInvokerMojo extends AbstractMojo {
         }
     }
 
+    /**
+     * Warns once per file when the script the runner is about to pick is a BeanShell script, which follows the
+     * resolution of the script runner: the name as given, then the name with the {@code .bsh} extension.
+     */
+    private void warnIfBeanShell(File basedir, String scriptName, FileLogger logger) {
+        if (scriptName == null || scriptName.isEmpty()) {
+            return;
+        }
+        File script = new File(basedir, scriptName);
+        if (!script.exists()) {
+            script = new File(basedir, scriptName + ".bsh");
+        }
+        if (script.isFile() && script.getName().endsWith(".bsh") && reportedBeanShellScripts.add(script)) {
+            String message = "BeanShell scripts are deprecated, port " + script + " to Groovy: "
+                    + "https://maven.apache.org/plugins/maven-invoker-plugin/examples/pre-post-build-script.html";
+            getLog().warn(message);
+            if (logger != null) {
+                logger.consumeLine("[WARNING] " + message);
+            }
+        }
+    }
+
     private boolean runSelectorHook(File basedir, Map<String, Object> context, FileLogger logger)
             throws MojoExecutionException, RunFailureException {
         try {
+            warnIfBeanShell(basedir, selectorScript, logger);
             scriptRunner.run("selector script", basedir, selectorScript, context, logger);
         } catch (ScriptReturnException e) {
             return false;
@@ -1976,6 +2005,7 @@ public abstract class AbstractInvokerMojo extends AbstractMojo {
             throws MojoExecutionException, RunFailureException {
         try {
             String hookName = invocationIndex > 0 ? preBuildHookScript + "." + invocationIndex : preBuildHookScript;
+            warnIfBeanShell(basedir, hookName, logger);
             scriptRunner.run("pre-build script", basedir, hookName, context, logger);
         } catch (ScriptException e) {
             if (logger != null) {
@@ -1991,6 +2021,7 @@ public abstract class AbstractInvokerMojo extends AbstractMojo {
             throws MojoExecutionException, RunFailureException {
         try {
             String hookName = invocationIndex > 0 ? postBuildHookScript + "." + invocationIndex : postBuildHookScript;
+            warnIfBeanShell(basedir, hookName, logger);
             scriptRunner.run("post-build script", basedir, hookName, context, logger);
         } catch (IOException e) {
             throw new MojoExecutionException(e.getMessage(), e);
diff --git a/src/site/markdown/examples/pre-post-build-script.md.vm b/src/site/markdown/examples/pre-post-build-script.md.vm
index 5b34a30..fc23374 100644
--- a/src/site/markdown/examples/pre-post-build-script.md.vm
+++ b/src/site/markdown/examples/pre-post-build-script.md.vm
@@ -21,9 +21,9 @@ under the License.
 
 Complementary to the post-build hook script, you can also create a pre-build hook script that will be run before the invocation of Maven. This can be used to do some preparations for the build.
 
-Default name of Pre-Build script is `prebuild`, you can use name `prebuild.bsh` or `prebuild.groovy` according to chosen script language.
+The default name of the pre-build script is `prebuild`, which resolves to `prebuild.groovy`, or to the deprecated `prebuild.bsh`.
 
-**BeanShell scripts are deprecated.** Support for `.bsh` scripts will be removed in a future release; write new scripts in Groovy and port existing BeanShell scripts. Tracked in [apache/maven#13207](https://github.com/apache/maven/issues/13207).
+**BeanShell scripts are deprecated.** Support for `.bsh` scripts will be removed in a future release; write new scripts in Groovy and port existing BeanShell scripts. The plugin logs a warning for every BeanShell script it runs. Tracked in [apache/maven#13207](https://github.com/apache/maven/issues/13207).
 
 In Pre-Build scripts you can prepare a test resources for your project.
 
diff --git a/src/site/markdown/examples/selector-scripts.md.vm b/src/site/markdown/examples/selector-scripts.md.vm
index 48fa491..c46c23a 100644
--- a/src/site/markdown/examples/selector-scripts.md.vm
+++ b/src/site/markdown/examples/selector-scripts.md.vm
@@ -19,7 +19,7 @@ under the License.
 
 # Selector Scripts
 
-Starting with plugin version 1.5, a custom script can be used to skip individual projects based on whatever criteria expressed in the script as illustrated in the following example. Assume the following directory structure:
+Starting with plugin version 1.5, a custom script can be used to skip individual projects based on whatever criteria expressed in the script as illustrated in the following example. Write the script in Groovy; BeanShell scripts are deprecated and the plugin warns when it runs one. Assume the following directory structure:
 
 ```unknown
 ./
@@ -29,7 +29,7 @@ Starting with plugin version 1.5, a custom script can be used to skip individual
       +- settings.xml
       +- conditional-it/
          +- pom.xml
-         +- check-assumptions.bsh
+         +- check-assumptions.groovy
          +- src/
 ```
 
@@ -51,7 +51,7 @@ The plugin configuration for this example would look like this:
           </pomIncludes>
           <settingsFile>src/it/settings.xml</settingsFile>
           <localRepositoryPath>${esc.d}{project.build.directory}/local-repo</localRepositoryPath>
-          <selectorScript>check-assumptions.bsh</selectorScript>
+          <selectorScript>check-assumptions.groovy</selectorScript>
         </configuration>
         <executions>
           <execution>
@@ -69,7 +69,7 @@ The plugin configuration for this example would look like this:
 </project>
 ```
 
-If the check-assumptions.bsh script returns `true` or does not return a value, then the project will be executed.
+If the `check-assumptions.groovy` script returns `true` or does not return a value, then the project will be executed.
 
 If the script returns any value other than `true`, then the project will not be executed.
 
diff --git a/src/site/markdown/usage.md.vm b/src/site/markdown/usage.md.vm
index e570f7d..109d1ea 100644
--- a/src/site/markdown/usage.md.vm
+++ b/src/site/markdown/usage.md.vm
@@ -39,7 +39,7 @@ The following example demonstrates a basic plugin configuration for running inte
          +- pom.xml
          +- invoker.properties
          +- test.properties
-         +- verify.bsh
+         +- verify.groovy
          +- src/
 ```
 
@@ -87,7 +87,7 @@ Next up, the `invoker:run` goal will execute during the phase `integration-test`
 
 Once the IT POMs have been filtered, a Maven build will be started on them. By default, the Invoker Plugin will execute the phase `package` on the IT POMs but that can be changed globally in the plugin configuration or for an individual integration test by using the [`invoker.properties`](./examples/invoker-properties.html) as done in the example for `second-it`. Likewise, system properties can be passed to the IT builds via the file `test.properties`. And the file `src/it/settings.xml`  [...]
 
-When an integration test has finished, the plugin will invoke an optional post build hook script. In the example, this is the case for `second-it` where `verify.bsh` will be run. The purpose of this script is usually to check that the build of the integration test did not only succeed but also produced the intended output. Have a look at the example [Using Pre and Post Build Script](./examples/pre-post-build-script.html) for a code snippet.
+When an integration test has finished, the plugin will invoke an optional post build hook script. In the example, this is the case for `second-it` where `verify.groovy` will be run. The purpose of this script is usually to check that the build of the integration test did not only succeed but also produced the intended output. Have a look at the example [Using Pre and Post Build Script](./examples/pre-post-build-script.html) for a code snippet.
 
 Running Only Some Tests
 -----------------------