1 package org.apache.maven.it;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
31
32
33
34
35
36
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
49
50
51
52
53
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
73 assertEquals( 4, resultingLines.size() );
74
75
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
85
86
87
88
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
108 assertEquals( 4, resultingLines.size() );
109
110
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
121
122
123
124
125
126
127
128
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 }