remodel 1
authoralfred <alfred@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 21 Aug 2006 08:54:07 +0000 (08:54 +0000)
committeralfred <alfred@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 21 Aug 2006 08:54:07 +0000 (08:54 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1335 6f19259b-4bc3-4df7-8a09-765794883524

Tools/Source/MigrationTools/org/tianocore/migration/Database.java
Tools/Source/MigrationTools/org/tianocore/migration/FirstPanel.java
Tools/Source/MigrationTools/org/tianocore/migration/Guid.java
Tools/Source/MigrationTools/org/tianocore/migration/Macro.java
Tools/Source/MigrationTools/org/tianocore/migration/MigrationTool.java
Tools/Source/MigrationTools/org/tianocore/migration/ModuleInfo.java
Tools/Source/MigrationTools/org/tianocore/migration/ModuleReader.java
Tools/Source/MigrationTools/org/tianocore/migration/MsaTreeEditor.java
Tools/Source/MigrationTools/org/tianocore/migration/MsaWriter.java
Tools/Source/MigrationTools/org/tianocore/migration/SourceFileReplacer.java

index f33670e7f19ae7ccd518f14a6796f66c6102c285..a4b0d47872f374c599e8dc69b8eb2b5e6d167fab 100644 (file)
@@ -15,13 +15,9 @@ package org.tianocore.migration;
 import java.io.*;\r
 import java.util.*;\r
 \r
-public class Database {\r
-       Database() throws Exception {\r
-               if (System.getenv("WORKSPACE") == null) {\r
-                       DatabasePath = "C:" + File.separator + "tianocore" + File.separator + "edk2" + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration";\r
-               } else {\r
-                       DatabasePath = System.getenv("WORKSPACE") + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration";\r
-               }\r
+public final class Database {\r
+       Database(String path) throws Exception {\r
+               DatabasePath = path;\r
                \r
                importDBLib("Library.csv");\r
                importDBGuid("Guid.csv", "Guid");\r
@@ -124,7 +120,7 @@ public class Database {
        public String getR9Macro(String r8macro) {\r
                return hashmacro.get(r8macro).r9name;                   // the verification job of if the macro exists in the database is done when registering it\r
        }\r
-       \r
+\r
        public String getR9Guidname(String r8Guid) {\r
                String temp = null;\r
                try {\r
@@ -134,7 +130,7 @@ public class Database {
                }\r
                return temp;\r
        }\r
-       \r
+\r
        public String getGuidType(String r8Guid) {\r
                String temp = null;\r
                try {\r
@@ -144,4 +140,12 @@ public class Database {
                }\r
                return temp;\r
        }\r
+\r
+       public static Database init() throws Exception {\r
+               if (System.getenv("WORKSPACE") == null) {\r
+                       return new Database("C:" + File.separator + "tianocore" + File.separator + "edk2" + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration");\r
+               } else {\r
+                       return new Database(System.getenv("WORKSPACE") + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration");\r
+               }\r
+       }\r
 }\r
index 1d9cf64a618ac96ef5d70ef9a8194a3e3f2e58bd..8c07783cd4aaef7af414d31928518327bf56678b 100644 (file)
@@ -128,21 +128,11 @@ public final class FirstPanel extends JPanel implements ActionListener, UI {
     public void actionPerformed(ActionEvent e) {\r
         if ( e.getSource() == moduleButton ) {\r
                modulepath = getFilepath();\r
-               /*\r
-               int ret = fc.showOpenDialog(this);\r
-               if (ret == JFileChooser.APPROVE_OPTION) {\r
-                       modulepath = fc.getSelectedFile().getAbsolutePath();\r
-                       moduletext.setText(modulepath);\r
-                log.append("ModulePath: " + modulepath + "\n");\r
-               }\r
-               */\r
         }\r
         if ( e.getSource() == goButton ) {\r
                try {\r
                        logfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "migration.log")));\r
-                       println("Project MsaGen");\r
-                       println("Copyright (c) 2006, Intel Corporation");\r
-                       Common.toDoAll(modulepath, ModuleInfo.class.getMethod("seekModule", String.class), null, null, Common.DIR);\r
+                       ModuleInfo.triger(modulepath);\r
                        logfile.flush();\r
                } catch (Exception en) {\r
                        println(en.getMessage());\r
index 440d0c6c68e4fa459a717b27e37a60ac5e4ec171..ed6a7a77f22796827e301c3622abcb7c9cd738ff 100644 (file)
@@ -45,8 +45,8 @@ public class Guid {
                String temp = null;\r
                \r
                temp = mtr.group();\r
-               if (db.hasGuid(temp)) {         // only changed guids registered, because both changed and not changed guids are included in database\r
-                       type = db.getGuidType(temp);\r
+               if (MigrationTool.db.hasGuid(temp)) {           // only changed guids registered, because both changed and not changed guids are included in database\r
+                       type = MigrationTool.db.getGuidType(temp);\r
                        if (type.matches("Protocol")) {\r
                                mi.protocol.add(temp);\r
                        } else if (type.matches("Ppi")) {\r
index 7051985ea7cb99969ea912384bb0e6b062444495..47c507baf41f4b46b65a47fe71eaa963044e9af1 100644 (file)
@@ -35,7 +35,7 @@ public class Macro {
                String temp = null;\r
                \r
                temp = mtr.group();\r
-               if (db.hasMacro(temp)) {                                        // only changed macros registered, because the database of macro has only changed ones\r
+               if (MigrationTool.db.hasMacro(temp)) {                                  // only changed macros registered, because the database of macro has only changed ones\r
                        if (!unmacro.contains(temp)) {\r
                                mi.hashnonlocalmacro.add(temp);\r
                        }\r
index be8d55a2e10113b195a7cbf2411b91fdf3b76649..0d48be52ebcd883c616182a4b4092e9a2c972cf5 100644 (file)
@@ -1,8 +1,11 @@
 package org.tianocore.migration;\r
 \r
 public class MigrationTool {\r
+       public static UI ui = null;\r
+       public static Database db = null;\r
+       \r
        public static void main(String[] args) throws Exception {\r
-               ModuleInfo.ui = FirstPanel.init();\r
-               ModuleInfo.db = new Database();\r
+               ui = FirstPanel.init();\r
+               db = Database.init();\r
        }\r
 }\r
index 2f3af0309e9c16b8fda479de182c0eab1d5bfec2..5502cbb00c573b475b251496072e1dbbdf7bbb5b 100644 (file)
@@ -24,16 +24,16 @@ public class ModuleInfo {
        ModuleInfo(String modulepath) throws Exception {\r
                this.modulepath = modulepath;\r
                \r
-               ui.println("Choose where to place the result");\r
-               if ((outputpath = ui.getFilepath()) == null) {\r
+               MigrationTool.ui.println("Choose where to place the result");\r
+               if ((outputpath = MigrationTool.ui.getFilepath()) == null) {\r
                        outputpath = modulepath; \r
                }\r
-               ui.println(outputpath);\r
+               MigrationTool.ui.println(outputpath);\r
                \r
                moduleScan();\r
        }\r
 \r
-       public static UI ui = null;                             //if MIM is still usefull, this can be given to it\r
+       //public static UI ui = null;                           //if MIM is still usefull, this can be given to it\r
        public static Database db = null;                       //if MIM is still usefull, this can be given to it\r
        \r
        public String modulepath = null;\r
@@ -68,10 +68,10 @@ public class ModuleInfo {
                \r
                String filename = null;\r
                if (msaorinf.isEmpty()) {\r
-                       ui.println("No INF nor MSA file found!");\r
+                       MigrationTool.ui.println("No INF nor MSA file found!");\r
                        System.exit(0);\r
                } else {\r
-                       filename = ui.choose("Found .inf or .msa file for module\n" + modulepath + "\nChoose one Please", msaorinf.toArray());\r
+                       filename = MigrationTool.ui.choose("Found .inf or .msa file for module\n" + modulepath + "\nChoose one Please", msaorinf.toArray());\r
                }\r
                //ModuleReader mr = new ModuleReader(modulepath, this, db, ui);\r
                if (filename.contains(".inf")) {\r
@@ -83,12 +83,12 @@ public class ModuleInfo {
                CommentOutNonLocalHFile();\r
                parsePreProcessedSourceCode();\r
 \r
-               new SourceFileReplacer(modulepath, outputpath, this, db, ui).flush();   // some adding library actions are taken here,so it must be put before "MsaWriter"\r
+               new SourceFileReplacer(modulepath, outputpath, this).flush();   // some adding library actions are taken here,so it must be put before "MsaWriter"\r
                \r
                // show result\r
-               if (ui.yesOrNo("Parse of the Module Information has completed. View details?")) {\r
-                       ui.println("\nModule Information : ");\r
-                       ui.println("Entrypoint : " + entrypoint);\r
+               if (MigrationTool.ui.yesOrNo("Parse of the Module Information has completed. View details?")) {\r
+                       MigrationTool.ui.println("\nModule Information : ");\r
+                       MigrationTool.ui.println("Entrypoint : " + entrypoint);\r
                        show(protocol, "Protocol : ");\r
                        show(ppi, "Ppi : ");\r
                        show(guid, "Guid : ");\r
@@ -100,20 +100,20 @@ public class ModuleInfo {
                        show(hashr8only, "hashr8only : ");\r
                }\r
                \r
-               new MsaWriter(modulepath, outputpath, this, db, ui).flush();\r
+               new MsaWriter(modulepath, outputpath, this).flush();\r
 \r
                Common.deleteDir(modulepath + File.separator + "temp");\r
                //Common.toDoAll(modulepath + File.separator + "temp", Common.class.getMethod("deleteDir", String.class), null, null, Common.DIR);\r
                \r
-               ui.println("Errors Left : " + db.error);\r
-               ui.println("Complete!");\r
-               ui.println("Your R9 module was placed here: " + modulepath + File.separator + "result");\r
-               ui.println("Your logfile was placed here: " + modulepath);\r
+               MigrationTool.ui.println("Errors Left : " + MigrationTool.db.error);\r
+               MigrationTool.ui.println("Complete!");\r
+               MigrationTool.ui.println("Your R9 module was placed here: " + modulepath + File.separator + "result");\r
+               MigrationTool.ui.println("Your logfile was placed here: " + modulepath);\r
        }\r
        \r
        private void show(Set<String> hash, String show) {\r
-               ui.println(show + hash.size());\r
-               ui.println(hash);\r
+               MigrationTool.ui.println(show + hash.size());\r
+               MigrationTool.ui.println(hash);\r
        }\r
        \r
        // add '//' to all non-local include lines\r
@@ -204,7 +204,7 @@ public class ModuleInfo {
                        matguid = Guid.ptnguid.matcher(line);                                                                           // several ways to implement this , which one is faster ? :\r
                        while (matguid.find()) {                                                                                                        // 1.currently , find once , then call to identify which is it\r
                                if ((temp = Guid.register(matguid, this, db)) != null) {                                // 2.use 3 different matchers , search 3 times to find each\r
-                                       //matguid.appendReplacement(result, db.getR9Guidname(temp));            // search the database for all 3 kinds of guids , high cost\r
+                                       //matguid.appendReplacement(result, MigrationTool.db.getR9Guidname(temp));              // search the database for all 3 kinds of guids , high cost\r
                                }\r
                        }\r
                        //matguid.appendTail(result);\r
@@ -221,8 +221,8 @@ public class ModuleInfo {
                        matfuncc = Func.ptnfuncc.matcher(line);\r
                        while (matfuncc.find()) {\r
                                if ((temp = Func.register(matfuncc, this, db)) != null) {\r
-                                       //ui.println(ifile + "  dofunc  " + temp);\r
-                                       //matfuncc.appendReplacement(result, db.getR9Func(temp));\r
+                                       //MigrationTool.ui.println(ifile + "  dofunc  " + temp);\r
+                                       //matfuncc.appendReplacement(result, MigrationTool.db.getR9Func(temp));\r
                                }\r
                        }\r
                        //matfuncc.appendTail(result);\r
@@ -268,10 +268,9 @@ public class ModuleInfo {
                        msaorinf.add(temp[temp.length - 1]);\r
                }\r
        }\r
-       \r
+\r
        public static final void seekModule(String filepath) throws Exception {\r
                if (isModule(filepath)) {\r
-                       //System.out.println("I'm in");\r
                        new ModuleInfo(filepath);\r
                }\r
        }\r
@@ -287,10 +286,10 @@ public class ModuleInfo {
                }\r
                return false;\r
        }\r
-/*\r
-       public static final void main(String[] args) throws Exception {\r
-               ui = FirstPanel.init();\r
-               db = new Database();\r
+       \r
+       public static final void triger(String path) throws Exception {\r
+               MigrationTool.ui.println("Project Migration");\r
+               MigrationTool.ui.println("Copyright (c) 2006, Intel Corporation");\r
+               Common.toDoAll(path, ModuleInfo.class.getMethod("seekModule", String.class), null, null, Common.DIR);\r
        }\r
-       */\r
 }
\ No newline at end of file
index b8bde6fef0fc445d46636ba1dc7409749ede0057..dd8df97b5ebdb251caaaa3fca53a06bd66bf1c03 100644 (file)
@@ -18,17 +18,6 @@ import java.util.regex.*;
 import org.tianocore.*;\r
 \r
 public final class ModuleReader {\r
-       ModuleReader(String path, ModuleInfo moduleinfo, Database database, UI u) {\r
-               //modulepath = path;\r
-               //mi = moduleinfo;\r
-               db = database;\r
-               ui = u;\r
-       }\r
-       //private static String modulepath;\r
-       //private static ModuleInfo mi;\r
-       private static Database db;\r
-       private static UI ui;\r
-       \r
        private static final Pattern ptninfequation = Pattern.compile("([^\\s]*)\\s*=\\s*([^\\s]*)");\r
        private static final Pattern ptnsection = Pattern.compile("\\[([^\\[\\]]*)\\]([^\\[\\]]*)\\n", Pattern.MULTILINE);\r
        private static final Pattern ptnfilename = Pattern.compile("[^\\s]+");\r
@@ -37,11 +26,11 @@ public final class ModuleReader {
                ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(new File(mi.modulepath + File.separator + name));\r
                ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc.getModuleSurfaceArea();\r
                MsaHeaderDocument.MsaHeader msaheader = msa.getMsaHeader();\r
-               \r
+\r
                mi.modulename = msaheader.getModuleName();\r
                mi.guidvalue = msaheader.getGuidValue();\r
                mi.moduletype = msaheader.getModuleType().toString();           // ???\r
-               \r
+\r
                SourceFilesDocument.SourceFiles sourcefiles = msa.getSourceFiles();\r
                \r
                String temp;\r
@@ -85,7 +74,7 @@ public final class ModuleReader {
                                        }\r
                                        if (mtrinfequation.group(1).matches("DPX_SOURCE")) {\r
                                                if (!mi.localmodulesources.contains(mtrinfequation.group(2))) {\r
-                                                       ui.println("DPX File Missing! : " + mtrinfequation.group(2));\r
+                                                       MigrationTool.ui.println("DPX File Missing! : " + mtrinfequation.group(2));\r
                                                }\r
                                        }\r
                                }\r
@@ -94,7 +83,7 @@ public final class ModuleReader {
                                mtrfilename = ptnfilename.matcher(mtrsection.group(2));\r
                                while (mtrfilename.find()) {\r
                                        if (!mi.localmodulesources.contains(mtrfilename.group())) {\r
-                                               ui.println("Source File Missing! : " + mtrfilename.group());\r
+                                               MigrationTool.ui.println("Source File Missing! : " + mtrfilename.group());\r
                                        }\r
                                }\r
                        }\r
index 19c3dcd984a50f0338ef6495af707507dc643a75..5eb688ce0e8d9e90770737933b0b896315af0d08 100644 (file)
@@ -104,7 +104,7 @@ public class MsaTreeEditor extends JPanel {
        }\r
        \r
        private void addNode() {\r
-               addNode((DefaultMutableTreeNode)(tree.getSelectionPath().getLastPathComponent()), ui.getInput("Input Node Name"));\r
+               addNode((DefaultMutableTreeNode)(tree.getSelectionPath().getLastPathComponent()), MigrationTool.ui.getInput("Input Node Name"));\r
        }\r
        \r
        private void addNode(DefaultMutableTreeNode parentNode, Object child) {\r
index caec997c922ac3c61e0c41b79f8f80e51a030090..f79843337c4a32fab4822708a3ec3ac584d962b7 100644 (file)
@@ -20,19 +20,15 @@ import org.tianocore.SupportedArchitectures.Enum;
 import org.apache.xmlbeans.*;\r
 \r
 public class MsaWriter {\r
-       MsaWriter(String path, String outpath, ModuleInfo moduleinfo, Database database, UI u) {\r
+       MsaWriter(String path, String outpath, ModuleInfo moduleinfo) {\r
                modulepath = path;\r
                outputpath = outpath;\r
                mi = moduleinfo;\r
-               db = database;\r
-               ui = u;\r
        }\r
 \r
        private String modulepath;\r
        private String outputpath;\r
        private ModuleInfo mi;\r
-       private Database db;\r
-       private UI ui;\r
        \r
        private ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.newInstance();\r
        \r
index c1c36981d5d8ac78f86e1cadade3fa99e97d5937..bc579ac741945ccc984cec8a78a0a38f177a89f7 100644 (file)
@@ -18,18 +18,14 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;\r
 \r
 public final class SourceFileReplacer {\r
-       SourceFileReplacer(String path, String outpath, ModuleInfo moduleinfo, Database database, UI fp) {\r
+       SourceFileReplacer(String path, String outpath, ModuleInfo moduleinfo) {\r
                modulepath = path;\r
                outputpath = outpath;\r
                mi = moduleinfo;\r
-               db = database;\r
-               ui = fp;\r
        }\r
        private String modulepath;\r
        private String outputpath;\r
        private ModuleInfo mi;\r
-       private Database db;\r
-       private UI ui;\r
        private boolean showdetails = false;\r
        \r
        private class r8tor9 {\r
@@ -72,7 +68,7 @@ public final class SourceFileReplacer {
        public void flush() throws Exception {\r
                String outname = null;\r
                String inname = null;\r
-               if (ui.yesOrNo("Changes will be made to the Source Code.  View details?")) {\r
+               if (MigrationTool.ui.yesOrNo("Changes will be made to the Source Code.  View details?")) {\r
                        showdetails = true;\r
                }\r
                \r
@@ -85,7 +81,7 @@ public final class SourceFileReplacer {
                                } else {\r
                                        outname = inname;\r
                                }\r
-                               ui.println("\nModifying file: " + inname);\r
+                               MigrationTool.ui.println("\nModifying file: " + inname);\r
                                Common.string2file(sourcefilereplace(modulepath + File.separator + "temp" + File.separator + inname), outputpath + File.separator + "Migration_" + mi.modulename + File.separator + outname);\r
                        } else if (inname.contains(".h") || inname.contains(".H") || inname.contains(".dxs") || inname.contains(".uni")) {\r
                                if (inname.contains(".H")) {\r
@@ -93,7 +89,7 @@ public final class SourceFileReplacer {
                                } else {\r
                                        outname = inname;\r
                                }\r
-                               ui.println("\nCopying file: " + inname);\r
+                               MigrationTool.ui.println("\nCopying file: " + inname);\r
                                Common.string2file(Common.file2string(modulepath + File.separator + "temp" + File.separator + inname), outputpath + File.separator + "Migration_" + mi.modulename + File.separator + outname);\r
                        }\r
                }\r
@@ -156,7 +152,7 @@ public final class SourceFileReplacer {
                // replace BS -> gBS , RT -> gRT\r
                Matcher mat = pat.matcher(line);\r
                if (mat.find()) {                                                                                               // add a library here\r
-                       ui.println("Converting all BS->gBS, RT->gRT");\r
+                       MigrationTool.ui.println("Converting all BS->gBS, RT->gRT");\r
                        line = mat.replaceAll("g$1$2$3");                                                       //unknown correctiveness\r
                }\r
                mat.reset();\r
@@ -173,7 +169,7 @@ public final class SourceFileReplacer {
                Pattern patentrypoint = Pattern.compile("EFI_DRIVER_ENTRY_POINT[^\\}]*\\}");\r
                Matcher matentrypoint = patentrypoint.matcher(line);\r
                if (matentrypoint.find()) {\r
-                       ui.println("Deleting Entry_Point");\r
+                       MigrationTool.ui.println("Deleting Entry_Point");\r
                        line = matentrypoint.replaceAll("");\r
                }\r
                */\r
@@ -191,10 +187,10 @@ public final class SourceFileReplacer {
                                mi.hashrequiredr9libs.add("UefiRuntimeServicesTableLib");               //a\r
                                mi.hashrequiredr9libs.add("DxeServicesTableLib");                               //l\r
                        } else {                                                                                                                        //\r
-                               mi.hashrequiredr9libs.add(db.getR9Lib(r8thing));                                // add a library here\r
+                               mi.hashrequiredr9libs.add(MigrationTool.db.getR9Lib(r8thing));                          // add a library here\r
                        }\r
                        \r
-                       if ((r9thing = db.getR9Func(r8thing)) != null) {\r
+                       if ((r9thing = MigrationTool.db.getR9Func(r8thing)) != null) {\r
                                if (!r8thing.equals(r9thing)) {\r
                                        if (line.contains(r8thing)) {\r
                                                line = line.replaceAll(r8thing, r9thing);\r
@@ -220,8 +216,8 @@ public final class SourceFileReplacer {
                it = mi.hashnonlocalmacro.iterator();\r
                while (it.hasNext()) {                                          //macros are all assumed MdePkg currently\r
                        r8thing = it.next();\r
-                       //mi.hashrequiredr9libs.add(db.getR9Lib(r8thing));              \r
-                       if ((r9thing = db.getR9Macro(r8thing)) != null) {\r
+                       //mi.hashrequiredr9libs.add(MigrationTool.db.getR9Lib(r8thing));                \r
+                       if ((r9thing = MigrationTool.db.getR9Macro(r8thing)) != null) {\r
                                if (line.contains(r8thing)) {\r
                                        line = line.replaceAll(r8thing, r9thing);\r
                                        filemacro.add(new r8tor9(r8thing, r9thing));\r
@@ -288,7 +284,7 @@ public final class SourceFileReplacer {
                show(fileppi, "ppi");\r
                show(fileprotocol, "protocol");\r
                if (!filer8only.isEmpty()) {\r
-                       ui.println("Converting r8only : " + filer8only);\r
+                       MigrationTool.ui.println("Converting r8only : " + filer8only);\r
                }\r
 \r
                filefunc.clear();\r
@@ -306,12 +302,12 @@ public final class SourceFileReplacer {
                r8tor9 temp;\r
                if (showdetails) {\r
                        if (!hash.isEmpty()) {\r
-                               ui.print("Converting " + sh + " : ");\r
+                               MigrationTool.ui.print("Converting " + sh + " : ");\r
                                while (it.hasNext()) {\r
                                        temp = it.next();\r
-                                       ui.print("[" + temp.r8thing + "->" + temp.r9thing + "] ");\r
+                                       MigrationTool.ui.print("[" + temp.r8thing + "->" + temp.r9thing + "] ");\r
                                }\r
-                               ui.println("");\r
+                               MigrationTool.ui.println("");\r
                        }\r
                }\r
        }\r
@@ -323,7 +319,7 @@ public final class SourceFileReplacer {
                it = hash.iterator();\r
                while (it.hasNext()) {\r
                        r8thing = it.next();\r
-                       if ((r9thing = db.getR9Guidname(r8thing)) != null) {\r
+                       if ((r9thing = MigrationTool.db.getR9Guidname(r8thing)) != null) {\r
                                if (!r8thing.equals(r9thing)) {\r
                                        if (line.contains(r8thing)) {\r
                                                line = line.replaceAll(r8thing, r9thing);\r