]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/Cpptasks/net/sf/antcontrib/cpptasks/PrecompileDef.java
Initial import.
[mirror_edk2.git] / Tools / Source / Cpptasks / net / sf / antcontrib / cpptasks / PrecompileDef.java
CommitLineData
878ddf1f 1/*\r
2 * \r
3 * Copyright 2002-2004 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;\r
18import java.io.File;\r
19import java.util.Enumeration;\r
20import java.util.Vector;\r
21\r
22import net.sf.antcontrib.cpptasks.types.ConditionalFileSet;\r
23\r
24import org.apache.tools.ant.Project;\r
25import org.apache.tools.ant.DirectoryScanner;\r
26import org.apache.tools.ant.types.DataType;\r
27/**\r
28 * An element that specifies a prototype file and rules for source files that\r
29 * should not use precompiled headers\r
30 * \r
31 * @author Curt Arnold\r
32 */\r
33public final class PrecompileDef extends DataType {\r
34 private final Vector exceptSets = new Vector();\r
35 private String ifCond;\r
36 /**\r
37 * Directory of prototype file\r
38 */\r
39 private File prototype = new File("stdafx.cpp");\r
40 private String unlessCond;\r
41 /**\r
42 * Constructor\r
43 * \r
44 */\r
45 public PrecompileDef() {\r
46 }\r
47 /**\r
48 * Method used by PrecompileExceptDef to add exception set to\r
49 * PrecompileDef.\r
50 */\r
51 public void appendExceptFileSet(ConditionalFileSet exceptSet) {\r
52 exceptSet.setProject(getProject());\r
53 exceptSets.addElement(exceptSet);\r
54 }\r
55 /**\r
56 * Adds filesets that specify files that should not be processed with\r
57 * precompiled headers enabled.\r
58 * \r
59 * @param exceptSet\r
60 * FileSet specify files that should not be processed with\r
61 * precompiled headers enabled.\r
62 */\r
63 public PrecompileExceptDef createExcept() {\r
64 return new PrecompileExceptDef(this);\r
65 }\r
66 public void execute() throws org.apache.tools.ant.BuildException {\r
67 throw new org.apache.tools.ant.BuildException(\r
68 "Not an actual task, but looks like one for documentation purposes");\r
69 }\r
70 public String[] getExceptFiles() {\r
71 PrecompileDef ref = getRef();\r
72 if (ref != null) {\r
73 return ref.getExceptFiles();\r
74 }\r
75 if (exceptSets.size() == 0) {\r
76 return new String[0];\r
77 }\r
78 Project p = getProject();\r
79 String[] exceptFiles = null;\r
80 Enumeration setEnum = exceptSets.elements();\r
81 while (setEnum.hasMoreElements()) {\r
82 ConditionalFileSet exceptSet = (ConditionalFileSet) setEnum\r
83 .nextElement();\r
84 if (exceptSet.isActive()) {\r
85 DirectoryScanner scanner = exceptSet\r
86 .getDirectoryScanner(p);\r
87 String[] scannerFiles = scanner.getIncludedFiles();\r
88 if (exceptFiles == null) {\r
89 exceptFiles = scannerFiles;\r
90 } else {\r
91 if (scannerFiles.length > 0) {\r
92 String[] newFiles = new String[exceptFiles.length\r
93 + scannerFiles.length];\r
94 for (int i = 0; i < exceptFiles.length; i++) {\r
95 newFiles[i] = exceptFiles[i];\r
96 }\r
97 int index = exceptFiles.length;\r
98 for (int i = 0; i < scannerFiles.length; i++) {\r
99 newFiles[index++] = scannerFiles[i];\r
100 }\r
101 exceptFiles = newFiles;\r
102 }\r
103 }\r
104 }\r
105 }\r
106 if (exceptFiles == null) {\r
107 exceptFiles = new String[0];\r
108 }\r
109 return exceptFiles;\r
110 }\r
111 /**\r
112 * Gets prototype source file\r
113 * \r
114 */\r
115 public File getPrototype() {\r
116 PrecompileDef ref = getRef();\r
117 if (ref != null) {\r
118 return ref.getPrototype();\r
119 }\r
120 return prototype;\r
121 }\r
122 private PrecompileDef getRef() {\r
123 if (isReference()) {\r
124 return ((PrecompileDef) getCheckedRef(PrecompileDef.class,\r
125 "PrecompileDef"));\r
126 }\r
127 return null;\r
128 }\r
129 public boolean isActive() { \r
130 boolean isActive = CUtil.isActive(getProject(), ifCond, unlessCond);\r
131 if (!isActive) {\r
132 PrecompileDef ref = getRef();\r
133 if (ref != null) {\r
134 return ref.isActive();\r
135 }\r
136 }\r
137 return isActive;\r
138 }\r
139 /**\r
140 * Sets a description of the current data type.\r
141 */\r
142 public void setDescription(String desc) {\r
143 super.setDescription(desc);\r
144 }\r
145 /**\r
146 * Sets an id that can be used to reference this element.\r
147 * \r
148 * @param id\r
149 * id\r
150 */\r
151 public void setId(String id) {\r
152 //\r
153 // this is actually accomplished by a different\r
154 // mechanism, but we can document it\r
155 //\r
156 }\r
157 /**\r
158 * Set the 'if' condition.\r
159 * \r
160 * The processor will be ignored unless the property is defined.\r
161 * \r
162 * The value of property is insignificant, but values that would imply\r
163 * misinterpretation ("false", "no") will throw an exception when\r
164 * isActive() is evaluated.\r
165 * \r
166 * @param propName\r
167 * name of property\r
168 */\r
169 public void setIf(String propName) {\r
170 ifCond = propName;\r
171 }\r
172 /**\r
173 * Sets file to precompile.\r
174 * \r
175 * Should be a source file that includes only one unguarded header file.\r
176 * Default value is "stdafx.cpp".\r
177 * \r
178 * @param prototype\r
179 * file path for prototype source file\r
180 */\r
181 public void setPrototype(File prototype) {\r
182 if (isReference()) {\r
183 throw tooManyAttributes();\r
184 }\r
185 if (prototype == null) {\r
186 throw new NullPointerException("prototype");\r
187 }\r
188 this.prototype = prototype;\r
189 }\r
190 /**\r
191 * Specifies that this element should behave as if the content of the\r
192 * element with the matching id attribute was inserted at this location.\r
193 * \r
194 * @param ref\r
195 * Reference to other element\r
196 * \r
197 */\r
198 public void setRefid(org.apache.tools.ant.types.Reference ref) {\r
199 super.setRefid(ref);\r
200 }\r
201 /**\r
202 * Set the 'unless' condition. If named property exists at execution time,\r
203 * the processor will be ignored.\r
204 * \r
205 * Value of property is insignificant, but values that would imply\r
206 * misinterpretation ("false", "no") of the behavior will throw an\r
207 * exception when isActive is called.\r
208 * \r
209 * @param propName\r
210 * name of property\r
211 */\r
212 public void setUnless(String propName) {\r
213 unlessCond = propName;\r
214 }\r
215}\r