]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/MigrationTools/org/tianocore/migration/SourceFileReplacer.java
last
[mirror_edk2.git] / Tools / Source / MigrationTools / org / tianocore / migration / SourceFileReplacer.java
index 03617ab7167cc61e51d0031b20be09fced2b994a..fdc8a657a7884f60b320cbfd504e44dfa007b46c 100644 (file)
@@ -17,20 +17,11 @@ import java.util.*;
 import java.util.regex.Matcher;\r
 import java.util.regex.Pattern;\r
 \r
-public class SourceFileReplacer {\r
-       SourceFileReplacer(String path, ModuleInfo moduleinfo, Database database, UI fp) {\r
-               modulepath = path;\r
-               mi = moduleinfo;\r
-               db = database;\r
-               ui = fp;\r
-       }\r
-       private String modulepath;\r
-       private ModuleInfo mi;\r
-       private Database db;\r
-       private UI ui;\r
-       private boolean showdetails = false;\r
+public final class SourceFileReplacer {\r
+       private static ModuleInfo mi;\r
+       private static boolean showdetails = false;\r
        \r
-       private class r8tor9 {\r
+       private static class r8tor9 {\r
                r8tor9(String r8, String r9) {\r
                        r8thing = r8;\r
                        r9thing = r9;\r
@@ -40,38 +31,20 @@ public class SourceFileReplacer {
        }\r
        \r
        // these sets are used only for printing log of the changes in current file\r
-       private Set<r8tor9> filefunc = new HashSet<r8tor9>();\r
-       private Set<r8tor9> filemacro = new HashSet<r8tor9>();\r
-       private Set<r8tor9> fileguid = new HashSet<r8tor9>();\r
-       private Set<r8tor9> fileppi = new HashSet<r8tor9>();\r
-       private Set<r8tor9> fileprotocol = new HashSet<r8tor9>();\r
-       private Set<String> filer8only = new HashSet<String>();\r
-       \r
-       private String r8only = "EfiLibInstallDriverBinding " +\r
-                       "EfiLibInstallAllDriverProtocols " +\r
-                       "EfiLibCompareLanguage " +\r
-                       "BufToHexString " +\r
-                       "EfiStrTrim " +                                                 //is the r8only lib going to be enlarged????  Caution !!!!\r
-                       "EfiValueToHexStr " +\r
-                       "HexStringToBuf " +\r
-                       "IsHexDigit " +\r
-                       "NibbleToHexChar " +\r
-                       "GetHob " +\r
-                       "GetHobListSize " +\r
-                       "GetHobVersion " +\r
-                       "GetHobBootMode " +\r
-                       "GetCpuHobInfo " +\r
-                       "GetDxeCoreHobInfo " +\r
-                       "GetNextFirmwareVolumeHob " +\r
-                       "GetNextGuidHob " +\r
-                       "GetPalEntryHobInfo " +\r
-                       "GetIoPortSpaceAddressHobInfo ";\r
+       private static final Set<r8tor9> filefunc = new HashSet<r8tor9>();\r
+       private static final Set<r8tor9> filemacro = new HashSet<r8tor9>();\r
+       private static final Set<r8tor9> fileguid = new HashSet<r8tor9>();\r
+       private static final Set<r8tor9> fileppi = new HashSet<r8tor9>();\r
+       private static final Set<r8tor9> fileprotocol = new HashSet<r8tor9>();\r
+       private static final Set<String> filer8only = new HashSet<String>();\r
        \r
-       public void flush() throws Exception {\r
-               PrintWriter outfile;\r
+       public static final void flush(ModuleInfo moduleinfo) throws Exception {\r
+               \r
+               mi = moduleinfo;\r
+               \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
@@ -84,24 +57,16 @@ public class SourceFileReplacer {
                                } else {\r
                                        outname = inname;\r
                                }\r
-                               ui.println("\nModifying file: " + inname);\r
-                               Common.ensureDir(modulepath + File.separator + "result" + File.separator + outname);\r
-                               outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + outname)));\r
-                               outfile.append(sourcefilereplace(modulepath + File.separator + "temp" + File.separator + inname));\r
-                               outfile.flush();\r
-                               outfile.close();\r
+                               MigrationTool.ui.println("\nModifying file: " + inname);\r
+                               Common.string2file(sourcefilereplace(mi.modulepath + File.separator + "temp" + File.separator + inname), mi.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
                                        outname = inname.replaceFirst(".H", ".h");\r
                                } else {\r
                                        outname = inname;\r
                                }\r
-                               ui.println("\nCopying file: " + inname);\r
-                               Common.ensureDir(modulepath + File.separator + "result" + File.separator + outname);\r
-                               outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + outname)));\r
-                               outfile.append(Common.sourcefiletostring(modulepath + File.separator + "temp" + File.separator + inname));\r
-                               outfile.flush();\r
-                               outfile.close();\r
+                               MigrationTool.ui.println("\nCopying file: " + inname);\r
+                               Common.string2file(Common.file2string(mi.modulepath + File.separator + "temp" + File.separator + inname), mi.outputpath + File.separator + "Migration_" + mi.modulename + File.separator + outname);\r
                        }\r
                }\r
 \r
