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 d1a7a26392d7668d1c7d473f8415b70687624ca5 Author: Sylwester Lachiewicz <[email protected]> AuthorDate: Wed Nov 25 19:24:46 2026 +0000 Log the BeanShell deprecation warning once per script file The warning also goes to the script's build log, and the deprecation notes now say support ends in 1.12; the optional-dependency step planned for 1.11 is dropped. --- .../BeanShellScriptInterpreter.java | 4 +- .../shared/scriptinterpreter/ScriptRunner.java | 51 +++++++++++++++++----- src/site/markdown/index.md.vm | 4 +- .../shared/scriptinterpreter/ScriptRunnerTest.java | 17 ++++++++ 4 files changed, 60 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/apache/maven/shared/scriptinterpreter/BeanShellScriptInterpreter.java b/src/main/java/org/apache/maven/shared/scriptinterpreter/BeanShellScriptInterpreter.java index f2a6854..434f32b 100644 --- a/src/main/java/org/apache/maven/shared/scriptinterpreter/BeanShellScriptInterpreter.java +++ b/src/main/java/org/apache/maven/shared/scriptinterpreter/BeanShellScriptInterpreter.java @@ -37,8 +37,8 @@ import bsh.TargetError; * Provides a facade to evaluate BeanShell scripts. * * @author Benjamin Bentmann - * @deprecated since 1.10: BeanShell scripts are deprecated, port them to Groovy. BeanShell becomes an optional - * dependency in 1.11 and support for it will be removed later (apache/maven#13207). + * @deprecated since 1.10: BeanShell scripts are deprecated, port them to Groovy. Support for them will be removed in + * 1.12 (apache/maven#13207). */ @Deprecated class BeanShellScriptInterpreter implements ScriptInterpreter { 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 0f7c837..5812fb1 100644 --- a/src/main/java/org/apache/maven/shared/scriptinterpreter/ScriptRunner.java +++ b/src/main/java/org/apache/maven/shared/scriptinterpreter/ScriptRunner.java @@ -29,6 +29,8 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.io.FilenameUtils; import org.slf4j.Logger; @@ -62,8 +64,13 @@ public class ScriptRunner implements Closeable { private String encoding; /** - * Creates a new script runner with BSH and Groovy interpreters. BeanShell is deprecated: it becomes an optional - * dependency in 1.11 and support for it will be removed later. + * The script files already warned about, so that each deprecation warning is logged once per file. + */ + private final Set<File> warnedScripts = ConcurrentHashMap.newKeySet(); + + /** + * Creates a new script runner with BSH and Groovy interpreters. BeanShell is deprecated and support for it will be + * removed in 1.12. */ @SuppressWarnings("deprecation") public ScriptRunner() { @@ -202,17 +209,18 @@ public class ScriptRunner implements Closeable { final Map<String, ?> context, final ExecutionLogger logger) throws IOException, ScriptException { - ScriptInterpreter interpreter = getInterpreter(scriptFile); + ScriptInterpreter interpreter = getInterpreter(scriptFile, logger); if (LOG.isDebugEnabled()) { String name = interpreter.getClass().getName(); name = name.substring(name.lastIndexOf('.') + 1); LOG.debug("Running script with {} :{}", name, scriptFile); } if (interpreter instanceof BeanShellScriptInterpreter) { - LOG.warn( - "BeanShell scripts are deprecated, port {} to Groovy; BeanShell becomes an optional dependency" - + " in maven-script-interpreter 1.11 and support for it will be removed later", - scriptFile); + warnOnce( + scriptFile, + "BeanShell scripts are deprecated and support for them will be removed, port " + scriptFile + + " to Groovy", + logger); } String script; @@ -284,24 +292,43 @@ public class ScriptRunner implements Closeable { /** * Determines the script interpreter for the specified script file by looking at its file extension. In this * context, file extensions are considered case-insensitive. Groovy is used for any unrecognized extension; up to - * 1.9 that was BeanShell, which is deprecated and becomes an optional dependency in 1.11. + * 1.9 that was BeanShell, which is deprecated and will be removed in 1.12. * * @param scriptFile The script file for which to determine an interpreter, must not be <code>null</code>. + * @param logger The logger that also receives the warning for an unrecognized extension, may be <code>null</code>. * @return The script interpreter for the file, never <code>null</code>. */ - private ScriptInterpreter getInterpreter(File scriptFile) { + private ScriptInterpreter getInterpreter(File scriptFile, ExecutionLogger logger) { String ext = FilenameUtils.getExtension(scriptFile.getName()).toLowerCase(Locale.ENGLISH); ScriptInterpreter interpreter = scriptInterpreters.get(ext); if (interpreter == null) { - LOG.warn( - "No interpreter registered for the extension of {}, running it as Groovy; up to" + warnOnce( + scriptFile, + "No interpreter registered for the extension of " + scriptFile + ", running it as Groovy; up to" + " maven-script-interpreter 1.9 such scripts ran as BeanShell", - scriptFile); + logger); interpreter = scriptInterpreters.get("groovy"); } return interpreter; } + /** + * Logs a warning about a script file the first time this runner sees that file, and copies it to the execution + * logger so that it also lands in the build log of the script. + * + * @param scriptFile The script file the warning is about, must not be <code>null</code>. + * @param message The warning, must not be <code>null</code>. + * @param logger The logger that also receives the warning, may be <code>null</code>. + */ + private void warnOnce(File scriptFile, String message, ExecutionLogger logger) { + if (warnedScripts.add(scriptFile.getAbsoluteFile())) { + LOG.warn(message); + if (logger != null) { + logger.consumeLine("[WARNING] " + message); + } + } + } + /** * Closes this script interpreter and releases any system resources associated with it. * diff --git a/src/site/markdown/index.md.vm b/src/site/markdown/index.md.vm index 1223bbb..99154ab 100644 --- a/src/site/markdown/index.md.vm +++ b/src/site/markdown/index.md.vm @@ -19,9 +19,9 @@ under the License. # ${project.name} -This component provides some utilities to interpret/execute some scripts for various implementations: groovy or beanshell. +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, BeanShell becomes an optional dependency in 1.11, and support for it will be removed later. 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. 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). 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 c3e87a4..cc71d3f 100644 --- a/src/test/java/org/apache/maven/shared/scriptinterpreter/ScriptRunnerTest.java +++ b/src/test/java/org/apache/maven/shared/scriptinterpreter/ScriptRunnerTest.java @@ -65,6 +65,23 @@ class ScriptRunnerTest { assertEquals(logContent, mirrorHandler.getLoggedMessage()); } + @Test + void beanshellDeprecationWarnedOncePerScript() throws Exception { + File logFile = new File(tempDir, "build.log"); + + try (FileLogger fileLogger = new FileLogger(logFile); + ScriptRunner scriptRunner = new ScriptRunner()) { + scriptRunner.run("first", new File("src/test/resources/bsh-test"), "return-null", null, fileLogger); + scriptRunner.run("second", new File("src/test/resources/bsh-test"), "return-null", null, fileLogger); + } + + String logContent = new String(Files.readAllBytes(logFile.toPath()), StandardCharsets.UTF_8); + String warning = "[WARNING] BeanShell scripts are deprecated"; + assertEquals(logContent.indexOf(warning), logContent.lastIndexOf(warning), logContent); + assertTrue(logContent.contains(warning), logContent); + assertTrue(logContent.contains("Finished second"), logContent); + } + @Test void beanshellReturnedNullShouldBeOk() throws Exception { File logFile = new File(tempDir, "build.log");
