package org.tianocore.migration;\r
\r
import java.io.File;\r
-import java.util.*;\r
+import java.util.HashMap;\r
+import java.util.Iterator;\r
+import java.util.Set;\r
\r
import javax.swing.JFileChooser;\r
\r
-import org.tianocore.UsageTypes;\r
-\r
+/**\r
+ * The class is used as the main class of the MigrationTool, maintains the main\r
+ * work flow, and all the global variables and constants. It extends nothing.\r
+ * \r
+ */\r
public class MigrationTool {\r
- public static UI ui = null;\r
- public static Database db = null;\r
-\r
- public static String MIGRATIONCOMMENT = "//@MT:";\r
-\r
- public static boolean printModuleInfo = false;\r
- public static boolean doCritic = false;\r
- public static boolean defaultoutput = false;\r
- \r
- public static final HashMap<ModuleInfo, String> ModuleInfoMap = new HashMap<ModuleInfo, String>();\r
-\r
- private static String startpath = null;\r
- \r
- private static final void mainFlow(ModuleInfo mi) throws Exception {\r
- ModuleReader.aimAt(mi);\r
- SourceFileReplacer.fireAt(mi); // some adding library actions are taken here,so it must be put before "MsaWriter"\r
-\r
- // show result\r
- if (MigrationTool.printModuleInfo) {\r
- MigrationTool.ui.println("\nModule Information : ");\r
- MigrationTool.ui.println("Entrypoint : " + mi.entrypoint);\r
- show(mi.protocols, "Protocol : ");\r
- show(mi.ppis, "Ppi : ");\r
- show(mi.guids, "Guid : ");\r
- show(mi.hashfuncc, "call : ");\r
- show(mi.hashfuncd, "def : ");\r
- show(mi.hashEFIcall, "EFIcall : ");\r
- show(mi.hashnonlocalmacro, "macro : ");\r
- show(mi.hashnonlocalfunc, "nonlocal : ");\r
- show(mi.hashr8only, "hashr8only : ");\r
- }\r
- new MsaWriter(mi).flush();\r
-\r
- //mi.getMsaOwner().flush(MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator + mi.modulename + ".___");\r
-\r
- if (MigrationTool.doCritic) {\r
- Critic.fireAt(ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename);\r
- }\r
-\r
- MigrationTool.ui.println("Errors Left : " + MigrationTool.db.error);\r
- MigrationTool.ui.println("Complete!");\r
- }\r
-\r
- private static final void show(Set<String> hash, String show) {\r
- MigrationTool.ui.println(show + hash.size());\r
- MigrationTool.ui.println(hash);\r
- }\r
-\r
- public static final String getTempDir(String modulepath) {\r
- return "C:" + File.separator + "MigrationTool_Temp" + modulepath.replace(startpath, "");\r
- }\r
-\r
- private static final String assignOutPutPath(String inputpath) {\r
- if (MigrationTool.defaultoutput) {\r
- return inputpath.replaceAll(Common.STRSEPARATER, "$1");\r
- } else {\r
- return MigrationTool.ui.getFilepath("Please choose where to place the output module", JFileChooser.DIRECTORIES_ONLY);\r
- }\r
- }\r
- \r
- public static final void seekModule(String filepath) throws Exception {\r
- if (ModuleInfo.isModule(filepath)) {\r
- ModuleInfoMap.put(new ModuleInfo(filepath), assignOutPutPath(filepath));\r
- }\r
- }\r
-\r
- public static final void startMigrateAll(String path) throws Exception {\r
- startpath = path;\r
- MigrationTool.ui.println("Project Migration");\r
- MigrationTool.ui.println("Copyright (c) 2006, Intel Corporation");\r
- \r
- if (new File("C:" + File.separator + "MigrationTool_Temp").exists()) {\r
- Common.deleteDir("C:" + File.separator + "MigrationTool_Temp");\r
- }\r
- \r
- Common.toDoAll(path, MigrationTool.class.getMethod("seekModule", String.class), null, null, Common.DIR);\r
- \r
- Iterator<ModuleInfo> miit = ModuleInfoMap.keySet().iterator();\r
- while (miit.hasNext()) {\r
- mainFlow(miit.next());\r
- }\r
- \r
- ModuleInfoMap.clear();\r
- \r
- Common.deleteDir("C:" + File.separator + "MigrationTool_Temp");\r
- }\r
-\r
- public static void main(String[] args) throws Exception {\r
- ui = FirstPanel.getInstance();\r
- db = Database.getInstance();\r
- }\r
+\r
+ //\r
+ // These two objects are serves globally, it is always required, and only\r
+ // one instance is ever allowed.\r
+ //\r
+ public static UI ui = null;\r
+\r
+ public static Database db = null;\r
+\r
+ //\r
+ // The global constant for MigrationTool generated comments.\r
+ //\r
+ public static String MIGRATIONCOMMENT = "//@MT:";\r
+\r
+ //\r
+ // Global switches that are changed by user by the FirstPanel.\r
+ //\r
+ public static boolean printModuleInfo = false;\r
+\r
+ public static boolean doCritic = false;\r
+\r
+ public static boolean defaultoutput = false;\r
+\r
+ //\r
+ // A hashmap that associates the reference to a ModuleInfo with its\r
+ // outputpath.\r
+ //\r
+ public static final HashMap<ModuleInfo, String> ModuleInfoMap = new HashMap<ModuleInfo, String>();\r
+\r
+ //\r
+ // The starting point of the MigrationTool.\r
+ //\r
+ private static String startpath = null;\r
+\r
+ /**\r
+ * This method defines the overall main work flow of the MigrationTool.\r
+ * \r
+ * @param mi\r
+ * @throws Exception\r
+ */\r
+ private static final void mainFlow(ModuleInfo mi) throws Exception {\r
+ ModuleReader.aimAt(mi);\r
+ SourceFileReplacer.fireAt(mi); // some adding library actions are taken\r
+ // here,so it must be put before\r
+ // "MsaWriter"\r
+\r
+ // show result\r
+ if (MigrationTool.printModuleInfo) {\r
+ MigrationTool.ui.println("\nModule Information : ");\r
+ MigrationTool.ui.println("Entrypoint : " + mi.entrypoint);\r
+ show(mi.protocols, "Protocol : ");\r
+ show(mi.ppis, "Ppi : ");\r
+ show(mi.guids, "Guid : ");\r
+ show(mi.hashfuncc, "call : ");\r
+ show(mi.hashfuncd, "def : ");\r
+ show(mi.hashEFIcall, "EFIcall : ");\r
+ show(mi.hashnonlocalmacro, "macro : ");\r
+ show(mi.hashnonlocalfunc, "nonlocal : ");\r
+ show(mi.hashr8only, "hashr8only : ");\r
+ }\r
+ new MsaWriter(mi).flush();\r
+\r
+ // mi.getMsaOwner().flush(MigrationTool.ModuleInfoMap.get(mi) +\r
+ // File.separator + "Migration_" + mi.modulename + File.separator +\r
+ // mi.modulename + ".___");\r
+\r
+ if (MigrationTool.doCritic) {\r
+ Critic.fireAt(ModuleInfoMap.get(mi) + File.separator + "Migration_"\r
+ + mi.modulename);\r
+ }\r
+\r
+ MigrationTool.ui.println("Errors Left : " + MigrationTool.db.error);\r
+ MigrationTool.ui.println("Complete!");\r
+ }\r
+\r
+ /**\r
+ * This method is specially written to print the message for ModuleInfo,\r
+ * just for less code repeating.\r
+ * \r
+ * @param hash\r
+ * @param show\r
+ */\r
+ private static final void show(Set<String> hash, String show) {\r
+ MigrationTool.ui.println(show + hash.size());\r
+ MigrationTool.ui.println(hash);\r
+ }\r
+\r
+ /**\r
+ * This method designates the location of temp directory.\r
+ * \r
+ * @param modulepath\r
+ * @return\r
+ */\r
+ public static final String getTempDir(String modulepath) {\r
+ return "C:" + File.separator + "MigrationTool_Temp"\r
+ + modulepath.replace(startpath, "");\r
+ }\r
+\r
+ private static final String assignOutPutPath(String inputpath) {\r
+ if (MigrationTool.defaultoutput) {\r
+ return inputpath.replaceAll(Common.STRSEPARATER, "$1");\r
+ } else {\r
+ return MigrationTool.ui.getFilepath(\r
+ "Please choose where to place the output module",\r
+ JFileChooser.DIRECTORIES_ONLY);\r
+ }\r
+ }\r
+\r
+ public static final void seekModule(String filepath) throws Exception {\r
+ if (ModuleInfo.isModule(filepath)) {\r
+ ModuleInfoMap.put(new ModuleInfo(filepath),\r
+ assignOutPutPath(filepath));\r
+ }\r
+ }\r
+\r
+ public static final void startMigrateAll(String path) throws Exception {\r
+ startpath = path;\r
+ MigrationTool.ui.println("Project Migration");\r
+ MigrationTool.ui.println("Copyright (c) 2006, Intel Corporation");\r
+\r
+ if (new File("C:" + File.separator + "MigrationTool_Temp").exists()) {\r
+ Common.deleteDir("C:" + File.separator + "MigrationTool_Temp");\r
+ }\r
+\r
+ Common.toDoAll(path, MigrationTool.class.getMethod("seekModule",\r
+ String.class), null, null, Common.DIR);\r
+\r
+ Iterator<ModuleInfo> miit = ModuleInfoMap.keySet().iterator();\r
+ while (miit.hasNext()) {\r
+ mainFlow(miit.next());\r
+ }\r
+\r
+ ModuleInfoMap.clear();\r
+\r
+ Common.deleteDir("C:" + File.separator + "MigrationTool_Temp");\r
+ }\r
+\r
+ public static void main(String[] args) throws Exception {\r
+ ui = FirstPanel.getInstance();\r
+ db = Database.getInstance();\r
+ }\r
}\r