1 package org.apache.maven.plugin.dependency;
2
3 import org.apache.maven.plugin.Mojo;
4 import org.apache.maven.plugin.logging.Log;
5
6 import java.io.File;
7 import java.io.PrintWriter;
8 import java.io.StringWriter;
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 public class TestSkip
30 extends AbstractDependencyMojoTestCase
31 {
32 public void testSkipAnalyze()
33 throws Exception
34 {
35 doTest("analyze");
36 }
37
38 public void testSkipAnalyzeDepMgt()
39 throws Exception
40 {
41 doTest("analyze-dep-mgt");
42 }
43
44 public void testSkipAnalyzeOnly()
45 throws Exception
46 {
47 doTest("analyze-only");
48 }
49
50 public void testSkipAnalyzeReport()
51 throws Exception
52 {
53 doSpecialTest("analyze-report");
54 }
55
56 public void testSkipAnalyzeDuplicate()
57 throws Exception
58 {
59 doTest("analyze-duplicate");
60 }
61
62 public void testSkipBuildClasspath()
63 throws Exception
64 {
65 doTest("build-classpath");
66 }
67
68 public void testSkipCopy()
69 throws Exception
70 {
71 doTest("copy");
72 }
73
74 public void testSkipCopyDependencies()
75 throws Exception
76 {
77 doTest("copy-dependencies");
78 }
79
80 public void testSkipGet()
81 throws Exception
82 {
83 doSpecialTest("get");
84 }
85
86 public void testSkipGoOffline()
87 throws Exception
88 {
89 doTest("go-offline");
90 }
91
92 public void testSkipList()
93 throws Exception
94 {
95 doTest("list");
96 }
97
98 public void testSkipProperties()
99 throws Exception
100 {
101 doTest("properties");
102 }
103
104 public void testSkipPurgeLocalRepository()
105 throws Exception
106 {
107 doTest("purge-local-repository");
108 }
109
110 public void testSkipResolve()
111 throws Exception
112 {
113 doTest("resolve");
114 }
115
116 public void testSkipResolvePlugins()
117 throws Exception
118 {
119 doTest("resolve-plugins");
120 }
121
122 public void testSkipSources()
123 throws Exception
124 {
125 doTest("sources");
126 }
127
128 public void testSkipTree()
129 throws Exception
130 {
131 doTest("tree");
132 }
133
134 public void testSkipUnpack()
135 throws Exception
136 {
137 doTest("unpack");
138 }
139
140 public void testSkipUnpackDependencies()
141 throws Exception
142 {
143 doTest("unpack-dependencies");
144 }
145
146
147 protected void doTest(String mojoName)
148 throws Exception
149 {
150 doConfigTest(mojoName, "plugin-config.xml");
151 }
152
153 protected void doSpecialTest(String mojoName)
154 throws Exception
155 {
156 doConfigTest(mojoName, "plugin-" + mojoName + "-config.xml");
157 }
158
159 private void doConfigTest(String mojoName, String configFile)
160 throws Exception
161 {
162 File testPom =
163 new File( getBasedir(), "target/test-classes/unit/skip-test/" + configFile );
164 Mojo mojo = lookupMojo( mojoName, testPom );
165 assertNotNull( mojo );
166 CapturingLog log = new CapturingLog();
167 mojo.setLog( log );
168 mojo.execute();
169
170 assertTrue( log.getContent().indexOf( "Skipping plugin execution" ) != -1 );
171 }
172
173 class CapturingLog
174 implements Log
175 {
176 StringBuilder sb = new StringBuilder();
177
178
179 public void debug( CharSequence content )
180 {
181 print( "debug", content );
182 }
183
184
185 public void debug( CharSequence content, Throwable error )
186 {
187 print( "debug", content, error );
188 }
189
190
191 public void debug( Throwable error )
192 {
193 print( "debug", error );
194 }
195
196
197 public void info( CharSequence content )
198 {
199 print( "info", content );
200 }
201
202
203 public void info( CharSequence content, Throwable error )
204 {
205 print( "info", content, error );
206 }
207
208
209 public void info( Throwable error )
210 {
211 print( "info", error );
212 }
213
214
215 public void warn( CharSequence content )
216 {
217 print( "warn", content );
218 }
219
220
221 public void warn( CharSequence content, Throwable error )
222 {
223 print( "warn", content, error );
224 }
225
226
227 public void warn( Throwable error )
228 {
229 print( "warn", error );
230 }
231
232
233 public void error( CharSequence content )
234 {
235 System.err.println( "[error] " + content.toString() );
236 }
237
238
239 public void error( CharSequence content, Throwable error )
240 {
241 StringWriter sWriter = new StringWriter();
242 PrintWriter pWriter = new PrintWriter( sWriter );
243
244 error.printStackTrace( pWriter );
245
246 System.err.println( "[error] " + content.toString() + "\n\n" + sWriter.toString() );
247 }
248
249
250
251
252 public void error( Throwable error )
253 {
254 StringWriter sWriter = new StringWriter();
255 PrintWriter pWriter = new PrintWriter( sWriter );
256
257 error.printStackTrace( pWriter );
258
259 System.err.println( "[error] " + sWriter.toString() );
260 }
261
262
263
264
265 public boolean isDebugEnabled()
266 {
267
268 return false;
269 }
270
271
272
273
274 public boolean isInfoEnabled()
275 {
276 return true;
277 }
278
279
280
281
282 public boolean isWarnEnabled()
283 {
284 return true;
285 }
286
287
288
289
290 public boolean isErrorEnabled()
291 {
292 return true;
293 }
294
295 private void print( String prefix, CharSequence content )
296 {
297 sb.append( "[" + prefix + "] " ).append( content.toString() ).append( "\n" );
298 }
299
300 private void print( String prefix, Throwable error )
301 {
302 StringWriter sWriter = new StringWriter();
303 PrintWriter pWriter = new PrintWriter( sWriter );
304
305 error.printStackTrace( pWriter );
306
307 sb.append( "[" + prefix + "] " ).append( sWriter.toString() ).append( "\n" );
308 }
309
310 private void print( String prefix, CharSequence content, Throwable error )
311 {
312 StringWriter sWriter = new StringWriter();
313 PrintWriter pWriter = new PrintWriter( sWriter );
314
315 error.printStackTrace( pWriter );
316
317 sb.append( "[" + prefix + "] " ).append( content.toString() ).append( "\n\n" )
318 .append( sWriter.toString() ).append( "\n" );
319 }
320
321 protected String getContent()
322 {
323 return sb.toString();
324 }
325 }
326
327 }