Coverage Report - org.apache.commons.launcher.types.ConditionalVariable
 
Classes in this File Line Coverage Branch Coverage Complexity
ConditionalVariable
0%
0/23
N/A
1
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  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  
 
 18  
 package org.apache.commons.launcher.types;
 19  
 
 20  
 import java.io.File;
 21  
 
 22  
 import org.apache.tools.ant.ProjectHelper;
 23  
 import org.apache.tools.ant.types.DataType;
 24  
 import org.apache.tools.ant.types.Path;
 25  
 
 26  
 /**
 27  
  * A class that represents nested <sysproperty> or <env> elements. This class
 28  
  * provides the same functionality as the class that represents these same
 29  
  * elements in a "java" task. In addition, this class supports conditional "if" 
 30  
  * and "unless" attributes.
 31  
  *
 32  
  * @author Patrick Luby
 33  
  */
 34  0
 public class ConditionalVariable extends DataType {
 35  
 
 36  
     //------------------------------------------------------------------ Fields
 37  
 
 38  
     /**
 39  
      * Cached "if" condition flag.
 40  
      */
 41  0
     private String ifCondition = null;
 42  
 
 43  
     /**
 44  
      * Cached key.
 45  
      */
 46  0
     private String key = null;
 47  
 
 48  
     /**
 49  
      * Cached "unless" condition flag.
 50  
      */
 51  0
     private String unlessCondition = null;
 52  
 
 53  
     /**
 54  
      * Cached value.
 55  
      */
 56  0
     private String value = null;
 57  
 
 58  
     //----------------------------------------------------------------- Methods
 59  
 
 60  
     /**
 61  
      * Get the "if" condition flag.
 62  
      *
 63  
      * @return the "if" condition flag
 64  
      */
 65  
     public String getIf() {
 66  
 
 67  0
         return ProjectHelper.replaceProperties(project, ifCondition, project.getProperties());
 68  
 
 69  
     }
 70  
 
 71  
     /**
 72  
      * Get the key.
 73  
      *
 74  
      * @return the key for this variable
 75  
      */
 76  
     public String getKey() {
 77  
 
 78  0
         return ProjectHelper.replaceProperties(project, key, project.getProperties());
 79  
 
 80  
     }
 81  
 
 82  
     /**
 83  
      * Get the "unless" condition flag.
 84  
      *
 85  
      * @return the "unless" condition flag
 86  
      */
 87  
     public String getUnless() {
 88  
  
 89  0
         return ProjectHelper.replaceProperties(project, unlessCondition, project.getProperties());
 90  
 
 91  
     }
 92  
 
 93  
     /**
 94  
      * Get the value.
 95  
      *
 96  
      * @return the value for this variable
 97  
      */
 98  
     public String getValue() {
 99  
 
 100  0
         return ProjectHelper.replaceProperties(project, value, project.getProperties());
 101  
 
 102  
     }
 103  
 
 104  
     /**
 105  
      * Set the value to a {@link File}.
 106  
      *
 107  
      * @param file the {@link File} for this variable
 108  
      */
 109  
     public void setFile(File file) {
 110  
 
 111  0
         this.value = file.getAbsolutePath();
 112  
 
 113  0
     }
 114  
 
 115  
     /**
 116  
      * Set the value to a {@link Path}.
 117  
      *
 118  
      * @param path the {@link Path} for this variable
 119  
      */
 120  
     public void setPath(Path path) {
 121  
 
 122  0
         this.value = path.toString();
 123  
 
 124  0
     }
 125  
 
 126  
     /**
 127  
      * Set the "if" condition. Tasks that nest this class as an element
 128  
      * should evaluate this flag in their {@link org.apache.tools.ant.Task#execute()} method. If the
 129  
      * following conditions are true, the task should process this element:
 130  
      * <ul>
 131  
      * <ol>The flag is neither null nor a empty string
 132  
      * <ol>The property that the flag resolves to after macro substitution
 133  
      *  is defined
 134  
      * </ul>
 135  
      *
 136  
      * @param property a property name or macro
 137  
      */
 138  
     public void setIf(String property) {
 139  
  
 140  0
         this.ifCondition = property;
 141  
 
 142  0
     }
 143  
 
 144  
     /**
 145  
      * Set the key.
 146  
      *
 147  
      * @param key the key for this variable
 148  
      */
 149  
     public void setKey(String key) {
 150  
 
 151  0
         this.key = key;
 152  
 
 153  0
     }
 154  
 
 155  
     /**
 156  
      * Set the value to a {@link Path}.
 157  
      *
 158  
      * @param path the {@link Path} for this variable
 159  
      */
 160  
     public void setFile(Path path) {
 161  
 
 162  0
         this.value = path.toString();
 163  
 
 164  0
     }
 165  
 
 166  
     /**
 167  
      * Set the "unless" condition. Tasks that nest this class as an element
 168  
      * should evaluate this flag in their {@link org.apache.tools.ant.Task#execute()} method. If the
 169  
      * following conditions are true, the task should ignore this element:
 170  
      * <ul>
 171  
      * <ol>The flag is neither null nor a empty string
 172  
      * <ol>The property that the flag resolves to after macro substitution
 173  
      *  is defined
 174  
      * </ul>
 175  
      *
 176  
      * @param property a property name or macro
 177  
      */
 178  
     public void setUnless(String property) {
 179  
  
 180  0
         this.unlessCondition = property;
 181  
 
 182  0
     }
 183  
 
 184  
     /**
 185  
      * Set the value.
 186  
      *
 187  
      * @param value the value for this variable
 188  
      */
 189  
     public void setValue(String value) {
 190  
 
 191  0
         this.value = value;
 192  
 
 193  0
     }
 194  
 
 195  
 }