1 18 23 24 package org.apache.tools.ant.taskdefs.optional.perforce; 25 26 import org.apache.tools.ant.BuildException; 27 import org.apache.tools.ant.Project; 28 29 41 public class P4Change extends P4Base { 42 44 protected String emptyChangeList = null; 45 protected String description = "AutoSubmit By Ant"; 46 48 53 public void execute() throws BuildException { 54 55 if (emptyChangeList == null) { 56 emptyChangeList = getEmptyChangeList(); 57 } 58 final Project myProj = getProject(); 59 60 P4Handler handler = new P4HandlerAdapter() { 61 public void process(String line) { 62 if (util.match("/Change/", line)) { 63 64 line = util.substitute("s/[^0-9]//g", line); 66 67 int changenumber = Integer.parseInt(line); 68 log("Change Number is " + changenumber, Project.MSG_INFO); 69 myProj.setProperty("p4.change", "" + changenumber); 70 71 } else if (util.match("/error/", line)) { 72 throw new BuildException("Perforce Error, check client settings and/or server"); 73 } 74 75 } 76 }; 77 78 handler.setOutput(emptyChangeList); 79 80 execP4Command("change -i", handler); 81 } 82 83 89 public String getEmptyChangeList() throws BuildException { 90 final StringBuffer stringbuf = new StringBuffer (); 91 92 execP4Command("change -o", new P4HandlerAdapter() { 93 public void process(String line) { 94 if (!util.match("/^#/", line)) { 95 if (util.match("/error/", line)) { 96 log("Client Error", Project.MSG_VERBOSE); 97 throw new BuildException("Perforce Error, " 98 + "check client settings and/or server"); 99 } else if (util.match("/<enter description here>/", line)) { 100 description = backslash(description); 102 line = util.substitute("s/<enter description here>/" 103 + description + "/", line); 104 } else if (util.match("/\\/\\//", line)) { 105 return; 107 } 108 stringbuf.append(line); 109 stringbuf.append("\n"); 110 } 111 } 112 }); 113 return stringbuf.toString(); 114 } 115 116 125 public static final String backslash(String value) { 126 final StringBuffer buf = new StringBuffer (value.length()); 127 final int len = value.length(); 128 for (int i = 0; i < len; i++) { 129 char c = value.charAt(i); 130 if (c == '/') { 131 buf.append('\\'); 132 } 133 buf.append(c); 134 } 135 return buf.toString(); 136 } 137 138 143 public void setDescription(String desc) { 144 this.description = desc; 145 } 146 147 } | Popular Tags |