]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - Tools/Java/Source/MigrationTools/org/tianocore/migration/MigrationTool.java
Coding Style
[mirror_edk2.git] / Tools / Java / Source / MigrationTools / org / tianocore / migration / MigrationTool.java
... / ...
CommitLineData
1/** @file\r
2 \r
3 Copyright (c) 2006, Intel Corporation\r
4 All rights reserved. This program and the accompanying materials\r
5 are licensed and made available under the terms and conditions of the BSD License\r
6 which accompanies this distribution. The full text of the license may be found at\r
7 http://opensource.org/licenses/bsd-license.php\r
8 \r
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11 \r
12 **/\r
13package org.tianocore.migration;\r
14\r
15import java.io.File;\r
16import java.util.HashMap;\r
17import java.util.Iterator;\r
18import java.util.Set;\r
19\r
20import javax.swing.JFileChooser;\r
21\r
22/**\r
23 * The class is used as the main class of the MigrationTool, maintains the main\r
24 * work flow, and all the global variables and constants. It extends nothing.\r
25 * \r
26 */\r
27public class MigrationTool {\r
28\r
29 //\r
30 // These two objects are serves globally, it is always required, and only\r
31 // one instance is ever allowed.\r
32 //\r
33 public static UI ui = null;\r
34\r
35 public static Database db = null;\r
36\r
37 //\r
38 // The global constant for MigrationTool generated comments.\r
39 //\r
40 public static String MIGRATIONCOMMENT = "//@MT:";\r
41\r
42 //\r
43 // Global switches that are changed by user by the FirstPanel.\r
44 //\r
45 public static boolean printModuleInfo = false;\r
46\r
47 public static boolean doCritic = false;\r
48\r
49 public static boolean defaultoutput = false;\r
50\r
51 //\r
52 // A hashmap that associates the reference to a ModuleInfo with its\r
53 // outputpath.\r
54 //\r
55 public static final HashMap<ModuleInfo, String> ModuleInfoMap = new HashMap<ModuleInfo, String>();\r
56\r
57 //\r
58 // The starting point of the MigrationTool.\r
59 //\r
60 private static String startpath = null;\r
61\r
62 /**\r
63 * This method defines the overall main work flow of the MigrationTool.\r
64 * \r
65 * @param mi\r
66 * @throws Exception\r
67 */\r
68 private static final void mainFlow(ModuleInfo mi) throws Exception {\r
69 ModuleReader.aimAt(mi);\r
70 SourceFileReplacer.fireAt(mi); // some adding library actions are taken\r
71 // here,so it must be put before\r
72 // "MsaWriter"\r
73\r
74 // show result\r
75 if (MigrationTool.printModuleInfo) {\r
76 MigrationTool.ui.println("\nModule Information : ");\r
77 MigrationTool.ui.println("Entrypoint : " + mi.entrypoint);\r
78 show(mi.protocols, "Protocol : ");\r
79 show(mi.ppis, "Ppi : ");\r
80 show(mi.guids, "Guid : ");\r
81 show(mi.hashfuncc, "call : ");\r
82 show(mi.hashfuncd, "def : ");\r
83 show(mi.hashEFIcall, "EFIcall : ");\r
84 show(mi.hashnonlocalmacro, "macro : ");\r
85 show(mi.hashnonlocalfunc, "nonlocal : ");\r
86 show(mi.hashr8only, "hashr8only : ");\r
87 }\r
88 new MsaWriter(mi).flush();\r
89\r
90 // mi.getMsaOwner().flush(MigrationTool.ModuleInfoMap.get(mi) +\r
91 // File.separator + "Migration_" + mi.modulename + File.separator +\r
92 // mi.modulename + ".___");\r
93\r
94 if (MigrationTool.doCritic) {\r
95 Critic.fireAt(ModuleInfoMap.get(mi) + File.separator + "Migration_"\r
96 + mi.modulename);\r
97 }\r
98\r
99 MigrationTool.ui.println("Errors Left : " + MigrationTool.db.error);\r
100 MigrationTool.ui.println("Complete!");\r
101 }\r
102\r
103 /**\r
104 * This method is specially written to print the message for ModuleInfo,\r
105 * just for less code repeating.\r
106 * \r
107 * @param hash\r
108 * @param show\r
109 */\r
110 private static final void show(Set<String> hash, String show) {\r
111 MigrationTool.ui.println(show + hash.size());\r
112 MigrationTool.ui.println(hash);\r
113 }\r
114\r
115 /**\r
116 * This method designates the location of temp directory.\r
117 * \r
118 * @param modulepath\r
119 * @return String\r
120 */\r
121 public static final String getTempDir(String modulepath) {\r
122 return "C:" + File.separator + "MigrationTool_Temp"\r
123 + modulepath.replace(startpath, "");\r
124 }\r
125\r
126 /**\r
127 * This method is the default output path generating scheme.\r
128 * \r
129 * @param inputpath\r
130 * @return String\r
131 */\r
132 private static final String assignOutPutPath(String inputpath) {\r
133 if (MigrationTool.defaultoutput) {\r
134 return inputpath.replaceAll(Common.STRSEPARATER, "$1");\r
135 } else {\r
136 return MigrationTool.ui.getFilepath(\r
137 "Please choose where to place the output module",\r
138 JFileChooser.DIRECTORIES_ONLY);\r
139 }\r
140 }\r
141\r
142 /**\r
143 * This function is called by main loop of the MigrationTool which\r
144 * verifies whether a dir contains a module, thus generating a map\r
145 * which shows the corresponding path for each module.\r
146 * \r
147 * @param filepath\r
148 * @throws Exception\r
149 */\r
150 public static final void seekModule(String filepath) throws Exception {\r
151 if (ModuleInfo.isModule(filepath)) {\r
152 ModuleInfoMap.put(new ModuleInfo(filepath),\r
153 assignOutPutPath(filepath));\r
154 }\r
155 }\r
156\r
157 /**\r
158 * This is the main loop of the tool.\r
159 * \r
160 * @param path\r
161 * @throws Exception\r
162 */\r
163 public static final void startMigrateAll(String path) throws Exception {\r
164 startpath = path;\r
165 MigrationTool.ui.println("Project Migration");\r
166 MigrationTool.ui.println("Copyright (c) 2006, Intel Corporation");\r
167\r
168 if (new File("C:" + File.separator + "MigrationTool_Temp").exists()) {\r
169 Common.deleteDir("C:" + File.separator + "MigrationTool_Temp");\r
170 }\r
171\r
172 Common.toDoAll(path, MigrationTool.class.getMethod("seekModule",\r
173 String.class), null, null, Common.DIR);\r
174\r
175 Iterator<ModuleInfo> miit = ModuleInfoMap.keySet().iterator();\r
176 while (miit.hasNext()) {\r
177 mainFlow(miit.next());\r
178 }\r
179\r
180 ModuleInfoMap.clear();\r
181\r
182 Common.deleteDir("C:" + File.separator + "MigrationTool_Temp");\r
183 }\r
184\r
185 /**\r
186 * This main method initializes the environment. \r
187 * \r
188 * @param args\r
189 * @throws Exception\r
190 */\r
191 public static void main(String[] args) throws Exception {\r
192 ui = FirstPanel.getInstance();\r
193 db = Database.getInstance();\r
194 }\r
195}