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 java.io.File;
23  import java.util.List;
24  
25  import org.apache.maven.it.util.ResourceExtractor;
26  
27  public class MavenITmng5581LifecycleMappingDelegate
28      extends AbstractMavenIntegrationTestCase
29  {
30      public MavenITmng5581LifecycleMappingDelegate()
31      {
32          super( "[3.2.1,)" );
33      }
34  
35      public void testCustomLifecycle()
36          throws Exception
37      {
38          /*
39           * This test comes in two parts, a build extension project that defines custom lifecycle with corresponding
40           * lifecycle mapping delegate, and a test project used to validate the custom lifecycle. The custom lifecycle id
41           * is "test-only", it has single build phase "test-only" and lifecycle mapping delegate that picks default
42           * surefire-plugin execution out of all mojos configured in project pom.xml. The test asserts it is possible to
43           * run "test-only" build phase and that it does not run maven-compiler-plugin.
44           */
45  
46          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5581-lifecycle-mapping-delegate" );
47          File extensionDir = new File( testDir, "extension" );
48          File projectDir = new File( testDir, "basic" );
49  
50          Verifier verifier;
51  
52          // install the test extension
53          verifier = newVerifier( extensionDir.getAbsolutePath(), "remote" );
54          verifier.executeGoal( "install" );
55          verifier.resetStreams();
56          verifier.verifyErrorFreeLog();
57  
58          // compile the test project
59          verifier = newVerifier( projectDir.getAbsolutePath(), "remote" );
60          verifier.executeGoal( "compile" );
61          verifier.resetStreams();
62          verifier.verifyErrorFreeLog();
63  
64          // run custom "test-only" build phase
65          verifier.setForkJvm( true );
66          verifier.setMavenDebug( true );
67          verifier.executeGoal( "test-only" );
68          verifier.resetStreams();
69          verifier.verifyErrorFreeLog();
70          verifier.verifyTextInLog( "maven-surefire-plugin" );
71          verifyTextNotInLog( verifier, "maven-compiler-plugin" );
72      }
73  
74      private void verifyTextNotInLog( Verifier verifier, String text )
75          throws VerificationException
76      {
77          List<String> lines = verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false );
78  
79          boolean textFound = false;
80          for ( String line : lines )
81          {
82              if ( line.contains( text ) )
83              {
84                  textFound = true;
85                  break;
86              }
87          }
88          if ( textFound )
89          {
90              throw new VerificationException( "Text found in log: " + text );
91          }
92      }
93  
94  }