**/\r
package org.tianocore.migration;\r
\r
-import java.io.*;\r
-import java.util.regex.*;\r
-import java.util.*;\r
-import java.lang.reflect.*;\r
+import java.io.BufferedReader;\r
+import java.io.BufferedWriter;\r
+import java.io.File;\r
+import java.io.FileReader;\r
+import java.io.FileWriter;\r
+import java.io.PrintWriter;\r
+import java.lang.reflect.Method;\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
+import java.util.Set;\r
+import java.util.regex.Matcher;\r
+import java.util.regex.Pattern;\r
\r
public final class Common {\r
- public static final int BOTH = 0;\r
- public static final int FILE = 1;\r
- public static final int DIR = 2;\r
- \r
- public static final String STRSEPARATER = "(.*)\\\\([^\\\\]*)";\r
- public static final Pattern PTNSEPARATER = Pattern.compile("(.*)\\\\([^\\\\]*)");\r
-\r
- //-------------------------------------regex------------------------------------------//\r
- \r
- public static final String replaceAll(String line, Pattern ptn, String des) {\r
- Matcher mtr = ptn.matcher(line);\r
-\r
- if (mtr.find()) {\r
- return mtr.replaceAll(des);\r
- }\r
- \r
- return line;\r
- }\r
-\r
- public static final boolean find (String line, String regex) {\r
- Pattern ptn = Pattern.compile(regex);\r
-\r
- return ptn.matcher (line).find (); \r
- }\r
- //-------------------------------------regex------------------------------------------//\r
- \r
- //-----------------------------------file&string---------------------------------------//\r
- \r
- public static final String file2string(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
- rd.close();\r
- return wholefile.toString();\r
- }\r
-\r
- public static final void string2file(String content, String filename) throws Exception {\r
- ensureDir(filename);\r
- PrintWriter outfile = new PrintWriter(new BufferedWriter(new FileWriter(filename)));\r
- outfile.append(content);\r
- outfile.flush();\r
- outfile.close();\r
- }\r
-\r
- public static final void fileCopy(String src, String des) throws Exception {\r
- string2file(file2string(src), des);\r
- }\r
- \r
- //-----------------------------------file&string---------------------------------------//\r
-\r
- //--------------------------------------dir--------------------------------------------//\r
- /*\r
- public static final HashSet<String> walkDir(String path, int mode) throws Exception {\r
- HashSet<String> pathlist = new HashSet<String>();\r
- Common.toDoAll(path, Common.class.getMethod("walkDir", String.class), null, null, mode);\r
- return pathlist;\r
- }\r
- */\r
- public static final void ensureDir(String objFileWhole) {\r
- File tempdir;\r
- Matcher mtrseparate = PTNSEPARATER.matcher(objFileWhole);\r
- if (mtrseparate.find()) {\r
- tempdir = new File(mtrseparate.group(1));\r
- if (!tempdir.exists()) tempdir.mkdirs();\r
- }\r
- }\r
- \r
- public static final void deleteDir(String objFileWhole) {\r
- String[] list = new File(objFileWhole).list();\r
- File temp;\r
- for (int i = 0 ; i < list.length ; i++) {\r
- temp = new File(objFileWhole + File.separator + list[i]);\r
- if (temp.isDirectory()) {\r
- deleteDir(objFileWhole + File.separator + list[i]);\r
- } else {\r
- temp.delete();\r
- }\r
- }\r
- new File(objFileWhole).delete();\r
- }\r
- \r
- public static final String dirCopy_(String src) throws Exception {\r
- Matcher mtrseparate = Common.PTNSEPARATER.matcher(src);\r
- if (mtrseparate.find()) {\r
- dirCopy(src, mtrseparate.group(1) + File.separator + "_" + mtrseparate.group(2));\r
- }\r
- return mtrseparate.group(1) + File.separator + "_" + mtrseparate.group(2);\r
- }\r
- \r
- public static final void dirCopy(String src, String des) throws Exception {\r
- String[] list = new File(src).list();\r
- File test;\r
-\r
- ensureDir(des);\r
- for (int i = 0 ; i < list.length ; i++) {\r
- test = new File(src + File.separator + list[i]);\r
- if (test.isDirectory()) {\r
- dirCopy(src + File.separator + list[i], des + File.separator + list[i]);\r
- } else {\r
- //ensureDir(des + File.separator + list[i]);\r
- string2file(file2string(src + File.separator + list[i]), des + File.separator + list[i]);\r
- }\r
- }\r
- }\r
- \r
- public static final void oneLevelDirCopy(String src, String des, String type) throws Exception {\r
- String[] list = new File(src).list();\r
- \r
- ensureDir(des);\r
- for (int i = 0; i < list.length; i++) {\r
- if (list[i].contains(type)) {\r
- string2file(file2string(src + File.separator + list[i]), des + File.separator + list[i]);\r
- }\r
- }\r
- }\r
-\r
- //--------------------------------------dir--------------------------------------------//\r
-\r
- //-------------------------------like python walk-----------------------------------------//\r
- \r
- public static final void toDoAll(String path, Method md, Object obj, Object[] args, int type) throws Exception {\r
- String[] list = new File(path).list();\r
- ArrayList<Object> _args = new ArrayList<Object>();\r
- \r
- _args.add(path);\r
- if (args != null) {\r
- for (int i = 0; i < args.length; i++) {\r
- _args.add(args[i]);\r
- }\r
- }\r
-\r
- if (type == DIR || type == BOTH) {\r
- md.invoke(obj, _args.toArray());\r
- }\r
- for (int i = 0 ; i < list.length ; i++) {\r
- if (new File(path + File.separator + list[i]).isDirectory()) {\r
- toDoAll(path + File.separator + list[i], md, obj, args, type);\r
- } else {\r
- if (type == FILE || type == BOTH) {\r
- _args.set(0, path + File.separator + list[i]);\r
- md.invoke(obj, _args.toArray());\r
- }\r
- }\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 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
- if (type == DIR || type == BOTH) {\r
- fda.run(path);\r
- }\r
- for (int i = 0 ; i < list.length ; i++) {\r
- test = new File(path + File.separator + list[i]);\r
- if (test.isDirectory()) {\r
- if (fda.filter(test)) {\r
- toDoAll(path + File.separator + list[i], fda, type);\r
- }\r
- } else {\r
- if (type == FILE || type == BOTH) {\r
- fda.run(path + File.separator + list[i]);\r
- }\r
- }\r
- }\r
- }\r
- \r
- public static interface ForDoAll {\r
- public void run(String filepath) throws Exception;\r
- \r
- public boolean filter(File dir);\r
- }\r
- \r
- public static abstract class Laplace {\r
- public void transform(String src, String des) throws Exception {\r
- Common.string2file(operation(Common.file2string(src)), des);\r
- }\r
- \r
- public abstract String operation(String wholeline);\r
- \r
- public abstract boolean recognize(String filename);\r
- \r
- public abstract String namechange(String oldname);\r
- }\r
- \r
- public static interface Element {\r
- \r
-// public int replace = 0;\r
-// public int type = 1;\r
- \r
- public String getReplace(String key);\r
- \r
-// public void getType(String key);\r
-// \r
-// public void setReplace(int num);\r
-// \r
-// public void setType(int num);\r
- \r
- }\r
+ public static final int BOTH = 0;\r
+\r
+ public static final int FILE = 1;\r
+\r
+ public static final int DIR = 2;\r
+\r
+ public static final String STRSEPARATER = "(.*)\\\\([^\\\\]*)";\r
+\r
+ public static final Pattern PTNSEPARATER = Pattern\r
+ .compile("(.*)\\\\([^\\\\]*)");\r
+\r
+ // -------------------------------------regex------------------------------------------//\r
+\r
+ public static final String replaceAll(String line, Pattern ptn, String des) {\r
+ Matcher mtr = ptn.matcher(line);\r
+\r
+ if (mtr.find()) {\r
+ return mtr.replaceAll(des);\r
+ }\r
+\r
+ return line;\r
+ }\r
+\r
+ public static final boolean find(String line, String regex) {\r
+ Pattern ptn = Pattern.compile(regex);\r
+\r
+ return ptn.matcher(line).find();\r
+ }\r
+\r
+ // -------------------------------------regex------------------------------------------//\r
+\r
+ // -----------------------------------file&string---------------------------------------//\r
+\r
+ public static final String file2string(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
+ rd.close();\r
+ return wholefile.toString();\r
+ }\r
+\r
+ public static final void string2file(String content, String filename)\r
+ throws Exception {\r
+ ensureDir(filename);\r
+ PrintWriter outfile = new PrintWriter(new BufferedWriter(\r
+ new FileWriter(filename)));\r
+ outfile.append(content);\r
+ outfile.flush();\r
+ outfile.close();\r
+ }\r
+\r
+ public static final void fileCopy(String src, String des) throws Exception {\r
+ string2file(file2string(src), des);\r
+ }\r
+\r
+ // -----------------------------------file&string---------------------------------------//\r
+\r
+ // --------------------------------------dir--------------------------------------------//\r
+ /*\r
+ * public static final HashSet<String> walkDir(String path, int mode)\r
+ * throws Exception { HashSet<String> pathlist = new HashSet<String>();\r
+ * Common.toDoAll(path, Common.class.getMethod("walkDir", String.class),\r
+ * null, null, mode); return pathlist; }\r
+ */\r
+ public static final void ensureDir(String objFileWhole) {\r
+ File tempdir;\r
+ Matcher mtrseparate = PTNSEPARATER.matcher(objFileWhole);\r
+ if (mtrseparate.find()) {\r
+ tempdir = new File(mtrseparate.group(1));\r
+ if (!tempdir.exists())\r
+ tempdir.mkdirs();\r
+ }\r
+ }\r
+\r
+ public static final void deleteDir(String objFileWhole) {\r
+ String[] list = new File(objFileWhole).list();\r
+ File temp;\r
+ for (int i = 0; i < list.length; i++) {\r
+ temp = new File(objFileWhole + File.separator + list[i]);\r
+ if (temp.isDirectory()) {\r
+ deleteDir(objFileWhole + File.separator + list[i]);\r
+ } else {\r
+ temp.delete();\r
+ }\r
+ }\r
+ new File(objFileWhole).delete();\r
+ }\r
+\r
+ public static final String dirCopy_(String src) throws Exception {\r
+ Matcher mtrseparate = Common.PTNSEPARATER.matcher(src);\r
+ if (mtrseparate.find()) {\r
+ dirCopy(src, mtrseparate.group(1) + File.separator + "_"\r
+ + mtrseparate.group(2));\r
+ }\r
+ return mtrseparate.group(1) + File.separator + "_"\r
+ + mtrseparate.group(2);\r
+ }\r
+\r
+ public static final void dirCopy(String src, String des) throws Exception {\r
+ String[] list = new File(src).list();\r
+ File test;\r
+\r
+ ensureDir(des);\r
+ for (int i = 0; i < list.length; i++) {\r
+ test = new File(src + File.separator + list[i]);\r
+ if (test.isDirectory()) {\r
+ dirCopy(src + File.separator + list[i], des + File.separator\r
+ + list[i]);\r
+ } else {\r
+ // ensureDir(des + File.separator + list[i]);\r
+ string2file(file2string(src + File.separator + list[i]), des\r
+ + File.separator + list[i]);\r
+ }\r
+ }\r
+ }\r
+\r
+ public static final void oneLevelDirCopy(String src, String des, String type)\r
+ throws Exception {\r
+ String[] list = new File(src).list();\r
+\r
+ ensureDir(des);\r
+ for (int i = 0; i < list.length; i++) {\r
+ if (list[i].contains(type)) {\r
+ string2file(file2string(src + File.separator + list[i]), des\r
+ + File.separator + list[i]);\r
+ }\r
+ }\r
+ }\r
+\r
+ // --------------------------------------dir--------------------------------------------//\r
+\r
+ // -------------------------------like python\r
+ // walk-----------------------------------------//\r
+\r
+ public static final void toDoAll(String path, Method md, Object obj,\r
+ Object[] args, int type) throws Exception {\r
+ String[] list = new File(path).list();\r
+ ArrayList<Object> _args = new ArrayList<Object>();\r
+\r
+ _args.add(path);\r
+ if (args != null) {\r
+ for (int i = 0; i < args.length; i++) {\r
+ _args.add(args[i]);\r
+ }\r
+ }\r
+\r
+ if (type == DIR || type == BOTH) {\r
+ md.invoke(obj, _args.toArray());\r
+ }\r
+ for (int i = 0; i < list.length; i++) {\r
+ if (new File(path + File.separator + list[i]).isDirectory()) {\r
+ toDoAll(path + File.separator + list[i], md, obj, args, type);\r
+ } else {\r
+ if (type == FILE || type == BOTH) {\r
+ _args.set(0, path + File.separator + list[i]);\r
+ md.invoke(obj, _args.toArray());\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ public static final void toDoAll(Set<String> set, ForDoAll fda)\r
+ throws Exception {\r
+ Iterator<String> di = set.iterator();\r
+ while (di.hasNext()) {\r
+ fda.run(di.next());\r
+ }\r
+ }\r
+\r
+ public static final void toDoAll(String path, ForDoAll fda, int type)\r
+ throws Exception { // filter of file type can be done in toDo\r
+ String[] list = new File(path).list();\r
+ File test;\r
+\r
+ if (type == DIR || type == BOTH) {\r
+ fda.run(path);\r
+ }\r
+ for (int i = 0; i < list.length; i++) {\r
+ test = new File(path + File.separator + list[i]);\r
+ if (test.isDirectory()) {\r
+ if (fda.filter(test)) {\r
+ toDoAll(path + File.separator + list[i], fda, type);\r
+ }\r
+ } else {\r
+ if (type == FILE || type == BOTH) {\r
+ fda.run(path + File.separator + list[i]);\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ public static interface ForDoAll {\r
+ public void run(String filepath) throws Exception;\r
+\r
+ public boolean filter(File dir);\r
+ }\r
+\r
+ public static abstract class Laplace {\r
+ public void transform(String src, String des) throws Exception {\r
+ Common.string2file(operation(Common.file2string(src)), des);\r
+ }\r
+\r
+ public abstract String operation(String wholeline);\r
+\r
+ public abstract boolean recognize(String filename);\r
+\r
+ public abstract String namechange(String oldname);\r
+ }\r
+\r
+ public static interface Element {\r
+\r
+ // public int replace = 0;\r
+ // public int type = 1;\r
+\r
+ public String getReplace(String key);\r
+\r
+ // public void getType(String key);\r
+ // \r
+ // public void setReplace(int num);\r
+ // \r
+ // public void setType(int num);\r
+\r
+ }\r
}\r
**/\r
package org.tianocore.migration;\r
\r
-import java.util.regex.*;\r
-import java.io.*;\r
+import java.io.BufferedReader;\r
+import java.io.StringReader;\r
+import java.util.regex.Matcher;\r
+import java.util.regex.Pattern;\r
\r
public final class Critic {\r
- public static final Pattern PTN_NEW_HEAD_COMMENT = Pattern.compile("^\\/\\*\\*.*?\\*\\*\\/",Pattern.DOTALL);\r
- private static final Pattern ptnheadcomment = Pattern.compile("^\\/\\*\\+\\+(.*?)\\-\\-\\*\\/",Pattern.DOTALL);\r
- private static final Pattern ptnfunccomment = Pattern.compile("([\\};\\/\">]\\s*)([\\w\\s\\*]*?[_\\w][_\\w\\d]*\\s*\\([^\\)\\(]*\\)\\s*)\\/\\*\\+\\+(.*?)\\-\\-\\*\\/\\s*(.*?)(?=[\\{;])",Pattern.DOTALL); // find function with {;">/ , may be unsafe\r
- //private static Pattern ptncommentstructure = Pattern.compile("\\/\\*\\+\\+\\s*Routine Description:\\s*(.*?)\\s*Arguments:\\s*(.*?)\\s*Returns:\\s*(.*?)\\s*\\-\\-\\*\\/",Pattern.DOTALL);\r
- private static final Pattern ptncommentequation = Pattern.compile("([^\\s]*)\\s+-\\s+(.*)\\s*");\r
- private static Matcher mtrcommentequation;\r
- private static final Pattern ptnnewcomment = Pattern.compile("(\\s*@(param|retval)\\s+[^\\s]+)\\s+(.*)");\r
- private static Matcher mtrnewcomment;\r
- \r
- private static final int totallinelength = 82;\r
- \r
- public static final void run(String filepath) throws Exception {\r
- if (MigrationTool.doCritic) { // this is left here to set an example for future structure\r
- critic(filepath);\r
- }\r
- }\r
- \r
- private static final void critic(String filepath) throws Exception {\r
- if (filepath.contains(".c") || filepath.contains(".h")) {\r
- BufferedReader rd = null;\r
- String line = null;\r
- StringBuffer templine = new StringBuffer();\r
- boolean incomment = false;\r
-\r
- System.out.println("Criticing " + filepath);\r
- String wholeline = Common.file2string(filepath);\r
-\r
- wholeline = wholeline.replaceAll("\t", " ");\r
- wholeline = Common.replaceAll(wholeline, ptnheadcomment, "/** @file$1**/");\r
- wholeline = Common.replaceAll(wholeline, ptnfunccomment, "$1\n/**$3\n**/\n$4$2");\r
- //wholeline = Common.replaceAll(wholeline, ptncommentstructure, "/**\n#%\n$1\n%#\n#%%\n$2\n%%#\n#%%%\n$3\n%%%#\n**/");\r
-\r
- // first scan\r
- boolean description = false;\r
- boolean arguments = false;\r
- boolean returns = false;\r
- boolean inequation = false;\r
- rd = new BufferedReader(new StringReader(wholeline));\r
- while ((line = rd.readLine()) != null) {\r
- if (line.matches("\\/\\*\\*")) {\r
- incomment = true;\r
- description = false;\r
- arguments = false;\r
- returns = false;\r
- templine.append(line + "\n");\r
- } else if (line.matches("\\*\\*\\/")) {\r
- incomment = false;\r
- templine.append("\n" + line + "\n");\r
- } else if (incomment) {\r
- if (line.contains("Routine Description:")) {\r
- description = true;\r
- arguments = false;\r
- returns = false;\r
- } else if (line.contains("Arguments:")) {\r
- description = false;\r
- arguments = true;\r
- returns = false;\r
- templine.append("\n");\r
- } else if (line.contains("Returns:")) {\r
- description = false;\r
- arguments = false;\r
- returns = true;\r
- templine.append("\n");\r
- } else if (description) {\r
- if (line.trim().length() != 0) {\r
- templine.append(" " + line.trim() + "\n");\r
- }\r
- } else if (arguments) {\r
- mtrcommentequation = ptncommentequation.matcher(line);\r
- if (mtrcommentequation.find()) {\r
- inequation = true;\r
- templine.append(" @param " + mtrcommentequation.group(1) + " " + mtrcommentequation.group(2) + "\n");\r
- } else if (inequation && line.trim().length() == 0) {\r
- inequation = false;\r
- } else if (inequation && line.trim().length() != 0) {\r
- templine.append("#%#%" + line + "\n");\r
- } else {\r
- if (line.trim().length() != 0) {\r
- templine.append(" " + line.trim() + "\n");\r
- }\r
- }\r
- } else if (returns) {\r
- mtrcommentequation = ptncommentequation.matcher(line);\r
- if (mtrcommentequation.find()) {\r
- inequation = true;\r
- templine.append(" @retval " + mtrcommentequation.group(1) + " " + mtrcommentequation.group(2) + "\n");\r
- } else if (inequation && line.trim().length() == 0) {\r
- inequation = false;\r
- } else if (inequation && line.trim().length() != 0) {\r
- templine.append("#%#%" + line + "\n");\r
- } else {\r
- if (line.trim().length() != 0) {\r
- templine.append(" @return " + line.trim() + "\n");\r
- }\r
- }\r
- }\r
- } else {\r
- templine.append(line + "\n");\r
- }\r
- }\r
- wholeline = templine.toString();\r
- wholeline = wholeline.replaceAll("\n#%#%\\s*", " ");\r
- //\r
- \r
- // secend scan\r
- int startmax = 0;\r
- rd = new BufferedReader(new StringReader(wholeline));\r
- while ((line = rd.readLine()) != null) {\r
- if (line.matches("\\/\\*\\*")) {\r
- incomment = true;\r
- templine.append(line + "\n");\r
- } else if (line.matches("\\*\\*\\/")) {\r
- incomment = false;\r
- templine.append(line + "\n");\r
- } else if (incomment) {\r
- mtrnewcomment = ptnnewcomment.matcher(line);\r
- if (mtrnewcomment.find()) {\r
- startmax = mtrnewcomment.group(1).length() > startmax ? mtrnewcomment.group(1).length() : startmax;\r
- }\r
- }\r
- }\r
- startmax++;\r
- //\r
- \r
- // third scan\r
- int n = 0;\r
- String temp = null;\r
- String[] tempcont = null;\r
- int count = 0;\r
- templine = new StringBuffer();\r
- rd = new BufferedReader(new StringReader(wholeline));\r
- while ((line = rd.readLine()) != null) {\r
- if (line.matches("\\/\\*\\*")) {\r
- incomment = true;\r
- templine.append(line + "\n");\r
- } else if (line.matches("\\*\\*\\/")) {\r
- incomment = false;\r
- templine.append(line + "\n");\r
- } else if (incomment) {\r
- mtrnewcomment = ptnnewcomment.matcher(line);\r
- if (mtrnewcomment.find()) {\r
- n = startmax - mtrnewcomment.group(1).length();\r
- templine.append(mtrnewcomment.group(1));\r
- while (n-- >= 0) {\r
- templine.append(" ");\r
- }\r
- temp = mtrnewcomment.group(3);\r
- tempcont = temp.split(" "); // use \\s+ ?\r
- \r
- count = 0;\r
- for (int i = 0; i < tempcont.length; i++) {\r
- count += tempcont[i].length();\r
- if (count <= (totallinelength - startmax)) {\r
- templine.append(tempcont[i] + " ");\r
- count += 1;\r
- } else {\r
- templine.append("\n");\r
- n = startmax;\r
- while (n-- >= 0) {\r
- templine.append(" ");\r
- }\r
- templine.append(tempcont[i] + " ");\r
- count = tempcont[i].length() + 1;\r
- }\r
- }\r
- templine.append("\n");\r
- } else {\r
- templine.append(line + "\n");\r
- }\r
- } else {\r
- templine.append(line + "\n");\r
- }\r
- }\r
- wholeline = templine.toString();\r
- //\r
- // Remove trailing blanks.\r
- // \r
- wholeline = wholeline.replaceAll (" +\n", "\n");\r
- Common.string2file(wholeline, filepath);\r
- }\r
- }\r
- \r
- public static final void fireAt(String path) throws Exception {\r
- //Common.toDoAll(Common.dirCopy_(path), Critic.class.getMethod("critic", String.class), null, null, Common.FILE);\r
- Common.toDoAll(path, Critic.class.getMethod("run", String.class), null, null, Common.FILE);\r
- //Common.toDoAll(Common.dirCopy_(path), critic, Common.FILE);\r
- System.out.println("Critic Done");\r
- }\r
+ public static final Pattern PTN_NEW_HEAD_COMMENT = Pattern.compile(\r
+ "^\\/\\*\\*.*?\\*\\*\\/", Pattern.DOTALL);\r
+\r
+ private static final Pattern ptnheadcomment = Pattern.compile(\r
+ "^\\/\\*\\+\\+(.*?)\\-\\-\\*\\/", Pattern.DOTALL);\r
+\r
+ private static final Pattern ptnfunccomment = Pattern\r
+ .compile(\r
+ "([\\};\\/\">]\\s*)([\\w\\s\\*]*?[_\\w][_\\w\\d]*\\s*\\([^\\)\\(]*\\)\\s*)\\/\\*\\+\\+(.*?)\\-\\-\\*\\/\\s*(.*?)(?=[\\{;])",\r
+ Pattern.DOTALL); // find function with {;">/ , may be\r
+ // unsafe\r
+\r
+ // private static Pattern ptncommentstructure =\r
+ // Pattern.compile("\\/\\*\\+\\+\\s*Routine\r
+ // Description:\\s*(.*?)\\s*Arguments:\\s*(.*?)\\s*Returns:\\s*(.*?)\\s*\\-\\-\\*\\/",Pattern.DOTALL);\r
+ private static final Pattern ptncommentequation = Pattern\r
+ .compile("([^\\s]*)\\s+-\\s+(.*)\\s*");\r
+\r
+ private static Matcher mtrcommentequation;\r
+\r
+ private static final Pattern ptnnewcomment = Pattern\r
+ .compile("(\\s*@(param|retval)\\s+[^\\s]+)\\s+(.*)");\r
+\r
+ private static Matcher mtrnewcomment;\r
+\r
+ private static final int totallinelength = 82;\r
+\r
+ public static final void run(String filepath) throws Exception {\r
+ if (MigrationTool.doCritic) { // this is left here to set an example\r
+ // for future structure\r
+ critic(filepath);\r
+ }\r
+ }\r
+\r
+ private static final void critic(String filepath) throws Exception {\r
+ if (filepath.contains(".c") || filepath.contains(".h")) {\r
+ BufferedReader rd = null;\r
+ String line = null;\r
+ StringBuffer templine = new StringBuffer();\r
+ boolean incomment = false;\r
+\r
+ System.out.println("Criticing " + filepath);\r
+ String wholeline = Common.file2string(filepath);\r
+\r
+ wholeline = wholeline.replaceAll("\t", " ");\r
+ wholeline = Common.replaceAll(wholeline, ptnheadcomment,\r
+ "/** @file$1**/");\r
+ wholeline = Common.replaceAll(wholeline, ptnfunccomment,\r
+ "$1\n/**$3\n**/\n$4$2");\r
+ // wholeline = Common.replaceAll(wholeline, ptncommentstructure,\r
+ // "/**\n#%\n$1\n%#\n#%%\n$2\n%%#\n#%%%\n$3\n%%%#\n**/");\r
+\r
+ // first scan\r
+ boolean description = false;\r
+ boolean arguments = false;\r
+ boolean returns = false;\r
+ boolean inequation = false;\r
+ rd = new BufferedReader(new StringReader(wholeline));\r
+ while ((line = rd.readLine()) != null) {\r
+ if (line.matches("\\/\\*\\*")) {\r
+ incomment = true;\r
+ description = false;\r
+ arguments = false;\r
+ returns = false;\r
+ templine.append(line + "\n");\r
+ } else if (line.matches("\\*\\*\\/")) {\r
+ incomment = false;\r
+ templine.append("\n" + line + "\n");\r
+ } else if (incomment) {\r
+ if (line.contains("Routine Description:")) {\r
+ description = true;\r
+ arguments = false;\r
+ returns = false;\r
+ } else if (line.contains("Arguments:")) {\r
+ description = false;\r
+ arguments = true;\r
+ returns = false;\r
+ templine.append("\n");\r
+ } else if (line.contains("Returns:")) {\r
+ description = false;\r
+ arguments = false;\r
+ returns = true;\r
+ templine.append("\n");\r
+ } else if (description) {\r
+ if (line.trim().length() != 0) {\r
+ templine.append(" " + line.trim() + "\n");\r
+ }\r
+ } else if (arguments) {\r
+ mtrcommentequation = ptncommentequation.matcher(line);\r
+ if (mtrcommentequation.find()) {\r
+ inequation = true;\r
+ templine.append(" @param "\r
+ + mtrcommentequation.group(1) + " "\r
+ + mtrcommentequation.group(2) + "\n");\r
+ } else if (inequation && line.trim().length() == 0) {\r
+ inequation = false;\r
+ } else if (inequation && line.trim().length() != 0) {\r
+ templine.append("#%#%" + line + "\n");\r
+ } else {\r
+ if (line.trim().length() != 0) {\r
+ templine.append(" " + line.trim() + "\n");\r
+ }\r
+ }\r
+ } else if (returns) {\r
+ mtrcommentequation = ptncommentequation.matcher(line);\r
+ if (mtrcommentequation.find()) {\r
+ inequation = true;\r
+ templine.append(" @retval "\r
+ + mtrcommentequation.group(1) + " "\r
+ + mtrcommentequation.group(2) + "\n");\r
+ } else if (inequation && line.trim().length() == 0) {\r
+ inequation = false;\r
+ } else if (inequation && line.trim().length() != 0) {\r
+ templine.append("#%#%" + line + "\n");\r
+ } else {\r
+ if (line.trim().length() != 0) {\r
+ templine.append(" @return " + line.trim()\r
+ + "\n");\r
+ }\r
+ }\r
+ }\r
+ } else {\r
+ templine.append(line + "\n");\r
+ }\r
+ }\r
+ wholeline = templine.toString();\r
+ wholeline = wholeline.replaceAll("\n#%#%\\s*", " ");\r
+ //\r
+\r
+ // secend scan\r
+ int startmax = 0;\r
+ rd = new BufferedReader(new StringReader(wholeline));\r
+ while ((line = rd.readLine()) != null) {\r
+ if (line.matches("\\/\\*\\*")) {\r
+ incomment = true;\r
+ templine.append(line + "\n");\r
+ } else if (line.matches("\\*\\*\\/")) {\r
+ incomment = false;\r
+ templine.append(line + "\n");\r
+ } else if (incomment) {\r
+ mtrnewcomment = ptnnewcomment.matcher(line);\r
+ if (mtrnewcomment.find()) {\r
+ startmax = mtrnewcomment.group(1).length() > startmax ? mtrnewcomment\r
+ .group(1).length()\r
+ : startmax;\r
+ }\r
+ }\r
+ }\r
+ startmax++;\r
+ //\r
+\r
+ // third scan\r
+ int n = 0;\r
+ String temp = null;\r
+ String[] tempcont = null;\r
+ int count = 0;\r
+ templine = new StringBuffer();\r
+ rd = new BufferedReader(new StringReader(wholeline));\r
+ while ((line = rd.readLine()) != null) {\r
+ if (line.matches("\\/\\*\\*")) {\r
+ incomment = true;\r
+ templine.append(line + "\n");\r
+ } else if (line.matches("\\*\\*\\/")) {\r
+ incomment = false;\r
+ templine.append(line + "\n");\r
+ } else if (incomment) {\r
+ mtrnewcomment = ptnnewcomment.matcher(line);\r
+ if (mtrnewcomment.find()) {\r
+ n = startmax - mtrnewcomment.group(1).length();\r
+ templine.append(mtrnewcomment.group(1));\r
+ while (n-- >= 0) {\r
+ templine.append(" ");\r
+ }\r
+ temp = mtrnewcomment.group(3);\r
+ tempcont = temp.split(" "); // use \\s+ ?\r
+\r
+ count = 0;\r
+ for (int i = 0; i < tempcont.length; i++) {\r
+ count += tempcont[i].length();\r
+ if (count <= (totallinelength - startmax)) {\r
+ templine.append(tempcont[i] + " ");\r
+ count += 1;\r
+ } else {\r
+ templine.append("\n");\r
+ n = startmax;\r
+ while (n-- >= 0) {\r
+ templine.append(" ");\r
+ }\r
+ templine.append(tempcont[i] + " ");\r
+ count = tempcont[i].length() + 1;\r
+ }\r
+ }\r
+ templine.append("\n");\r
+ } else {\r
+ templine.append(line + "\n");\r
+ }\r
+ } else {\r
+ templine.append(line + "\n");\r
+ }\r
+ }\r
+ wholeline = templine.toString();\r
+ //\r
+ // Remove trailing blanks.\r
+ // \r
+ wholeline = wholeline.replaceAll(" +\n", "\n");\r
+ Common.string2file(wholeline, filepath);\r
+ }\r
+ }\r
+\r
+ public static final void fireAt(String path) throws Exception {\r
+ // Common.toDoAll(Common.dirCopy_(path),\r
+ // Critic.class.getMethod("critic", String.class), null, null,\r
+ // Common.FILE);\r
+ Common.toDoAll(path, Critic.class.getMethod("run", String.class), null,\r
+ null, Common.FILE);\r
+ // Common.toDoAll(Common.dirCopy_(path), critic, Common.FILE);\r
+ System.out.println("Critic Done");\r
+ }\r
}
\ No newline at end of file
**/\r
package org.tianocore.migration;\r
\r
-import java.io.*;\r
-import java.util.*;\r
-import java.util.regex.*;\r
+import java.io.BufferedReader;\r
+import java.io.File;\r
+import java.io.FileReader;\r
+import java.util.HashMap;\r
+import java.util.HashSet;\r
+import java.util.Iterator;\r
+import java.util.Map;\r
+import java.util.Set;\r
+import java.util.regex.Matcher;\r
+import java.util.regex.Pattern;\r
\r
import org.apache.xmlbeans.XmlObject;\r
-import org.apache.xmlbeans.XmlObject.Factory;\r
import org.tianocore.DbPathAndFilename;\r
import org.tianocore.FrameworkDatabaseDocument;\r
+import org.tianocore.PackageSurfaceAreaDocument;\r
import org.tianocore.FrameworkDatabaseDocument.FrameworkDatabase;\r
import org.tianocore.GuidDeclarationsDocument.GuidDeclarations;\r
-import org.tianocore.PackageListDocument.PackageList;\r
-import org.tianocore.PackageSurfaceAreaDocument;\r
+import org.tianocore.LibraryClassDeclarationsDocument.LibraryClassDeclarations;\r
+import org.tianocore.LibraryClassDeclarationsDocument.LibraryClassDeclarations.LibraryClass;\r
import org.tianocore.PackageSurfaceAreaDocument.PackageSurfaceArea;\r
import org.tianocore.PpiDeclarationsDocument.PpiDeclarations;\r
import org.tianocore.ProtocolDeclarationsDocument.ProtocolDeclarations;\r
-import org.tianocore.LibraryClassDeclarationsDocument.LibraryClassDeclarations;\r
-import org.tianocore.LibraryClassDeclarationsDocument.LibraryClassDeclarations.LibraryClass;\r
\r
public final class Database {\r
- private static final Database INSTANCE = Database.init();;\r
- \r
- Database(String path) {\r
- DatabasePath = path;\r
-\r
- try {\r
- //collectWorkSpaceDatabase();\r
- importPkgGuid("PkgGuid.csv");\r
- importDBLib("Library.csv");\r
- importDBGuid("Guid.csv", "Guid");\r
- importDBGuid("Ppi.csv", "Ppi");\r
- importDBGuid("Protocol.csv", "Protocol");\r
- importDBMacro("Macro.csv");\r
- importListR8Only();\r
- } catch (Exception e) {\r
- System.out.println(e.getMessage());\r
- }\r
- }\r
- \r
- public String DatabasePath;\r
- public Set<String> error = new HashSet<String>();\r
- public Set<String> r8only = new HashSet<String>();\r
- \r
- private Map<String,Guid> hashguid = new HashMap<String,Guid>();\r
- private Map<String,Func> hashfunc = new HashMap<String,Func>();\r
- private Map<String,Macro> hashmacro = new HashMap<String,Macro>();\r
- private Map<String,String> hashPkgGuid = new HashMap<String,String>();\r
-\r
- \r
- //-------------------------------------import------------------------------------------//\r
- private void importPkgGuid(String filename) throws Exception {\r
- BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));\r
- String line;\r
- String[] linecontext;\r
- \r
- if (rd.ready()) {\r
- System.out.println("Found " + filename + ", Importing Package Guid Database.");\r
- //\r
- // Skip the title row.\r
- // \r
- line = rd.readLine();\r
- while ((line = rd.readLine()) != null) {\r
- if (line.length() != 0) {\r
- linecontext = line.split(",");\r
- hashPkgGuid.put(linecontext[0], linecontext[1]);\r
- }\r
- }\r
- }\r
- }\r
- public Iterator<String> dumpAllPkgGuid() {\r
- return hashPkgGuid.values().iterator();\r
- }\r
- private void importDBLib(String filename) throws Exception {\r
- BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));\r
- String line;\r
- String[] linecontext;\r
- Func lf;\r
- \r
- if (rd.ready()) {\r
- System.out.println("Found " + filename + ", Importing Library Database.");\r
- while ((line = rd.readLine()) != null) {\r
- if (line.length() != 0) {\r
- linecontext = line.split(",");\r
- lf = new Func(linecontext);\r
- hashfunc.put(lf.r8funcname,lf);\r
- }\r
- }\r
- }\r
- }\r
- \r
- private void importDBGuid(String filename, String type) throws Exception {\r
- BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));\r
- String line;\r
- String[] linecontext;\r
- Guid gu;\r
- \r
- if (rd.ready()) {\r
- System.out.println("Found " + filename + ", Importing " + type + " Database.");\r
- while ((line = rd.readLine()) != null) {\r
- if (line.length() != 0) {\r
- linecontext = line.split(",");\r
- gu = new Guid(linecontext, type);\r
- hashguid.put(gu.r8name,gu);\r
- }\r
- }\r
- }\r
- }\r
- \r
- private void importDBMacro(String filename) throws Exception {\r
- BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));\r
- String line;\r
- String[] linecontext;\r
- Macro mc;\r
- \r
- if (rd.ready()) {\r
- System.out.println("Found " + filename + ", Importing Macro Database.");\r
- while ((line = rd.readLine()) != null) {\r
- if (line.length() != 0) {\r
- linecontext = line.split(",");\r
- mc = new Macro(linecontext);\r
- hashmacro.put(mc.r8name,mc);\r
- }\r
- }\r
- }\r
- }\r
-\r
- private void importListR8Only() throws Exception {\r
- Pattern ptnr8only = Pattern.compile("////#?(\\w*)?.*?R8_(.*?)\\s*\\(.*?////~", Pattern.DOTALL);\r
- String wholeline = Common.file2string(DatabasePath + File.separator + "R8Lib.c");\r
- System.out.println("Found " + "R8Lib.c" + ", Importing R8Lib Database.");\r
- Matcher mtrr8only = ptnr8only.matcher(wholeline);\r
- while (mtrr8only.find()) {\r
- r8only.add(mtrr8only.group(2));\r
- }\r
- }\r
- \r
- //-------------------------------------import------------------------------------------//\r
-\r
- //-------------------------------------get------------------------------------------//\r
-\r
- public String getR9Lib(String r8funcname) {\r
- String temp = null;\r
- if (hashfunc.containsKey(r8funcname)) {\r
- temp = hashfunc.get(r8funcname).r9libname;\r
- }\r
- return temp;\r
- }\r
- \r
- public String getR9Func(String r8funcname) {\r
- String temp = null;\r
- if (hashfunc.containsKey(r8funcname)) {\r
- temp = hashfunc.get(r8funcname).r9funcname;\r
- }\r
- return temp;\r
- }\r
- \r
- public String getR9Macro(String r8macro) {\r
- return hashmacro.get(r8macro).r9name; // the verification job of if the macro exists in the database is done when registering it\r
- }\r
-\r
- public String getR9Guidname(String r8Guid) {\r
- String temp = null;\r
- try {\r
- temp = hashguid.get(r8Guid).r9name;\r
- } catch (NullPointerException e) {\r
- error.add("getR9Guidname :" + r8Guid);\r
- }\r
- return temp;\r
- }\r
-\r
- public String getGuidType(String r8Guid) {\r
- String temp = null;\r
- try {\r
- temp = hashguid.get(r8Guid).type;\r
- } catch (NullPointerException e) {\r
- error.add("getR9Guidname :" + r8Guid);\r
- }\r
- return temp;\r
- }\r
-\r
- //-------------------------------------get------------------------------------------//\r
-\r
- //-------------------------------------has------------------------------------------//\r
-\r
- public boolean hasFunc(String r8lib) {\r
- return hashfunc.containsKey(r8lib);\r
- }\r
-\r
- public boolean hasGuid(String r8guid) {\r
- return hashguid.containsKey(r8guid);\r
- }\r
-\r
- public boolean hasMacro(String r8macro) {\r
- return hashmacro.containsKey(r8macro);\r
- }\r
- \r
- //-------------------------------------has------------------------------------------//\r
- \r
- //-------------------------------------init------------------------------------------//\r
-\r
- private static final Database init() {\r
- if (System.getenv("WORKSPACE") == null) {\r
- return new Database("C:" + File.separator + "tianocore" + File.separator + "edk2" + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration");\r
- } else {\r
- return new Database(System.getenv("WORKSPACE") + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration");\r
- }\r
- }\r
- \r
- public static final Database getInstance() {\r
- return INSTANCE;\r
- }\r
-\r
-\r
-\r
- private String workspacePath;\r
- private HashMap<String, String> hashDbGuids = new HashMap<String, String>();\r
- private HashMap<String, String> hashDbPpis = new HashMap<String, String>();\r
- private HashMap<String, String> hashDbProtocols = new HashMap<String, String>();\r
- private HashMap<String, String> hashDbLibSymbols = new HashMap<String, String>();\r
- private HashMap<String, String> hashDbLibFunctions = new HashMap<String, String>();\r
- private HashMap<String, String> hashDbLibExterns = new HashMap<String, String>();\r
-\r
- private final String regLibClassName = ".*\\W(\\w[\\w\\d]*)\\.h";\r
- private final Pattern ptnLibClassName = Pattern.compile(regLibClassName);\r
-\r
- private final String regLibSymbol = "#define\\s+(\\w[\\w\\d]*)";\r
- private final Pattern ptnLibSymbol = Pattern.compile(regLibSymbol);\r
-\r
- private final String regLibDataType = "[A-Z][A-Z0-9_]*\\s*\\**";\r
- private final String regLibFunction = regLibDataType + "\\s*(?:EFIAPI)?\\s+" + \r
- "(\\w[\\w\\d]*)\\s*\\([^)]*\\)\\s*;";\r
- private Pattern ptnLibFunction = Pattern.compile(regLibFunction);\r
-\r
- private final String regLibExtern = "extern\\s+" + regLibDataType + \r
- "\\s*(\\w[\\w\\d]*)";\r
- private final Pattern ptnLibExtern = Pattern.compile(regLibExtern);\r
-\r
- private final String convertToOsFilePath(String filePath) {\r
- return filePath.replace("/", File.separator).replace("\\", File.separator);\r
- }\r
- private final void collectLibHeaderFileInfo(String libHeaderFile, String pkgGuid) throws Exception {\r
- String fileContents;\r
- String libClassName;\r
- String libContainer;\r
- Matcher mtrLibClass;\r
- Matcher mtrLibSymbol;\r
- Matcher mtrLibFunction;\r
- Matcher mtrLibExtern;\r
-\r
- System.out.println ("Parsing: " + libHeaderFile);\r
- mtrLibClass = ptnLibClassName.matcher(libHeaderFile);\r
- if (!mtrLibClass.matches()) {\r
- throw new Exception("Illegal libary header file");\r
- }\r
- libClassName = mtrLibClass.group(1);\r
- libContainer = libClassName + "@" + pkgGuid;\r
-\r
- fileContents = Common.file2string(libHeaderFile);\r
- mtrLibSymbol = ptnLibSymbol.matcher(fileContents);\r
- while (mtrLibSymbol.find()) {\r
- String libSymbol;\r
- String oldLibContainer;\r
-\r
- libSymbol = mtrLibSymbol.group(1);\r
- oldLibContainer = hashDbLibSymbols.put(libSymbol, libContainer);\r
- if (oldLibContainer != null) {\r
- String warnMessage;\r
-\r
- warnMessage = "Duplicated Lib Symbol:" + libSymbol + " Found. " +\r
- "Later package will overide the previous one"; \r
- System.out.println(warnMessage);\r
- }\r
- }\r
-\r
- mtrLibFunction = ptnLibFunction.matcher(fileContents);\r
- while (mtrLibFunction.find()) {\r
- String libFunction;\r
- String oldLibContainer;\r
-\r
- libFunction = mtrLibFunction.group(1);\r
- oldLibContainer = hashDbLibFunctions.put(libFunction, libContainer);\r
- if (oldLibContainer != null) {\r
- String warnMessage;\r
-\r
- warnMessage = "Duplicated Lib Function:" + libFunction + " Found. " +\r
- "Later package will overide the previous one"; \r
- System.out.println(warnMessage);\r
- }\r
- }\r
-\r
- mtrLibExtern = ptnLibExtern.matcher(fileContents);\r
- while (mtrLibExtern.find()) {\r
- String libExtern;\r
- String oldLibContainer;\r
-\r
- libExtern = mtrLibExtern.group(1);\r
- oldLibContainer = hashDbLibExterns.put(libExtern, libContainer);\r
- if (oldLibContainer != null) {\r
- String warnMessage;\r
-\r
- warnMessage = "Duplicated Lib Extern:" + libExtern + " Found. " +\r
- "Later package will overide the previous one"; \r
- System.out.println(warnMessage);\r
- }\r
- }\r
- }\r
- private final void collectLibDataBase(PackageSurfaceArea spdDatabase, String pkgDirectory) throws Exception {\r
- String pkgGuid;\r
- LibraryClassDeclarations libClassDeclarations;\r
-\r
- pkgGuid = spdDatabase.getSpdHeader().getGuidValue();\r
- libClassDeclarations = spdDatabase.getLibraryClassDeclarations();\r
- if (libClassDeclarations != null) {\r
- Iterator<LibraryClass> itLibClass;\r
-\r
- itLibClass = libClassDeclarations.getLibraryClassList().iterator();\r
- while (itLibClass.hasNext()) {\r
- String libHeaderFile;\r
-\r
- libHeaderFile = pkgDirectory + File.separator +\r
- itLibClass.next().getIncludeHeader(); \r
- libHeaderFile = convertToOsFilePath (libHeaderFile);\r
- try {\r
- collectLibHeaderFileInfo(libHeaderFile, pkgGuid);\r
- } catch (Exception e) {\r
- String errorMessage;\r
-\r
- errorMessage = "Error (" + e.getMessage() + ")occurs when parsing " +\r
- libHeaderFile;\r
- System.out.println(errorMessage);\r
- }\r
- }\r
- }\r
- }\r
- private final void collectGuidDatabase(PackageSurfaceArea spdDatabase) throws Exception {\r
- String pkgGuid;\r
- GuidDeclarations guidDeclarations;\r
-\r
- pkgGuid = spdDatabase.getSpdHeader().getGuidValue();\r
- guidDeclarations = spdDatabase.getGuidDeclarations();\r
- if (guidDeclarations != null) {\r
- Iterator<GuidDeclarations.Entry> itGuids;\r
-\r
- itGuids = guidDeclarations.getEntryList().iterator();\r
- while (itGuids.hasNext()) {\r
- hashDbGuids.put(itGuids.next().getCName(), pkgGuid); \r
- }\r
- }\r
- \r
- }\r
-\r
- private final void collectPpiDatabase(PackageSurfaceArea spdDatabase) throws Exception {\r
- String pkgGuid;\r
- PpiDeclarations ppiDeclarations;\r
-\r
- pkgGuid = spdDatabase.getSpdHeader().getGuidValue();\r
- ppiDeclarations = spdDatabase.getPpiDeclarations();\r
-\r
- if (ppiDeclarations != null) {\r
- Iterator<PpiDeclarations.Entry> itPpis;\r
-\r
- itPpis = ppiDeclarations.getEntryList().iterator();\r
- while (itPpis.hasNext()) {\r
- hashDbPpis.put(itPpis.next().getCName(), pkgGuid); \r
- }\r
- }\r
- \r
- }\r
-\r
- private final void collectProtocolDatabase(PackageSurfaceArea spdDatabase) throws Exception {\r
- String pkgGuid;\r
- ProtocolDeclarations protocolDeclarations;\r
-\r
- pkgGuid = spdDatabase.getSpdHeader().getGuidValue();\r
- protocolDeclarations = spdDatabase.getProtocolDeclarations();\r
-\r
- if (protocolDeclarations != null) {\r
- Iterator<ProtocolDeclarations.Entry> itProtocols;\r
-\r
- itProtocols = protocolDeclarations.getEntryList().iterator();\r
- while (itProtocols.hasNext()) {\r
- hashDbGuids.put(itProtocols.next().getCName(), pkgGuid); \r
- }\r
- }\r
- \r
- }\r
-\r
- private final void collectPackageDatabase(String packageFileName) throws Exception {\r
- XmlObject xmlPackage;\r
- PackageSurfaceArea spdDatabase;\r
- File pkgFile;\r
- \r
- pkgFile = new File(packageFileName);\r
- xmlPackage = XmlObject.Factory.parse(pkgFile);\r
- spdDatabase = ((PackageSurfaceAreaDocument) xmlPackage).getPackageSurfaceArea();\r
- \r
- collectGuidDatabase(spdDatabase);\r
- collectProtocolDatabase(spdDatabase);\r
- collectPpiDatabase(spdDatabase);\r
- collectLibDataBase(spdDatabase, pkgFile.getParent());\r
-\r
-\r
- }\r
- public final void collectWorkSpaceDatabase() throws Exception {\r
- String databaseFileName;\r
- File databaseFile;\r
- XmlObject xmlDatabase;\r
- FrameworkDatabase frameworkDatabase;\r
- Iterator<DbPathAndFilename> packageFile;\r
- \r
- workspacePath = System.getenv("WORKSPACE");\r
- \r
- if (workspacePath == null) {\r
- String errorMessage = "Envivornment variable \"WORKSPACE\" is not set!";\r
- throw new Exception(errorMessage);\r
- }\r
- databaseFileName = workspacePath + File.separator + \r
- "Tools" + File.separator +\r
- "Conf" + File.separator + \r
- "FrameworkDatabase.db";\r
- System.out.println("Open " + databaseFileName);\r
- databaseFile = new File(databaseFileName);\r
- xmlDatabase = XmlObject.Factory.parse(databaseFile);\r
- frameworkDatabase = ((FrameworkDatabaseDocument) xmlDatabase).getFrameworkDatabase();\r
- packageFile = frameworkDatabase.getPackageList().getFilenameList().iterator();\r
-\r
- while (packageFile.hasNext()) {\r
- String packageFileName = packageFile.next().getStringValue();\r
- packageFileName = workspacePath + File.separator + packageFileName;\r
- packageFileName = convertToOsFilePath(packageFileName);\r
-\r
- System.out.println("Parsing: " + packageFileName);\r
- try {\r
- collectPackageDatabase(packageFileName);\r
- } catch (Exception e) {\r
- System.out.println("Error occured when opening " + packageFileName + e.getMessage());\r
- }\r
- }\r
- }\r
+ private static final Database INSTANCE = Database.init();;\r
+\r
+ Database(String path) {\r
+ DatabasePath = path;\r
+\r
+ try {\r
+ // collectWorkSpaceDatabase();\r
+ importPkgGuid("PkgGuid.csv");\r
+ importDBLib("Library.csv");\r
+ importDBGuid("Guid.csv", "Guid");\r
+ importDBGuid("Ppi.csv", "Ppi");\r
+ importDBGuid("Protocol.csv", "Protocol");\r
+ importDBMacro("Macro.csv");\r
+ importListR8Only();\r
+ } catch (Exception e) {\r
+ System.out.println(e.getMessage());\r
+ }\r
+ }\r
+\r
+ public String DatabasePath;\r
+\r
+ public Set<String> error = new HashSet<String>();\r
+\r
+ public Set<String> r8only = new HashSet<String>();\r
+\r
+ private Map<String, Guid> hashguid = new HashMap<String, Guid>();\r
+\r
+ private Map<String, Func> hashfunc = new HashMap<String, Func>();\r
+\r
+ private Map<String, Macro> hashmacro = new HashMap<String, Macro>();\r
+\r
+ private Map<String, String> hashPkgGuid = new HashMap<String, String>();\r
+\r
+ // -------------------------------------import------------------------------------------//\r
+ private void importPkgGuid(String filename) throws Exception {\r
+ BufferedReader rd = new BufferedReader(new FileReader(DatabasePath\r
+ + File.separator + filename));\r
+ String line;\r
+ String[] linecontext;\r
+\r
+ if (rd.ready()) {\r
+ System.out.println("Found " + filename\r
+ + ", Importing Package Guid Database.");\r
+ //\r
+ // Skip the title row.\r
+ // \r
+ line = rd.readLine();\r
+ while ((line = rd.readLine()) != null) {\r
+ if (line.length() != 0) {\r
+ linecontext = line.split(",");\r
+ hashPkgGuid.put(linecontext[0], linecontext[1]);\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ public Iterator<String> dumpAllPkgGuid() {\r
+ return hashPkgGuid.values().iterator();\r
+ }\r
+\r
+ private void importDBLib(String filename) throws Exception {\r
+ BufferedReader rd = new BufferedReader(new FileReader(DatabasePath\r
+ + File.separator + filename));\r
+ String line;\r
+ String[] linecontext;\r
+ Func lf;\r
+\r
+ if (rd.ready()) {\r
+ System.out.println("Found " + filename\r
+ + ", Importing Library Database.");\r
+ while ((line = rd.readLine()) != null) {\r
+ if (line.length() != 0) {\r
+ linecontext = line.split(",");\r
+ lf = new Func(linecontext);\r
+ hashfunc.put(lf.r8funcname, lf);\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ private void importDBGuid(String filename, String type) throws Exception {\r
+ BufferedReader rd = new BufferedReader(new FileReader(DatabasePath\r
+ + File.separator + filename));\r
+ String line;\r
+ String[] linecontext;\r
+ Guid gu;\r
+\r
+ if (rd.ready()) {\r
+ System.out.println("Found " + filename + ", Importing " + type\r
+ + " Database.");\r
+ while ((line = rd.readLine()) != null) {\r
+ if (line.length() != 0) {\r
+ linecontext = line.split(",");\r
+ gu = new Guid(linecontext, type);\r
+ hashguid.put(gu.r8name, gu);\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ private void importDBMacro(String filename) throws Exception {\r
+ BufferedReader rd = new BufferedReader(new FileReader(DatabasePath\r
+ + File.separator + filename));\r
+ String line;\r
+ String[] linecontext;\r
+ Macro mc;\r
+\r
+ if (rd.ready()) {\r
+ System.out.println("Found " + filename\r
+ + ", Importing Macro Database.");\r
+ while ((line = rd.readLine()) != null) {\r
+ if (line.length() != 0) {\r
+ linecontext = line.split(",");\r
+ mc = new Macro(linecontext);\r
+ hashmacro.put(mc.r8name, mc);\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ private void importListR8Only() throws Exception {\r
+ Pattern ptnr8only = Pattern.compile(\r
+ "////#?(\\w*)?.*?R8_(.*?)\\s*\\(.*?////~", Pattern.DOTALL);\r
+ String wholeline = Common.file2string(DatabasePath + File.separator\r
+ + "R8Lib.c");\r
+ System.out\r
+ .println("Found " + "R8Lib.c" + ", Importing R8Lib Database.");\r
+ Matcher mtrr8only = ptnr8only.matcher(wholeline);\r
+ while (mtrr8only.find()) {\r
+ r8only.add(mtrr8only.group(2));\r
+ }\r
+ }\r
+\r
+ // -------------------------------------import------------------------------------------//\r
+\r
+ // -------------------------------------get------------------------------------------//\r
+\r
+ public String getR9Lib(String r8funcname) {\r
+ String temp = null;\r
+ if (hashfunc.containsKey(r8funcname)) {\r
+ temp = hashfunc.get(r8funcname).r9libname;\r
+ }\r
+ return temp;\r
+ }\r
+\r
+ public String getR9Func(String r8funcname) {\r
+ String temp = null;\r
+ if (hashfunc.containsKey(r8funcname)) {\r
+ temp = hashfunc.get(r8funcname).r9funcname;\r
+ }\r
+ return temp;\r
+ }\r
+\r
+ public String getR9Macro(String r8macro) {\r
+ return hashmacro.get(r8macro).r9name; // the verification job of if\r
+ // the macro exists in the\r
+ // database is done when\r
+ // registering it\r
+ }\r
+\r
+ public String getR9Guidname(String r8Guid) {\r
+ String temp = null;\r
+ try {\r
+ temp = hashguid.get(r8Guid).r9name;\r
+ } catch (NullPointerException e) {\r
+ error.add("getR9Guidname :" + r8Guid);\r
+ }\r
+ return temp;\r
+ }\r
+\r
+ public String getGuidType(String r8Guid) {\r
+ String temp = null;\r
+ try {\r
+ temp = hashguid.get(r8Guid).type;\r
+ } catch (NullPointerException e) {\r
+ error.add("getR9Guidname :" + r8Guid);\r
+ }\r
+ return temp;\r
+ }\r
+\r
+ // -------------------------------------get------------------------------------------//\r
+\r
+ // -------------------------------------has------------------------------------------//\r
+\r
+ public boolean hasFunc(String r8lib) {\r
+ return hashfunc.containsKey(r8lib);\r
+ }\r
+\r
+ public boolean hasGuid(String r8guid) {\r
+ return hashguid.containsKey(r8guid);\r
+ }\r
+\r
+ public boolean hasMacro(String r8macro) {\r
+ return hashmacro.containsKey(r8macro);\r
+ }\r
+\r
+ // -------------------------------------has------------------------------------------//\r
+\r
+ // -------------------------------------init------------------------------------------//\r
+\r
+ private static final Database init() {\r
+ if (System.getenv("WORKSPACE") == null) {\r
+ return new Database("C:" + File.separator + "tianocore"\r
+ + File.separator + "edk2" + File.separator + "Tools"\r
+ + File.separator + "Conf" + File.separator + "Migration");\r
+ } else {\r
+ return new Database(System.getenv("WORKSPACE") + File.separator\r
+ + "Tools" + File.separator + "Conf" + File.separator\r
+ + "Migration");\r
+ }\r
+ }\r
+\r
+ public static final Database getInstance() {\r
+ return INSTANCE;\r
+ }\r
+\r
+ private String workspacePath;\r
+\r
+ private HashMap<String, String> hashDbGuids = new HashMap<String, String>();\r
+\r
+ private HashMap<String, String> hashDbPpis = new HashMap<String, String>();\r
+\r
+ private HashMap<String, String> hashDbProtocols = new HashMap<String, String>();\r
+\r
+ private HashMap<String, String> hashDbLibSymbols = new HashMap<String, String>();\r
+\r
+ private HashMap<String, String> hashDbLibFunctions = new HashMap<String, String>();\r
+\r
+ private HashMap<String, String> hashDbLibExterns = new HashMap<String, String>();\r
+\r
+ private final String regLibClassName = ".*\\W(\\w[\\w\\d]*)\\.h";\r
+\r
+ private final Pattern ptnLibClassName = Pattern.compile(regLibClassName);\r
+\r
+ private final String regLibSymbol = "#define\\s+(\\w[\\w\\d]*)";\r
+\r
+ private final Pattern ptnLibSymbol = Pattern.compile(regLibSymbol);\r
+\r
+ private final String regLibDataType = "[A-Z][A-Z0-9_]*\\s*\\**";\r
+\r
+ private final String regLibFunction = regLibDataType\r
+ + "\\s*(?:EFIAPI)?\\s+" + "(\\w[\\w\\d]*)\\s*\\([^)]*\\)\\s*;";\r
+\r
+ private Pattern ptnLibFunction = Pattern.compile(regLibFunction);\r
+\r
+ private final String regLibExtern = "extern\\s+" + regLibDataType\r
+ + "\\s*(\\w[\\w\\d]*)";\r
+\r
+ private final Pattern ptnLibExtern = Pattern.compile(regLibExtern);\r
+\r
+ private final String convertToOsFilePath(String filePath) {\r
+ return filePath.replace("/", File.separator).replace("\\",\r
+ File.separator);\r
+ }\r
+\r
+ private final void collectLibHeaderFileInfo(String libHeaderFile,\r
+ String pkgGuid) throws Exception {\r
+ String fileContents;\r
+ String libClassName;\r
+ String libContainer;\r
+ Matcher mtrLibClass;\r
+ Matcher mtrLibSymbol;\r
+ Matcher mtrLibFunction;\r
+ Matcher mtrLibExtern;\r
+\r
+ System.out.println("Parsing: " + libHeaderFile);\r
+ mtrLibClass = ptnLibClassName.matcher(libHeaderFile);\r
+ if (!mtrLibClass.matches()) {\r
+ throw new Exception("Illegal libary header file");\r
+ }\r
+ libClassName = mtrLibClass.group(1);\r
+ libContainer = libClassName + "@" + pkgGuid;\r
+\r
+ fileContents = Common.file2string(libHeaderFile);\r
+ mtrLibSymbol = ptnLibSymbol.matcher(fileContents);\r
+ while (mtrLibSymbol.find()) {\r
+ String libSymbol;\r
+ String oldLibContainer;\r
+\r
+ libSymbol = mtrLibSymbol.group(1);\r
+ oldLibContainer = hashDbLibSymbols.put(libSymbol, libContainer);\r
+ if (oldLibContainer != null) {\r
+ String warnMessage;\r
+\r
+ warnMessage = "Duplicated Lib Symbol:" + libSymbol + " Found. "\r
+ + "Later package will overide the previous one";\r
+ System.out.println(warnMessage);\r
+ }\r
+ }\r
+\r
+ mtrLibFunction = ptnLibFunction.matcher(fileContents);\r
+ while (mtrLibFunction.find()) {\r
+ String libFunction;\r
+ String oldLibContainer;\r
+\r
+ libFunction = mtrLibFunction.group(1);\r
+ oldLibContainer = hashDbLibFunctions.put(libFunction, libContainer);\r
+ if (oldLibContainer != null) {\r
+ String warnMessage;\r
+\r
+ warnMessage = "Duplicated Lib Function:" + libFunction\r
+ + " Found. "\r
+ + "Later package will overide the previous one";\r
+ System.out.println(warnMessage);\r
+ }\r
+ }\r
+\r
+ mtrLibExtern = ptnLibExtern.matcher(fileContents);\r
+ while (mtrLibExtern.find()) {\r
+ String libExtern;\r
+ String oldLibContainer;\r
+\r
+ libExtern = mtrLibExtern.group(1);\r
+ oldLibContainer = hashDbLibExterns.put(libExtern, libContainer);\r
+ if (oldLibContainer != null) {\r
+ String warnMessage;\r
+\r
+ warnMessage = "Duplicated Lib Extern:" + libExtern + " Found. "\r
+ + "Later package will overide the previous one";\r
+ System.out.println(warnMessage);\r
+ }\r
+ }\r
+ }\r
+\r
+ private final void collectLibDataBase(PackageSurfaceArea spdDatabase,\r
+ String pkgDirectory) throws Exception {\r
+ String pkgGuid;\r
+ LibraryClassDeclarations libClassDeclarations;\r
+\r
+ pkgGuid = spdDatabase.getSpdHeader().getGuidValue();\r
+ libClassDeclarations = spdDatabase.getLibraryClassDeclarations();\r
+ if (libClassDeclarations != null) {\r
+ Iterator<LibraryClass> itLibClass;\r
+\r
+ itLibClass = libClassDeclarations.getLibraryClassList().iterator();\r
+ while (itLibClass.hasNext()) {\r
+ String libHeaderFile;\r
+\r
+ libHeaderFile = pkgDirectory + File.separator\r
+ + itLibClass.next().getIncludeHeader();\r
+ libHeaderFile = convertToOsFilePath(libHeaderFile);\r
+ try {\r
+ collectLibHeaderFileInfo(libHeaderFile, pkgGuid);\r
+ } catch (Exception e) {\r
+ String errorMessage;\r
+\r
+ errorMessage = "Error (" + e.getMessage()\r
+ + ")occurs when parsing " + libHeaderFile;\r
+ System.out.println(errorMessage);\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ private final void collectGuidDatabase(PackageSurfaceArea spdDatabase)\r
+ throws Exception {\r
+ String pkgGuid;\r
+ GuidDeclarations guidDeclarations;\r
+\r
+ pkgGuid = spdDatabase.getSpdHeader().getGuidValue();\r
+ guidDeclarations = spdDatabase.getGuidDeclarations();\r
+ if (guidDeclarations != null) {\r
+ Iterator<GuidDeclarations.Entry> itGuids;\r
+\r
+ itGuids = guidDeclarations.getEntryList().iterator();\r
+ while (itGuids.hasNext()) {\r
+ hashDbGuids.put(itGuids.next().getCName(), pkgGuid);\r
+ }\r
+ }\r
+\r
+ }\r
+\r
+ private final void collectPpiDatabase(PackageSurfaceArea spdDatabase)\r
+ throws Exception {\r
+ String pkgGuid;\r
+ PpiDeclarations ppiDeclarations;\r
+\r
+ pkgGuid = spdDatabase.getSpdHeader().getGuidValue();\r
+ ppiDeclarations = spdDatabase.getPpiDeclarations();\r
+\r
+ if (ppiDeclarations != null) {\r
+ Iterator<PpiDeclarations.Entry> itPpis;\r
+\r
+ itPpis = ppiDeclarations.getEntryList().iterator();\r
+ while (itPpis.hasNext()) {\r
+ hashDbPpis.put(itPpis.next().getCName(), pkgGuid);\r
+ }\r
+ }\r
+\r
+ }\r
+\r
+ private final void collectProtocolDatabase(PackageSurfaceArea spdDatabase)\r
+ throws Exception {\r
+ String pkgGuid;\r
+ ProtocolDeclarations protocolDeclarations;\r
+\r
+ pkgGuid = spdDatabase.getSpdHeader().getGuidValue();\r
+ protocolDeclarations = spdDatabase.getProtocolDeclarations();\r
+\r
+ if (protocolDeclarations != null) {\r
+ Iterator<ProtocolDeclarations.Entry> itProtocols;\r
+\r
+ itProtocols = protocolDeclarations.getEntryList().iterator();\r
+ while (itProtocols.hasNext()) {\r
+ hashDbGuids.put(itProtocols.next().getCName(), pkgGuid);\r
+ }\r
+ }\r
+\r
+ }\r
+\r
+ private final void collectPackageDatabase(String packageFileName)\r
+ throws Exception {\r
+ XmlObject xmlPackage;\r
+ PackageSurfaceArea spdDatabase;\r
+ File pkgFile;\r
+\r
+ pkgFile = new File(packageFileName);\r
+ xmlPackage = XmlObject.Factory.parse(pkgFile);\r
+ spdDatabase = ((PackageSurfaceAreaDocument) xmlPackage)\r
+ .getPackageSurfaceArea();\r
+\r
+ collectGuidDatabase(spdDatabase);\r
+ collectProtocolDatabase(spdDatabase);\r
+ collectPpiDatabase(spdDatabase);\r
+ collectLibDataBase(spdDatabase, pkgFile.getParent());\r
+\r
+ }\r
+\r
+ public final void collectWorkSpaceDatabase() throws Exception {\r
+ String databaseFileName;\r
+ File databaseFile;\r
+ XmlObject xmlDatabase;\r
+ FrameworkDatabase frameworkDatabase;\r
+ Iterator<DbPathAndFilename> packageFile;\r
+\r
+ workspacePath = System.getenv("WORKSPACE");\r
+\r
+ if (workspacePath == null) {\r
+ String errorMessage = "Envivornment variable \"WORKSPACE\" is not set!";\r
+ throw new Exception(errorMessage);\r
+ }\r
+ databaseFileName = workspacePath + File.separator + "Tools"\r
+ + File.separator + "Conf" + File.separator\r
+ + "FrameworkDatabase.db";\r
+ System.out.println("Open " + databaseFileName);\r
+ databaseFile = new File(databaseFileName);\r
+ xmlDatabase = XmlObject.Factory.parse(databaseFile);\r
+ frameworkDatabase = ((FrameworkDatabaseDocument) xmlDatabase)\r
+ .getFrameworkDatabase();\r
+ packageFile = frameworkDatabase.getPackageList().getFilenameList()\r
+ .iterator();\r
+\r
+ while (packageFile.hasNext()) {\r
+ String packageFileName = packageFile.next().getStringValue();\r
+ packageFileName = workspacePath + File.separator + packageFileName;\r
+ packageFileName = convertToOsFilePath(packageFileName);\r
+\r
+ System.out.println("Parsing: " + packageFileName);\r
+ try {\r
+ collectPackageDatabase(packageFileName);\r
+ } catch (Exception e) {\r
+ System.out.println("Error occured when opening "\r
+ + packageFileName + e.getMessage());\r
+ }\r
+ }\r
+ }\r
}\r
**/\r
package org.tianocore.migration;\r
\r
-import java.awt.*;\r
-import java.awt.event.*;\r
-import java.io.*;\r
-import java.util.*;\r
-import javax.swing.*;\r
-\r
-public final class FirstPanel extends JPanel implements ActionListener, ItemListener, UI {\r
- /**\r
- * Define class Serial Version UID\r
- */\r
- private static final long serialVersionUID = 207759413522910399L;\r
- \r
- private static final FirstPanel INSTANCE = FirstPanel.init();\r
- \r
- private String startpath = null;\r
- \r
- private JButton moduleButton, goButton, msaEditorButton, criticButton, specifyCommentButton;\r
- private JTextField moduletext;\r
- private JTextArea log;\r
- private JFileChooser fc = new JFileChooser();\r
- private JCheckBox filebox, screenbox, mibox, criticbox, defaultpathbox;\r
- \r
- private boolean tofile = true, toscreen = true;\r
- private PrintWriter logfile;\r
-\r
- FirstPanel() {\r
- GridBagLayout gridbag = new GridBagLayout();\r
- setLayout(gridbag);\r
- \r
- GridBagConstraints cst = new GridBagConstraints();\r
- \r
- goButton = new JButton("Go");\r
- goButton.addActionListener(this);\r
- goButton.setActionCommand("go");\r
- \r
- moduleButton = new JButton("Choose ModulePath");\r
- moduleButton.addActionListener(this);\r
-\r
- msaEditorButton = new JButton("MsaEditor");\r
- msaEditorButton.addActionListener(this);\r
- \r
- criticButton = new JButton("Critic");\r
- criticButton.addActionListener(this);\r
- \r
- specifyCommentButton = new JButton("Comment Style");\r
- specifyCommentButton.addActionListener(this);\r
- \r
- moduletext = new JTextField(30);\r
- \r
- filebox = new JCheckBox("Output to logfile", true);\r
- filebox.addItemListener(this);\r
- \r
- screenbox = new JCheckBox("Specify logfile", false);\r
- screenbox.addItemListener(this);\r
- \r
- mibox = new JCheckBox("Print ModuleInfo", false);\r
- mibox.addItemListener(this);\r
- MigrationTool.printModuleInfo = false;\r
- \r
- criticbox = new JCheckBox("Run Critic", true);\r
- criticbox.addItemListener(this);\r
- MigrationTool.doCritic = true;\r
- \r
- defaultpathbox = new JCheckBox("Use Default Output Path", true);\r
- defaultpathbox.addItemListener(this);\r
- MigrationTool.defaultoutput = true;\r
- \r
- JPanel modulePanel = new JPanel();\r
- modulePanel.add(moduleButton);\r
- modulePanel.add(moduletext);\r
- modulePanel.add(goButton);\r
- //modulePanel.add(msaEditorButton);\r
- cst.gridx = 0;\r
- cst.gridy = 0;\r
- //cst.gridwidth = GridBagConstraints.REMAINDER;\r
- gridbag.setConstraints(modulePanel, cst);\r
- add(modulePanel);\r
-\r
- cst.gridx = 1;\r
- cst.gridy = 0;\r
- gridbag.setConstraints(specifyCommentButton, cst);\r
- add(specifyCommentButton);\r
- //gridbag.setConstraints(criticButton, cst);\r
- //add(criticButton);\r
- \r
- JPanel checkboxPanel = new JPanel();\r
- checkboxPanel.setLayout(new BoxLayout(checkboxPanel, BoxLayout.Y_AXIS));\r
- checkboxPanel.add(filebox);\r
- checkboxPanel.add(screenbox);\r
- checkboxPanel.add(mibox);\r
- checkboxPanel.add(criticbox);\r
- checkboxPanel.add(defaultpathbox);\r
- cst.gridx = 1;\r
- cst.gridy = 1;\r
- //cst.gridheight = 2;\r
- gridbag.setConstraints(checkboxPanel, cst);\r
- add(checkboxPanel);\r
- \r
- log = new JTextArea(10,20);\r
- log.setMargin(new Insets(5,5,5,5));\r
- log.setEditable(false);\r
- JScrollPane logScrollPane = new JScrollPane(log);\r
- cst.gridx = 0;\r
- cst.gridy = 1;\r
- cst.fill = GridBagConstraints.BOTH;\r
- gridbag.setConstraints(logScrollPane, cst);\r
- add(logScrollPane);\r
- }\r
- \r
- //---------------------------------------------------------------------------------------//\r
- \r
- public boolean yesOrNo(String question) {\r
- return JOptionPane.showConfirmDialog(this, question, "Yes or No", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;\r
- }\r
- \r
- public void print(String message) {\r
- if (toscreen == true) {\r
- log.append(message);\r
- System.out.print(message);\r
- }\r
- if (tofile == true) {\r
- logfile.append(message);\r
- }\r
- }\r
- \r
- public void println(String message) {\r
- print(message + "\n");\r
- }\r
-\r
- public void println(Set<String> hash) {\r
- if (toscreen == true) {\r
- log.append(hash + "\n");\r
- System.out.println(hash);\r
- }\r
- if (tofile == true) {\r
- logfile.append(hash + "\n");\r
- }\r
- }\r
-\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
- public String getInput(String message) {\r
- return (String)JOptionPane.showInputDialog(message);\r
- }\r
-\r
- //---------------------------------------------------------------------------------------//\r
-\r
- public String getFilepath(String title, int mode) {\r
- fc.setDialogTitle(title);\r
- fc.setFileSelectionMode(mode);\r
- if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {\r
- log.append(fc.getSelectedFile().getAbsolutePath() + "\n");\r
- return fc.getSelectedFile().getAbsolutePath();\r
- }\r
- return null;\r
- }\r
-\r
- //---------------------------------------------------------------------------------------//\r
-\r
- public void actionPerformed(ActionEvent e) {\r
- if ( e.getSource() == moduleButton ) {\r
- startpath = getFilepath("Please choose a starting path", JFileChooser.DIRECTORIES_ONLY);\r
- moduletext.setText(startpath);\r
- }\r
- if ( e.getSource() == goButton ) {\r
- try {\r
- logfile = new PrintWriter(new BufferedWriter(new FileWriter(startpath.replaceAll(Common.STRSEPARATER, "$1") + File.separator + "migration.log")));\r
- MigrationTool.startMigrateAll(startpath);\r
- logfile.flush();\r
- logfile.close();\r
- } catch (Exception en) {\r
- println(en.getMessage());\r
- }\r
- }\r
- if ( e.getSource() == msaEditorButton) {\r
- try {\r
- MsaTreeEditor.init();\r
- } catch (Exception en) {\r
- println(en.getMessage());\r
- }\r
- }\r
- if ( e.getSource() == criticButton) {\r
- try {\r
- Critic.fireAt(startpath);\r
- } catch (Exception en) {\r
- println(en.getMessage());\r
- }\r
- }\r
- if ( e.getSource() == specifyCommentButton) {\r
- try { // input examine is not imposed but should be added\r
- MigrationTool.MIGRATIONCOMMENT = getInput("Please type in wanted comment style used by the tool\nbe sure to start with '//', or you won't enjoy the result");\r
- //MsaWriter.parse("C:\\tianocore\\edk2\\MdePkg\\Library\\BaseLib\\BaseLib.msa");\r
- } catch (Exception en) {\r
- println(en.getMessage());\r
- }\r
- }\r
- }\r
- \r
- public void itemStateChanged(ItemEvent e) {\r
- if (e.getSource() == filebox) {\r
- if (e.getStateChange() == ItemEvent.DESELECTED) {\r
- System.out.println("filebox DESELECTED");\r
- } else if (e.getStateChange() == ItemEvent.SELECTED) {\r
- System.out.println("filebox SELECTED");\r
- }\r
- } else if (e.getSource() == screenbox) {\r
- if (e.getStateChange() == ItemEvent.DESELECTED) {\r
- System.out.println("screenbox DESELECTED");\r
- } else if (e.getStateChange() == ItemEvent.SELECTED) {\r
- System.out.println("screenbox SELECTED");\r
- }\r
- } else if (e.getSource() == mibox) {\r
- if (e.getStateChange() == ItemEvent.DESELECTED) {\r
- MigrationTool.printModuleInfo = false;\r
- } else if (e.getStateChange() == ItemEvent.SELECTED) {\r
- MigrationTool.printModuleInfo = true;\r
- }\r
- } else if (e.getSource() == criticbox) {\r
- if (e.getStateChange() == ItemEvent.DESELECTED) {\r
- MigrationTool.doCritic = false;\r
- } else if (e.getStateChange() == ItemEvent.SELECTED) {\r
- MigrationTool.doCritic = true;\r
- }\r
- } else if (e.getSource() == defaultpathbox) {\r
- if (e.getStateChange() == ItemEvent.DESELECTED) {\r
- MigrationTool.defaultoutput = false;\r
- } else if (e.getStateChange() == ItemEvent.SELECTED) {\r
- MigrationTool.defaultoutput = true;\r
- }\r
- }\r
- }\r
-\r
- //---------------------------------------------------------------------------------------//\r
- \r
- private static final FirstPanel init() {\r
- try {\r
- UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());\r
- } catch (Exception e) {\r
- System.out.println(e.getMessage());\r
- }\r
- \r
- JFrame frame = new JFrame("MigrationTools");\r
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\r
-\r
- FirstPanel fp = new FirstPanel();\r
- fp.setOpaque(true);\r
- frame.setContentPane(fp);\r
-\r
- frame.pack();\r
- frame.setVisible(true);\r
- \r
- return fp;\r
- }\r
- \r
- public static final FirstPanel getInstance() {\r
- return INSTANCE;\r
- }\r
+import java.awt.GridBagConstraints;\r
+import java.awt.GridBagLayout;\r
+import java.awt.Insets;\r
+import java.awt.event.ActionEvent;\r
+import java.awt.event.ActionListener;\r
+import java.awt.event.ItemEvent;\r
+import java.awt.event.ItemListener;\r
+import java.io.BufferedWriter;\r
+import java.io.File;\r
+import java.io.FileWriter;\r
+import java.io.PrintWriter;\r
+import java.util.Set;\r
+\r
+import javax.swing.BoxLayout;\r
+import javax.swing.JButton;\r
+import javax.swing.JCheckBox;\r
+import javax.swing.JFileChooser;\r
+import javax.swing.JFrame;\r
+import javax.swing.JOptionPane;\r
+import javax.swing.JPanel;\r
+import javax.swing.JScrollPane;\r
+import javax.swing.JTextArea;\r
+import javax.swing.JTextField;\r
+import javax.swing.UIManager;\r
+\r
+public final class FirstPanel extends JPanel implements ActionListener,\r
+ ItemListener, UI {\r
+ /**\r
+ * Define class Serial Version UID\r
+ */\r
+ private static final long serialVersionUID = 207759413522910399L;\r
+\r
+ private static final FirstPanel INSTANCE = FirstPanel.init();\r
+\r
+ private String startpath = null;\r
+\r
+ private JButton moduleButton, goButton, msaEditorButton, criticButton,\r
+ specifyCommentButton;\r
+\r
+ private JTextField moduletext;\r
+\r
+ private JTextArea log;\r
+\r
+ private JFileChooser fc = new JFileChooser();\r
+\r
+ private JCheckBox filebox, screenbox, mibox, criticbox, defaultpathbox;\r
+\r
+ private boolean tofile = true, toscreen = true;\r
+\r
+ private PrintWriter logfile;\r
+\r
+ FirstPanel() {\r
+ GridBagLayout gridbag = new GridBagLayout();\r
+ setLayout(gridbag);\r
+\r
+ GridBagConstraints cst = new GridBagConstraints();\r
+\r
+ goButton = new JButton("Go");\r
+ goButton.addActionListener(this);\r
+ goButton.setActionCommand("go");\r
+\r
+ moduleButton = new JButton("Choose ModulePath");\r
+ moduleButton.addActionListener(this);\r
+\r
+ msaEditorButton = new JButton("MsaEditor");\r
+ msaEditorButton.addActionListener(this);\r
+\r
+ criticButton = new JButton("Critic");\r
+ criticButton.addActionListener(this);\r
+\r
+ specifyCommentButton = new JButton("Comment Style");\r
+ specifyCommentButton.addActionListener(this);\r
+\r
+ moduletext = new JTextField(30);\r
+\r
+ filebox = new JCheckBox("Output to logfile", true);\r
+ filebox.addItemListener(this);\r
+\r
+ screenbox = new JCheckBox("Specify logfile", false);\r
+ screenbox.addItemListener(this);\r
+\r
+ mibox = new JCheckBox("Print ModuleInfo", false);\r
+ mibox.addItemListener(this);\r
+ MigrationTool.printModuleInfo = false;\r
+\r
+ criticbox = new JCheckBox("Run Critic", true);\r
+ criticbox.addItemListener(this);\r
+ MigrationTool.doCritic = true;\r
+\r
+ defaultpathbox = new JCheckBox("Use Default Output Path", true);\r
+ defaultpathbox.addItemListener(this);\r
+ MigrationTool.defaultoutput = true;\r
+\r
+ JPanel modulePanel = new JPanel();\r
+ modulePanel.add(moduleButton);\r
+ modulePanel.add(moduletext);\r
+ modulePanel.add(goButton);\r
+ // modulePanel.add(msaEditorButton);\r
+ cst.gridx = 0;\r
+ cst.gridy = 0;\r
+ // cst.gridwidth = GridBagConstraints.REMAINDER;\r
+ gridbag.setConstraints(modulePanel, cst);\r
+ add(modulePanel);\r
+\r
+ cst.gridx = 1;\r
+ cst.gridy = 0;\r
+ gridbag.setConstraints(specifyCommentButton, cst);\r
+ add(specifyCommentButton);\r
+ // gridbag.setConstraints(criticButton, cst);\r
+ // add(criticButton);\r
+\r
+ JPanel checkboxPanel = new JPanel();\r
+ checkboxPanel.setLayout(new BoxLayout(checkboxPanel, BoxLayout.Y_AXIS));\r
+ checkboxPanel.add(filebox);\r
+ checkboxPanel.add(screenbox);\r
+ checkboxPanel.add(mibox);\r
+ checkboxPanel.add(criticbox);\r
+ checkboxPanel.add(defaultpathbox);\r
+ cst.gridx = 1;\r
+ cst.gridy = 1;\r
+ // cst.gridheight = 2;\r
+ gridbag.setConstraints(checkboxPanel, cst);\r
+ add(checkboxPanel);\r
+\r
+ log = new JTextArea(10, 20);\r
+ log.setMargin(new Insets(5, 5, 5, 5));\r
+ log.setEditable(false);\r
+ JScrollPane logScrollPane = new JScrollPane(log);\r
+ cst.gridx = 0;\r
+ cst.gridy = 1;\r
+ cst.fill = GridBagConstraints.BOTH;\r
+ gridbag.setConstraints(logScrollPane, cst);\r
+ add(logScrollPane);\r
+ }\r
+\r
+ // ---------------------------------------------------------------------------------------//\r
+\r
+ public boolean yesOrNo(String question) {\r
+ return JOptionPane.showConfirmDialog(this, question, "Yes or No",\r
+ JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;\r
+ }\r
+\r
+ public void print(String message) {\r
+ if (toscreen == true) {\r
+ log.append(message);\r
+ System.out.print(message);\r
+ }\r
+ if (tofile == true) {\r
+ logfile.append(message);\r
+ }\r
+ }\r
+\r
+ public void println(String message) {\r
+ print(message + "\n");\r
+ }\r
+\r
+ public void println(Set<String> hash) {\r
+ if (toscreen == true) {\r
+ log.append(hash + "\n");\r
+ System.out.println(hash);\r
+ }\r
+ if (tofile == true) {\r
+ logfile.append(hash + "\n");\r
+ }\r
+ }\r
+\r
+ public String choose(String message, Object[] choicelist) {\r
+ return (String) JOptionPane.showInputDialog(this, message, "Choose",\r
+ JOptionPane.PLAIN_MESSAGE, null, choicelist, choicelist[0]);\r
+ }\r
+\r
+ public String getInput(String message) {\r
+ return (String) JOptionPane.showInputDialog(message);\r
+ }\r
+\r
+ // ---------------------------------------------------------------------------------------//\r
+\r
+ public String getFilepath(String title, int mode) {\r
+ fc.setDialogTitle(title);\r
+ fc.setFileSelectionMode(mode);\r
+ if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {\r
+ log.append(fc.getSelectedFile().getAbsolutePath() + "\n");\r
+ return fc.getSelectedFile().getAbsolutePath();\r
+ }\r
+ return null;\r
+ }\r
+\r
+ // ---------------------------------------------------------------------------------------//\r
+\r
+ public void actionPerformed(ActionEvent e) {\r
+ if (e.getSource() == moduleButton) {\r
+ startpath = getFilepath("Please choose a starting path",\r
+ JFileChooser.DIRECTORIES_ONLY);\r
+ moduletext.setText(startpath);\r
+ }\r
+ if (e.getSource() == goButton) {\r
+ try {\r
+ logfile = new PrintWriter(new BufferedWriter(new FileWriter(\r
+ startpath.replaceAll(Common.STRSEPARATER, "$1")\r
+ + File.separator + "migration.log")));\r
+ MigrationTool.startMigrateAll(startpath);\r
+ logfile.flush();\r
+ logfile.close();\r
+ } catch (Exception en) {\r
+ println(en.getMessage());\r
+ }\r
+ }\r
+ if (e.getSource() == msaEditorButton) {\r
+ try {\r
+ MsaTreeEditor.init();\r
+ } catch (Exception en) {\r
+ println(en.getMessage());\r
+ }\r
+ }\r
+ if (e.getSource() == criticButton) {\r
+ try {\r
+ Critic.fireAt(startpath);\r
+ } catch (Exception en) {\r
+ println(en.getMessage());\r
+ }\r
+ }\r
+ if (e.getSource() == specifyCommentButton) {\r
+ try { // input examine is not imposed but should be added\r
+ MigrationTool.MIGRATIONCOMMENT = getInput("Please type in wanted comment style used by the tool\nbe sure to start with '//', or you won't enjoy the result");\r
+ // MsaWriter.parse("C:\\tianocore\\edk2\\MdePkg\\Library\\BaseLib\\BaseLib.msa");\r
+ } catch (Exception en) {\r
+ println(en.getMessage());\r
+ }\r
+ }\r
+ }\r
+\r
+ public void itemStateChanged(ItemEvent e) {\r
+ if (e.getSource() == filebox) {\r
+ if (e.getStateChange() == ItemEvent.DESELECTED) {\r
+ System.out.println("filebox DESELECTED");\r
+ } else if (e.getStateChange() == ItemEvent.SELECTED) {\r
+ System.out.println("filebox SELECTED");\r
+ }\r
+ } else if (e.getSource() == screenbox) {\r
+ if (e.getStateChange() == ItemEvent.DESELECTED) {\r
+ System.out.println("screenbox DESELECTED");\r
+ } else if (e.getStateChange() == ItemEvent.SELECTED) {\r
+ System.out.println("screenbox SELECTED");\r
+ }\r
+ } else if (e.getSource() == mibox) {\r
+ if (e.getStateChange() == ItemEvent.DESELECTED) {\r
+ MigrationTool.printModuleInfo = false;\r
+ } else if (e.getStateChange() == ItemEvent.SELECTED) {\r
+ MigrationTool.printModuleInfo = true;\r
+ }\r
+ } else if (e.getSource() == criticbox) {\r
+ if (e.getStateChange() == ItemEvent.DESELECTED) {\r
+ MigrationTool.doCritic = false;\r
+ } else if (e.getStateChange() == ItemEvent.SELECTED) {\r
+ MigrationTool.doCritic = true;\r
+ }\r
+ } else if (e.getSource() == defaultpathbox) {\r
+ if (e.getStateChange() == ItemEvent.DESELECTED) {\r
+ MigrationTool.defaultoutput = false;\r
+ } else if (e.getStateChange() == ItemEvent.SELECTED) {\r
+ MigrationTool.defaultoutput = true;\r
+ }\r
+ }\r
+ }\r
+\r
+ // ---------------------------------------------------------------------------------------//\r
+\r
+ private static final FirstPanel init() {\r
+ try {\r
+ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());\r
+ } catch (Exception e) {\r
+ System.out.println(e.getMessage());\r
+ }\r
+\r
+ JFrame frame = new JFrame("MigrationTools");\r
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\r
+\r
+ FirstPanel fp = new FirstPanel();\r
+ fp.setOpaque(true);\r
+ frame.setContentPane(fp);\r
+\r
+ frame.pack();\r
+ frame.setVisible(true);\r
+\r
+ return fp;\r
+ }\r
+\r
+ public static final FirstPanel getInstance() {\r
+ return INSTANCE;\r
+ }\r
}
\ No newline at end of file
**/\r
package org.tianocore.migration;\r
\r
-import java.util.regex.*;\r
+import java.util.regex.Matcher;\r
+import java.util.regex.Pattern;\r
\r
public class Func {\r
- Func(String r8func,String r8lib,String r9func,String r9lib) {\r
- r8funcname = r8func;\r
- r8libname = r8lib;\r
- r9funcname = r9func;\r
- r9libname = r9lib;\r
- }\r
- Func(String[] linecontext) {\r
- r8funcname = linecontext[1];\r
- r8libname = linecontext[0];\r
- r9funcname = linecontext[2];\r
- if (r9funcname.contains("n/a")) {\r
- r9funcname = "#error Unknown or missing library function in EDKII: " + r8funcname;\r
- }\r
- r9libname = linecontext[3];\r
- }\r
- public String r8funcname;\r
- public String r8libname;\r
- public String r9funcname;\r
- public String r9libname;\r
-\r
- public static Pattern ptnbrace = Pattern.compile("\\{[^\\{\\}]*\\}",Pattern.MULTILINE);\r
- public static Pattern ptnfuncc = Pattern.compile("(?<!->)([a-zA-Z_]\\w*)\\s*\\(",Pattern.MULTILINE);\r
- public static Pattern ptnfuncd = Pattern.compile("([a-zA-Z_]\\w*)\\s*\\([^\\)\\(]*\\)\\s*@",Pattern.MULTILINE);\r
- public static Pattern ptnlowcase = Pattern.compile("[a-z]"); // must be removed\r
- \r
- private static String reservedwords = "if for pack while switch return sizeof";\r
- \r
- public static String register(Matcher mtr, ModuleInfo mi, Database db) {\r
- String temp = null;\r
-\r
- temp = mtr.group(1); // both changed and not changed funcc are registered , for finding all the non-local function calls\r
- Matcher mtrlowcase = ptnlowcase.matcher(temp); // must be removed , so the two funcs can be merged\r
- if (!reservedwords.contains(temp) && mtrlowcase.find()) {\r
- mi.hashfuncc.add(temp);\r
- }\r
- return temp;\r
- }\r
+ Func(String r8func, String r8lib, String r9func, String r9lib) {\r
+ r8funcname = r8func;\r
+ r8libname = r8lib;\r
+ r9funcname = r9func;\r
+ r9libname = r9lib;\r
+ }\r
+\r
+ Func(String[] linecontext) {\r
+ r8funcname = linecontext[1];\r
+ r8libname = linecontext[0];\r
+ r9funcname = linecontext[2];\r
+ if (r9funcname.contains("n/a")) {\r
+ r9funcname = "#error Unknown or missing library function in EDKII: "\r
+ + r8funcname;\r
+ }\r
+ r9libname = linecontext[3];\r
+ }\r
+\r
+ public String r8funcname;\r
+\r
+ public String r8libname;\r
+\r
+ public String r9funcname;\r
+\r
+ public String r9libname;\r
+\r
+ public static Pattern ptnbrace = Pattern.compile("\\{[^\\{\\}]*\\}",\r
+ Pattern.MULTILINE);\r
+\r
+ public static Pattern ptnfuncc = Pattern.compile(\r
+ "(?<!->)([a-zA-Z_]\\w*)\\s*\\(", Pattern.MULTILINE);\r
+\r
+ public static Pattern ptnfuncd = Pattern.compile(\r
+ "([a-zA-Z_]\\w*)\\s*\\([^\\)\\(]*\\)\\s*@", Pattern.MULTILINE);\r
+\r
+ public static Pattern ptnlowcase = Pattern.compile("[a-z]"); // must be\r
+ // removed\r
+\r
+ private static String reservedwords = "if for pack while switch return sizeof";\r
+\r
+ public static String register(Matcher mtr, ModuleInfo mi, Database db) {\r
+ String temp = null;\r
+\r
+ temp = mtr.group(1); // both changed and not changed funcc are\r
+ // registered , for finding all the non-local\r
+ // function calls\r
+ Matcher mtrlowcase = ptnlowcase.matcher(temp); // must be removed , so\r
+ // the two funcs can be\r
+ // merged\r
+ if (!reservedwords.contains(temp) && mtrlowcase.find()) {\r
+ mi.hashfuncc.add(temp);\r
+ }\r
+ return temp;\r
+ }\r
}\r
**/\r
package org.tianocore.migration;\r
\r
-import java.util.regex.*;\r
+import java.util.regex.Matcher;\r
+import java.util.regex.Pattern;\r
\r
import org.tianocore.UsageTypes;\r
\r
public class Guid {\r
- Guid (String r8, String t, String n, String r9, String gv, String p) {\r
- r8name = r8;\r
- type = t;\r
- name = n;\r
- r9name = r9;\r
- guidvalue = gv;\r
- pack = p;\r
- }\r
- Guid (String[] linecontext, String t) {\r
- r8name = linecontext[1];\r
- type = t;\r
- name = linecontext[0];\r
- r9name = linecontext[2];\r
- guidvalue = linecontext[3];\r
- pack = linecontext[4];\r
- }\r
- public String r8name;\r
- public String type;\r
- public String name;\r
- public String r9name;\r
- public String guidvalue;\r
- public String pack;\r
+ Guid(String r8, String t, String n, String r9, String gv, String p) {\r
+ r8name = r8;\r
+ type = t;\r
+ name = n;\r
+ r9name = r9;\r
+ guidvalue = gv;\r
+ pack = p;\r
+ }\r
\r
- public static Pattern ptnguid = Pattern.compile("g\\w*Guid");\r
+ Guid(String[] linecontext, String t) {\r
+ r8name = linecontext[1];\r
+ type = t;\r
+ name = linecontext[0];\r
+ r9name = linecontext[2];\r
+ guidvalue = linecontext[3];\r
+ pack = linecontext[4];\r
+ }\r
\r
- public static String register(Matcher mtr, ModuleInfo mi, Database db) {\r
- String type = null;\r
- String temp = null;\r
- \r
- temp = mtr.group();\r
- if (MigrationTool.db.hasGuid(temp)) { // only changed guids registered, because both changed and not changed guids are included in database\r
- type = MigrationTool.db.getGuidType(temp);\r
- if (type.matches("Protocol")) {\r
- mi.addProtocol(temp, UsageTypes.ALWAYS_CONSUMED);\r
- //mi.protocols.add(temp);\r
- } else if (type.matches("Ppi")) {\r
- mi.addPpi(temp, UsageTypes.ALWAYS_CONSUMED);\r
- //mi.ppis.add(temp);\r
- } else if (type.matches("Guid")) {\r
- mi.addGuid(temp, UsageTypes.ALWAYS_CONSUMED);\r
- //mi.guids.add(temp);\r
- }\r
- return temp;\r
- }\r
- return null;\r
- }\r
+ public String r8name;\r
+\r
+ public String type;\r
+\r
+ public String name;\r
+\r
+ public String r9name;\r
+\r
+ public String guidvalue;\r
+\r
+ public String pack;\r
+\r
+ public static Pattern ptnguid = Pattern.compile("g\\w*Guid");\r
+\r
+ public static String register(Matcher mtr, ModuleInfo mi, Database db) {\r
+ String type = null;\r
+ String temp = null;\r
+\r
+ temp = mtr.group();\r
+ if (MigrationTool.db.hasGuid(temp)) { // only changed guids\r
+ // registered, because both\r
+ // changed and not changed guids\r
+ // are included in database\r
+ type = MigrationTool.db.getGuidType(temp);\r
+ if (type.matches("Protocol")) {\r
+ mi.addProtocol(temp, UsageTypes.ALWAYS_CONSUMED);\r
+ // mi.protocols.add(temp);\r
+ } else if (type.matches("Ppi")) {\r
+ mi.addPpi(temp, UsageTypes.ALWAYS_CONSUMED);\r
+ // mi.ppis.add(temp);\r
+ } else if (type.matches("Guid")) {\r
+ mi.addGuid(temp, UsageTypes.ALWAYS_CONSUMED);\r
+ // mi.guids.add(temp);\r
+ }\r
+ return temp;\r
+ }\r
+ return null;\r
+ }\r
}
\ No newline at end of file
**/\r
package org.tianocore.migration;\r
\r
-import java.util.regex.*;\r
+import java.util.regex.Matcher;\r
+import java.util.regex.Pattern;\r
\r
public class Macro {\r
- Macro(String r8, String r9) {\r
- r8name = r8;\r
- r9name = r9;\r
- }\r
- Macro(String[] linecontext) {\r
- r8name = linecontext[0];\r
- r9name = linecontext[1];\r
- }\r
- \r
- public String r8name;\r
- public String r9name;\r
-\r
- public static Pattern ptntmacro = Pattern.compile("\\b\\w(\\w|\\d)*",Pattern.MULTILINE);\r
-\r
- private static String unmacro = "VOID UINTN BOOLEAN ASSERT OPTIONAL STATIC NULL TRUE IN OUT FALSE";\r
-\r
- public static String register(Matcher mtr, ModuleInfo mi, Database db) {\r
- String temp = null;\r
- \r
- temp = mtr.group();\r
- mi.hashmacro.add(temp);\r
- if (MigrationTool.db.hasMacro(temp)) { // only changed macros registered, because the database of macro has only changed ones\r
- if (!unmacro.contains(temp)) {\r
- mi.hashnonlocalmacro.add(temp);\r
- }\r
- return temp;\r
- }\r
- return null;\r
- }\r
+ Macro(String r8, String r9) {\r
+ r8name = r8;\r
+ r9name = r9;\r
+ }\r
+\r
+ Macro(String[] linecontext) {\r
+ r8name = linecontext[0];\r
+ r9name = linecontext[1];\r
+ }\r
+\r
+ public String r8name;\r
+\r
+ public String r9name;\r
+\r
+ public static Pattern ptntmacro = Pattern.compile("\\b\\w(\\w|\\d)*",\r
+ Pattern.MULTILINE);\r
+\r
+ private static String unmacro = "VOID UINTN BOOLEAN ASSERT OPTIONAL STATIC NULL TRUE IN OUT FALSE";\r
+\r
+ public static String register(Matcher mtr, ModuleInfo mi, Database db) {\r
+ String temp = null;\r
+\r
+ temp = mtr.group();\r
+ mi.hashmacro.add(temp);\r
+ if (MigrationTool.db.hasMacro(temp)) { // only changed macros\r
+ // registered, because the\r
+ // database of macro has only\r
+ // changed ones\r
+ if (!unmacro.contains(temp)) {\r
+ mi.hashnonlocalmacro.add(temp);\r
+ }\r
+ return temp;\r
+ }\r
+ return null;\r
+ }\r
}
\ No newline at end of file
package org.tianocore.migration;\r
\r
import java.io.File;\r
-import java.util.*;\r
+import java.util.HashMap;\r
+import java.util.Iterator;\r
+import java.util.Set;\r
\r
import javax.swing.JFileChooser;\r
\r
-import org.tianocore.UsageTypes;\r
-\r
+/**\r
+ * The class is used as the main class of the MigrationTool, maintains the main\r
+ * work flow, and all the global variables and constants. It extends nothing.\r
+ * \r
+ */\r
public class MigrationTool {\r
- public static UI ui = null;\r
- public static Database db = null;\r
-\r
- public static String MIGRATIONCOMMENT = "//@MT:";\r
-\r
- public static boolean printModuleInfo = false;\r
- public static boolean doCritic = false;\r
- public static boolean defaultoutput = false;\r
- \r
- public static final HashMap<ModuleInfo, String> ModuleInfoMap = new HashMap<ModuleInfo, String>();\r
-\r
- private static String startpath = null;\r
- \r
- private static final void mainFlow(ModuleInfo mi) throws Exception {\r
- ModuleReader.aimAt(mi);\r
- SourceFileReplacer.fireAt(mi); // some adding library actions are taken here,so it must be put before "MsaWriter"\r
-\r
- // show result\r
- if (MigrationTool.printModuleInfo) {\r
- MigrationTool.ui.println("\nModule Information : ");\r
- MigrationTool.ui.println("Entrypoint : " + mi.entrypoint);\r
- show(mi.protocols, "Protocol : ");\r
- show(mi.ppis, "Ppi : ");\r
- show(mi.guids, "Guid : ");\r
- show(mi.hashfuncc, "call : ");\r
- show(mi.hashfuncd, "def : ");\r
- show(mi.hashEFIcall, "EFIcall : ");\r
- show(mi.hashnonlocalmacro, "macro : ");\r
- show(mi.hashnonlocalfunc, "nonlocal : ");\r
- show(mi.hashr8only, "hashr8only : ");\r
- }\r
- new MsaWriter(mi).flush();\r
-\r
- //mi.getMsaOwner().flush(MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator + mi.modulename + ".___");\r
-\r
- if (MigrationTool.doCritic) {\r
- Critic.fireAt(ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename);\r
- }\r
-\r
- MigrationTool.ui.println("Errors Left : " + MigrationTool.db.error);\r
- MigrationTool.ui.println("Complete!");\r
- }\r
-\r
- private static final void show(Set<String> hash, String show) {\r
- MigrationTool.ui.println(show + hash.size());\r
- MigrationTool.ui.println(hash);\r
- }\r
-\r
- public static final String getTempDir(String modulepath) {\r
- return "C:" + File.separator + "MigrationTool_Temp" + modulepath.replace(startpath, "");\r
- }\r
-\r
- private static final String assignOutPutPath(String inputpath) {\r
- if (MigrationTool.defaultoutput) {\r
- return inputpath.replaceAll(Common.STRSEPARATER, "$1");\r
- } else {\r
- return MigrationTool.ui.getFilepath("Please choose where to place the output module", JFileChooser.DIRECTORIES_ONLY);\r
- }\r
- }\r
- \r
- public static final void seekModule(String filepath) throws Exception {\r
- if (ModuleInfo.isModule(filepath)) {\r
- ModuleInfoMap.put(new ModuleInfo(filepath), assignOutPutPath(filepath));\r
- }\r
- }\r
-\r
- public static final void startMigrateAll(String path) throws Exception {\r
- startpath = path;\r
- MigrationTool.ui.println("Project Migration");\r
- MigrationTool.ui.println("Copyright (c) 2006, Intel Corporation");\r
- \r
- if (new File("C:" + File.separator + "MigrationTool_Temp").exists()) {\r
- Common.deleteDir("C:" + File.separator + "MigrationTool_Temp");\r
- }\r
- \r
- Common.toDoAll(path, MigrationTool.class.getMethod("seekModule", String.class), null, null, Common.DIR);\r
- \r
- Iterator<ModuleInfo> miit = ModuleInfoMap.keySet().iterator();\r
- while (miit.hasNext()) {\r
- mainFlow(miit.next());\r
- }\r
- \r
- ModuleInfoMap.clear();\r
- \r
- Common.deleteDir("C:" + File.separator + "MigrationTool_Temp");\r
- }\r
-\r
- public static void main(String[] args) throws Exception {\r
- ui = FirstPanel.getInstance();\r
- db = Database.getInstance();\r
- }\r
+\r
+ //\r
+ // These two objects are serves globally, it is always required, and only\r
+ // one instance is ever allowed.\r
+ //\r
+ public static UI ui = null;\r
+\r
+ public static Database db = null;\r
+\r
+ //\r
+ // The global constant for MigrationTool generated comments.\r
+ //\r
+ public static String MIGRATIONCOMMENT = "//@MT:";\r
+\r
+ //\r
+ // Global switches that are changed by user by the FirstPanel.\r
+ //\r
+ public static boolean printModuleInfo = false;\r
+\r
+ public static boolean doCritic = false;\r
+\r
+ public static boolean defaultoutput = false;\r
+\r
+ //\r
+ // A hashmap that associates the reference to a ModuleInfo with its\r
+ // outputpath.\r
+ //\r
+ public static final HashMap<ModuleInfo, String> ModuleInfoMap = new HashMap<ModuleInfo, String>();\r
+\r
+ //\r
+ // The starting point of the MigrationTool.\r
+ //\r
+ private static String startpath = null;\r
+\r
+ /**\r
+ * This method defines the overall main work flow of the MigrationTool.\r
+ * \r
+ * @param mi\r
+ * @throws Exception\r
+ */\r
+ private static final void mainFlow(ModuleInfo mi) throws Exception {\r
+ ModuleReader.aimAt(mi);\r
+ SourceFileReplacer.fireAt(mi); // some adding library actions are taken\r
+ // here,so it must be put before\r
+ // "MsaWriter"\r
+\r
+ // show result\r
+ if (MigrationTool.printModuleInfo) {\r
+ MigrationTool.ui.println("\nModule Information : ");\r
+ MigrationTool.ui.println("Entrypoint : " + mi.entrypoint);\r
+ show(mi.protocols, "Protocol : ");\r
+ show(mi.ppis, "Ppi : ");\r
+ show(mi.guids, "Guid : ");\r
+ show(mi.hashfuncc, "call : ");\r
+ show(mi.hashfuncd, "def : ");\r
+ show(mi.hashEFIcall, "EFIcall : ");\r
+ show(mi.hashnonlocalmacro, "macro : ");\r
+ show(mi.hashnonlocalfunc, "nonlocal : ");\r
+ show(mi.hashr8only, "hashr8only : ");\r
+ }\r
+ new MsaWriter(mi).flush();\r
+\r
+ // mi.getMsaOwner().flush(MigrationTool.ModuleInfoMap.get(mi) +\r
+ // File.separator + "Migration_" + mi.modulename + File.separator +\r
+ // mi.modulename + ".___");\r
+\r
+ if (MigrationTool.doCritic) {\r
+ Critic.fireAt(ModuleInfoMap.get(mi) + File.separator + "Migration_"\r
+ + mi.modulename);\r
+ }\r
+\r
+ MigrationTool.ui.println("Errors Left : " + MigrationTool.db.error);\r
+ MigrationTool.ui.println("Complete!");\r
+ }\r
+\r
+ /**\r
+ * This method is specially written to print the message for ModuleInfo,\r
+ * just for less code repeating.\r
+ * \r
+ * @param hash\r
+ * @param show\r
+ */\r
+ private static final void show(Set<String> hash, String show) {\r
+ MigrationTool.ui.println(show + hash.size());\r
+ MigrationTool.ui.println(hash);\r
+ }\r
+\r
+ /**\r
+ * This method designates the location of temp directory.\r
+ * \r
+ * @param modulepath\r
+ * @return\r
+ */\r
+ public static final String getTempDir(String modulepath) {\r
+ return "C:" + File.separator + "MigrationTool_Temp"\r
+ + modulepath.replace(startpath, "");\r
+ }\r
+\r
+ private static final String assignOutPutPath(String inputpath) {\r
+ if (MigrationTool.defaultoutput) {\r
+ return inputpath.replaceAll(Common.STRSEPARATER, "$1");\r
+ } else {\r
+ return MigrationTool.ui.getFilepath(\r
+ "Please choose where to place the output module",\r
+ JFileChooser.DIRECTORIES_ONLY);\r
+ }\r
+ }\r
+\r
+ public static final void seekModule(String filepath) throws Exception {\r
+ if (ModuleInfo.isModule(filepath)) {\r
+ ModuleInfoMap.put(new ModuleInfo(filepath),\r
+ assignOutPutPath(filepath));\r
+ }\r
+ }\r
+\r
+ public static final void startMigrateAll(String path) throws Exception {\r
+ startpath = path;\r
+ MigrationTool.ui.println("Project Migration");\r
+ MigrationTool.ui.println("Copyright (c) 2006, Intel Corporation");\r
+\r
+ if (new File("C:" + File.separator + "MigrationTool_Temp").exists()) {\r
+ Common.deleteDir("C:" + File.separator + "MigrationTool_Temp");\r
+ }\r
+\r
+ Common.toDoAll(path, MigrationTool.class.getMethod("seekModule",\r
+ String.class), null, null, Common.DIR);\r
+\r
+ Iterator<ModuleInfo> miit = ModuleInfoMap.keySet().iterator();\r
+ while (miit.hasNext()) {\r
+ mainFlow(miit.next());\r
+ }\r
+\r
+ ModuleInfoMap.clear();\r
+\r
+ Common.deleteDir("C:" + File.separator + "MigrationTool_Temp");\r
+ }\r
+\r
+ public static void main(String[] args) throws Exception {\r
+ ui = FirstPanel.getInstance();\r
+ db = Database.getInstance();\r
+ }\r
}\r
**/\r
package org.tianocore.migration;\r
\r
-import java.io.*;\r
-import java.util.*;\r
+import java.io.File;\r
+import java.util.HashSet;\r
+import java.util.Set;\r
\r
import org.tianocore.UsageTypes;\r
import org.tianocore.SupportedArchitectures.Enum;\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
-*/\r
+ * Class ModuleInfo is built for scanning the source files, it contains all the\r
+ * needed information and all the temporary data.\r
+ */\r
public final class ModuleInfo {\r
- ModuleInfo(String modulepath) throws Exception {\r
- this.modulepath = modulepath;\r
- this.temppath = MigrationTool.getTempDir(this.modulepath);\r
- }\r
-\r
- public final String modulepath;\r
- public final String temppath;\r
- \r
- private MsaOwner msaowner = MsaOwner.initNewMsaOwner();\r
- \r
- public String modulename = null;\r
- public String guidvalue = null;\r
- public String moduletype = null;\r
- public String entrypoint = null;\r
- public String license = null;\r
- \r
- public final Set<String> localmodulesources = new HashSet<String>(); //contains both .c and .h\r
- public final Set<String> preprocessedccodes = new HashSet<String>();\r
- public final Set<String> msaorinf = new HashSet<String>(); //only a little, hash may be too big for this\r
- public final Set<String> infincludes = new HashSet<String>();\r
- public final Set<String> infsources = new HashSet<String>();\r
- \r
- public final Set<String> hashfuncc = new HashSet<String>();\r
- public final Set<String> hashfuncd = new HashSet<String>();\r
- public final Set<String> hashnonlocalfunc = new HashSet<String>();\r
- public final Set<String> hashnonlocalmacro = new HashSet<String>();\r
- public final Set<String> hashEFIcall = new HashSet<String>();\r
- public final Set<String> hashr8only = new HashSet<String>();\r
- public final Set<String> hashmacro = new HashSet<String>();\r
- \r
- public final Set<String> hashrequiredr9libs = new HashSet<String>(); // hashrequiredr9libs is now all added in SourceFileReplacer \r
- public final Set<String> guids = new HashSet<String>();\r
- public final Set<String> protocols = new HashSet<String>();\r
- public final Set<String> ppis = new HashSet<String>();\r
-\r
- //-----------------------------------------------------------------------------------//\r
-\r
- //addModuleType\r
- //addGuidValue\r
- //addModuleName\r
- \r
- public final boolean addSourceFile (String filename, Enum en) {\r
- localmodulesources.add(filename);\r
- return msaowner.addSourceFile(filename, en);\r
- }\r
- \r
- public final boolean addProtocol (String proname, UsageTypes.Enum usage) {\r
- protocols.add(proname);\r
- return msaowner.addProtocol(proname, usage);\r
- }\r
- \r
- public final boolean addPpi (String ppiname, UsageTypes.Enum usage) {\r
- ppis.add(ppiname);\r
- return msaowner.addPpi(ppiname, usage);\r
- }\r
- \r
- public final boolean addGuid (String guidname, UsageTypes.Enum usage) {\r
- guids.add(guidname);\r
- return msaowner.addGuid(guidname, usage);\r
- }\r
- \r
- public final boolean addLibraryClass(String name, UsageTypes.Enum usage) {\r
- //\r
- // This section is only for adding library classes, this functionality should be inside MsaOwner!!!\r
- //\r
- //if (!hashrequiredr9libs.contains(name)) {\r
- msaowner.addLibraryClass(name, usage);\r
- //}\r
- //\r
- hashrequiredr9libs.add(name);\r
- return true;\r
- }\r
- \r
- //-----------------------------------------------------------------------------------//\r
- \r
- public final String getModuleType() {\r
- if (moduletype.contains("PEI")) {\r
- return "PEIM";\r
- } else {\r
- return "DXE_DRIVER";\r
- }\r
- }\r
- \r
- public final void enroll(String filepath) throws Exception {\r
- String temp = null;\r
- if (filepath.contains(".inf") || filepath.contains(".msa")) {\r
- temp = filepath.replace(modulepath + File.separator, "");\r
- if (!temp.contains(File.separator)) { // .inf in subdirectory is not regarded\r
- msaorinf.add(temp);\r
- }\r
- } else if (filepath.contains(".c") || filepath.contains(".C") || filepath.contains(".h") || \r
- filepath.contains(".H") || filepath.contains(".dxs") || filepath.contains(".uni") ||\r
- filepath.contains(".s") || filepath.contains(".S") || filepath.contains(".i") ||\r
- filepath.contains(".asm")) {\r
- addSourceFile(filepath.replace(modulepath + File.separator, ""), null);\r
- } \r
- }\r
-\r
- public static final boolean isModule(String path) {\r
- String[] list = new File(path).list();\r
- for (int i = 0 ; i < list.length ; i++) {\r
- if (!new File(list[i]).isDirectory()) {\r
- if (list[i].contains(".inf") || list[i].contains(".msa")) {\r
- return true;\r
- }\r
- }\r
- }\r
- return false;\r
- }\r
- \r
- public final MsaOwner getMsaOwner() {\r
- return msaowner;\r
- }\r
+ ModuleInfo(String modulepath) throws Exception {\r
+ this.modulepath = modulepath;\r
+ this.temppath = MigrationTool.getTempDir(this.modulepath);\r
+ }\r
+\r
+ public final String modulepath;\r
+\r
+ public final String temppath;\r
+\r
+ private MsaOwner msaowner = MsaOwner.initNewMsaOwner();\r
+\r
+ public String modulename = null;\r
+\r
+ public String guidvalue = null;\r
+\r
+ public String moduletype = null;\r
+\r
+ public String entrypoint = null;\r
+\r
+ public String license = null;\r
+\r
+ public final Set<String> localmodulesources = new HashSet<String>(); // contains\r
+ // both\r
+ // .c\r
+ // and\r
+ // .h\r
+\r
+ public final Set<String> preprocessedccodes = new HashSet<String>();\r
+\r
+ public final Set<String> msaorinf = new HashSet<String>(); // only a\r
+ // little, hash\r
+ // may be too\r
+ // big for this\r
+\r
+ public final Set<String> infincludes = new HashSet<String>();\r
+\r
+ public final Set<String> infsources = new HashSet<String>();\r
+\r
+ public final Set<String> hashfuncc = new HashSet<String>();\r
+\r
+ public final Set<String> hashfuncd = new HashSet<String>();\r
+\r
+ public final Set<String> hashnonlocalfunc = new HashSet<String>();\r
+\r
+ public final Set<String> hashnonlocalmacro = new HashSet<String>();\r
+\r
+ public final Set<String> hashEFIcall = new HashSet<String>();\r
+\r
+ public final Set<String> hashr8only = new HashSet<String>();\r
+\r
+ public final Set<String> hashmacro = new HashSet<String>();\r
+\r
+ public final Set<String> hashrequiredr9libs = new HashSet<String>(); // hashrequiredr9libs\r
+ // is\r
+ // now\r
+ // all\r
+ // added\r
+ // in\r
+ // SourceFileReplacer\r
+\r
+ public final Set<String> guids = new HashSet<String>();\r
+\r
+ public final Set<String> protocols = new HashSet<String>();\r
+\r
+ public final Set<String> ppis = new HashSet<String>();\r
+\r
+ // -----------------------------------------------------------------------------------//\r
+\r
+ // addModuleType\r
+ // addGuidValue\r
+ // addModuleName\r
+\r
+ public final boolean addSourceFile(String filename, Enum en) {\r
+ localmodulesources.add(filename);\r
+ return msaowner.addSourceFile(filename, en);\r
+ }\r
+\r
+ public final boolean addProtocol(String proname, UsageTypes.Enum usage) {\r
+ protocols.add(proname);\r
+ return msaowner.addProtocol(proname, usage);\r
+ }\r
+\r
+ public final boolean addPpi(String ppiname, UsageTypes.Enum usage) {\r
+ ppis.add(ppiname);\r
+ return msaowner.addPpi(ppiname, usage);\r
+ }\r
+\r
+ public final boolean addGuid(String guidname, UsageTypes.Enum usage) {\r
+ guids.add(guidname);\r
+ return msaowner.addGuid(guidname, usage);\r
+ }\r
+\r
+ public final boolean addLibraryClass(String name, UsageTypes.Enum usage) {\r
+ //\r
+ // This section is only for adding library classes, this functionality\r
+ // should be inside MsaOwner!!!\r
+ //\r
+ // if (!hashrequiredr9libs.contains(name)) {\r
+ msaowner.addLibraryClass(name, usage);\r
+ // }\r
+ //\r
+ hashrequiredr9libs.add(name);\r
+ return true;\r
+ }\r
+\r
+ // -----------------------------------------------------------------------------------//\r
+\r
+ public final String getModuleType() {\r
+ if (moduletype.contains("PEI")) {\r
+ return "PEIM";\r
+ } else {\r
+ return "DXE_DRIVER";\r
+ }\r
+ }\r
+\r
+ public final void enroll(String filepath) throws Exception {\r
+ String temp = null;\r
+ if (filepath.contains(".inf") || filepath.contains(".msa")) {\r
+ temp = filepath.replace(modulepath + File.separator, "");\r
+ if (!temp.contains(File.separator)) { // .inf in subdirectory is\r
+ // not regarded\r
+ msaorinf.add(temp);\r
+ }\r
+ } else if (filepath.contains(".c") || filepath.contains(".C")\r
+ || filepath.contains(".h") || filepath.contains(".H")\r
+ || filepath.contains(".dxs") || filepath.contains(".uni")\r
+ || filepath.contains(".s") || filepath.contains(".S")\r
+ || filepath.contains(".i") || filepath.contains(".asm")) {\r
+ addSourceFile(filepath.replace(modulepath + File.separator, ""),\r
+ null);\r
+ }\r
+ }\r
+\r
+ public static final boolean isModule(String path) {\r
+ String[] list = new File(path).list();\r
+ for (int i = 0; i < list.length; i++) {\r
+ if (!new File(list[i]).isDirectory()) {\r
+ if (list[i].contains(".inf") || list[i].contains(".msa")) {\r
+ return true;\r
+ }\r
+ }\r
+ }\r
+ return false;\r
+ }\r
+\r
+ public final MsaOwner getMsaOwner() {\r
+ return msaowner;\r
+ }\r
}
\ No newline at end of file
**/\r
package org.tianocore.migration;\r
\r
-import java.io.*;\r
-import java.util.*;\r
-import java.util.regex.*;\r
+import java.io.BufferedReader;\r
+import java.io.File;\r
+import java.io.FileReader;\r
+import java.io.StringReader;\r
+import java.util.Iterator;\r
+import java.util.regex.Matcher;\r
+import java.util.regex.Pattern;\r
\r
-import org.tianocore.*;\r
+import org.tianocore.FilenameDocument;\r
+import org.tianocore.ModuleSurfaceAreaDocument;\r
+import org.tianocore.MsaHeaderDocument;\r
+import org.tianocore.SourceFilesDocument;\r
\r
public final class ModuleReader implements Common.ForDoAll {\r
- private static final ModuleReader modulereader = new ModuleReader();\r
- private ModuleInfo mi;\r
- private final CommentLaplace commentlaplace = new CommentLaplace();\r
- \r
- private static final Pattern ptninfequation = Pattern.compile("([^\\s]*)\\s*=\\s*([^\\s]*)");\r
- private static final Pattern ptnsection = Pattern.compile("\\[([^\\[\\]]*)\\]([^\\[\\]]*)\\n", Pattern.MULTILINE);\r
- private static final Pattern ptnfilename = Pattern.compile("[^\\s]+");\r
-\r
- public final void ModuleScan() throws Exception {\r
- Common.toDoAll(mi.modulepath, ModuleInfo.class.getMethod("enroll", String.class), mi, null, Common.FILE);\r
-\r
- // inf&msa\r
- String filename = null;\r
- if (mi.msaorinf.isEmpty()) {\r
- MigrationTool.ui.println("No INF nor MSA file found!");\r
- System.exit(0);\r
- } else {\r
- if (mi.msaorinf.size() == 1) {\r
- filename = (String)mi.msaorinf.toArray()[0];\r
- } else {\r
- filename = MigrationTool.ui.choose("Found .inf or .msa file for module\n" + mi.modulepath + "\nChoose one Please", mi.msaorinf.toArray());\r
- }\r
- }\r
-\r
- if (filename.contains(".inf")) {\r
- readInf(filename);\r
- } else if (filename.contains(".msa")) {\r
- readMsa(filename);\r
- }\r
- // inf&msa\r
-\r
- preProcessModule();\r
- }\r
- \r
- private final void readMsa(String name) throws Exception {\r
- ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(new File(mi.modulepath + File.separator + name));\r
- ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc.getModuleSurfaceArea();\r
- MsaHeaderDocument.MsaHeader msaheader = msa.getMsaHeader();\r
-\r
- mi.modulename = msaheader.getModuleName();\r
- mi.guidvalue = msaheader.getGuidValue();\r
- mi.moduletype = msaheader.getModuleType().toString(); // ???\r
-\r
- SourceFilesDocument.SourceFiles sourcefiles = msa.getSourceFiles();\r
- \r
- String temp;\r
- Iterator<FilenameDocument.Filename> li = sourcefiles.getFilenameList().iterator();\r
- while (li.hasNext()) {\r
- if (!mi.localmodulesources.contains(temp = li.next().toString())) {\r
- System.out.println("Source File Missing! : " + temp);\r
- }\r
- }\r
- }\r
- private final String extractLicense(String wholeline) throws Exception {\r
- String tempLine;\r
- String license = null;\r
-\r
- BufferedReader rd = new BufferedReader(new StringReader(wholeline));\r
- while ((tempLine = rd.readLine()) != null) {\r
- if (tempLine.contains("#")) {\r
- if (tempLine.contains("Copyright")) {\r
- //\r
- // Find license info.\r
- // \r
- license = "";\r
- while ((tempLine = rd.readLine())!= null) {\r
- if (!tempLine.contains("#") ||\r
- tempLine.contains("Module Name:") ||\r
- tempLine.contains("Abstract:")) {\r
- //\r
- // We assume license ends here.\r
- // \r
- break;\r
- }\r
- license += " " + tempLine.replaceAll("\\s*[#]\\s*(.*)", "$1\n");\r
- }\r
- break;\r
- }\r
- }\r
- }\r
- return license;\r
- }\r
-\r
- private final void readInf(String name) throws Exception {\r
- System.out.println("\nParsing INF file: " + name);\r
- String wholeline;\r
- Matcher mtrinfequation;\r
- Matcher mtrsection;\r
- Matcher mtrfilename;\r
-\r
- wholeline = Common.file2string(mi.modulepath + File.separator + name);\r
- mi.license = extractLicense(wholeline);\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
- 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).contains("nmake.")) {\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
- MigrationTool.ui.println("DPX File Missing! : " + mtrinfequation.group(2));\r
- }\r
- }\r
- }\r
- }\r
- if (mtrsection.group(1).contains("sources.")) {\r
- mtrfilename = ptnfilename.matcher(mtrsection.group(2));\r
- while (mtrfilename.find()) {\r
- mi.infsources.add(mtrfilename.group());\r
- if (!mi.localmodulesources.contains(mtrfilename.group())) {\r
- MigrationTool.ui.println("Warn: Source File Missing! : " + mtrfilename.group());\r
- }\r
- }\r
- }\r
- if (mtrsection.group(1).matches("includes.")) {\r
- mtrfilename = ptnfilename.matcher(mtrsection.group(2));\r
- while (mtrfilename.find()) {\r
- mi.infincludes.add(mtrfilename.group());\r
- }\r
- }\r
- }\r
- }\r
- \r
- private final void preProcessModule() throws Exception {\r
- // according to .inf file, add extraordinary includes and sourcefiles\r
- Common.dirCopy(mi.modulepath, mi.temppath); // collect all Laplace.namechange to here???\r
- \r
- if (!mi.infincludes.isEmpty()) {\r
- Iterator<String> it = mi.infincludes.iterator();\r
- String tempincludename = null;\r
- while (it.hasNext()) {\r
- tempincludename = it.next();\r
- if (tempincludename.contains("..")) {\r
- Matcher mtr = Common.PTNSEPARATER.matcher(tempincludename);\r
- if (mtr.find() && !mtr.group(2).matches(".")) {\r
- Common.oneLevelDirCopy(mi.modulepath.replaceAll(Common.STRSEPARATER, "$1") + File.separator + mtr.group(2), mi.temppath, ".h");\r
- } else {\r
- Common.oneLevelDirCopy(mi.modulepath.replaceAll(Common.STRSEPARATER, "$1"), mi.temppath, ".h");\r
- }\r
- }\r
- }\r
- }\r
- if (!mi.infsources.isEmpty()) {\r
- Iterator<String> it = mi.infsources.iterator();\r
- String tempsourcename = null;\r
- while (it.hasNext()) {\r
- tempsourcename = it.next();\r
- if (tempsourcename.contains("..")) {\r
- Common.ensureDir(mi.temppath + File.separator + "MT_Parent_Sources");\r
- Matcher mtr = Common.PTNSEPARATER.matcher(tempsourcename);\r
- if (mtr.find()) {\r
- Common.fileCopy(mi.modulepath.replaceAll(Common.STRSEPARATER, "$1") + File.separator + mtr.group(2), mi.temppath + File.separator + "MT_Parent_Sources" + File.separator + mtr.group(2));\r
- }\r
- }\r
- }\r
- }\r
-\r
- Common.toDoAll(mi.temppath, this, Common.FILE);\r
- \r
- parsePreProcessedSourceCode();\r
-\r
- }\r
-\r
- private final void parsePreProcessedSourceCode() throws Exception {\r
- BufferedReader rd = null;\r
- String ifile = null;\r
- String line = null;\r
- String temp = null;\r
- \r
- Iterator<String> ii = mi.localmodulesources.iterator();\r
- while (ii.hasNext()) {\r
- temp = ii.next();\r
- if (temp.contains(".c") || temp.contains(".dxs")) {\r
- mi.preprocessedccodes.add(temp);\r
- }\r
- }\r
- \r
- ii = mi.preprocessedccodes.iterator();\r
- \r
- Pattern patefifuncc = Pattern.compile("g?(BS|RT)\\s*->\\s*([a-zA-Z_]\\w*)",Pattern.MULTILINE);\r
- Matcher matguid;\r
- Matcher matfuncc;\r
- Matcher matfuncd;\r
- Matcher matenclosereplace;\r
- Matcher matefifuncc;\r
- Matcher matmacro;\r
- \r
- while (ii.hasNext()) {\r
- StringBuffer wholefile = new StringBuffer();\r
- ifile = ii.next();\r
- rd = new BufferedReader(new FileReader(mi.temppath + File.separator + ifile));\r
- while ((line = rd.readLine()) != null) {\r
- wholefile.append(line + '\n');\r
- }\r
- line = wholefile.toString();\r
- \r
- // find guid\r
- matguid = Guid.ptnguid.matcher(line); // several ways to implement this , which one is faster ? :\r
- while (matguid.find()) { // 1.currently , find once , then call to identify which is it\r
- if ((temp = Guid.register(matguid, mi, MigrationTool.db)) != null) { // 2.use 3 different matchers , search 3 times to find each\r
- //matguid.appendReplacement(result, MigrationTool.db.getR9Guidname(temp)); // search the database for all 3 kinds of guids , high cost\r
- }\r
- }\r
- //matguid.appendTail(result);\r
- //line = result.toString();\r
-\r
- // find EFI call in form of '->' , many 'gUnicodeCollationInterface->' like things are not changed\r
- // This item is not simply replaced , special operation is required.\r
- matefifuncc = patefifuncc.matcher(line);\r
- while (matefifuncc.find()) {\r
- mi.hashEFIcall.add(matefifuncc.group(2));\r
- }\r
-\r
- // find function call\r
- matfuncc = Func.ptnfuncc.matcher(line);\r
- while (matfuncc.find()) {\r
- if ((temp = Func.register(matfuncc, mi, MigrationTool.db)) != null) {\r
- //MigrationTool.ui.println(ifile + " dofunc " + temp);\r
- //matfuncc.appendReplacement(result, MigrationTool.db.getR9Func(temp));\r
- }\r
- }\r
- //matfuncc.appendTail(result);\r
- //line = result.toString();\r
-\r
- // find macro\r
- matmacro = Macro.ptntmacro.matcher(line);\r
- while (matmacro.find()) {\r
- if ((temp = Macro.register(matmacro, mi, MigrationTool.db)) != null) {\r
- }\r
- }\r
- \r
- // find function definition\r
- // replace all {} to @\r
- while ((matenclosereplace = Func.ptnbrace.matcher(line)).find()) {\r
- line = matenclosereplace.replaceAll("@");\r
- }\r
-\r
- matfuncd = Func.ptnfuncd.matcher(line);\r
- while (matfuncd.find()) {\r
- if ((temp = Func.register(matfuncd, mi, MigrationTool.db)) != null) {\r
- }\r
- }\r
- }\r
- \r
- // op on hash\r
- Iterator<String> funcci = mi.hashfuncc.iterator();\r
- while (funcci.hasNext()) {\r
- if (!mi.hashfuncd.contains(temp = funcci.next()) && !mi.hashEFIcall.contains(temp)) {\r
- mi.hashnonlocalfunc.add(temp); // this set contains both changed and not changed items\r
- }\r
- }\r
- }\r
- \r
- public class CommentLaplace extends Common.Laplace {\r
- public String operation(String wholeline) {\r
- StringBuffer wholebuffer = new StringBuffer();\r
- String templine = null;\r
- Pattern ptnincludefile = Pattern.compile("[\"<](.*[.]h)[\">]");\r
- Pattern ptninclude = Pattern.compile("#include\\s*(.*)");\r
- Matcher mtrinclude = ptninclude.matcher(wholeline);\r
- Matcher mtrincludefile = null;\r
- while (mtrinclude.find()) {\r
- mtrincludefile = ptnincludefile.matcher(mtrinclude.group(1));\r
- if (mtrincludefile.find() && mi.localmodulesources.contains(mtrincludefile.group(1))) {\r
- templine = mtrinclude.group();\r
- } else {\r
- templine = MigrationTool.MIGRATIONCOMMENT + mtrinclude.group();\r
- }\r
- mtrinclude.appendReplacement(wholebuffer, templine);\r
- }\r
- mtrinclude.appendTail(wholebuffer);\r
- return wholebuffer.toString();\r
- }\r
- \r
- public boolean recognize(String filename) {\r
- return filename.contains(".c") || filename.contains(".h") || filename.contains(".dxs");\r
- }\r
- \r
- public String namechange(String oldname) {\r
- return oldname;\r
- }\r
- }\r
-\r
- //-----------------------------------ForDoAll-----------------------------------//\r
- public void run(String filepath) throws Exception {\r
- String name = mi.temppath + File.separator + filepath.replace(mi.temppath + File.separator, "");\r
- if (commentlaplace.recognize(name)) {\r
- commentlaplace.transform(name, name);\r
- }\r
- }\r
-\r
- public boolean filter(File dir) {\r
- return true;\r
- }\r
- //-----------------------------------ForDoAll-----------------------------------//\r
- \r
- public final void setModuleInfo(ModuleInfo m) {\r
- mi = m;\r
- }\r
- \r
- public static final void aimAt(ModuleInfo mi) throws Exception {\r
- modulereader.setModuleInfo(mi);\r
- modulereader.ModuleScan();\r
- }\r
+ private static final ModuleReader modulereader = new ModuleReader();\r
+\r
+ private ModuleInfo mi;\r
+\r
+ private final CommentLaplace commentlaplace = new CommentLaplace();\r
+\r
+ private static final Pattern ptninfequation = Pattern\r
+ .compile("([^\\s]*)\\s*=\\s*([^\\s]*)");\r
+\r
+ private static final Pattern ptnsection = Pattern.compile(\r
+ "\\[([^\\[\\]]*)\\]([^\\[\\]]*)\\n", Pattern.MULTILINE);\r
+\r
+ private static final Pattern ptnfilename = Pattern.compile("[^\\s]+");\r
+\r
+ public final void ModuleScan() throws Exception {\r
+ Common.toDoAll(mi.modulepath, ModuleInfo.class.getMethod("enroll",\r
+ String.class), mi, null, Common.FILE);\r
+\r
+ // inf&msa\r
+ String filename = null;\r
+ if (mi.msaorinf.isEmpty()) {\r
+ MigrationTool.ui.println("No INF nor MSA file found!");\r
+ System.exit(0);\r
+ } else {\r
+ if (mi.msaorinf.size() == 1) {\r
+ filename = (String) mi.msaorinf.toArray()[0];\r
+ } else {\r
+ filename = MigrationTool.ui.choose(\r
+ "Found .inf or .msa file for module\n" + mi.modulepath\r
+ + "\nChoose one Please", mi.msaorinf.toArray());\r
+ }\r
+ }\r
+\r
+ if (filename.contains(".inf")) {\r
+ readInf(filename);\r
+ } else if (filename.contains(".msa")) {\r
+ readMsa(filename);\r
+ }\r
+ // inf&msa\r
+\r
+ preProcessModule();\r
+ }\r
+\r
+ private final void readMsa(String name) throws Exception {\r
+ ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory\r
+ .parse(new File(mi.modulepath + File.separator + name));\r
+ ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc\r
+ .getModuleSurfaceArea();\r
+ MsaHeaderDocument.MsaHeader msaheader = msa.getMsaHeader();\r
+\r
+ mi.modulename = msaheader.getModuleName();\r
+ mi.guidvalue = msaheader.getGuidValue();\r
+ mi.moduletype = msaheader.getModuleType().toString(); // ???\r
+\r
+ SourceFilesDocument.SourceFiles sourcefiles = msa.getSourceFiles();\r
+\r
+ String temp;\r
+ Iterator<FilenameDocument.Filename> li = sourcefiles.getFilenameList()\r
+ .iterator();\r
+ while (li.hasNext()) {\r
+ if (!mi.localmodulesources.contains(temp = li.next().toString())) {\r
+ System.out.println("Source File Missing! : " + temp);\r
+ }\r
+ }\r
+ }\r
+\r
+ private final String extractLicense(String wholeline) throws Exception {\r
+ String tempLine;\r
+ String license = null;\r
+\r
+ BufferedReader rd = new BufferedReader(new StringReader(wholeline));\r
+ while ((tempLine = rd.readLine()) != null) {\r
+ if (tempLine.contains("#")) {\r
+ if (tempLine.contains("Copyright")) {\r
+ //\r
+ // Find license info.\r
+ // \r
+ license = "";\r
+ while ((tempLine = rd.readLine()) != null) {\r
+ if (!tempLine.contains("#")\r
+ || tempLine.contains("Module Name:")\r
+ || tempLine.contains("Abstract:")) {\r
+ //\r
+ // We assume license ends here.\r
+ // \r
+ break;\r
+ }\r
+ license += " "\r
+ + tempLine\r
+ .replaceAll("\\s*[#]\\s*(.*)", "$1\n");\r
+ }\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ return license;\r
+ }\r
+\r
+ private final void readInf(String name) throws Exception {\r
+ System.out.println("\nParsing INF file: " + name);\r
+ String wholeline;\r
+ Matcher mtrinfequation;\r
+ Matcher mtrsection;\r
+ Matcher mtrfilename;\r
+\r
+ wholeline = Common.file2string(mi.modulepath + File.separator + name);\r
+ mi.license = extractLicense(wholeline);\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
+ 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).contains("nmake.")) {\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\r
+ .group(2))) {\r
+ MigrationTool.ui.println("DPX File Missing! : "\r
+ + mtrinfequation.group(2));\r
+ }\r
+ }\r
+ }\r
+ }\r
+ if (mtrsection.group(1).contains("sources.")) {\r
+ mtrfilename = ptnfilename.matcher(mtrsection.group(2));\r
+ while (mtrfilename.find()) {\r
+ mi.infsources.add(mtrfilename.group());\r
+ if (!mi.localmodulesources.contains(mtrfilename.group())) {\r
+ MigrationTool.ui\r
+ .println("Warn: Source File Missing! : "\r
+ + mtrfilename.group());\r
+ }\r
+ }\r
+ }\r
+ if (mtrsection.group(1).matches("includes.")) {\r
+ mtrfilename = ptnfilename.matcher(mtrsection.group(2));\r
+ while (mtrfilename.find()) {\r
+ mi.infincludes.add(mtrfilename.group());\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ private final void preProcessModule() throws Exception {\r
+ // according to .inf file, add extraordinary includes and sourcefiles\r
+ Common.dirCopy(mi.modulepath, mi.temppath); // collect all\r
+ // Laplace.namechange to\r
+ // here???\r
+\r
+ if (!mi.infincludes.isEmpty()) {\r
+ Iterator<String> it = mi.infincludes.iterator();\r
+ String tempincludename = null;\r
+ while (it.hasNext()) {\r
+ tempincludename = it.next();\r
+ if (tempincludename.contains("..")) {\r
+ Matcher mtr = Common.PTNSEPARATER.matcher(tempincludename);\r
+ if (mtr.find() && !mtr.group(2).matches(".")) {\r
+ Common.oneLevelDirCopy(mi.modulepath.replaceAll(\r
+ Common.STRSEPARATER, "$1")\r
+ + File.separator + mtr.group(2), mi.temppath,\r
+ ".h");\r
+ } else {\r
+ Common.oneLevelDirCopy(mi.modulepath.replaceAll(\r
+ Common.STRSEPARATER, "$1"), mi.temppath, ".h");\r
+ }\r
+ }\r
+ }\r
+ }\r
+ if (!mi.infsources.isEmpty()) {\r
+ Iterator<String> it = mi.infsources.iterator();\r
+ String tempsourcename = null;\r
+ while (it.hasNext()) {\r
+ tempsourcename = it.next();\r
+ if (tempsourcename.contains("..")) {\r
+ Common.ensureDir(mi.temppath + File.separator\r
+ + "MT_Parent_Sources");\r
+ Matcher mtr = Common.PTNSEPARATER.matcher(tempsourcename);\r
+ if (mtr.find()) {\r
+ Common.fileCopy(mi.modulepath.replaceAll(\r
+ Common.STRSEPARATER, "$1")\r
+ + File.separator + mtr.group(2), mi.temppath\r
+ + File.separator + "MT_Parent_Sources"\r
+ + File.separator + mtr.group(2));\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ Common.toDoAll(mi.temppath, this, Common.FILE);\r
+\r
+ parsePreProcessedSourceCode();\r
+\r
+ }\r
+\r
+ private final void parsePreProcessedSourceCode() throws Exception {\r
+ BufferedReader rd = null;\r
+ String ifile = null;\r
+ String line = null;\r
+ String temp = null;\r
+\r
+ Iterator<String> ii = mi.localmodulesources.iterator();\r
+ while (ii.hasNext()) {\r
+ temp = ii.next();\r
+ if (temp.contains(".c") || temp.contains(".dxs")) {\r
+ mi.preprocessedccodes.add(temp);\r
+ }\r
+ }\r
+\r
+ ii = mi.preprocessedccodes.iterator();\r
+\r
+ Pattern patefifuncc = Pattern.compile(\r
+ "g?(BS|RT)\\s*->\\s*([a-zA-Z_]\\w*)", Pattern.MULTILINE);\r
+ Matcher matguid;\r
+ Matcher matfuncc;\r
+ Matcher matfuncd;\r
+ Matcher matenclosereplace;\r
+ Matcher matefifuncc;\r
+ Matcher matmacro;\r
+\r
+ while (ii.hasNext()) {\r
+ StringBuffer wholefile = new StringBuffer();\r
+ ifile = ii.next();\r
+ rd = new BufferedReader(new FileReader(mi.temppath + File.separator\r
+ + ifile));\r
+ while ((line = rd.readLine()) != null) {\r
+ wholefile.append(line + '\n');\r
+ }\r
+ line = wholefile.toString();\r
+\r
+ // find guid\r
+ matguid = Guid.ptnguid.matcher(line); // several ways to implement\r
+ // this , which one is\r
+ // faster ? :\r
+ while (matguid.find()) { // 1.currently , find once , then call\r
+ // to identify which is it\r
+ if ((temp = Guid.register(matguid, mi, MigrationTool.db)) != null) { // 2.use\r
+ // 3\r
+ // different\r
+ // matchers\r
+ // ,\r
+ // search\r
+ // 3\r
+ // times\r
+ // to\r
+ // find\r
+ // each\r
+ // matguid.appendReplacement(result,\r
+ // MigrationTool.db.getR9Guidname(temp)); // search the\r
+ // database for all 3 kinds of guids , high cost\r
+ }\r
+ }\r
+ // matguid.appendTail(result);\r
+ // line = result.toString();\r
+\r
+ // find EFI call in form of '->' , many\r
+ // 'gUnicodeCollationInterface->' like things are not changed\r
+ // This item is not simply replaced , special operation is required.\r
+ matefifuncc = patefifuncc.matcher(line);\r
+ while (matefifuncc.find()) {\r
+ mi.hashEFIcall.add(matefifuncc.group(2));\r
+ }\r
+\r
+ // find function call\r
+ matfuncc = Func.ptnfuncc.matcher(line);\r
+ while (matfuncc.find()) {\r
+ if ((temp = Func.register(matfuncc, mi, MigrationTool.db)) != null) {\r
+ // MigrationTool.ui.println(ifile + " dofunc " + temp);\r
+ // matfuncc.appendReplacement(result,\r
+ // MigrationTool.db.getR9Func(temp));\r
+ }\r
+ }\r
+ // matfuncc.appendTail(result);\r
+ // line = result.toString();\r
+\r
+ // find macro\r
+ matmacro = Macro.ptntmacro.matcher(line);\r
+ while (matmacro.find()) {\r
+ if ((temp = Macro.register(matmacro, mi, MigrationTool.db)) != null) {\r
+ }\r
+ }\r
+\r
+ // find function definition\r
+ // replace all {} to @\r
+ while ((matenclosereplace = Func.ptnbrace.matcher(line)).find()) {\r
+ line = matenclosereplace.replaceAll("@");\r
+ }\r
+\r
+ matfuncd = Func.ptnfuncd.matcher(line);\r
+ while (matfuncd.find()) {\r
+ if ((temp = Func.register(matfuncd, mi, MigrationTool.db)) != null) {\r
+ }\r
+ }\r
+ }\r
+\r
+ // op on hash\r
+ Iterator<String> funcci = mi.hashfuncc.iterator();\r
+ while (funcci.hasNext()) {\r
+ if (!mi.hashfuncd.contains(temp = funcci.next())\r
+ && !mi.hashEFIcall.contains(temp)) {\r
+ mi.hashnonlocalfunc.add(temp); // this set contains both\r
+ // changed and not changed items\r
+ }\r
+ }\r
+ }\r
+\r
+ public class CommentLaplace extends Common.Laplace {\r
+ public String operation(String wholeline) {\r
+ StringBuffer wholebuffer = new StringBuffer();\r
+ String templine = null;\r
+ Pattern ptnincludefile = Pattern.compile("[\"<](.*[.]h)[\">]");\r
+ Pattern ptninclude = Pattern.compile("#include\\s*(.*)");\r
+ Matcher mtrinclude = ptninclude.matcher(wholeline);\r
+ Matcher mtrincludefile = null;\r
+ while (mtrinclude.find()) {\r
+ mtrincludefile = ptnincludefile.matcher(mtrinclude.group(1));\r
+ if (mtrincludefile.find()\r
+ && mi.localmodulesources.contains(mtrincludefile\r
+ .group(1))) {\r
+ templine = mtrinclude.group();\r
+ } else {\r
+ templine = MigrationTool.MIGRATIONCOMMENT\r
+ + mtrinclude.group();\r
+ }\r
+ mtrinclude.appendReplacement(wholebuffer, templine);\r
+ }\r
+ mtrinclude.appendTail(wholebuffer);\r
+ return wholebuffer.toString();\r
+ }\r
+\r
+ public boolean recognize(String filename) {\r
+ return filename.contains(".c") || filename.contains(".h")\r
+ || filename.contains(".dxs");\r
+ }\r
+\r
+ public String namechange(String oldname) {\r
+ return oldname;\r
+ }\r
+ }\r
+\r
+ // -----------------------------------ForDoAll-----------------------------------//\r
+ public void run(String filepath) throws Exception {\r
+ String name = mi.temppath + File.separator\r
+ + filepath.replace(mi.temppath + File.separator, "");\r
+ if (commentlaplace.recognize(name)) {\r
+ commentlaplace.transform(name, name);\r
+ }\r
+ }\r
+\r
+ public boolean filter(File dir) {\r
+ return true;\r
+ }\r
+\r
+ // -----------------------------------ForDoAll-----------------------------------//\r
+\r
+ public final void setModuleInfo(ModuleInfo m) {\r
+ mi = m;\r
+ }\r
+\r
+ public static final void aimAt(ModuleInfo mi) throws Exception {\r
+ modulereader.setModuleInfo(mi);\r
+ modulereader.ModuleScan();\r
+ }\r
}\r
\r
import java.io.BufferedWriter;\r
import java.io.FileWriter;\r
-import java.util.*;\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
+import java.util.List;\r
\r
import org.apache.xmlbeans.XmlOptions;\r
-import org.tianocore.*;\r
+import org.tianocore.ExternsDocument;\r
+import org.tianocore.FilenameDocument;\r
+import org.tianocore.GuidsDocument;\r
+import org.tianocore.LibraryClassDefinitionsDocument;\r
+import org.tianocore.LibraryClassDocument;\r
+import org.tianocore.LicenseDocument;\r
+import org.tianocore.ModuleDefinitionsDocument;\r
+import org.tianocore.ModuleSurfaceAreaDocument;\r
+import org.tianocore.ModuleTypeDef;\r
+import org.tianocore.MsaHeaderDocument;\r
+import org.tianocore.PPIsDocument;\r
+import org.tianocore.PackageDependenciesDocument;\r
+import org.tianocore.ProtocolsDocument;\r
+import org.tianocore.SourceFilesDocument;\r
+import org.tianocore.SupportedArchitectures;\r
+import org.tianocore.UsageTypes;\r
import org.tianocore.SupportedArchitectures.Enum;\r
\r
public class MsaOwner {\r
- public static final String COPYRIGHT = "Copyright (c) 2006, Intel Corporation";\r
- public static final String VERSION = "1.0";\r
- public static final String ABSTRACT = "Component name for module ";\r
- public static final String DESCRIPTION = "FIX ME!";\r
- public static final String LICENSE = "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
- " with the terms of the license. Except as permitted by such\n" +\r
- " license, no part of this software or documentation may be\n" +\r
- " reproduced, stored in a retrieval system, or transmitted in any\n" +\r
- " form or by any means without the express written consent of\n" +\r
- " Intel Corporation.";\r
- public static final String SPECIFICATION = "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";\r
- \r
- public static final Enum IA32 = SupportedArchitectures.IA_32;\r
- public static final Enum X64 = SupportedArchitectures.X_64;\r
- public static final Enum IPF = SupportedArchitectures.IPF;\r
- public static final Enum EBC = SupportedArchitectures.EBC;\r
- \r
- private ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.newInstance();\r
- \r
- private ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = null;\r
- private MsaHeaderDocument.MsaHeader msaheader = null;\r
- private LicenseDocument.License license = null;\r
- private ModuleDefinitionsDocument.ModuleDefinitions moduledefinitions = null;\r
- private SourceFilesDocument.SourceFiles sourcefiles = null; //found local .h files are not written\r
- private GuidsDocument.Guids guids = null;\r
- private ProtocolsDocument.Protocols protocols = null;\r
- private PPIsDocument.PPIs ppis = null;\r
- private PackageDependenciesDocument.PackageDependencies packagedependencies = null;\r
- private LibraryClassDefinitionsDocument.LibraryClassDefinitions libclassdefs = null;\r
- private ExternsDocument.Externs externs = null;\r
- \r
- private List<Enum> listarch = new ArrayList<Enum>();\r
- //private Map<String, Enum> mapfilenames = new HashMap<String, Enum>(); //this need to be installed manually when msa is to be written\r
- //private Map<String, UsageTypes.Enum> mapprotocols = new HashMap<String, UsageTypes.Enum>();\r
-\r
- //-----------------------------msaheader-------------------------------------//\r
-\r
- public final boolean addLibraryClass (String name, UsageTypes.Enum usage) {\r
- /*\r
- if (!libclassdefs.getLibraryClassList().contains(name)) {\r
- LibraryClassDocument.LibraryClass classname;\r
- classname = libclassdefs.addNewLibraryClass();\r
- classname.setKeyword(name);\r
- classname.setUsage(usage);\r
- return true;\r
- } else {\r
- return false;\r
- }\r
- */\r
- if (name == null) {\r
- return false;\r
- } else {\r
- Iterator<LibraryClassDocument.LibraryClass> classit = libclassdefs.getLibraryClassList().iterator();\r
- while (classit.hasNext()) {\r
- if (classit.next().getKeyword().matches(name)) {\r
- //MigrationTool.ui.println ("Warning: Duplicate LibraryClass");\r
- return false;\r
- }\r
- }\r
- \r
- LibraryClassDocument.LibraryClass classname;\r
- classname = libclassdefs.addNewLibraryClass();\r
- classname.setKeyword(name);\r
- classname.setUsage(usage);\r
- return true;\r
- \r
- }\r
- }\r
- \r
- public final boolean addGuid (String guidname, UsageTypes.Enum usage) {\r
- if (guids == null) {\r
- guids = msa.addNewGuids();\r
- }\r
- \r
- Iterator<GuidsDocument.Guids.GuidCNames> guidit = guids.getGuidCNamesList().iterator();\r
- while (guidit.hasNext()) {\r
- if (guidit.next().getGuidCName() == guidname) {\r
- //MigrationTool.ui.println ("Warning: Duplicate Guid");\r
- return false;\r
- }\r
- }\r
- \r
- GuidsDocument.Guids.GuidCNames guid;\r
- guid = guids.addNewGuidCNames();\r
- guid.setGuidCName(guidname);\r
- guid.setUsage(usage);\r
- return true;\r
- }\r
- \r
- \r
- public final boolean addPpi (String ppiname, UsageTypes.Enum usage) {\r
- if (ppis == null) {\r
- ppis = msa.addNewPPIs();\r
- }\r
- \r
- Iterator<PPIsDocument.PPIs.Ppi> ppiit = ppis.getPpiList().iterator();\r
- while (ppiit.hasNext()) {\r
- if (ppiit.next().getPpiCName() == ppiname) {\r
- //MigrationTool.ui.println ("Warning: Duplicate Ppi");\r
- return false;\r
- }\r
- }\r
- \r
- PPIsDocument.PPIs.Ppi ppi;\r
- ppi = ppis.addNewPpi();\r
- ppi.setPpiCName(ppiname);\r
- ppi.setUsage(usage);\r
- return true;\r
- }\r
- \r
- public final boolean addProtocol (String proname, UsageTypes.Enum usage) {\r
- if (protocols == null) {\r
- protocols = msa.addNewProtocols();\r
- }\r
-\r
- Iterator<ProtocolsDocument.Protocols.Protocol> proit = protocols.getProtocolList().iterator();\r
- while (proit.hasNext()) {\r
- if (proit.next().getProtocolCName() == proname) {\r
- //MigrationTool.ui.println ("Warning: Duplicate Protocol");\r
- return false;\r
- }\r
- }\r
-\r
- ProtocolsDocument.Protocols.Protocol protocol;\r
- protocol = protocols.addNewProtocol();\r
- protocol.setProtocolCName(proname);\r
- protocol.setUsage(usage);\r
- return true;\r
- }\r
- \r
- public final boolean addSourceFile (String name, Enum en) {\r
- Iterator<FilenameDocument.Filename> fileit = sourcefiles.getFilenameList().iterator();\r
- while (fileit.hasNext()) {\r
- if (fileit.next().getStringValue() == name) {\r
- MigrationTool.ui.println ("Warning: Duplicate SourceFileName");\r
- return false;\r
- }\r
- }\r
- \r
- FilenameDocument.Filename filename;\r
- List<Enum> arch = new ArrayList<Enum>();\r
- filename = sourcefiles.addNewFilename();\r
- filename.setStringValue(name);\r
- arch.add(en);\r
- filename.setSupArchList(arch);\r
- return true;\r
- }\r
- \r
- // entry point todo\r
- \r
- public final boolean setupExternSpecification () {\r
- addExternSpecification("EFI_SPECIFICATION_VERSION 0x00020000");\r
- addExternSpecification("EDK_RELEASE_VERSION 0x00020000");\r
- return true;\r
- }\r
- \r
- public final boolean addExternSpecification (String specification) {\r
- if (externs.getSpecificationList().contains(specification)) {\r
- return false;\r
- } else {\r
- externs.addSpecification(specification);\r
- return true;\r
- }\r
- }\r
- \r
- public final boolean setupPackageDependencies() {\r
- Iterator<String> it;\r
- //\r
- // For now, simply add all package guids in the database. \r
- // \r
- it = MigrationTool.db.dumpAllPkgGuid();\r
- while (it.hasNext()) {\r
- packagedependencies.addNewPackage().setPackageGuid(it.next());\r
- }\r
- return true;\r
- }\r
- \r
- public final boolean addPackage (String guid) {\r
- if (packagedependencies.getPackageList().contains(guid)) {\r
- return false;\r
- } else {\r
- packagedependencies.addNewPackage().setPackageGuid(guid);\r
- return true;\r
- }\r
- }\r
- \r
- public final boolean setupModuleDefinitions () { //????????? give this job to moduleinfo\r
- moduledefinitions.setBinaryModule(false);\r
- moduledefinitions.setOutputFileBasename(msaheader.getModuleName());\r
- return true;\r
- }\r
- public final boolean addSupportedArchitectures (Enum arch) {\r
- if (listarch.contains(arch)) {\r
- return false;\r
- } else {\r
- listarch.add(arch);\r
- return true;\r
- }\r
- }\r
- \r
- public final boolean addSpecification (String specification) {\r
- if (msaheader.getSpecification() == null) {\r
- if (specification == null) {\r
- msaheader.setSpecification(SPECIFICATION);\r
- } else {\r
- msaheader.setSpecification(specification);\r
- }\r
- return true;\r
- } else {\r
- MigrationTool.ui.println ("Warning: Duplicate Specification");\r
- return false;\r
- }\r
- }\r
- \r
- public final boolean addLicense (String licensecontent) {\r
- if (msaheader.getLicense() == null) {\r
- license = msaheader.addNewLicense();\r
- if (licensecontent == null) {\r
- license.setStringValue(LICENSE);\r
- } else {\r
- license.setStringValue(licensecontent);\r
- }\r
- return true;\r
- } else {\r
- MigrationTool.ui.println ("Warning: Duplicate License");\r
- return false;\r
- }\r
- }\r
- \r
- public final boolean addDescription (String description) {\r
- if (msaheader.getDescription() == null) {\r
- if (description == null) {\r
- msaheader.setDescription(DESCRIPTION);\r
- } else {\r
- msaheader.setDescription(description);\r
- }\r
- return true;\r
- } else {\r
- MigrationTool.ui.println ("Warning: Duplicate Description");\r
- return false;\r
- }\r
- }\r
- \r
- public final boolean addAbstract (String abs) {\r
- if (msaheader.getAbstract() == null) {\r
- if (abs == null) {\r
- msaheader.setAbstract(ABSTRACT + msaheader.getModuleName());\r
- } else {\r
- msaheader.setVersion(abs);\r
- }\r
- return true;\r
- } else {\r
- MigrationTool.ui.println ("Warning: Duplicate Abstract");\r
- return false;\r
- }\r
- }\r
- \r
- public final boolean addVersion (String version) {\r
- if (msaheader.getVersion() == null) {\r
- if (version == null) {\r
- msaheader.setVersion(VERSION);\r
- } else {\r
- msaheader.setVersion(version);\r
- }\r
- return true;\r
- } else {\r
- MigrationTool.ui.println ("Warning: Duplicate Version");\r
- return false;\r
- }\r
- }\r
- \r
- public final boolean addCopyRight (String copyright) {\r
- if (msaheader.getCopyright() == null) {\r
- if (copyright == null) {\r
- msaheader.setCopyright(COPYRIGHT);\r
- } else {\r
- msaheader.setCopyright(copyright);\r
- }\r
- return true;\r
- } else {\r
- MigrationTool.ui.println ("Warning: Duplicate CopyRight");\r
- return false;\r
- }\r
- }\r
- \r
- public final boolean addModuleType (String moduletype) {\r
- if (msaheader.getModuleType() == null) {\r
- msaheader.setModuleType(ModuleTypeDef.Enum.forString(moduletype));\r
- return true;\r
- } else {\r
- MigrationTool.ui.println ("Warning: Duplicate ModuleType");\r
- return false;\r
- }\r
- }\r
- \r
- public final boolean addGuidValue (String guidvalue) {\r
- if (msaheader.getGuidValue() == null) {\r
- msaheader.setGuidValue(guidvalue);\r
- return true;\r
- } else {\r
- MigrationTool.ui.println ("Warning: Duplicate GuidValue");\r
- return false;\r
- }\r
- }\r
- \r
- public final boolean addModuleName (String modulename) {\r
- if (msaheader.getModuleName() == null) {\r
- msaheader.setModuleName(modulename);\r
- return true;\r
- } else {\r
- MigrationTool.ui.println ("Warning: Duplicate ModuleName");\r
- return false;\r
- }\r
- }\r
- //-----------------------------msaheader-------------------------------------//\r
- \r
- private final void fullfill () throws Exception {\r
- addCopyRight(null);\r
- addVersion(null);\r
- addAbstract(null);\r
- addDescription(null);\r
- addLicense(null);\r
- addSpecification(null);\r
- }\r
- \r
- public final void flush(String outputpath) throws Exception {\r
- XmlOptions options = new XmlOptions();\r
-\r
- options.setCharacterEncoding("UTF-8");\r
- options.setSavePrettyPrint();\r
- options.setSavePrettyPrintIndent(2);\r
- options.setUseDefaultNamespace();\r
- \r
- BufferedWriter bw = new BufferedWriter(new FileWriter(outputpath));\r
- fullfill();\r
- msadoc.save(bw, options);\r
- bw.flush();\r
- bw.close();\r
- }\r
- \r
- private final MsaOwner init () {\r
- msa = msadoc.addNewModuleSurfaceArea();\r
- msaheader = msa.addNewMsaHeader();\r
- moduledefinitions = msa.addNewModuleDefinitions();\r
- moduledefinitions.setSupportedArchitectures(listarch);\r
- \r
- sourcefiles = msa.addNewSourceFiles();\r
- packagedependencies = msa.addNewPackageDependencies();\r
- libclassdefs = msa.addNewLibraryClassDefinitions();\r
- externs = msa.addNewExterns();\r
- return this;\r
- }\r
- \r
- public static final MsaOwner initNewMsaOwner() {\r
- return new MsaOwner().init();\r
- }\r
+ public static final String COPYRIGHT = "Copyright (c) 2006, Intel Corporation";\r
+\r
+ public static final String VERSION = "1.0";\r
+\r
+ public static final String ABSTRACT = "Component name for module ";\r
+\r
+ public static final String DESCRIPTION = "FIX ME!";\r
+\r
+ public static final String LICENSE = "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
+ + " with the terms of the license. Except as permitted by such\n"\r
+ + " license, no part of this software or documentation may be\n"\r
+ + " reproduced, stored in a retrieval system, or transmitted in any\n"\r
+ + " form or by any means without the express written consent of\n"\r
+ + " Intel Corporation.";\r
+\r
+ public static final String SPECIFICATION = "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";\r
+\r
+ public static final Enum IA32 = SupportedArchitectures.IA_32;\r
+\r
+ public static final Enum X64 = SupportedArchitectures.X_64;\r
+\r
+ public static final Enum IPF = SupportedArchitectures.IPF;\r
+\r
+ public static final Enum EBC = SupportedArchitectures.EBC;\r
+\r
+ private ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory\r
+ .newInstance();\r
+\r
+ private ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = null;\r
+\r
+ private MsaHeaderDocument.MsaHeader msaheader = null;\r
+\r
+ private LicenseDocument.License license = null;\r
+\r
+ private ModuleDefinitionsDocument.ModuleDefinitions moduledefinitions = null;\r
+\r
+ private SourceFilesDocument.SourceFiles sourcefiles = null; // found local\r
+ // .h files are\r
+ // not written\r
+\r
+ private GuidsDocument.Guids guids = null;\r
+\r
+ private ProtocolsDocument.Protocols protocols = null;\r
+\r
+ private PPIsDocument.PPIs ppis = null;\r
+\r
+ private PackageDependenciesDocument.PackageDependencies packagedependencies = null;\r
+\r
+ private LibraryClassDefinitionsDocument.LibraryClassDefinitions libclassdefs = null;\r
+\r
+ private ExternsDocument.Externs externs = null;\r
+\r
+ private List<Enum> listarch = new ArrayList<Enum>();\r
+\r
+ // private Map<String, Enum> mapfilenames = new HashMap<String, Enum>();\r
+ // //this need to be installed manually when msa is to be written\r
+ // private Map<String, UsageTypes.Enum> mapprotocols = new HashMap<String,\r
+ // UsageTypes.Enum>();\r
+\r
+ // -----------------------------msaheader-------------------------------------//\r
+\r
+ public final boolean addLibraryClass(String name, UsageTypes.Enum usage) {\r
+ /*\r
+ * if (!libclassdefs.getLibraryClassList().contains(name)) {\r
+ * LibraryClassDocument.LibraryClass classname; classname =\r
+ * libclassdefs.addNewLibraryClass(); classname.setKeyword(name);\r
+ * classname.setUsage(usage); return true; } else { return false; }\r
+ */\r
+ if (name == null) {\r
+ return false;\r
+ } else {\r
+ Iterator<LibraryClassDocument.LibraryClass> classit = libclassdefs\r
+ .getLibraryClassList().iterator();\r
+ while (classit.hasNext()) {\r
+ if (classit.next().getKeyword().matches(name)) {\r
+ // MigrationTool.ui.println ("Warning: Duplicate\r
+ // LibraryClass");\r
+ return false;\r
+ }\r
+ }\r
+\r
+ LibraryClassDocument.LibraryClass classname;\r
+ classname = libclassdefs.addNewLibraryClass();\r
+ classname.setKeyword(name);\r
+ classname.setUsage(usage);\r
+ return true;\r
+\r
+ }\r
+ }\r
+\r
+ public final boolean addGuid(String guidname, UsageTypes.Enum usage) {\r
+ if (guids == null) {\r
+ guids = msa.addNewGuids();\r
+ }\r
+\r
+ Iterator<GuidsDocument.Guids.GuidCNames> guidit = guids\r
+ .getGuidCNamesList().iterator();\r
+ while (guidit.hasNext()) {\r
+ if (guidit.next().getGuidCName() == guidname) {\r
+ // MigrationTool.ui.println ("Warning: Duplicate Guid");\r
+ return false;\r
+ }\r
+ }\r
+\r
+ GuidsDocument.Guids.GuidCNames guid;\r
+ guid = guids.addNewGuidCNames();\r
+ guid.setGuidCName(guidname);\r
+ guid.setUsage(usage);\r
+ return true;\r
+ }\r
+\r
+ public final boolean addPpi(String ppiname, UsageTypes.Enum usage) {\r
+ if (ppis == null) {\r
+ ppis = msa.addNewPPIs();\r
+ }\r
+\r
+ Iterator<PPIsDocument.PPIs.Ppi> ppiit = ppis.getPpiList().iterator();\r
+ while (ppiit.hasNext()) {\r
+ if (ppiit.next().getPpiCName() == ppiname) {\r
+ // MigrationTool.ui.println ("Warning: Duplicate Ppi");\r
+ return false;\r
+ }\r
+ }\r
+\r
+ PPIsDocument.PPIs.Ppi ppi;\r
+ ppi = ppis.addNewPpi();\r
+ ppi.setPpiCName(ppiname);\r
+ ppi.setUsage(usage);\r
+ return true;\r
+ }\r
+\r
+ public final boolean addProtocol(String proname, UsageTypes.Enum usage) {\r
+ if (protocols == null) {\r
+ protocols = msa.addNewProtocols();\r
+ }\r
+\r
+ Iterator<ProtocolsDocument.Protocols.Protocol> proit = protocols\r
+ .getProtocolList().iterator();\r
+ while (proit.hasNext()) {\r
+ if (proit.next().getProtocolCName() == proname) {\r
+ // MigrationTool.ui.println ("Warning: Duplicate Protocol");\r
+ return false;\r
+ }\r
+ }\r
+\r
+ ProtocolsDocument.Protocols.Protocol protocol;\r
+ protocol = protocols.addNewProtocol();\r
+ protocol.setProtocolCName(proname);\r
+ protocol.setUsage(usage);\r
+ return true;\r
+ }\r
+\r
+ public final boolean addSourceFile(String name, Enum en) {\r
+ Iterator<FilenameDocument.Filename> fileit = sourcefiles\r
+ .getFilenameList().iterator();\r
+ while (fileit.hasNext()) {\r
+ if (fileit.next().getStringValue() == name) {\r
+ MigrationTool.ui.println("Warning: Duplicate SourceFileName");\r
+ return false;\r
+ }\r
+ }\r
+\r
+ FilenameDocument.Filename filename;\r
+ List<Enum> arch = new ArrayList<Enum>();\r
+ filename = sourcefiles.addNewFilename();\r
+ filename.setStringValue(name);\r
+ arch.add(en);\r
+ filename.setSupArchList(arch);\r
+ return true;\r
+ }\r
+\r
+ // entry point todo\r
+\r
+ public final boolean setupExternSpecification() {\r
+ addExternSpecification("EFI_SPECIFICATION_VERSION 0x00020000");\r
+ addExternSpecification("EDK_RELEASE_VERSION 0x00020000");\r
+ return true;\r
+ }\r
+\r
+ public final boolean addExternSpecification(String specification) {\r
+ if (externs.getSpecificationList().contains(specification)) {\r
+ return false;\r
+ } else {\r
+ externs.addSpecification(specification);\r
+ return true;\r
+ }\r
+ }\r
+\r
+ public final boolean setupPackageDependencies() {\r
+ Iterator<String> it;\r
+ //\r
+ // For now, simply add all package guids in the database.\r
+ // \r
+ it = MigrationTool.db.dumpAllPkgGuid();\r
+ while (it.hasNext()) {\r
+ packagedependencies.addNewPackage().setPackageGuid(it.next());\r
+ }\r
+ return true;\r
+ }\r
+\r
+ public final boolean addPackage(String guid) {\r
+ if (packagedependencies.getPackageList().contains(guid)) {\r
+ return false;\r
+ } else {\r
+ packagedependencies.addNewPackage().setPackageGuid(guid);\r
+ return true;\r
+ }\r
+ }\r
+\r
+ public final boolean setupModuleDefinitions() { // ????????? give this job\r
+ // to moduleinfo\r
+ moduledefinitions.setBinaryModule(false);\r
+ moduledefinitions.setOutputFileBasename(msaheader.getModuleName());\r
+ return true;\r
+ }\r
+\r
+ public final boolean addSupportedArchitectures(Enum arch) {\r
+ if (listarch.contains(arch)) {\r
+ return false;\r
+ } else {\r
+ listarch.add(arch);\r
+ return true;\r
+ }\r
+ }\r
+\r
+ public final boolean addSpecification(String specification) {\r
+ if (msaheader.getSpecification() == null) {\r
+ if (specification == null) {\r
+ msaheader.setSpecification(SPECIFICATION);\r
+ } else {\r
+ msaheader.setSpecification(specification);\r
+ }\r
+ return true;\r
+ } else {\r
+ MigrationTool.ui.println("Warning: Duplicate Specification");\r
+ return false;\r
+ }\r
+ }\r
+\r
+ public final boolean addLicense(String licensecontent) {\r
+ if (msaheader.getLicense() == null) {\r
+ license = msaheader.addNewLicense();\r
+ if (licensecontent == null) {\r
+ license.setStringValue(LICENSE);\r
+ } else {\r
+ license.setStringValue(licensecontent);\r
+ }\r
+ return true;\r
+ } else {\r
+ MigrationTool.ui.println("Warning: Duplicate License");\r
+ return false;\r
+ }\r
+ }\r
+\r
+ public final boolean addDescription(String description) {\r
+ if (msaheader.getDescription() == null) {\r
+ if (description == null) {\r
+ msaheader.setDescription(DESCRIPTION);\r
+ } else {\r
+ msaheader.setDescription(description);\r
+ }\r
+ return true;\r
+ } else {\r
+ MigrationTool.ui.println("Warning: Duplicate Description");\r
+ return false;\r
+ }\r
+ }\r
+\r
+ public final boolean addAbstract(String abs) {\r
+ if (msaheader.getAbstract() == null) {\r
+ if (abs == null) {\r
+ msaheader.setAbstract(ABSTRACT + msaheader.getModuleName());\r
+ } else {\r
+ msaheader.setVersion(abs);\r
+ }\r
+ return true;\r
+ } else {\r
+ MigrationTool.ui.println("Warning: Duplicate Abstract");\r
+ return false;\r
+ }\r
+ }\r
+\r
+ public final boolean addVersion(String version) {\r
+ if (msaheader.getVersion() == null) {\r
+ if (version == null) {\r
+ msaheader.setVersion(VERSION);\r
+ } else {\r
+ msaheader.setVersion(version);\r
+ }\r
+ return true;\r
+ } else {\r
+ MigrationTool.ui.println("Warning: Duplicate Version");\r
+ return false;\r
+ }\r
+ }\r
+\r
+ public final boolean addCopyRight(String copyright) {\r
+ if (msaheader.getCopyright() == null) {\r
+ if (copyright == null) {\r
+ msaheader.setCopyright(COPYRIGHT);\r
+ } else {\r
+ msaheader.setCopyright(copyright);\r
+ }\r
+ return true;\r
+ } else {\r
+ MigrationTool.ui.println("Warning: Duplicate CopyRight");\r
+ return false;\r
+ }\r
+ }\r
+\r
+ public final boolean addModuleType(String moduletype) {\r
+ if (msaheader.getModuleType() == null) {\r
+ msaheader.setModuleType(ModuleTypeDef.Enum.forString(moduletype));\r
+ return true;\r
+ } else {\r
+ MigrationTool.ui.println("Warning: Duplicate ModuleType");\r
+ return false;\r
+ }\r
+ }\r
+\r
+ public final boolean addGuidValue(String guidvalue) {\r
+ if (msaheader.getGuidValue() == null) {\r
+ msaheader.setGuidValue(guidvalue);\r
+ return true;\r
+ } else {\r
+ MigrationTool.ui.println("Warning: Duplicate GuidValue");\r
+ return false;\r
+ }\r
+ }\r
+\r
+ public final boolean addModuleName(String modulename) {\r
+ if (msaheader.getModuleName() == null) {\r
+ msaheader.setModuleName(modulename);\r
+ return true;\r
+ } else {\r
+ MigrationTool.ui.println("Warning: Duplicate ModuleName");\r
+ return false;\r
+ }\r
+ }\r
+\r
+ // -----------------------------msaheader-------------------------------------//\r
+\r
+ private final void fullfill() throws Exception {\r
+ addCopyRight(null);\r
+ addVersion(null);\r
+ addAbstract(null);\r
+ addDescription(null);\r
+ addLicense(null);\r
+ addSpecification(null);\r
+ }\r
+\r
+ public final void flush(String outputpath) throws Exception {\r
+ XmlOptions options = new XmlOptions();\r
+\r
+ options.setCharacterEncoding("UTF-8");\r
+ options.setSavePrettyPrint();\r
+ options.setSavePrettyPrintIndent(2);\r
+ options.setUseDefaultNamespace();\r
+\r
+ BufferedWriter bw = new BufferedWriter(new FileWriter(outputpath));\r
+ fullfill();\r
+ msadoc.save(bw, options);\r
+ bw.flush();\r
+ bw.close();\r
+ }\r
+\r
+ private final MsaOwner init() {\r
+ msa = msadoc.addNewModuleSurfaceArea();\r
+ msaheader = msa.addNewMsaHeader();\r
+ moduledefinitions = msa.addNewModuleDefinitions();\r
+ moduledefinitions.setSupportedArchitectures(listarch);\r
+\r
+ sourcefiles = msa.addNewSourceFiles();\r
+ packagedependencies = msa.addNewPackageDependencies();\r
+ libclassdefs = msa.addNewLibraryClassDefinitions();\r
+ externs = msa.addNewExterns();\r
+ return this;\r
+ }\r
+\r
+ public static final MsaOwner initNewMsaOwner() {\r
+ return new MsaOwner().init();\r
+ }\r
}
\ No newline at end of file
package org.tianocore.migration;\r
\r
-import java.awt.*;\r
-import java.awt.event.*;\r
-import javax.swing.*;\r
-import javax.swing.tree.*;\r
-import javax.xml.parsers.*;\r
-import org.w3c.dom.*;\r
+import java.awt.GridBagLayout;\r
+import java.awt.event.ActionEvent;\r
+import java.awt.event.ActionListener;\r
+import java.awt.event.MouseAdapter;\r
+import java.awt.event.MouseEvent;\r
+\r
+import javax.swing.JFileChooser;\r
+import javax.swing.JFrame;\r
+import javax.swing.JMenuItem;\r
+import javax.swing.JPanel;\r
+import javax.swing.JPopupMenu;\r
+import javax.swing.JScrollPane;\r
+import javax.swing.JTree;\r
+import javax.swing.SwingUtilities;\r
+import javax.swing.UIManager;\r
+import javax.swing.tree.DefaultMutableTreeNode;\r
+import javax.swing.tree.DefaultTreeModel;\r
+import javax.swing.tree.TreePath;\r
+import javax.swing.tree.TreeSelectionModel;\r
+import javax.xml.parsers.DocumentBuilder;\r
+import javax.xml.parsers.DocumentBuilderFactory;\r
+\r
+import org.w3c.dom.Document;\r
+import org.w3c.dom.Element;\r
+import org.w3c.dom.Node;\r
+import org.w3c.dom.NodeList;\r
\r
public class MsaTreeEditor extends JPanel {\r
- /**\r
- * Define class Serial Version UID\r
- */\r
- private static final long serialVersionUID = 3169905938472150649L;\r
- \r
- MsaTreeEditor() throws Exception {\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
- //scrollPane.setSize(800, 600);\r
- add(scrollPane);\r
- \r
- popupmenu = new JPopupMenu();\r
- menuitemadd = new JMenuItem("Add Node");\r
- menuitemdel = new JMenuItem("Delete Node");\r
- menuitemedit = new JMenuItem("Edit Node");\r
- popupmenu.add(menuitemadd);\r
- popupmenu.add(menuitemdel);\r
- popupmenu.add(menuitemedit);\r
- menuitemadd.addActionListener(actionListener);\r
- menuitemdel.addActionListener(actionListener);\r
- menuitemedit.addActionListener(actionListener);\r
-\r
- genDomTree(MigrationTool.ui.getFilepath("Select a msa file", JFileChooser.FILES_AND_DIRECTORIES));\r
- }\r
- \r
- //private ModuleSurfaceAreaDocument msadoc;\r
- \r
- private JTree tree;\r
- private DefaultMutableTreeNode rootNode;\r
- private DefaultTreeModel treeModel;\r
- private JMenuItem menuitemadd, menuitemdel, menuitemedit;\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
- if (ae.getSource() == menuitemadd) {\r
- addNode();\r
- } else if (ae.getSource() == menuitemdel) {\r
- delNode();\r
- } else if (ae.getSource() == menuitemedit) {\r
- editNode();\r
- }\r
- }\r
- };\r
- \r
- private void editNode() {\r
- DefaultMutableTreeNode node = (DefaultMutableTreeNode)(tree.getSelectionPath().getLastPathComponent());\r
- Element element = (Element)node.getUserObject();\r
- System.out.println(element.getTextContent());\r
- }\r
- \r
- private void delNode() {\r
- treeModel.removeNodeFromParent((DefaultMutableTreeNode)(tree.getSelectionPath().getLastPathComponent()));\r
- }\r
- \r
- private void addNode() {\r
- addNode((DefaultMutableTreeNode)(tree.getSelectionPath().getLastPathComponent()), MigrationTool.ui.getInput("Input Node Name"));\r
- }\r
- \r
- private DefaultMutableTreeNode 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
- return childNode;\r
- }\r
-\r
- private final void handleNode(Node node, DefaultMutableTreeNode parentNode) {\r
- DefaultMutableTreeNode curNode = null;\r
- if (node.getNodeType() == Node.ELEMENT_NODE) {\r
- System.out.println("elem");\r
- curNode = addNode(parentNode, node);\r
- } else if (node.getNodeType() == Node.DOCUMENT_NODE){\r
- System.out.println("doc");\r
- curNode = addNode(parentNode, "MsaDocum"); // can Docum be with Root Node?\r
- }\r
-\r
- NodeList nodelist = node.getChildNodes();\r
- for (int i = 0; i < nodelist.getLength(); i++) {\r
- handleNode(nodelist.item(i), curNode);\r
- }\r
- }\r
- \r
- private final void genDomTree(String filename) throws Exception {\r
- DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();\r
- Document document = builder.parse(filename);\r
- handleNode(document, rootNode);\r
- }\r
- \r
- public static final void init() 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();\r
- mte.setLayout(new GridBagLayout());\r
- mte.setOpaque(true);\r
- frame.setContentPane(mte);\r
-\r
- frame.pack();\r
- frame.setVisible(true);\r
- }\r
+ /**\r
+ * Define class Serial Version UID\r
+ */\r
+ private static final long serialVersionUID = 3169905938472150649L;\r
+\r
+ MsaTreeEditor() throws Exception {\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(\r
+ TreeSelectionModel.SINGLE_TREE_SELECTION);\r
+ tree.setShowsRootHandles(false);\r
+ tree.addMouseListener(mouseadapter);\r
+\r
+ JScrollPane scrollPane = new JScrollPane(tree);\r
+ // scrollPane.setSize(800, 600);\r
+ add(scrollPane);\r
+\r
+ popupmenu = new JPopupMenu();\r
+ menuitemadd = new JMenuItem("Add Node");\r
+ menuitemdel = new JMenuItem("Delete Node");\r
+ menuitemedit = new JMenuItem("Edit Node");\r
+ popupmenu.add(menuitemadd);\r
+ popupmenu.add(menuitemdel);\r
+ popupmenu.add(menuitemedit);\r
+ menuitemadd.addActionListener(actionListener);\r
+ menuitemdel.addActionListener(actionListener);\r
+ menuitemedit.addActionListener(actionListener);\r
+\r
+ genDomTree(MigrationTool.ui.getFilepath("Select a msa file",\r
+ JFileChooser.FILES_AND_DIRECTORIES));\r
+ }\r
+\r
+ // private ModuleSurfaceAreaDocument msadoc;\r
+\r
+ private JTree tree;\r
+\r
+ private DefaultMutableTreeNode rootNode;\r
+\r
+ private DefaultTreeModel treeModel;\r
+\r
+ private JMenuItem menuitemadd, menuitemdel, menuitemedit;\r
+\r
+ private JPopupMenu popupmenu;\r
+\r
+ private MouseAdapter mouseadapter = new MouseAdapter() {\r
+ public void mouseReleased(MouseEvent me) {\r
+ if (me.getClickCount() == 1\r
+ && SwingUtilities.isRightMouseButton(me)) {\r
+ tree.setSelectionPath(tree.getPathForLocation(me.getX(), me\r
+ .getY()));\r
+ popupmenu.show(tree, me.getX(), me.getY());\r
+ }\r
+ }\r
+ };\r
+\r
+ private ActionListener actionListener = new ActionListener() {\r
+ public void actionPerformed(ActionEvent ae) {\r
+ if (ae.getSource() == menuitemadd) {\r
+ addNode();\r
+ } else if (ae.getSource() == menuitemdel) {\r
+ delNode();\r
+ } else if (ae.getSource() == menuitemedit) {\r
+ editNode();\r
+ }\r
+ }\r
+ };\r
+\r
+ private void editNode() {\r
+ DefaultMutableTreeNode node = (DefaultMutableTreeNode) (tree\r
+ .getSelectionPath().getLastPathComponent());\r
+ Element element = (Element) node.getUserObject();\r
+ System.out.println(element.getTextContent());\r
+ }\r
+\r
+ private void delNode() {\r
+ treeModel.removeNodeFromParent((DefaultMutableTreeNode) (tree\r
+ .getSelectionPath().getLastPathComponent()));\r
+ }\r
+\r
+ private void addNode() {\r
+ addNode((DefaultMutableTreeNode) (tree.getSelectionPath()\r
+ .getLastPathComponent()), MigrationTool.ui\r
+ .getInput("Input Node Name"));\r
+ }\r
+\r
+ private DefaultMutableTreeNode addNode(DefaultMutableTreeNode parentNode,\r
+ Object child) {\r
+ DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child);\r
+ treeModel.insertNodeInto(childNode, parentNode, parentNode\r
+ .getChildCount());\r
+ tree.scrollPathToVisible(new TreePath(childNode.getPath()));\r
+ return childNode;\r
+ }\r
+\r
+ private final void handleNode(Node node, DefaultMutableTreeNode parentNode) {\r
+ DefaultMutableTreeNode curNode = null;\r
+ if (node.getNodeType() == Node.ELEMENT_NODE) {\r
+ System.out.println("elem");\r
+ curNode = addNode(parentNode, node);\r
+ } else if (node.getNodeType() == Node.DOCUMENT_NODE) {\r
+ System.out.println("doc");\r
+ curNode = addNode(parentNode, "MsaDocum"); // can Docum be with\r
+ // Root Node?\r
+ }\r
+\r
+ NodeList nodelist = node.getChildNodes();\r
+ for (int i = 0; i < nodelist.getLength(); i++) {\r
+ handleNode(nodelist.item(i), curNode);\r
+ }\r
+ }\r
+\r
+ private final void genDomTree(String filename) throws Exception {\r
+ DocumentBuilder builder = DocumentBuilderFactory.newInstance()\r
+ .newDocumentBuilder();\r
+ Document document = builder.parse(filename);\r
+ handleNode(document, rootNode);\r
+ }\r
+\r
+ public static final void init() 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();\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
**/\r
package org.tianocore.migration;\r
\r
-import java.io.*;\r
-import java.util.*;\r
+import java.io.BufferedReader;\r
+import java.io.BufferedWriter;\r
+import java.io.File;\r
+import java.io.FileWriter;\r
+import java.io.InputStreamReader;\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import java.util.UUID;\r
\r
-import org.tianocore.*;\r
+import org.apache.xmlbeans.XmlCursor;\r
+import org.apache.xmlbeans.XmlOptions;\r
+import org.tianocore.ExternsDocument;\r
+import org.tianocore.FilenameDocument;\r
+import org.tianocore.GuidsDocument;\r
+import org.tianocore.LibraryClassDefinitionsDocument;\r
+import org.tianocore.LibraryClassDocument;\r
+import org.tianocore.ModuleDefinitionsDocument;\r
+import org.tianocore.ModuleSurfaceAreaDocument;\r
+import org.tianocore.ModuleTypeDef;\r
+import org.tianocore.MsaHeaderDocument;\r
+import org.tianocore.PPIsDocument;\r
+import org.tianocore.PackageDependenciesDocument;\r
+import org.tianocore.ProtocolsDocument;\r
+import org.tianocore.SourceFilesDocument;\r
+import org.tianocore.SupportedArchitectures;\r
+import org.tianocore.UsageTypes;\r
import org.tianocore.SupportedArchitectures.Enum;\r
-import org.apache.xmlbeans.*;\r
\r
public class MsaWriter {\r
- MsaWriter(ModuleInfo moduleinfo) {\r
- mi = moduleinfo;\r
- }\r
- \r
- private ModuleInfo mi;\r
- private ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.newInstance();\r
- \r
- private ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc.addNewModuleSurfaceArea();\r
- private MsaHeaderDocument.MsaHeader msaheader = msa.addNewMsaHeader();\r
- private ModuleDefinitionsDocument.ModuleDefinitions md = msa.addNewModuleDefinitions();\r
- private SourceFilesDocument.SourceFiles sourcefiles = msa.addNewSourceFiles(); //found local .h files are not written\r
- private GuidsDocument.Guids guids;\r
- private ProtocolsDocument.Protocols protocols;\r
- private PPIsDocument.PPIs ppis;\r
- private PackageDependenciesDocument.PackageDependencies pd = msa.addNewPackageDependencies();\r
- private LibraryClassDefinitionsDocument.LibraryClassDefinitions libclassdefs = msa.addNewLibraryClassDefinitions();\r
- private ExternsDocument.Externs externs = msa.addNewExterns();\r
- \r
- private String Query (String requirement) throws Exception {\r
- String answer;\r
- BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));\r
- System.out.println(requirement);\r
- while ((answer = rd.readLine()).length() == 0) ;\r
- return answer;\r
- }\r
- \r
- private void addSourceFiles (String name) { // furthur modification needed\r
- List<Enum> arch = new ArrayList<Enum>();\r
- FilenameDocument.Filename filename;\r
- filename = sourcefiles.addNewFilename();\r
- filename.setStringValue(name);\r
- \r
- if (name.contains("x64" + File.separator)) { // filename ???\r
- arch.add(SupportedArchitectures.X_64);\r
- System.out.println("x64" + File.separator);\r
- filename.setSupArchList(arch);\r
- } else if (name.contains("Ia32" + File.separator)) { // filename ???\r
- arch.add(SupportedArchitectures.IA_32);\r
- System.out.println("Ia32" + File.separator);\r
- filename.setSupArchList(arch);\r
- } else if (name.contains("Ipf" + File.separator)) { // filename ???\r
- arch.add(SupportedArchitectures.IPF);\r
- System.out.println("Ipf" + File.separator);\r
- filename.setSupArchList(arch);\r
- } else if (name.contains("Ebc" + File.separator)) { // filename ???\r
- arch.add(SupportedArchitectures.EBC);\r
- System.out.println("Ebc" + File.separator);\r
- filename.setSupArchList(arch);\r
- }\r
- }\r
- private void addWrapper() {\r
- XmlCursor cursor = msa.newCursor();\r
- String uri = "http://www.TianoCore.org/2006/Edk2.0";\r
- cursor.push();\r
- cursor.toNextToken();\r
- cursor.insertNamespace("", uri);\r
- cursor.insertNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");\r
- cursor.pop();\r
- msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)cursor.getObject();\r
- }\r
- private ModuleSurfaceAreaDocument fulfillMsadoc() throws Exception {\r
- Iterator<String> it;\r
- String temp;\r
- \r
- if (mi.modulename != null) {\r
- msaheader.setModuleName(mi.modulename);\r
- } else {\r
- msaheader.setModuleName(mi.modulename = Query("Module Name Not Found! Please Input ModuleName"));\r
- }\r
- if (mi.guidvalue == null) {\r
- mi.guidvalue = UUID.randomUUID().toString();\r
- MigrationTool.ui.println ("Guid value can not be retrieved from inf file. Generate " + mi.guidvalue + " at random!"); \r
- } \r
- msaheader.setGuidValue(mi.guidvalue);\r
- if (mi.moduletype != null) {\r
- msaheader.setModuleType(ModuleTypeDef.Enum.forString(mi.getModuleType()));\r
- } else {\r
- msaheader.setModuleType(ModuleTypeDef.Enum.forString(mi.moduletype = Query("Guid Value Not Found! Please Input Guid Value")));\r
- }\r
-\r
- msaheader.setCopyright("Copyright (c) 2006, Intel Corporation. All right reserved.");\r
- msaheader.setVersion("1.0");\r
- msaheader.setAbstract("Component name for module " + mi.modulename);\r
- msaheader.setDescription("FIX ME!");\r
-\r
- if (mi.license == null) {\r
- mi.license = "FIX ME!";\r
- MigrationTool.ui.println ("Fail to extract license info in inf file"); \r
- }\r
- msaheader.addNewLicense().setStringValue(mi.license);\r
- msaheader.setSpecification("FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052");\r
- \r
- List<Enum> arch = new ArrayList<Enum>();\r
- arch.add(SupportedArchitectures.IA_32);\r
- arch.add(SupportedArchitectures.X_64);\r
- arch.add(SupportedArchitectures.IPF);\r
- arch.add(SupportedArchitectures.EBC);\r
- md.setSupportedArchitectures(arch);\r
- md.setBinaryModule(false);\r
- md.setOutputFileBasename(mi.modulename);\r
- //\r
- // For now, simply add all package guids in the database. \r
- // \r
- it = MigrationTool.db.dumpAllPkgGuid();\r
- while (it.hasNext()) {\r
- pd.addNewPackage().setPackageGuid(it.next());\r
- }\r
- externs.addNewSpecification().setStringValue("EFI_SPECIFICATION_VERSION 0x00020000");\r
- externs.addNewSpecification().setStringValue("EDK_RELEASE_VERSION 0x00020000");\r
- if (mi.entrypoint != null) {\r
- externs.addNewExtern().setModuleEntryPoint(mi.entrypoint);\r
- org.tianocore.ModuleTypeDef.Enum moduleType = msaheader.getModuleType();\r
- if (moduleType == ModuleTypeDef.PEIM) {\r
- mi.hashrequiredr9libs.add("PeimEntryPoint");\r
- } else {\r
- mi.hashrequiredr9libs.add("UefiDriverEntryPoint");\r
- }\r
- }\r
- \r
- it = mi.localmodulesources.iterator();\r
- while (it.hasNext()) {\r
- addSourceFiles(it.next());\r
- }\r
- if (!mi.protocols.isEmpty()) {\r
- protocols = msa.addNewProtocols();\r
- it = mi.protocols.iterator();\r
- while (it.hasNext()) {\r
- if ((temp = it.next()) != null) {\r
- ProtocolsDocument.Protocols.Protocol pr = protocols.addNewProtocol();\r
- pr.setProtocolCName(temp);\r
- pr.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
- }\r
- }\r
- }\r
- if (!mi.ppis.isEmpty()) {\r
- ppis = msa.addNewPPIs();\r
- it = mi.ppis.iterator();\r
- while (it.hasNext()) {\r
- if ((temp = it.next()) != null) {\r
- PPIsDocument.PPIs.Ppi pp = ppis.addNewPpi();\r
- pp.setPpiCName(temp);\r
- pp.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
- }\r
- }\r
- }\r
- if (!mi.guids.isEmpty()) {\r
- guids = msa.addNewGuids();\r
- it = mi.guids.iterator();\r
- while (it.hasNext()) {\r
- if ((temp = it.next()) != null) {\r
- GuidsDocument.Guids.GuidCNames gcn = guids.addNewGuidCNames();\r
- gcn.setGuidCName(temp);\r
- gcn.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
- }\r
- }\r
- }\r
- it = mi.hashrequiredr9libs.iterator();\r
- while (it.hasNext()) {\r
- if ((temp = it.next()) != null && !temp.matches("%") && !temp.matches("n/a")) {\r
- LibraryClassDocument.LibraryClass lc = libclassdefs.addNewLibraryClass();\r
- lc.setKeyword(temp);\r
- lc.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
- }\r
- }\r
- addWrapper();\r
- msadoc.setModuleSurfaceArea(msa);\r
- return msadoc;\r
- }\r
- \r
- public void flush() throws Exception {\r
- XmlOptions options = new XmlOptions();\r
-\r
- options.setCharacterEncoding("UTF-8");\r
- options.setSavePrettyPrint();\r
- options.setSavePrettyPrintIndent(2);\r
- options.setUseDefaultNamespace();\r
-\r
- BufferedWriter bw = new BufferedWriter(new FileWriter(MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator + mi.modulename + ".msa"));\r
- fulfillMsadoc().save(bw, options);\r
- //MsaTreeEditor.init(mi, ui, msadoc);\r
- bw.flush();\r
- bw.close();\r
- }\r
-\r
- private static void flush(String path, ModuleSurfaceAreaDocument msadoc) throws Exception {\r
- XmlOptions options = new XmlOptions();\r
-\r
- options.setCharacterEncoding("UTF-8");\r
- options.setSavePrettyPrint();\r
- options.setSavePrettyPrintIndent(2);\r
- options.setUseDefaultNamespace();\r
-\r
- BufferedWriter bw = new BufferedWriter(new FileWriter(path));\r
- msadoc.save(bw, options);\r
- bw.flush();\r
- bw.close();\r
- }\r
-\r
- public static final void parse(String msafile) throws Exception {\r
- ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(msafile);\r
- flush("c:\\temp.msa", msadoc);\r
- }\r
+ MsaWriter(ModuleInfo moduleinfo) {\r
+ mi = moduleinfo;\r
+ }\r
+\r
+ private ModuleInfo mi;\r
+\r
+ private ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory\r
+ .newInstance();\r
+\r
+ private ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc\r
+ .addNewModuleSurfaceArea();\r
+\r
+ private MsaHeaderDocument.MsaHeader msaheader = msa.addNewMsaHeader();\r
+\r
+ private ModuleDefinitionsDocument.ModuleDefinitions md = msa\r
+ .addNewModuleDefinitions();\r
+\r
+ private SourceFilesDocument.SourceFiles sourcefiles = msa\r
+ .addNewSourceFiles(); // found local .h files are not written\r
+\r
+ private GuidsDocument.Guids guids;\r
+\r
+ private ProtocolsDocument.Protocols protocols;\r
+\r
+ private PPIsDocument.PPIs ppis;\r
+\r
+ private PackageDependenciesDocument.PackageDependencies pd = msa\r
+ .addNewPackageDependencies();\r
+\r
+ private LibraryClassDefinitionsDocument.LibraryClassDefinitions libclassdefs = msa\r
+ .addNewLibraryClassDefinitions();\r
+\r
+ private ExternsDocument.Externs externs = msa.addNewExterns();\r
+\r
+ private String Query(String requirement) throws Exception {\r
+ String answer;\r
+ BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));\r
+ System.out.println(requirement);\r
+ while ((answer = rd.readLine()).length() == 0)\r
+ ;\r
+ return answer;\r
+ }\r
+\r
+ private void addSourceFiles(String name) { // furthur modification needed\r
+ List<Enum> arch = new ArrayList<Enum>();\r
+ FilenameDocument.Filename filename;\r
+ filename = sourcefiles.addNewFilename();\r
+ filename.setStringValue(name);\r
+\r
+ if (name.contains("x64" + File.separator)) { // filename ???\r
+ arch.add(SupportedArchitectures.X_64);\r
+ System.out.println("x64" + File.separator);\r
+ filename.setSupArchList(arch);\r
+ } else if (name.contains("Ia32" + File.separator)) { // filename ???\r
+ arch.add(SupportedArchitectures.IA_32);\r
+ System.out.println("Ia32" + File.separator);\r
+ filename.setSupArchList(arch);\r
+ } else if (name.contains("Ipf" + File.separator)) { // filename ???\r
+ arch.add(SupportedArchitectures.IPF);\r
+ System.out.println("Ipf" + File.separator);\r
+ filename.setSupArchList(arch);\r
+ } else if (name.contains("Ebc" + File.separator)) { // filename ???\r
+ arch.add(SupportedArchitectures.EBC);\r
+ System.out.println("Ebc" + File.separator);\r
+ filename.setSupArchList(arch);\r
+ }\r
+ }\r
+\r
+ private void addWrapper() {\r
+ XmlCursor cursor = msa.newCursor();\r
+ String uri = "http://www.TianoCore.org/2006/Edk2.0";\r
+ cursor.push();\r
+ cursor.toNextToken();\r
+ cursor.insertNamespace("", uri);\r
+ cursor.insertNamespace("xsi",\r
+ "http://www.w3.org/2001/XMLSchema-instance");\r
+ cursor.pop();\r
+ msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea) cursor.getObject();\r
+ }\r
+\r
+ private ModuleSurfaceAreaDocument fulfillMsadoc() throws Exception {\r
+ Iterator<String> it;\r
+ String temp;\r
+\r
+ if (mi.modulename != null) {\r
+ msaheader.setModuleName(mi.modulename);\r
+ } else {\r
+ msaheader\r
+ .setModuleName(mi.modulename = Query("Module Name Not Found! Please Input ModuleName"));\r
+ }\r
+ if (mi.guidvalue == null) {\r
+ mi.guidvalue = UUID.randomUUID().toString();\r
+ MigrationTool.ui\r
+ .println("Guid value can not be retrieved from inf file. Generate "\r
+ + mi.guidvalue + " at random!");\r
+ }\r
+ msaheader.setGuidValue(mi.guidvalue);\r
+ if (mi.moduletype != null) {\r
+ msaheader.setModuleType(ModuleTypeDef.Enum.forString(mi\r
+ .getModuleType()));\r
+ } else {\r
+ msaheader\r
+ .setModuleType(ModuleTypeDef.Enum\r
+ .forString(mi.moduletype = Query("Guid Value Not Found! Please Input Guid Value")));\r
+ }\r
+\r
+ msaheader\r
+ .setCopyright("Copyright (c) 2006, Intel Corporation. All right reserved.");\r
+ msaheader.setVersion("1.0");\r
+ msaheader.setAbstract("Component name for module " + mi.modulename);\r
+ msaheader.setDescription("FIX ME!");\r
+\r
+ if (mi.license == null) {\r
+ mi.license = "FIX ME!";\r
+ MigrationTool.ui\r
+ .println("Fail to extract license info in inf file");\r
+ }\r
+ msaheader.addNewLicense().setStringValue(mi.license);\r
+ msaheader\r
+ .setSpecification("FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052");\r
+\r
+ List<Enum> arch = new ArrayList<Enum>();\r
+ arch.add(SupportedArchitectures.IA_32);\r
+ arch.add(SupportedArchitectures.X_64);\r
+ arch.add(SupportedArchitectures.IPF);\r
+ arch.add(SupportedArchitectures.EBC);\r
+ md.setSupportedArchitectures(arch);\r
+ md.setBinaryModule(false);\r
+ md.setOutputFileBasename(mi.modulename);\r
+ //\r
+ // For now, simply add all package guids in the database.\r
+ // \r
+ it = MigrationTool.db.dumpAllPkgGuid();\r
+ while (it.hasNext()) {\r
+ pd.addNewPackage().setPackageGuid(it.next());\r
+ }\r
+ externs.addNewSpecification().setStringValue(\r
+ "EFI_SPECIFICATION_VERSION 0x00020000");\r
+ externs.addNewSpecification().setStringValue(\r
+ "EDK_RELEASE_VERSION 0x00020000");\r
+ if (mi.entrypoint != null) {\r
+ externs.addNewExtern().setModuleEntryPoint(mi.entrypoint);\r
+ org.tianocore.ModuleTypeDef.Enum moduleType = msaheader\r
+ .getModuleType();\r
+ if (moduleType == ModuleTypeDef.PEIM) {\r
+ mi.hashrequiredr9libs.add("PeimEntryPoint");\r
+ } else {\r
+ mi.hashrequiredr9libs.add("UefiDriverEntryPoint");\r
+ }\r
+ }\r
+\r
+ it = mi.localmodulesources.iterator();\r
+ while (it.hasNext()) {\r
+ addSourceFiles(it.next());\r
+ }\r
+ if (!mi.protocols.isEmpty()) {\r
+ protocols = msa.addNewProtocols();\r
+ it = mi.protocols.iterator();\r
+ while (it.hasNext()) {\r
+ if ((temp = it.next()) != null) {\r
+ ProtocolsDocument.Protocols.Protocol pr = protocols\r
+ .addNewProtocol();\r
+ pr.setProtocolCName(temp);\r
+ pr.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
+ }\r
+ }\r
+ }\r
+ if (!mi.ppis.isEmpty()) {\r
+ ppis = msa.addNewPPIs();\r
+ it = mi.ppis.iterator();\r
+ while (it.hasNext()) {\r
+ if ((temp = it.next()) != null) {\r
+ PPIsDocument.PPIs.Ppi pp = ppis.addNewPpi();\r
+ pp.setPpiCName(temp);\r
+ pp.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
+ }\r
+ }\r
+ }\r
+ if (!mi.guids.isEmpty()) {\r
+ guids = msa.addNewGuids();\r
+ it = mi.guids.iterator();\r
+ while (it.hasNext()) {\r
+ if ((temp = it.next()) != null) {\r
+ GuidsDocument.Guids.GuidCNames gcn = guids\r
+ .addNewGuidCNames();\r
+ gcn.setGuidCName(temp);\r
+ gcn.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
+ }\r
+ }\r
+ }\r
+ it = mi.hashrequiredr9libs.iterator();\r
+ while (it.hasNext()) {\r
+ if ((temp = it.next()) != null && !temp.matches("%")\r
+ && !temp.matches("n/a")) {\r
+ LibraryClassDocument.LibraryClass lc = libclassdefs\r
+ .addNewLibraryClass();\r
+ lc.setKeyword(temp);\r
+ lc.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
+ }\r
+ }\r
+ addWrapper();\r
+ msadoc.setModuleSurfaceArea(msa);\r
+ return msadoc;\r
+ }\r
+\r
+ public void flush() throws Exception {\r
+ XmlOptions options = new XmlOptions();\r
+\r
+ options.setCharacterEncoding("UTF-8");\r
+ options.setSavePrettyPrint();\r
+ options.setSavePrettyPrintIndent(2);\r
+ options.setUseDefaultNamespace();\r
+\r
+ BufferedWriter bw = new BufferedWriter(new FileWriter(\r
+ MigrationTool.ModuleInfoMap.get(mi) + File.separator\r
+ + "Migration_" + mi.modulename + File.separator\r
+ + mi.modulename + ".msa"));\r
+ fulfillMsadoc().save(bw, options);\r
+ // MsaTreeEditor.init(mi, ui, msadoc);\r
+ bw.flush();\r
+ bw.close();\r
+ }\r
+\r
+ private static void flush(String path, ModuleSurfaceAreaDocument msadoc)\r
+ throws Exception {\r
+ XmlOptions options = new XmlOptions();\r
+\r
+ options.setCharacterEncoding("UTF-8");\r
+ options.setSavePrettyPrint();\r
+ options.setSavePrettyPrintIndent(2);\r
+ options.setUseDefaultNamespace();\r
+\r
+ BufferedWriter bw = new BufferedWriter(new FileWriter(path));\r
+ msadoc.save(bw, options);\r
+ bw.flush();\r
+ bw.close();\r
+ }\r
+\r
+ public static final void parse(String msafile) throws Exception {\r
+ ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory\r
+ .parse(msafile);\r
+ flush("c:\\temp.msa", msadoc);\r
+ }\r
}\r
package org.tianocore.migration;\r
\r
import java.io.File;\r
-import java.util.*;\r
+import java.util.HashSet;\r
+import java.util.Iterator;\r
\r
public final class PathIterator implements Common.ForDoAll {\r
-// this PathIterator is based on HashSet, an thread implementation is required.\r
- PathIterator(String path, int md) throws Exception {\r
- startpath = path;\r
- mode = md;\r
- Common.toDoAll(startpath, this, mode);\r
- it = pathlist.iterator();\r
- }\r
- private String startpath = null;\r
- private int mode;\r
- private HashSet<String> pathlist = new HashSet<String>();\r
- private Iterator<String> it = null;\r
-\r
- public final void run(String path) throws Exception {\r
- pathlist.add(path);\r
- }\r
-\r
- public boolean filter(File dir) {\r
- return true;\r
- }\r
- \r
- public final String next() {\r
- return it.next();\r
- }\r
-\r
- public final boolean hasNext() {\r
- return it.hasNext();\r
- }\r
-\r
- public final String toString() {\r
- return pathlist.toString();\r
- }\r
+ // this PathIterator is based on HashSet, an thread implementation is\r
+ // required.\r
+ PathIterator(String path, int md) throws Exception {\r
+ startpath = path;\r
+ mode = md;\r
+ Common.toDoAll(startpath, this, mode);\r
+ it = pathlist.iterator();\r
+ }\r
+\r
+ private String startpath = null;\r
+\r
+ private int mode;\r
+\r
+ private HashSet<String> pathlist = new HashSet<String>();\r
+\r
+ private Iterator<String> it = null;\r
+\r
+ public final void run(String path) throws Exception {\r
+ pathlist.add(path);\r
+ }\r
+\r
+ public boolean filter(File dir) {\r
+ return true;\r
+ }\r
+\r
+ public final String next() {\r
+ return it.next();\r
+ }\r
+\r
+ public final boolean hasNext() {\r
+ return it.hasNext();\r
+ }\r
+\r
+ public final String toString() {\r
+ return pathlist.toString();\r
+ }\r
}\r
**/\r
package org.tianocore.migration;\r
\r
-import java.io.*;\r
-import java.util.*;\r
+import java.io.BufferedWriter;\r
+import java.io.File;\r
+import java.io.FileWriter;\r
+import java.io.PrintWriter;\r
+import java.util.HashSet;\r
+import java.util.Iterator;\r
+import java.util.Set;\r
import java.util.regex.Matcher;\r
import java.util.regex.Pattern;\r
\r
import org.tianocore.UsageTypes;\r
\r
public final class SourceFileReplacer implements Common.ForDoAll {\r
- private static final SourceFileReplacer SFReplacer = new SourceFileReplacer();\r
- private ModuleInfo mi;\r
- private static final Set<Common.Laplace> Laplaces = new HashSet<Common.Laplace>();\r
-\r
- // these sets are used only for printing log of the changes in current file\r
- private static final Set<r8tor9> filefunc = new HashSet<r8tor9>();\r
- private static final Set<r8tor9> filemacro = new HashSet<r8tor9>();\r
- private static final Set<r8tor9> fileguid = new HashSet<r8tor9>();\r
- private static final Set<r8tor9> fileppi = new HashSet<r8tor9>();\r
- private static final Set<r8tor9> fileprotocol = new HashSet<r8tor9>();\r
- private static final Set<String> filer8only = new HashSet<String>();\r
- \r
- private static final String[] specialhoblibfunc = {\r
- "BuildModuleHob",\r
- "BuildResourceDescriptorHob",\r
- "BuildFvHob",\r
- "BuildCpuHob",\r
- "BuildGuidDataHob",\r
- &nb