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-script-interpreter.git

commit 080ed17c6d03f50242d4dfbade14bd47142927b7
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Wed Nov 25 20:04:49 2026 +0000

    Add a switch for the BeanShell deprecation warning
---
 .../maven/shared/scriptinterpreter/ScriptRunner.java  | 19 ++++++++++++++++++-
 src/site/markdown/index.md.vm                         |  2 +-
 .../shared/scriptinterpreter/ScriptRunnerTest.java    | 15 +++++++++++++++
 3 files changed, 34 insertions(+), 2 deletions(-)

diff --git 
a/src/main/java/org/apache/maven/shared/scriptinterpreter/ScriptRunner.java 
b/src/main/java/org/apache/maven/shared/scriptinterpreter/ScriptRunner.java
index 5812fb1..34c818e 100644
--- a/src/main/java/org/apache/maven/shared/scriptinterpreter/ScriptRunner.java
+++ b/src/main/java/org/apache/maven/shared/scriptinterpreter/ScriptRunner.java
@@ -68,6 +68,11 @@ public class ScriptRunner implements Closeable {
      */
     private final Set<File> warnedScripts = ConcurrentHashMap.newKeySet();
 
+    /**
+     * Whether running a BeanShell script logs the deprecation warning.
+     */
+    private volatile boolean beanShellWarning = true;
+
     /**
      * Creates a new script runner with BSH and Groovy interpreters. BeanShell 
is deprecated and support for it will be
      * removed in 1.12.
@@ -100,6 +105,18 @@ public class ScriptRunner implements Closeable {
         this.globalVariables.put(name, value);
     }
 
+    /**
+     * Sets whether running a BeanShell script logs the deprecation warning, 
so that callers can let their users
+     * silence it while they port their scripts. It goes away together with 
BeanShell support in 1.12.
+     *
+     * @param beanShellWarning <code>false</code> to run BeanShell scripts 
without the deprecation warning, the
+     *            default is <code>true</code>.
+     * @since 1.10
+     */
+    public void setBeanShellWarning(boolean beanShellWarning) {
+        this.beanShellWarning = beanShellWarning;
+    }
+
     /**
      * Sets the additional class path for the hook scripts. Note that the 
provided list is copied, so any later changes
      * will not affect the scripts.
@@ -215,7 +232,7 @@ public class ScriptRunner implements Closeable {
             name = name.substring(name.lastIndexOf('.') + 1);
             LOG.debug("Running script with {} :{}", name, scriptFile);
         }
-        if (interpreter instanceof BeanShellScriptInterpreter) {
+        if (beanShellWarning && interpreter instanceof 
BeanShellScriptInterpreter) {
             warnOnce(
                     scriptFile,
                     "BeanShell scripts are deprecated and support for them 
will be removed, port " + scriptFile
diff --git a/src/site/markdown/index.md.vm b/src/site/markdown/index.md.vm
index 99154ab..05cbb31 100644
--- a/src/site/markdown/index.md.vm
+++ b/src/site/markdown/index.md.vm
@@ -21,7 +21,7 @@ under the License.
 
 This component provides some utilities to interpret/execute some scripts for 
various implementations: Groovy, and the deprecated BeanShell.
 
-**BeanShell is deprecated** since 1.10: port `.bsh` scripts to Groovy. Running 
a BeanShell script logs a warning once per script file, also in the build log 
of the script, and support for BeanShell will be removed in 1.12. A script with 
an unknown file extension runs as Groovy; up to 1.9 it ran as BeanShell. The 
retirement is tracked in 
[apache/maven#13207](https://github.com/apache/maven/issues/13207).
+**BeanShell is deprecated** since 1.10: port `.bsh` scripts to Groovy. Running 
a BeanShell script logs a warning once per script file, also in the build log 
of the script, and support for BeanShell will be removed in 1.12. Callers can 
switch the warning off with `ScriptRunner.setBeanShellWarning(false)`, for 
example to let their users silence it while they port their scripts. A script 
with an unknown file extension runs as Groovy; up to 1.9 it ran as BeanShell. 
The retirement is tracked  [...]
 
 Dependency declaration
 ----------------------
diff --git 
a/src/test/java/org/apache/maven/shared/scriptinterpreter/ScriptRunnerTest.java 
b/src/test/java/org/apache/maven/shared/scriptinterpreter/ScriptRunnerTest.java
index cc71d3f..b72a4df 100644
--- 
a/src/test/java/org/apache/maven/shared/scriptinterpreter/ScriptRunnerTest.java
+++ 
b/src/test/java/org/apache/maven/shared/scriptinterpreter/ScriptRunnerTest.java
@@ -82,6 +82,21 @@ class ScriptRunnerTest {
         assertTrue(logContent.contains("Finished second"), logContent);
     }
 
+    @Test
+    void beanshellDeprecationWarningCanBeSwitchedOff() throws Exception {
+        File logFile = new File(tempDir, "build.log");
+
+        try (FileLogger fileLogger = new FileLogger(logFile);
+                ScriptRunner scriptRunner = new ScriptRunner()) {
+            scriptRunner.setBeanShellWarning(false);
+            scriptRunner.run("test", new File("src/test/resources/bsh-test"), 
"return-null", null, fileLogger);
+        }
+
+        String logContent = new String(Files.readAllBytes(logFile.toPath()), 
StandardCharsets.UTF_8);
+        assertFalse(logContent.contains("BeanShell scripts are deprecated"), 
logContent);
+        assertTrue(logContent.contains("Finished test"), logContent);
+    }
+
     @Test
     void beanshellReturnedNullShouldBeOk() throws Exception {
         File logFile = new File(tempDir, "build.log");

Reply via email to