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  import static org.hamcrest.MatcherAssert.assertThat;
28  import static org.hamcrest.Matchers.is;
29  
30  public class MavenITmng6566ExecuteAnnotationShouldNotReExecuteGoalsTest
31      extends AbstractMavenIntegrationTestCase
32  {
33      private static final String RESOURCE_PATH = "/mng-6566-execute-annotation-should-not-re-execute-goals";
34      private static final String PLUGIN_KEY = "org.apache.maven.its.mng6566:plugin:1.0-SNAPSHOT";
35  
36      private File testDir;
37  
38      public MavenITmng6566ExecuteAnnotationShouldNotReExecuteGoalsTest()
39      {
40          super( "[4.0.0-alpha-1,)" );
41      }
42  
43      public void setUp()
44              throws Exception
45      {
46          testDir = ResourceExtractor.simpleExtractResources( getClass(), RESOURCE_PATH );
47  
48          File pluginDir = new File( testDir, "plugin" );
49          Verifier verifier = newVerifier( pluginDir.getAbsolutePath(), "remote" );
50          verifier.executeGoal( "install" );
51          verifier.resetStreams();
52          verifier.verifyErrorFreeLog();
53      }
54  
55      public void testRunsCompileGoalOnceWithDirectPluginInvocation()
56              throws Exception
57      {
58          File consumerDir = new File( testDir, "consumer" );
59  
60          Verifier verifier = newVerifier( consumerDir.getAbsolutePath() );
61          verifier.setLogFileName( "log-direct-plugin-invocation.txt" );
62          verifier.executeGoal( PLUGIN_KEY + ":require-compile-phase" );
63          verifier.resetStreams();
64          verifier.verifyErrorFreeLog();
65  
66          assertCompiledOnce( verifier );
67          verifier.verifyTextInLog( "MNG-6566 plugin require-compile-phase goal executed" );
68      }
69  
70      /**
71       * This test uses the <pre>require-compile-phase</pre> goal of the test plugin.
72       *
73       * @throws Exception in case of failure
74       */
75      public void testRunsCompileGoalOnceWithPhaseExecution()
76              throws Exception
77      {
78          File consumerDir = new File( testDir, "consumer" );
79  
80          Verifier verifier = newVerifier( consumerDir.getAbsolutePath() );
81          verifier.setLogFileName( "log-phase-execution.txt" );
82          verifier.executeGoal( "compile" );
83          verifier.resetStreams();
84          verifier.verifyErrorFreeLog();
85  
86          assertCompiledOnce( verifier );
87          verifier.verifyTextInLog( "MNG-6566 plugin require-compile-phase goal executed" );
88      }
89  
90      private void assertCompiledOnce( Verifier verifier )
91              throws VerificationException
92      {
93          List<String> lines = verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false );
94          int counter = 0;
95          for ( String line : lines )
96          {
97              if ( line.contains( "maven-compiler-plugin:0.1-stub-SNAPSHOT:compile") )
98              {
99                  counter++;
100             }
101         }
102         assertThat( "Compile goal was expected to run once", counter, is( 1 ) );
103     }
104 }