View Javadoc
1   package org.apache.maven.plugin.checkstyle.exec;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.ByteArrayOutputStream;
23  import java.io.File;
24  import java.util.Collection;
25  import java.util.Collections;
26  import java.util.List;
27  
28  import org.apache.maven.artifact.Artifact;
29  import org.apache.maven.model.Resource;
30  import org.apache.maven.plugin.logging.Log;
31  import org.apache.maven.project.MavenProject;
32  
33  import com.puppycrawl.tools.checkstyle.DefaultLogger;
34  import com.puppycrawl.tools.checkstyle.api.AuditListener;
35  
36  /**
37   * @author Olivier Lamy
38   * @since 2.5
39   * @version $Id: CheckstyleExecutorRequest.html 922623 2014-09-17 22:57:25Z hboutemy $
40   */
41  public class CheckstyleExecutorRequest
42  {
43  
44      /**
45       * Specifies the names filter of the source files to be used for Checkstyle.
46       */
47      private String includes;
48  
49      /**
50       * Specifies the names filter of the source files to be excluded for Checkstyle.
51       */
52      private String excludes;
53  
54      /**
55       * Specifies names filter for resources.
56       */
57      private String resourceIncludes;
58  
59      /**
60       * Specifies names filter for resources.
61       */
62      private String resourceExcludes;
63  
64      private MavenProject project;
65  
66      private Log log;
67  
68      private String suppressionsLocation;
69  
70      private boolean includeTestSourceDirectory;
71  
72      private Collection<File> testSourceDirectories;
73  
74      private Collection<File> sourceDirectories;
75  
76      private boolean includeResources;
77  
78      private boolean includeTestResources;
79  
80      private List<Resource> resources;
81  
82      private List<Resource> testResources;
83  
84      private boolean failsOnError;
85  
86      private AuditListener listener;
87  
88      private boolean consoleOutput;
89  
90      private DefaultLogger defaultLogger;
91  
92      private ByteArrayOutputStream stringOutputStream;
93  
94      private String propertiesLocation;
95  
96      //
97  
98      private String configLocation;
99  
100     private String propertyExpansion;
101 
102     private String headerLocation;
103 
104     private String cacheFile;
105 
106     private String suppressionsFileExpression;
107 
108     private String encoding;
109 
110     /**
111      * @since 2.8
112      */
113     private boolean aggregate = false;
114 
115     /**
116      * @since 2.8
117      */
118     private List<MavenProject> reactorProjects;
119     
120     /**
121      * @since 2.12.1
122      */
123     private List<Artifact> licenseArtifacts;
124 
125     /**
126      * @since 2.12.1
127      */
128     private List<Artifact> configurationArtifacts;
129     
130     /**
131      * Constructor.
132      */
133     public CheckstyleExecutorRequest( )
134     {
135         //nothing
136     }
137 
138     /**
139      * Returns the includes parameter.
140      *
141      * @return The includes parameter.
142      */
143     public String getIncludes()
144     {
145         return includes;
146     }
147 
148     public CheckstyleExecutorRequest setIncludes( String includes )
149     {
150         this.includes = includes;
151         return this;
152     }
153 
154     public String getExcludes()
155     {
156         return excludes;
157     }
158 
159     public CheckstyleExecutorRequest setExcludes( String excludes )
160     {
161         this.excludes = excludes;
162         return this;
163     }
164 
165     public String getResourceIncludes()
166     {
167         return resourceIncludes;
168     }
169 
170     public CheckstyleExecutorRequest setResourceIncludes( String resourceIncludes )
171     {
172         this.resourceIncludes = resourceIncludes;
173         return this;
174     }
175 
176     public String getResourceExcludes()
177     {
178         return resourceExcludes;
179     }
180 
181     public CheckstyleExecutorRequest setResourceExcludes( String resourceExcludes )
182     {
183         this.resourceExcludes = resourceExcludes;
184         return this;
185     }
186 
187     public MavenProject getProject()
188     {
189         return project;
190     }
191 
192     public CheckstyleExecutorRequest setProject( MavenProject project )
193     {
194         this.project = project;
195         return this;
196     }
197 
198     public Log getLog()
199     {
200         return log;
201     }
202 
203     public CheckstyleExecutorRequest setLog( Log log )
204     {
205         this.log = log;
206         return this;
207     }
208 
209     public String getSuppressionsLocation()
210     {
211         return suppressionsLocation;
212     }
213 
214     public CheckstyleExecutorRequest setSuppressionsLocation( String suppressionsLocation )
215     {
216         this.suppressionsLocation = suppressionsLocation;
217         return this;
218     }
219 
220     public boolean isIncludeTestSourceDirectory()
221     {
222         return includeTestSourceDirectory;
223     }
224 
225     public CheckstyleExecutorRequest setIncludeTestSourceDirectory( boolean includeTestSourceDirectory )
226     {
227         this.includeTestSourceDirectory = includeTestSourceDirectory;
228         return this;
229     }
230 
231     /**
232      * 
233      * @return first entry of testSourceDirectories, otherwise {@code null}
234      * @deprecated instead use {@link #getTestSourceDirectories()}
235      */
236     @Deprecated
237     public File getTestSourceDirectory()
238     {
239         if( testSourceDirectories == null || testSourceDirectories.size() == 0 )
240         {
241             return null;
242         }
243         else
244         {
245             return testSourceDirectories.iterator().next();
246         }
247     }
248 
249     /**
250      * 
251      * @param testSourceDirectory a single testSourceDirectory
252      * @return this request
253      * @deprecated instead use {@link #setTestSourceDirectories(Collection)}
254      */
255     @Deprecated
256     public CheckstyleExecutorRequest setTestSourceDirectory( File testSourceDirectory )
257     {
258         this.testSourceDirectories = Collections.singletonList( testSourceDirectory );
259         return this;
260     }
261     
262     public Collection<File> getTestSourceDirectories()
263     {
264         return testSourceDirectories;
265     }
266     
267     public CheckstyleExecutorRequest setTestSourceDirectories( Collection<File> testSourceDirectories )
268     {
269         this.testSourceDirectories = testSourceDirectories;
270         return this;
271     }
272     
273     /**
274      * @return first entry of sourceDirectories, otherwise {@code null}
275      * @deprecated instead use {@link #getSourceDirectories()}
276      */
277     @Deprecated
278     public File getSourceDirectory()
279     {
280         if( sourceDirectories == null || sourceDirectories.size() == 0 )
281         {
282             return null;
283         }
284         else
285         {
286             return sourceDirectories.iterator().next();
287         }
288     }
289 
290     /**
291      * 
292      * @param sourceDirectory a single sourceDirectory
293      * @return this request
294      * @deprecated instead use {@link #setSourceDirectories(Collection)}
295      */
296     @Deprecated
297     public CheckstyleExecutorRequest setSourceDirectory( File sourceDirectory )
298     {
299         this.sourceDirectories = Collections.singletonList( sourceDirectory );
300         return this;
301     }
302     
303     public Collection<File> getSourceDirectories()
304     {
305         return sourceDirectories;
306     }
307     
308     public CheckstyleExecutorRequest setSourceDirectories( Collection<File> sourceDirectories )
309     {
310         this.sourceDirectories = sourceDirectories;
311         return this;
312     }
313 
314     public List<Resource> getResources()
315     {
316         return resources;
317     }
318 
319     public CheckstyleExecutorRequest setResources( List<Resource> resources )
320     {
321         this.resources = resources;
322         return this;
323     }
324 
325     public List<Resource> getTestResources()
326     {
327         return testResources;
328     }
329 
330     public CheckstyleExecutorRequest setTestResources( List<Resource> testResources )
331     {
332         this.testResources = testResources;
333         return this;
334     }
335 
336     public boolean isFailsOnError()
337     {
338         return failsOnError;
339     }
340 
341     public CheckstyleExecutorRequest setFailsOnError( boolean failsOnError )
342     {
343         this.failsOnError = failsOnError;
344         return this;
345     }
346 
347     public AuditListener getListener()
348     {
349         return listener;
350     }
351 
352     public CheckstyleExecutorRequest setListener( AuditListener listener )
353     {
354         this.listener = listener;
355         return this;
356     }
357 
358     public boolean isConsoleOutput()
359     {
360         return consoleOutput;
361     }
362 
363     public CheckstyleExecutorRequest setConsoleOutput( boolean consoleOutput )
364     {
365         this.consoleOutput = consoleOutput;
366         return this;
367     }
368 
369     public CheckstyleExecutorRequest setConsoleListener( DefaultLogger defaultLogger )
370     {
371         this.defaultLogger = defaultLogger;
372         return this;
373     }
374 
375     public DefaultLogger getConsoleListener()
376     {
377         return this.defaultLogger;
378     }
379 
380     public ByteArrayOutputStream getStringOutputStream()
381     {
382         return stringOutputStream;
383     }
384 
385     public CheckstyleExecutorRequest setStringOutputStream( ByteArrayOutputStream stringOutputStream )
386     {
387         this.stringOutputStream = stringOutputStream;
388         return this;
389     }
390 
391     public String getConfigLocation()
392     {
393         return configLocation;
394     }
395 
396     public CheckstyleExecutorRequest setConfigLocation( String configLocation )
397     {
398         this.configLocation = configLocation;
399         return this;
400     }
401 
402     public String getPropertyExpansion()
403     {
404         return propertyExpansion;
405     }
406 
407     public CheckstyleExecutorRequest setPropertyExpansion( String propertyExpansion )
408     {
409         this.propertyExpansion = propertyExpansion;
410         return this;
411     }
412 
413     public String getHeaderLocation()
414     {
415         return headerLocation;
416     }
417 
418     public CheckstyleExecutorRequest setHeaderLocation( String headerLocation )
419     {
420         this.headerLocation = headerLocation;
421         return this;
422     }
423 
424     public String getCacheFile()
425     {
426         return cacheFile;
427     }
428 
429     public CheckstyleExecutorRequest setCacheFile( String cacheFile )
430     {
431         this.cacheFile = cacheFile;
432         return this;
433     }
434 
435     public String getSuppressionsFileExpression()
436     {
437         return suppressionsFileExpression;
438     }
439 
440     public CheckstyleExecutorRequest setSuppressionsFileExpression( String suppressionsFileExpression )
441     {
442         this.suppressionsFileExpression = suppressionsFileExpression;
443         return this;
444     }
445 
446     public String getEncoding()
447     {
448         return encoding;
449     }
450 
451     public CheckstyleExecutorRequest setEncoding( String encoding )
452     {
453         this.encoding = encoding;
454         return this;
455     }
456 
457     public String getPropertiesLocation()
458     {
459         return propertiesLocation;
460     }
461 
462     public void setPropertiesLocation( String propertiesLocation )
463     {
464         this.propertiesLocation = propertiesLocation;
465     }
466 
467     /**
468      * Returns true if the report is aggregated.
469      *
470      * @return <code>true</code> if the report is aggregated.
471      */
472     public boolean isAggregate()
473     {
474         return aggregate;
475     }
476 
477     /**
478      * Sets the aggregate parameter.
479      *
480      * @param pAggregate <code>true</code> if an aggregated report is desired.
481      * @return This object.
482      */
483     public CheckstyleExecutorRequest setAggregate( boolean pAggregate )
484     {
485         this.aggregate = pAggregate;
486         return this;
487     }
488 
489     /**
490      * Returns the list of reactor projects.
491      *
492      * @return The reactor projects.
493      */
494     public List<MavenProject> getReactorProjects()
495     {
496         return reactorProjects;
497     }
498 
499     /**
500      * Sets the list of reactor projects.
501      *
502      * @param pReactorProjects The reactor projects.
503      * @return This object.
504      */
505     public CheckstyleExecutorRequest setReactorProjects( List<MavenProject> pReactorProjects )
506     {
507         this.reactorProjects = pReactorProjects;
508         return this;
509     }
510 
511     /**
512      * Returns a list of license artifacts, which may contain the license.
513      * 
514      * @return the license artifacts
515      */
516     public List<Artifact> getLicenseArtifacts()
517     {
518         return licenseArtifacts;
519     }
520 
521     /**
522      * Sets a list of license artifacts, which may contain the license.
523      * 
524      * @param licenseArtifacts
525      * @return This object.
526      */
527     public CheckstyleExecutorRequest setLicenseArtifacts( List<Artifact> licenseArtifacts )
528     {
529         this.licenseArtifacts = licenseArtifacts;
530         return this;
531     }
532     
533     /**
534      * Returns a list of artifacts, which may contain the checkstyle configuration.
535      * 
536      * @return the license artifacts
537      */
538     public List<Artifact> getConfigurationArtifacts()
539     {
540         return configurationArtifacts;
541     }
542 
543     /**
544      * Sets a list of artifacts, which may contain the checkstyle configuration.
545      * 
546      * @param configArtifacts
547      * @return This object.
548      */
549     public CheckstyleExecutorRequest setConfigurationArtifacts( List<Artifact> configArtifacts )
550     {
551         this.configurationArtifacts = configArtifacts;
552         return this;
553     }
554     
555     public boolean isIncludeResources()
556     {
557         return includeResources;
558     }
559 
560     /**
561      * @param includeResources whether to include the resource directories in the checks.
562      * @return This object.
563      */
564     public CheckstyleExecutorRequest setIncludeResources( boolean includeResources )
565     {
566         this.includeResources = includeResources;
567         return this;
568     }
569 
570     public boolean isIncludeTestResources()
571     {
572         return includeTestResources;
573     }
574 
575     /**
576      * @param includeTestResources whether to set the test resource directories in the checks.
577      * @return This object.
578      */
579     public CheckstyleExecutorRequest setIncludeTestResources( boolean includeTestResources )
580     {
581         this.includeTestResources = includeTestResources;
582         return this;
583     }
584 }