1 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 ; 46 47 57 public class AlienBrainCore { 58 59 protected static final Logger LOG = Logger.getLogger(AlienBrainCore.class); 60 61 protected static final String AB_NO_SESSION = "Invalid session please logon!"; 62 63 private String server; 64 private String database; 65 private String user; 66 private String password; 67 private String path; 68 private String branch; 69 70 75 public void setServer(String server) { 76 this.server = server; 77 } 78 79 public String getServer() { 80 return server; 81 } 82 83 88 public void setDatabase(String database) { 89 this.database = database; 90 } 91 92 public String getDatabase() { 93 return database; 94 } 95 96 101 public void setUser(String user) { 102 this.user = user; 103 } 104 105 public String getUser() { 106 return user; 107 } 108 109 114 public void setPassword(String password) { 115 this.password = password; 116 } 117 118 public String getPassword() { 119 return password; 120 } 121 122 128 public void setPath(String path) { 129 this.path = path; 130 } 131 132 public String getPath() { 133 return path; 134 } 135 136 141 public void setBranch(String branch) { 142 this.branch = branch; 143 } 144 145 public String getBranch() { 146 return branch; 147 } 148 149 156 protected void addFlagIfSet(Commandline cmdLine, boolean flagValue, String flagName) { 157 if (flagValue) { 158 cmdLine.createArgument().setValue(flagName); 159 } 160 } 161 162 169 protected void addArgumentIfSet(Commandline cmdLine, String argument, String flag) { 170 if (argument != null) { 171 cmdLine.createArgument().setValue(flag); 172 cmdLine.createArgument().setValue(argument); 173 } 174 } 175 176 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 197 protected void setActiveBranch(String branch) throws IOException , 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 |