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.ArrayList;
26 import java.util.Arrays;
27 import java.util.Collections;
28 import java.util.List;
29 import java.util.Properties;
30
31
32
33
34
35
36 public class MavenITmng0187CollectedProjectsTest
37 extends AbstractMavenIntegrationTestCase
38 {
39
40 public MavenITmng0187CollectedProjectsTest()
41 {
42 super( ALL_MAVEN_VERSIONS );
43 }
44
45
46
47
48
49
50
51 public void testit()
52 throws Exception
53 {
54 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-0187" );
55
56 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
57 verifier.setAutoclean( false );
58 verifier.deleteDirectory( "target" );
59 verifier.deleteDirectory( "sub-1/target" );
60 verifier.deleteDirectory( "sub-1/sub-2/target" );
61 verifier.executeGoal( "validate" );
62 verifier.verifyErrorFreeLog();
63 verifier.resetStreams();
64
65 Properties props;
66
67 props = verifier.loadProperties( "target/project.properties" );
68 assertEquals( "2", props.getProperty( "project.collectedProjects.size" ) );
69 assertEquals( Arrays.asList( new String[]{ "sub-1", "sub-2" } ), getProjects( props ) );
70
71 props = verifier.loadProperties( "sub-1/target/project.properties" );
72 assertEquals( "1", props.getProperty( "project.collectedProjects.size" ) );
73 assertEquals( Arrays.asList( new String[]{ "sub-2" } ), getProjects( props ) );
74
75 props = verifier.loadProperties( "sub-1/sub-2/target/project.properties" );
76 assertEquals( "0", props.getProperty( "project.collectedProjects.size" ) );
77 assertEquals( Arrays.asList( new String[]{} ), getProjects( props ) );
78 }
79
80 private List<String> getProjects( Properties props )
81 {
82 List<String> projects = new ArrayList<>();
83
84 for ( Object o : props.keySet() )
85 {
86 String key = o.toString();
87 if ( key.startsWith( "project.collectedProjects." ) && !key.endsWith( ".size" ) )
88 {
89 projects.add( props.getProperty( key ) );
90 }
91 }
92
93 Collections.sort( projects );
94
95 return projects;
96 }
97
98 }