From b40f5df3472da47e01b95aa125516ada8a9586e2 Mon Sep 17 00:00:00 2001 From: Mirko Friedenhagen Date: Mon, 15 Dec 2014 22:28:43 +0100 Subject: [PATCH 1/7] Try to update jenkins core. --- pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 93c3c08..74326a9 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.jenkins-ci.plugins plugin - 1.450 + 1.580.1 @@ -95,6 +95,7 @@ org.jenkins-ci.main maven-plugin + 1.534 xpp3 From efc37c7813109c02a0d59dc08c231e90be72b5cc Mon Sep 17 00:00:00 2001 From: Mirko Friedenhagen Date: Tue, 16 Dec 2014 08:15:16 +0100 Subject: [PATCH 2/7] Use 1.534 as parent for now, as newest LTS (1.580.1) is breaking everything. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 74326a9..5cacac0 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.jenkins-ci.plugins plugin - 1.580.1 + 1.534 From 6b70b70b599a21c44e7e470a87c40aa833dab429 Mon Sep 17 00:00:00 2001 From: Mirko Friedenhagen Date: Tue, 16 Dec 2014 22:13:55 +0100 Subject: [PATCH 3/7] Update parent to first breaking core version. --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 5cacac0..bd98dc4 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.jenkins-ci.plugins plugin - 1.534 + 1.584 @@ -95,7 +95,7 @@ org.jenkins-ci.main maven-plugin - 1.534 + 2.8 xpp3 From 2caf8b23d4b885842568e1e8e0ff91dea5493cf4 Mon Sep 17 00:00:00 2001 From: Mirko Friedenhagen Date: Tue, 16 Dec 2014 22:20:52 +0100 Subject: [PATCH 4/7] Cast getBuild to accomodate changed API in newer Jenkins version. --- .../plugins/violations/graph/SeverityTypeDataSet.java | 7 ++++--- .../violations/hudson/AbstractViolationsBuildAction.java | 9 ++------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/main/java/hudson/plugins/violations/graph/SeverityTypeDataSet.java b/src/main/java/hudson/plugins/violations/graph/SeverityTypeDataSet.java index 7ac238d..e184ce8 100644 --- a/src/main/java/hudson/plugins/violations/graph/SeverityTypeDataSet.java +++ b/src/main/java/hudson/plugins/violations/graph/SeverityTypeDataSet.java @@ -1,5 +1,6 @@ package hudson.plugins.violations.graph; +import hudson.model.Run; import org.jfree.data.category.CategoryDataset; import hudson.util.DataSetBuilder; @@ -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(); } diff --git a/src/main/java/hudson/plugins/violations/hudson/AbstractViolationsBuildAction.java b/src/main/java/hudson/plugins/violations/hudson/AbstractViolationsBuildAction.java index 0862ab8..64e8353 100644 --- a/src/main/java/hudson/plugins/violations/hudson/AbstractViolationsBuildAction.java +++ b/src/main/java/hudson/plugins/violations/hudson/AbstractViolationsBuildAction.java @@ -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; @@ -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; @@ -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); } From 677dc8981b161f11368db8aebe4d94473ae6f757 Mon Sep 17 00:00:00 2001 From: Mirko Friedenhagen Date: Wed, 17 Dec 2014 21:13:54 +0100 Subject: [PATCH 5/7] Use reflection to access protected field result from the build, see JENKINS-25406 as well. As of https://github.com/jenkinsci/jenkins/commit/28dfd90d2d6ae99c57eb174871c46f4e07e303ba#diff-c4f9931d88bca347279b881007d71f0eL445 the field may not be set anymore directly when the build already was completed. TODO: the summary still thinks the build was a SUCCESS. --- .../plugins/violations/ViolationsReport.java | 44 ++++++++++++++++--- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/src/main/java/hudson/plugins/violations/ViolationsReport.java b/src/main/java/hudson/plugins/violations/ViolationsReport.java index ea2a066..e4275c9 100644 --- a/src/main/java/hudson/plugins/violations/ViolationsReport.java +++ b/src/main/java/hudson/plugins/violations/ViolationsReport.java @@ -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; @@ -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 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( From 7003049734440b7268bb79d87d7c716a0668ae5f Mon Sep 17 00:00:00 2001 From: Mirko Friedenhagen Date: Wed, 17 Dec 2014 11:24:01 +0100 Subject: [PATCH 6/7] Ignore netbeans configurations --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 2fea509..d0b2671 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ target/ *.iml *.ipr *.iws +nb-configuration.xml From fca1a5baaa9c837df5cbdc6a543ba2cb5aeb0343 Mon Sep 17 00:00:00 2001 From: Mirko Friedenhagen Date: Wed, 17 Dec 2014 11:24:18 +0100 Subject: [PATCH 7/7] Use Java 1.7 --- pom.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pom.xml b/pom.xml index bd98dc4..19fecef 100644 --- a/pom.xml +++ b/pom.xml @@ -24,6 +24,8 @@ UTF-8 UTF-8 UTF-8 + 1.7 + 1.7