From 411936228169317b022316887fedce57382ba180 Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Sun, 6 Oct 2024 10:22:32 +0200 Subject: [PATCH] [ARCHETYPE-681] Fix output from archetype verification --- .../test-settings.xml | 4 ++++ .../verify.groovy | 23 +++++++++++++++++++ .../ARCHETYPE-622_main_build_settings/pom.xml | 2 +- .../test-settings.xml | 4 ++++ .../verify.groovy | 19 ++++++++------- .../build-and-run-its/test-settings.xml | 4 ++++ .../build-archetype/test-settings.xml | 4 ++++ .../build-ignore-eol/test-settings.xml | 4 ++++ .../maven/archetype/mojos/FileLogger.java | 18 ++++----------- .../archetype/mojos/IntegrationTestMojo.java | 4 +--- 10 files changed, 60 insertions(+), 26 deletions(-) create mode 100644 maven-archetype-plugin/src/it/projects/ARCHETYPE-606_include-gitignore/verify.groovy diff --git a/maven-archetype-plugin/src/it/projects/ARCHETYPE-606_include-gitignore/test-settings.xml b/maven-archetype-plugin/src/it/projects/ARCHETYPE-606_include-gitignore/test-settings.xml index ab9e16e42..cb295a6ba 100644 --- a/maven-archetype-plugin/src/it/projects/ARCHETYPE-606_include-gitignore/test-settings.xml +++ b/maven-archetype-plugin/src/it/projects/ARCHETYPE-606_include-gitignore/test-settings.xml @@ -32,9 +32,11 @@ under the License. @localRepositoryUrl@ true + ignore true + ignore @@ -44,9 +46,11 @@ under the License. @localRepositoryUrl@ true + ignore true + ignore diff --git a/maven-archetype-plugin/src/it/projects/ARCHETYPE-606_include-gitignore/verify.groovy b/maven-archetype-plugin/src/it/projects/ARCHETYPE-606_include-gitignore/verify.groovy new file mode 100644 index 000000000..77eac963b --- /dev/null +++ b/maven-archetype-plugin/src/it/projects/ARCHETYPE-606_include-gitignore/verify.groovy @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * 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 + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +buildLog = new File( basedir, '../../logs/ARCHETYPE-606_include-gitignore/build.log' ).text +assert buildLog.contains( '[INFO] Invoking post-archetype-generation goals: compile' ) : 'post-archetype-generation invocation not recorder in log' +assert buildLog.contains( '[INFO] [INFO]' ) : 'output of post-archetype-generation should be present in log' + diff --git a/maven-archetype-plugin/src/it/projects/ARCHETYPE-622_main_build_settings/pom.xml b/maven-archetype-plugin/src/it/projects/ARCHETYPE-622_main_build_settings/pom.xml index b7ae168ff..9d90bf789 100644 --- a/maven-archetype-plugin/src/it/projects/ARCHETYPE-622_main_build_settings/pom.xml +++ b/maven-archetype-plugin/src/it/projects/ARCHETYPE-622_main_build_settings/pom.xml @@ -56,8 +56,8 @@ under the License. ${maven.compiler.source} ${maven.compiler.target} - + false diff --git a/maven-archetype-plugin/src/it/projects/ARCHETYPE-622_main_build_settings/test-settings.xml b/maven-archetype-plugin/src/it/projects/ARCHETYPE-622_main_build_settings/test-settings.xml index ab9e16e42..cb295a6ba 100644 --- a/maven-archetype-plugin/src/it/projects/ARCHETYPE-622_main_build_settings/test-settings.xml +++ b/maven-archetype-plugin/src/it/projects/ARCHETYPE-622_main_build_settings/test-settings.xml @@ -32,9 +32,11 @@ under the License. @localRepositoryUrl@ true + ignore true + ignore @@ -44,9 +46,11 @@ under the License. @localRepositoryUrl@ true + ignore true + ignore diff --git a/maven-archetype-plugin/src/it/projects/ARCHETYPE-622_main_build_settings/verify.groovy b/maven-archetype-plugin/src/it/projects/ARCHETYPE-622_main_build_settings/verify.groovy index 272ea5a57..363e7a84a 100644 --- a/maven-archetype-plugin/src/it/projects/ARCHETYPE-622_main_build_settings/verify.groovy +++ b/maven-archetype-plugin/src/it/projects/ARCHETYPE-622_main_build_settings/verify.groovy @@ -21,24 +21,27 @@ import java.io.* import org.codehaus.plexus.util.* -def basedir = new File(basedir, "target/test-classes/projects/basic/project/basic") -assert basedir.exists() : "${basedir} is missing." +def basedirTargetProject = new File(basedir, "target/test-classes/projects/basic/project/basic") +assert basedirTargetProject.exists() : "${basedirTargetProject} is missing." -def main = new File(basedir, "src/main") +def main = new File(basedirTargetProject, "src/main") def app = new File(main, "java/build/archetype/App.java") // check assert app.isFile() : "${app} file is missing or not a file." -def buildLog = new File(basedir, "build.log") -def content = FileUtils.fileRead(buildLog, "UTF-8") +def buildLog = new File(basedirTargetProject, "build.log").text -assert content.contains("Archetype tests executed!") : +assert buildLog.contains("Archetype tests executed!") : "build.log missing System.out.println from verify.groovy" // we expect the archetype:integration-test to use the settings.xml from the main Maven build - so downloading should happen // also from local.central specified in the test-settings.xml -assert content.contains("local.central (file://") : +assert buildLog.contains("local.central (file://") : "test-settings.xml wasn't passed from the main Maven build!: 'local.central (file://' was NOT found in the output! The output was:\n${content}" def settingsXmlPath = new File("maven-archetype-plugin/target/it/projects/ARCHETYPE-622_main_build_settings/target/archetype-it", "archetype-settings.xml").toPath().toString().replace("\\", "\\\\") -assert content.matches("(?s).*\\[DEBUG\\] Reading user settings from .*" + settingsXmlPath + ".*") : "test-settings.xml wasn't passed from the main Maven build!: 'Reading user settings from ... archetype-settings.xml' was NOT found in the output! The output was:\n${content}" +assert buildLog.matches("(?s).*\\[DEBUG\\] Reading user settings from .*" + settingsXmlPath + ".*") : "test-settings.xml wasn't passed from the main Maven build!: 'Reading user settings from ... archetype-settings.xml' was NOT found in the output! The output was: ${buildLog}" + +def mainBuildLog = new File( basedir, "../../logs/ARCHETYPE-622_main_build_settings/build.log" ).text +assert mainBuildLog.contains('[INFO] Invoking post-archetype-generation goals: compile') : 'post-archetype-generation invocation not recorder in log' +assert !mainBuildLog.contains('[INFO] [INFO]') : 'output of post-archetype-generation should not be present in log' \ No newline at end of file diff --git a/maven-archetype-plugin/src/it/projects/build-and-run-its/test-settings.xml b/maven-archetype-plugin/src/it/projects/build-and-run-its/test-settings.xml index ab9e16e42..cb295a6ba 100644 --- a/maven-archetype-plugin/src/it/projects/build-and-run-its/test-settings.xml +++ b/maven-archetype-plugin/src/it/projects/build-and-run-its/test-settings.xml @@ -32,9 +32,11 @@ under the License. @localRepositoryUrl@ true + ignore true + ignore @@ -44,9 +46,11 @@ under the License. @localRepositoryUrl@ true + ignore true + ignore diff --git a/maven-archetype-plugin/src/it/projects/build-archetype/test-settings.xml b/maven-archetype-plugin/src/it/projects/build-archetype/test-settings.xml index ab9e16e42..cb295a6ba 100644 --- a/maven-archetype-plugin/src/it/projects/build-archetype/test-settings.xml +++ b/maven-archetype-plugin/src/it/projects/build-archetype/test-settings.xml @@ -32,9 +32,11 @@ under the License. @localRepositoryUrl@ true + ignore true + ignore @@ -44,9 +46,11 @@ under the License. @localRepositoryUrl@ true + ignore true + ignore diff --git a/maven-archetype-plugin/src/it/projects/build-ignore-eol/test-settings.xml b/maven-archetype-plugin/src/it/projects/build-ignore-eol/test-settings.xml index ab9e16e42..cb295a6ba 100644 --- a/maven-archetype-plugin/src/it/projects/build-ignore-eol/test-settings.xml +++ b/maven-archetype-plugin/src/it/projects/build-ignore-eol/test-settings.xml @@ -32,9 +32,11 @@ under the License. @localRepositoryUrl@ true + ignore true + ignore @@ -44,9 +46,11 @@ under the License. @localRepositoryUrl@ true + ignore true + ignore 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 18332eff4..a02ec3e0d 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,18 +40,14 @@ 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, FileLoggerMirrorHandler { +class FileLogger extends org.apache.maven.shared.scriptinterpreter.FileLogger implements InvocationOutputHandler { - Logger logger; /** * Creates a new logger that writes to the specified file. * @@ -69,13 +65,7 @@ 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, Logger log) throws IOException { - super(outputFile); - logger = log; - } - - @Override - public void consumeOutput(String message) { - logger.info(message); + FileLogger(File outputFile, Log log) throws IOException { + super(outputFile, log::info); } } 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 4543ed4c5..8b2de572c 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 @@ -69,7 +69,6 @@ import org.codehaus.plexus.util.introspection.ReflectionValueExtractor; import org.codehaus.plexus.util.xml.XmlStreamReader; import org.codehaus.plexus.util.xml.XmlStreamWriter; -import org.slf4j.LoggerFactory; /** *

Execute the archetype integration tests, consisting in generating projects from the current archetype and optionally @@ -588,7 +587,6 @@ private void invokePostArchetypeGenerationGoals(String goals, File basedir, File if (logger != null) { request.setErrorHandler(logger); - request.setOutputHandler(logger); } @@ -659,7 +657,7 @@ private FileLogger setupLogger(File basedir) throws IOException { File outputLog = new File(basedir, "build.log"); if (streamLogs) { - logger = new FileLogger(outputLog, LoggerFactory.getLogger(getClass())); + logger = new FileLogger(outputLog, getLog()); } else { logger = new FileLogger(outputLog); }