**/\r
package org.tianocore.framework.tasks;\r
\r
-import java.io.File;\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-import java.util.StringTokenizer;\r
-\r
/**\r
- Database\r
- \r
Database represents an exceplicity name list of database file. \r
- \r
**/\r
-public class Database implements NestElement{\r
- ///\r
- /// name of database file\r
- ///\r
- private String name = "";\r
- ///\r
- /// name of file including database files\r
- /// \r
- private File file;\r
- ///\r
- /// the database file name list\r
- ///\r
- private List<String> nameList = new ArrayList<String>();\r
- \r
- /**\r
- getName\r
- \r
- This function is to get class member "name".\r
- \r
- @return class member "name".\r
- **/\r
- public String getName() {\r
- return this.name;\r
- }\r
+public class Database extends NestElement {\r
/**\r
- setName\r
+ Override NestElement.toString() to return a string with leading "-db"\r
\r
- This function is to set class member "name".\r
- \r
- @param name : name of database file.\r
- **/\r
- public void setName(String name) {\r
- this.name = " -db " + name;\r
- }\r
-\r
- /**\r
- toString\r
- \r
- This function is to call getName() function.\r
- @return class member "name". \r
+ @return String \r
**/\r
public String toString() {\r
- return getName();\r
- }\r
- \r
- /**\r
- getFile\r
- \r
- This function is to get file which include the database file list.\r
- \r
- @return class member "file"\r
- \r
- **/\r
- public File getFile() {\r
- return this.file;\r
- }\r
- /**\r
- setFile\r
- \r
- This function is to set class member "file".\r
- \r
- @param file The file which include the database file list. \r
- **/\r
- public void setFile(File file) {\r
- this.file = file;\r
- }\r
- \r
-\r
- public void setList(String fileNameList) {\r
- if (fileNameList != null && fileNameList.length() > 0) {\r
- StringTokenizer tokens = new StringTokenizer(fileNameList, " \t,;", false);\r
- while (tokens.hasMoreTokens()) {\r
- String fileName = tokens.nextToken().trim();\r
- if (fileName.length() > 0) {\r
- this.nameList.add(fileName);\r
- }\r
- }\r
- }\r
- }\r
-\r
- public List<String> getList() {\r
- return nameList;\r
- }\r
+ return super.toString(" -db ");\r
+ } \r
}
\ No newline at end of file
argList.add("-b");\r
Iterator binList = this.binaryFileList.iterator();\r
while (binList.hasNext()){\r
- argList.add(((Input)binList.next()).getFile());\r
+ argList.addAll(((Input)binList.next()).getNameList());\r
}\r
}\r
\r
argList.add("-e");\r
Iterator pe32List = this.pe32FileList.iterator();\r
while (pe32List.hasNext()){\r
- argList.add(((Input)pe32List.next()).getFile());\r
+ argList.addAll(((Input)pe32List.next()).getNameList());\r
}\r
}\r
\r
argList.add("-ec");\r
Iterator pe32ComprList = this.pe32ComprFileList.iterator();\r
while (pe32ComprList.hasNext()){\r
- argList.add(((Input)pe32ComprList.next()).getFile());\r
+ argList.addAll(((Input)pe32ComprList.next()).getNameList());\r
}\r
}\r
\r
argList.add("-mcmerge");\r
Iterator mciList = mciFileArray.iterator();\r
while (mciList.hasNext()) {\r
- argList.add(((Input) mciList.next()).getFile());\r
+ argList.addAll(((Input) mciList.next()).getNameList());\r
}\r
}\r
\r
GenCRC32SectionTask is to call GenCRC32Section.exe to generate crc32 section. \r
\r
**/\r
-public class GenCRC32SectionTask extends Task implements EfiDefine{\r
+public class GenCRC32SectionTask extends Task implements EfiDefine {\r
///\r
/// output file\r
///\r
///\r
/// inputFile list\r
///\r
- private List<Object> inputFileList = new ArrayList<Object>();\r
+ private List<NestElement> inputFileList = new ArrayList<NestElement>();\r
\r
///\r
/// Project\r
// \r
// string line of input files \r
// \r
- String inputFiles = list2Str(inputFileList, ""); \r
+ String inputFiles = " -i "; \r
+ for (int i = 0; i < inputFileList.size(); ++i) {\r
+ inputFiles += inputFileList.get(i).toString(" ");\r
+ }\r
+\r
// \r
// assemble argument \r
//\r
*/\r
public void setOutputFile(String outputFile) {\r
this.outputFile = " -o " + outputFile;\r
- };\r
- \r
- /**\r
- * transfer List to String\r
- * @param list : nested element list\r
- * @param tag : interval tag of parameter\r
- * @return string line of parameters \r
- */\r
- private String list2Str(List list, String tag) {\r
- /*\r
- * string line for return\r
- */\r
- String paraStr = " -i"; \r
- /*\r
- * nested element in list\r
- */\r
- NestElement element; \r
- /*\r
- * iterator of nested element list\r
- */\r
- Iterator elementIter = list.iterator(); \r
- /*\r
- * string parameter list\r
- */\r
- List<Object> strList = new ArrayList<Object>(); \r
- \r
- while (elementIter.hasNext()) {\r
- element = (NestElement) elementIter.next();\r
- if (null != element.getFile()) {\r
- FileParser.loadFile(project, strList, element.getFile(), tag);\r
- } else {\r
- paraStr = paraStr + element.getName();\r
- }\r
- }\r
- /*\r
- * iterator of string parameter list\r
- */\r
- Iterator strIter = strList.iterator(); \r
- while (strIter.hasNext()) {\r
- paraStr = paraStr + " " + strIter.next();\r
- }\r
- return paraStr;\r
- } \r
+ }\r
}\r
\r
package org.tianocore.framework.tasks;\r
\r
-import java.io.File;\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-import java.util.StringTokenizer;\r
-\r
-public class IncludePath implements NestElement {\r
- /**\r
- IncludePath nested element Class\r
- class member\r
- -name : name of include path \r
- -file : name of file including include path\r
- **/\r
- private String path = "";\r
- private File file;\r
- private List<String> nameList = new ArrayList<String>();\r
- \r
- /**\r
- get class member "file"\r
-\r
- @returns The File object\r
- **/\r
- public File getFile() {\r
- return this.file;\r
- }\r
-\r
- /**\r
- set class member "file"\r
-\r
- @param file The name of include path\r
- **/\r
- public void setFile(File file) {\r
- this.file = file;\r
- }\r
- \r
- /**\r
- get class member "file"\r
-\r
- @returns The name of include path\r
- **/\r
- public String getPath() {\r
- return this.path;\r
- }\r
- \r
- /**\r
- get class member "name"\r
-\r
- @returns The name of include path\r
- **/\r
- public String getName() {\r
- return this.path;\r
- }\r
- \r
- /**\r
- set class member "name"\r
-\r
- @param name The name of include path\r
- **/\r
- public void setName(String name){\r
- this.path = " -I " + name;\r
- }\r
-\r
- /**\r
- set class member "path"\r
-\r
- @param name name of file including include paths \r
- **/\r
- public void setPath(String name) {\r
- this.path = " -I " + name;\r
- }\r
-\r
- /**\r
- override Object.toString()\r
-\r
- @returns name of file including include paths \r
- **/\r
+/**\r
+ IncludePath class is generally used to pass arguments with "-i" before each\r
+ of them.\r
+ **/\r
+public class IncludePath extends NestElement {\r
public String toString() {\r
- return getPath();\r
- }\r
- \r
- /**\r
- set class member "list"\r
-\r
- @param fileNameList name list of include paths, sperated by space, tab,\r
- comma or semi-comma\r
- **/\r
- public void setList(String fileNameList) {\r
- if (fileNameList != null && fileNameList.length() > 0) {\r
- StringTokenizer tokens = new StringTokenizer(fileNameList, " \t,;", false);\r
- while (tokens.hasMoreTokens()) {\r
- String fileName = tokens.nextToken().trim();\r
- if (fileName.length() > 0) {\r
- this.nameList.add(fileName);\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- get class member "list"\r
-\r
- @returns The include paths list.\r
- **/\r
- public List<String> getList() {\r
- return nameList;\r
+ return super.toString(" -i ");\r
}\r
}\r
\r
\r
/**\r
Input class is defined to be as nested elements of other elements, to specify \r
- the path of file(s)\r
+ the path of file(s).\r
**/\r
-public class Input {\r
- private String filePath;\r
- \r
- public Input() {\r
- \r
- }\r
-\r
- /**\r
- Standard set method of ANT task, for "file" attribute\r
-\r
- @param path The path of a file\r
- **/\r
- public void setFile(String path) {\r
- filePath = path;\r
- }\r
-\r
- /**\r
- Standard get method of ANT task, for "file" attribute\r
-\r
- @returns The path of current specified file.\r
- **/\r
- public String getFile() {\r
- return filePath;\r
+public class Input extends NestElement {\r
+ public String toString() {\r
+ return super.toString(" -f ");\r
}\r
}\r
**/\r
package org.tianocore.framework.tasks;\r
\r
-import java.io.File;\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-import java.util.StringTokenizer;\r
-\r
-public class InputFile implements NestElement {\r
- /**\r
- InputFile nested element Class\r
- class member\r
- -name : name of input file \r
- -file : name of file including input files\r
- **/\r
- private String name = "";\r
- private File file;\r
- private List<String> nameList = new ArrayList<String>();\r
- \r
- /**\r
- get class member "name"\r
- @returns name parameter\r
- **/\r
- public String getName() {\r
- return this.name;\r
- }\r
-\r
- /**\r
- set class member "name"\r
- @param name name of input file \r
- **/\r
- public void setName(String name) {\r
- this.name = " " + name;\r
- }\r
-\r
+/**\r
+ InputFile is always used to pass arguments separated by space\r
+ **/\r
+public class InputFile extends NestElement {\r
public String toString() {\r
- return getName();\r
- }\r
- \r
- /**\r
- get class member "file"\r
- @returns file parameter\r
- **/\r
- public File getFile() {\r
- return this.file;\r
- }\r
-\r
- /**\r
- set class member "file"\r
- @param ext name of file including input files \r
- **/\r
- public void setFile(File file) {\r
- this.file = file;\r
- }\r
-\r
- /**\r
- set class member "list"\r
-\r
- @param fileNameList name list of include paths, sperated by space, tab,\r
- comma or semi-comma\r
- **/\r
- public void setList(String fileNameList) {\r
- if (fileNameList != null && fileNameList.length() > 0) {\r
- StringTokenizer tokens = new StringTokenizer(fileNameList, " \t,;", false);\r
- while (tokens.hasMoreTokens()) {\r
- String fileName = tokens.nextToken().trim();\r
- if (fileName.length() > 0) {\r
- this.nameList.add(fileName);\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- get class member "list"\r
-\r
- @returns The include paths list.\r
- **/\r
- public List<String> getList() {\r
- return nameList;\r
+ return super.toString(" ");\r
}\r
}\r
\r
// private members, use set/get to access them\r
//\r
private static final String cmdName = "MakeDeps";\r
- private String includePath = null;\r
private String depsFile = null;\r
private String subDir = null;\r
private boolean quietMode = true;\r
/// compose full tool path\r
///\r
if (toolPath == null || toolPath.length() == 0) {\r
- toolPath = "./" + cmdName;\r
+ toolPath = cmdName;\r
} else {\r
if (toolPath.endsWith("/") || toolPath.endsWith("\\")) {\r
toolPath = toolPath + cmdName;\r
} else {\r
- toolPath = toolPath + "/" + cmdName;\r
+ toolPath = toolPath + File.separator + cmdName;\r
}\r
}\r
\r
///\r
StringBuffer args = new StringBuffer(4096);\r
if (ignoreError) {\r
- args.append(" -ignorenotfound");\r
+ args.append(" -ignorenotfound ");\r
}\r
if (quietMode) {\r
- args.append(" -q");\r
+ args.append(" -q ");\r
}\r
if (subDir != null && subDir.length() > 0) {\r
args.append(" -s ");\r
///\r
/// compose source file arguments\r
///\r
- Iterator iterator = inputFileList.iterator();\r
- while (iterator.hasNext()) {\r
- Input inputFile = (Input)iterator.next();\r
- String inputFileString = cleanupPathName(inputFile.getFile());\r
- args.append(" -f ");\r
- args.append(inputFileString);\r
+ for (int i = 0, listLength = inputFileList.size(); i < listLength; ++i) {\r
+ args.append(inputFileList.get(i).toString());\r
}\r
\r
- ///\r
- /// compose search pathes argument\r
- ///\r
- StringBuffer includePathArg = new StringBuffer(4096);\r
- if (includePath != null && includePath.length() > 0) {\r
- StringTokenizer pathTokens = new StringTokenizer(includePath, ";");\r
- while (pathTokens.hasMoreTokens()) {\r
- String tmpPath = pathTokens.nextToken().trim();\r
- if (tmpPath.length() == 0) {\r
- continue;\r
- }\r
-\r
- includePathArg.append(" -i ");\r
- includePathArg.append(cleanupPathName(tmpPath));\r
- }\r
+ for (int i = 0, listLength = includePathList.size(); i < listLength; ++i) {\r
+ args.append(includePathList.get(i).toString());\r
}\r
- iterator = includePathList.iterator();\r
- while (iterator.hasNext()) {\r
- IncludePath path = (IncludePath)iterator.next();\r
- includePathArg.append(cleanupPathName(path.getPath()));\r
- }\r
- args.append(includePathArg);\r
\r
///\r
/// We don't need a real target. So just a "dummy" is given\r
///\r
args.append(" -target dummy");\r
args.append(" -o ");\r
- args.append(cleanupPathName(depsFile));\r
+ args.append(depsFile);\r
\r
///\r
/// prepare to execute the tool\r
\r
if (result != 0) {\r
EdkLog.log(EdkLog.EDK_INFO, "MakeDeps failed!");\r
- return;\r
+ throw new BuildException("MakeDeps: failed to generate dependency file!");\r
}\r
}\r
\r
@param dir The name of sub-directory in which source files will be scanned\r
**/\r
public void setSubDir(String dir) {\r
- subDir = dir;\r
+ subDir = cleanupPathName(dir);\r
}\r
\r
/**\r
return subDir;\r
}\r
\r
- /**\r
- Set method for "IncludePath" attribute\r
-\r
- @param path The name of include path\r
- **/\r
- public void setIncludePath(String path) {\r
- includePath = cleanupPathName(path);\r
- }\r
-\r
- /**\r
- Get method for "IncludePath" attribute\r
-\r
- @returns The name of include path\r
- **/\r
- public String getIncludePath() {\r
- return includePath;\r
- }\r
-\r
/**\r
Set method for "ExtraDeps" attribute\r
\r
@param deps The name of dependency file specified separately\r
**/\r
public void setExtraDeps(String deps) {\r
- extraDeps = deps;\r
+ extraDeps = cleanupPathName(deps);\r
}\r
\r
/**\r
return false;\r
}\r
\r
- ///\r
- /// If the source file(s) is newer than dependency list file, we need to\r
- /// re-generate the dependency list file\r
- ///\r
+ //\r
+ // If the source file(s) is newer than dependency list file, we need to\r
+ // re-generate the dependency list file\r
+ //\r
long depsFileTimeStamp = df.lastModified();\r
- Iterator iterator = inputFileList.iterator();\r
+ Iterator<Input> iterator = (Iterator<Input>)inputFileList.iterator();\r
while (iterator.hasNext()) {\r
- Input inputFile = (Input)iterator.next();\r
- File sf = new File(inputFile.getFile());\r
- if (sf.lastModified() > depsFileTimeStamp) {\r
- return false;\r
+ Input inputFile = iterator.next();\r
+ List<String> fileList = inputFile.getNameList();\r
+ for (int i = 0, length = fileList.size(); i < length; ++i) {\r
+ File sf = new File(fileList.get(i));\r
+ if (sf.lastModified() > depsFileTimeStamp) {\r
+ return false;\r
+ }\r
}\r
}\r
\r
- ///\r
- /// If the source files haven't been changed since last time the dependency\r
- /// list file was generated, we need to check each file in the file list to\r
- /// see if any of them is changed or not. If anyone of them is newer than\r
- /// the dependency list file, MakeDeps.exe is needed to run again.\r
- ///\r
+ //\r
+ // If the source files haven't been changed since last time the dependency\r
+ // list file was generated, we need to check each file in the file list to\r
+ // see if any of them is changed or not. If anyone of them is newer than\r
+ // the dependency list file, MakeDeps.exe is needed to run again.\r
+ //\r
LineNumberReader lineReader = null;\r
FileReader fileReader = null;\r
boolean ret = true;\r
\r
import java.io.File;\r
import java.util.List;\r
+import java.util.ArrayList;\r
+import java.io.FileReader;\r
+import java.io.BufferedReader;\r
+import java.util.StringTokenizer;\r
+\r
+import org.apache.tools.ant.types.DataType;\r
+import org.apache.tools.ant.types.Path;\r
+import org.apache.tools.ant.BuildException;\r
\r
/**\r
- Interface NestElement is just to define common interfaces for nested element\r
+ Interface NestElement is to define common interfaces for nested element\r
**/\r
-public interface NestElement {\r
+public class NestElement extends DataType {\r
+ //\r
+ // The name list. All the name strings got from setXXX methods will be put\r
+ // in here.\r
+ //\r
+ private List<String> nameList = new ArrayList<String>();\r
+\r
+ /**\r
+ Handle "name" attribute. No delimiter and special treatment are assumed.\r
+\r
+ @param name A single string value of "name" attribute \r
+ **/\r
+ public void setName(String name) {\r
+ if (name.length() > 0) {\r
+ nameList.add(name);\r
+ }\r
+ }\r
+\r
+ /**\r
+ Handle "list" attribute. The value of "list" is assumed as string \r
+ separated by space, tab, comma or semmicolon.\r
+\r
+ @param nameList The value of "list" separated by " \t,;"\r
+ **/\r
+ public void setList(String nameList) {\r
+ if (nameList.length() == 0) {\r
+ return;\r
+ }\r
+\r
+ StringTokenizer tokens = new StringTokenizer(nameList, " \t,;", false);\r
+ while (tokens.hasMoreTokens()) {\r
+ String name = tokens.nextToken().trim();\r
+ if (name.length() > 0) {\r
+ this.nameList.add(name);\r
+ }\r
+ }\r
+ }\r
+\r
+ /**\r
+ Handle "ListFile" attribute. The value of "ListFile" should be the path of\r
+ a file which contains name strings, one name per line.\r
+\r
+ @param listFileName The file path\r
+ **/\r
+ public void setListFile(String listFileName) {\r
+ FileReader fileReader = null;\r
+ BufferedReader in = null;\r
+ String str;\r
+\r
+ //\r
+ // Check if the file exists or not\r
+ // \r
+ File file = new File(listFileName);\r
+ if (!file.exists()) {\r
+ throw new BuildException("The file, " + file + " does not exist!"); \r
+ } \r
+\r
+ try {\r
+ fileReader = new FileReader(file);\r
+ in = new BufferedReader(fileReader);\r
+\r
+ //\r
+ // Read line by line\r
+ // \r
+ while((str = in.readLine()) != null){\r
+ str = str.trim();\r
+ if (str.length() == 0){\r
+ continue;\r
+ }\r
+\r
+ //getProject().replaceProperties(str);\r
+ nameList.add(str);\r
+ }\r
+ } catch (Exception e){\r
+ throw new BuildException(e.getMessage()); \r
+ } finally {\r
+ try {\r
+ //\r
+ // close the file\r
+ // \r
+ if (in != null) {\r
+ in.close();\r
+ }\r
+ if (fileReader != null) {\r
+ fileReader.close();\r
+ }\r
+ } catch (Exception e) {\r
+ throw new BuildException(e.getMessage()); \r
+ }\r
+ }\r
+ }\r
+\r
+ /**\r
+ Handle "file" attribute. The value of "file" should be a path.\r
+\r
+ @param file The path name of a file\r
+ **/\r
+ public void setFile(String file) {\r
+ setPath(file);\r
+ }\r
+\r
+ /**\r
+ Handle "path" attribute. The value of "path" may contain compound path\r
+ separator (/ or \) which should be cleaned up. Because the "path" string\r
+ will always be passed to external native program which may not handle \r
+ non-native path separator, the clean-up action is a must. And the value\r
+ of "path" may contains several path separated by space, tab, comma or\r
+ semmicolon. We need to split it and put each part in nameList.\r
+\r
+ @param path String value of a file system path\r
+ **/\r
+ public void setPath(String path) {\r
+ if (path.length() == 0) {\r
+ return;\r
+ }\r
+\r
+ //\r
+ // split the value of "path" into separated single path\r
+ // \r
+ StringTokenizer tokens = new StringTokenizer(path, " \t,;", false);\r
+ while (tokens.hasMoreTokens()) {\r
+ String pathName = tokens.nextToken().trim();\r
+ if (pathName.length() > 0) {\r
+ //\r
+ // Make clean the path string before storing it\r
+ // \r
+ this.nameList.add(cleanupPath(pathName));\r
+ }\r
+ }\r
+ }\r
+\r
+ /**\r
+ Handle "FileName" attribute. The value of "FileName" should be the path\r
+ of a file which contains path strings, one path per line.\r
+\r
+ @param pathFileName\r
+ **/\r
+ public void setPathFile(String pathFileName) {\r
+ FileReader fileReader = null;\r
+ BufferedReader in = null;\r
+ String path;\r
+\r
+ //\r
+ // Check if the file exists or not\r
+ // \r
+ File file = new File(pathFileName);\r
+ if (!file.exists()) {\r
+ throw new BuildException("The file, " + file + " does not exist!"); \r
+ } \r
+\r
+ try {\r
+ fileReader = new FileReader(file);\r
+ in = new BufferedReader(fileReader);\r
+\r
+ //\r
+ // Read the file line by line, skipping empty ones\r
+ // \r
+ while((path = in.readLine()) != null){\r
+ path = path.trim();\r
+ if (path.length() == 0){\r
+ continue;\r
+ }\r
+ //getProject().replaceProperties(path);\r
+\r
+ //\r
+ // Make clean the path string before storing it.\r
+ // \r
+ nameList.add(cleanupPath(path));\r
+ }\r
+ } catch (Exception e){\r
+ throw new BuildException(e.getMessage()); \r
+ } finally {\r
+ try {\r
+ //\r
+ // close the file\r
+ // \r
+ if (in != null) {\r
+ in.close();\r
+ }\r
+ if (fileReader != null) {\r
+ fileReader.close();\r
+ }\r
+ } catch (Exception e) {\r
+ throw new BuildException(e.getMessage()); \r
+ }\r
+ }\r
+ }\r
+\r
/**\r
- nested element Interface for up-casting \r
+ Return the name list.\r
+\r
+ @return List<String> The list contains the name(path) strings\r
**/\r
- \r
- public String getName();\r
+ public List<String> getNameList() {\r
+ return nameList;\r
+ }\r
+\r
+ /**\r
+ Compose and return the the name/path string without any delimiter. The trick\r
+ here is that it's actually used to return the value of nameList which\r
+ has just one name/string.\r
\r
- public void setName(String name);\r
+ @return String\r
+ **/\r
+ public String toString() {\r
+ return toString("");\r
+ }\r
+\r
+ /**\r
+ Compose and return the name/path string concatenated by leading "prefix".\r
+\r
+ @param prefix The string will be put before each name/string in nameList\r
+ \r
+ @return String The string concatenated with "prefix"\r
+ **/\r
+ public String toString(String prefix) {\r
+ StringBuffer string = new StringBuffer(1024);\r
+ int length = nameList.size();\r
\r
- public String toString();\r
+ for (int i = 0; i < length; ++i) {\r
+ string.append(prefix);\r
+ string.append(nameList.get(i));\r
+ }\r
\r
- public File getFile();\r
+ return string.toString();\r
+ }\r
\r
- public void setFile(File file);\r
+ //\r
+ // Remove any duplicated path separator or inconsistent path separator\r
+ //\r
+ private String cleanupPath(String path) {\r
+ String separator = "\\" + File.separator;\r
+ String duplicateSeparator = separator + "{2}";\r
\r
- public void setList(String fileNameList);\r
+ path = Path.translateFile(path);\r
+ path = path.replaceAll(duplicateSeparator, separator);\r
\r
- public List<String> getList();\r
+ return path;\r
+ }\r
}\r
**/\r
package org.tianocore.framework.tasks;\r
\r
-import java.io.File;\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-import java.util.StringTokenizer;\r
-\r
/**\r
SkipExt nested element Class\r
- class member\r
- -name : extension name of skiped file \r
- -file : name of file including ext\r
**/\r
-public class SkipExt implements NestElement {\r
- private String name = "";\r
- private File file;\r
- private List<String> nameList = new ArrayList<String>();\r
- \r
- /**\r
- get class member "name"\r
- @returns name parameter\r
- **/\r
- public String getName() {\r
- return this.name;\r
- }\r
- /**\r
- set class member "name"\r
- @param name extension name of skiped file \r
- **/\r
- public void setName(String name) {\r
- this.name = " -skipext " + name;\r
- }\r
-\r
+public class SkipExt extends NestElement {\r
public String toString() {\r
- return getName();\r
- }\r
-\r
- /**\r
- get class member "file"\r
- @returns file parameter\r
- **/\r
- public File getFile() {\r
- return this.file;\r
- }\r
- /**\r
- set class member "file"\r
- @param name of file including ext \r
- **/\r
- public void setFile(File file) {\r
- this.file = file;\r
- }\r
-\r
- public void setList(String fileNameList) {\r
- if (fileNameList != null && fileNameList.length() > 0) {\r
- StringTokenizer tokens = new StringTokenizer(fileNameList, " \t,;", false);\r
- while (tokens.hasMoreTokens()) {\r
- String fileName = tokens.nextToken().trim();\r
- if (fileName.length() > 0) {\r
- this.nameList.add(fileName);\r
- }\r
- }\r
- }\r
- }\r
-\r
- public List<String> getList() {\r
- return nameList;\r
+ return super.toString(" -skipext ");\r
}\r
- \r
}\r
\r
**/\r
package org.tianocore.framework.tasks;\r
\r
+import java.io.File;\r
import java.util.*;\r
+\r
+import org.apache.tools.ant.BuildException;\r
import org.apache.tools.ant.Project;\r
import org.apache.tools.ant.Task;\r
-import org.apache.tools.ant.BuildException;\r
import org.apache.tools.ant.taskdefs.Execute;\r
import org.apache.tools.ant.taskdefs.LogStreamHandler;\r
import org.apache.tools.ant.types.Commandline;\r
\r
private String outputDatabase = "";\r
\r
- private List<Object> databaseList = new ArrayList<Object>();\r
+ private List<Database> databaseList = new ArrayList<Database>();\r
\r
- private List<Object> inputFileList = new ArrayList<Object>();\r
+ private List<InputFile> inputFileList = new ArrayList<InputFile>();\r
\r
///\r
/// parse options newDatabase -- "ture/false" unquoteString -- "ture/false"\r
\r
private String unquotedString = "";\r
\r
- private List<Object> includePathList = new ArrayList<Object>();\r
+ private List<IncludePath> includePathList = new ArrayList<IncludePath>();\r
\r
///\r
/// scan options ignoreNotFound -- "ture/false"\r
///\r
private String ignoreNotFound = "";\r
\r
- private List<Object> skipExtList = new ArrayList<Object>();\r
+ private List<SkipExt> skipExtList = new ArrayList<SkipExt>();\r
\r
///\r
/// dump options\r
if (path == null) {\r
command = "StrGather";\r
} else {\r
- command = path + "/" + "StrGather";\r
+ command = path + File.separator + "StrGather";\r
}\r
\r
///\r
/// transfer nested elements into string\r
///\r
- String databases = list2Str(databaseList, "-db");\r
- String skipExts = list2Str(skipExtList, "-skipext");\r
- String includePaths = list2Str(includePathList, "-I");\r
- String inputFiles = list2Str(inputFileList, "");\r
+ String databases = list2Str(databaseList);\r
+ String skipExts = list2Str(skipExtList);\r
+ String includePaths = list2Str(includePathList);\r
+ String inputFiles = list2Str(inputFileList);\r
\r
///\r
/// assemble argument\r
}\r
\r
/**\r
- transfer List to String\r
- \r
- @param list nested element list\r
- @param tag interval tag of parameter\r
+ Compose the content in each NestElement into a single string.\r
\r
- @returns string line of parameters\r
+ @param list The NestElement list\r
+ \r
+ @return String\r
**/\r
- private String list2Str(List list, String tag) {\r
- ///\r
- /// string line for return\r
- ///\r
- String paraStr = "";\r
- ///\r
- /// nested element in list\r
- ///\r
- NestElement element;\r
- ///\r
- /// iterator of nested element list\r
- ///\r
- Iterator elementIter = list.iterator();\r
- ///\r
- /// string parameter list\r
- ///\r
- List<Object> strList = new ArrayList<Object>();\r
-\r
- while (elementIter.hasNext()) {\r
- element = (NestElement) elementIter.next();\r
- if (null != element.getFile()) {\r
- ///\r
- /// nested element include file\r
- ///\r
- FileParser.loadFile(project, strList, element.getFile(), tag);\r
- } \r
-\r
- if (element.getName().length() > 0) {\r
- ///\r
- /// nested element include name \r
- ///\r
- paraStr = paraStr + " " + element.getName();\r
- }\r
-\r
- List<String> nameList = element.getList();\r
- if (nameList.size() > 0) {\r
- Iterator nameIter = nameList.iterator();\r
- while (nameIter.hasNext()) {\r
- paraStr = paraStr + " " + tag + " " + (String)nameIter.next();\r
- }\r
- }\r
- }\r
- ///\r
- /// iterator of string parameter list\r
- ///\r
- Iterator strIter = strList.iterator();\r
- while (strIter.hasNext()) {\r
- paraStr = paraStr + " " + strIter.next();\r
+ private String list2Str(List list) {\r
+ int listLength = list.size();\r
+ String str = "";\r
+ for (int i = 0; i < listLength; ++i) {\r
+ NestElement e = (NestElement)list.get(i);\r
+ str += e.toString();\r
}\r
- return paraStr;\r
- }\r
\r
+ return str;\r
+ }\r
}\r
String toolName = "";\r
List<Object> toolArgList = new ArrayList<Object>();\r
String outputPath;\r
- String outPutFileName ;\r
+ File outputFile ;\r
List<Input> inputFiles = new ArrayList<Input>();\r
\r
/**\r
@param buffer The buffer to put the result with alignment\r
**/\r
public void toBuffer (DataOutputStream buffer){\r
- File OutputFile;\r
- byte data;\r
-\r
///\r
/// call extern tool\r
///\r
///\r
/// check if file exist\r
///\r
- OutputFile = new File (this.outPutFileName);\r
- long fileLen = OutputFile.length();\r
- if (!OutputFile.exists()) {\r
- throw new BuildException("The file " + outPutFileName + " does not exist!\n");\r
+ //File OutputFile = new File (this.outPutFileName);\r
+ if (!outputFile.exists()) {\r
+ throw new BuildException("The file " + outputFile.getPath() + " does not exist!\n");\r
}\r
\r
///\r
/// Read output file and write it's cotains to buffer\r
///\r
+ FileInputStream fs = null;\r
+ DataInputStream in = null;\r
try {\r
- FileInputStream fs = new FileInputStream (this.outPutFileName);\r
- DataInputStream In = new DataInputStream (fs);\r
-\r
- int i = 0;\r
- while (i < fileLen) {\r
- data = In.readByte();\r
- buffer.writeByte(data);\r
- i ++;\r
- }\r
+ fs = new FileInputStream (outputFile);\r
+ in = new DataInputStream (fs);\r
+\r
+\r
+ int fileLen = (int)outputFile.length();\r
+ byte[] data = new byte[fileLen];\r
+ in.read(data);\r
+ buffer.write(data, 0, fileLen);\r
\r
///\r
/// 4 byte alignment\r
fileLen++;\r
buffer.writeByte(0);\r
}\r
- In.close();\r
-\r
} catch (Exception e) {\r
System.out.print(e.getMessage());\r
throw new BuildException("Tool call, toBuffer failed!\n");\r
+ } finally {\r
+ try {\r
+ if (in != null) {\r
+ in.close();\r
+ }\r
+ if (fs != null) {\r
+ fs.close();\r
+ }\r
+ } catch (Exception e) {\r
+ System.out.println("WARNING: Cannot close " + outputFile.getPath());\r
+ }\r
}\r
}\r
\r
///\r
/// input files for tools\r
///\r
- argument = argument + "-i ";\r
+ argument += " -i ";\r
while (inputIter.hasNext()) {\r
file = (Input)inputIter.next();\r
- argument = argument + file.getFile() + " ";\r
+ argument += file.toString(" ");\r
}\r
\r
- outPutFileName = outputPath + File.separatorChar + (new File(file.getFile())).getName() + ".crc";\r
- argument = argument + " -o " + outPutFileName; \r
-\r
try {\r
+ outputFile = File.createTempFile("temp", ".crc", new File(outputPath));\r
+ argument = argument + " -o " + outputFile.getPath();\r
\r
///\r
/// execute command line\r
private String vfrFile = "";\r
private String vfrFileName = "";\r
\r
- private List<Object> includepathList = new ArrayList<Object>();\r
+ private List<IncludePath> includepathList = new ArrayList<IncludePath>();\r
\r
/**\r
get class member of createList file\r
List<Object> includePath = new ArrayList<Object>(); \r
String incPath = ""; \r
\r
- int count = includepathList.size(); \r
- IncludePath path;\r
+ int count = includepathList.size(); \r
for (int i = 0; i < count; i++) {\r
- path = (IncludePath) includepathList.get(i);\r
- if (path.getFile() != null) {\r
- FileParser.loadFile( project,includePath,path.getFile(), "-I"); \r
- }\r
- }\r
- for (int i = 0; i < count; i++) {\r
- incPath = incPath + " " + includepathList.get(i);\r
- }\r
- count = includePath.size();\r
- for (int i = 0; i < count; i++) {\r
- incPath = incPath + " " + includePath.get(i);\r
+ incPath += includepathList.get(i).toString();\r
}\r
+\r
String argument = this.createIfrBinFile +\r
this.processerArg + \r
incPath +\r