01: package net.sourceforge.cruisecontrol.distributed.core;
02:
03: import net.sourceforge.cruisecontrol.CruiseControlException;
04: import net.sourceforge.cruisecontrol.util.ValidationHelper;
05:
06: import java.io.Serializable;
07: import java.io.File;
08:
09: /**
10: * @author Dan Rollo
11: * Date: Oct 16, 2007
12: * Time: 1:03:56 AM
13: */
14: public class RemoteResult implements Serializable {
15:
16: private static final long serialVersionUID = -8269577385052199821L;
17:
18: private final int idx;
19: // @todo Allow agent file to include props and be resolved at runtime?
20: private File agentDir;
21: private File tempZippedFile;
22: private File masterDir;
23: static final String MSG_SUFFIX_BAD_DISTRIBUTED_CHILD_ELEMENT_RESULT = "<distributed> child element <remoteResult>";
24:
25: public RemoteResult(int idx) {
26: this .idx = idx;
27: }
28:
29: public int getIdx() {
30: return idx;
31: }
32:
33: private void checkNonResetable(final String attribName,
34: final File oldValue, final File newValue) {
35: if (oldValue != null) {
36: throw new IllegalStateException(attribName
37: + " already set to: "
38: + oldValue.getAbsolutePath()
39: + ", can not be reset to: "
40: + (newValue != null ? newValue.getAbsolutePath()
41: : null));
42: }
43: }
44:
45: public void setAgentDir(final String agentDirectory) {
46: final File newAgentDir = new File(agentDirectory);
47: checkNonResetable("agentDir", this .agentDir, newAgentDir);
48: this .agentDir = newAgentDir;
49: }
50:
51: public File getAgentDir() {
52: return agentDir;
53: }
54:
55: public void setMasterDir(final String masterDirectory) {
56: final File newMasterDir = new File(masterDirectory);
57: checkNonResetable("masterDir", this .masterDir, newMasterDir);
58: this .masterDir = newMasterDir;
59: }
60:
61: public File getMasterDir() {
62: return masterDir;
63: }
64:
65: /** Intended only for unit testing. */
66: void resetTempZippedFile() {
67: tempZippedFile = null;
68: }
69:
70: public void storeTempZippedFile(final File tempZippedFile) {
71: checkNonResetable("storeTempZippedFile", this .tempZippedFile,
72: tempZippedFile);
73: this .tempZippedFile = tempZippedFile;
74: }
75:
76: public File fetchTempZippedFile() {
77: return tempZippedFile;
78: }
79:
80: public void validate() throws CruiseControlException {
81: ValidationHelper.assertTrue(idx >= 0,
82: "Invalid remoteResult index: " + idx);
83: ValidationHelper.assertIsSet(agentDir, "agentDir",
84: MSG_SUFFIX_BAD_DISTRIBUTED_CHILD_ELEMENT_RESULT);
85: ValidationHelper.assertIsSet(masterDir, "masterDir",
86: MSG_SUFFIX_BAD_DISTRIBUTED_CHILD_ELEMENT_RESULT);
87: }
88:
89: public String toString() {
90: return "agentDir: "
91: + (agentDir != null ? agentDir.getAbsolutePath() : "")
92: + "; masterDir: "
93: + (masterDir != null ? masterDir.getAbsolutePath() : "")
94: + "; tempZippedFile: "
95: + (tempZippedFile != null ? tempZippedFile
96: .getAbsolutePath() : "");
97: }
98: }
|