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.*;
26
27
28
29
30 public class MavenITmng6173GetAllProjectsInReactorTest
31 extends AbstractMavenIntegrationTestCase
32 {
33
34 public MavenITmng6173GetAllProjectsInReactorTest()
35 {
36 super( "[3.2.1,3.3.1),[3.5.0-alpha-2,)" );
37 }
38
39
40
41
42
43
44
45 public void testitShouldReturnAllProjectsInReactor()
46 throws Exception
47 {
48
49 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-6173-get-all-projects-in-reactor" );
50
51 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
52 verifier.setAutoclean( false );
53 verifier.deleteDirectory( "target" );
54 verifier.deleteDirectory( "module-1/target" );
55 verifier.deleteDirectory( "module-2/target" );
56 verifier.addCliOption( "-pl" );
57 verifier.addCliOption( "module-1" );
58 verifier.executeGoal( "validate" );
59 verifier.verifyErrorFreeLog();
60 verifier.resetStreams();
61
62 Properties properties = verifier.loadProperties( "module-1/target/session.properties" );
63 assertEquals( "3", properties.getProperty( "session.allProjects.size" ) );
64 assertEquals( Arrays.asList( new String[]{ "base-project", "module-1", "module-2" } ),
65 getProjects( properties ) );
66 }
67
68 private List<String> getProjects(Properties properties )
69 {
70 List<String> projects = new ArrayList<>();
71
72 for ( Object o : properties.keySet() )
73 {
74 String key = o.toString();
75 if ( key.startsWith( "session.allProjects." ) && !key.endsWith( ".size" ) )
76 {
77 projects.add( properties.getProperty( key ) );
78 }
79 }
80
81 Collections.sort( projects );
82
83 return projects;
84 }
85
86 }