REMODEL OF SourceFileReplacer.java
authoralfred <alfred@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 5 Sep 2006 07:37:01 +0000 (07:37 +0000)
committeralfred <alfred@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 5 Sep 2006 07:37:01 +0000 (07:37 +0000)
AT LAST

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1464 6f19259b-4bc3-4df7-8a09-765794883524

Tools/Source/MigrationTools/org/tianocore/migration/Common.java
Tools/Source/MigrationTools/org/tianocore/migration/MigrationTool.java
Tools/Source/MigrationTools/org/tianocore/migration/ModuleInfo.java
Tools/Source/MigrationTools/org/tianocore/migration/SourceFileReplacer.java

index 19f64f7e512ea5dc874bc73714e755eff8f8340b..fb89dcae4dfa452e65d43b2e05ade852a577caca 100644 (file)
@@ -142,8 +142,15 @@ public final class Common {
                        }\r
                }\r
        }\r
+\r
+       public static final void toDoAll(Set<String> set, ForDoAll fda) throws Exception {\r
+               Iterator<String> di = set.iterator();\r
+               while (di.hasNext()) {\r
+                       fda.run(di.next());\r
+               }\r
+       }\r
        \r
-       public static void toDoAll(String path, ForDoAll fda, int type) throws Exception { // filter of file type can be done in toDo\r
+       public static final void toDoAll(String path, ForDoAll fda, int type) throws Exception { // filter of file type can be done in toDo\r
                String[] list = new File(path).list();\r
                File test;\r
 \r
index cbb49a13daa06953406b0afaef9c8f37cf6918bd..5f84ccd6538b74286a78a5c4802bfa20b63c1b6a 100644 (file)
@@ -34,7 +34,7 @@ public class MigrationTool {
                ModuleReader.ModuleScan(mi);\r
                \r
                //MigrationTool.ui.yesOrNo("go on replace?");\r
-               SourceFileReplacer.flush(mi);   // some adding library actions are taken here,so it must be put before "MsaWriter"\r
+               SourceFileReplacer.fireAt(mi);  // some adding library actions are taken here,so it must be put before "MsaWriter"\r
 \r
                //MigrationTool.ui.yesOrNo("go on show?");\r
                // show result\r
index 5706488c94fdc965c06b99f4b3cfcf9a04ca37b1..d53c7b93f746ce4092c7cf4417a2e1a880ee1ac3 100644 (file)
@@ -15,8 +15,6 @@ package org.tianocore.migration;
 import java.io.*;\r
 import java.util.*;\r
 \r
-import org.tianocore.ModuleTypeDef;\r
-\r
 /*\r
        Class ModuleInfo is built for scanning the source files, it contains all the needed\r
 information and all the temporary data.\r
index 50606a716004c7c7dc99614b6d729becb8c76a77..e6d86b60b43afba0592174b95562a54e8bd8866b 100644 (file)
@@ -17,9 +17,10 @@ import java.util.*;
 import java.util.regex.Matcher;\r
 import java.util.regex.Pattern;\r
 \r
-public final class SourceFileReplacer {\r
-       private static ModuleInfo mi;\r
-       private static boolean showdetails = false;\r
+public final class SourceFileReplacer implements Common.ForDoAll {\r
+       private static final SourceFileReplacer SFReplacer = new SourceFileReplacer();\r
+       private ModuleInfo mi;\r
+       private static boolean showdetails = true;              // set this as default now, may be changed in the future\r
        \r
        private static class r8tor9 {\r
                r8tor9(String r8, String r9) {\r
@@ -38,52 +39,11 @@ public final class SourceFileReplacer {
        private static final Set<r8tor9> fileprotocol = new HashSet<r8tor9>();\r
        private static final Set<String> filer8only = new HashSet<String>();\r
        \r
-       public static final void flush(ModuleInfo moduleinfo) throws Exception {\r
-               mi = moduleinfo;\r
-               \r
-               String outname = null;\r
-               String inname = null;\r
-\r
-               showdetails = true;                     // set this as default now, may be changed in the future\r
-               \r
-               Iterator<String> di = mi.localmodulesources.iterator();\r
-               String tempinpath = mi.modulepath + File.separator + "temp" + File.separator;\r
-               String tempoutpath = MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator;\r
-               while (di.hasNext()) {\r
-                       inname = di.next();\r
-                       if (inname.contains(".c") || inname.contains(".C")) {\r
-                               if (inname.contains(".C")) {\r
-                                       outname = inname.replaceFirst(".C", ".c");\r
-                               } else {\r
-                                       outname = inname;\r
-                               }\r
-                               MigrationTool.ui.println("\nModifying file: " + inname);\r
-                               Common.string2file(sourcefilereplace(Common.file2string(tempinpath + inname)), tempoutpath + outname);\r
-                       } else if (inname.contains(".h") || inname.contains(".H") || inname.contains(".uni")) {\r
-                               if (inname.contains(".H")) {\r
-                                       outname = inname.replaceFirst(".H", ".h");\r
-                               } else {\r
-                                       outname = inname;\r
-                               }\r
-                               MigrationTool.ui.println("\nCopying file: " + inname);\r
-                               Common.string2file(Common.file2string(tempinpath + inname), tempoutpath + outname);\r
-                       } else if (inname.contains(".dxs")) {\r
-                               outname = inname;\r
-                               MigrationTool.ui.println("\nModifying file: " + inname);\r
-                               Common.string2file(convertdxs(Common.file2string(tempinpath + inname)), tempoutpath + outname);\r
-                       }\r
-               }\r
-\r
-               if (!mi.hashr8only.isEmpty()) {\r
-                       addr8only();\r
-               }\r
-       }\r
-       \r
        private static final String addincludefile(String wholeline, String hfile) {\r
                return wholeline.replaceFirst("(\\*/\\s)", "$1\n#include " + hfile + "\n");\r
        }\r
        \r
-       private static final String convertdxs(String wholeline) {\r
+       private final String convertdxs(String wholeline) {\r
                if (mi.getModuleType().equals("PEIM")) {\r
                        return addincludefile(wholeline, "\\<PeimDepex.h\\>");\r
                } else {\r
@@ -91,7 +51,7 @@ public final class SourceFileReplacer {
                }\r
        }\r
        \r
-       private static final void addr8only() throws Exception {\r
+       private final void addr8only() throws Exception {\r
                String paragraph = null;\r
                String line = Common.file2string(MigrationTool.db.DatabasePath + File.separator + "R8Lib.c");\r
                PrintWriter outfile1 = new PrintWriter(new BufferedWriter(new FileWriter(MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator + "R8Lib.c")));\r
@@ -123,7 +83,7 @@ public final 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 static final String sourcefilereplace(String wholeline) throws Exception {\r
+       private final String sourcefilereplace(String wholeline) throws Exception {\r
                boolean addr8 = false;\r
 \r
                Pattern pat = Pattern.compile("g?(BS|RT)(\\s*->\\s*)([a-zA-Z_]\\w*)", Pattern.MULTILINE);                                       // ! only two level () bracket allowed !\r
@@ -312,4 +272,60 @@ public final class SourceFileReplacer {
                        }\r
                }\r
        }\r
+       \r
+       //-----------------------------------ForDoAll-----------------------------------//\r
+       public void run(String filepath) throws Exception {\r
+               String outname = null;\r
+               String inname = filepath.replace(mi.modulepath + File.separator, "");\r
+               String tempinpath = mi.modulepath + File.separator + "temp" + File.separator;\r
+               String tempoutpath = MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator;\r
+\r
+               if (inname.contains(".c") || inname.contains(".C")) {\r
+                       if (inname.contains(".C")) {\r
+                               outname = inname.replaceFirst(".C", ".c");\r
+                       } else {\r
+                               outname = inname;\r
+                       }\r
+                       MigrationTool.ui.println("\nModifying file: " + inname);\r
+                       Common.string2file(sourcefilereplace(Common.file2string(tempinpath + inname)), tempoutpath + outname);\r
+               } else if (inname.contains(".h") || inname.contains(".H") || inname.contains(".uni")) {\r
+                       if (inname.contains(".H")) {\r
+                               outname = inname.replaceFirst(".H", ".h");\r
+                       } else {\r
+                               outname = inname;\r
+                       }\r
+                       MigrationTool.ui.println("\nCopying file: " + inname);\r
+                       Common.string2file(Common.file2string(tempinpath + inname), tempoutpath + outname);\r
+               } else if (inname.contains(".dxs")) {\r
+                       outname = inname;\r
+                       MigrationTool.ui.println("\nModifying file: " + inname);\r
+                       Common.string2file(convertdxs(Common.file2string(tempinpath + inname)), tempoutpath + outname);\r
+               }\r
+       }\r
+       \r
+       public boolean dirFilter(String filepath) {\r
+               return true;\r
+       }\r
+       \r
+       public boolean fileFilter(String filepath) {\r
+               return true;\r
+       }\r
+       //-----------------------------------ForDoAll-----------------------------------//\r
+       \r
+       private final void setModuleInfo(ModuleInfo moduleinfo) {\r
+               mi = moduleinfo;\r
+       }\r
+       \r
+       private final void start() throws Exception {\r
+               Common.toDoAll(mi.localmodulesources, this);\r
+               \r
+               if (!mi.hashr8only.isEmpty()) {\r
+                       addr8only();\r
+               }\r
+       }\r
+       \r
+       public static final void fireAt(ModuleInfo moduleinfo) throws Exception {\r
+               SFReplacer.setModuleInfo(moduleinfo);\r
+               SFReplacer.start();\r
+       }\r
 }\r