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.Arrays;
26  import java.util.LinkedList;
27  import java.util.List;
28  
29  /**
30   * An integration test to check the enhancements to print out version
31   * information during the reactor summary output at the correct
32   * positions.
33   *
34   * <a href="https://issues.apache.org/jira/browse/MNG-6391">MNG-6391</a>.
35   *
36   * @author Karl Heinz Marbaise khmarbaise@apache.org
37   */
38  public class MavenITmng6391PrintVersionTest
39      extends AbstractMavenIntegrationTestCase
40  {
41  
42      public MavenITmng6391PrintVersionTest()
43      {
44          super( "[3.6.0,)" );
45      }
46  
47      /**
48       * Check that the resulting output is
49       * as expected for the root module and last
50       * module in build but not for the intermediate
51       * modules.
52       *
53       * @throws Exception in case of failure
54       */
55      public void testitShouldPrintVersionAtTopAndAtBottom()
56          throws Exception
57      {
58          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-6391-print-version" );
59  
60          Verifier verifier = newVerifier( testDir.getAbsolutePath(), false );
61          verifier.setMavenDebug( false );
62          verifier.setAutoclean( false );
63  
64          verifier.setLogFileName( "version-log.txt" );
65          verifier.executeGoals( Arrays.asList( "clean" ) );
66          verifier.verifyErrorFreeLog();
67          verifier.resetStreams();
68  
69          List<String> loadedLines = verifier.loadLines( "version-log.txt", "UTF-8" );
70          List<String> resultingLines = extractReactorBuildOrder( loadedLines );
71  
72          // We expecting exactly four lines as result.
73          assertEquals( 5, resultingLines.size() );
74  
75          // We expect those lines in the following exact order.
76          assertTrue( resultingLines.get( 0 ).startsWith( "[INFO] Reactor Summary for base-project 1.3.0-SNAPSHOT:" ) );
77          assertTrue( resultingLines.get( 1 ).startsWith( "[INFO] base-project ....................................... SUCCESS [" ) );
78          assertTrue( resultingLines.get( 2 ).startsWith( "[INFO] module-1 ........................................... SUCCESS [" ) );
79          assertTrue( resultingLines.get( 3 ).startsWith( "[INFO] module-2 ........................................... SUCCESS [" ) );
80          assertTrue( resultingLines.get( 4 ).startsWith( "[INFO] module-3 ........................................... SUCCESS [" ) );
81  
82      }
83  
84      /**
85       * Check that the resulting output is
86       * as expected for all modules in case
87       * for an aggregator build.
88       *
89       * @throws Exception in case of failure
90       */
91      public void testitShouldPrintVersionInAllLines()
92          throws Exception
93      {
94          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-6391-print-version-aggregator" );
95  
96          Verifier verifier = newVerifier( testDir.getAbsolutePath(), false );
97          verifier.setMavenDebug( false );
98          verifier.setAutoclean( false );
99  
100         verifier.setLogFileName( "version-log.txt" );
101         verifier.executeGoals( Arrays.asList( "clean" ) );
102         verifier.verifyErrorFreeLog();
103         verifier.resetStreams();
104 
105         List<String> loadedLines = verifier.loadLines( "version-log.txt", "UTF-8" );
106         List<String> resultingLines = extractReactorBuildOrder( loadedLines );
107 
108         // We expecting exactly four lines as result.
109         assertEquals( 5, resultingLines.size() );
110 
111         // We expect those lines in the following exact order.
112         assertTrue( resultingLines.get( 0 ).startsWith( "[INFO] Reactor Summary:" ) );
113         assertTrue( resultingLines.get( 1 ).startsWith( "[INFO] module-1 1.2.7.43.RELEASE .......................... SUCCESS [  " ) );
114         assertTrue( resultingLines.get( 2 ).startsWith( "[INFO] module-2 7.5-SNAPSHOT .............................. SUCCESS [  " ) );
115         assertTrue( resultingLines.get( 3 ).startsWith( "[INFO] module-3 1-RC1 ..................................... SUCCESS [  " ) );
116         assertTrue( resultingLines.get( 4 ).startsWith( "[INFO] base-project 1.0.0-SNAPSHOT ........................ SUCCESS [  " ) );
117 
118     }
119 
120     /**
121      * Extract the lines at the end of the Maven output:
122      *
123      * <pre>
124      * [INFO] Reactor Summary..: XXX
125      * [INFO]
126      * [INFO] ...SUCCESS [  0.035 s]
127      * [INFO] ...SUCCESS [  0.035 s]
128      * [INFO] ...SUCCESS [  0.035 s]
129      * </pre>
130      */
131     private List<String> extractReactorBuildOrder( List<String> loadedLines )
132     {
133         List<String> resultingLines = new LinkedList<String>();
134         boolean start = false;
135         for ( String line : loadedLines )
136         {
137             if ( start )
138             {
139                 if ( line.startsWith( "[INFO] -------------" ) )
140                 {
141                     start = false;
142                 }
143                 else if ( !line.endsWith( "[INFO] " ) )
144                 {
145                     resultingLines.add( line );
146                 }
147             }
148             else
149             {
150                 if ( line.startsWith( "[INFO] Reactor Summary" ) )
151                 {
152                     start = true;
153                     resultingLines.add( line );
154                 }
155 
156             }
157         }
158         return resultingLines;
159 
160     }
161 
162 }