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