]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/GenBuild/org/tianocore/build/toolchain/ConfigReader.java
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
.apache
.tools
.ant
.Project
;
19 import org
.tianocore
.build
.exception
.GenBuildException
;
21 import java
.io
.BufferedReader
;
23 import java
.io
.FileReader
;
24 import java
.util
.ArrayList
;
25 import java
.util
.List
;
29 ConfigReader is used to read tool chain config file with flat format. Comments
30 is line starting with character '#'.
34 public class ConfigReader
{
37 Parse specified tool chain definition file.
39 @param filename The config file name with full path
41 @return String[][] The definition array
43 public static synchronized String
[][] parse(Project prj
, String filename
) throws GenBuildException
{
44 return parse(prj
, new File(filename
));
48 Get all definitions in config file. the config file format is flat
49 with "A=B". If line started with '#' looks as comments.
51 @param configFile The config file
53 @return String[][] The variables defined in the config file
55 @throws GenBuildException
56 Config file's format is not valid
58 public static synchronized String
[][] parse(Project prj
, File configFile
) throws GenBuildException
{
59 List
<String
> keyList
= new ArrayList
<String
>(256);
60 List
<String
> valueList
= new ArrayList
<String
>(256);
64 FileReader reader
= new FileReader(configFile
);
65 BufferedReader in
= new BufferedReader(reader
);
68 while ((str
= in
.readLine()) != null) {
72 // skip empty line, comment (start with '#')
74 if (str
.length() == 0 || str
.startsWith("#")) {
79 // stop if the definition line is not in "name=value" form
82 if ((index
= str
.indexOf('=')) <= 0) {
83 throw new GenBuildException("ERROR Processing file ["
84 + configFile
.getAbsolutePath()
85 + "] (line " + lines
+ ").\n");
89 // look as line "A = B"
91 keyList
.add(str
.substring(0, index
).trim());
93 valueList
.add(prj
.replaceProperties(str
.substring(index
+ 1).trim()));
95 valueList
.add(str
.substring(index
+ 1).trim());
98 } catch (Exception ex
) {
99 GenBuildException e
= new GenBuildException("ERROR Processing file ["
100 + configFile
.getAbsolutePath()
101 + "] (line " + lines
+ ").\n" + ex
.getMessage());
102 e
.setStackTrace(ex
.getStackTrace());
106 String
[][] definitions
= new String
[2][keyList
.size()];
107 definitions
[0] = (String
[])keyList
.toArray(definitions
[0]);
108 definitions
[1] = (String
[])valueList
.toArray(definitions
[1]);