From 53ded3d59f56f37b3bfb984015ded7a093c6bf51 Mon Sep 17 00:00:00 2001 From: mike cirioli Date: Mon, 10 Dec 2018 16:22:32 -0500 Subject: [PATCH] Fixes getBuildCause(String classname) so that it no longer relies on class loading to determine if a class meets the filter critera --- .../support/steps/build/RunWrapper.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/workflow/support/steps/build/RunWrapper.java b/src/main/java/org/jenkinsci/plugins/workflow/support/steps/build/RunWrapper.java index 9cf355e0..830cb691 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/support/steps/build/RunWrapper.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/support/steps/build/RunWrapper.java @@ -138,7 +138,18 @@ public int getNumber() throws AbortException { @Whitelisted public JSONArray getBuildCauses() throws IOException, ClassNotFoundException { - return getBuildCauses("hudson.model.Cause"); + JSONArray result = new JSONArray(); + + for(Cause cause : build().getCauses()) { + StringWriter w = new StringWriter(); + CauseAction causeAction = new CauseAction(cause); + DataWriter writer = JSON.createDataWriter(causeAction, w); + Model model = new ModelBuilder().get(CauseAction.class); + model.writeTo(causeAction, writer); + // return a slightlly cleaner object by removing the outer object + result.add(JSONObject.fromObject(w.toString()).getJSONArray("causes").get(0)); + } + return result; } /** @@ -151,12 +162,11 @@ public JSONArray getBuildCauses() throws IOException, ClassNotFoundException { * @throws IOException */ @Whitelisted - public JSONArray getBuildCauses(String className) throws IOException, ClassNotFoundException { - Class clazz = Class.forName(className); + public JSONArray getBuildCauses(String className) throws IOException { JSONArray result = new JSONArray(); for(Cause cause : build().getCauses()) { - if (clazz.isInstance(cause)) { + if (className.equals(cause.getClass().getName())) { StringWriter w = new StringWriter(); CauseAction causeAction = new CauseAction(cause); DataWriter writer = JSON.createDataWriter(causeAction, w);