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.List;
26  
27  public class MavenITmng6981ProjectListShouldIncludeChildrenTest
28          extends AbstractMavenIntegrationTestCase
29  {
30  
31      private static final String RESOURCE_PATH = "/mng-6981-pl-should-include-children";
32  
33      public MavenITmng6981ProjectListShouldIncludeChildrenTest()
34      {
35          super( "[4.0.0-alpha-1,)" );
36      }
37  
38      public void testProjectListShouldIncludeChildrenByDefault()
39              throws Exception
40      {
41          final File testDir = ResourceExtractor.simpleExtractResources( getClass(), RESOURCE_PATH );
42          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
43  
44          verifier.addCliOption( "-pl" );
45          verifier.addCliOption( ":module-a" );
46          verifier.executeGoal( "compile" );
47          verifier.verifyTextInLog( "Building module-a-1 1.0" );
48      }
49  
50      /**
51       * Since --pl's behavior is changed, make sure the alternative for building a pom without its children still works.
52       *
53       * @throws Exception in case of failure
54       */
55      public void testFileSwitchAllowsExcludeOfChildren()
56              throws Exception
57      {
58          final File testDir = ResourceExtractor.simpleExtractResources( getClass(), RESOURCE_PATH );
59          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
60  
61          verifier.addCliOption( "-f" );
62          verifier.addCliOption( "module-a" );
63          verifier.addCliOption( "--non-recursive" );
64          verifier.setLogFileName( "log-non-recursive.txt" );
65          verifier.executeGoal( "compile" );
66          verifyTextNotInLog( verifier, "Building module-a-1 1.0" );
67      }
68  
69      /**
70       * Throws an exception if the text <strong>is</strong> present in the log.
71       *
72       * @param verifier the verifier to use
73       * @param text the text to assert present
74       * @throws VerificationException if text is not found in log
75       */
76      private void verifyTextNotInLog( Verifier verifier, String text )
77              throws VerificationException
78      {
79          List<String> lines = verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false );
80  
81          for ( String line : lines )
82          {
83              if ( Verifier.stripAnsi( line ).contains( text ) )
84              {
85                  throw new VerificationException( "Text found in log: " + text );
86              }
87          }
88      }
89  }