]>
Commit | Line | Data |
---|---|---|
5ad6d22a | 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 | |
482407d3 | 13 | package org.tianocore.migration;\r |
14 | \r | |
15 | import java.io.File;\r | |
71f30e51 | 16 | import java.util.HashMap;\r |
17 | import java.util.Iterator;\r | |
18 | import java.util.Set;\r | |
482407d3 | 19 | \r |
5ad6d22a | 20 | import javax.swing.JFileChooser;\r |
21 | \r | |
71f30e51 | 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 | |
482407d3 | 27 | public class MigrationTool {\r |
71f30e51 | 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\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 | private static final String assignOutPutPath(String inputpath) {\r | |
127 | if (MigrationTool.defaultoutput) {\r | |
128 | return inputpath.replaceAll(Common.STRSEPARATER, "$1");\r | |
129 | } else {\r | |
130 | return MigrationTool.ui.getFilepath(\r | |
131 | "Please choose where to place the output module",\r | |
132 | JFileChooser.DIRECTORIES_ONLY);\r | |
133 | }\r | |
134 | }\r | |
135 | \r | |
136 | public static final void seekModule(String filepath) throws Exception {\r | |
137 | if (ModuleInfo.isModule(filepath)) {\r | |
138 | ModuleInfoMap.put(new ModuleInfo(filepath),\r | |
139 | assignOutPutPath(filepath));\r | |
140 | }\r | |
141 | }\r | |
142 | \r | |
143 | public static final void startMigrateAll(String path) throws Exception {\r | |
144 | startpath = path;\r | |
145 | MigrationTool.ui.println("Project Migration");\r | |
146 | MigrationTool.ui.println("Copyright (c) 2006, Intel Corporation");\r | |
147 | \r | |
148 | if (new File("C:" + File.separator + "MigrationTool_Temp").exists()) {\r | |
149 | Common.deleteDir("C:" + File.separator + "MigrationTool_Temp");\r | |
150 | }\r | |
151 | \r | |
152 | Common.toDoAll(path, MigrationTool.class.getMethod("seekModule",\r | |
153 | String.class), null, null, Common.DIR);\r | |
154 | \r | |
155 | Iterator<ModuleInfo> miit = ModuleInfoMap.keySet().iterator();\r | |
156 | while (miit.hasNext()) {\r | |
157 | mainFlow(miit.next());\r | |
158 | }\r | |
159 | \r | |
160 | ModuleInfoMap.clear();\r | |
161 | \r | |
162 | Common.deleteDir("C:" + File.separator + "MigrationTool_Temp");\r | |
163 | }\r | |
164 | \r | |
165 | public static void main(String[] args) throws Exception {\r | |
166 | ui = FirstPanel.getInstance();\r | |
167 | db = Database.getInstance();\r | |
168 | }\r | |
482407d3 | 169 | }\r |