From dbe046189a929859fdbe25bc0def1b1cbd28b1dd Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Mon, 15 Apr 2024 00:43:26 +0200 Subject: [PATCH] [ARCHETYPE-658] Upgrade Groovy from 2.x to 4.0.22 --- archetype-common/pom.xml | 7 +++--- maven-archetype-plugin/pom.xml | 2 +- .../META-INF/archetype-post-generate.groovy | 8 +++--- .../maven/archetype/mojos/FileLogger.java | 16 +++++++++--- .../archetype/mojos/IntegrationTestMojo.java | 25 +++++++------------ 5 files changed, 28 insertions(+), 30 deletions(-) diff --git a/archetype-common/pom.xml b/archetype-common/pom.xml index 27f8bfb9d..199884751 100644 --- a/archetype-common/pom.xml +++ b/archetype-common/pom.xml @@ -48,10 +48,9 @@ archetype-descriptor - org.codehaus.groovy - groovy-all - 2.4.16 - compile + org.apache.groovy + groovy + 4.0.21 org.apache.ivy diff --git a/maven-archetype-plugin/pom.xml b/maven-archetype-plugin/pom.xml index fae3a113f..0ed608c91 100644 --- a/maven-archetype-plugin/pom.xml +++ b/maven-archetype-plugin/pom.xml @@ -143,7 +143,7 @@ org.apache.maven.shared maven-script-interpreter - 1.2 + 1.5 diff --git a/maven-archetype-plugin/src/it/projects/ARCHETYPE-565_groovy-json/archetype/src/main/resources/META-INF/archetype-post-generate.groovy b/maven-archetype-plugin/src/it/projects/ARCHETYPE-565_groovy-json/archetype/src/main/resources/META-INF/archetype-post-generate.groovy index 48f0468cb..fdabd927e 100644 --- a/maven-archetype-plugin/src/it/projects/ARCHETYPE-565_groovy-json/archetype/src/main/resources/META-INF/archetype-post-generate.groovy +++ b/maven-archetype-plugin/src/it/projects/ARCHETYPE-565_groovy-json/archetype/src/main/resources/META-INF/archetype-post-generate.groovy @@ -6,9 +6,9 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -16,10 +16,8 @@ * specific language governing permissions and limitations * under the License. */ -import groovy.json.JsonException // Should error on this line if test fails. - import java.nio.file.Files import java.nio.file.Paths def p = Paths.get(request.getOutputDirectory(), request.getArtifactId(), 'test.txt') -Files.createFile(p) \ No newline at end of file +Files.createFile(p) diff --git a/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/FileLogger.java b/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/FileLogger.java index 95f61fd0e..18332eff4 100644 --- a/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/FileLogger.java +++ b/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/FileLogger.java @@ -40,16 +40,18 @@ import java.io.File; import java.io.IOException; -import org.apache.maven.plugin.logging.Log; import org.apache.maven.shared.invoker.InvocationOutputHandler; import org.apache.maven.shared.scriptinterpreter.ExecutionLogger; +import org.apache.maven.shared.scriptinterpreter.FileLoggerMirrorHandler; +import org.slf4j.Logger; /** * @since 2.2 */ class FileLogger extends org.apache.maven.shared.scriptinterpreter.FileLogger - implements InvocationOutputHandler, ExecutionLogger { + implements InvocationOutputHandler, ExecutionLogger, FileLoggerMirrorHandler { + Logger logger; /** * Creates a new logger that writes to the specified file. * @@ -67,7 +69,13 @@ class FileLogger extends org.apache.maven.shared.scriptinterpreter.FileLogger * @param log The mojo logger to additionally output messages to, may be null if not used. * @throws java.io.IOException If the output file could not be created. */ - FileLogger(File outputFile, Log log) throws IOException { - super(outputFile, log); + FileLogger(File outputFile, Logger log) throws IOException { + super(outputFile); + logger = log; + } + + @Override + public void consumeOutput(String message) { + logger.info(message); } } diff --git a/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/IntegrationTestMojo.java b/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/IntegrationTestMojo.java index 959b94fba..041237417 100644 --- a/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/IntegrationTestMojo.java +++ b/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/IntegrationTestMojo.java @@ -62,7 +62,7 @@ import org.apache.maven.shared.invoker.InvocationResult; import org.apache.maven.shared.invoker.Invoker; import org.apache.maven.shared.invoker.MavenInvocationException; -import org.apache.maven.shared.scriptinterpreter.RunFailureException; +import org.apache.maven.shared.scriptinterpreter.ScriptException; import org.apache.maven.shared.scriptinterpreter.ScriptRunner; import org.apache.maven.shared.transfer.artifact.DefaultArtifactCoordinate; import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver; @@ -74,6 +74,7 @@ import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.WriterFactory; import org.codehaus.plexus.util.introspection.ReflectionValueExtractor; +import org.slf4j.LoggerFactory; /** *

Execute the archetype integration tests, consisting in generating projects from the current archetype and optionally @@ -661,22 +662,14 @@ private void invokePostArchetypeGenerationGoals(String goals, File basedir, File getLog().info("No post-archetype-generation goals to invoke."); } // verify result - ScriptRunner scriptRunner = new ScriptRunner(getLog()); - scriptRunner.setScriptEncoding(encoding); + try (ScriptRunner scriptRunner = new ScriptRunner()) { + scriptRunner.setScriptEncoding(encoding); - Map context = new LinkedHashMap<>(); - context.put("projectDir", basedir); + Map context = new LinkedHashMap<>(); + context.put("projectDir", basedir); - try { - scriptRunner.run( - "post-build script", - goalFile.getParentFile(), - postBuildHookScript, - context, - logger, - "failure post script", - true); - } catch (RunFailureException e) { + scriptRunner.run("post-build script", goalFile.getParentFile(), postBuildHookScript, context, logger); + } catch (ScriptException e) { throw new IntegrationTestFailure("post build script failure failure: " + e.getMessage(), e); } } @@ -688,7 +681,7 @@ private FileLogger setupLogger(File basedir) throws IOException { File outputLog = new File(basedir, "build.log"); if (streamLogs) { - logger = new FileLogger(outputLog, getLog()); + logger = new FileLogger(outputLog, LoggerFactory.getLogger(getClass())); } else { logger = new FileLogger(outputLog); }