Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ target/
*.iml
*.ipr
*.iws
nb-configuration.xml
5 changes: 4 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.450</version>
<version>1.584</version>
<relativePath />
</parent>

Expand All @@ -24,6 +24,8 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<project.build.outputEncoding>UTF-8</project.build.outputEncoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.7</maven.compiler.source>
</properties>

<issueManagement>
Expand Down Expand Up @@ -95,6 +97,7 @@
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>maven-plugin</artifactId>
<version>2.8</version>
</dependency>
<dependency>
<groupId>xpp3</groupId>
Expand Down
44 changes: 38 additions & 6 deletions src/main/java/hudson/plugins/violations/ViolationsReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.IOException;
import java.io.File;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -532,17 +533,48 @@ private boolean isFailed() {
/**
* Set the unstable/failed status of a build based
* on this violations report.
*
* Because of JENKINS-25406 we need to access this field via reflection.
*/
public void setBuildResult() {
if (isFailed()) {
build.setResult(Result.FAILURE);
return;
final Field resultField;
final Result result = build.getResult();
try {
Class<? extends AbstractBuild> klass = build.getClass();
resultField = getField(klass, "result");
resultField.setAccessible(true);
if (isFailed()) {
if (result == null || result.isBetterThan(Result.FAILURE)) {
resultField.set(build, Result.FAILURE);
}
return;
}
if (isUnstable()) {
if (result == null || result.isBetterThan(Result.UNSTABLE)) {
resultField.set(build, Result.UNSTABLE);
}
}
} catch (NoSuchFieldException e) {
throw new RuntimeException("Could not get resultField from build.", e);
} catch (IllegalAccessException e) {
throw new RuntimeException("Could not set value for resultField.", e);
}
if (isUnstable()) {
build.setResult(Result.UNSTABLE);
}

// http://stackoverflow.com/a/735311/49132
private static Field getField(Class clazz, String fieldName) throws NoSuchFieldException {
try {
return clazz.getDeclaredField(fieldName);
} catch (NoSuchFieldException e) {
Class superClass = clazz.getSuperclass();
if (superClass == null) {
throw e;
} else {
return getField(superClass, fieldName);
}
}
}

private static final long serialVersionUID = 1L;

public static ViolationsReport findViolationsReport(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package hudson.plugins.violations.graph;

import hudson.model.Run;
import org.jfree.data.category.CategoryDataset;

import hudson.util.DataSetBuilder;
Expand Down Expand Up @@ -81,15 +82,15 @@ public CategoryDataset buildDataSet() {
nums[Severity.MEDIUM_VALUE] + nums[Severity.MEDIUM_HIGH_VALUE]
+ nums[Severity.MEDIUM_LOW_VALUE],
MEDIUM_ROW,
new NumberOnlyBuildLabel(r.getBuild()));
new NumberOnlyBuildLabel((Run)r.getBuild()));
builder.add(
nums[Severity.HIGH_VALUE],
HIGH_ROW,
new NumberOnlyBuildLabel(r.getBuild()));
new NumberOnlyBuildLabel((Run)r.getBuild()));
builder.add(
nums[Severity.LOW_VALUE],
LOW_ROW,
new NumberOnlyBuildLabel(r.getBuild()));
new NumberOnlyBuildLabel((Run)r.getBuild()));
}
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.awt.Color;
import java.awt.BasicStroke;

import hudson.model.*;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
Expand All @@ -24,12 +25,6 @@
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerProxy;

import hudson.model.Action;
import hudson.model.Actionable;
import hudson.model.HealthReportingAction;
import hudson.model.HealthReport;
import hudson.model.AbstractBuild;

import hudson.util.ChartUtil;
import hudson.util.DataSetBuilder;
import hudson.util.ShiftedCategoryAxis;
Expand Down Expand Up @@ -192,7 +187,7 @@ req, rsp, new SeverityTypeDataSet(

for (ViolationsReport r: ViolationsReport.iteration(getBuild())) {
ChartUtil.NumberOnlyBuildLabel label
= new ChartUtil.NumberOnlyBuildLabel(r.getBuild());
= new ChartUtil.NumberOnlyBuildLabel((Run)r.getBuild());
for (String ty: r.getViolations().keySet()) {
dsb.add(roundUp(r.getViolations().get(ty)), ty, label);
}
Expand Down