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