]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/MigrationTools/org/tianocore/migration/MigrationTool.java
7ed4113ad4014276d7c63c9555bc6339f9be0048
[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
120 */
121 public static final String getTempDir(String modulepath) {
122 return "C:" + File.separator + "MigrationTool_Temp"
123 + modulepath.replace(startpath, "");
124 }
125
126 private static final String assignOutPutPath(String inputpath) {
127 if (MigrationTool.defaultoutput) {
128 return inputpath.replaceAll(Common.STRSEPARATER, "$1");
129 } else {
130 return MigrationTool.ui.getFilepath(
131 "Please choose where to place the output module",
132 JFileChooser.DIRECTORIES_ONLY);
133 }
134 }
135
136 public static final void seekModule(String filepath) throws Exception {
137 if (ModuleInfo.isModule(filepath)) {
138 ModuleInfoMap.put(new ModuleInfo(filepath),
139 assignOutPutPath(filepath));
140 }
141 }
142
143 public static final void startMigrateAll(String path) throws Exception {
144 startpath = path;
145 MigrationTool.ui.println("Project Migration");
146 MigrationTool.ui.println("Copyright (c) 2006, Intel Corporation");
147
148 if (new File("C:" + File.separator + "MigrationTool_Temp").exists()) {
149 Common.deleteDir("C:" + File.separator + "MigrationTool_Temp");
150 }
151
152 Common.toDoAll(path, MigrationTool.class.getMethod("seekModule",
153 String.class), null, null, Common.DIR);
154
155 Iterator<ModuleInfo> miit = ModuleInfoMap.keySet().iterator();
156 while (miit.hasNext()) {
157 mainFlow(miit.next());
158 }
159
160 ModuleInfoMap.clear();
161
162 Common.deleteDir("C:" + File.separator + "MigrationTool_Temp");
163 }
164
165 public static void main(String[] args) throws Exception {
166 ui = FirstPanel.getInstance();
167 db = Database.getInstance();
168 }
169 }