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.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
72
73
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 }