]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/Merge/src/org/tianocore/Merge/MergeCmd.java
Restructuring for better separation of Tool packages.
[mirror_edk2.git] / Tools / Java / Source / Merge / src / org / tianocore / Merge / MergeCmd.java
1 // @file
2 // MergeCmd command-line interface to the classes that combine
3 // multiple MSA files into a single MSA file.
4 //
5 // Copyright (c) 2006, Intel Corporation All rights reserved.
6 //
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
11 //
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.
14 //
15 // This program is the command line interface to the CombineMsa class, which
16 // will take the following arguments:
17 //
18 // Input:
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.
25 //
26 // Output:
27 // Target.msa
28 //
29 // Modifies - OPTIONAL
30 // Package.spd
31 //
32
33 package org.tianocore.Merge;
34
35 import java.io.*;
36 import java.util.*;
37
38 // import org.tianocore.Merge.CombineMsa;
39
40 public class MergeCmd {
41
42 private static int DEBUG = 1;
43
44 private static final String copyright = "Copyright (c) 2006, Intel Corporation All rights reserved.";
45
46 private static final String version = "Version 0.1";
47
48 private int VERBOSE = 0;
49
50 private String targetFile = null;
51
52 private ArrayList<String> leafFiles = new ArrayList<String>();
53
54 private String spdFile = null;
55
56 private String uiName = null;
57
58 private String fileBasename = null;
59
60 private final int ESUCCESS = 0;
61
62 private final int EFAILURE = 1;
63
64 private final static int FOUND = 1;
65
66 private final static int NOTFOUND = 0;
67
68 private int result = ESUCCESS;
69
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());
78 if (spdFile != null)
79 System.out.println("Package Name: " + spdFile);
80 if (uiName != null)
81 System.out.println("User Interface Name: " + uiName);
82 }
83 CombineMsa newMsa = new CombineMsa();
84 result = newMsa.combineMsaFiles(targetFile, leafFiles, uiName, spdFile, fileBasename, VERBOSE);
85 }
86 return result;
87 }
88
89 private int parseCmdLine(String[] args) {
90
91 if (args.length == NOTFOUND) {
92 outputUsage();
93 System.exit(EFAILURE);
94 }
95
96 for (int i = 0; i < args.length; i++) {
97 if (args[i].toLowerCase().contains("-t")) {
98 i++;
99 targetFile = args[i];
100 targetFile.replace(" ", "_");
101 if (!targetFile.toLowerCase().contains(".msa"))
102 targetFile = targetFile + ".msa";
103
104
105 } else if (args[i].toLowerCase().contains("-p")) {
106 i++;
107 spdFile = args[i];
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;
115 try {
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);
121 } else {
122 spdFile = null;
123 System.out
124 .println("Continuing with the Merge. Don't forget to add the new MSA file to a Package.");
125 }
126 } catch (IOException e) {
127 System.out.println("IOException: " + e);
128 }
129 }
130 } else if (args[i].toLowerCase().contains("-u")) {
131 i++;
132 uiName = args[i];
133 } else if (args[i].toLowerCase().contains("-o")) {
134 i++;
135 fileBasename = args[i];
136 } else if (args[i].toLowerCase().contains("-v")) {
137 VERBOSE++;
138 } else if ((args[i].toLowerCase().contains("-h")) || (args[i].toLowerCase().contains("-?"))
139 || (args[i].toLowerCase().contains("/h")) || (args[i].toLowerCase().contains("--help"))) {
140 outputUsage();
141 System.exit(EFAILURE);
142 } else {
143 if (args[i].startsWith("-")) {
144 System.out.println("Invalid Argument: " + args[i]);
145 outputUsage();
146 System.out.println("Merge Aborted!");
147 System.exit(EFAILURE);
148 }
149 String leafFile = args[i];
150 if (!leafFile.toLowerCase().contains(".msa"))
151 leafFile = leafFile + ".msa";
152
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);
157 } else {
158 if (DEBUG > 9)
159 System.out.println("Found Leaf Module: " + leafFile);
160 leafFiles.add(leafFile);
161 }
162 }
163 }
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;
168 try {
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);
175 }
176 } catch (IOException e) {
177 System.out.println("IOException: " + e);
178 }
179
180 }
181 return ESUCCESS;
182 }
183
184 private static int testFile(String Filename) {
185 File tFile = new File(Filename);
186 if (DEBUG > 8)
187 System.out.println("File is located: " + tFile.getPath());
188 if (tFile.exists())
189 return FOUND;
190 else
191 return NOTFOUND;
192 }
193
194 private static void outputUsage() {
195
196
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("");
210 }
211 }