1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.github.maven_nar.cpptasks.types;
21
22 import java.util.Vector;
23
24 import org.apache.tools.ant.BuildException;
25 import org.apache.tools.ant.types.DataType;
26 import org.apache.tools.ant.types.Reference;
27
28 import com.github.maven_nar.cpptasks.CUtil;
29
30
31
32
33
34
35
36
37
38
39 public class DefineSet extends DataType {
40 private final Vector<UndefineArgument> defineList = new Vector<>();
41 private String ifCond = null;
42 private String unlessCond = null;
43
44
45
46
47
48
49
50
51 public void addDefine(final DefineArgument arg) throws BuildException {
52 if (isReference()) {
53 throw noChildrenAllowed();
54 }
55 this.defineList.addElement(arg);
56 }
57
58
59 private void addDefines(final String[] defs, final boolean isDefine) {
60 for (final String def2 : defs) {
61 UndefineArgument def;
62 if (isDefine) {
63 def = new DefineArgument();
64 } else {
65 def = new UndefineArgument();
66 }
67 def.setName(def2);
68 this.defineList.addElement(def);
69 }
70 }
71
72
73
74
75
76
77
78
79 public void addUndefine(final UndefineArgument arg) throws BuildException {
80 if (isReference()) {
81 throw noChildrenAllowed();
82 }
83 this.defineList.addElement(arg);
84 }
85
86 public void execute() throws org.apache.tools.ant.BuildException {
87 throw new org.apache.tools.ant.BuildException("Not an actual task, but looks like one for documentation purposes");
88 }
89
90
91 public UndefineArgument[] getDefines() throws BuildException {
92 if (isReference()) {
93 final DefineSet defset = (DefineSet) getCheckedRef(DefineSet.class, "DefineSet");
94 return defset.getDefines();
95 } else {
96 if (isActive()) {
97 final UndefineArgument[] defs = new UndefineArgument[this.defineList.size()];
98 this.defineList.copyInto(defs);
99 return defs;
100 } else {
101 return new UndefineArgument[0];
102 }
103 }
104 }
105
106
107
108
109
110
111
112
113 public final boolean isActive() throws BuildException {
114 return CUtil.isActive(getProject(), this.ifCond, this.unlessCond);
115 }
116
117
118
119
120
121
122
123
124
125
126 public void setDefine(final CUtil.StringArrayBuilder defList) throws BuildException {
127 if (isReference()) {
128 throw tooManyAttributes();
129 }
130 addDefines(defList.getValue(), true);
131 }
132
133
134
135
136 @Override
137 public void setDescription(final String desc) {
138 super.setDescription(desc);
139 }
140
141
142
143
144
145
146
147 public void setId(final String id) {
148
149
150
151
152 }
153
154
155
156
157
158
159
160
161
162
163
164
165
166 public final void setIf(final String propName) {
167 this.ifCond = propName;
168 }
169
170
171
172
173
174
175
176
177 @Override
178 public void setRefid(final Reference r) throws BuildException {
179 if (!this.defineList.isEmpty()) {
180 throw tooManyAttributes();
181 }
182 super.setRefid(r);
183 }
184
185
186
187
188
189
190
191
192
193 public void setUndefine(final CUtil.StringArrayBuilder undefList) throws BuildException {
194 if (isReference()) {
195 throw tooManyAttributes();
196 }
197 addDefines(undefList.getValue(), false);
198 }
199
200
201
202
203
204
205
206
207
208
209
210
211
212 public final void setUnless(final String propName) {
213 this.unlessCond = propName;
214 }
215 }