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  import java.util.Map;
27  
28  /**
29   * Data object to store all configuration options needed to execute PMD
30   * as a separate process.
31   *
32   * <p>This class is intended to be serialized and read back.
33   *
34   * <p>Some properties might be optional and can be <code>null</code>.
35   */
36  public class PmdRequest implements Serializable {
37      private static final long serialVersionUID = -6324416880563476455L;
38  
39      private Map<String, String> jdkToolchain;
40  
41      private String language;
42      private String languageVersion;
43      private int minimumPriority;
44      private String auxClasspath;
45      private String suppressMarker;
46      private String analysisCacheLocation;
47      private List<String> rulesets;
48      private String sourceEncoding;
49      private List<File> files = new ArrayList<>();
50  
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 includeXmlInReports;
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 setJdkToolchain(Map<String, String> jdkToolchain) {
82          this.jdkToolchain = jdkToolchain;
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 setLogLevel(String logLevel) {
130         this.logLevel = logLevel;
131     }
132 
133     public void setSkipPmdError(boolean skipPmdError) {
134         this.skipPmdError = skipPmdError;
135     }
136 
137     public void setIncludeXmlInReports(boolean includeXmlInReports) {
138         this.includeXmlInReports = includeXmlInReports;
139     }
140 
141     public void setReportOutputDirectory(String reportOutputDirectory) {
142         this.reportOutputDirectory = reportOutputDirectory;
143     }
144 
145     public void setExcludeFromFailureFile(String excludeFromFailureFile) {
146         this.excludeFromFailureFile = excludeFromFailureFile;
147     }
148 
149     public Map<String, String> getJdkToolchain() {
150         return jdkToolchain;
151     }
152 
153     public String getLanguage() {
154         return language;
155     }
156 
157     public String getLanguageVersion() {
158         return languageVersion;
159     }
160 
161     public int getMinimumPriority() {
162         return minimumPriority;
163     }
164 
165     public String getAuxClasspath() {
166         return auxClasspath;
167     }
168 
169     public String getSuppressMarker() {
170         return suppressMarker;
171     }
172 
173     public String getAnalysisCacheLocation() {
174         return analysisCacheLocation;
175     }
176 
177     public List<String> getRulesets() {
178         return rulesets;
179     }
180 
181     public String getSourceEncoding() {
182         return sourceEncoding;
183     }
184 
185     public List<File> getFiles() {
186         return files;
187     }
188 
189     public String getBenchmarkOutputLocation() {
190         return benchmarkOutputLocation;
191     }
192 
193     public String getTargetDirectory() {
194         return targetDirectory;
195     }
196 
197     public String getOutputEncoding() {
198         return outputEncoding;
199     }
200 
201     public String getFormat() {
202         return format;
203     }
204 
205     public String getLogLevel() {
206         return logLevel;
207     }
208 
209     public boolean isDebugEnabled() {
210         return "debug".equals(logLevel);
211     }
212 
213     public boolean isSkipPmdError() {
214         return skipPmdError;
215     }
216 
217     public boolean isIncludeXmlInReports() {
218         return includeXmlInReports;
219     }
220 
221     public String getReportOutputDirectory() {
222         return reportOutputDirectory;
223     }
224 
225     public String getExcludeFromFailureFile() {
226         return excludeFromFailureFile;
227     }
228 }