2 // DbCmds command-line interface to the classes that
3 // update the FrameworkDatabase.db file based on WORKSPACE Contents
5 // Copyright (c) 2006, Intel Corporation All rights reserved.
7 // This program and the accompanying materials are licensed and made
8 // available under the terms and conditions of the BSD License which
9 // accompanies this distribution. The full text of the license may
10 // be found at http://opensource.org/licenses/bsd-license.php
12 // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 // This program is the command line interface to the CombineMsa class, which
16 // will take the following arguments:
19 // -t, --test Test the Workspace against the FrameworkDatabase.db file
20 // Returns 0 if valid, returns 1 if failed
22 // -f, --fix Fix the FrameworkDatabase.db file, so that it matches the
23 // the contents of the WORKSPACE
24 // Returns 0 if valid, returns 1 if failed
26 // -v [-v] Verbose Flag - sum of these will be used to set different
27 // levels of verbosity
29 // -i Interactive, when used with -f or --fix, will query the user
30 // regarding adds and deletes of packages and platforms from
33 // -a, --add Add an SPD or FPD file to the FrameworkDatabase.db file. The
34 // SPD/FPD file must exist, or the command will fail.
35 // Returns 0 if valid, returns 1 if failed
37 // -r, --del Remove an SPD or FPD file from the FrameworkDatabase.db file.
38 // If the SPD/FPD file exists, the user will be queried to
39 // remove it from the directory tree. For SPD files, the user
40 // will also be presented with a list of Modules in the SPD
41 // file, with the query to remove the modules as well as the
43 // Returns 0 if valid, returns 1 if failed
45 // -u Display the UiName for all Packages and Platforms currently in
46 // the FrameworkDatabase.db file.
47 // Returns 0 if valid, returns 1 if failed
49 // -c Display a CSV listing of Type (SPD|FPD) UiName and Filename of
50 // every entry in the FrameworkDatabase.db file.
51 // Returns 0 if valid, returns 1 if failed
53 // No Options Display a list of Type (Package|Platfrom) and Filename of every
54 // entry in the FrameworkDatabase.db file.
55 // Returns 0 if valid, returns 1 if failed
57 // -h, -?, --help Displays this usage and exits.
58 // Returns 0 if valid, returns 1 if failed
62 // Displayed information
64 // Modifies - OPTIONAL
65 // FrameworkDatabase.db
68 package org
.tianocore
.DbTools
;
75 SHOW_CSV
, SHOW_PLATFORMS
, SHOW_PACKAGES
, FIX_DB
, TEST_DB
, FIND_SOMETHING
, SHOW_FAR
, ADD_SOMETHING
,
79 private int DEBUG
= 0;
81 private static final String copyright
= "Copyright (c) 2006, Intel Corporation All rights reserved.";
83 private static final String version
= "Version 0.1";
85 private static final String Specification
= "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
87 private int VERBOSE
= 0;
89 public boolean INTERACTIVE
= false;
91 private String workspace
= System
.getenv("WORKSPACE");
93 private final String frameworkDatabase
= workspace
+ File
.separator
+ "Tools" + File
.separator
+ "Conf"
94 + File
.separator
+ "FrameworkDatabase.db";
96 private final int ESUCCESS
= 0;
98 private final int EFAILURE
= 1;
100 private final int MIN_VERBOSE
= 0;
102 private final int MED_VERBOSE
= 1;
104 private final int MAX_VERBOSE
= 2;
106 private final static int FOUND
= 1;
108 private final static int NOTFOUND
= 0;
110 private boolean TEST
= false;
112 private int result
= ESUCCESS
;
114 private Cmd commandToCall
;
116 private boolean isPlatform
= false;
118 private boolean isPackage
= false;
120 private boolean isFar
= false;
122 private boolean QUIET
= false;
124 private String commandArgs
= "";
126 private String whatToFind
= "";
128 public int DbUpdateCmdLine(String
[] args
) {
130 if (testFile(frameworkDatabase
) == NOTFOUND
) {
131 System
.out
.println("ERROR: E000 Invalid Workspace!");
132 System
.out
.println("The environment variable, WORKSPACE, does not point to a valid workspace");
133 System
.out
.println("DbUpdate Aborted!");
135 System
.exit(EFAILURE
);
137 result
= parseCmdLine(args
);
138 if (result
== ESUCCESS
) {
140 System
.out
.println("Parse Succeeded!");
141 if (VERBOSE
> MAX_VERBOSE
)
142 System
.out
.println("WORKSPACE: " + workspace
);
144 System
.out
.println("Command to call: " + commandToCall
.toString());
145 result
= processCmdLine(commandToCall
);
147 if (QUIET
== false) {
148 System
.out
.println("Invalid Arguments");
154 System
.out
.println(" Result: " + result
);
159 private int processCmdLine(Cmd cmdCode
) {
160 UpdateDb dbUp
= new UpdateDb();
164 // display current Database contents in CSV format
166 if ((DEBUG
> 3) || (VERBOSE
> MED_VERBOSE
))
167 System
.out
.println("Display contents of the FrameworkDatabase.db file in CSV format.");
168 result
= dbUp
.getCsvEntries(frameworkDatabase
, VERBOSE
);
171 // Automatically make the database match the contents of the workspace
172 // Modifies: FrameworkDatabase.db
173 if ((VERBOSE
> MIN_VERBOSE
) && (QUIET
== false)) {
175 System
.out
.println("Adjusting the FrameworkDatabase to match the contents of the WORKSPACE: "
178 System
.out
.println("Verify the FrameworkDatabase matches the contents of the WORKSPACE: "
181 if ((DEBUG
> 3) || (VERBOSE
> MED_VERBOSE
))
182 System
.out
.println("Scan the Workspace and update the FrameworkDatabase.db file.");
183 result
= dbUp
.fixDatabase(workspace
, VERBOSE
, INTERACTIVE
, TEST
, QUIET
);
187 // Add a Platform, package or FAR to the workspace.
188 // Modifies: FrameworkDatabase.db
189 if (((DEBUG
> 3) || (VERBOSE
> MED_VERBOSE
)) && (isPlatform
))
190 System
.out
.println("Add Platform " + commandArgs
+ " to the FrameworkDatabase.db file");
191 else if (((DEBUG
> 3) || (VERBOSE
> MED_VERBOSE
)) && (isPackage
))
192 System
.out
.println("Add Package " + commandArgs
+ " to the FrameworkDatabase.db file");
193 else if (((DEBUG
> 3) || (VERBOSE
> MED_VERBOSE
)) && (isFar
))
194 System
.out
.println("Add Framework Archive " + commandArgs
+ " to the FrameworkDatabase.db file");
195 result
= dbUp
.addItem(frameworkDatabase
, commandArgs
, VERBOSE
, INTERACTIVE
);
197 case DELETE_SOMETHING
:
198 // Remove a platform, package or FAR from the workspace
199 // Modifies: FrameworkDatabase.db, AND Filesystem
200 if (((DEBUG
> 3) || (VERBOSE
> MED_VERBOSE
)) && (isPlatform
))
201 System
.out
.println("Removing Platform " + commandArgs
+ " from the FrameworkDatabase.db file");
202 else if (((DEBUG
> 3) || (VERBOSE
> MED_VERBOSE
)) && (isPackage
))
203 System
.out
.println("Removing Package " + commandArgs
+ " from the FrameworkDatabase.db file");
204 else if (((DEBUG
> 3) || (VERBOSE
> MED_VERBOSE
)) && (isFar
))
205 System
.out
.println("Removing Framework Archive " + commandArgs
+ " from the FrameworkDatabase.db file");
206 result
= dbUp
.addItem(workspace
, commandArgs
, VERBOSE
, INTERACTIVE
);
209 // Find something in the workspace
211 if ((DEBUG
> 3) || (VERBOSE
> MED_VERBOSE
))
212 System
.out
.println("Finding " + whatToFind
+ " " + commandArgs
+ " in the Workspace");
213 result
= dbUp
.findItem(workspace
, VERBOSE
, whatToFind
, commandArgs
);
216 // Display FAR information for all SPDs in the workspace
218 if ((DEBUG
> 3) || (VERBOSE
> MED_VERBOSE
))
219 System
.out
.println("Display Framework Archives in the Workspace");
220 result
= dbUp
.findFars(workspace
, VERBOSE
);
223 // Display SPD information for all SPDs in the workspace
225 if ((DEBUG
> 3) || (VERBOSE
> MED_VERBOSE
))
226 System
.out
.println("Display Packages in the Workspace");
227 result
= dbUp
.findSpds(workspace
, VERBOSE
);
230 // Display FPD information for all SPDs in the workspace
232 if ((DEBUG
> 3) || (VERBOSE
> MED_VERBOSE
))
233 System
.out
.println("Display Platforms in the Workspace");
234 result
= dbUp
.findFpds(workspace
, VERBOSE
);
237 // ERROR IF WE GET HERE!
238 if ((DEBUG
> 3) || (VERBOSE
> MAX_VERBOSE
))
239 System
.out
.println("We could not process the following: " + commandToCall
.toString());
240 else if (QUIET
== false)
248 private int parseCmdLine(String
[] args
) {
250 // Default is to fix the database.
251 commandToCall
= Cmd
.FIX_DB
;
252 if (args
.length
== NOTFOUND
) {
253 if ((DEBUG
> 3) || (VERBOSE
> MAX_VERBOSE
))
254 System
.out
.println("NO ARGUMENTS! " + commandToCall
.toString());
258 for (int i
= 0; i
< args
.length
; i
++)
259 if (args
[i
].toLowerCase().contentEquals("-q"))
262 for (int i
= 0; i
< args
.length
; i
++) {
263 String arg
= args
[i
].trim();
264 // This is the list of valid options
265 if (!((arg
.toLowerCase().startsWith("-t")) || (arg
.toLowerCase().startsWith("--t"))
266 || (arg
.toLowerCase().startsWith("-q")) || (arg
.toLowerCase().startsWith("-i"))
267 || (arg
.toLowerCase().startsWith("-f")) || (arg
.toLowerCase().startsWith("--f"))
268 || (arg
.toLowerCase().startsWith("-c")) || (arg
.toLowerCase().startsWith("--c"))
269 || (arg
.toLowerCase().startsWith("-a")) || (arg
.toLowerCase().startsWith("--a"))
270 || (arg
.toLowerCase().startsWith("-r")) || (arg
.toLowerCase().startsWith("--d"))
271 || (arg
.toLowerCase().startsWith("-v")) || (arg
.toLowerCase().startsWith("--c"))
272 || (arg
.toLowerCase().startsWith("--p")) || (arg
.toLowerCase().startsWith("-h"))
273 || (arg
.toLowerCase().startsWith("--h")) || (arg
.toLowerCase().startsWith("/h")) || (arg
275 .startsWith("-?")))) {
276 // This is the fall through, we got something we did not know how to
278 if (args
[i
].startsWith("-")) {
279 System
.out
.println("ERROR: E1004 Unknown Option: " + arg
);
280 System
.out
.println("Try running with -h or --help");
282 System
.out
.println("ERROR: E1005 Unknown Argument: " + arg
);
283 System
.out
.println("Try running with -h or --help");
285 System
.out
.println("Program Aborted!");
287 System
.exit(EFAILURE
);
289 if ((arg
.toLowerCase().contentEquals("-t")) || (arg
.toLowerCase().contains("--test"))) {
290 // Test Workspace, do not fix.
293 if (arg
.toLowerCase().contentEquals("-q")) {
296 if (arg
.toLowerCase().contentEquals("-i")) {
299 if ((arg
.toLowerCase().contentEquals("-f")) || (arg
.toLowerCase().contains("--fix"))) {
300 // Non-interactive fix of the database
301 commandToCall
= Cmd
.FIX_DB
;
303 if ((arg
.toLowerCase().contentEquals("-c")) || (arg
.toLowerCase().contains("--csv"))) {
304 // Dump database in CSV format
305 commandToCall
= Cmd
.SHOW_CSV
;
307 if ((arg
.toLowerCase().trim().contentEquals("-a")) || (arg
.toLowerCase().contains("--add"))) {
309 if (args
[i
].startsWith("-")) {
310 System
.out
.println("ERROR: E002 Missing Argument!");
312 .println("The add function requires an argument, either a package name or a platform name!");
313 System
.out
.println("DbUpdate Aborted!");
315 System
.exit(EFAILURE
);
317 commandToCall
= Cmd
.ADD_SOMETHING
;
318 commandArgs
= args
[i
];
319 setArgType(commandArgs
);
321 if ((arg
.toLowerCase().trim().contentEquals("-r")) || (arg
.toLowerCase().contains("--del"))) {
323 if (args
[i
].startsWith("-")) {
324 System
.out
.println("ERROR: E002 Missing Argument!");
326 .println("The remove function requires an argument, either a package name or a platform name!");
327 System
.out
.println("DbUpdate Aborted!");
329 System
.exit(EFAILURE
);
331 commandToCall
= Cmd
.DELETE_SOMETHING
;
332 commandArgs
= args
[i
];
333 setArgType(commandArgs
);
335 if (arg
.toLowerCase().contains("--find")) {
336 commandToCall
= Cmd
.FIND_SOMETHING
;
338 if (args
[i
].toLowerCase().contains("--lib"))
339 whatToFind
= "LIBRARY";
340 else if (args
[i
].toLowerCase().contains("--guid"))
342 else if (args
[i
].toLowerCase().contains("--ppi"))
344 else if (args
[i
].toLowerCase().contains("--prot"))
345 whatToFind
= "PROTOCOL";
346 else if (args
[i
].toLowerCase().contains("--pcd"))
348 else if (args
[i
].startsWith("-")) {
349 System
.out
.println("ERROR: E001 Invalid Argument");
350 System
.out
.println("The find function takes either a qualifier of --guid, --ppi,");
351 System
.out
.println(" --proto, --pcd, or the string to search for.");
353 System
.exit(EFAILURE
);
355 commandArgs
= args
[i
];
357 if (!whatToFind
.contentEquals("")) {
359 if (args
[i
].startsWith("-")) {
360 System
.out
.println("ERROR: E001 Invalid Argument");
361 System
.out
.println("The find function qualifier (--guid, --ppi, --proto, --pcd)");
362 System
.out
.println(" must be followed by the string to search for.");
364 System
.exit(EFAILURE
);
366 commandArgs
= args
[i
];
370 if (arg
.trim().contentEquals("-v")) {
373 if (arg
.toLowerCase().contains("--lib")) {
374 whatToFind
= "LIBRARY";
376 if (arg
.toLowerCase().contains("--guid")) {
379 if (arg
.toLowerCase().contains("--ppi")) {
382 if (arg
.toLowerCase().contains("--prot")) {
383 whatToFind
= "PROTOCOL";
385 if (arg
.toLowerCase().contains("--pcd")) {
388 if (arg
.toLowerCase().contentEquals("-d") || arg
.trim().toLowerCase().contains("--debug")) {
389 if ((i
+ 1 == args
.length
) || (args
[i
+ 1].trim().startsWith("-"))) {
391 } else if (i
+ 1 < args
.length
) {
392 String pattern
= "^\\d+";
393 if (args
[i
+ 1].trim().matches(pattern
)) {
395 DEBUG
= Integer
.parseInt(args
[i
]);
400 if (arg
.trim().contentEquals("-V")) {
401 System
.out
.println("DbTools, " + version
);
402 System
.out
.println(copyright
);
403 System
.out
.println(Specification
);
405 System
.exit(ESUCCESS
);
407 if (arg
.toLowerCase().trim().startsWith("--pack")) {
408 commandToCall
= Cmd
.SHOW_PACKAGES
;
410 if (arg
.toLowerCase().trim().startsWith("--far")) {
411 commandToCall
= Cmd
.SHOW_FAR
;
413 if (arg
.toLowerCase().trim().startsWith("--plat")) {
414 commandToCall
= Cmd
.SHOW_PLATFORMS
;
416 if ((arg
.toLowerCase().contentEquals("-h")) || (arg
.toLowerCase().contentEquals("-?"))
417 || (arg
.toLowerCase().startsWith("/h")) || (arg
.toLowerCase().contentEquals("--help"))) {
419 System
.exit(EFAILURE
);
426 private int testFile(String Filename
) {
427 File tFile
= new File(Filename
);
429 System
.out
.println("File is located: " + tFile
.getPath());
436 private void setArgType(String argv
) {
437 if (argv
.trim().toLowerCase().contains(".spd"))
439 if (argv
.trim().toLowerCase().contains(".fpd"))
441 if (argv
.trim().toLowerCase().contains(".far"))
445 public String
getArgType() {
446 String argt
= "UNKNOWN";
456 private static void outputUsage() {
458 System
.out
.println("DbTool, " + version
);
459 System
.out
.println(copyright
);
460 System
.out
.println("Usage:");
461 System
.out
.println(" DbTool [-v] [-t] [-q] [-V] [--package] [--platform] [-h | -? | --help]");
462 System
.out
.println(" where:");
463 System
.out
.println(" -h | -? | --help OPTIONAL - This Help Text");
465 .println(" -t | --test OPTIONAL - Test the FrameworkDatabase Contents against the WORKSPACE");
467 .println(" -q OPTIONAL - Quiet mode - pass or fail only on return value, nothing is printed");
469 .println(" -f | --fix OPTIONAL - Automatically fix (non-interactive) the Database file to match the WORKSPACE.");
471 .println(" -v OPTIONAL - Verbose, print information messages. Adding more -v arguments increases verbosity.");
472 System
.out
.println(" --package OPTIONAL - Show all Packages installed in the WORKSPACE.");
473 System
.out
.println(" --platforms OPTIONAL - Show all Platforms installed in the WORKSPACE.");
474 System
.out
.println(" -V OPTIONAL - Display Version information and exit.");
476 // TODO: Implement the following options.
479 System.out.println("");
480 System.out.println(" =================== Options below this line have not been implemented in this release ===================");
482 .println(" -i OPTIONAL - Force interactive on commands that modify the WORKSPACE");
484 .println(" --far OPTIONAL - Show all Framework Archives installed in the WORKSPACE.");
486 .println(" --find [qualifier] value OPTIONAL - Search the WORKSPACE for value, with one and only one optional Qualifier.");
487 System.out.println(" qualifiers: --guid Find a GUID by Guid C Name");
488 System.out.println(" --prot Find a Protocol or ProtocolNotify by C Name");
489 System.out.println(" --ppi Find a PPI or PpiNotify by C Name");
490 System.out.println(" --pcd Find a PCD entry by C Name");
491 System.out.println(" --lib Find information about a Library Class");
493 .println(" -c OPTIONAL - Print a comma separated value listing of TYPE,UiName,Filename");
495 .println(" -a, --add value OPTIONAL - Add a value (package, platform or far) to the database");
497 .println(" -r, --del value OPTIONAL - Remove a value (package, platform or far) from the database");
498 System.out.println("");