Turn to Regex in ModuleReader.java
authoralfred <alfred@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 15 Aug 2006 12:35:00 +0000 (12:35 +0000)
committeralfred <alfred@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 15 Aug 2006 12:35:00 +0000 (12:35 +0000)
1st edition of MsaTreeEditor.java
Some edit on ia32 x64... in .inf-read and MsaWriter.java

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

Tools/Source/MigrationTools/org/tianocore/migration/Common.java [new file with mode: 0644]
Tools/Source/MigrationTools/org/tianocore/migration/FirstPanel.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 [new file with mode: 0644]
Tools/Source/MigrationTools/org/tianocore/migration/MsaWriter.java
Tools/Source/MigrationTools/org/tianocore/migration/SourceFileReplacer.java
Tools/Source/MigrationTools/org/tianocore/migration/UI.java

diff --git a/Tools/Source/MigrationTools/org/tianocore/migration/Common.java b/Tools/Source/MigrationTools/org/tianocore/migration/Common.java
new file mode 100644 (file)
index 0000000..10bc283
--- /dev/null
@@ -0,0 +1,32 @@
+package org.tianocore.migration;\r
+\r
+import java.io.BufferedReader;\r
+import java.io.File;\r
+import java.io.FileReader;\r
+import java.util.regex.Matcher;\r
+import java.util.regex.Pattern;\r
+\r
+public class Common {\r
+       public static String sourcefiletostring(String filename) throws Exception {\r
+               BufferedReader rd = new BufferedReader(new FileReader(filename));\r
+               StringBuffer wholefile = new StringBuffer();\r
+               String line;\r
+               while ((line = rd.readLine()) != null) {\r
+                       wholefile.append(line + "\n");\r
+               }\r
+               return wholefile.toString();\r
+       }\r
+\r
+       public static void ensureDir(String objFileWhole) {\r
+               Pattern ptnseparate = Pattern.compile("(.*)\\\\[^\\\\]*");\r
+               Matcher mtrseparate;\r
+               File tempdir;\r
+\r
+               mtrseparate = ptnseparate.matcher(objFileWhole);\r
+               if (mtrseparate.find()) {\r
+                       tempdir = new File(mtrseparate.group(1));\r
+                       if (!tempdir.exists()) tempdir.mkdirs();\r
+               }\r
+               \r
+       }\r
+}\r
index 30085d449edd0770bc1fd7c5ab4712334da39fa5..9f853e42f2e53cea900fa9a2b358d4cd1467db36 100644 (file)
@@ -25,8 +25,9 @@ public class FirstPanel extends JPanel implements ActionListener, UI {
        private static final long serialVersionUID = 207759413522910399L;\r
        \r
        private String modulepath;\r
+       private ModuleInfo mi;\r
        \r
-       private JButton moduleButton , goButton;\r
+       private JButton moduleButton, goButton, msaEditorButton;\r
        private JTextField moduletext;\r
        private JTextArea log;\r
        private JFileChooser fc;\r
@@ -43,6 +44,9 @@ public class FirstPanel extends JPanel implements ActionListener, UI {
                moduleButton = new JButton("Choose ModulePath");\r
                moduleButton.addActionListener(this);\r
 \r
+               msaEditorButton = new JButton("MsaEditor");\r
+               msaEditorButton.addActionListener(this);\r
+               \r
                moduletext = new JTextField(30);\r
                \r
                filebox = new JCheckBox("Output to logfile", true);\r
@@ -54,9 +58,10 @@ public class FirstPanel extends JPanel implements ActionListener, UI {
         modulePanel.add(filebox);\r
         modulePanel.add(screenbox);\r
         modulePanel.add(goButton);\r
+        modulePanel.add(msaEditorButton);\r
         add(modulePanel);\r
 \r
-        log = new JTextArea(50,25);\r
+        log = new JTextArea(20,25);\r
         log.setMargin(new Insets(5,5,5,5));\r
         log.setEditable(false);\r
         JScrollPane logScrollPane = new JScrollPane(log);\r
@@ -99,16 +104,13 @@ public class FirstPanel extends JPanel implements ActionListener, UI {
        public String choose(String message, Object[] choicelist) {\r
                return (String)JOptionPane.showInputDialog(this, message,"Choose",JOptionPane.PLAIN_MESSAGE,null,choicelist,choicelist[0]);\r
        }\r
-\r
-       //---------------------------------------------------------------------------------------//\r
        \r
-       /*\r
-       public boolean getOption(String item) {\r
-               if (item.matches("file")) {\r
-               }\r
+       public String getInput(String message) {\r
+               return (String)JOptionPane.showInputDialog(message);\r
        }\r
-       */\r
-       \r
+\r
+       //---------------------------------------------------------------------------------------//\r
+\r
     public void actionPerformed(ActionEvent e) {\r
         if ( e.getSource() == moduleButton ) {\r
                int ret = fc.showOpenDialog(this);\r
@@ -123,12 +125,19 @@ public class FirstPanel extends JPanel implements ActionListener, UI {
                        logfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "migration.log")));\r
                        println("Project MsaGen");\r
                        println("Copyright (c) 2006, Intel Corporation");\r
-                       new ModuleInfo(modulepath, this, new Database());\r
+                       mi = new ModuleInfo(modulepath, this, new Database());\r
                        logfile.flush();\r
                } catch (Exception en) {\r
                        println(en.getMessage());\r
                }\r
         }\r
+        if ( e.getSource() == msaEditorButton) {\r
+               try {\r
+               MsaTreeEditor.init(mi, this);\r
+               } catch (Exception en) {\r
+                       println(en.getMessage());\r
+               }\r
+        }\r
     }\r
     \r
     public void itemStateChanged(ItemEvent e) {\r
@@ -156,7 +165,7 @@ public class FirstPanel extends JPanel implements ActionListener, UI {
                fp.setOpaque(true);\r
         frame.setContentPane(fp);\r
 \r
-               frame.setSize(800,600);\r
+               frame.pack();\r
                frame.setVisible(true);\r
     }\r
 }
\ No newline at end of file
index 220b3e8d4064485e8e3302c74a914c4b21db565d..5e3bbb50d02878f0ae17f47918d825942ebcb21c 100644 (file)
@@ -86,7 +86,7 @@ public class ModuleInfo {
                } else {\r
                        filename = ui.choose("Found .inf or .msa file in the module\nChoose one Please", msaorinf.toArray());\r
                }\r
-               ModuleReader mr = new ModuleReader(modulepath, this, db);\r
+               ModuleReader mr = new ModuleReader(modulepath, this, db, ui);\r
                if (filename.contains(".inf")) {\r
                        mr.readInf(filename);\r
                } else if (filename.contains(".msa")) {\r
@@ -130,19 +130,6 @@ public class ModuleInfo {
                ui.println(show + hash.size());\r
                ui.println(hash);\r
        }\r
-\r
-       public void ensureDir(String objFileWhole) {\r
-               Pattern ptnseparate = Pattern.compile("(.*)\\\\[^\\\\]*");\r
-               Matcher mtrseparate;\r
-               File tempdir;\r
-\r
-               mtrseparate = ptnseparate.matcher(objFileWhole);\r
-               if (mtrseparate.find()) {\r
-                       tempdir = new File(mtrseparate.group(1));\r
-                       if (!tempdir.exists()) tempdir.mkdirs();\r
-               }\r
-               \r
-       }\r
        \r
        // add '//' to all non-local include lines\r
        private void CommentOutNonLocalHFile() throws IOException {\r
@@ -158,7 +145,7 @@ public class ModuleInfo {
                while ( ii.hasNext() ) {\r
                        curFile = ii.next();\r
                        rd = new BufferedReader(new FileReader(modulepath + File.separator + curFile));\r
-                       ensureDir(modulepath + File.separator + "temp" + File.separator + curFile);\r
+                       Common.ensureDir(modulepath + File.separator + "temp" + File.separator + curFile);\r
                        outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "temp" + File.separator + curFile)));\r
                        while ((line = rd.readLine()) != null) {\r
                                if (line.contains("#include")) {\r
index 3f379b7256f5a822358d2e30bac50bd30ca811b1..46fb4994bb39c8362308f4d70c1246ca27b912fd 100644 (file)
@@ -18,16 +18,20 @@ import java.util.regex.*;
 import org.tianocore.*;\r
 \r
 public class ModuleReader {\r
-       ModuleReader(String path, ModuleInfo moduleinfo, Database database) {\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 String modulepath;\r
        private ModuleInfo mi;\r
        private Database db;\r
+       private UI ui;\r
        \r
-       private static Pattern ptninfequation = Pattern.compile("([^ ]*) *= *([^ ]*)");\r
+       private static Pattern ptninfequation = Pattern.compile("([^\\s]*)\\s*=\\s*([^\\s]*)");\r
+       private static Pattern ptnsection = Pattern.compile("\\[([^\\[\\]]*)\\]([^\\[\\]]*)\\n", Pattern.MULTILINE);\r
+       private static Pattern ptnfilename = Pattern.compile("[^\\s]+");\r
        \r
        public void readMsa(String name) throws Exception {\r
                ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(new File(modulepath + File.separator + name));\r
@@ -53,40 +57,48 @@ public class ModuleReader {
                System.out.println("Parsing INF file: " + name);\r
                BufferedReader rd = new BufferedReader(new FileReader(modulepath + File.separator + name));\r
                String line;\r
+               String wholeline;\r
                String[] linecontext;\r
                boolean inSrc = false;\r
                Matcher mtrinfequation;\r
+               Matcher mtrsection;\r
+               Matcher mtrfilename;\r
 \r
-               while ((line = rd.readLine()) != null) {\r
-                       if (line.length() != 0) {\r
-                               if (inSrc) {\r
-                                       if (line.contains("[")) {\r
-                                               inSrc = false;\r
-                                       } else {\r
-                                               linecontext = line.split(" ");\r
-                                               if (linecontext[2].length() != 0) {\r
-                                                       if (!mi.localmodulesources.contains(linecontext[2])) {\r
-                                                               System.out.println("Source File Missing! : " + linecontext[2]);\r
-                                                       }\r
-                                               }\r
+               wholeline = Common.sourcefiletostring(modulepath + File.separator + name);\r
+               mtrsection = ptnsection.matcher(wholeline);\r
+               while (mtrsection.find()) {\r
+                       if (mtrsection.group(1).matches("defines")) {\r
+                               mtrinfequation = ptninfequation.matcher(mtrsection.group(2));\r
+                               while (mtrinfequation.find()) {\r
+                                       if (mtrinfequation.group(1).matches("BASE_NAME")) {\r
+                                               mi.modulename = mtrinfequation.group(2);\r
                                        }\r
-                               } else {\r
-                                       if ((mtrinfequation = ptninfequation.matcher(line)).find()) {\r
-                                               if (mtrinfequation.group(1).matches("BASE_NAME")) {\r
-                                                       mi.modulename = mtrinfequation.group(2);\r
-                                               }\r
-                                               if (mtrinfequation.group(1).matches("FILE_GUID")) {\r
-                                                       mi.guidvalue = mtrinfequation.group(2);\r
-                                               }\r
-                                               if (mtrinfequation.group(1).matches("COMPONENT_TYPE")) {\r
-                                                       mi.moduletype = mtrinfequation.group(2);\r
-                                               }\r
-                                               if (mtrinfequation.group(1).matches("IMAGE_ENTRY_POINT")) {\r
-                                                       mi.entrypoint = mtrinfequation.group(2);\r
+                                       if (mtrinfequation.group(1).matches("FILE_GUID")) {\r
+                                               mi.guidvalue = mtrinfequation.group(2);\r
+                                       }\r
+                                       if (mtrinfequation.group(1).matches("COMPONENT_TYPE")) {\r
+                                               mi.moduletype = mtrinfequation.group(2);\r
+                                       }\r
+                               }\r
+                       }\r
+                       if (mtrsection.group(1).matches("nmake.common")) {\r
+                               mtrinfequation = ptninfequation.matcher(mtrsection.group(2));\r
+                               while (mtrinfequation.find()) {\r
+                                       if (mtrinfequation.group(1).matches("IMAGE_ENTRY_POINT")) {\r
+                                               mi.entrypoint = mtrinfequation.group(2);\r
+                                       }\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
                                                }\r
                                        }\r
-                                       if (line.contains("sources")) {\r
-                                               inSrc = true;\r
+                               }\r
+                       }\r
+                       if (mtrsection.group(1).contains("sources.")) {\r
+                               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
                                        }\r
                                }\r
                        }\r
diff --git a/Tools/Source/MigrationTools/org/tianocore/migration/MsaTreeEditor.java b/Tools/Source/MigrationTools/org/tianocore/migration/MsaTreeEditor.java
new file mode 100644 (file)
index 0000000..a324e81
--- /dev/null
@@ -0,0 +1,84 @@
+package org.tianocore.migration;\r
+\r
+import java.awt.*;\r
+import java.awt.event.*;\r
+import javax.swing.*;\r
+import javax.swing.tree.*;\r
+\r
+public class MsaTreeEditor extends JPanel {\r
+       MsaTreeEditor(ModuleInfo m, UI u) {\r
+               mi = m;\r
+               ui = u;\r
+               \r
+        rootNode = new DefaultMutableTreeNode("Root Node");\r
+        treeModel = new DefaultTreeModel(rootNode);\r
+\r
+        tree = new JTree(treeModel);\r
+        tree.setEditable(true);\r
+        tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);\r
+        tree.setShowsRootHandles(false);\r
+        tree.addMouseListener(mouseadapter);\r
+\r
+        JScrollPane scrollPane = new JScrollPane(tree);\r
+        add(scrollPane);\r
+        \r
+        popupmenu = new JPopupMenu();\r
+        JMenuItem menuitemadd = new JMenuItem("addNode");\r
+        JMenuItem menuitemdel = new JMenuItem("deleteNode");\r
+        popupmenu.add(menuitemadd);\r
+        popupmenu.add(menuitemdel);\r
+        menuitemadd.addActionListener(actionListener);\r
+        menuitemdel.addActionListener(actionListener);\r
+        \r
+        addNode(rootNode, "1st");\r
+        addNode(rootNode, "2nd");\r
+       }\r
+       \r
+       private ModuleInfo mi;\r
+       private UI ui;\r
+       \r
+       private JTree tree;\r
+       private DefaultMutableTreeNode rootNode;\r
+       private DefaultTreeModel treeModel;\r
+       \r
+       private JPopupMenu popupmenu;\r
+       private MouseAdapter mouseadapter = new MouseAdapter() {\r
+               public void mouseReleased(MouseEvent me) {\r
+                       if (me.getClickCount() == 1 && SwingUtilities.isRightMouseButton(me)) {\r
+                               tree.setSelectionPath(tree.getPathForLocation(me.getX(), me.getY()));\r
+                               popupmenu.show(tree, me.getX(), me.getY());\r
+                       }\r
+               }\r
+       };\r
+       private ActionListener actionListener = new ActionListener() {\r
+               public void actionPerformed(ActionEvent ae) {\r
+                       addNode();\r
+               }\r
+       };\r
+       \r
+       public void addNode() {\r
+               addNode((DefaultMutableTreeNode)(tree.getSelectionPath().getLastPathComponent()), ui.getInput("Input Node Name"));\r
+               System.out.println();\r
+       }\r
+       \r
+       public void addNode(DefaultMutableTreeNode parentNode, Object child) {\r
+        DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child);\r
+        treeModel.insertNodeInto(childNode, parentNode, parentNode.getChildCount());\r
+        tree.scrollPathToVisible(new TreePath(childNode.getPath()));\r
+       }\r
+\r
+       public static void init(ModuleInfo mi, UI ui) throws Exception {\r
+       UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());\r
+\r
+               JFrame frame = new JFrame("MsaTreeEditor");\r
+               frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\r
+\r
+               MsaTreeEditor mte = new MsaTreeEditor(mi, ui);\r
+               mte.setLayout(new GridBagLayout());\r
+               mte.setOpaque(true);\r
+        frame.setContentPane(mte);\r
+\r
+               frame.pack();\r
+               frame.setVisible(true);\r
+       }\r
+}
\ No newline at end of file
index 7d907690e902b51cc9f28631f45a7aef8e3de674..2c3c97274e5ba3bde5400520e21dea6fdc4d8045 100644 (file)
@@ -78,7 +78,7 @@ public class MsaWriter {
                msaheader.setCopyright("Copyright (c) 2006, Intel Corporation");\r
                msaheader.setVersion("1.0");\r
                msaheader.setAbstract("Component name for module " + mi.modulename);\r
-               msaheader.setDescription("FIX ME!");                                                    //???\r
+               msaheader.setDescription("FIX ME!");\r
                msaheader.addNewLicense().setStringValue("All rights reserved.\n" +\r
                                "      This software and associated documentation (if any) is furnished\n" +\r
                                "      under a license and may only be used or copied in accordance\n" +\r
@@ -103,9 +103,17 @@ public class MsaWriter {
                externs.addNewSpecification().setStringValue("EDK_RELEASE_VERSION 0x00020000");\r
                externs.addNewExtern().setModuleEntryPoint(mi.entrypoint);\r
                \r
+               FilenameDocument.Filename filename;\r
                it = mi.localmodulesources.iterator();\r
+               //System.out.println(mi.localmodulesources);\r
                while (it.hasNext()) {\r
-                       sourcefiles.addNewFilename().setStringValue(it.next());\r
+                       temp = it.next();\r
+                       filename = sourcefiles.addNewFilename();\r
+                       filename.setStringValue(temp);\r
+                       //if (temp.contains("x64" + File.separator)) {\r
+                               //System.out.println("find");\r
+                               //filename.setSupArchList();\r
+                       //}\r
                }\r
                if (!mi.protocol.isEmpty()) {\r
                        protocols = msa.addNewProtocols();\r
index dbe981ef94adccedf98431c51986348b2b1c969f..03617ab7167cc61e51d0031b20be09fced2b994a 100644 (file)
@@ -85,7 +85,7 @@ public class SourceFileReplacer {
                                        outname = inname;\r
                                }\r
                                ui.println("\nModifying file: " + inname);\r
-                               mi.ensureDir(modulepath + File.separator + "result" + File.separator + outname);\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
@@ -97,9 +97,9 @@ public class SourceFileReplacer {
                                        outname = inname;\r
                                }\r
                                ui.println("\nCopying file: " + inname);\r
-                               mi.ensureDir(modulepath + File.separator + "result" + File.separator + outname);\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(sourcefiletostring(modulepath + File.separator + "temp" + File.separator + inname));\r
+                               outfile.append(Common.sourcefiletostring(modulepath + File.separator + "temp" + File.separator + inname));\r
                                outfile.flush();\r
                                outfile.close();\r
                        }\r
@@ -112,8 +112,8 @@ public class SourceFileReplacer {
        \r
        private void addr8only() throws Exception {\r
                String paragraph = null;\r
-               String line = sourcefiletostring(Database.defaultpath + File.separator + "R8Lib.c");\r
-               mi.ensureDir(modulepath + File.separator + "result" + File.separator + "R8Lib.c");\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
                Pattern ptnr8only = Pattern.compile("////#?(\\w*)?.*?R8_(\\w*).*?////~", Pattern.DOTALL);\r
@@ -142,16 +142,6 @@ public class SourceFileReplacer {
                mi.localmodulesources.add("R8Lib.c");\r
        }\r
        \r
-       private String sourcefiletostring(String filename) throws Exception {\r
-               BufferedReader rd = new BufferedReader(new FileReader(filename));\r
-               StringBuffer wholefile = new StringBuffer();\r
-               String line;\r
-               while ((line = rd.readLine()) != null) {\r
-                       wholefile.append(line + "\n");\r
-               }\r
-               return wholefile.toString();\r
-       }\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
                BufferedReader rd = new BufferedReader(new FileReader(filename));\r
index 7f91ebe46170546ea04c3fa318ef053018c5aa4a..170a2488bd99573196720cb370df2cca2b029c36 100644 (file)
@@ -25,4 +25,6 @@ public interface UI {
        public void println(Set<String> hash);\r
        \r
        public String choose(String message, Object[] choicelist);\r
+       \r
+       public String getInput(String message);\r
 }\r