1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.checkstyle;
20
21 import java.io.File;
22 import java.util.List;
23
24 import org.apache.maven.model.Resource;
25 import org.apache.maven.plugins.annotations.Mojo;
26 import org.apache.maven.plugins.annotations.ResolutionScope;
27 import org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorRequest;
28 import org.apache.maven.reporting.MavenReportException;
29
30
31
32
33
34
35
36
37
38
39 @Mojo(name = "checkstyle", requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true)
40 public class CheckstyleReport extends AbstractCheckstyleReport {
41
42
43
44 protected CheckstyleExecutorRequest createRequest() throws MavenReportException {
45 CheckstyleExecutorRequest request = new CheckstyleExecutorRequest();
46 request.setConsoleListener(getConsoleListener())
47 .setConsoleOutput(consoleOutput)
48 .setExcludes(excludes)
49 .setFailsOnError(failsOnError)
50 .setIncludes(includes)
51 .setResourceIncludes(resourceIncludes)
52 .setResourceExcludes(resourceExcludes)
53 .setIncludeResources(includeResources)
54 .setIncludeTestResources(includeTestResources)
55 .setIncludeTestSourceDirectory(includeTestSourceDirectory)
56 .setListener(getListener())
57 .setProject(project)
58 .setSourceDirectories(getSourceDirectories())
59 .setResources(resources)
60 .setTestResources(testResources)
61 .setStringOutputStream(stringOutputStream)
62 .setSuppressionsLocation(suppressionsLocation)
63 .setTestSourceDirectories(getTestSourceDirectories())
64 .setPropertyExpansion(propertyExpansion)
65 .setHeaderLocation(headerLocation)
66 .setCacheFile(cacheFile)
67 .setSuppressionsFileExpression(suppressionsFileExpression)
68 .setEncoding(getInputEncoding())
69 .setPropertiesLocation(propertiesLocation);
70 return request;
71 }
72
73
74 public String getOutputName() {
75 return "checkstyle";
76 }
77
78
79 public boolean canGenerateReport() {
80 if (skip) {
81 return false;
82 }
83
84
85 for (File sourceDirectory : getSourceDirectories()) {
86 if (sourceDirectory.exists()) {
87 return true;
88 }
89 }
90
91 if (includeTestSourceDirectory) {
92 for (File testSourceDirectory : getTestSourceDirectories()) {
93 if (testSourceDirectory.exists()) {
94 return true;
95 }
96 }
97 }
98
99 return ((includeResources && hasResources(resources)) || (includeTestResources && hasResources(testResources)));
100 }
101
102
103
104
105
106
107 private boolean hasResources(List<Resource> resources) {
108 for (Resource resource : resources) {
109 if (new File(resource.getDirectory()).exists()) {
110 return true;
111 }
112 }
113 return false;
114 }
115 }