Skip to content

Commit

Permalink
[ARCHETYPE-681] Fix output from archetype verification
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed Oct 6, 2024
1 parent 7af674d commit 6b085af
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ under the License.
<url>@localRepositoryUrl@</url>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</snapshots>
</repository>
</repositories>
Expand All @@ -44,9 +46,11 @@ under the License.
<url>@localRepositoryUrl@</url>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
Expand Down
Original file line number Diff line number Diff line change
@@ -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'

Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ under the License.
<properties>
<maven.compiler.source>${maven.compiler.source}</maven.compiler.source>
<maven.compiler.target>${maven.compiler.target}</maven.compiler.target>

</properties>
<streamLogs>false</streamLogs>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ under the License.
<url>@localRepositoryUrl@</url>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</snapshots>
</repository>
</repositories>
Expand All @@ -44,9 +46,11 @@ under the License.
<url>@localRepositoryUrl@</url>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <fileset packaged="true">
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'
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ under the License.
<url>@localRepositoryUrl@</url>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</snapshots>
</repository>
</repositories>
Expand All @@ -44,9 +46,11 @@ under the License.
<url>@localRepositoryUrl@</url>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ under the License.
<url>@localRepositoryUrl@</url>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</snapshots>
</repository>
</repositories>
Expand All @@ -44,9 +46,11 @@ under the License.
<url>@localRepositoryUrl@</url>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ under the License.
<url>@localRepositoryUrl@</url>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</snapshots>
</repository>
</repositories>
Expand All @@ -44,9 +46,11 @@ under the License.
<url>@localRepositoryUrl@</url>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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 <code>null</code> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
* <p>Execute the archetype integration tests, consisting in generating projects from the current archetype and optionally
Expand Down Expand Up @@ -588,7 +587,6 @@ private void invokePostArchetypeGenerationGoals(String goals, File basedir, File

if (logger != null) {
request.setErrorHandler(logger);

request.setOutputHandler(logger);
}

Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 6b085af

Please sign in to comment.