001: /********************************************************************************
002: * CruiseControl, a Continuous Integration Toolkit
003: * Copyright (c) 2001-2003, 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;
037:
038: import java.util.Date;
039:
040: /**
041: * @author jfredrick
042: */
043: public class MockProject extends Project {
044:
045: private int buildCount = 0;
046: private Date lastBuild;
047: private static final long ONE_SECOND = 1000;
048: private boolean keepLooping = false;
049: private int loopCount = 0;
050: private ProjectState mockState;
051:
052: public ProjectState getState() {
053: if (mockState == null) {
054: return super .getState();
055: }
056:
057: return mockState;
058: }
059:
060: void setMockState(ProjectState newState) {
061: mockState = newState;
062: }
063:
064: public void execute() {
065: buildCount++;
066: lastBuild = new Date();
067: try {
068: Thread.sleep(ONE_SECOND);
069: } catch (InterruptedException e) {
070: String message = "MockProject.execute() interrupted";
071: System.out.println(message);
072: throw new RuntimeException(message);
073: }
074: }
075:
076: public int getBuildCount() {
077: return buildCount;
078: }
079:
080: public Date getLastBuildDate() {
081: return lastBuild;
082: }
083:
084: void loop() {
085: loopCount = 0;
086: keepLooping = true;
087: while (keepLooping) {
088: loopCount++;
089: try {
090: checkWait();
091: Thread.sleep(50);
092: } catch (InterruptedException e) {
093: String message = "MockProject.loop() interrupted";
094: throw new RuntimeException(message);
095: }
096: }
097: }
098:
099: void checkWait() throws InterruptedException {
100: }
101:
102: void stopLooping() {
103: keepLooping = false;
104: }
105:
106: int getLoopCount() {
107: return loopCount;
108: }
109:
110: /*
111: * don't do anything
112: *
113: * @see net.sourceforge.cruisecontrol.Project#checkLogDirectory()
114: */
115: protected void checkLogDirectory() {
116: }
117:
118: }
|