]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/Cpptasks/net/sf/antcontrib/cpptasks/types/ConditionalFileSet.java
Initial import.
[mirror_edk2.git] / Tools / Source / Cpptasks / net / sf / antcontrib / cpptasks / types / ConditionalFileSet.java
1 /*
2 *
3 * Copyright 2001-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.types;
18 import net.sf.antcontrib.cpptasks.CUtil;
19
20 import org.apache.tools.ant.BuildException;
21 import org.apache.tools.ant.Project;
22 import org.apache.tools.ant.types.AbstractFileSet;
23 import org.apache.tools.ant.types.FileSet;
24 /**
25 * An Ant FileSet object augmented with if and unless conditions.
26 *
27 * @author Curt Arnold
28 */
29 public class ConditionalFileSet extends FileSet {
30 private String ifCond;
31 private String unlessCond;
32 public ConditionalFileSet() {
33 }
34 public void execute() throws org.apache.tools.ant.BuildException {
35 throw new org.apache.tools.ant.BuildException(
36 "Not an actual task, but looks like one for documentation purposes");
37 }
38 /**
39 * overrides FileSet's implementation which would throw an exception since
40 * the referenced object isn't this type.
41 */
42 protected AbstractFileSet getRef(Project p) {
43 return (AbstractFileSet) getRefid().getReferencedObject(p);
44 }
45 /**
46 * Returns true if the Path's if and unless conditions (if any) are
47 * satisfied.
48 */
49 public boolean isActive() throws BuildException {
50 Project p = getProject();
51 if (p == null) {
52 throw new java.lang.IllegalStateException(
53 "setProject() should have been called");
54 }
55 return CUtil.isActive(p, ifCond, unlessCond);
56 }
57 /**
58 * Sets the property name for the 'if' condition.
59 *
60 * The fileset will be ignored unless the property is defined.
61 *
62 * The value of the property is insignificant, but values that would imply
63 * misinterpretation ("false", "no") will throw an exception when
64 * evaluated.
65 */
66 public void setIf(String propName) {
67 ifCond = propName;
68 }
69 /**
70 * Set the property name for the 'unless' condition.
71 *
72 * If named property is set, the fileset will be ignored.
73 *
74 * The value of the property is insignificant, but values that would imply
75 * misinterpretation ("false", "no") of the behavior will throw an
76 * exception when evaluated.
77 *
78 * @param propName
79 * name of property
80 */
81 public void setUnless(String propName) {
82 unlessCond = propName;
83 }
84 }