2 // MergeCmd command-line interface to the classes that combine
3 // multiple MSA files into a single MSA file.
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 Target The MSA file that will be created
20 // -u UiName The UiName for the merged MSA OPTIONAL
21 // If not provided, the UiName will come from the
22 // first leaf MSA file
23 // -p Package The SPD file that the new MSA file will be added to. OPTIONAL
24 // leaf.msa The path and filename of the MSA files to be merged into the Target.
29 // Modifies - OPTIONAL
33 package org
.tianocore
.Merge
;
38 // import org.tianocore.Merge.CombineMsa;
40 public class MergeCmd
{
42 private static int DEBUG
= 1;
44 private static final String copyright
= "Copyright (c) 2006, Intel Corporation All rights reserved.";
46 private static final String version
= "Version 0.1";
48 private int VERBOSE
= 0;
50 private String targetFile
= null;
52 private ArrayList
<String
> leafFiles
= new ArrayList
<String
>();
54 private String spdFile
= null;
56 private String uiName
= null;
58 private String fileBasename
= null;
60 private final int ESUCCESS
= 0;
62 private final int EFAILURE
= 1;
64 private final static int FOUND
= 1;
66 private final static int NOTFOUND
= 0;
68 private int result
= ESUCCESS
;
70 public int MergeCmdLine(String
[] args
) {
71 result
= parseCmdLine(args
);
72 if (result
== ESUCCESS
) {
73 if ((DEBUG
> 7) || (VERBOSE
> 5)) {
74 System
.out
.println("Parse Succeeded!");
75 System
.out
.println("CWD: " + System
.getProperty("user.dir"));
76 System
.out
.println("Merge Module Name: " + targetFile
);
77 System
.out
.println("Found Leaf Module: " + leafFiles
.size());
79 System
.out
.println("Package Name: " + spdFile
);
81 System
.out
.println("User Interface Name: " + uiName
);
83 CombineMsa newMsa
= new CombineMsa();
84 result
= newMsa
.combineMsaFiles(targetFile
, leafFiles
, uiName
, spdFile
, fileBasename
, VERBOSE
);
89 private int parseCmdLine(String
[] args
) {
91 if (args
.length
== NOTFOUND
) {
93 System
.exit(EFAILURE
);
96 for (int i
= 0; i
< args
.length
; i
++) {
97 if (args
[i
].toLowerCase().contains("-t")) {
100 targetFile
.replace(" ", "_");
101 if (!targetFile
.toLowerCase().contains(".msa"))
102 targetFile
= targetFile
+ ".msa";
105 } else if (args
[i
].toLowerCase().contains("-p")) {
108 if (!spdFile
.toLowerCase().contains(".spd"))
109 spdFile
= spdFile
+ ".spd";
110 spdFile
= spdFile
.replace("\\", "/").trim();
111 if (testFile(spdFile
) == NOTFOUND
) {
112 System
.out
.println("WARNING: The Package file: " + spdFile
+ " does NOT exist!");
113 System
.out
.print("Do you want to continue anyway [y|N]? ");
114 String inputLine
= null;
116 BufferedReader inputString
= new BufferedReader(new InputStreamReader(System
.in
));
117 inputLine
= inputString
.readLine();
118 if ((inputLine
.length() == 0) || (!inputLine
.toLowerCase().contains("y"))) {
119 System
.out
.println("Merge Aborted at user request!");
120 System
.exit(EFAILURE
);
124 .println("Continuing with the Merge. Don't forget to add the new MSA file to a Package.");
126 } catch (IOException e
) {
127 System
.out
.println("IOException: " + e
);
130 } else if (args
[i
].toLowerCase().contains("-u")) {
133 } else if (args
[i
].toLowerCase().contains("-o")) {
135 fileBasename
= args
[i
];
136 } else if (args
[i
].toLowerCase().contains("-v")) {
138 } else if ((args
[i
].toLowerCase().contains("-h")) || (args
[i
].toLowerCase().contains("-?"))
139 || (args
[i
].toLowerCase().contains("/h")) || (args
[i
].toLowerCase().contains("--help"))) {
141 System
.exit(EFAILURE
);
143 if (args
[i
].startsWith("-")) {
144 System
.out
.println("Invalid Argument: " + args
[i
]);
146 System
.out
.println("Merge Aborted!");
147 System
.exit(EFAILURE
);
149 String leafFile
= args
[i
];
150 if (!leafFile
.toLowerCase().contains(".msa"))
151 leafFile
= leafFile
+ ".msa";
153 if (testFile(leafFile
) == NOTFOUND
) {
154 System
.out
.println("ERROR: The Leaf MSA File: " + leafFile
+ " was NOT FOUND!");
155 System
.out
.println("Merge Aborted!");
156 System
.exit(EFAILURE
);
159 System
.out
.println("Found Leaf Module: " + leafFile
);
160 leafFiles
.add(leafFile
);
164 if (testFile(targetFile
) == FOUND
) {
165 System
.out
.println("WARNING: The targetfile: " + targetFile
+ "Already Exists!");
166 System
.out
.print("Do you want to over write it [y|N]? ");
167 String inputLine
= null;
169 BufferedReader inputString
= new BufferedReader(new InputStreamReader(System
.in
));
170 inputLine
= inputString
.readLine();
171 if ((inputLine
.length() == 0) || (!inputLine
.toLowerCase().contains("y"))) {
172 System
.out
.println("Please correct the options, then try again.");
173 System
.out
.println("Merge Aborted at user request!");
174 System
.exit(EFAILURE
);
176 } catch (IOException e
) {
177 System
.out
.println("IOException: " + e
);
184 private static int testFile(String Filename
) {
185 File tFile
= new File(Filename
);
187 System
.out
.println("File is located: " + tFile
.getPath());
194 private static void outputUsage() {
197 System
.out
.println("Merge, " + version
);
198 System
.out
.println(copyright
);
199 System
.out
.println("Usage:");
200 System
.out
.println(" merge [-v] -t target [-u UiName] [-p PackageFile] dir1" + File
.separator
+ "leaf1 ... dirN" + File
.separator
+ "leafN [-h | -? | --help]");
201 System
.out
.println(" where:");
202 System
.out
.println(" -h | -? | --help OPTIONAL - This Help Text");
203 System
.out
.println(" -t Target REQUIRED - The Name of the new Merge Module MSA file");
204 System
.out
.println(" -p Package OPTIONAL - The Name of the Package (SPD) file to add the target");
205 System
.out
.println(" -u UiName OPTIONAL - The User Interface Name for the Target Module");
206 System
.out
.println(" -v OPTIONAL - Verbose, print information messages.");
207 System
.out
.println(" -o OutputFileBasename OPTIONAL - Set the Output Filename for this module to Basename");
208 System
.out
.println(" dir1" + File
.separator
+ "leaf1 ... dirN" + File
.separator
+ "leafN REQUIRED The path to two or more MSA files that will be merged");
209 System
.out
.println("");