001: /********************************************************************************
002: * CruiseControl, a Continuous Integration Toolkit
003: * Copyright (c) 2007, ThoughtWorks, Inc.
004: * 200 E. Randolph, 25th Floor
005: * Chicago, IL 60601 USA
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * + Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * + Redistributions in binary form must reproduce the above
016: * copyright notice, this list of conditions and the following
017: * disclaimer in the documentation and/or other materials provided
018: * with the distribution.
019: *
020: * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
021: * names of its contributors may be used to endorse or promote
022: * products derived from this software without specific prior
023: * written permission.
024: *
025: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
026: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
027: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
028: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
029: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
030: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
031: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
032: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
033: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
034: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
035: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
036: ********************************************************************************/package net.sourceforge.cruisecontrol.dashboard.web.command;
037:
038: import net.sourceforge.cruisecontrol.dashboard.CurrentStatus;
039: import net.sourceforge.cruisecontrol.dashboard.BuildSummary;
040: import net.sourceforge.cruisecontrol.dashboard.utils.CCDateFormatter;
041:
042: public class CCTrayBuildSummaryAdapter implements XmlAdapter {
043:
044: private final BuildSummary summary;
045:
046: private String baseUrl;
047:
048: private String lastBuildStatus;
049:
050: public CCTrayBuildSummaryAdapter(String baseUrl,
051: BuildSummary summary) {
052: this .summary = summary;
053: this .baseUrl = baseUrl;
054: this .lastBuildStatus = summary.hasPassed() ? "Success"
055: : "Failure";
056: }
057:
058: public String getName() {
059: return summary.getProjectName();
060: }
061:
062: public String getActivity() {
063: CurrentStatus status = summary.getCurrentStatus();
064: if (status.equals(CurrentStatus.BOOTSTRAPPING)
065: || status.equals(CurrentStatus.MODIFICATIONSET)) {
066: return "CheckingModifications";
067: } else if (status.equals(CurrentStatus.BUILDING)) {
068: return "Building";
069: } else {
070: return "Sleeping";
071: }
072: }
073:
074: public String getLastBuildStatus() {
075: return lastBuildStatus;
076: }
077:
078: public String getLastBuildLabel() {
079: return summary.getLabel();
080: }
081:
082: public String getLastBuildTime() {
083: return CCDateFormatter.format(summary.getBuildDate(),
084: "yyyy-MM-dd'T'HH:mm:ss");
085: }
086:
087: public String toXml() {
088: StringBuffer sb = new StringBuffer();
089: sb.append("<Project").append(" name=").append(
090: quote(this .getName())).append(" activity=").append(
091: quote(this .getActivity())).append(" lastBuildStatus=")
092: .append(quote(this .getLastBuildStatus())).append(
093: " lastBuildLabel=").append(
094: quote(this .getLastBuildLabel())).append(
095: " lastBuildTime=").append(
096: quote(this .getLastBuildTime())).append(
097: " webUrl=").append(
098: quote(baseUrl + "tab/build/detail/"
099: + this .getName())).append(" />")
100: .append("\n");
101: return sb.toString();
102: }
103:
104: private String quote(String text) {
105: return '"' + text + '"';
106: }
107: }
|