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 50 51 public class P4Counter extends P4Base { 52 56 public String counter = null; 57 60 public String property = null; 61 64 public boolean shouldSetValue = false; 65 68 public boolean shouldSetProperty = false; 69 72 public int value = 0; 73 74 76 80 public void setName(String counter) { 81 this.counter = counter; 82 } 83 84 88 public void setValue(int value) { 89 this.value = value; 90 shouldSetValue = true; 91 } 92 93 98 public void setProperty(String property) { 99 this.property = property; 100 shouldSetProperty = true; 101 } 102 103 107 public void execute() throws BuildException { 108 109 if ((counter == null) || counter.length() == 0) { 110 throw new BuildException("No counter specified to retrieve"); 111 } 112 113 if (shouldSetValue && shouldSetProperty) { 114 throw new BuildException("Cannot both set the value of the property and retrieve the " 115 + "value of the property."); 116 } 117 118 String command = "counter " + P4CmdOpts + " " + counter; 119 if (!shouldSetProperty) { 120 command = "-s " + command; 125 } 126 if (shouldSetValue) { 127 command += " " + value; 128 } 129 130 if (shouldSetProperty) { 131 final Project myProj = getProject(); 132 133 P4Handler handler = new P4HandlerAdapter() { 134 public void process(String line) { 135 log("P4Counter retrieved line \"" + line + "\"", Project.MSG_VERBOSE); 136 try { 137 value = Integer.parseInt(line); 138 myProj.setProperty(property, "" + value); 139 } catch (NumberFormatException nfe) { 140 throw new BuildException("Perforce error. " 141 + "Could not retrieve counter value."); 142 } 143 } 144 }; 145 146 execP4Command(command, handler); 147 } else { 148 execP4Command(command, new SimpleP4OutputHandler(this)); 149 } 150 } 151 } 152 | Popular Tags |