mirror of https://github.com/acidanthera/audk.git
Add Critic.java
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1290 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
e78205b8d0
commit
fed802b139
|
@ -1,13 +1,11 @@
|
||||||
package org.tianocore.migration;
|
package org.tianocore.migration;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.*;
|
||||||
import java.io.File;
|
import java.util.regex.*;
|
||||||
import java.io.FileReader;
|
import java.util.*;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class Common {
|
public class Common {
|
||||||
public static String sourcefiletostring(String filename) throws Exception {
|
public static String file2string(String filename) throws Exception {
|
||||||
BufferedReader rd = new BufferedReader(new FileReader(filename));
|
BufferedReader rd = new BufferedReader(new FileReader(filename));
|
||||||
StringBuffer wholefile = new StringBuffer();
|
StringBuffer wholefile = new StringBuffer();
|
||||||
String line;
|
String line;
|
||||||
|
@ -27,6 +25,48 @@ public class Common {
|
||||||
tempdir = new File(mtrseparate.group(1));
|
tempdir = new File(mtrseparate.group(1));
|
||||||
if (!tempdir.exists()) tempdir.mkdirs();
|
if (!tempdir.exists()) tempdir.mkdirs();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void string2file(String content, String filename) throws Exception {
|
||||||
|
ensureDir(filename);
|
||||||
|
PrintWriter outfile = new PrintWriter(new BufferedWriter(new FileWriter(filename)));
|
||||||
|
outfile.append(content);
|
||||||
|
outfile.flush();
|
||||||
|
outfile.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HashSet<String> dirScan(String path) { // use HashSet, persue speed rather than space
|
||||||
|
HashSet<String> filelist = new HashSet<String>();
|
||||||
|
String[] list = new File(path).list();
|
||||||
|
File test;
|
||||||
|
|
||||||
|
for (int i = 0 ; i < list.length ; i++) {
|
||||||
|
test = new File(path + File.separator + list[i]);
|
||||||
|
if (test.isDirectory()) {
|
||||||
|
dirScan(path + File.separator + list[i]);
|
||||||
|
} else {
|
||||||
|
filelist.add(path + File.separator + list[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return filelist;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void toDoAll(String path, ForDoAll fda) throws Exception { // filter of file type can be done in toDo
|
||||||
|
String[] list = new File(path).list();
|
||||||
|
File test;
|
||||||
|
|
||||||
|
for (int i = 0 ; i < list.length ; i++) {
|
||||||
|
test = new File(path + File.separator + list[i]);
|
||||||
|
if (test.isDirectory()) {
|
||||||
|
toDoAll(path + File.separator + list[i], fda);
|
||||||
|
} else {
|
||||||
|
fda.toDo(path + File.separator + list[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static interface ForDoAll {
|
||||||
|
public void toDo(String filepath) throws Exception;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
package org.tianocore.migration;
|
||||||
|
|
||||||
|
import java.util.regex.*;
|
||||||
|
|
||||||
|
public class Critic implements Common.ForDoAll {
|
||||||
|
Critic() {
|
||||||
|
filepath = null;
|
||||||
|
}
|
||||||
|
Critic(String path) {
|
||||||
|
filepath = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String filepath = null;
|
||||||
|
|
||||||
|
private static Pattern ptnheadcomment = Pattern.compile("^\\/\\*\\+\\+(.*?)\\-\\-\\*\\/",Pattern.DOTALL);
|
||||||
|
private static Matcher mtrheadcomment;
|
||||||
|
|
||||||
|
public void toDo(String filepath) throws Exception {
|
||||||
|
if (filepath.contains(".c") || filepath.contains(".h")) {
|
||||||
|
String wholeline = Common.file2string(filepath);
|
||||||
|
mtrheadcomment = ptnheadcomment.matcher(wholeline);
|
||||||
|
if (mtrheadcomment.find()) { //as we find only the head comment here, use 'if' not 'while'
|
||||||
|
wholeline = mtrheadcomment.replaceFirst("/** @file$1**/");
|
||||||
|
Common.string2file(wholeline, filepath + "_");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void fireAt(String path) throws Exception {
|
||||||
|
Common.toDoAll(path, new Critic());
|
||||||
|
System.out.println("Critic Done");
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,7 +27,7 @@ public class FirstPanel extends JPanel implements ActionListener, UI {
|
||||||
private String modulepath;
|
private String modulepath;
|
||||||
private ModuleInfo mi;
|
private ModuleInfo mi;
|
||||||
|
|
||||||
private JButton moduleButton, goButton, msaEditorButton;
|
private JButton moduleButton, goButton, msaEditorButton, criticButton;
|
||||||
private JTextField moduletext;
|
private JTextField moduletext;
|
||||||
private JTextArea log;
|
private JTextArea log;
|
||||||
private JFileChooser fc;
|
private JFileChooser fc;
|
||||||
|
@ -47,6 +47,9 @@ public class FirstPanel extends JPanel implements ActionListener, UI {
|
||||||
msaEditorButton = new JButton("MsaEditor");
|
msaEditorButton = new JButton("MsaEditor");
|
||||||
msaEditorButton.addActionListener(this);
|
msaEditorButton.addActionListener(this);
|
||||||
|
|
||||||
|
criticButton = new JButton("Critic");
|
||||||
|
criticButton.addActionListener(this);
|
||||||
|
|
||||||
moduletext = new JTextField(30);
|
moduletext = new JTextField(30);
|
||||||
|
|
||||||
filebox = new JCheckBox("Output to logfile", true);
|
filebox = new JCheckBox("Output to logfile", true);
|
||||||
|
@ -59,6 +62,7 @@ public class FirstPanel extends JPanel implements ActionListener, UI {
|
||||||
modulePanel.add(screenbox);
|
modulePanel.add(screenbox);
|
||||||
modulePanel.add(goButton);
|
modulePanel.add(goButton);
|
||||||
modulePanel.add(msaEditorButton);
|
modulePanel.add(msaEditorButton);
|
||||||
|
modulePanel.add(criticButton);
|
||||||
add(modulePanel);
|
add(modulePanel);
|
||||||
|
|
||||||
log = new JTextArea(20,25);
|
log = new JTextArea(20,25);
|
||||||
|
@ -138,6 +142,13 @@ public class FirstPanel extends JPanel implements ActionListener, UI {
|
||||||
println(en.getMessage());
|
println(en.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ( e.getSource() == criticButton) {
|
||||||
|
try {
|
||||||
|
Critic.fireAt(modulepath);
|
||||||
|
} catch (Exception en) {
|
||||||
|
println(en.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void itemStateChanged(ItemEvent e) {
|
public void itemStateChanged(ItemEvent e) {
|
||||||
|
|
|
@ -113,7 +113,7 @@ public class ModuleInfo {
|
||||||
show(hashr8only, "hashr8only : ");
|
show(hashr8only, "hashr8only : ");
|
||||||
}
|
}
|
||||||
|
|
||||||
new MsaWriter(modulepath, this, db).flush();
|
new MsaWriter(modulepath, this, db, ui).flush();
|
||||||
|
|
||||||
// remove temp directory
|
// remove temp directory
|
||||||
//File tempdir = new File(modulepath + File.separator + "temp");
|
//File tempdir = new File(modulepath + File.separator + "temp");
|
||||||
|
|
|
@ -54,17 +54,13 @@ public class ModuleReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readInf(String name) throws Exception {
|
public void readInf(String name) throws Exception {
|
||||||
System.out.println("Parsing INF file: " + name);
|
System.out.println("\nParsing INF file: " + name);
|
||||||
BufferedReader rd = new BufferedReader(new FileReader(modulepath + File.separator + name));
|
|
||||||
String line;
|
|
||||||
String wholeline;
|
String wholeline;
|
||||||
String[] linecontext;
|
|
||||||
boolean inSrc = false;
|
|
||||||
Matcher mtrinfequation;
|
Matcher mtrinfequation;
|
||||||
Matcher mtrsection;
|
Matcher mtrsection;
|
||||||
Matcher mtrfilename;
|
Matcher mtrfilename;
|
||||||
|
|
||||||
wholeline = Common.sourcefiletostring(modulepath + File.separator + name);
|
wholeline = Common.file2string(modulepath + File.separator + name);
|
||||||
mtrsection = ptnsection.matcher(wholeline);
|
mtrsection = ptnsection.matcher(wholeline);
|
||||||
while (mtrsection.find()) {
|
while (mtrsection.find()) {
|
||||||
if (mtrsection.group(1).matches("defines")) {
|
if (mtrsection.group(1).matches("defines")) {
|
||||||
|
|
|
@ -5,12 +5,44 @@ import java.awt.event.*;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.tree.*;
|
import javax.swing.tree.*;
|
||||||
|
|
||||||
|
import org.tianocore.ModuleSurfaceAreaDocument;
|
||||||
|
|
||||||
public class MsaTreeEditor extends JPanel {
|
public class MsaTreeEditor extends JPanel {
|
||||||
/**
|
/**
|
||||||
* Define class Serial Version UID
|
* Define class Serial Version UID
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 3169905938472150649L;
|
private static final long serialVersionUID = 3169905938472150649L;
|
||||||
|
/*
|
||||||
|
MsaTreeEditor(ModuleInfo m, UI u, ModuleSurfaceAreaDocument md) {
|
||||||
|
mi = m;
|
||||||
|
ui = u;
|
||||||
|
msadoc = md;
|
||||||
|
|
||||||
|
//rootNode = msadoc.getDomNode();
|
||||||
|
rootNode = new DefaultMutableTreeNode("Root Node");
|
||||||
|
treeModel = new DefaultTreeModel(rootNode);
|
||||||
|
|
||||||
|
tree = new JTree(treeModel);
|
||||||
|
tree.setEditable(true);
|
||||||
|
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
|
||||||
|
tree.setShowsRootHandles(false);
|
||||||
|
tree.addMouseListener(mouseadapter);
|
||||||
|
|
||||||
|
JScrollPane scrollPane = new JScrollPane(tree);
|
||||||
|
add(scrollPane);
|
||||||
|
|
||||||
|
popupmenu = new JPopupMenu();
|
||||||
|
menuitemadd = new JMenuItem("addNode");
|
||||||
|
menuitemdel = new JMenuItem("deleteNode");
|
||||||
|
popupmenu.add(menuitemadd);
|
||||||
|
popupmenu.add(menuitemdel);
|
||||||
|
menuitemadd.addActionListener(actionListener);
|
||||||
|
menuitemdel.addActionListener(actionListener);
|
||||||
|
|
||||||
|
addNode(rootNode, "1st");
|
||||||
|
addNode(rootNode, "2nd");
|
||||||
|
}
|
||||||
|
*/
|
||||||
MsaTreeEditor(ModuleInfo m, UI u) {
|
MsaTreeEditor(ModuleInfo m, UI u) {
|
||||||
mi = m;
|
mi = m;
|
||||||
ui = u;
|
ui = u;
|
||||||
|
@ -28,8 +60,8 @@ public class MsaTreeEditor extends JPanel {
|
||||||
add(scrollPane);
|
add(scrollPane);
|
||||||
|
|
||||||
popupmenu = new JPopupMenu();
|
popupmenu = new JPopupMenu();
|
||||||
JMenuItem menuitemadd = new JMenuItem("addNode");
|
menuitemadd = new JMenuItem("addNode");
|
||||||
JMenuItem menuitemdel = new JMenuItem("deleteNode");
|
menuitemdel = new JMenuItem("deleteNode");
|
||||||
popupmenu.add(menuitemadd);
|
popupmenu.add(menuitemadd);
|
||||||
popupmenu.add(menuitemdel);
|
popupmenu.add(menuitemdel);
|
||||||
menuitemadd.addActionListener(actionListener);
|
menuitemadd.addActionListener(actionListener);
|
||||||
|
@ -41,10 +73,12 @@ public class MsaTreeEditor extends JPanel {
|
||||||
|
|
||||||
private ModuleInfo mi;
|
private ModuleInfo mi;
|
||||||
private UI ui;
|
private UI ui;
|
||||||
|
//private ModuleSurfaceAreaDocument msadoc;
|
||||||
|
|
||||||
private JTree tree;
|
private JTree tree;
|
||||||
private DefaultMutableTreeNode rootNode;
|
private DefaultMutableTreeNode rootNode;
|
||||||
private DefaultTreeModel treeModel;
|
private DefaultTreeModel treeModel;
|
||||||
|
private JMenuItem menuitemadd, menuitemdel;
|
||||||
|
|
||||||
private JPopupMenu popupmenu;
|
private JPopupMenu popupmenu;
|
||||||
private MouseAdapter mouseadapter = new MouseAdapter() {
|
private MouseAdapter mouseadapter = new MouseAdapter() {
|
||||||
|
@ -57,21 +91,32 @@ public class MsaTreeEditor extends JPanel {
|
||||||
};
|
};
|
||||||
private ActionListener actionListener = new ActionListener() {
|
private ActionListener actionListener = new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent ae) {
|
public void actionPerformed(ActionEvent ae) {
|
||||||
addNode();
|
if (ae.getSource() == menuitemadd) {
|
||||||
|
addNode();
|
||||||
|
} else if (ae.getSource() == menuitemdel) {
|
||||||
|
delNode();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public void addNode() {
|
private void delNode() {
|
||||||
addNode((DefaultMutableTreeNode)(tree.getSelectionPath().getLastPathComponent()), ui.getInput("Input Node Name"));
|
treeModel.removeNodeFromParent((DefaultMutableTreeNode)(tree.getSelectionPath().getLastPathComponent()));
|
||||||
System.out.println();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addNode(DefaultMutableTreeNode parentNode, Object child) {
|
private void addNode() {
|
||||||
|
addNode((DefaultMutableTreeNode)(tree.getSelectionPath().getLastPathComponent()), ui.getInput("Input Node Name"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addNode(DefaultMutableTreeNode parentNode, Object child) {
|
||||||
DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child);
|
DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child);
|
||||||
treeModel.insertNodeInto(childNode, parentNode, parentNode.getChildCount());
|
treeModel.insertNodeInto(childNode, parentNode, parentNode.getChildCount());
|
||||||
tree.scrollPathToVisible(new TreePath(childNode.getPath()));
|
tree.scrollPathToVisible(new TreePath(childNode.getPath()));
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
public static void init(ModuleInfo mi, UI ui, ModuleSurfaceAreaDocument msadoc) throws Exception {
|
||||||
|
init(mi, ui);
|
||||||
|
}
|
||||||
|
*/
|
||||||
public static void init(ModuleInfo mi, UI ui) throws Exception {
|
public static void init(ModuleInfo mi, UI ui) throws Exception {
|
||||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||||
|
|
||||||
|
|
|
@ -20,15 +20,17 @@ import org.tianocore.SupportedArchitectures.Enum;
|
||||||
import org.apache.xmlbeans.*;
|
import org.apache.xmlbeans.*;
|
||||||
|
|
||||||
public class MsaWriter {
|
public class MsaWriter {
|
||||||
MsaWriter(String path, ModuleInfo moduleinfo, Database database) {
|
MsaWriter(String path, ModuleInfo moduleinfo, Database database, UI u) {
|
||||||
modulepath = path;
|
modulepath = path;
|
||||||
mi = moduleinfo;
|
mi = moduleinfo;
|
||||||
db = database;
|
db = database;
|
||||||
|
ui = u;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String modulepath;
|
private String modulepath;
|
||||||
private ModuleInfo mi;
|
private ModuleInfo mi;
|
||||||
private Database db;
|
private Database db;
|
||||||
|
private UI ui;
|
||||||
|
|
||||||
private ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.newInstance();
|
private ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.newInstance();
|
||||||
|
|
||||||
|
@ -187,6 +189,7 @@ public class MsaWriter {
|
||||||
|
|
||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + mi.modulename + ".msa"));
|
BufferedWriter bw = new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + mi.modulename + ".msa"));
|
||||||
fulfillMsadoc().save(bw, options);
|
fulfillMsadoc().save(bw, options);
|
||||||
|
//MsaTreeEditor.init(mi, ui, msadoc);
|
||||||
bw.flush();
|
bw.flush();
|
||||||
bw.close();
|
bw.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,11 +85,14 @@ public class SourceFileReplacer {
|
||||||
outname = inname;
|
outname = inname;
|
||||||
}
|
}
|
||||||
ui.println("\nModifying file: " + inname);
|
ui.println("\nModifying file: " + inname);
|
||||||
|
Common.string2file(sourcefilereplace(modulepath + File.separator + "temp" + File.separator + inname), modulepath + File.separator + "result" + File.separator + outname);
|
||||||
|
/*
|
||||||
Common.ensureDir(modulepath + File.separator + "result" + File.separator + outname);
|
Common.ensureDir(modulepath + File.separator + "result" + File.separator + outname);
|
||||||
outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + outname)));
|
outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + outname)));
|
||||||
outfile.append(sourcefilereplace(modulepath + File.separator + "temp" + File.separator + inname));
|
outfile.append(sourcefilereplace(modulepath + File.separator + "temp" + File.separator + inname));
|
||||||
outfile.flush();
|
outfile.flush();
|
||||||
outfile.close();
|
outfile.close();
|
||||||
|
*/
|
||||||
} else if (inname.contains(".h") || inname.contains(".H") || inname.contains(".dxs") || inname.contains(".uni")) {
|
} else if (inname.contains(".h") || inname.contains(".H") || inname.contains(".dxs") || inname.contains(".uni")) {
|
||||||
if (inname.contains(".H")) {
|
if (inname.contains(".H")) {
|
||||||
outname = inname.replaceFirst(".H", ".h");
|
outname = inname.replaceFirst(".H", ".h");
|
||||||
|
@ -97,11 +100,14 @@ public class SourceFileReplacer {
|
||||||
outname = inname;
|
outname = inname;
|
||||||
}
|
}
|
||||||
ui.println("\nCopying file: " + inname);
|
ui.println("\nCopying file: " + inname);
|
||||||
|
Common.string2file(Common.file2string(modulepath + File.separator + "temp" + File.separator + inname), modulepath + File.separator + "result" + File.separator + outname);
|
||||||
|
/*
|
||||||
Common.ensureDir(modulepath + File.separator + "result" + File.separator + outname);
|
Common.ensureDir(modulepath + File.separator + "result" + File.separator + outname);
|
||||||
outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + outname)));
|
outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + outname)));
|
||||||
outfile.append(Common.sourcefiletostring(modulepath + File.separator + "temp" + File.separator + inname));
|
outfile.append(Common.file2string(modulepath + File.separator + "temp" + File.separator + inname));
|
||||||
outfile.flush();
|
outfile.flush();
|
||||||
outfile.close();
|
outfile.close();
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +118,7 @@ public class SourceFileReplacer {
|
||||||
|
|
||||||
private void addr8only() throws Exception {
|
private void addr8only() throws Exception {
|
||||||
String paragraph = null;
|
String paragraph = null;
|
||||||
String line = Common.sourcefiletostring(Database.defaultpath + File.separator + "R8Lib.c");
|
String line = Common.file2string(Database.defaultpath + File.separator + "R8Lib.c");
|
||||||
Common.ensureDir(modulepath + File.separator + "result" + File.separator + "R8Lib.c");
|
Common.ensureDir(modulepath + File.separator + "result" + File.separator + "R8Lib.c");
|
||||||
PrintWriter outfile1 = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + "R8Lib.c")));
|
PrintWriter outfile1 = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + "R8Lib.c")));
|
||||||
PrintWriter outfile2 = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + "R8Lib.h")));
|
PrintWriter outfile2 = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + "R8Lib.h")));
|
||||||
|
|
Loading…
Reference in New Issue