Skip to content

Commit

Permalink
Fixes getBuildCause(String classname) so that it no longer relies on
Browse files Browse the repository at this point in the history
class loading to determine if a class meets the filter critera
  • Loading branch information
mikecirioli committed Dec 10, 2018
1 parent 68f35ca commit 53ded3d
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<CauseAction> 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;
}

/**
Expand All @@ -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);
Expand Down

0 comments on commit 53ded3d

Please sign in to comment.