diff --git a/src/main/java/hudson/plugins/pmd/PmdCutoff.java b/src/main/java/hudson/plugins/pmd/PmdCutoff.java new file mode 100644 index 0000000..c18c598 --- /dev/null +++ b/src/main/java/hudson/plugins/pmd/PmdCutoff.java @@ -0,0 +1,54 @@ +package hudson.plugins.pmd; + +import org.apache.commons.lang.StringUtils; +import org.kohsuke.stapler.export.Exported; +import org.kohsuke.stapler.export.ExportedBean; + +import java.io.Serializable; + +/** + * Holds the cutoff values for high and medium priority. + */ +@ExportedBean +public class PmdCutoff + implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * PMD priority 0..5 for high jenkins priority. + *
+ * Any PMD message with a priority lower (inclusive) than this value is mapped to "high priority". + * If this field is set to "0", then no message is mapped to "high priority". + * If it is set to "5", every message is mapped to "high priority". + */ + @Exported + public String cutoffHighPriority = StringUtils.EMPTY; + + /** + * PMD priority 0..5 for normal jenkins priority. + *
+ * Any PMD message with a priority lower (inclusive) than this value is mapped to "normal priority".
+ * If this field is set to the same value as cutoffHighPriority, then no message is mapped to "normal priority".
+ * If this field is set to 5, then no message is mapped to "low priority".
+ */
+ @Exported
+ public String cutoffNormalPriority = StringUtils.EMPTY;
+
+ public boolean isValid() {
+ return isValidValue(cutoffHighPriority)
+ && isValidValue(cutoffNormalPriority)
+ // high and normal can be the same (then no values are mapped to "normal"), but 'high' must be greater than 'normal'.
+ && Integer.valueOf(cutoffHighPriority) <= Integer.valueOf(cutoffNormalPriority);
+ }
+
+ private static boolean isValidValue(String value) {
+ if (StringUtils.isNotBlank(value)) {
+ try {
+ int x = Integer.valueOf(value);
+ return x >= 0 && x <= 5;
+ } catch (NumberFormatException ignored) {
+ }
+ }
+ return false;
+ }
+}
diff --git a/src/main/java/hudson/plugins/pmd/PmdPublisher.java b/src/main/java/hudson/plugins/pmd/PmdPublisher.java
index a8ad634..031e5b7 100644
--- a/src/main/java/hudson/plugins/pmd/PmdPublisher.java
+++ b/src/main/java/hudson/plugins/pmd/PmdPublisher.java
@@ -23,6 +23,8 @@
import hudson.plugins.analysis.util.PluginLogger;
import hudson.plugins.pmd.parser.PmdParser;
+import javax.annotation.CheckForNull;
+
/**
* Publishes the results of the PMD analysis (freestyle project type).
*
@@ -38,6 +40,8 @@ public class PmdPublisher extends HealthAwarePublisher {
/** Ant file-set pattern of files to work with. */
private String pattern;
+ private PmdCutoff pmdCutoff = new PmdCutoff();
+
/**
* Constructor used from methods like {@link StaplerRequest#bindJSON(Class, JSONObject)} (Class, JSONObject)} and
* {@link StaplerRequest#bindParameters(Class, String)}.
@@ -66,13 +70,37 @@ public void setPattern(final String pattern) {
this.pattern = pattern;
}
+ public PmdCutoff getPmdCutoff() {
+ return pmdCutoff;
+ }
+
+ @CheckForNull
+ public String getCutoffHighPriority() {
+ return pmdCutoff.cutoffHighPriority;
+ }
+
+ @DataBoundSetter
+ public void setCutoffHighPriority(String cutoffHighPriority) {
+ pmdCutoff.cutoffHighPriority = cutoffHighPriority;
+ }
+
+ @CheckForNull
+ public String getCutoffNormalPriority() {
+ return pmdCutoff.cutoffNormalPriority;
+ }
+
+ @DataBoundSetter
+ public void setCutoffNormalPriority(String cutoffNormalPriority) {
+ pmdCutoff.cutoffNormalPriority = cutoffNormalPriority;
+ }
+
@Override
public BuildResult perform(final Run, ?> build, final FilePath workspace, final PluginLogger logger) throws
InterruptedException, IOException {
logger.log("Collecting PMD analysis files...");
FilesParser parser = new FilesParser(PLUGIN_NAME,
StringUtils.defaultIfEmpty(expandFilePattern(getPattern(), build.getEnvironment(TaskListener.NULL)), DEFAULT_PATTERN),
- new PmdParser(getDefaultEncoding()), shouldDetectModules(), isMavenBuild(build));
+ new PmdParser(getDefaultEncoding(), pmdCutoff.cutoffHighPriority, pmdCutoff.cutoffNormalPriority), shouldDetectModules(), isMavenBuild(build));
ParserResult project = workspace.act(parser);
logger.logLines(project.getLogMessages());
diff --git a/src/main/java/hudson/plugins/pmd/PmdReporter.java b/src/main/java/hudson/plugins/pmd/PmdReporter.java
index 412357e..e8f3bae 100644
--- a/src/main/java/hudson/plugins/pmd/PmdReporter.java
+++ b/src/main/java/hudson/plugins/pmd/PmdReporter.java
@@ -26,12 +26,14 @@
* @author Ulli Hafner
*/
public class PmdReporter extends HealthAwareReporterPmdReporter
.
*
@@ -99,16 +101,25 @@ public PmdReporter(final String healthy, final String unHealthy, final String th
final String failedTotalAll, final String failedTotalHigh, final String failedTotalNormal, final String failedTotalLow,
final String failedNewAll, final String failedNewHigh, final String failedNewNormal, final String failedNewLow,
final boolean canRunOnFailed, final boolean usePreviousBuildAsReference,
- final boolean useStableBuildAsReference, final boolean canComputeNew) {
+ final boolean useStableBuildAsReference, final boolean canComputeNew,
+ final String cutoffHighPriority, final String cutoffNormalPriority) {
super(healthy, unHealthy, thresholdLimit, useDeltaValues,
unstableTotalAll, unstableTotalHigh, unstableTotalNormal, unstableTotalLow,
unstableNewAll, unstableNewHigh, unstableNewNormal, unstableNewLow,
failedTotalAll, failedTotalHigh, failedTotalNormal, failedTotalLow,
failedNewAll, failedNewHigh, failedNewNormal, failedNewLow,
canRunOnFailed, usePreviousBuildAsReference, useStableBuildAsReference, canComputeNew, PLUGIN_NAME);
+
+ pmdCutoff.cutoffHighPriority = cutoffHighPriority;
+ pmdCutoff.cutoffNormalPriority = cutoffNormalPriority;
}
+
// CHECKSTYLE:ON
+ public PmdCutoff getPmdCutoff() {
+ return pmdCutoff;
+ }
+
@Override
protected boolean acceptGoal(final String goal) {
return "pmd".equals(goal) || "site".equals(goal) || "report".equals(goal) || "check".equals(goal);
@@ -117,7 +128,7 @@ protected boolean acceptGoal(final String goal) {
@Override
public ParserResult perform(final MavenBuildProxy build, final MavenProject pom, final MojoInfo mojo, final PluginLogger logger) throws InterruptedException, IOException {
FilesParser pmdCollector = new FilesParser(PLUGIN_NAME, PMD_XML_FILE,
- new PmdParser(getDefaultEncoding()), getModuleName(pom));
+ new PmdParser(getDefaultEncoding(), pmdCutoff.cutoffHighPriority, pmdCutoff.cutoffNormalPriority), getModuleName(pom));
return getTargetPath(pom).act(pmdCollector);
}
@@ -147,5 +158,18 @@ protected Class
+
+
+
+
+
+
+ ${%field.high.value}
+
+
+
+
+
+ ${%field.normal.value}
+
+
+
+