1 37 package net.sourceforge.cruisecontrol.bootstrappers; 38 39 import com.starbase.starteam.commandline.StarTeamCmd; 40 import net.sourceforge.cruisecontrol.Bootstrapper; 41 import net.sourceforge.cruisecontrol.CruiseControlException; 42 import net.sourceforge.cruisecontrol.util.ValidationHelper; 43 import net.sourceforge.cruisecontrol.util.Commandline; 44 45 67 public class StarTeamBootstrapper implements Bootstrapper { 68 69 private String username; 70 private String password; 71 private String servername; 72 private String serverport; 73 private String projectname; 74 private String viewname; 75 private String foldername; 76 private String localfoldername; 77 private String filenames; 78 79 public StarTeamBootstrapper() { 80 } 81 82 public void setUsername(String name) { 83 username = name; 84 } 85 86 public void setPassword(String passwd) { 87 password = passwd; 88 } 89 90 public void setServer(String server) { 91 servername = server; 92 } 93 94 public void setPort(String port) { 95 serverport = port; 96 } 97 98 public void setProject(String project) { 99 projectname = project; 100 } 101 102 public void setView(String view) { 103 viewname = view; 104 } 105 106 public void setFolder(String folder) { 107 foldername = folder; 108 } 109 110 public void setLocalFolder(String localfolder) { 111 localfoldername = localfolder; 112 } 113 114 public void setFiles(String files) { 115 filenames = files; 116 } 117 118 public void bootstrap() throws CruiseControlException { 119 Commandline args = buildCheckoutCommand(); 120 int retVal = StarTeamCmd.run(args.getCommandline()); 121 if (retVal != 0) { 122 throw new CruiseControlException("Error executing StarTeam checkout command: " + args.toString()); 123 } 124 } 125 126 public void validate() throws CruiseControlException { 127 ValidationHelper.assertFalse(filenames == null 128 || username == null 129 || password == null 130 || servername == null 131 || serverport == null 132 || projectname == null 133 || viewname == null 134 || foldername == null, 135 "'files', 'username', 'password','server', 'port', 'project', 'view' and 'folder'" 136 + " are all required for StarTeamBootstrapper"); 137 } 138 139 private Commandline buildCheckoutCommand() { 140 Commandline commandLine = new Commandline(); 141 commandLine.createArgument().setValue("co"); 142 commandLine.createArgument().setValue("-p"); 143 commandLine.createArgument().setValue( 144 username 145 + ':' 146 + password 147 + '@' 148 + servername 149 + ':' 150 + serverport 151 + '/' 152 + projectname 153 + '/' 154 + viewname 155 + '/' 156 + foldername); 157 if (localfoldername != null) { 158 commandLine.createArgument().setValue("-fp"); 159 commandLine.createArgument().setValue(localfoldername); 160 } 161 commandLine.createArgument().setValue("-o"); 162 commandLine.createArgument().setValue("-x"); 163 commandLine.createArgument().setLine(filenames); 164 return commandLine; 165 } 166 167 public String toString() { 168 return buildCheckoutCommand().toString(); 169 } 170 171 public static void main(String [] args) throws CruiseControlException { 172 StarTeamBootstrapper bootstrapper = new StarTeamBootstrapper(); 173 bootstrapper.setUsername("ccuser"); 174 bootstrapper.setPassword("ccuser"); 175 bootstrapper.setServer("starteamserver"); 176 bootstrapper.setPort("4001"); 177 bootstrapper.setProject("ProjectName"); 178 bootstrapper.setView("ViewName"); 179 bootstrapper.setFolder("src/folder"); 180 bootstrapper.setLocalFolder("checkoutfolder"); 181 bootstrapper.setFiles("build.properties build.xml"); 182 System.out.println(bootstrapper); 183 bootstrapper.bootstrap(); 184 } 185 } 186 | Popular Tags |