/** @file\r
ConfigReader class.\r
-\r
- ConfigReader is used to read tool chain config file with flat format.\r
-\r
+ \r
+ ConfigReader is used to read tool chain config file with flat format. \r
+ \r
Copyright (c) 2006, Intel Corporation\r
All rights reserved. This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
import java.util.List;\r
\r
/**\r
-\r
+ \r
ConfigReader is used to read tool chain config file with flat format. Comments\r
is line starting with character '#'.\r
-\r
+ \r
@since GenBuild 1.0\r
**/\r
public class ConfigReader {\r
\r
- private static String confPath = ".";\r
-\r
-\r
- /**\r
- Public construct method.\r
- **/\r
- public ConfigReader () {\r
- }\r
-\r
/**\r
- Default filepath is ".".\r
+ Parse specified tool chain definition file.\r
+ \r
+ @param filename The config file name with full path\r
\r
- @param filename the config file name like "target.txt"\r
- @return the variables defined in file\r
+ @return String[][] The definition array\r
**/\r
public static synchronized String[][] parse(String filename) throws EdkException {\r
- return parse(confPath, filename);\r
+ return parse(new File(filename));\r
}\r
\r
/**\r
- Get all variables defined in config file. the config file format is flat\r
- with "A=B". If line started with '#' looks as comments.\r
-\r
- @param confPath the path of config file\r
- @param filename the file name of the config file\r
- @return the variables defined in the config file\r
- @throws BuildException\r
- Config file's format is not valid\r
+ Get all definitions in config file. the config file format is flat\r
+ with "A=B". If line started with '#' looks as comments. \r
+ \r
+ @param configFile The config file\r
+\r
+ @return String[][] The variables defined in the config file\r
+\r
+ @throws EdkException\r
+ Config file's format is not valid\r
**/\r
- public static synchronized String[][] parse(String confPath, String filename) throws EdkException {\r
- //Map<String, String> map = new TreeMap<String,String>(comparator);\r
+ public static synchronized String[][] parse(File configFile) throws EdkException {\r
List<String> keyList = new ArrayList<String>(256);\r
List<String> valueList = new ArrayList<String>(256);\r
+ int lines = 0;\r
\r
try {\r
- File file = new File(confPath + File.separatorChar + filename);\r
- FileReader reader = new FileReader(file);\r
+ FileReader reader = new FileReader(configFile);\r
BufferedReader in = new BufferedReader(reader);\r
String str;\r
\r
while ((str = in.readLine()) != null) {\r
+ ++lines;\r
str = str.trim();\r
//\r
- // if str is empty line, comments (start with '#'),\r
- // without '=', or start with '='\r
+ // skip empty line, comment (start with '#') \r
//\r
- int index;\r
- if (str.length() == 0 || str.startsWith("#") ||\r
- (index = str.indexOf('=')) <= 0) {\r
+ if (str.length() == 0 || str.startsWith("#")) {\r
continue;\r
}\r
+\r
+ //\r
+ // stop if the definition line is not in "name=value" form\r
+ // \r
+ int index;\r
+ if ((index = str.indexOf('=')) <= 0) {\r
+ throw new EdkException("ERROR Processing file [" + configFile.getAbsolutePath() \r
+ + "] (line " + lines + ").\n");\r
+ }\r
+\r
//\r
// look as line "A = B"\r
//\r
valueList.add(str.substring(index + 1).trim());\r
}\r
} catch (Exception e) {\r
- throw new EdkException("ERROR Processing file [" + filename + "].\n" + e.getMessage());\r
+ throw new EdkException("ERROR Processing file [" + configFile.getAbsolutePath() \r
+ + "] (line " + lines + ").\n" + e.getMessage());\r
}\r
\r
String[][] definitions = new String[2][keyList.size()];\r
\r
return definitions;\r
}\r
-\r
- public static synchronized ToolChainMap parseToolChainConfig(File ConfigFile) throws EdkException {\r
- ToolChainMap map = new ToolChainMap();\r
-\r
- try {\r
- FileReader reader = new FileReader(ConfigFile);\r
- BufferedReader in = new BufferedReader(reader);\r
- String str;\r
-\r
- while ((str = in.readLine()) != null) {\r
- str = str.trim();\r
- //\r
- // if str is empty line, comments (start with '#'),\r
- // without '=', or start with '='\r
- //\r
- int index;\r
- if (str.length() == 0 || str.startsWith("#") ||\r
- (index = str.indexOf('=')) <= 0) {\r
- continue;\r
- }\r
- //\r
- // look as line "A = B"\r
- //\r
- String key = str.substring(0, index).trim().toUpperCase();\r
- String value = str.substring(index + 1).trim();\r
- map.put(key, value);\r
- }\r
- } catch (Exception e) {\r
- throw new EdkException("ERROR Processing file [" + ConfigFile.getAbsolutePath() + "].\n" + e.getMessage());\r
- }\r
-\r
- return map;\r
- }\r
}\r
\r
\r