]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/toolchain/ConfigReader.java
0472265d399f0194b103a2745521ee8cee9100b2
4 ConfigReader is used to read tool chain config file with flat format.
6 Copyright (c) 2006, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 package org
.tianocore
.build
.toolchain
;
17 import org
.tianocore
.build
.exception
.EdkException
;
19 import java
.io
.BufferedReader
;
21 import java
.io
.FileReader
;
22 import java
.util
.ArrayList
;
23 import java
.util
.List
;
27 ConfigReader is used to read tool chain config file with flat format. Comments
28 is line starting with character '#'.
32 public class ConfigReader
{
34 private static String confPath
= ".";
38 Public construct method.
40 public ConfigReader () {
44 Default filepath is ".".
46 @param filename the config file name like "target.txt"
47 @return the variables defined in file
49 public static synchronized String
[][] parse(String filename
) throws EdkException
{
50 return parse(confPath
, filename
);
54 Get all variables defined in config file. the config file format is flat
55 with "A=B". If line started with '#' looks as comments.
57 @param confPath the path of config file
58 @param filename the file name of the config file
59 @return the variables defined in the config file
60 @throws BuildException
61 Config file's format is not valid
63 public static synchronized String
[][] parse(String confPath
, String filename
) throws EdkException
{
64 //Map<String, String> map = new TreeMap<String,String>(comparator);
65 List
<String
> keyList
= new ArrayList
<String
>(256);
66 List
<String
> valueList
= new ArrayList
<String
>(256);
69 File file
= new File(confPath
+ File
.separatorChar
+ filename
);
70 FileReader reader
= new FileReader(file
);
71 BufferedReader in
= new BufferedReader(reader
);
74 while ((str
= in
.readLine()) != null) {
77 // if str is empty line, comments (start with '#'),
78 // without '=', or start with '='
81 if (str
.length() == 0 || str
.startsWith("#") ||
82 (index
= str
.indexOf('=')) <= 0) {
86 // look as line "A = B"
88 keyList
.add(str
.substring(0, index
).trim());
89 valueList
.add(str
.substring(index
+ 1).trim());
91 } catch (Exception e
) {
92 throw new EdkException("Process file [" + filename
+ "] error. \n" + e
.getMessage());
95 String
[][] definitions
= new String
[2][keyList
.size()];
96 definitions
[0] = (String
[])keyList
.toArray(definitions
[0]);
97 definitions
[1] = (String
[])valueList
.toArray(definitions
[1]);
102 public static synchronized ToolChainMap
parseToolChainConfig(File ConfigFile
) throws EdkException
{
103 ToolChainMap map
= new ToolChainMap();
106 FileReader reader
= new FileReader(ConfigFile
);
107 BufferedReader in
= new BufferedReader(reader
);
110 while ((str
= in
.readLine()) != null) {
113 // if str is empty line, comments (start with '#'),
114 // without '=', or start with '='
117 if (str
.length() == 0 || str
.startsWith("#") ||
118 (index
= str
.indexOf('=')) <= 0) {
122 // look as line "A = B"
124 String key
= str
.substring(0, index
).trim().toUpperCase();
125 String value
= str
.substring(index
+ 1).trim();
128 } catch (Exception e
) {
129 throw new EdkException("Process file [" + ConfigFile
.getAbsolutePath() + "] error. \n" + e
.getMessage());