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.*;
26  
27  /**
28   * Test case for <a href="https://issues.apache.org/jira/browse/MNG-6173">MNG-6173</a>.
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       * Verifies that {@code MavenSession#getAllProjects()} returns all projects in the reactor
41       * not only they ones being built.
42       *
43       * @throws Exception in case of failure
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  }