1 package hudson.util; 2 3 import java.util.ArrayList ; 4 import java.util.List ; 5 import java.util.StringTokenizer ; 6 import java.util.Arrays ; 7 8 13 public class ArgumentListBuilder { 14 private final List <String > args = new ArrayList <String >(); 15 16 public ArgumentListBuilder add(String a) { 17 args.add(a); 18 return this; 19 } 20 21 public ArgumentListBuilder prepend(String ... args) { 22 this.args.addAll(0, Arrays.asList(args)); 23 return this; 24 } 25 26 34 public ArgumentListBuilder addQuoted(String a) { 35 return add('"'+a+'"'); 36 } 37 38 public ArgumentListBuilder add(String ... args) { 39 for (String arg : args) { 40 add(arg); 41 } 42 return this; 43 } 44 45 48 public ArgumentListBuilder addTokenized(String s) { 49 StringTokenizer tokens = new StringTokenizer (s); 50 while(tokens.hasMoreTokens()) 51 add(tokens.nextToken()); 52 return this; 53 } 54 55 public String [] toCommandArray() { 56 return args.toArray(new String [args.size()]); 57 } 58 59 public ArgumentListBuilder clone() { 60 ArgumentListBuilder r = new ArgumentListBuilder(); 61 r.args.addAll(this.args); 62 return r; 63 } 64 65 public List <String > toList() { 66 return args; 67 } 68 } 69 | Popular Tags |