KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > sourcecontrols > AlienBrainCore


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.sourcecontrols;
38
39 import net.sourceforge.cruisecontrol.CruiseControlException;
40 import net.sourceforge.cruisecontrol.util.Commandline;
41 import net.sourceforge.cruisecontrol.util.ManagedCommandline;
42
43 import org.apache.log4j.Logger;
44
45 import java.io.IOException JavaDoc;
46
47 /**
48  * This class implements the SourceControl methods for an AlienBrain
49  * repository. It does this by taking advantage of the AlienBrain command-
50  * line utility. Obviously, the command line utility must be installed
51  * and working in order for this class to work.
52  *
53  * This class is based very heavily on P4.java.
54  *
55  * @author <a HREF="mailto:scottj+cc@escherichia.net">Scott Jacobs</a>
56  */

57 public class AlienBrainCore {
58     
59     protected static final Logger LOG = Logger.getLogger(AlienBrainCore.class);
60     
61     protected static final String JavaDoc AB_NO_SESSION = "Invalid session please logon!";
62     
63     private String JavaDoc server;
64     private String JavaDoc database;
65     private String JavaDoc user;
66     private String JavaDoc password;
67     private String JavaDoc path;
68     private String JavaDoc branch;
69
70     /**
71      * Sets the hostname of the server hosting the AlienBrain repository.
72      *
73      *@param server The AlienBrain server's hostname.
74      */

75     public void setServer(String JavaDoc server) {
76         this.server = server;
77     }
78
79     public String JavaDoc getServer() {
80         return server;
81     }
82     
83     /**
84      * Sets the name of the project database.
85      *
86      *@param database The name of the project database.
87      */

88     public void setDatabase(String JavaDoc database) {
89         this.database = database;
90     }
91     
92     public String JavaDoc getDatabase() {
93         return database;
94     }
95     
96     /**
97      * Sets the name of the AlienBrain user account used to connect.
98      *
99      *@param user The name of the AlienBrin user account.
100      */

101     public void setUser(String JavaDoc user) {
102         this.user = user;
103     }
104     
105     public String JavaDoc getUser() {
106         return user;
107     }
108     
109     /**
110      * Sets the password of the AlienBrain user account used to connect.
111      *
112      *@param password The password of the AlienBrin user account.
113      */

114     public void setPassword(String JavaDoc password) {
115         this.password = password;
116     }
117     
118     public String JavaDoc getPassword() {
119         return password;
120     }
121     
122     /**
123      * Sets the path to the project within the AlienBrain repository.
124      *
125      * @param path The path within the project database to check for
126      * modificiations. Typically something like alienbrain://path/to/project
127      */

128     public void setPath(String JavaDoc path) {
129         this.path = path;
130     }
131     
132     public String JavaDoc getPath() {
133         return path;
134     }
135     
136     /**
137      * Sets the path to the project within the AlienBrain repository.
138      *
139      *@param branch The branch within the AlienBrain project.
140      */

141     public void setBranch(String JavaDoc branch) {
142         this.branch = branch;
143     }
144   
145     public String JavaDoc getBranch() {
146         return branch;
147     }
148   
149     /**
150      * Try to add a flag to a Commandline
151      *
152      *@param cmdLine The Commandline object to possibly add arguments
153      *@param flagValue Whether or not to add the flag.
154      *@param flagName The flag to use if the argument is added.
155      */

156     protected void addFlagIfSet(Commandline cmdLine, boolean flagValue, String JavaDoc flagName) {
157         if (flagValue) {
158             cmdLine.createArgument().setValue(flagName);
159         }
160     }
161
162     /**
163      * Try to add flagged argument to a Commandline
164      *
165      *@param cmdLine The Commandline object to possibly add arguments
166      *@param argument The argument to possibly add.
167      *@param flag The flag to use if the argument is added.
168      */

169     protected void addArgumentIfSet(Commandline cmdLine, String JavaDoc argument, String JavaDoc flag) {
170         if (argument != null) {
171             cmdLine.createArgument().setValue(flag);
172             cmdLine.createArgument().setValue(argument);
173         }
174     }
175
176     /**
177      * Construct a ManagedCommandline preset with arguments applicable to
178      * any AlienBrain command that we wish to run.
179      */

180     protected ManagedCommandline buildCommonCommand() {
181         ManagedCommandline cmdLine = new ManagedCommandline();
182         cmdLine.setExecutable("ab");
183         addArgumentIfSet(cmdLine, user, "-u");
184         addArgumentIfSet(cmdLine, password, "-p");
185         addArgumentIfSet(cmdLine, server, "-s");
186         addArgumentIfSet(cmdLine, database, "-d");
187
188         return cmdLine;
189     }
190
191     
192     /**
193      * Sets the active branch to the provided branch name.
194      *
195      *@param branch The branch name.
196      */

197     protected void setActiveBranch(String JavaDoc branch) throws IOException JavaDoc, CruiseControlException {
198         ManagedCommandline cmdLine = buildCommonCommand();
199         cmdLine.createArgument().setValue("setactivebranch");
200         cmdLine.createArgument().setValue(branch);
201         LOG.debug("Executing: " + cmdLine.toString());
202         cmdLine.execute();
203         cmdLine.assertExitCode(0);
204     }
205 }
206
Popular Tags