summaryrefslogtreecommitdiffstats
path: root/tags/native-sca-1.0.incubating-M3-RC4/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Options.java
blob: 6e951f03deab5d3f3801e3b2a01b1593e2d2c345 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/**
 *
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 */

/* @version $Rev$ $Date$ */

/*
 *  Branched from the original class that was also contributed to the 
 *  org.apache.axis.tools.common package.
 *  
 */
package org.apache.tuscany.sca.cpp.tools.common;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Command line options passed to a tool's main program. All command line
 * options should begin with a dash "-". Some command line options take a value
 * which is the next parameter after the option. Others do not.
 */
public class Options {
    static HashMap pairs = new HashMap();

    static List values = new ArrayList();

    /**
     * No one constructs this class.
     */
    private Options() {
    }

    public static void reset() {
        pairs = new HashMap();
        values = new ArrayList();
    }

    /**
     * Initialises the options based on the args passed to main
     */
    public static void set(String args[]) {
        for (int i = 0; i < args.length; i++) {
            if (args[i].startsWith("-")) {
                if ((i + 1 <= args.length - 1) && // next one is testable
                        !args[i + 1].startsWith("-") // and it starts with a "-"
                ) {
                    String key = args[i];
                    Object pairValue = pairs.get(key);
                    if (null == pairValue) {
                        pairs.put(args[i], args[i + 1]);
                    } else if (pairValue instanceof String) {
                        List l = new ArrayList();
                        l.add(pairValue);
                        l.add(args[i + 1]);
                        pairs.put(key, l);
                    } else if (pairValue instanceof List) {
                        ((List) pairValue).add(args[i + 1]);
                    }
                    i++; // Step over value for this key
                } else
                    values.add(args[i]);
            }
        }
    }

    public static Object getOption(String key) {
        return pairs.get(key);
    }

    static boolean isOptionSet(String key) {
        return values.contains(key) || null!=pairs.get(key);
    }

    /**
     * This option will cause scagen to print out messages
     * about the artefacts it is processing
     * @return
     */
    public static boolean verbose() {
        return isOptionSet("-verbose");
    }

    /**
     * This option will cause scagen to print out some
     * basic internal log type messages 
     * @return
     */
    public static boolean debug() {
        return isOptionSet("-debug");
    }

    /**
     * This option will cause scagen to print out some
     * text that can be used or pasted into a command
     * file to copy all the relevant artefacts from
     * where they are found or generated to a specific
     * deployment location
     * 
     * @return
     */
    public static boolean deploy() {
        return isOptionSet("-deploy");
    }

    /**
     * This option will prevent scagen from actually writing out
     * the generated files. It is useful if used in conjunction
     * with the "-deploy" option. 
     * @return
     */
    public static boolean noGenerate() {
        return isOptionSet("-nogenerate");
    }

    /**
     * This option is useful only when used in conjunction with
     * the "-deploy" option. It changes the output to be more like the
     * source code of a command script to copy the files to a 
     * specific place. 
     * @return
     */
    public static boolean outputCommand() {
        return isOptionSet("-outputCommand");
    }

    /**
     * This option is useful only when used in conjunction with
     * the "-deploy" option. It changes the output to be a simple
     * list of artefacts. It has no effect if the "-outputCommand"
     * option is set. 
     * 
     * @return
     */
    public static boolean list() {
        return isOptionSet("-list");
    }

    /**
     * This option is maintained for compatibility with the
     * original package source. It is not used by new scagen code. 
     * 
     * @return
     */
    public static boolean quiet() {
        return isOptionSet("-quiet");
    }
}