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-invoker-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 7e88f0d Prefix per-job console output with project path under
parallelThreads (#765)
7e88f0d is described below
commit 7e88f0d6038104916be7f15525475139242b1c2f
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Fri Nov 27 21:06:48 2026 +0200
Prefix per-job console output with project path under parallelThreads (#765)
* Prefix per-job console output with project path under parallelThreads
Interleaved output from concurrent jobs could not be attributed to a
project; every mojo-log line for a job (Building, script-run, streamed
build output) now carries a "[<project>] " prefix when parallelThreads
> 1, while single-threaded output and build.log file content stay
unchanged.
Fixes #684
* Use the project prefix for every per-job console line
The bracketed prefix replaces both the "Building: <project>" line and
the dot-padded result line, in single-threaded runs too, so parallel
and sequential output have one shape and the project name appears once
per line.
* Adapt the script-streamLogs ITs to the prefixed console lines
* Remove orphaned javadoc of the result column
* Use the project prefix for the error result line
The error line added on master still used the removed dot-padded format and
no longer compiled.
---
src/it/parallel-log-prefix-single-threaded/pom.xml | 68 +++++++++++++++++++++
.../src/it/alpha/pom.xml | 32 ++++++++++
.../src/it/alpha/setup.groovy | 26 ++++++++
.../src/it/beta/pom.xml | 32 ++++++++++
.../src/it/beta/setup.groovy | 26 ++++++++
.../verify.groovy | 58 ++++++++++++++++++
src/it/parallel-log-prefix/pom.xml | 70 ++++++++++++++++++++++
src/it/parallel-log-prefix/src/it/alpha/pom.xml | 32 ++++++++++
.../parallel-log-prefix/src/it/alpha/setup.groovy | 26 ++++++++
src/it/parallel-log-prefix/src/it/beta/pom.xml | 32 ++++++++++
.../parallel-log-prefix/src/it/beta/setup.groovy | 26 ++++++++
src/it/parallel-log-prefix/verify.groovy | 58 ++++++++++++++++++
src/it/project-setup/verify.groovy | 16 +++--
src/it/rerun-build/verify.groovy | 8 +--
src/it/script-streamLogs/verify.groovy | 18 +++---
src/it/selector-conditions/verify.groovy | 16 ++---
.../maven/plugins/invoker/AbstractInvokerMojo.java | 57 ++++++------------
.../apache/maven/plugins/invoker/FileLogger.java | 29 ++++++++-
.../plugins/invoker/BuildOutputFilesTest.java | 4 +-
19 files changed, 565 insertions(+), 69 deletions(-)
diff --git a/src/it/parallel-log-prefix-single-threaded/pom.xml
b/src/it/parallel-log-prefix-single-threaded/pom.xml
new file mode 100644
index 0000000..1aaaafc
--- /dev/null
+++ b/src/it/parallel-log-prefix-single-threaded/pom.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.plugins.invoker</groupId>
+ <artifactId>parallel-log-prefix-single-threaded</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <!--
+ MINVOKER-684 control case: with the default parallelThreads=1 the per-job
console lines carry the same
+ "[<project>] " prefix as in a parallel run, so the format does not depend
on the thread count.
+ -->
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-invoker-plugin</artifactId>
+ <version>@project.version@</version>
+ <configuration>
+ <cloneProjectsTo>${project.build.directory}/its</cloneProjectsTo>
+ <pomIncludes>
+ <pomInclude>*/pom.xml</pomInclude>
+ </pomIncludes>
+ <preBuildHookScript>setup</preBuildHookScript>
+ <goals>
+ <goal>validate</goal>
+ </goals>
+ <streamLogs>true</streamLogs>
+ </configuration>
+ <executions>
+ <execution>
+ <id>integration-test</id>
+ <phase>initialize</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/src/it/parallel-log-prefix-single-threaded/src/it/alpha/pom.xml
b/src/it/parallel-log-prefix-single-threaded/src/it/alpha/pom.xml
new file mode 100644
index 0000000..b45c6da
--- /dev/null
+++ b/src/it/parallel-log-prefix-single-threaded/src/it/alpha/pom.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>test</groupId>
+ <artifactId>alpha</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+</project>
diff --git
a/src/it/parallel-log-prefix-single-threaded/src/it/alpha/setup.groovy
b/src/it/parallel-log-prefix-single-threaded/src/it/alpha/setup.groovy
new file mode 100644
index 0000000..25c5a1f
--- /dev/null
+++ b/src/it/parallel-log-prefix-single-threaded/src/it/alpha/setup.groovy
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+import java.io.*;
+
+// marker for parent build that this sub build was indeed run
+File touchFile = new File( basedir, "touch.txt" )
+touchFile.createNewFile()
+
+println("Output from setup script for alpha")
diff --git a/src/it/parallel-log-prefix-single-threaded/src/it/beta/pom.xml
b/src/it/parallel-log-prefix-single-threaded/src/it/beta/pom.xml
new file mode 100644
index 0000000..836512c
--- /dev/null
+++ b/src/it/parallel-log-prefix-single-threaded/src/it/beta/pom.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>test</groupId>
+ <artifactId>beta</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+</project>
diff --git
a/src/it/parallel-log-prefix-single-threaded/src/it/beta/setup.groovy
b/src/it/parallel-log-prefix-single-threaded/src/it/beta/setup.groovy
new file mode 100644
index 0000000..c38a165
--- /dev/null
+++ b/src/it/parallel-log-prefix-single-threaded/src/it/beta/setup.groovy
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+import java.io.*;
+
+// marker for parent build that this sub build was indeed run
+File touchFile = new File( basedir, "touch.txt" )
+touchFile.createNewFile()
+
+println("Output from setup script for beta")
diff --git a/src/it/parallel-log-prefix-single-threaded/verify.groovy
b/src/it/parallel-log-prefix-single-threaded/verify.groovy
new file mode 100644
index 0000000..4895413
--- /dev/null
+++ b/src/it/parallel-log-prefix-single-threaded/verify.groovy
@@ -0,0 +1,58 @@
+/*
+ * 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.
+ */
+
+def FS = File.separator
+def alphaProject = 'alpha' + FS + 'pom.xml'
+def betaProject = 'beta' + FS + 'pom.xml'
+
+// make sure both sub builds were indeed run
+assert new File(basedir, 'target/its/alpha/touch.txt').exists()
+assert new File(basedir, 'target/its/beta/touch.txt').exists()
+
+def lines = new File(basedir, 'build.log').readLines()
+
+// MINVOKER-684: every console line emitted on behalf of a job is prefixed
with the job's project path, so
+// output from several jobs stays attributable when it interleaves. The format
does not depend on
+// parallelThreads.
+
+// start and result lines
+assert lines.any { it.contains('[' + alphaProject + '] starting') }
+assert lines.any { it.contains('[' + betaProject + '] starting') }
+assert lines.any { it.contains('[' + alphaProject + '] SUCCESS (') }
+assert lines.any { it.contains('[' + betaProject + '] SUCCESS (') }
+
+// the project name appears once per line, as the prefix
+assert lines.findAll { it.contains('] starting') }.every {
it.count(alphaProject) + it.count(betaProject) == 1 }
+
+// script-run lines reaching the console via streamLogs are prefixed
+assert lines.any { it.contains('[' + alphaProject + '] Running pre-build
script') }
+assert lines.any { it.contains('[' + betaProject + '] Running pre-build
script') }
+
+// streamed script output lines are prefixed
+assert lines.any { it.contains('[' + alphaProject + '] Output from setup
script for alpha') }
+assert lines.any { it.contains('[' + betaProject + '] Output from setup script
for beta') }
+
+// the prefix is a console-only concern: the per-job build.log file content
must stay untouched
+def alphaLog = new File(basedir, 'target/its/alpha/build.log').text
+def betaLog = new File(basedir, 'target/its/beta/build.log').text
+
+assert !alphaLog.contains('[' + alphaProject + ']')
+assert !betaLog.contains('[' + betaProject + ']')
+assert alphaLog.contains('Running pre-build script')
+assert betaLog.contains('Running pre-build script')
diff --git a/src/it/parallel-log-prefix/pom.xml
b/src/it/parallel-log-prefix/pom.xml
new file mode 100644
index 0000000..50e5d31
--- /dev/null
+++ b/src/it/parallel-log-prefix/pom.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.plugins.invoker</groupId>
+ <artifactId>parallel-log-prefix</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <!--
+ MINVOKER-684: when several jobs run in parallel their console lines
interleave. Every mojo-log line
+ emitted on behalf of one job (start, result, script-run, streamed build
output, ...) must be prefixed with
+ the job's project path so it stays attributable.
+ -->
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-invoker-plugin</artifactId>
+ <version>@project.version@</version>
+ <configuration>
+ <cloneProjectsTo>${project.build.directory}/its</cloneProjectsTo>
+ <pomIncludes>
+ <pomInclude>*/pom.xml</pomInclude>
+ </pomIncludes>
+ <preBuildHookScript>setup</preBuildHookScript>
+ <goals>
+ <goal>validate</goal>
+ </goals>
+ <streamLogs>true</streamLogs>
+ <parallelThreads>2</parallelThreads>
+ </configuration>
+ <executions>
+ <execution>
+ <id>integration-test</id>
+ <phase>initialize</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/src/it/parallel-log-prefix/src/it/alpha/pom.xml
b/src/it/parallel-log-prefix/src/it/alpha/pom.xml
new file mode 100644
index 0000000..b45c6da
--- /dev/null
+++ b/src/it/parallel-log-prefix/src/it/alpha/pom.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>test</groupId>
+ <artifactId>alpha</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+</project>
diff --git a/src/it/parallel-log-prefix/src/it/alpha/setup.groovy
b/src/it/parallel-log-prefix/src/it/alpha/setup.groovy
new file mode 100644
index 0000000..25c5a1f
--- /dev/null
+++ b/src/it/parallel-log-prefix/src/it/alpha/setup.groovy
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+import java.io.*;
+
+// marker for parent build that this sub build was indeed run
+File touchFile = new File( basedir, "touch.txt" )
+touchFile.createNewFile()
+
+println("Output from setup script for alpha")
diff --git a/src/it/parallel-log-prefix/src/it/beta/pom.xml
b/src/it/parallel-log-prefix/src/it/beta/pom.xml
new file mode 100644
index 0000000..836512c
--- /dev/null
+++ b/src/it/parallel-log-prefix/src/it/beta/pom.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>test</groupId>
+ <artifactId>beta</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+</project>
diff --git a/src/it/parallel-log-prefix/src/it/beta/setup.groovy
b/src/it/parallel-log-prefix/src/it/beta/setup.groovy
new file mode 100644
index 0000000..c38a165
--- /dev/null
+++ b/src/it/parallel-log-prefix/src/it/beta/setup.groovy
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+import java.io.*;
+
+// marker for parent build that this sub build was indeed run
+File touchFile = new File( basedir, "touch.txt" )
+touchFile.createNewFile()
+
+println("Output from setup script for beta")
diff --git a/src/it/parallel-log-prefix/verify.groovy
b/src/it/parallel-log-prefix/verify.groovy
new file mode 100644
index 0000000..4895413
--- /dev/null
+++ b/src/it/parallel-log-prefix/verify.groovy
@@ -0,0 +1,58 @@
+/*
+ * 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.
+ */
+
+def FS = File.separator
+def alphaProject = 'alpha' + FS + 'pom.xml'
+def betaProject = 'beta' + FS + 'pom.xml'
+
+// make sure both sub builds were indeed run
+assert new File(basedir, 'target/its/alpha/touch.txt').exists()
+assert new File(basedir, 'target/its/beta/touch.txt').exists()
+
+def lines = new File(basedir, 'build.log').readLines()
+
+// MINVOKER-684: every console line emitted on behalf of a job is prefixed
with the job's project path, so
+// output from several jobs stays attributable when it interleaves. The format
does not depend on
+// parallelThreads.
+
+// start and result lines
+assert lines.any { it.contains('[' + alphaProject + '] starting') }
+assert lines.any { it.contains('[' + betaProject + '] starting') }
+assert lines.any { it.contains('[' + alphaProject + '] SUCCESS (') }
+assert lines.any { it.contains('[' + betaProject + '] SUCCESS (') }
+
+// the project name appears once per line, as the prefix
+assert lines.findAll { it.contains('] starting') }.every {
it.count(alphaProject) + it.count(betaProject) == 1 }
+
+// script-run lines reaching the console via streamLogs are prefixed
+assert lines.any { it.contains('[' + alphaProject + '] Running pre-build
script') }
+assert lines.any { it.contains('[' + betaProject + '] Running pre-build
script') }
+
+// streamed script output lines are prefixed
+assert lines.any { it.contains('[' + alphaProject + '] Output from setup
script for alpha') }
+assert lines.any { it.contains('[' + betaProject + '] Output from setup script
for beta') }
+
+// the prefix is a console-only concern: the per-job build.log file content
must stay untouched
+def alphaLog = new File(basedir, 'target/its/alpha/build.log').text
+def betaLog = new File(basedir, 'target/its/beta/build.log').text
+
+assert !alphaLog.contains('[' + alphaProject + ']')
+assert !betaLog.contains('[' + betaProject + ']')
+assert alphaLog.contains('Running pre-build script')
+assert betaLog.contains('Running pre-build script')
diff --git a/src/it/project-setup/verify.groovy
b/src/it/project-setup/verify.groovy
index d6d8643..11192c6 100644
--- a/src/it/project-setup/verify.groovy
+++ b/src/it/project-setup/verify.groovy
@@ -35,24 +35,28 @@ try
String log = FileUtils.fileRead( logFile );
+ String project3Start = "[project3" + File.separator + "pom.xml] starting";
+ String project6Start = "[project6" + File.separator + "pom.xml] starting";
+
System.out.println( "Checking for first build" );
- int index = log.indexOf( "Building: project" );
- if ( !log.substring( index, index + 18 ).equals( "Building: project3" ) )
+ int index = log.indexOf( "] starting" );
+ int lineStart = log.lastIndexOf( "[project", index );
+ if ( lineStart < 0 || !log.substring( lineStart ).startsWith(
project3Start ) )
{
- System.out.println( "FAILED!\n" + log.substring( index, index + 18 ) );
+ System.out.println( "FAILED!\n" + log.substring( lineStart < 0 ? 0 :
lineStart, index + 10 ) );
return false;
}
System.out.println( "Checking for duplicate build" );
- index = log.indexOf( "Building: project3", index + 1 );
+ index = log.indexOf( project3Start, lineStart + 1 );
if ( index >= 0 )
{
System.out.println( "FAILED!" );
return false;
}
- int indexProject3 = log.indexOf( "Building: project3" );
- int indexProject6 = log.indexOf( "Building: project6" );
+ int indexProject3 = log.indexOf( project3Start );
+ int indexProject6 = log.indexOf( project6Start );
if(indexProject3 > indexProject6)
{
System.out.println( "FAILED! project3 should be build before project6"
);
diff --git a/src/it/rerun-build/verify.groovy b/src/it/rerun-build/verify.groovy
index 154be42..57ff5f2 100644
--- a/src/it/rerun-build/verify.groovy
+++ b/src/it/rerun-build/verify.groovy
@@ -27,11 +27,11 @@ def buildLog = new File(basedir, 'build.log').text
def fs = File.separator
-assert buildLog.count("setup${fs}pom.xml ....................................
FAILED") == 1
-assert buildLog.count("setup${fs}pom.xml ....................................
SUCCESS") == 1
+assert buildLog.count("[setup${fs}pom.xml] FAILED") == 1
+assert buildLog.count("[setup${fs}pom.xml] SUCCESS") == 1
-assert buildLog.count("project${fs}pom.xml ..................................
FAILED") == 1
-assert buildLog.count("project${fs}pom.xml ..................................
SUCCESS") == 1
+assert buildLog.count("[project${fs}pom.xml] FAILED") == 1
+assert buildLog.count("[project${fs}pom.xml] SUCCESS") == 1
def setupBuildLog1 = new File(basedir, 'target/it/setup/build.log.1').text
assert setupBuildLog1.count("[INFO] BUILD SUCCESS") == 1
diff --git a/src/it/script-streamLogs/verify.groovy
b/src/it/script-streamLogs/verify.groovy
index 298e1b5..b73825f 100644
--- a/src/it/script-streamLogs/verify.groovy
+++ b/src/it/script-streamLogs/verify.groovy
@@ -46,23 +46,23 @@ for ( String itDir : [ 'its-stream-false',
'its-stream-true' ] ) {
// streamLogs=false: failed scripts show no output in the build log
def notStreamed = buildLog.substring(0, second)
// beanshell failed and no log message
-assert !notStreamed.contains('[INFO] Output form beanshell script')
-assert notStreamed.contains('[INFO]
org.apache.maven.shared.scriptinterpreter.ScriptEvaluationException:
java.lang.OutOfMemoryError: Requested array size exceeds VM limit')
-assert notStreamed.contains('[INFO] beanshell' + FS + 'pom.xml
................................ FAILED')
+assert !notStreamed.contains('Output form beanshell script')
+assert notStreamed.contains('[INFO] [beanshell' + FS + 'pom.xml]
org.apache.maven.shared.scriptinterpreter.ScriptEvaluationException:
java.lang.OutOfMemoryError: Requested array size exceeds VM limit')
+assert notStreamed.contains('[INFO] [beanshell' + FS + 'pom.xml] FAILED')
// groovy failed and no log message
-assert !notStreamed.contains('[INFO] Output from groovy script')
+assert !notStreamed.contains('Output from groovy script')
assert notStreamed.contains('Assertion failed:')
assert notStreamed.contains('assert
pom.contains("<modelVersion>9.9.9</modelVersion>")')
-assert notStreamed.contains('[INFO] groovy' + FS + 'pom.xml
................................... FAILED')
+assert notStreamed.contains('[INFO] [groovy' + FS + 'pom.xml] FAILED')
// streamLogs=true: the output of the failed scripts is in the build log
def streamed = buildLog.substring(second)
// beanshell failed and log message
-assert streamed.contains('[INFO] Output form beanshell script')
+assert streamed.contains('[INFO] [beanshell' + FS + 'pom.xml] Output form
beanshell script')
assert streamed.contains('java.lang.OutOfMemoryError: Requested array size
exceeds VM limit')
-assert streamed.contains('[INFO] beanshell' + FS + 'pom.xml
................................ FAILED')
+assert streamed.contains('[INFO] [beanshell' + FS + 'pom.xml] FAILED')
// groovy failed and log message
-assert streamed.contains('[INFO] Output from groovy script')
+assert streamed.contains('[INFO] [groovy' + FS + 'pom.xml] Output from groovy
script')
assert streamed.contains('Assertion failed:')
assert streamed.contains('assert
pom.contains("<modelVersion>9.9.9</modelVersion>")')
-assert streamed.contains('[INFO] groovy' + FS + 'pom.xml
................................... FAILED')
+assert streamed.contains('[INFO] [groovy' + FS + 'pom.xml] FAILED')
diff --git a/src/it/selector-conditions/verify.groovy
b/src/it/selector-conditions/verify.groovy
index e4dd549..753d711 100644
--- a/src/it/selector-conditions/verify.groovy
+++ b/src/it/selector-conditions/verify.groovy
@@ -30,11 +30,11 @@ assert !(new File(basedir,
'target/its/toolchain-mismatch/build.log').exists())
def log = new File( basedir, 'build.log').text
-assert log.contains("jre-version-match${FS}pom.xml ........................
SUCCESS")
-assert log.contains("jre-version-mismatch${FS}pom.xml .....................
SKIPPED due to JRE version")
-assert log.contains("maven-version-match${FS}pom.xml ......................
SUCCESS")
-assert log.contains("maven-version-mismatch${FS}pom.xml ...................
SKIPPED due to Maven version")
-assert log.contains("os-family-match${FS}pom.xml ..........................
SUCCESS")
-assert log.contains("os-family-mismatch${FS}pom.xml .......................
SKIPPED due to OS")
-assert log.contains("toolchain-match${FS}pom.xml ..........................
SUCCESS")
-assert log.contains("toolchain-mismatch${FS}pom.xml .......................
SKIPPED due to Toolchain")
+assert log.contains("[jre-version-match${FS}pom.xml] SUCCESS")
+assert log.contains("[jre-version-mismatch${FS}pom.xml] SKIPPED due to JRE
version")
+assert log.contains("[maven-version-match${FS}pom.xml] SUCCESS")
+assert log.contains("[maven-version-mismatch${FS}pom.xml] SKIPPED due to Maven
version")
+assert log.contains("[os-family-match${FS}pom.xml] SUCCESS")
+assert log.contains("[os-family-mismatch${FS}pom.xml] SKIPPED due to OS")
+assert log.contains("[toolchain-match${FS}pom.xml] SUCCESS")
+assert log.contains("[toolchain-mismatch${FS}pom.xml] SKIPPED due to
Toolchain")
diff --git
a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
index 4866bb0..a1f7c91 100644
--- a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
+++ b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
@@ -83,7 +83,6 @@ import
org.apache.maven.shared.invoker.MavenInvocationException;
import org.apache.maven.shared.scriptinterpreter.ScriptException;
import org.apache.maven.shared.scriptinterpreter.ScriptReturnException;
import org.apache.maven.shared.scriptinterpreter.ScriptRunner;
-import org.apache.maven.shared.utils.logging.MessageBuilder;
import org.apache.maven.toolchain.ToolchainManager;
import org.codehaus.plexus.interpolation.InterpolationException;
import org.codehaus.plexus.interpolation.Interpolator;
@@ -126,11 +125,6 @@ public abstract class AbstractInvokerMojo extends
AbstractMojo {
*/
static final String SPLIT_LOCAL_REPOSITORY_PROPERTY =
"aether.enhancedLocalRepository.split";
- /**
- * The zero-based column index where to print the invoker result.
- */
- private static final int RESULT_COLUMN = 60;
-
/**
* Flag used to suppress certain invocations. This is useful in tailoring
the build using profiles.
*
@@ -1665,7 +1659,11 @@ public abstract class AbstractInvokerMojo extends
AbstractMojo {
// FIXME: Think about the following code part -- ^^^^^^^ END
- getLog().info(buffer().a("Building:
").strong(buildJob.getProject()).build());
+ // every console line emitted on behalf of this job carries its
project path, so the output of jobs
+ // running in parallel stays attributable when it interleaves
(MINVOKER-684)
+ String logPrefix = "[" + buildJob.getProject() + "] ";
+
+ getLog().info(logPrefix + "starting");
File interpolatedPomFile = null;
try {
@@ -1683,7 +1681,7 @@ public abstract class AbstractInvokerMojo extends
AbstractMojo {
long startTime = System.currentTimeMillis();
boolean executed;
- FileLogger buildLogger = setupBuildLogFile(basedir,
buildJob.getExecutionCount());
+ FileLogger buildLogger = setupBuildLogFile(basedir,
buildJob.getExecutionCount(), logPrefix);
if (buildLogger != null) {
buildJob.setBuildlog(buildLogger.getOutputFile().getAbsolutePath());
}
@@ -1705,14 +1703,14 @@ public abstract class AbstractInvokerMojo extends
AbstractMojo {
buildJob.setFailureMessage(null);
if (!suppressSummaries) {
- getLog().info(pad(buildJob).success("SUCCESS").a(' ')
+ "("
+
getLog().info(buffer().a(logPrefix).success("SUCCESS").a(' ') + "("
+ formatElapsedTime(buildJob.getTime()) + ")");
}
} else {
buildJob.setResult(BuildJob.Result.SKIPPED);
if (!suppressSummaries) {
- getLog().info(pad(buildJob).warning("SKIPPED").a(' ')
+ "("
+
getLog().info(buffer().a(logPrefix).warning("SKIPPED").a(' ') + "("
+ formatElapsedTime(buildJob.getTime()) + ")");
}
}
@@ -1740,7 +1738,7 @@ public abstract class AbstractInvokerMojo extends
AbstractMojo {
String message = String.join(", ", messages);
if (!suppressSummaries) {
- getLog().info(pad(buildJob).warning("SKIPPED") + " due to
" + message);
+ getLog().info(buffer().a(logPrefix).warning("SKIPPED") + "
due to " + message);
}
// Abuse failureMessage, the field in the report which should
contain the reason for skipping
@@ -1752,16 +1750,17 @@ public abstract class AbstractInvokerMojo extends
AbstractMojo {
buildJob.setFailureMessage(e.getMessage());
if (!suppressSummaries) {
- getLog().info(" " + e.getMessage());
- getLog().info(pad(buildJob).failure("FAILED").a(' ') + "(" +
formatElapsedTime(buildJob.getTime())
- + ")");
+ getLog().info(logPrefix + e.getMessage());
+ getLog().info(buffer().a(logPrefix).failure("FAILED").a(' ') +
"("
+ + formatElapsedTime(buildJob.getTime()) + ")");
}
} catch (Exception | Error e) {
// The report is written below while the exception is still
propagating, so the result has to be set here.
buildJob.setResult(BuildJob.Result.ERROR);
buildJob.setFailureMessage(String.valueOf(e));
- getLog().error(pad(buildJob).failure("ERROR").a(' ') + "(" +
formatElapsedTime(buildJob.getTime()) + ")");
+ getLog().error(buffer().a(logPrefix).failure("ERROR").a(' ') + "("
+ formatElapsedTime(buildJob.getTime())
+ + ")");
getLog().error(" " + e);
throw e;
} finally {
@@ -1770,28 +1769,6 @@ public abstract class AbstractInvokerMojo extends
AbstractMojo {
}
}
- private MessageBuilder pad(BuildJob buildJob) {
- MessageBuilder buffer = buffer(128);
-
- buffer.a(" ");
- buffer.a(buildJob.getProject());
-
- int l = 10 + buildJob.getProject().length();
-
- if (l < RESULT_COLUMN) {
- buffer.a(' ');
- l++;
-
- if (l < RESULT_COLUMN) {
- for (int i = RESULT_COLUMN - l; i > 0; i--) {
- buffer.a('.');
- }
- }
- }
-
- return buffer.a(' ');
- }
-
/**
* Delete the interpolated pom file if it has been created before.
*
@@ -2159,10 +2136,12 @@ public abstract class AbstractInvokerMojo extends
AbstractMojo {
*
* @param basedir The base directory of the project, must not be
<code>null</code>.
* @param executionCount current execution count of the build job, used to
determine whether to append to or create a new log file
+ * @param logPrefix prefix prepended to every line mirrored to the mojo
logger, never affects the content
+ * written to {@code build.log}.
* @return The build logger or <code>null</code> if logging has been
disabled.
* @throws org.apache.maven.plugin.MojoExecutionException If the log file
could not be created.
*/
- FileLogger setupBuildLogFile(File basedir, int executionCount) throws
MojoExecutionException {
+ FileLogger setupBuildLogFile(File basedir, int executionCount, String
logPrefix) throws MojoExecutionException {
FileLogger logger = null;
if (!noLog) {
@@ -2192,7 +2171,7 @@ public abstract class AbstractInvokerMojo extends
AbstractMojo {
getLog().debug("Renaming existing log file " + logPath + "
to " + logFileBackup);
Files.move(logPath, logFileBackup,
StandardCopyOption.REPLACE_EXISTING);
}
- logger = new FileLogger(logPath.toFile(), streamLogger);
+ logger = new FileLogger(logPath.toFile(), streamLogger,
logPrefix);
getLog().debug("New build log initialized: " + logPath);
} catch (IOException e) {
throw new MojoExecutionException("Error initializing build
logfile in: " + projectLogDirectory, e);
diff --git a/src/main/java/org/apache/maven/plugins/invoker/FileLogger.java
b/src/main/java/org/apache/maven/plugins/invoker/FileLogger.java
index 1a0d535..6f6011c 100644
--- a/src/main/java/org/apache/maven/plugins/invoker/FileLogger.java
+++ b/src/main/java/org/apache/maven/plugins/invoker/FileLogger.java
@@ -23,6 +23,7 @@ import java.io.IOException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.shared.invoker.InvocationOutputHandler;
+import org.apache.maven.shared.scriptinterpreter.FileLoggerMirrorHandler;
/**
*
@@ -37,6 +38,32 @@ class FileLogger extends
org.apache.maven.shared.scriptinterpreter.FileLogger im
* @throws IOException If the output file could not be created.
*/
FileLogger(File outputFile, final Log log) throws IOException {
- super(outputFile, log != null ? log::info : null);
+ this(outputFile, log, null);
+ }
+
+ /**
+ * Creates a new logger that writes to the specified file and optionally
mirrors messages to the given mojo
+ * logger, prefixing every mirrored line with {@code logPrefix}. The file
content is never prefixed, only the
+ * lines mirrored to the mojo logger, which is how per-job output stays
attributable when several jobs run in
+ * parallel and interleave on the console.
+ *
+ * @param outputFile The path to the output file, must not be
<code>null</code>.
+ * @param log The mojo logger to additionally output messages to, may be
<code>null</code> if not used.
+ * @param logPrefix The prefix to prepend to every line mirrored to the
mojo logger, may be <code>null</code> or
+ * empty if no prefix is needed.
+ * @throws IOException If the output file could not be created.
+ */
+ FileLogger(File outputFile, final Log log, final String logPrefix) throws
IOException {
+ super(outputFile, toMirrorHandler(log, logPrefix));
+ }
+
+ private static FileLoggerMirrorHandler toMirrorHandler(final Log log,
final String logPrefix) {
+ if (log == null) {
+ return null;
+ }
+ if (logPrefix == null || logPrefix.isEmpty()) {
+ return log::info;
+ }
+ return line -> log.info(logPrefix + line);
}
}
diff --git
a/src/test/java/org/apache/maven/plugins/invoker/BuildOutputFilesTest.java
b/src/test/java/org/apache/maven/plugins/invoker/BuildOutputFilesTest.java
index 403eb00..95af0ab 100644
--- a/src/test/java/org/apache/maven/plugins/invoker/BuildOutputFilesTest.java
+++ b/src/test/java/org/apache/maven/plugins/invoker/BuildOutputFilesTest.java
@@ -66,7 +66,7 @@ class BuildOutputFilesTest {
setVariableValueToObject(
mojo, "logDirectory",
tempDir.resolve("target/it-logs").toFile());
- closeLogger(mojo.setupBuildLogFile(module, 1));
+ closeLogger(mojo.setupBuildLogFile(module, 1, ""));
assertThat(tempDir.resolve("target/it-logs/module/build.log")).isRegularFile();
assertThat(tempDir.resolve("target/it/module/build.log")).doesNotExist();
@@ -81,7 +81,7 @@ class BuildOutputFilesTest {
assertThat(ReflectionUtils.getValueIncludingSuperclasses("cloneProjectsTo",
mojo))
.isNull();
- closeLogger(mojo.setupBuildLogFile(project, 1));
+ closeLogger(mojo.setupBuildLogFile(project, 1, ""));
assertThat(tempDir.resolve("src/it/clone-none/build.log")).isRegularFile();
}