View Javadoc
1   package org.apache.maven.it;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.it.util.ResourceExtractor;
23  
24  import java.io.File;
25  import java.util.LinkedList;
26  import java.util.List;
27  
28  /**
29   * Using a <code>${revision}</code> in the version will change the reactor order before fixing
30   * <a href="https://issues.apache.org/jira/browse/MNG-6057">MNG-6057</a>. Without the fix for this issue the order of
31   * the reactor is changed in that way that the parent is ordered to the last position instead of the first position.
32   *
33   * @author Karl Heinz Marbaise khmarbaise@apache.org
34   */
35  public class MavenITmng6057CheckReactorOrderTest
36      extends AbstractMavenIntegrationTestCase
37  {
38  
39      public MavenITmng6057CheckReactorOrderTest()
40      {
41          // The first version which contains the fix for the MNG-6057 issue.
42          // TODO: Think about it!
43          super( "[3.5.0-alpha-2,)" );
44      }
45  
46      /**
47       * Verify that the result shows the reactor order as expected.
48       *
49       * @throws Exception in case of failure
50       */
51      public void testitReactorShouldResultInExpectedOrder()
52          throws Exception
53      {
54          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-6057-check-reactor-order" );
55  
56          Verifier verifier = newVerifier( testDir.getAbsolutePath(), false );
57          verifier.setMavenDebug( false );
58          verifier.setAutoclean( false );
59  
60          verifier.setLogFileName( "log-only.txt" );
61          verifier.addCliOption( "-Drevision=1.3.0-SNAPSHOT" );
62          verifier.executeGoal( "clean" );
63          verifier.verifyErrorFreeLog();
64          verifier.resetStreams();
65  
66          List<String> loadedLines = verifier.loadLines( "log-only.txt", "UTF-8" );
67          List<String> resultingLines = extractReactorBuildOrder( loadedLines );
68  
69          // We expecting exactly three lines as result.
70          assertEquals( 3, resultingLines.size() );
71  
72          // We expect those lines in the following exact order.
73          assertTrue( resultingLines.get( 0 ).startsWith( "[INFO] base-project" ) );
74          assertTrue( resultingLines.get( 1 ).startsWith( "[INFO] module-1" ) );
75          assertTrue( resultingLines.get( 2 ).startsWith( "[INFO] module-2" ) );
76      }
77  
78      /**
79       * Extract the lines at the beginning of the Maven output:
80       *
81       * <pre>
82       * [INFO] Reactor Build Order:
83       * [INFO]
84       * [INFO] module-1
85       * [INFO] module-2
86       * [INFO] base-project
87       * [INFO]
88       * </pre>
89       */
90      private List<String> extractReactorBuildOrder( List<String> loadedLines )
91      {
92          List<String> resultingLines = new LinkedList<String>();
93          boolean start = false;
94          for ( String line : loadedLines )
95          {
96              if ( start )
97              {
98                  if ( line.startsWith( "[INFO] -------------" ) )
99                  {
100                     start = false;
101                 }
102                 else if ( !line.endsWith( "[INFO] " ) )
103                 {
104                     resultingLines.add( line );
105                 }
106             }
107             else
108             {
109                 if ( line.startsWith( "[INFO] Reactor Build Order:" ) )
110                 {
111                     start = true;
112                 }
113 
114             }
115         }
116         return resultingLines;
117 
118     }
119 
120 }