1 | /*
|
---|
2 | * Copyright 2000-2004 The Apache Software Foundation
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | *
|
---|
16 | */
|
---|
17 | package org.apache.tools.ant.taskdefs.optional.dotnet;
|
---|
18 |
|
---|
19 | import org.apache.tools.ant.BuildException;
|
---|
20 | import org.apache.tools.ant.Task;
|
---|
21 | import org.apache.tools.ant.Project;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * definitions can be conditional. What .NET conditions can not be
|
---|
25 | * is in any state other than defined and undefined; you cannot give
|
---|
26 | * a definition a value.
|
---|
27 | */
|
---|
28 | public class DotnetDefine {
|
---|
29 | private String name;
|
---|
30 | private String ifCond;
|
---|
31 | private String unlessCond;
|
---|
32 |
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * the name of a property which must be defined for
|
---|
36 | * the definition to be set. Optional.
|
---|
37 | * @param condition the name of the property
|
---|
38 | */
|
---|
39 | public void setIf(String condition) {
|
---|
40 | this.ifCond = condition;
|
---|
41 | }
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * the name of a property which must be undefined for
|
---|
45 | * the definition to be set. Optional.
|
---|
46 | * @param condition the name of the property
|
---|
47 | */
|
---|
48 | public void setUnless(String condition) {
|
---|
49 | this.unlessCond = condition;
|
---|
50 | }
|
---|
51 |
|
---|
52 | public String getName() {
|
---|
53 | return name;
|
---|
54 | }
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * the name of the definition. Required.
|
---|
58 | * @param name
|
---|
59 | */
|
---|
60 | public void setName(String name) {
|
---|
61 | this.name = name;
|
---|
62 | }
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * This method gets the value of this definition. Will be null if a condition
|
---|
66 | * was declared and not met
|
---|
67 | * @param owner owning task
|
---|
68 | * @return The value of the definition.
|
---|
69 | * @throws BuildException
|
---|
70 | */
|
---|
71 | public String getValue(Task owner) throws BuildException {
|
---|
72 | if (name == null) {
|
---|
73 | throw new BuildException("No name provided for the define element",
|
---|
74 | owner.getLocation());
|
---|
75 | }
|
---|
76 | if (!isSet(owner)) {
|
---|
77 | return null;
|
---|
78 | }
|
---|
79 | return name;
|
---|
80 | }
|
---|
81 |
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * logic taken from patternset
|
---|
85 | * @param owner
|
---|
86 | * @return true if the condition is valid
|
---|
87 | */
|
---|
88 | public boolean isSet(Task owner) {
|
---|
89 | Project p = owner.getProject();
|
---|
90 | if (ifCond != null && p.getProperty(ifCond) == null) {
|
---|
91 | return false;
|
---|
92 | } else if (unlessCond != null && p.getProperty(unlessCond) != null) {
|
---|
93 | return false;
|
---|
94 | }
|
---|
95 | return true;
|
---|
96 | }
|
---|
97 | }
|
---|