• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.manifmerger;
18 
19 import com.android.sdklib.util.CommandLineParser;
20 import com.android.utils.ILogger;
21 
22 import java.util.List;
23 
24 
25 /**
26  * Specific command-line flags for the {@link ManifestMerger}.
27  */
28 class ArgvParser extends CommandLineParser {
29 
30     /*
31      * Steps needed to add a new action:
32      * - Each action is defined as a "verb object" followed by parameters.
33      * - Either reuse a VERB_ constant or define a new one.
34      * - Either reuse an OBJECT_ constant or define a new one.
35      * - Add a new entry to mAction with a one-line help summary.
36      * - In the constructor, add a define() call for each parameter (either mandatory
37      *   or optional) for the given action.
38      */
39 
40     public final static String VERB_MERGE       = "merge";                          //$NON-NLS-1$
41     public static final String KEY_OUT          = "out";                            //$NON-NLS-1$
42     public static final String KEY_MAIN         = "main";                           //$NON-NLS-1$
43     public static final String KEY_LIBS         = "libs";                           //$NON-NLS-1$
44 
45     /**
46      * Action definitions for ManifestMerger command line.
47      * <p/>
48      * This list serves two purposes: first it is used to know which verb/object
49      * actions are acceptable on the command-line; second it provides a summary
50      * for each action that is printed in the help.
51      * <p/>
52      * Each entry is a string array with:
53      * <ul>
54      * <li> the verb.
55      * <li> an object (use #NO_VERB_OBJECT if there's no object).
56      * <li> a description.
57      * <li> an alternate form for the object (e.g. plural).
58      * </ul>
59      */
60     private final static String[][] ACTIONS = {
61 
62             { VERB_MERGE, NO_VERB_OBJECT,
63                 "Merge two or more manifests." },
64 
65     };
66 
ArgvParser(ILogger logger)67     public ArgvParser(ILogger logger) {
68         super(logger, ACTIONS);
69 
70         // The following defines the parameters of the actions defined in mAction.
71 
72         // --- merge manifest ---
73 
74         define(Mode.STRING, true,
75                 VERB_MERGE, NO_VERB_OBJECT, "o", KEY_OUT,                           //$NON-NLS-1$
76                 "Output path (where to write the merged manifest). Use - for stdout.", null);
77 
78         define(Mode.STRING, true,
79                 VERB_MERGE, NO_VERB_OBJECT, "1", KEY_MAIN,                          //$NON-NLS-1$
80                 "Path of the main manifest (what to merge *into*)", null);
81 
82         define(Mode.STRING_ARRAY, true,
83                 VERB_MERGE, NO_VERB_OBJECT, "2", KEY_LIBS,                          //$NON-NLS-1$
84                 "Paths of library manifests to be merged into the main one.",
85                 null);
86     }
87 
88     @Override
acceptLackOfVerb()89     public boolean acceptLackOfVerb() {
90         return true;
91     }
92 
93     // -- some helpers for generic action flags
94 
95     /** Helper to retrieve the --out value. */
getParamOut()96     public String getParamOut() {
97         return (String) getValue(null, null, KEY_OUT);
98     }
99 
100     /** Helper to retrieve the --main value. */
getParamMain()101     public String getParamMain() {
102         return (String) getValue(null, null, KEY_MAIN);
103     }
104 
105     /**
106      * Helper to retrieve the --libs values.
107      */
getParamLibs()108     public String[] getParamLibs() {
109         Object v = getValue(null, null, KEY_LIBS);
110         if (v instanceof List<?>) {
111             List<?> a = (List<?>) v;
112             return a.toArray(new String[a.size()]);
113         }
114         return null;
115     }
116 }
117