]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/Cpptasks/net/sf/antcontrib/cpptasks/userdefine/UserDefineDef.java
6c03e73919840d1d6693bdef405ee62b74268d01
[mirror_edk2.git] / Tools / Source / Cpptasks / net / sf / antcontrib / cpptasks / userdefine / UserDefineDef.java
1 /*
2 *
3 * Copyright 2002-2006 The Ant-Contrib project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package net.sf.antcontrib.cpptasks.userdefine;
18
19 import java.io.BufferedReader;
20 import java.io.File;
21 import java.io.FileReader;
22 import java.util.Iterator;
23 import java.util.LinkedHashSet;
24 import java.util.Set;
25 import java.util.Vector;
26
27 import org.apache.tools.ant.BuildException;
28 import org.apache.tools.ant.Project;
29
30 import net.sf.antcontrib.cpptasks.ProcessorDef;
31 import net.sf.antcontrib.cpptasks.types.ConditionalPath;
32 import net.sf.antcontrib.cpptasks.types.IncludePath;
33 import net.sf.antcontrib.cpptasks.types.LibrarySet;
34
35 public class UserDefineDef extends ProcessorDef{
36
37 public UserDefineDef () {}
38
39 private String type = "CC";
40
41 private String family = "MSFT";
42
43 private String cmd;
44
45 private String includepathDelimiter;
46
47 private String outputDelimiter;
48
49 private File workdir;
50
51 private Vector includePaths= new Vector();
52
53 private String outputFile;
54
55 private Vector _libset = new Vector();
56
57 public void addLibset(LibrarySet libset) {
58 if (isReference()) {
59 throw noChildrenAllowed();
60 }
61 if (libset == null) {
62 throw new NullPointerException("libset");
63 }
64
65 _libset.add(libset);
66 }
67
68 public void execute() throws org.apache.tools.ant.BuildException {
69 throw new org.apache.tools.ant.BuildException(
70 "Not an actual task, but looks like one for documentation purposes");
71 }
72
73
74 public void addConfiguredArgument(UserDefineArgument arg) {
75 if (isReference()) {
76 throw noChildrenAllowed();
77 }
78 addConfiguredProcessorArg(arg);
79 }
80
81 /**
82 * Creates an include path.
83 */
84 public IncludePath createIncludePath() {
85 Project p = getProject();
86 if (p == null) {
87 throw new java.lang.IllegalStateException("project must be set");
88 }
89 if (isReference()) {
90 throw noChildrenAllowed();
91 }
92 IncludePath path = new IncludePath(p);
93 includePaths.addElement(path);
94 return path;
95 }
96
97
98 /**
99 * Add a <includepath> if specify the file attribute
100 *
101 * @throws BuildException
102 * if the specify file not exist
103 */
104 protected void loadFile(Vector activePath, File file) throws BuildException {
105 FileReader fileReader;
106 BufferedReader in;
107 String str;
108 if (!file.exists()) {
109 throw new BuildException("The file " + file + " is not existed");
110 }
111 try {
112 fileReader = new FileReader(file);
113 in = new BufferedReader(fileReader);
114 while ((str = in.readLine()) != null) {
115 if (str.trim() == "") {
116 continue;
117 }
118 str = getProject().replaceProperties(str);
119 activePath.addElement(str.trim());
120 }
121 } catch (Exception e) {
122 throw new BuildException(e.getMessage());
123 }
124 }
125
126 /**
127 * Returns the specific include path.
128 */
129 public String[] getActiveIncludePaths() {
130 if (isReference()) {
131 return ((UserDefineDef) getCheckedRef(UserDefineDef.class,
132 "UserDefineDef")).getActiveIncludePaths();
133 }
134 return getActivePaths(includePaths);
135 }
136
137 private String[] getActivePaths(Vector paths) {
138 Project p = getProject();
139 if (p == null) {
140 throw new java.lang.IllegalStateException("project not set");
141 }
142 Vector activePaths = new Vector(paths.size());
143 for (int i = 0; i < paths.size(); i++) {
144 ConditionalPath path = (ConditionalPath) paths.elementAt(i);
145 if (path.isActive(p)) {
146 if (path.getFile() == null) {
147 String[] pathEntries = path.list();
148 for (int j = 0; j < pathEntries.length; j++) {
149 activePaths.addElement(pathEntries[j]);
150 }
151 } else {
152 loadFile(activePaths, path.getFile());
153 }
154 }
155 }
156 String[] pathNames = new String[activePaths.size()];
157 activePaths.copyInto(pathNames);
158 return pathNames;
159 }
160
161 public String getIncludepathDelimiter() {
162 if (isReference()) {
163 return ((UserDefineDef) getCheckedRef(UserDefineDef.class,
164 "UserDefineDef")).getIncludepathDelimiter();
165 }
166 return includepathDelimiter;
167 }
168
169 public void setIncludepathDelimiter(String includepathDelimiter) {
170 if (isReference()) {
171 throw tooManyAttributes();
172 }
173 this.includepathDelimiter = includepathDelimiter;
174 }
175
176 public String getType() {
177 if (isReference()) {
178 return ((UserDefineDef) getCheckedRef(UserDefineDef.class,
179 "UserDefineDef")).getType();
180 }
181 return type;
182 }
183
184 public void setType(String type) {
185 if (isReference()) {
186 throw tooManyAttributes();
187 }
188 this.type = type;
189 }
190
191 public String getCmd() {
192 return cmd;
193 }
194
195 public void setCmd(String cmd) {
196 if (isReference()) {
197 throw tooManyAttributes();
198 }
199 this.cmd = cmd;
200 }
201
202 public String getFamily() {
203 return family;
204 }
205
206 public void setFamily(String family) {
207 if (isReference()) {
208 throw tooManyAttributes();
209 }
210 this.family = family;
211 }
212
213 public String getOutputFile() {
214 return outputFile;
215 }
216
217 public void setOutputFile(String outputFile) {
218 if (isReference()) {
219 throw tooManyAttributes();
220 }
221 this.outputFile = outputFile;
222 }
223
224 public File getWorkdir() {
225 return workdir;
226 }
227
228 public void setWorkdir(File workdir) {
229 if (isReference()) {
230 throw tooManyAttributes();
231 }
232 this.workdir = workdir;
233 }
234
235 public String[] get_libset() {
236 Set libs = new LinkedHashSet();
237 Iterator iter = _libset.iterator();
238 while (iter.hasNext()) {
239 LibrarySet librarySet = (LibrarySet)iter.next();
240 File basedir = librarySet.getDir(getProject());
241 String[] libStrArray = librarySet.getLibs();
242 for (int i = 0 ; i < libStrArray.length; i ++) {
243 if (basedir != null) {
244 File libFile = new File(libStrArray[i]);
245 if (libFile.isAbsolute()) {
246 libs.add(libFile.getPath());
247 }
248 else {
249 libs.add(basedir.getPath() + File.separatorChar + libFile.getPath());
250 }
251 }
252 else {
253 libs.add(libStrArray[i]);
254 }
255 }
256 }
257 return (String[])libs.toArray(new String[libs.size()]);
258 }
259
260 public String getOutputDelimiter() {
261 return outputDelimiter;
262 }
263
264 public void setOutputDelimiter(String outputDelimiter) {
265 this.outputDelimiter = outputDelimiter;
266 }
267
268 }