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