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