KickJava   Java API By Example, From Geeks To Geeks.

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


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 net.sourceforge.cruisecontrol.CruiseControlException;
40 import net.sourceforge.cruisecontrol.sourcecontrols.SSCM;
41 import net.sourceforge.cruisecontrol.util.StreamPumper;
42 import org.apache.log4j.Logger;
43 import java.io.IOException JavaDoc;
44
45 /**
46  * Bootstrapper for Surround SCM. Accepts one Branch/Repository path for fetching files
47  *
48  * @author Matt Harp
49  */

50 public class SSCMBootstrapper implements net.sourceforge.cruisecontrol.Bootstrapper
51 {
52    public void validate() throws CruiseControlException { /* nothing is required */ }
53
54    public void bootstrap() throws CruiseControlException {
55       java.util.ArrayList JavaDoc paramList = new java.util.ArrayList JavaDoc();
56       SSCM.SSCMCLIStringParam strparamFile = new SSCM.SSCMCLIStringParam("file", "", false);
57       strparamFile.setData("/");
58       paramList.add(strparamFile);
59       paramList.add(strparamBranch);
60       paramList.add(strparamRepository);
61       paramList.add(fparamMakeWritable);
62       paramList.add(fparamForceFetch);
63
64       paramList.add(strparamLabel);
65       if (strparamLabel.isSet()) { paramList.add(strparamIncludeRemovedFiles); }
66
67       paramList.add(fparamRecursive);
68       if (!fparamForceFetch.isSet()) { // If fetch is forced, then local file will be replaced.
69
if (!strparamOverwrite.isSet()) { strparamOverwrite.setData("skip"); } // so we don't overwrite local changes.
70
paramList.add(strparamOverwrite);
71       }
72
73       paramList.add(strparamServerLogin);
74       paramList.add(strparamServerConnect);
75
76       executeCLICommand(paramList);
77     }
78
79    public void setBranch(String JavaDoc str) { strparamBranch.setData(str); }
80    public void setRepository(String JavaDoc str) { strparamRepository.setData(str); }
81    public void setLabel(String JavaDoc str) { strparamLabel.setData(str); }
82    public void setServerConnect(String JavaDoc str) { strparamServerConnect.setData(str); }
83    public void setServerLogin(String JavaDoc str) { strparamServerLogin.setData(str); }
84    public void setIncludeRemovedFiles(boolean f) { strparamIncludeRemovedFiles.setData(f ? "" : "-"); }
85    public void setOverwrite(boolean f) { strparamOverwrite.setData(f ? "replace" : "skip"); }
86    public void setRecursive(boolean f) { if (f) { fparamRecursive.setData(null); } }
87    public void setForceFetch(boolean f) { if (f) { fparamForceFetch.setData(null); } }
88    public void setMakeWritable(boolean f) { if (f) { fparamMakeWritable.setData(null); } }
89
90    private SSCM.SSCMCLIStringParam strparamBranch = new SSCM.SSCMCLIStringParam("branch", "-b", false);
91    private SSCM.SSCMCLIStringParam strparamRepository = new SSCM.SSCMCLIStringParam("repository", "-p", false);
92    private SSCM.SSCMCLIStringParam strparamLabel = new SSCM.SSCMCLIStringParam("label", "-l", false);
93    private SSCM.SSCMCLIStringParam strparamServerConnect = new SSCM.SSCMCLIStringParam("serverconnect", "-z", false);
94    private SSCM.SSCMCLIStringParam strparamServerLogin = new SSCM.SSCMCLIStringParam("serverlogin", "-y", false);
95    private SSCM.SSCMCLIStringParam strparamIncludeRemovedFiles =
96        new SSCM.SSCMCLIStringParam("includeremoved", "-i", false);
97    private SSCM.SSCMCLIStringParam strparamOverwrite = new SSCM.SSCMCLIStringParam("overwrite", "-w", false);
98
99    private SSCM.SSCMCLIBoolParam fparamRecursive = new SSCM.SSCMCLIBoolParam("recursive", "-r", false);
100    private SSCM.SSCMCLIBoolParam fparamForceFetch = new SSCM.SSCMCLIBoolParam("force", "-f", false);
101    private SSCM.SSCMCLIBoolParam fparamMakeWritable = new SSCM.SSCMCLIBoolParam("writable", "-e", false);
102
103    private static final Logger LOG = Logger.getLogger(SSCMBootstrapper.class);
104
105    protected void executeCLICommand(java.util.List JavaDoc paramList) throws CruiseControlException {
106       StringBuffer JavaDoc strbufferCmdLine = new StringBuffer JavaDoc("sscm get ");
107
108       // Next, we just iterate through the list, adding entries.
109
for (int i = 0; i < paramList.size(); ++i) {
110          SSCM.SSCMCLIParam param = (SSCM.SSCMCLIParam) paramList.get(i);
111
112          if (param == null) {
113             throw new IllegalArgumentException JavaDoc("paramList may not contain null values");
114          }
115          if (param.checkRequired()) {
116             String JavaDoc str = param.getFormatted();
117             if (str != null) {
118                strbufferCmdLine.append(str);
119                strbufferCmdLine.append(' ');
120             }
121          } else {
122             throw new CruiseControlException("Required parameter '" + param.getParamName() + "' is missing!");
123          }
124       }
125
126       LOG.debug(strbufferCmdLine.toString() + "\n");
127
128       try {
129         Process JavaDoc process = Runtime.getRuntime().exec(strbufferCmdLine.toString());
130         new Thread JavaDoc(new StreamPumper(process.getInputStream())).start();
131         new Thread JavaDoc(new StreamPumper(process.getErrorStream())).start();
132
133         process.waitFor();
134
135         process.getInputStream().close();
136         process.getOutputStream().close();
137         process.getErrorStream().close();
138       } catch (IOException JavaDoc e) {
139          throw new CruiseControlException("Problem trying to execute command line process", e);
140       } catch (InterruptedException JavaDoc e) {
141          throw new CruiseControlException("Problem trying to execute command line process", e);
142       }
143    }
144
145 }
146
147
Popular Tags