@@ -110,12 +75,12 @@ public class SourceFileReplacer {
                }\r
        }\r
        \r
-       private void addr8only() throws Exception {\r
+       private static final void addr8only() throws Exception {\r
                String paragraph = null;\r
-               String line = Common.sourcefiletostring(Database.defaultpath + File.separator + "R8Lib.c");\r
-               Common.ensureDir(modulepath + File.separator + "result" + File.separator + "R8Lib.c");\r
-               PrintWriter outfile1 = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + "R8Lib.c")));\r
-               PrintWriter outfile2 = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + "R8Lib.h")));\r
+               String line = Common.file2string(MigrationTool.db.DatabasePath + File.separator + "R8Lib.c");\r
+               //Common.ensureDir(mi.modulepath + File.separator + "Migration_" + mi.modulename + File.separator + "R8Lib.c");\r
+               PrintWriter outfile1 = new PrintWriter(new BufferedWriter(new FileWriter(mi.outputpath + File.separator + "Migration_" + mi.modulename + File.separator + "R8Lib.c")));\r
+               PrintWriter outfile2 = new PrintWriter(new BufferedWriter(new FileWriter(mi.outputpath + File.separator + "Migration_" + mi.modulename + File.separator + "R8Lib.h")));\r
                Pattern ptnr8only = Pattern.compile("////#?(\\w*)?.*?R8_(\\w*).*?////~", Pattern.DOTALL);\r
                Matcher mtrr8only = ptnr8only.matcher(line);\r
                Matcher mtrr8onlyhead;\r
@@ -143,7 +108,7 @@ public class SourceFileReplacer {
        }\r
        \r
        // Caution : if there is @ in file , it will be replaced with \n , so is you use Doxygen ... God Bless you!\r
-       private String sourcefilereplace(String filename) throws Exception {\r
+       private static final String sourcefilereplace(String filename) throws Exception {\r
                BufferedReader rd = new BufferedReader(new FileReader(filename));\r
                StringBuffer wholefile = new StringBuffer();\r
                String line;\r
@@ -163,7 +128,7 @@ public 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
@@ -180,7 +145,7 @@ public 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
@@ -198,10 +163,10 @@ public 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
@@ -209,7 +174,7 @@ public class SourceFileReplacer {
                                                Iterator<r8tor9> rt = filefunc.iterator();\r
                                                while (rt.hasNext()) {\r
                                                        temp = rt.next();\r
-                                                       if (r8only.contains(temp.r8thing)) {\r
+                                                       if (MigrationTool.db.r8only.contains(temp.r8thing)) {\r
                                                                filer8only.add(r8thing);\r
                                                                mi.hashr8only.add(r8thing);\r
                                                                addr8 = true;\r
@@ -227,8 +192,8 @@ public 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
@@ -295,7 +260,7 @@ public 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
@@ -308,29 +273,29 @@ public class SourceFileReplacer {
                return line;\r
        }\r
        \r
-       private void show(Set<r8tor9> hash, String sh) {\r
+       private static final void show(Set<r8tor9> hash, String sh) {\r
                Iterator<r8tor9> it = hash.iterator();\r
                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
        \r
-       private void replaceGuid(String line, Set<String> hash, String kind, Set<r8tor9> filehash) {\r
+       private static final void replaceGuid(String line, Set<String> hash, String kind, Set<r8tor9> filehash) {\r
                Iterator<String> it;\r
                String r8thing;\r
                String r9thing;\r
                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