View Javadoc
1   package org.apache.maven.it;
2   
3   import java.io.File;
4   import java.util.ArrayList;
5   import java.util.Arrays;
6   import java.util.LinkedHashSet;
7   import java.util.List;
8   import java.util.Set;
9   
10  import org.apache.maven.it.util.ResourceExtractor;
11  
12  /**
13   * Test set for <a href="https://issues.apache.org/jira/browse/MNG-5965">MNG-5965</a>.
14   */
15  public class MavenITmng5965ParallelBuildMultipliesWorkTest
16      extends AbstractMavenIntegrationTestCase
17  {
18      public MavenITmng5965ParallelBuildMultipliesWorkTest()
19      {
20          super( "[3.6.1,)" );
21      }
22  
23      public void testItShouldOnlyRunEachTaskOnce()
24          throws Exception
25      {
26          File testDir =
27              ResourceExtractor.simpleExtractResources( getClass(), "/mng-5965-parallel-build-multiplies-work" );
28  
29          Verifier verifier = newVerifier( testDir.getAbsolutePath(), false );
30          verifier.setMavenDebug( false );
31          verifier.setAutoclean( false );
32  
33          verifier.setLogFileName( "log-only.txt" );
34          verifier.addCliOption( "-T1" );
35          // include an aggregator task so that the two goals end up in different task segments
36          verifier.executeGoals( Arrays.asList( "clean", "install:help" ) );
37          verifier.verifyErrorFreeLog();
38          verifier.resetStreams();
39  
40          List<String> logLines = verifier.loadLines( "log-only.txt", "UTF-8" );
41  
42          List<String> cleanGoalsExecuted = findCleanExecutions( logLines );
43  
44          // clean only executed once per module
45          assertNoRepeatedLines( cleanGoalsExecuted );
46  
47          // clean executed in the 3 modules
48          assertEquals( cleanGoalsExecuted.size(), 3 );
49      }
50  
51      private void assertNoRepeatedLines( List<String> logLines )
52          throws VerificationException
53      {
54          Set<String> uniqueLines = new LinkedHashSet<>();
55          for ( String line : logLines )
56          {
57              if ( uniqueLines.contains( line ) )
58              {
59                  throw new VerificationException( "Goal executed twice: " + line );
60              }
61              uniqueLines.add( line );
62          }
63      }
64  
65      private List<String> findCleanExecutions( List<String> fullLog )
66      {
67          List<String> cleanExecutions = new ArrayList<>();
68          for ( String line : fullLog )
69          {
70              if ( line.contains( "(default-clean)" ) )
71              {
72                  cleanExecutions.add( line );
73              }
74          }
75  
76          return cleanExecutions;
77      }
78  
79  }