]>
git.proxmox.com Git - mirror_edk2.git/blob - ConfigReader.java
fa1fc239f4ffd26d6ff1637176aa77503fd85a6f
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
.GenBuildException
;
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
{
35 Parse specified tool chain definition file.
37 @param filename The config file name with full path
39 @return String[][] The definition array
41 public static synchronized String
[][] parse(String filename
) throws GenBuildException
{
42 return parse(new File(filename
));
46 Get all definitions in config file. the config file format is flat
47 with "A=B". If line started with '#' looks as comments.
49 @param configFile The config file
51 @return String[][] The variables defined in the config file
53 @throws GenBuildException
54 Config file's format is not valid
56 public static synchronized String
[][] parse(File configFile
) throws GenBuildException
{
57 List
<String
> keyList
= new ArrayList
<String
>(256);
58 List
<String
> valueList
= new ArrayList
<String
>(256);
62 FileReader reader
= new FileReader(configFile
);
63 BufferedReader in
= new BufferedReader(reader
);
66 while ((str
= in
.readLine()) != null) {
70 // skip empty line, comment (start with '#')
72 if (str
.length() == 0 || str
.startsWith("#")) {
77 // stop if the definition line is not in "name=value" form
80 if ((index
= str
.indexOf('=')) <= 0) {
81 throw new GenBuildException("ERROR Processing file ["
82 + configFile
.getAbsolutePath()
83 + "] (line " + lines
+ ").\n");
87 // look as line "A = B"
89 keyList
.add(str
.substring(0, index
).trim());
90 valueList
.add(str
.substring(index
+ 1).trim());
92 } catch (Exception ex
) {
93 GenBuildException e
= new GenBuildException("ERROR Processing file ["
94 + configFile
.getAbsolutePath()
95 + "] (line " + lines
+ ").\n" + ex
.getMessage());
96 e
.setStackTrace(ex
.getStackTrace());
100 String
[][] definitions
= new String
[2][keyList
.size()];
101 definitions
[0] = (String
[])keyList
.toArray(definitions
[0]);
102 definitions
[1] = (String
[])valueList
.toArray(definitions
[1]);