View Javadoc
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   * Licensed to the Apache Software Foundation (ASF) under one
12   * or more contributor license agreements.  See the NOTICE file
13   * distributed with this work for additional information
14   * regarding copyright ownership.  The ASF licenses this file
15   * to you under the Apache License, Version 2.0 (the
16   * "License"); you may not use this file except in compliance
17   * with the License.  You may obtain a copy of the License at
18   *
19   *  http://www.apache.org/licenses/LICENSE-2.0
20   *
21   * Unless required by applicable law or agreed to in writing,
22   * software distributed under the License is distributed on an
23   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
24   * KIND, either express or implied.  See the License for the
25   * specific language governing permissions and limitations
26   * under the License.
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     protected void doTest( String mojoName )
147         throws Exception
148     {
149         doConfigTest( mojoName, "plugin-config.xml" );
150     }
151 
152     protected void doSpecialTest( String mojoName )
153         throws Exception
154     {
155         doConfigTest( mojoName, "plugin-" + mojoName + "-config.xml" );
156     }
157 
158     private void doConfigTest( String mojoName, String configFile )
159         throws Exception
160     {
161         File testPom =
162             new File( getBasedir(), "target/test-classes/unit/skip-test/" + configFile );
163         Mojo mojo = lookupMojo( mojoName, testPom );
164         assertNotNull( mojo );
165         CapturingLog log = new CapturingLog();
166         mojo.setLog( log );
167         mojo.execute();
168 
169         assertTrue(log.getContent().contains("Skipping plugin execution"));
170     }
171 
172     class CapturingLog
173         implements Log
174     {
175         StringBuilder sb = new StringBuilder();
176 
177         /** {@inheritDoc} */
178         public void debug( CharSequence content )
179         {
180             print( "debug", content );
181         }
182 
183         /** {@inheritDoc} */
184         public void debug( CharSequence content, Throwable error )
185         {
186             print( "debug", content, error );
187         }
188 
189         /** {@inheritDoc} */
190         public void debug( Throwable error )
191         {
192             print( "debug", error );
193         }
194 
195         /** {@inheritDoc} */
196         public void info( CharSequence content )
197         {
198             print( "info", content );
199         }
200 
201         /** {@inheritDoc} */
202         public void info( CharSequence content, Throwable error )
203         {
204             print( "info", content, error );
205         }
206 
207         /** {@inheritDoc} */
208         public void info( Throwable error )
209         {
210             print( "info", error );
211         }
212 
213         /** {@inheritDoc} */
214         public void warn( CharSequence content )
215         {
216             print( "warn", content );
217         }
218 
219         /** {@inheritDoc} */
220         public void warn( CharSequence content, Throwable error )
221         {
222             print( "warn", content, error );
223         }
224 
225         /** {@inheritDoc} */
226         public void warn( Throwable error )
227         {
228             print( "warn", error );
229         }
230 
231         /** {@inheritDoc} */
232         public void error( CharSequence content )
233         {
234             System.err.println( "[error] " + content.toString() );
235         }
236 
237         /** {@inheritDoc} */
238         public void error( CharSequence content, Throwable error )
239         {
240             StringWriter sWriter = new StringWriter();
241             PrintWriter pWriter = new PrintWriter( sWriter );
242 
243             error.printStackTrace( pWriter );
244 
245             System.err.println( "[error] " + content.toString() + "\n\n" + sWriter.toString() );
246         }
247 
248         /**
249          * @see org.apache.maven.plugin.logging.Log#error(java.lang.Throwable)
250          */
251         public void error( Throwable error )
252         {
253             StringWriter sWriter = new StringWriter();
254             PrintWriter pWriter = new PrintWriter( sWriter );
255 
256             error.printStackTrace( pWriter );
257 
258             System.err.println( "[error] " + sWriter.toString() );
259         }
260 
261         /**
262          * @see org.apache.maven.plugin.logging.Log#isDebugEnabled()
263          */
264         public boolean isDebugEnabled()
265         {
266             // TODO: Not sure how best to set these for this implementation...
267             return false;
268         }
269 
270         /**
271          * @see org.apache.maven.plugin.logging.Log#isInfoEnabled()
272          */
273         public boolean isInfoEnabled()
274         {
275             return true;
276         }
277 
278         /**
279          * @see org.apache.maven.plugin.logging.Log#isWarnEnabled()
280          */
281         public boolean isWarnEnabled()
282         {
283             return true;
284         }
285 
286         /**
287          * @see org.apache.maven.plugin.logging.Log#isErrorEnabled()
288          */
289         public boolean isErrorEnabled()
290         {
291             return true;
292         }
293 
294         private void print( String prefix, CharSequence content )
295         {
296             sb.append("[").append(prefix).append("] ").append(content.toString()).append( "\n" );
297         }
298 
299         private void print( String prefix, Throwable error )
300         {
301             StringWriter sWriter = new StringWriter();
302             PrintWriter pWriter = new PrintWriter( sWriter );
303 
304             error.printStackTrace( pWriter );
305 
306             sb.append("[").append(prefix).append("] ").append(sWriter.toString()).append( "\n" );
307         }
308 
309         private void print( String prefix, CharSequence content, Throwable error )
310         {
311             StringWriter sWriter = new StringWriter();
312             PrintWriter pWriter = new PrintWriter( sWriter );
313 
314             error.printStackTrace( pWriter );
315 
316             sb.append("[").append(prefix).append("] ").append(content.toString()).append( "\n\n" )
317                 .append( sWriter.toString() ).append( "\n" );
318         }
319 
320         protected String getContent()
321         {
322             return sb.toString();
323         }
324     }
325 
326 }