View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.dependency;
20  
21  import javax.inject.Inject;
22  
23  import org.apache.maven.api.plugin.testing.InjectMojo;
24  import org.apache.maven.api.plugin.testing.MojoParameter;
25  import org.apache.maven.api.plugin.testing.MojoTest;
26  import org.apache.maven.model.Plugin;
27  import org.apache.maven.plugin.Mojo;
28  import org.apache.maven.plugin.MojoExecution;
29  import org.apache.maven.plugin.logging.Log;
30  import org.apache.maven.plugins.dependency.analyze.AnalyzeDepMgt;
31  import org.apache.maven.plugins.dependency.analyze.AnalyzeDuplicateMojo;
32  import org.apache.maven.plugins.dependency.analyze.AnalyzeMojo;
33  import org.apache.maven.plugins.dependency.analyze.AnalyzeOnlyMojo;
34  import org.apache.maven.plugins.dependency.analyze.AnalyzeReport;
35  import org.apache.maven.plugins.dependency.fromConfiguration.CopyMojo;
36  import org.apache.maven.plugins.dependency.fromConfiguration.UnpackMojo;
37  import org.apache.maven.plugins.dependency.fromDependencies.BuildClasspathMojo;
38  import org.apache.maven.plugins.dependency.fromDependencies.CopyDependenciesMojo;
39  import org.apache.maven.plugins.dependency.fromDependencies.UnpackDependenciesMojo;
40  import org.apache.maven.plugins.dependency.resolvers.GoOfflineMojo;
41  import org.apache.maven.plugins.dependency.resolvers.ListMojo;
42  import org.apache.maven.plugins.dependency.resolvers.OldResolveDependencySourcesMojo;
43  import org.apache.maven.plugins.dependency.resolvers.ResolveDependenciesMojo;
44  import org.apache.maven.plugins.dependency.resolvers.ResolvePluginsMojo;
45  import org.apache.maven.plugins.dependency.tree.TreeMojo;
46  import org.junit.jupiter.api.Test;
47  
48  import static org.mockito.ArgumentMatchers.contains;
49  import static org.mockito.Mockito.verify;
50  import static org.mockito.Mockito.when;
51  
52  @MojoTest
53  class TestSkip {
54  
55      @Inject
56      private MojoExecution mojoExecution;
57  
58      @Inject
59      private Log log;
60  
61      @Test
62      @InjectMojo(goal = "analyze")
63      @MojoParameter(name = "skip", value = "true")
64      void testSkipAnalyze(AnalyzeMojo mojo) throws Exception {
65          doTest(mojo);
66      }
67  
68      @Test
69      @InjectMojo(goal = "analyze-dep-mgt")
70      @MojoParameter(name = "skip", value = "true")
71      void testSkipAnalyzeDepMgt(AnalyzeDepMgt mojo) throws Exception {
72          doTest(mojo);
73      }
74  
75      @Test
76      @InjectMojo(goal = "analyze-only")
77      @MojoParameter(name = "skip", value = "true")
78      void testSkipAnalyzeOnly(AnalyzeOnlyMojo mojo) throws Exception {
79          doTest(mojo);
80      }
81  
82      @Test
83      @InjectMojo(goal = "analyze-report")
84      @MojoParameter(name = "skip", value = "true")
85      void testSkipAnalyzeReport(AnalyzeReport mojo) throws Exception {
86          Plugin plugin = new Plugin();
87          plugin.setArtifactId("maven-dependency-plugin");
88          plugin.setVersion("1.0.0");
89          when(mojoExecution.getPlugin()).thenReturn(plugin);
90          when(mojoExecution.getGoal()).thenReturn("analyze-report");
91  
92          mojo.execute();
93          verify(log)
94                  .info(contains(
95                          "Skipping org.apache.maven.plugins:maven-dependency-plugin:1.0.0:analyze-report report goal"));
96      }
97  
98      @Test
99      @InjectMojo(goal = "analyze-duplicate")
100     @MojoParameter(name = "skip", value = "true")
101     void testSkipAnalyzeDuplicate(AnalyzeDuplicateMojo mojo) throws Exception {
102         doTest(mojo);
103     }
104 
105     @Test
106     @InjectMojo(goal = "build-classpath")
107     @MojoParameter(name = "skip", value = "true")
108     void testSkipBuildClasspath(BuildClasspathMojo mojo) throws Exception {
109         doTest(mojo);
110     }
111 
112     @Test
113     @InjectMojo(goal = "copy")
114     @MojoParameter(name = "skip", value = "true")
115     void testSkipCopy(CopyMojo mojo) throws Exception {
116         doTest(mojo);
117     }
118 
119     @Test
120     @InjectMojo(goal = "copy-dependencies")
121     @MojoParameter(name = "skip", value = "true")
122     void testSkipCopyDependencies(CopyDependenciesMojo mojo) throws Exception {
123         doTest(mojo);
124     }
125 
126     @Test
127     @InjectMojo(goal = "get")
128     @MojoParameter(name = "skip", value = "true")
129     void testSkipGet(GetMojo mojo) throws Exception {
130         doTest(mojo);
131     }
132 
133     @Test
134     @InjectMojo(goal = "go-offline")
135     @MojoParameter(name = "skip", value = "true")
136     void testSkipGoOffline(GoOfflineMojo mojo) throws Exception {
137         doTest(mojo);
138     }
139 
140     @Test
141     @InjectMojo(goal = "list")
142     @MojoParameter(name = "skip", value = "true")
143     void testSkipList(ListMojo mojo) throws Exception {
144         doTest(mojo);
145     }
146 
147     @Test
148     @InjectMojo(goal = "properties")
149     @MojoParameter(name = "skip", value = "true")
150     void testSkipProperties(PropertiesMojo mojo) throws Exception {
151         doTest(mojo);
152     }
153 
154     @Test
155     @InjectMojo(goal = "purge-local-repository")
156     @MojoParameter(name = "skip", value = "true")
157     void testSkipPurgeLocalRepository(PurgeLocalRepositoryMojo mojo) throws Exception {
158         doTest(mojo);
159     }
160 
161     @Test
162     @InjectMojo(goal = "resolve")
163     @MojoParameter(name = "skip", value = "true")
164     void testSkipResolve(ResolveDependenciesMojo mojo) throws Exception {
165         doTest(mojo);
166     }
167 
168     @Test
169     @InjectMojo(goal = "resolve-plugins")
170     @MojoParameter(name = "skip", value = "true")
171     void testSkipResolvePlugins(ResolvePluginsMojo mojo) throws Exception {
172         doTest(mojo);
173     }
174 
175     @Test
176     @InjectMojo(goal = "sources")
177     @MojoParameter(name = "skip", value = "true")
178     void testSkipSources(OldResolveDependencySourcesMojo mojo) throws Exception {
179         doTest(mojo);
180     }
181 
182     @Test
183     @InjectMojo(goal = "tree")
184     @MojoParameter(name = "skip", value = "true")
185     void testSkipTree(TreeMojo mojo) throws Exception {
186         doTest(mojo);
187     }
188 
189     @Test
190     @InjectMojo(goal = "unpack")
191     @MojoParameter(name = "skip", value = "true")
192     void testSkipUnpack(UnpackMojo mojo) throws Exception {
193         doTest(mojo);
194     }
195 
196     @Test
197     @InjectMojo(goal = "unpack-dependencies")
198     @MojoParameter(name = "skip", value = "true")
199     void testSkipUnpackDependencies(UnpackDependenciesMojo mojo) throws Exception {
200         doTest(mojo);
201     }
202 
203     private void doTest(Mojo mojo) throws Exception {
204         mojo.execute();
205         verify(log).info(contains("Skipping plugin"));
206     }
207 }