summaryrefslogtreecommitdiff
path: root/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/FileParser.java
blob: cc48b71dabd6f09a96e6f2d64d801eca807bef71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/** @file
 FileParser class.

 FileParser class is to parse file which contains the list of file name and 
 add those files to list.
  
 
 Copyright (c) 2006, Intel Corporation
 All rights reserved. This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
 http://opensource.org/licenses/bsd-license.php
 
 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

 **/
package org.tianocore.framework.tasks;
import java.io.*;
import java.util.List;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;

/**
  FileParser class.

  FileParser class is to parse file which contains the list of file name and 
  add those files to list.
**/
public class  FileParser {
    /**
      loadFile
     
      This function is to add files to array from input file which contains the 
      files list.
      @param  project  The current project.
      @param  list     File array.
      @param  file     File which contains the file list.
      @param  tag      Target of architecture.
      @throws BuildException
    **/
    public static synchronized void loadFile(Project project, List<Object> list, File file, String tag) throws BuildException{
        FileReader fileReader;
        BufferedReader in;
        String str;
        
        if (!file.exists()) {
            throw new BuildException("The file, " + file + " does not exist!");           
        } 
        try {
            fileReader = new FileReader(file);
            in = new BufferedReader(fileReader);
            while((str=in.readLine())!= null){
                if (str.trim()==""){
                    continue;
                }
                str = project.replaceProperties(str);
                if (str.trim().substring(0,2).equalsIgnoreCase(tag)) {
                    list.add(str.trim());
                } else {
                    list.add(tag + " " + str.trim());
                }
                
            }
        } catch (Exception e){
            System.out.println(e.getMessage());
            
        }
    }
    
}