View Javadoc
1   package org.apache.maven.plugins.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         doSpecialTest( "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 = new File( getBasedir(), "target/test-classes/unit/skip-test/" + configFile );
162         Mojo mojo = lookupMojo( mojoName, testPom );
163         assertNotNull( mojo );
164         CapturingLog log = new CapturingLog();
165         mojo.setLog( log );
166         mojo.execute();
167 
168         assertTrue( log.getContent().contains( "Skipping plugin execution" ) );
169     }
170 
171     class CapturingLog
172         implements Log
173     {
174         StringBuilder sb = new StringBuilder();
175 
176         /** {@inheritDoc} */
177         public void debug( CharSequence content )
178         {
179             print( "debug", content );
180         }
181 
182         /** {@inheritDoc} */
183         public void debug( CharSequence content, Throwable error )
184         {
185             print( "debug", content, error );
186         }
187 
188         /** {@inheritDoc} */
189         public void debug( Throwable error )
190         {
191             print( "debug", error );
192         }
193 
194         /** {@inheritDoc} */
195         public void info( CharSequence content )
196         {
197             print( "info", content );
198         }
199 
200         /** {@inheritDoc} */
201         public void info( CharSequence content, Throwable error )
202         {
203             print( "info", content, error );
204         }
205 
206         /** {@inheritDoc} */
207         public void info( Throwable error )
208         {
209             print( "info", error );
210         }
211 
212         /** {@inheritDoc} */
213         public void warn( CharSequence content )
214         {
215             print( "warn", content );
216         }
217 
218         /** {@inheritDoc} */
219         public void warn( CharSequence content, Throwable error )
220         {
221             print( "warn", content, error );
222         }
223 
224         /** {@inheritDoc} */
225         public void warn( Throwable error )
226         {
227             print( "warn", error );
228         }
229 
230         /** {@inheritDoc} */
231         public void error( CharSequence content )
232         {
233             System.err.println( "[error] " + content.toString() );
234         }
235 
236         /** {@inheritDoc} */
237         public void error( CharSequence content, Throwable error )
238         {
239             StringWriter sWriter = new StringWriter();
240             PrintWriter pWriter = new PrintWriter( sWriter );
241 
242             error.printStackTrace( pWriter );
243 
244             System.err.println( "[error] " + content.toString() + "\n\n" + sWriter.toString() );
245         }
246 
247         /**
248          * @see org.apache.maven.plugin.logging.Log#error(java.lang.Throwable)
249          */
250         public void error( Throwable error )
251         {
252             StringWriter sWriter = new StringWriter();
253             PrintWriter pWriter = new PrintWriter( sWriter );
254 
255             error.printStackTrace( pWriter );
256 
257             System.err.println( "[error] " + sWriter.toString() );
258         }
259 
260         /**
261          * @see org.apache.maven.plugin.logging.Log#isDebugEnabled()
262          */
263         public boolean isDebugEnabled()
264         {
265             // TODO: Not sure how best to set these for this implementation...
266             return false;
267         }
268 
269         /**
270          * @see org.apache.maven.plugin.logging.Log#isInfoEnabled()
271          */
272         public boolean isInfoEnabled()
273         {
274             return true;
275         }
276 
277         /**
278          * @see org.apache.maven.plugin.logging.Log#isWarnEnabled()
279          */
280         public boolean isWarnEnabled()
281         {
282             return true;
283         }
284 
285         /**
286          * @see org.apache.maven.plugin.logging.Log#isErrorEnabled()
287          */
288         public boolean isErrorEnabled()
289         {
290             return true;
291         }
292 
293         private void print( String prefix, CharSequence content )
294         {
295             sb.append( "[" ).append( prefix ).append( "] " ).append( content.toString() ).append( "\n" );
296         }
297 
298         private void print( String prefix, Throwable error )
299         {
300             StringWriter sWriter = new StringWriter();
301             PrintWriter pWriter = new PrintWriter( sWriter );
302 
303             error.printStackTrace( pWriter );
304 
305             sb.append( "[" ).append( prefix ).append( "] " ).append( sWriter.toString() ).append( "\n" );
306         }
307 
308         private void print( String prefix, CharSequence content, Throwable error )
309         {
310             StringWriter sWriter = new StringWriter();
311             PrintWriter pWriter = new PrintWriter( sWriter );
312 
313             error.printStackTrace( pWriter );
314 
315             sb.append( "[" ).append( prefix ).append( "] " ).append( content.toString() ).append( "\n\n" ).append( sWriter.toString() ).append( "\n" );
316         }
317 
318         protected String getContent()
319         {
320             return sb.toString();
321         }
322     }
323 
324 }