Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-14814] Truncate deeply nested upstream causes.
  • Loading branch information
jglick committed Aug 15, 2012
1 parent b027876 commit bfa6481
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions core/src/main/java/hudson/model/Cause.java
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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) {
Expand All @@ -178,6 +214,16 @@ public static class ConverterImpl extends XStream2.PassthruConverter<UpstreamCau
}
}
}

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

}

/**
Expand Down

0 comments on commit bfa6481

Please sign in to comment.