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
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.
13 package org
.tianocore
.migration
;
16 import java
.util
.HashMap
;
17 import java
.util
.Iterator
;
20 import javax
.swing
.JFileChooser
;
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.
27 public class MigrationTool
{
30 // These two objects are serves globally, it is always required, and only
31 // one instance is ever allowed.
33 public static UI ui
= null;
35 public static Database db
= null;
38 // The global constant for MigrationTool generated comments.
40 public static String MIGRATIONCOMMENT
= "//@MT:";
43 // Global switches that are changed by user by the FirstPanel.
45 public static boolean printModuleInfo
= false;
47 public static boolean doCritic
= false;
49 public static boolean defaultoutput
= false;
52 // A hashmap that associates the reference to a ModuleInfo with its
55 public static final HashMap
<ModuleInfo
, String
> ModuleInfoMap
= new HashMap
<ModuleInfo
, String
>();
58 // The starting point of the MigrationTool.
60 private static String startpath
= null;
63 * This method defines the overall main work flow of the MigrationTool.
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
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 : ");
88 new MsaWriter(mi
).flush();
90 // mi.getMsaOwner().flush(MigrationTool.ModuleInfoMap.get(mi) +
91 // File.separator + "Migration_" + mi.modulename + File.separator +
92 // mi.modulename + ".___");
94 if (MigrationTool
.doCritic
) {
95 Critic
.fireAt(ModuleInfoMap
.get(mi
) + File
.separator
+ "Migration_"
99 MigrationTool
.ui
.println("Errors Left : " + MigrationTool
.db
.error
);
100 MigrationTool
.ui
.println("Complete!");
104 * This method is specially written to print the message for ModuleInfo,
105 * just for less code repeating.
110 private static final void show(Set
<String
> hash
, String show
) {
111 MigrationTool
.ui
.println(show
+ hash
.size());
112 MigrationTool
.ui
.println(hash
);
116 * This method designates the location of temp directory.
121 public static final String
getTempDir(String modulepath
) {
122 return "C:" + File
.separator
+ "MigrationTool_Temp"
123 + modulepath
.replace(startpath
, "");
126 private static final String
assignOutPutPath(String inputpath
) {
127 if (MigrationTool
.defaultoutput
) {
128 return inputpath
.replaceAll(Common
.STRSEPARATER
, "$1");
130 return MigrationTool
.ui
.getFilepath(
131 "Please choose where to place the output module",
132 JFileChooser
.DIRECTORIES_ONLY
);
136 public static final void seekModule(String filepath
) throws Exception
{
137 if (ModuleInfo
.isModule(filepath
)) {
138 ModuleInfoMap
.put(new ModuleInfo(filepath
),
139 assignOutPutPath(filepath
));
143 public static final void startMigrateAll(String path
) throws Exception
{
145 MigrationTool
.ui
.println("Project Migration");
146 MigrationTool
.ui
.println("Copyright (c) 2006, Intel Corporation");
148 if (new File("C:" + File
.separator
+ "MigrationTool_Temp").exists()) {
149 Common
.deleteDir("C:" + File
.separator
+ "MigrationTool_Temp");
152 Common
.toDoAll(path
, MigrationTool
.class.getMethod("seekModule",
153 String
.class), null, null, Common
.DIR
);
155 Iterator
<ModuleInfo
> miit
= ModuleInfoMap
.keySet().iterator();
156 while (miit
.hasNext()) {
157 mainFlow(miit
.next());
160 ModuleInfoMap
.clear();
162 Common
.deleteDir("C:" + File
.separator
+ "MigrationTool_Temp");
165 public static void main(String
[] args
) throws Exception
{
166 ui
= FirstPanel
.getInstance();
167 db
= Database
.getInstance();