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