KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > bootstrappers > CurrentBuildStatusFTPBootstrapper


1 /********************************************************************************
2  * CruiseControl, a Continuous Integration Toolkit
3  * Copyright (c) 2001, ThoughtWorks, Inc.
4  * 651 W Washington Ave. Suite 600
5  * Chicago, IL 60661 USA
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * + Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * + Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  *
20  * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
21  * names of its contributors may be used to endorse or promote
22  * products derived from this software without specific prior
23  * written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
29  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  ********************************************************************************/

37 package net.sourceforge.cruisecontrol.bootstrappers;
38
39 import java.util.Date JavaDoc;
40 import java.io.File JavaDoc;
41 import java.io.IOException JavaDoc;
42
43 import net.sourceforge.cruisecontrol.Bootstrapper;
44 import net.sourceforge.cruisecontrol.util.AbstractFTPClass;
45 import net.sourceforge.cruisecontrol.util.ValidationHelper;
46 import net.sourceforge.cruisecontrol.CruiseControlException;
47 import net.sourceforge.cruisecontrol.util.CurrentBuildFileWriter;
48 import net.sourceforge.cruisecontrol.util.Util;
49 import org.apache.log4j.Logger;
50
51
52 /**
53  * Does the same thing as CurrentBuildStatusBootstrapper, but also
54  * sends it to an FTP server.
55  * @deprecated Was obsoleted by {@link net.sourceforge.cruisecontrol.listeners.CurrentBuildStatusFTPListener}
56  */

57 public class CurrentBuildStatusFTPBootstrapper extends AbstractFTPClass
58         implements Bootstrapper {
59     private static final Logger LOG = Logger.getLogger(CurrentBuildStatusFTPBootstrapper.class);
60
61     private String JavaDoc fileName;
62     private String JavaDoc destdir;
63
64     public CurrentBuildStatusFTPBootstrapper() {
65         LOG.warn("CurrentBuildStatusFTPBootstrapper was obsoleted by CurrentBuildStatusFTPListener");
66     }
67
68     public void setFile(String JavaDoc fileName) {
69         this.fileName = fileName;
70     }
71
72
73     public void setDestDir(String JavaDoc dir) {
74         this.destdir = dir;
75     }
76
77
78     public void bootstrap() throws CruiseControlException {
79         String JavaDoc out = makeFile();
80         String JavaDoc fname = destdir + File.separator + fileName;
81
82         sendFileToFTPPath(out, fname);
83     }
84     
85     
86     protected String JavaDoc makeFile()
87         throws CruiseControlException {
88         CurrentBuildFileWriter.writefile(
89             "Current Build Started At:\n",
90             new Date JavaDoc(),
91             fileName);
92
93         try {
94             return Util.readFileToString(fileName);
95         } catch (IOException JavaDoc ioe) {
96             throw new CruiseControlException(ioe.getMessage());
97         }
98     }
99
100     /*
101     protected String makeLogFile() throws CruiseControlException {
102         StringBuffer out = new StringBuffer(
103               "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
104             + "<cruisecontrol>"
105                + "<modifications />"
106                + "<info>"
107                     + "<property name=\"lastbuild\" value=\"200301010000000\" />"
108                     + "<property name=\"lastsuccessfulbuildbuild\" value=\"200301010000000\" />"
109                     + "<property name=\"builddate\" value=\"01/01/2003 00:00:00\" />"
110                     + "<property name=\"cctimestamp\" value=\"200301010000000\" />"
111                     + "<property name=\"label\" value=\"\" />"
112                     + "<property name=\"interval\" value=\"0\" />"
113                     + "<property name=\"lastbuildsuccessful\" value=\"true\" />"
114                     + "<property name=\"logfile\" value=\"\\logBASE.xml\" />"
115                     + "<property name=\"projectname\" value=\"");
116         out.append(projectName);
117         out.append("\" />"
118                + "</info>"
119                + "<build error=\"Never built\" />"
120             + "</cruisecontrol>");
121         return out.toString();
122     }
123     */

124
125
126     public void validate() throws CruiseControlException {
127         ValidationHelper.assertIsSet(fileName, "file", this.getClass());
128         ValidationHelper.assertIsSet(destdir, "destdir", this.getClass());
129         super.validate();
130     }
131
132 }
133
Popular Tags