exec-maven-plugin icon indicating copy to clipboard operation
exec-maven-plugin copied to clipboard

Only prefix program output with thread name when running with multiple threads

Open hankolerd opened this issue 5 years ago • 1 comments

This is a follow-up to some review comments in Pull Request #153 (for Issue #152) after it had been merged.

Attaching the owning thread name to program output as a prefix will only occur if the Maven session is running with 2 or more threads (i.e. session.isParallel()). Otherwise no log prefix is attached.

Examples Below is sample output of two modules in a reactor with the following plugin execution configured:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <version>3.0.1-SNAPSHOT</version>
  <executions>
    <execution>
      <id>test</id>
      <phase>compile</phase>
      <goals>
        <goal>exec</goal>
      </goals>
      <configuration>
        <executable>bash</executable>
        <arguments>
          <argument>-c</argument>
          <argument><![CDATA[
            for i in {1..100}
            do
              echo "${project.artifactId} - $i"
            done
          ]]></argument>
        </arguments>
      </configuration>
    </execution>
  </executions>
</plugin>

Example 1. Default behavior, single-thread: mvn clean install

module1 - 56
module1 - 57
...
module2 - 61
module2 - 62
...

Example 2. Default behavior, multi-thread: mvn clean install -T 2

...
module1 - 53
2m o-d u8l0e
module2 - 81
module2 - 812
 m-o d5u4l
module1 - 55
...

Example 3. With Maven Logger option enabled, single-thread: mvn clean install -Dexec.useMavenLogger=true

13:22:22.491 [Exec Stream Pumper] [INFO] module1 - 56
13:22:22.492 [Exec Stream Pumper] [INFO] module1 - 57
...
13:22:22.692 [Exec Stream Pumper] [INFO] module2 - 61
13:22:22.692 [Exec Stream Pumper] [INFO] module2 - 62

Example 4. With Maven Logger option enabled, multi-thread: mvn clean install -T 2 -Dexec.useMavenLogger=true

...
13:23:43.808 [Exec Stream Pumper] [INFO] [BuilderThread 1] module1 - 53
13:23:43.808 [Exec Stream Pumper] [INFO] [BuilderThread 2] module2 - 58
13:23:43.808 [Exec Stream Pumper] [INFO] [BuilderThread 1] module1 - 54
13:23:43.808 [Exec Stream Pumper] [INFO] [BuilderThread 2] module2 - 59
...

NOTE: In these last 2 examples, My Maven installation is configured to always print timestamp and thread name before Maven log output.

hankolerd avatar Jun 18 '20 20:06 hankolerd

interesting! happy to merge. do you mind resolving conflicts?

olamy avatar Jul 12 '22 07:07 olamy