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.types.EnumeratedAttribute; 23 24 /** 25 * An compiler/linker command line flag. 26 */ 27 public class CommandLineArgument { 28 /** 29 * Enumerated attribute with the values "start", "mid" and "end", 30 */ 31 public static class LocationEnum extends EnumeratedAttribute { 32 @Override 33 public String[] getValues() { 34 return new String[] { 35 "start", "mid", "end" 36 }; 37 } 38 } 39 40 private String ifCond; 41 private int location; 42 private String unlessCond; 43 private String value; 44 45 public CommandLineArgument() { 46 } 47 48 public int getLocation() { 49 return this.location; 50 } 51 52 public String getValue() { 53 return this.value; 54 } 55 56 /** 57 * Returns true if the define's if and unless conditions (if any) are 58 * satisfied. 59 */ 60 public boolean isActive(final org.apache.tools.ant.Project p) { 61 if (this.value == null) { 62 return false; 63 } 64 if (this.ifCond != null && p.getProperty(this.ifCond) == null) { 65 return false; 66 } else if (this.unlessCond != null && p.getProperty(this.unlessCond) != null) { 67 return false; 68 } 69 return true; 70 } 71 72 /** 73 * Sets the property name for the 'if' condition. 74 * 75 * The argument will be ignored unless the property is defined. 76 * 77 * The value of the property is insignificant, but values that would imply 78 * misinterpretation ("false", "no") will throw an exception when 79 * evaluated. 80 */ 81 public void setIf(final String propName) { 82 this.ifCond = propName; 83 } 84 85 /** 86 * Specifies relative location of argument on command line. "start" will 87 * place argument at start of command line, "mid" will place argument after 88 * all "start" arguments but before filenames, "end" will place argument 89 * after filenames. 90 * 91 */ 92 public void setLocation(final LocationEnum location) { 93 this.location = location.getIndex(); 94 } 95 96 /** 97 * Set the property name for the 'unless' condition. 98 * 99 * If named property is set, the argument will be ignored. 100 * 101 * The value of the property is insignificant, but values that would imply 102 * misinterpretation ("false", "no") of the behavior will throw an 103 * exception when evaluated. 104 * 105 * @param propName 106 * name of property 107 */ 108 public void setUnless(final String propName) { 109 this.unlessCond = propName; 110 } 111 112 /** 113 * Specifies the string that should appear on the command line. The 114 * argument will be quoted if it contains embedded blanks. Use multiple 115 * arguments to avoid quoting. 116 * 117 */ 118 public void setValue(final String value) { 119 this.value = value; 120 } 121 }