View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.pmd.exec;
20  
21  import java.io.File;
22  import java.io.Serializable;
23  import java.util.ArrayList;
24  import java.util.Collection;
25  import java.util.List;
26  
27  /**
28   * Data object to store all configuration options needed to execute PMD
29   * as a separate process.
30   *
31   * <p>This class is intended to be serialized and read back.
32   *
33   * <p>Some properties might be optional and can be <code>null</code>.
34   */
35  public class PmdRequest implements Serializable {
36      private static final long serialVersionUID = -6324416880563476455L;
37  
38      private String javaExecutable;
39  
40      private String language;
41      private String languageVersion;
42      private int minimumPriority;
43      private String auxClasspath;
44      private String suppressMarker;
45      private String analysisCacheLocation;
46      private List<String> rulesets;
47      private String sourceEncoding;
48      private List<File> files = new ArrayList<>();
49  
50      private boolean showPmdLog;
51      private String logLevel;
52      private boolean skipPmdError;
53  
54      private String excludeFromFailureFile;
55      private String targetDirectory;
56      private String outputEncoding;
57      private String format;
58      private String benchmarkOutputLocation;
59      private boolean includeXmlInSite;
60      private String reportOutputDirectory;
61  
62      /**
63       * Configure language and language version.
64       *
65       * @param language the language
66       * @param targetJdk the language version, optional, can be <code>null</code>
67       */
68      public void setLanguageAndVersion(String language, String targetJdk) {
69          if ("java".equals(language) || null == language) {
70              this.language = "java";
71              this.languageVersion = targetJdk;
72          } else if ("javascript".equals(language) || "ecmascript".equals(language)) {
73              this.language = "ecmascript";
74          } else if ("jsp".equals(language)) {
75              this.language = "jsp";
76          } else {
77              this.language = language;
78          }
79      }
80  
81      public void setJavaExecutable(String javaExecutable) {
82          this.javaExecutable = javaExecutable;
83      }
84  
85      public void setMinimumPriority(int minimumPriority) {
86          this.minimumPriority = minimumPriority;
87      }
88  
89      public void setAuxClasspath(String auxClasspath) {
90          this.auxClasspath = auxClasspath;
91      }
92  
93      public void setSuppressMarker(String suppressMarker) {
94          this.suppressMarker = suppressMarker;
95      }
96  
97      public void setAnalysisCacheLocation(String analysisCacheLocation) {
98          this.analysisCacheLocation = analysisCacheLocation;
99      }
100 
101     public void setRulesets(List<String> rulesets) {
102         this.rulesets = rulesets;
103     }
104 
105     public void setSourceEncoding(String sourceEncoding) {
106         this.sourceEncoding = sourceEncoding;
107     }
108 
109     public void addFiles(Collection<File> files) {
110         this.files.addAll(files);
111     }
112 
113     public void setBenchmarkOutputLocation(String benchmarkOutputLocation) {
114         this.benchmarkOutputLocation = benchmarkOutputLocation;
115     }
116 
117     public void setTargetDirectory(String targetDirectory) {
118         this.targetDirectory = targetDirectory;
119     }
120 
121     public void setOutputEncoding(String outputEncoding) {
122         this.outputEncoding = outputEncoding;
123     }
124 
125     public void setFormat(String format) {
126         this.format = format;
127     }
128 
129     public void setShowPmdLog(boolean showPmdLog) {
130         this.showPmdLog = showPmdLog;
131     }
132 
133     public void setLogLevel(String logLevel) {
134         this.logLevel = logLevel;
135     }
136 
137     public void setSkipPmdError(boolean skipPmdError) {
138         this.skipPmdError = skipPmdError;
139     }
140 
141     public void setIncludeXmlInSite(boolean includeXmlInSite) {
142         this.includeXmlInSite = includeXmlInSite;
143     }
144 
145     public void setReportOutputDirectory(String reportOutputDirectory) {
146         this.reportOutputDirectory = reportOutputDirectory;
147     }
148 
149     public void setExcludeFromFailureFile(String excludeFromFailureFile) {
150         this.excludeFromFailureFile = excludeFromFailureFile;
151     }
152 
153     public String getJavaExecutable() {
154         return javaExecutable;
155     }
156 
157     public String getLanguage() {
158         return language;
159     }
160 
161     public String getLanguageVersion() {
162         return languageVersion;
163     }
164 
165     public int getMinimumPriority() {
166         return minimumPriority;
167     }
168 
169     public String getAuxClasspath() {
170         return auxClasspath;
171     }
172 
173     public String getSuppressMarker() {
174         return suppressMarker;
175     }
176 
177     public String getAnalysisCacheLocation() {
178         return analysisCacheLocation;
179     }
180 
181     public List<String> getRulesets() {
182         return rulesets;
183     }
184 
185     public String getSourceEncoding() {
186         return sourceEncoding;
187     }
188 
189     public List<File> getFiles() {
190         return files;
191     }
192 
193     public String getBenchmarkOutputLocation() {
194         return benchmarkOutputLocation;
195     }
196 
197     public String getTargetDirectory() {
198         return targetDirectory;
199     }
200 
201     public String getOutputEncoding() {
202         return outputEncoding;
203     }
204 
205     public String getFormat() {
206         return format;
207     }
208 
209     public boolean isShowPmdLog() {
210         return showPmdLog;
211     }
212 
213     public String getLogLevel() {
214         return logLevel;
215     }
216 
217     public boolean isDebugEnabled() {
218         return "debug".equals(logLevel);
219     }
220 
221     public boolean isSkipPmdError() {
222         return skipPmdError;
223     }
224 
225     public boolean isIncludeXmlInSite() {
226         return includeXmlInSite;
227     }
228 
229     public String getReportOutputDirectory() {
230         return reportOutputDirectory;
231     }
232 
233     public String getExcludeFromFailureFile() {
234         return excludeFromFailureFile;
235     }
236 }