3 * Copyright 2001-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
.types
;
18 import java
.util
.Vector
;
20 import net
.sf
.antcontrib
.cpptasks
.CUtil
;
22 import org
.apache
.tools
.ant
.BuildException
;
23 import org
.apache
.tools
.ant
.types
.DataType
;
24 import org
.apache
.tools
.ant
.types
.Reference
;
26 * Set of preprocessor macro defines and undefines.
28 * @author Mark A Russell <a
29 * href="mailto:mark_russell@csgsystems.com">mark_russell@csg_systems.com
31 * @author Adam Murdoch
33 public class DefineSet
extends DataType
{
34 private Vector defineList
= new Vector();
35 private String ifCond
= null;
36 private String unlessCond
= null;
39 * Adds a define element.
41 * @throws BuildException
44 public void addDefine(DefineArgument arg
) throws BuildException
{
46 throw noChildrenAllowed();
48 defineList
.addElement(arg
);
50 /** Adds defines/undefines. */
51 private void addDefines(String
[] defs
, boolean isDefine
) {
52 for (int i
= 0; i
< defs
.length
; i
++) {
55 def
= new DefineArgument();
57 def
= new UndefineArgument();
60 defineList
.addElement(def
);
65 * Adds an undefine element.
67 * @throws BuildException
70 public void addUndefine(UndefineArgument arg
) throws BuildException
{
72 throw noChildrenAllowed();
74 defineList
.addElement(arg
);
76 public void execute() throws org
.apache
.tools
.ant
.BuildException
{
77 throw new org
.apache
.tools
.ant
.BuildException(
78 "Not an actual task, but looks like one for documentation purposes");
80 /** Returns the defines and undefines in this set. */
81 public UndefineArgument
[] getDefines() throws BuildException
{
83 DefineSet defset
= (DefineSet
) getCheckedRef(DefineSet
.class,
85 return defset
.getDefines();
88 UndefineArgument
[] defs
= new UndefineArgument
[defineList
90 defineList
.copyInto(defs
);
93 return new UndefineArgument
[0];
98 * Returns true if the define's if and unless conditions (if any) are
101 * @exception BuildException
102 * throws build exception if name is not set
104 public final boolean isActive() throws BuildException
{
105 return CUtil
.isActive(getProject(), ifCond
, unlessCond
);
108 * A comma-separated list of preprocessor macros to define. Use nested
109 * define elements to define macro values.
112 * comma-separated list of preprocessor macros
113 * @throws BuildException
114 * throw if defineset is a reference
116 public void setDefine(CUtil
.StringArrayBuilder defList
)
117 throws BuildException
{
119 throw tooManyAttributes();
121 addDefines(defList
.getValue(), true);
124 * Sets a description of the current data type.
126 public void setDescription(String desc
) {
127 super.setDescription(desc
);
130 * Sets an id that can be used to reference this element.
135 public void setId(String id
) {
137 // this is actually accomplished by a different
138 // mechanism, but we can document it
142 * Sets the property name for the 'if' condition.
144 * The define will be ignored unless the property is defined.
146 * The value of the property is insignificant, but values that would imply
147 * misinterpretation ("false", "no") will throw an exception when
153 public final void setIf(String propName
) {
157 * Specifies that this element should behave as if the content of the
158 * element with the matching id attribute was inserted at this location. If
159 * specified, no other attributes or child content should be specified,
160 * other than "description".
163 public void setRefid(Reference r
) throws BuildException
{
164 if (!defineList
.isEmpty()) {
165 throw tooManyAttributes();
170 * A comma-separated list of preprocessor macros to undefine.
173 * comma-separated list of preprocessor macros
174 * @throws BuildException
175 * throw if defineset is a reference
177 public void setUndefine(CUtil
.StringArrayBuilder undefList
)
178 throws BuildException
{
180 throw tooManyAttributes();
182 addDefines(undefList
.getValue(), false);
185 * Set the property name for the 'unless' condition.
187 * If named property is set, the define will be ignored.
189 * The value of the property is insignificant, but values that would imply
190 * misinterpretation ("false", "no") of the behavior will throw an
191 * exception when evaluated.
196 public final void setUnless(String propName
) {
197 unlessCond
= propName
;