--- /dev/null
+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
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
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
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
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
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
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
} 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
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
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
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
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
--- /dev/null
+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
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
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
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
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
\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
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
public void println(Set<String> hash);\r
\r
public String choose(String message, Object[] choicelist);\r
+ \r
+ public String getInput(String message);\r
}\r