]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - Tools/Java/Source/GenBuild/org/tianocore/build/toolchain/ConfigReader.java
1. Update to just keep several line JAVA related msg; 2. Remove file PropertyManager...
[mirror_edk2.git] / Tools / Java / Source / GenBuild / org / tianocore / build / toolchain / ConfigReader.java
... / ...
CommitLineData
1/** @file\r
2 ConfigReader class.\r
3 \r
4 ConfigReader is used to read tool chain config file with flat format. \r
5 \r
6Copyright (c) 2006, Intel Corporation\r
7All rights reserved. This program and the accompanying materials\r
8are licensed and made available under the terms and conditions of the BSD License\r
9which accompanies this distribution. The full text of the license may be found at\r
10http://opensource.org/licenses/bsd-license.php\r
11\r
12THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14**/\r
15package org.tianocore.build.toolchain;\r
16\r
17import org.tianocore.build.exception.GenBuildException;\r
18\r
19import java.io.BufferedReader;\r
20import java.io.File;\r
21import java.io.FileReader;\r
22import java.util.ArrayList;\r
23import java.util.List;\r
24\r
25/**\r
26 \r
27 ConfigReader is used to read tool chain config file with flat format. Comments\r
28 is line starting with character '#'.\r
29 \r
30 @since GenBuild 1.0\r
31**/\r
32public class ConfigReader {\r
33\r
34 /**\r
35 Parse specified tool chain definition file.\r
36 \r
37 @param filename The config file name with full path\r
38\r
39 @return String[][] The definition array\r
40 **/\r
41 public static synchronized String[][] parse(String filename) throws GenBuildException {\r
42 return parse(new File(filename));\r
43 }\r
44\r
45 /**\r
46 Get all definitions in config file. the config file format is flat\r
47 with "A=B". If line started with '#' looks as comments. \r
48 \r
49 @param configFile The config file\r
50\r
51 @return String[][] The variables defined in the config file\r
52\r
53 @throws GenBuildException\r
54 Config file's format is not valid\r
55 **/\r
56 public static synchronized String[][] parse(File configFile) throws GenBuildException {\r
57 List<String> keyList = new ArrayList<String>(256);\r
58 List<String> valueList = new ArrayList<String>(256);\r
59 int lines = 0;\r
60\r
61 try {\r
62 FileReader reader = new FileReader(configFile);\r
63 BufferedReader in = new BufferedReader(reader);\r
64 String str;\r
65\r
66 while ((str = in.readLine()) != null) {\r
67 ++lines;\r
68 str = str.trim();\r
69 //\r
70 // skip empty line, comment (start with '#') \r
71 //\r
72 if (str.length() == 0 || str.startsWith("#")) {\r
73 continue;\r
74 }\r
75\r
76 //\r
77 // stop if the definition line is not in "name=value" form\r
78 // \r
79 int index;\r
80 if ((index = str.indexOf('=')) <= 0) {\r
81 throw new GenBuildException("ERROR Processing file [" \r
82 + configFile.getAbsolutePath() \r
83 + "] (line " + lines + ").\n");\r
84 }\r
85\r
86 //\r
87 // look as line "A = B"\r
88 //\r
89 keyList.add(str.substring(0, index).trim());\r
90 valueList.add(str.substring(index + 1).trim());\r
91 }\r
92 } catch (Exception ex) {\r
93 GenBuildException e = new GenBuildException("ERROR Processing file [" \r
94 + configFile.getAbsolutePath() \r
95 + "] (line " + lines + ").\n" + ex.getMessage());\r
96 e.setStackTrace(ex.getStackTrace());\r
97 throw e;\r
98 }\r
99\r
100 String[][] definitions = new String[2][keyList.size()];\r
101 definitions[0] = (String[])keyList.toArray(definitions[0]);\r
102 definitions[1] = (String[])valueList.toArray(definitions[1]);\r
103\r
104 return definitions;\r
105 }\r
106}\r
107\r
108\r