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