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;
037:
038: import org.apache.commons.lang.StringUtils;
039:
040: /**
041: * Understands the current status of a build.
042: */
043: public final class CurrentStatus implements ViewableStatus {
044: public static final CurrentStatus QUEUED = new CurrentStatus(
045: "Queued", "in build queue");
046:
047: public static final CurrentStatus BOOTSTRAPPING = new CurrentStatus(
048: "Bootstrapping", "bootstrapping");
049:
050: public static final CurrentStatus MODIFICATIONSET = new CurrentStatus(
051: "ModificationSet", "checking for modifications");
052:
053: public static final CurrentStatus BUILDING = new CurrentStatus(
054: "Building", "now building");
055:
056: public static final CurrentStatus WAITING = new CurrentStatus(
057: "Waiting", "waiting for next time to build");
058:
059: public static final CurrentStatus PAUSED = new CurrentStatus(
060: "Paused", "paused");
061:
062: public static final CurrentStatus DISCONTINUED = new CurrentStatus(
063: "Discontinued", "Discontinued");
064:
065: private static final CurrentStatus[] STATUSES = new CurrentStatus[] {
066: QUEUED, BOOTSTRAPPING, MODIFICATIONSET, BUILDING, WAITING,
067: PAUSED, DISCONTINUED };
068:
069: private String status;
070:
071: private String cruiseStatus;
072:
073: public static CurrentStatus getProjectBuildStatus(String statusStr) {
074: for (int i = 0; i < STATUSES.length; i++) {
075: CurrentStatus status = STATUSES[i];
076: if (StringUtils
077: .indexOf(statusStr, status.getCruiseStatus()) == 0) {
078: return status;
079: }
080: }
081: return DISCONTINUED;
082: }
083:
084: private CurrentStatus(String status, String cruiseStatus) {
085: this .status = status;
086: this .cruiseStatus = cruiseStatus;
087: }
088:
089: public String getStatus() {
090: return status;
091: }
092:
093: public String getCruiseStatus() {
094: return cruiseStatus;
095: }
096:
097: public String toString() {
098: return getCruiseStatus();
099: }
100: }
|