Subversion Repositories DevTools

Rev

Rev 6914 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6914 dpurdie 1
package com.erggroup.buildtool.utilities;
2
/**
3
 * This class is used to create commands by building up a command line piece by piece.
4
 * The full command can them be extracted either as a string or as an array of strings
5
 */
6
import java.util.ArrayList;
7
 
8
public class CommandBuilder {
9
 
10
    /**
11
     * An array of command being accumulated
12
     */
13
    ArrayList<String> cmd = new ArrayList<String>();
14
 
15
 
16
    /** Re-init the command list
17
     *  Discards the current Array List and start again
18
     *  
19
     *  @param argList           - Variable number of string arguments
20
     */
21
    public void init(String... argList)
22
    {
23
        cmd.clear();
24
        add(argList);
25
    }
26
 
27
    /** Add one or more strings to the command
28
     * 
29
     * @param argList           - Variable number of string arguments
30
     */
31
    public void add( String... argList )
32
    {
33
        for(String c: argList)
34
        {
35
            cmd.add(c);
36
        }
37
    }
38
 
39
    /** Conditionally add one or more strings to the command
40
     * 
41
     * @param enable            - If true then add the commands
42
     * @param argList           - Variable number of string arguments
43
     */
44
    public void add( Boolean enable, String... argList )
45
    {
46
        if (enable)
47
        {
48
            add(argList);
49
        }
50
    }
51
 
52
    /** Convert the command fragments into a string
53
     *  The argument are space-separated
54
     */
55
    public String toString()
56
    {
57
        String commandString = "";
58
        for(String c: cmd)
59
        {
60
            commandString += c + " ";
61
        }
62
        return commandString;
63
    }
64
 
65
    /** Convert the command fragments into a string array
66
     */
67
    public String[] getArray()
68
    {
69
        String[] rv = cmd.toArray(new String[0]);
70
        return rv;
71
    }
72
}