|
21 | 21 | import java.io.File; |
22 | 22 |
|
23 | 23 | import org.apache.maven.execution.MavenSession; |
| 24 | +import org.apache.maven.model.Plugin; |
24 | 25 | import org.apache.maven.plugin.Mojo; |
| 26 | +import org.apache.maven.plugin.MojoExecution; |
| 27 | +import org.apache.maven.plugin.descriptor.MojoDescriptor; |
| 28 | +import org.apache.maven.plugin.descriptor.PluginDescriptor; |
25 | 29 | import org.apache.maven.plugin.logging.Log; |
26 | 30 | import org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub; |
27 | 31 | import org.apache.maven.project.MavenProject; |
@@ -56,7 +60,7 @@ public void testSkipAnalyzeOnly() throws Exception { |
56 | 60 | } |
57 | 61 |
|
58 | 62 | public void testSkipAnalyzeReport() throws Exception { |
59 | | - doSpecialTest("analyze-report"); |
| 63 | + doSpecialTest("analyze-report", true); |
60 | 64 | } |
61 | 65 |
|
62 | 66 | public void testSkipAnalyzeDuplicate() throws Exception { |
@@ -124,19 +128,55 @@ protected void doTest(String mojoName) throws Exception { |
124 | 128 | } |
125 | 129 |
|
126 | 130 | protected void doSpecialTest(String mojoName) throws Exception { |
127 | | - doConfigTest(mojoName, "plugin-" + mojoName + "-config.xml"); |
| 131 | + doConfigTest(mojoName, "plugin-" + mojoName + "-config.xml", false); |
| 132 | + } |
| 133 | + |
| 134 | + protected void doSpecialTest(String mojoName, boolean addMojoExecution) throws Exception { |
| 135 | + doConfigTest(mojoName, "plugin-" + mojoName + "-config.xml", addMojoExecution); |
128 | 136 | } |
129 | 137 |
|
130 | 138 | private void doConfigTest(String mojoName, String configFile) throws Exception { |
| 139 | + doConfigTest(mojoName, configFile, false); |
| 140 | + } |
| 141 | + |
| 142 | + private void doConfigTest(String mojoName, String configFile, boolean addMojoExecution) throws Exception { |
131 | 143 | File testPom = new File(getBasedir(), "target/test-classes/unit/skip-test/" + configFile); |
132 | 144 | Mojo mojo = lookupMojo(mojoName, testPom); |
133 | | - assertNotNull(mojo); |
| 145 | + assertNotNull("Mojo not found.", mojo); |
| 146 | + |
| 147 | + if (addMojoExecution) { |
| 148 | + setVariableValueToObject(mojo, "mojoExecution", getMockMojoExecution(mojoName)); |
| 149 | + } |
134 | 150 | Log log = mock(Log.class); |
135 | 151 | mojo.setLog(log); |
136 | 152 | mojo.execute(); |
137 | 153 |
|
138 | 154 | ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class); |
139 | 155 | verify(log, atLeastOnce()).info(captor.capture()); |
140 | | - assertTrue(captor.getValue().contains("Skipping plugin execution")); |
| 156 | + String skipMessage; |
| 157 | + if (addMojoExecution) { |
| 158 | + MojoExecution me = getMockMojoExecution(mojoName); |
| 159 | + String reportMojoInfo = me.getPlugin().getId() + ":" + me.getGoal(); |
| 160 | + skipMessage = "Skipping " + reportMojoInfo + " report goal"; |
| 161 | + } else { |
| 162 | + skipMessage = "Skipping plugin execution"; |
| 163 | + } |
| 164 | + assertTrue(captor.getValue().contains(skipMessage)); |
| 165 | + } |
| 166 | + |
| 167 | + private MojoExecution getMockMojoExecution(String goal) { |
| 168 | + MojoDescriptor md = new MojoDescriptor(); |
| 169 | + md.setGoal(goal); |
| 170 | + |
| 171 | + MojoExecution me = new MojoExecution(md); |
| 172 | + |
| 173 | + PluginDescriptor pd = new PluginDescriptor(); |
| 174 | + Plugin p = new Plugin(); |
| 175 | + p.setGroupId("org.apache.maven.plugins"); |
| 176 | + p.setArtifactId("maven-dependency-plugin"); |
| 177 | + pd.setPlugin(p); |
| 178 | + md.setPluginDescriptor(pd); |
| 179 | + |
| 180 | + return me; |
141 | 181 | } |
142 | 182 | } |
0 commit comments