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 String logLevel;
51      private boolean skipPmdError;
52  
53      private String excludeFromFailureFile;
54      private String targetDirectory;
55      private String outputEncoding;
56      private String format;
57      private String benchmarkOutputLocation;
58      private boolean includeXmlInSite;
59      private String reportOutputDirectory;
60  
61      /**
62       * Configure language and language version.
63       *
64       * @param language the language
65       * @param targetJdk the language version, optional, can be <code>null</code>
66       */
67      public void setLanguageAndVersion(String language, String targetJdk) {
68          if ("java".equals(language) || null == language) {
69              this.language = "java";
70              this.languageVersion = targetJdk;
71          } else if ("javascript".equals(language) || "ecmascript".equals(language)) {
72              this.language = "ecmascript";
73          } else if ("jsp".equals(language)) {
74              this.language = "jsp";
75          } else {
76              this.language = language;
77          }
78      }
79  
80      public void setJavaExecutable(String javaExecutable) {
81          this.javaExecutable = javaExecutable;
82      }
83  
84      public void setMinimumPriority(int minimumPriority) {
85          this.minimumPriority = minimumPriority;
86      }
87  
88      public void setAuxClasspath(String auxClasspath) {
89          this.auxClasspath = auxClasspath;
90      }
91  
92      public void setSuppressMarker(String suppressMarker) {
93          this.suppressMarker = suppressMarker;
94      }
95  
96      public void setAnalysisCacheLocation(String analysisCacheLocation) {
97          this.analysisCacheLocation = analysisCacheLocation;
98      }
99  
100     public void setRulesets(List<String> rulesets) {
101         this.rulesets = rulesets;
102     }
103 
104     public void setSourceEncoding(String sourceEncoding) {
105         this.sourceEncoding = sourceEncoding;
106     }
107 
108     public void addFiles(Collection<File> files) {
109         this.files.addAll(files);
110     }
111 
112     public void setBenchmarkOutputLocation(String benchmarkOutputLocation) {
113         this.benchmarkOutputLocation = benchmarkOutputLocation;
114     }
115 
116     public void setTargetDirectory(String targetDirectory) {
117         this.targetDirectory = targetDirectory;
118     }
119 
120     public void setOutputEncoding(String outputEncoding) {
121         this.outputEncoding = outputEncoding;
122     }
123 
124     public void setFormat(String format) {
125         this.format = format;
126     }
127 
128     public void setLogLevel(String logLevel) {
129         this.logLevel = logLevel;
130     }
131 
132     public void setSkipPmdError(boolean skipPmdError) {
133         this.skipPmdError = skipPmdError;
134     }
135 
136     public void setIncludeXmlInSite(boolean includeXmlInSite) {
137         this.includeXmlInSite = includeXmlInSite;
138     }
139 
140     public void setReportOutputDirectory(String reportOutputDirectory) {
141         this.reportOutputDirectory = reportOutputDirectory;
142     }
143 
144     public void setExcludeFromFailureFile(String excludeFromFailureFile) {
145         this.excludeFromFailureFile = excludeFromFailureFile;
146     }
147 
148     public String getJavaExecutable() {
149         return javaExecutable;
150     }
151 
152     public String getLanguage() {
153         return language;
154     }
155 
156     public String getLanguageVersion() {
157         return languageVersion;
158     }
159 
160     public int getMinimumPriority() {
161         return minimumPriority;
162     }
163 
164     public String getAuxClasspath() {
165         return auxClasspath;
166     }
167 
168     public String getSuppressMarker() {
169         return suppressMarker;
170     }
171 
172     public String getAnalysisCacheLocation() {
173         return analysisCacheLocation;
174     }
175 
176     public List<String> getRulesets() {
177         return rulesets;
178     }
179 
180     public String getSourceEncoding() {
181         return sourceEncoding;
182     }
183 
184     public List<File> getFiles() {
185         return files;
186     }
187 
188     public String getBenchmarkOutputLocation() {
189         return benchmarkOutputLocation;
190     }
191 
192     public String getTargetDirectory() {
193         return targetDirectory;
194     }
195 
196     public String getOutputEncoding() {
197         return outputEncoding;
198     }
199 
200     public String getFormat() {
201         return format;
202     }
203 
204     public String getLogLevel() {
205         return logLevel;
206     }
207 
208     public boolean isDebugEnabled() {
209         return "debug".equals(logLevel);
210     }
211 
212     public boolean isSkipPmdError() {
213         return skipPmdError;
214     }
215 
216     public boolean isIncludeXmlInSite() {
217         return includeXmlInSite;
218     }
219 
220     public String getReportOutputDirectory() {
221         return reportOutputDirectory;
222     }
223 
224     public String getExcludeFromFailureFile() {
225         return excludeFromFailureFile;
226     }
227 }