1 18 19 package org.apache.tools.ant.taskdefs.optional.ccm; 20 21 22 import java.io.BufferedReader ; 23 import java.io.IOException ; 24 import java.io.InputStream ; 25 import java.io.InputStreamReader ; 26 import java.io.OutputStream ; 27 import org.apache.tools.ant.BuildException; 28 import org.apache.tools.ant.Project; 29 import org.apache.tools.ant.taskdefs.Execute; 30 import org.apache.tools.ant.taskdefs.ExecuteStreamHandler; 31 import org.apache.tools.ant.types.Commandline; 32 33 34 39 public class CCMCreateTask extends Continuus implements ExecuteStreamHandler { 40 41 private String comment = null; 42 private String platform = null; 43 private String resolver = null; 44 private String release = null; 45 private String subSystem = null; 46 private String task = null; 47 48 51 public CCMCreateTask() { 52 super(); 53 setCcmAction(COMMAND_CREATE_TASK); 54 } 55 56 57 65 public void execute() throws BuildException { 66 Commandline commandLine = new Commandline(); 67 int result = 0; 68 69 commandLine.setExecutable(getCcmCommand()); 72 commandLine.createArgument().setValue(getCcmAction()); 73 74 checkOptions(commandLine); 75 76 result = run(commandLine, this); 77 if (Execute.isFailure(result)) { 78 String msg = "Failed executing: " + commandLine.toString(); 79 throw new BuildException(msg, getLocation()); 80 } 81 82 Commandline commandLine2 = new Commandline(); 84 commandLine2.setExecutable(getCcmCommand()); 85 commandLine2.createArgument().setValue(COMMAND_DEFAULT_TASK); 86 commandLine2.createArgument().setValue(getTask()); 87 88 log(commandLine.describeCommand(), Project.MSG_DEBUG); 89 90 result = run(commandLine2); 91 if (result != 0) { 92 String msg = "Failed executing: " + commandLine2.toString(); 93 throw new BuildException(msg, getLocation()); 94 } 95 96 } 97 98 99 102 private void checkOptions(Commandline cmd) { 103 if (getComment() != null) { 104 cmd.createArgument().setValue(FLAG_COMMENT); 105 cmd.createArgument().setValue("\"" + getComment() + "\""); 106 } 107 108 if (getPlatform() != null) { 109 cmd.createArgument().setValue(FLAG_PLATFORM); 110 cmd.createArgument().setValue(getPlatform()); 111 } 113 if (getResolver() != null) { 114 cmd.createArgument().setValue(FLAG_RESOLVER); 115 cmd.createArgument().setValue(getResolver()); 116 } 118 if (getSubSystem() != null) { 119 cmd.createArgument().setValue(FLAG_SUBSYSTEM); 120 cmd.createArgument().setValue("\"" + getSubSystem() + "\""); 121 } 123 if (getRelease() != null) { 124 cmd.createArgument().setValue(FLAG_RELEASE); 125 cmd.createArgument().setValue(getRelease()); 126 } } 128 129 130 134 public String getComment() { 135 return comment; 136 } 137 138 143 public void setComment(String v) { 144 this.comment = v; 145 } 146 147 148 152 public String getPlatform() { 153 return platform; 154 } 155 156 161 public void setPlatform(String v) { 162 this.platform = v; 163 } 164 165 166 170 public String getResolver() { 171 return resolver; 172 } 173 174 179 public void setResolver(String v) { 180 this.resolver = v; 181 } 182 183 184 188 public String getRelease() { 189 return release; 190 } 191 192 197 public void setRelease(String v) { 198 this.release = v; 199 } 200 201 205 public String getSubSystem() { 206 return subSystem; 207 } 208 209 214 public void setSubSystem(String v) { 215 this.subSystem = v; 216 } 217 218 219 223 public String getTask() { 224 return task; 225 } 226 227 233 public void setTask(String v) { 234 this.task = v; 235 } 236 237 240 public static final String FLAG_COMMENT = "/synopsis"; 241 242 245 public static final String FLAG_PLATFORM = "/plat"; 246 247 250 public static final String FLAG_RESOLVER = "/resolver"; 251 252 255 public static final String FLAG_RELEASE = "/release"; 256 257 260 public static final String FLAG_SUBSYSTEM = "/subsystem"; 261 262 265 public static final String FLAG_TASK = "/task"; 266 267 268 270 274 public void start() throws IOException { 275 } 276 277 280 public void stop() { 281 } 282 283 288 public void setProcessInputStream(OutputStream param1) throws IOException { 289 } 290 291 296 public void setProcessErrorStream(InputStream is) throws IOException { 297 BufferedReader reader = new BufferedReader (new InputStreamReader (is)); 298 String s = reader.readLine(); 299 if (s != null) { 300 log("err " + s, Project.MSG_DEBUG); 301 } } 303 304 309 public void setProcessOutputStream(InputStream is) throws IOException { 310 311 String buffer = ""; 312 try { 313 BufferedReader reader = new BufferedReader (new InputStreamReader (is)); 314 buffer = reader.readLine(); 315 if (buffer != null) { 316 log("buffer:" + buffer, Project.MSG_DEBUG); 317 String taskstring = buffer.substring(buffer.indexOf(' ')).trim(); 318 taskstring = taskstring.substring(0, taskstring.lastIndexOf(' ')).trim(); 319 setTask(taskstring); 320 log("task is " + getTask(), Project.MSG_DEBUG); 321 } } catch (NullPointerException npe) { 323 log("error procession stream , null pointer exception", Project.MSG_ERR); 324 npe.printStackTrace(); 325 throw new BuildException(npe.getClass().getName()); 326 } catch (Exception e) { 327 log("error procession stream " + e.getMessage(), Project.MSG_ERR); 328 throw new BuildException(e.getMessage()); 329 } 331 } 332 333 } 334 335 | Popular Tags |