001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.tools.ant.taskdefs.optional.dotnet;
019:
020: import org.apache.tools.ant.BuildException;
021: import org.apache.tools.ant.Task;
022: import org.apache.tools.ant.Project;
023:
024: /**
025: * definitions can be conditional. What .NET conditions can not be
026: * is in any state other than defined and undefined; you cannot give
027: * a definition a value.
028: */
029: public class DotnetDefine {
030: private String name;
031: private String ifCond;
032: private String unlessCond;
033:
034: /**
035: * the name of a property which must be defined for
036: * the definition to be set. Optional.
037: * @param condition the name of the property
038: */
039: public void setIf(String condition) {
040: this .ifCond = condition;
041: }
042:
043: /**
044: * the name of a property which must be undefined for
045: * the definition to be set. Optional.
046: * @param condition the name of the property
047: */
048: public void setUnless(String condition) {
049: this .unlessCond = condition;
050: }
051:
052: /**
053: * Get the name of the definition.
054: * @return the name.
055: */
056: public String getName() {
057: return name;
058: }
059:
060: /**
061: * the name of the definition. Required.
062: * @param name the name value.
063: */
064: public void setName(String name) {
065: this .name = name;
066: }
067:
068: /**
069: * This method gets the value of this definition. Will be null if a condition
070: * was declared and not met
071: * @param owner owning task
072: * @return The value of the definition.
073: * @throws BuildException if there is an error.
074: */
075: public String getValue(Task owner) throws BuildException {
076: if (name == null) {
077: throw new BuildException(
078: "No name provided for the define element", owner
079: .getLocation());
080: }
081: if (!isSet(owner)) {
082: return null;
083: }
084: return name;
085: }
086:
087: /**
088: * logic taken from patternset
089: * @param owner the owning task.
090: * @return true if the condition is valid
091: */
092: public boolean isSet(Task owner) {
093: Project p = owner.getProject();
094: if (ifCond != null && p.getProperty(ifCond) == null) {
095: return false;
096: } else if (unlessCond != null
097: && p.getProperty(unlessCond) != null) {
098: return false;
099: }
100: return true;
101: }
102: }
|