3 * Copyright 2002-2004 The Ant-Contrib project
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package net
.sf
.antcontrib
.cpptasks
;
19 import java
.util
.Enumeration
;
20 import java
.util
.Vector
;
22 import net
.sf
.antcontrib
.cpptasks
.types
.ConditionalFileSet
;
24 import org
.apache
.tools
.ant
.Project
;
25 import org
.apache
.tools
.ant
.DirectoryScanner
;
26 import org
.apache
.tools
.ant
.types
.DataType
;
28 * An element that specifies a prototype file and rules for source files that
29 * should not use precompiled headers
33 public final class PrecompileDef
extends DataType
{
34 private final Vector exceptSets
= new Vector();
35 private String ifCond
;
37 * Directory of prototype file
39 private File prototype
= new File("stdafx.cpp");
40 private String unlessCond
;
45 public PrecompileDef() {
48 * Method used by PrecompileExceptDef to add exception set to
51 public void appendExceptFileSet(ConditionalFileSet exceptSet
) {
52 exceptSet
.setProject(getProject());
53 exceptSets
.addElement(exceptSet
);
56 * Adds filesets that specify files that should not be processed with
57 * precompiled headers enabled.
60 * FileSet specify files that should not be processed with
61 * precompiled headers enabled.
63 public PrecompileExceptDef
createExcept() {
64 return new PrecompileExceptDef(this);
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");
70 public String
[] getExceptFiles() {
71 PrecompileDef ref
= getRef();
73 return ref
.getExceptFiles();
75 if (exceptSets
.size() == 0) {
78 Project p
= getProject();
79 String
[] exceptFiles
= null;
80 Enumeration setEnum
= exceptSets
.elements();
81 while (setEnum
.hasMoreElements()) {
82 ConditionalFileSet exceptSet
= (ConditionalFileSet
) setEnum
84 if (exceptSet
.isActive()) {
85 DirectoryScanner scanner
= exceptSet
86 .getDirectoryScanner(p
);
87 String
[] scannerFiles
= scanner
.getIncludedFiles();
88 if (exceptFiles
== null) {
89 exceptFiles
= scannerFiles
;
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
];
97 int index
= exceptFiles
.length
;
98 for (int i
= 0; i
< scannerFiles
.length
; i
++) {
99 newFiles
[index
++] = scannerFiles
[i
];
101 exceptFiles
= newFiles
;
106 if (exceptFiles
== null) {
107 exceptFiles
= new String
[0];
112 * Gets prototype source file
115 public File
getPrototype() {
116 PrecompileDef ref
= getRef();
118 return ref
.getPrototype();
122 private PrecompileDef
getRef() {
124 return ((PrecompileDef
) getCheckedRef(PrecompileDef
.class,
129 public boolean isActive() {
130 boolean isActive
= CUtil
.isActive(getProject(), ifCond
, unlessCond
);
132 PrecompileDef ref
= getRef();
134 return ref
.isActive();
140 * Sets a description of the current data type.
142 public void setDescription(String desc
) {
143 super.setDescription(desc
);
146 * Sets an id that can be used to reference this element.
151 public void setId(String id
) {
153 // this is actually accomplished by a different
154 // mechanism, but we can document it
158 * Set the 'if' condition.
160 * The processor will be ignored unless the property is defined.
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.
169 public void setIf(String propName
) {
173 * Sets file to precompile.
175 * Should be a source file that includes only one unguarded header file.
176 * Default value is "stdafx.cpp".
179 * file path for prototype source file
181 public void setPrototype(File prototype
) {
183 throw tooManyAttributes();
185 if (prototype
== null) {
186 throw new NullPointerException("prototype");
188 this.prototype
= prototype
;
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.
195 * Reference to other element
198 public void setRefid(org
.apache
.tools
.ant
.types
.Reference ref
) {
202 * Set the 'unless' condition. If named property exists at execution time,
203 * the processor will be ignored.
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.
212 public void setUnless(String propName
) {
213 unlessCond
= propName
;