Simplifying the display logic for health report icons. Providing a mechanism for custom health report icons which are correctly sized. Providing a mechanism for plugins to provide multiple health reports if they know what they are doing!

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@3968 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
stephenconnolly committed 2007-08-01 08:53:57 +00:00
1 parent e65e5cccc0
commit a38814815e
3 files changed
+52 -6

No files matched your search

@@ -1,6 +1,10 @@
package hudson.model;
import java.io.Serializable;
import java.util.List;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
/**
* Represents health of something (typically project).
@@ -43,6 +47,8 @@ public class HealthReport implements Serializable, Comparable<HealthReport> {
* If the path begins with a '/' then it will be the absolute path, otherwise the image is
* assumed to be in one of <code>/images/16x16/</code>, <code>/images/24x24/</code> or
* <code>/images/32x32/</code> depending on the icon size selected by the user.
* When calculating the url to display for absolute paths, the getIconUrl(String) method
* will replace /32x32/ in the path with the appropriate size.
* @param description The health icon's tool-tip.
*/
public HealthReport(int score, String iconUrl, String description) {
@@ -109,6 +115,21 @@ public class HealthReport implements Serializable, Comparable<HealthReport> {
return iconUrl;
}
/**
* Get's the iconUrl relative to the hudson root url, for the correct size.
* @param size The size, e.g. 32x32, 24x24 or 16x16.
* @return The url relative to hudson's root url.
*/
public String getIconUrl(String size) {
if (iconUrl == null) {
return "/images/" + size + "/" + HEALTH_UNKNOWN;
}
if (iconUrl.startsWith("/")) {
return iconUrl.replace("/32x32/", "/" + size + "/");
}
return "/images/" + size + "/" + iconUrl;
}
/**
* Setter for property 'iconUrl'.
*
@@ -136,6 +157,25 @@ public class HealthReport implements Serializable, Comparable<HealthReport> {
this.description = description;
}
/**
* Getter for property 'aggregatedReports'.
*
* @return Value for property 'aggregatedReports'.
*/
public List<HealthReport> getAggregatedReports() {
return Collections.EMPTY_LIST;
}
/**
* Getter for property 'aggregateReport'.
*
* @return Value for property 'aggregateReport'.
*/
public boolean isAggregateReport() {
return false;
}
/** {@inheritDoc} */
public int compareTo(HealthReport o) {
return (this.score < o.score ? -1 : (this.score == o.score ? 0 : 1));
}
+10 -2
View File
@@ -522,12 +522,20 @@ public abstract class Job<JobT extends Job<JobT,RunT>, RunT extends Run<JobT,Run
for (HealthReportingAction healthReportingAction : lastBuild.getActions(HealthReportingAction.class)) {
final HealthReport report = healthReportingAction.getBuildHealth();
if (report != null) {
reports.add(report);
if (report.isAggregateReport()) {
reports.addAll(report.getAggregatedReports());
} else {
reports.add(report);
}
}
}
final HealthReport report = getBuildStabilityHealthReport();
if (report != null) {
reports.add(report);
if (report.isAggregateReport()) {
reports.addAll(report.getAggregatedReports());
} else {
reports.add(report);
}
}
}