+++ /dev/null
-/*\r
- * \r
- * Copyright 2002-2004 The Ant-Contrib project\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package net.sf.antcontrib.cpptasks;\r
-import java.io.File;\r
-import java.util.Enumeration;\r
-import java.util.Vector;\r
-\r
-import net.sf.antcontrib.cpptasks.types.ConditionalFileSet;\r
-\r
-import org.apache.tools.ant.Project;\r
-import org.apache.tools.ant.DirectoryScanner;\r
-import org.apache.tools.ant.types.DataType;\r
-/**\r
- * An element that specifies a prototype file and rules for source files that\r
- * should not use precompiled headers\r
- * \r
- * @author Curt Arnold\r
- */\r
-public final class PrecompileDef extends DataType {\r
- private final Vector exceptSets = new Vector();\r
- private String ifCond;\r
- /**\r
- * Directory of prototype file\r
- */\r
- private File prototype = new File("stdafx.cpp");\r
- private String unlessCond;\r
- /**\r
- * Constructor\r
- * \r
- */\r
- public PrecompileDef() {\r
- }\r
- /**\r
- * Method used by PrecompileExceptDef to add exception set to\r
- * PrecompileDef.\r
- */\r
- public void appendExceptFileSet(ConditionalFileSet exceptSet) {\r
- exceptSet.setProject(getProject());\r
- exceptSets.addElement(exceptSet);\r
- }\r
- /**\r
- * Adds filesets that specify files that should not be processed with\r
- * precompiled headers enabled.\r
- * \r
- * @param exceptSet\r
- * FileSet specify files that should not be processed with\r
- * precompiled headers enabled.\r
- */\r
- public PrecompileExceptDef createExcept() {\r
- return new PrecompileExceptDef(this);\r
- }\r
- public void execute() throws org.apache.tools.ant.BuildException {\r
- throw new org.apache.tools.ant.BuildException(\r
- "Not an actual task, but looks like one for documentation purposes");\r
- }\r
- public String[] getExceptFiles() {\r
- PrecompileDef ref = getRef();\r
- if (ref != null) {\r
- return ref.getExceptFiles();\r
- }\r
- if (exceptSets.size() == 0) {\r
- return new String[0];\r
- }\r
- Project p = getProject();\r
- String[] exceptFiles = null;\r
- Enumeration setEnum = exceptSets.elements();\r
- while (setEnum.hasMoreElements()) {\r
- ConditionalFileSet exceptSet = (ConditionalFileSet) setEnum\r
- .nextElement();\r
- if (exceptSet.isActive()) {\r
- DirectoryScanner scanner = exceptSet\r
- .getDirectoryScanner(p);\r
- String[] scannerFiles = scanner.getIncludedFiles();\r
- if (exceptFiles == null) {\r
- exceptFiles = scannerFiles;\r
- } else {\r
- if (scannerFiles.length > 0) {\r
- String[] newFiles = new String[exceptFiles.length\r
- + scannerFiles.length];\r
- for (int i = 0; i < exceptFiles.length; i++) {\r
- newFiles[i] = exceptFiles[i];\r
- }\r
- int index = exceptFiles.length;\r
- for (int i = 0; i < scannerFiles.length; i++) {\r
- newFiles[index++] = scannerFiles[i];\r
- }\r
- exceptFiles = newFiles;\r
- }\r
- }\r
- }\r
- }\r
- if (exceptFiles == null) {\r
- exceptFiles = new String[0];\r
- }\r
- return exceptFiles;\r
- }\r
- /**\r
- * Gets prototype source file\r
- * \r
- */\r
- public File getPrototype() {\r
- PrecompileDef ref = getRef();\r
- if (ref != null) {\r
- return ref.getPrototype();\r
- }\r
- return prototype;\r
- }\r
- private PrecompileDef getRef() {\r
- if (isReference()) {\r
- return ((PrecompileDef) getCheckedRef(PrecompileDef.class,\r
- "PrecompileDef"));\r
- }\r
- return null;\r
- }\r
- public boolean isActive() { \r
- boolean isActive = CUtil.isActive(getProject(), ifCond, unlessCond);\r
- if (!isActive) {\r
- PrecompileDef ref = getRef();\r
- if (ref != null) {\r
- return ref.isActive();\r
- }\r
- }\r
- return isActive;\r
- }\r
- /**\r
- * Sets a description of the current data type.\r
- */\r
- public void setDescription(String desc) {\r
- super.setDescription(desc);\r
- }\r
- /**\r
- * Sets an id that can be used to reference this element.\r
- * \r
- * @param id\r
- * id\r
- */\r
- public void setId(String id) {\r
- //\r
- // this is actually accomplished by a different\r
- // mechanism, but we can document it\r
- //\r
- }\r
- /**\r
- * Set the 'if' condition.\r
- * \r
- * The processor will be ignored unless the property is defined.\r
- * \r
- * The value of property is insignificant, but values that would imply\r
- * misinterpretation ("false", "no") will throw an exception when\r
- * isActive() is evaluated.\r
- * \r
- * @param propName\r
- * name of property\r
- */\r
- public void setIf(String propName) {\r
- ifCond = propName;\r
- }\r
- /**\r
- * Sets file to precompile.\r
- * \r
- * Should be a source file that includes only one unguarded header file.\r
- * Default value is "stdafx.cpp".\r
- * \r
- * @param prototype\r
- * file path for prototype source file\r
- */\r
- public void setPrototype(File prototype) {\r
- if (isReference()) {\r
- throw tooManyAttributes();\r
- }\r
- if (prototype == null) {\r
- throw new NullPointerException("prototype");\r
- }\r
- this.prototype = prototype;\r
- }\r
- /**\r
- * Specifies that this element should behave as if the content of the\r
- * element with the matching id attribute was inserted at this location.\r
- * \r
- * @param ref\r
- * Reference to other element\r
- * \r
- */\r
- public void setRefid(org.apache.tools.ant.types.Reference ref) {\r
- super.setRefid(ref);\r
- }\r
- /**\r
- * Set the 'unless' condition. If named property exists at execution time,\r
- * the processor will be ignored.\r
- * \r
- * Value of property is insignificant, but values that would imply\r
- * misinterpretation ("false", "no") of the behavior will throw an\r
- * exception when isActive is called.\r
- * \r
- * @param propName\r
- * name of property\r
- */\r
- public void setUnless(String propName) {\r
- unlessCond = propName;\r
- }\r
-}\r