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-6352">MNG-6352</a>.
35   *
36   * @author Karl Heinz Marbaise khmarbaise@apache.org
37   */
38  public class MavenITmng6352PrintVersionTest
39      extends AbstractMavenIntegrationTestCase
40  {
41  
42      public MavenITmng6352PrintVersionTest()
43      {
44          super( "[3.5.3,3.5.4]" );
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-6352-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( 4, resultingLines.size() );
74  
75          // We expect those lines in the following exact order.
76          assertTrue( resultingLines.get( 0 ).startsWith( "[INFO] base-project 1.3.0-SNAPSHOT ........................ SUCCESS [" ) );
77          assertTrue( resultingLines.get( 1 ).startsWith( "[INFO] module-1 ........................................... SUCCESS [" ) );
78          assertTrue( resultingLines.get( 2 ).startsWith( "[INFO] module-2 ........................................... SUCCESS [" ) );
79          assertTrue( resultingLines.get( 3 ).startsWith( "[INFO] module-3 1.3.0-SNAPSHOT ............................ SUCCESS [" ) );
80  
81      }
82  
83      /**
84       * Check that the resulting output is
85       * as expected for all modules in case
86       * for an aggregator build.
87       *
88       * @throws Exception in case of failure
89       */
90      public void testitShouldPrintVersionInAllLines()
91          throws Exception
92      {
93          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-6352-print-version-aggregator" );
94  
95          Verifier verifier = newVerifier( testDir.getAbsolutePath(), false );
96          verifier.setMavenDebug( false );
97          verifier.setAutoclean( false );
98  
99          verifier.setLogFileName( "version-log.txt" );
100         verifier.executeGoals( Arrays.asList( "clean" ) );
101         verifier.verifyErrorFreeLog();
102         verifier.resetStreams();
103 
104         List<String> loadedLines = verifier.loadLines( "version-log.txt", "UTF-8" );
105         List<String> resultingLines = extractReactorBuildOrder( loadedLines );
106 
107         // We expecting exactly four lines as result.
108         assertEquals( 4, resultingLines.size() );
109 
110         // We expect those lines in the following exact order.
111         assertTrue( resultingLines.get( 0 ).startsWith( "[INFO] module-1 1.2.7.43.RELEASE .......................... SUCCESS [  " ) );
112         assertTrue( resultingLines.get( 1 ).startsWith( "[INFO] module-2 7.5-SNAPSHOT .............................. SUCCESS [  " ) );
113         assertTrue( resultingLines.get( 2 ).startsWith( "[INFO] module-3 1-RC1 ..................................... SUCCESS [  " ) );
114         assertTrue( resultingLines.get( 3 ).startsWith( "[INFO] base-project 1.0.0-SNAPSHOT ........................ SUCCESS [  " ) );
115 
116     }
117 
118 
119     /**
120      * Extract the lines at the end of the Maven output:
121      *
122      * <pre>
123      * [INFO] Reactor Summary:
124      * [INFO]
125      * [INFO] ...SUCCESS [  0.035 s]
126      * [INFO] ...SUCCESS [  0.035 s]
127      * [INFO] ...SUCCESS [  0.035 s]
128      * </pre>
129      */
130     private List<String> extractReactorBuildOrder( List<String> loadedLines )
131     {
132         List<String> resultingLines = new LinkedList<String>();
133         boolean start = false;
134         for ( String line : loadedLines )
135         {
136             if ( start )
137             {
138                 if ( line.startsWith( "[INFO] -------------" ) )
139                 {
140                     start = false;
141                 }
142                 else if ( !line.endsWith( "[INFO] " ) )
143                 {
144                     resultingLines.add( line );
145                 }
146             }
147             else
148             {
149                 if ( line.startsWith( "[INFO] Reactor Summary:" ) )
150                 {
151                     start = true;
152                 }
153 
154             }
155         }
156         return resultingLines;
157 
158     }
159 
160 }