Skip to content
Permalink
Browse files

[FIXED JENKINS-14814] Truncate deeply nested upstream causes.

  • Loading branch information...
jglick committed Aug 15, 2012
1 parent b027876 commit bfa648152f266540536e76f7b3ebcb1598ad5f6f
Showing with 48 additions and 2 deletions.
  1. +48 −2 core/src/main/java/hudson/model/Cause.java
@@ -34,6 +34,7 @@
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import javax.annotation.Nonnull;

/**
* Cause object base class. This class hierarchy is used to keep track of why
@@ -100,14 +101,19 @@ public String getShortDescription() {
* A build is triggered by the completion of another build (AKA upstream build.)
*/
public static class UpstreamCause extends Cause {

/**
* Maximum depth of transitive upstream causes we want to record.
*/
private static final int MAX_DEPTH = 10;
private String upstreamProject, upstreamUrl;
private int upstreamBuild;
/**
* @deprecated since 2009-02-28
*/
@Deprecated
private transient Cause upstreamCause;
private List<Cause> upstreamCauses;
private @Nonnull List<Cause> upstreamCauses;

/**
* @deprecated since 2009-02-28
@@ -121,7 +127,33 @@ public UpstreamCause(Run<?, ?> up) {
upstreamBuild = up.getNumber();
upstreamProject = up.getParent().getFullName();
upstreamUrl = up.getParent().getUrl();
upstreamCauses = new ArrayList<Cause>(up.getCauses());
upstreamCauses = new ArrayList<Cause>();
for (Cause c : up.getCauses()) {
upstreamCauses.add(trim(c, MAX_DEPTH));
}
}

private UpstreamCause(String upstreamProject, int upstreamBuild, String upstreamUrl, @Nonnull List<Cause> upstreamCauses) {
this.upstreamProject = upstreamProject;
this.upstreamBuild = upstreamBuild;
this.upstreamUrl = upstreamUrl;
this.upstreamCauses = upstreamCauses;
}

private @Nonnull Cause trim(@Nonnull Cause c, int depth) {
if (!(c instanceof UpstreamCause)) {
return c;
}
UpstreamCause uc = (UpstreamCause) c;
List<Cause> cs = new ArrayList<Cause>();
if (depth > 0) {
for (Cause c2 : uc.upstreamCauses) {
cs.add(trim(c2, depth - 1));
}
} else {
cs.add(new DeeplyNestedUpstreamCause());
}
return new UpstreamCause(uc.upstreamProject, uc.upstreamBuild, uc.upstreamUrl, cs);
}

/**
@@ -167,6 +199,10 @@ public void print(TaskListener listener) {
);
}

@Override public String toString() {
return upstreamUrl + upstreamBuild + upstreamCauses;
}

public static class ConverterImpl extends XStream2.PassthruConverter<UpstreamCause> {
public ConverterImpl(XStream2 xstream) { super(xstream); }
@Override protected void callback(UpstreamCause uc, UnmarshallingContext context) {
@@ -178,6 +214,16 @@ public void print(TaskListener listener) {
}
}
}

public static class DeeplyNestedUpstreamCause extends Cause {
@Override public String getShortDescription() {
return "(deeply nested causes)";
}
@Override public String toString() {
return "JENKINS-14814";
}
}

}

/**

0 comments on commit bfa6481

Please sign in to comment.
You can’t perform that action at this time.