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 java.io.File;
23 import java.util.Arrays;
24 import java.util.Collections;
25 import java.util.HashSet;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.Set;
29
30 import org.apache.maven.it.util.ResourceExtractor;
31
32
33
34
35
36
37
38
39 public class MavenITmng5669ReadPomsOnce
40 extends AbstractMavenIntegrationTestCase
41 {
42
43 public MavenITmng5669ReadPomsOnce()
44 {
45 super( "[4.0.0-alpha-1,)" );
46 }
47
48 public void testWithoutBuildConsumer()
49 throws Exception
50 {
51
52 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5669-read-poms-once" );
53 Verifier verifier = newVerifier( testDir.getAbsolutePath(), false );
54 Map<String, String> filterProperties =
55 Collections.singletonMap( "${javaAgentJar}",
56 verifier.getArtifactPath( "mng-coreit", "javaagent", "1.0-SNAPSHOT", "jar" ) );
57 verifier.filterFile( ".mvn/jvm.config", ".mvn/jvm.config", null, filterProperties );
58
59 verifier.setForkJvm( true );
60 verifier.setMavenDebug( false );
61 verifier.setAutoclean( false );
62 verifier.addCliOption( "-q" );
63 verifier.addCliOption( "-U" );
64 verifier.addCliOption( "-Dmaven.experimental.buildconsumer=false" );
65 verifier.executeGoals( Arrays.asList( "verify" ) );
66 verifier.resetStreams();
67
68 List<String> logTxt = verifier.loadLines( "log.txt", "utf-8" );
69 for ( String line : logTxt )
70 {
71 if ( line.startsWith( "Picked up JAVA_TOOL_OPTIONS:" ) )
72 {
73 logTxt.remove( line );
74 break;
75 }
76 }
77 assertEquals( logTxt.toString(), 168, logTxt.size() );
78
79
80 Set<String> uniqueBuildingSources = new HashSet<>( 168 );
81 final String buildSourceKey = "org.apache.maven.model.building.source=";
82 final int keyLength = buildSourceKey.length();
83 for ( String line : logTxt )
84 {
85 int start = line.indexOf( buildSourceKey );
86 if ( start < 0 )
87 {
88 continue;
89 }
90
91 int end = line.indexOf( ", ", start );
92 if ( end < 0 )
93 {
94 end = line.length() - 1;
95 }
96 uniqueBuildingSources.add( line.substring( start + keyLength, end ) );
97 }
98 assertEquals( uniqueBuildingSources.size(), 167 );
99 }
100
101 public void testWithBuildConsumer()
102 throws Exception
103 {
104
105 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5669-read-poms-once" );
106 Verifier verifier = newVerifier( testDir.getAbsolutePath(), false );
107 Map<String, String> filterProperties =
108 Collections.singletonMap( "${javaAgentJar}",
109 verifier.getArtifactPath( "mng-coreit", "javaagent", "1.0-SNAPSHOT", "jar" ) );
110 verifier.filterFile( ".mvn/jvm.config", ".mvn/jvm.config", null, filterProperties );
111
112 verifier.setLogFileName( "log-bc.txt" );
113 verifier.setForkJvm( true );
114 verifier.setMavenDebug( false );
115 verifier.setAutoclean( false );
116 verifier.addCliOption( "-q" );
117 verifier.addCliOption( "-U" );
118 verifier.addCliOption( "-Dmaven.experimental.buildconsumer=true" );
119 verifier.executeGoals( Arrays.asList( "verify" ) );
120 verifier.resetStreams();
121
122 List<String> logTxt = verifier.loadLines( "log-bc.txt", "utf-8" );
123 for ( String line : logTxt )
124 {
125 if ( line.startsWith( "Picked up JAVA_TOOL_OPTIONS:" ) )
126 {
127 logTxt.remove( line );
128 break;
129 }
130 }
131 assertEquals( logTxt.toString(), 168 + 4 ,
132 logTxt.size() );
133
134
135 Set<String> uniqueBuildingSources = new HashSet<>( 168 );
136 final String buildSourceKey = "org.apache.maven.model.building.source=";
137 final int keyLength = buildSourceKey.length();
138 for ( String line : logTxt )
139 {
140 int start = line.indexOf( buildSourceKey );
141 if ( start < 0 )
142 {
143 continue;
144 }
145
146 int end = line.indexOf( ", ", start );
147 if ( end < 0 )
148 {
149 end = line.length() - 1;
150 }
151 uniqueBuildingSources.add( line.substring( start + keyLength, end ) );
152 }
153 assertEquals( uniqueBuildingSources.size(), 167 );
154 }
155
156 }