]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/global/DpFile.java
Change GenBuildLogger format.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / global / DpFile.java
1 /** @file
2 This file is used to define class which represents dependency file in ANT task
3
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14 package org.tianocore.build.global;
15
16 import org.apache.tools.ant.types.DataType;
17 import org.apache.tools.ant.types.Path;
18
19 import java.io.File;
20 import java.io.FileReader;
21 import java.io.IOException;
22 import java.io.LineNumberReader;
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.regex.Matcher;
26 import java.util.regex.Pattern;
27
28 /**
29 DpFile is a ANT DataType which can be used to specify dependency files from
30 a file list file, from file list string separated by space, comma or semi-comma,
31 or from file name with absolute path
32 **/
33 public class DpFile extends DataType {
34 ///
35 /// keep the list of files path
36 ///
37 private List<String> nameList = new ArrayList<String>();
38
39 /**
40 Empty constructor just in case
41 **/
42 public DpFile() {
43 }
44
45 /**
46 Empty execute method of ANT task, just in case
47 **/
48 public void execute() {
49 }
50
51 /**
52 Standard set method of ANT task/datatype, for ListFile attribute. It simply
53 fetch one file path a line from specified list file, and put them in nameList
54
55 @param fileListFile file which contains a file list, one file a line,
56 with full path
57 **/
58 public void setListFile(String fileListFile) {
59 File file = new File(fileListFile);
60 if (!file.exists()) {
61 return;
62 }
63
64 try {
65 FileReader fileReader = new FileReader(file);
66 LineNumberReader lineReader = new LineNumberReader(fileReader);
67
68 String filePath = null;
69 while ((filePath = lineReader.readLine()) != null) {
70 filePath = filePath.trim();
71 if (filePath.length() == 0) {
72 continue;
73 }
74 this.nameList.add(filePath);
75 }
76
77 lineReader.close();
78 fileReader.close();
79 } catch (IOException e) {
80 System.out.println (e.getMessage());
81 }
82 }
83
84 /**
85 Standard set method of ANT task/datatype, for List attribute.
86
87 @param fileList string with file pathes separated by space, comma,
88 or semi-comma
89 **/
90 public void setList(String fileList) {
91 //
92 // space, comma or semi-comma separated files list
93 //
94 Pattern pattern = Pattern.compile("([^ ,;\n\r]++)[ ,;\n\r]*+");
95 Matcher matcher = pattern.matcher(fileList);
96
97 while (matcher.find()) {
98 //
99 // keep each file name before " ,;\n\r"
100 //
101 String filePath = fileList.substring(matcher.start(1), matcher.end(1)).trim();
102 if (filePath.length() == 0) {
103 continue;
104 }
105 nameList.add(Path.translateFile(filePath));
106 }
107
108 }
109
110 /**
111 Standard set method of ANT task/datatype, for Name attribute.
112
113 @param fileName string of a file full path
114 **/
115 public void setName(String fileName) {
116 this.nameList.add(fileName);
117 }
118
119 /**
120 Fetch the file name list.
121
122 @returns A string list which contains file names specified to check dependnecy
123 **/
124 public List<String> getList() {
125 return this.nameList;
126 }
127 }
128
129