1 /* 2 * #%L 3 * Native ARchive plugin for Maven 4 * %% 5 * Copyright (C) 2002 - 2014 NAR Maven Plugin developers. 6 * %% 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 * #L% 19 */ 20 package com.github.maven_nar.cpptasks.types; 21 22 import org.apache.tools.ant.BuildException; 23 import org.apache.tools.ant.Project; 24 import org.apache.tools.ant.types.Path; 25 26 import com.github.maven_nar.cpptasks.CUtil; 27 28 /** 29 * An Ant Path object augmented with if and unless conditionals 30 * 31 * @author Curt Arnold 32 */ 33 public class ConditionalPath extends Path { 34 private String ifCond; 35 private String unlessCond; 36 37 public ConditionalPath(final Project project) { 38 super(project); 39 } 40 41 public ConditionalPath(final Project p, final String path) { 42 super(p, path); 43 } 44 45 /** 46 * Returns true if the Path's if and unless conditions (if any) are 47 * satisfied. 48 */ 49 public boolean isActive(final org.apache.tools.ant.Project p) throws BuildException { 50 return CUtil.isActive(p, this.ifCond, this.unlessCond); 51 } 52 53 /** 54 * Sets the property name for the 'if' condition. 55 * 56 * The path will be ignored unless the property is defined. 57 * 58 * The value of the property is insignificant, but values that would imply 59 * misinterpretation ("false", "no") will throw an exception when 60 * evaluated. 61 * 62 * @param propName 63 * property name 64 */ 65 public void setIf(final String propName) { 66 this.ifCond = propName; 67 } 68 69 /** 70 * Set the property name for the 'unless' condition. 71 * 72 * If named property is set, the path 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(final String propName) { 82 this.unlessCond = propName; 83 } 84 }