提交 dc4c44c5 编写于 作者: K kohsuke

Run is made comparable on its own. Added a reusable BuildLabel class that just shows the number.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@1543 71c3de6d-444a-0410-be80-ed276b4c234a
上级 67efb278
......@@ -4,14 +4,13 @@ import com.thoughtworks.xstream.XStream;
import hudson.CloseProofOutputStream;
import hudson.ExtensionPoint;
import hudson.FeedAdapter;
import hudson.FilePath;
import hudson.Util;
import static hudson.Util.combine;
import hudson.XmlFile;
import hudson.FilePath;
import hudson.tasks.LogRotator;
import hudson.tasks.BuildStep;
import hudson.tasks.LogRotator;
import hudson.tasks.test.AbstractTestResultAction;
import hudson.util.CharSpool;
import hudson.util.IOException2;
import hudson.util.XStream2;
import org.kohsuke.stapler.StaplerRequest;
......@@ -47,7 +46,7 @@ import java.util.logging.Logger;
* @author Kohsuke Kawaguchi
*/
public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,RunT>>
extends DirectoryHolder implements ExtensionPoint {
extends DirectoryHolder implements ExtensionPoint, Comparable<RunT> {
protected transient final JobT project;
......@@ -144,6 +143,14 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
getDataFile().unmarshal(this); // load the rest of the data
}
/**
* Ordering based on build numbers.
*/
public int compareTo(RunT that) {
return this.number - that.number;
}
/**
* Returns the build result.
*
......
......@@ -6,6 +6,7 @@ import hudson.model.Build;
import hudson.model.Project;
import hudson.model.Result;
import hudson.util.ChartUtil;
import hudson.util.ChartUtil.NumberOnlyBuildLabel;
import hudson.util.ColorPalette;
import hudson.util.DataSetBuilder;
import hudson.util.ShiftedCategoryAxis;
......@@ -108,39 +109,14 @@ public abstract class AbstractTestResultAction<T extends AbstractTestResultActio
if(req.checkIfModified(owner.getTimestamp(),rsp))
return;
class BuildLabel implements Comparable<BuildLabel> {
private final Build build;
public BuildLabel(Build build) {
this.build = build;
}
public int compareTo(BuildLabel that) {
return this.build.number-that.build.number;
}
public boolean equals(Object o) {
BuildLabel that = (BuildLabel) o;
return build==that.build;
}
public int hashCode() {
return build.hashCode();
}
public String toString() {
return build.getDisplayName();
}
}
boolean failureOnly = Boolean.valueOf(req.getParameter("failureOnly"));
DataSetBuilder<String,BuildLabel> dsb = new DataSetBuilder<String,BuildLabel>();
DataSetBuilder<String,NumberOnlyBuildLabel> dsb = new DataSetBuilder<String,NumberOnlyBuildLabel>();
for( AbstractTestResultAction<?> a=this; a!=null; a=a.getPreviousResult(AbstractTestResultAction.class) ) {
dsb.add( a.getFailCount(), "failed", new BuildLabel(a.owner));
dsb.add( a.getFailCount(), "failed", new NumberOnlyBuildLabel(a.owner));
if(!failureOnly)
dsb.add( a.getTotalCount()-a.getFailCount(),"total", new BuildLabel(a.owner));
dsb.add( a.getTotalCount()-a.getFailCount(),"total", new NumberOnlyBuildLabel(a.owner));
}
ChartUtil.generateGraph(req,rsp,createChart(dsb.build()),500,200);
......
......@@ -11,12 +11,41 @@ import java.awt.HeadlessException;
import java.awt.image.BufferedImage;
import java.io.IOException;
import hudson.model.Build;
/**
* See issue 93. Detect an error in X11 and handle it gracefully.
*
* @author Kohsuke Kawaguchi
*/
public class ChartUtil {
/**
* Can be used as a graph label. Only displays numbers.
*/
public static final class NumberOnlyBuildLabel implements Comparable<NumberOnlyBuildLabel> {
private final Build build;
public NumberOnlyBuildLabel(Build build) {
this.build = build;
}
public int compareTo(NumberOnlyBuildLabel that) {
return this.build.number-that.build.number;
}
public boolean equals(Object o) {
NumberOnlyBuildLabel that = (NumberOnlyBuildLabel) o;
return build==that.build;
}
public int hashCode() {
return build.hashCode();
}
public String toString() {
return build.getDisplayName();
}
}
/**
* See issue 93. Detect an error in X11 and handle it gracefully.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册