1 28 29 package com.idaremedia.antx.solo; 30 31 import org.apache.tools.ant.BuildException; 32 import org.apache.tools.ant.Project; 33 import org.apache.tools.ant.taskdefs.Property; 34 35 import com.idaremedia.antx.AntXFixture; 36 import com.idaremedia.antx.ExportScope; 37 import com.idaremedia.antx.FlexString; 38 import com.idaremedia.antx.apis.AntLibFriendly; 39 import com.idaremedia.antx.go.Unless; 40 import com.idaremedia.antx.parameters.FlexValueSupport; 41 import com.idaremedia.antx.parameters.TransformEnabled; 42 import com.idaremedia.antx.parameters.TransformHelper; 43 import com.idaremedia.antx.parameters.TrimEnabled; 44 import com.idaremedia.antx.parameters.ValueTransform; 45 46 81 82 public final class CopyPropertyTask extends Property 83 implements FlexValueSupport, TrimEnabled, TransformEnabled, AntLibFriendly 84 { 85 88 public CopyPropertyTask() 89 { 90 super(); 91 } 92 93 94 97 public void setProject(Project P) 98 { 99 super.setProject(P); 100 m_XValue.setProject(P); 101 } 102 103 104 108 public void setUnless(String property) 109 { 110 m_unlessProperty = (property==null) ? "" : property; 111 } 112 113 114 119 public final String getUnlessProperty() 120 { 121 return m_unlessProperty; 122 } 123 124 125 126 131 public void setTrim(boolean b) 132 { 133 m_XValue.setTrim(b); 134 } 135 136 137 142 public boolean willTrim() 143 { 144 return m_XValue.isTrimmed(); 145 } 146 147 148 153 public final void setTransform(ValueTransform t) 154 { 155 m_T = t==null ? ValueTransform.NONE 156 : ValueTransform.from(t.getValue()); 157 } 158 159 160 166 public final ValueTransform getTransform() 167 { 168 return m_T; 169 } 170 171 172 173 174 179 public void setValue(String value) 180 { 181 super.setValue(value); 182 m_XValue.set(value); 183 m_XValue.setIsLiteral(); } 185 186 187 192 public void setVariable(String variable) 193 { 194 setValue(variable); 195 m_XValue.setIsExported(true); 196 } 197 198 199 202 public final void setVar(String variable) 203 { 204 setVariable(variable); 205 } 206 207 208 213 public final boolean isVariable() 214 { 215 return m_XValue.isExported(); 216 } 217 218 219 224 public void setProperty(String property) 225 { 226 setValue(property); 227 m_XValue.setIsProperty(true); 228 } 229 230 231 236 public final boolean isProperty() 237 { 238 return m_XValue.isProperty(); 239 } 240 241 242 247 public void setReference(String refid) 248 { 249 setValue(refid); 250 m_XValue.setIsReference(true); 251 } 252 253 254 259 public final boolean isReference() 260 { 261 return m_XValue.isReference(); 262 } 263 264 265 266 272 public void setScope(String scope) 273 { 274 m_scope = ExportScope.from(scope,ExportScope.PROJECT); 275 } 276 277 278 279 285 public final String getValue() 286 { 287 if (m_XValue.isUndefined()) { 288 return null; 289 } 290 String xvalue = m_XValue.getValue(getProject()); 291 if (xvalue==null) { 292 return m_XValue.get(); } 294 295 ValueTransform t= getTransform(); 296 if (t!=ValueTransform.NONE) { return TransformHelper.apply(t,xvalue,getProject()); 298 } 299 return xvalue; 300 } 301 302 303 304 308 public final boolean isSimpleAssignment() 309 { 310 return (getFile()==null && 311 getResource()==null && 312 getUrl()==null && 313 getRefid()==null && 314 !m_XValue.isUndefined()); 315 } 316 317 318 319 327 public void execute() 328 { 329 333 if (Unless.allowed(m_unlessProperty,getProject())) { 334 if (getName()!=null && isSimpleAssignment()) { 335 if (!ExportScope.ALL.equals(m_scope)) { 336 addProperty(getName(), getValue()); 337 } 338 else { String name1 = getName(); 340 String valu = getValue(); 341 try { 342 System.setProperty(name1, valu); 343 } catch(SecurityException secX) { 344 throw new BuildException(secX,getLocation()); 345 } 346 AntXFixture.unsetProperty(name1); 347 getProject().setInheritedProperty(name1,valu); 348 } 349 } else { 350 super.execute(); 351 } 352 } 353 } 354 355 356 private FlexString m_XValue = new FlexString(); 357 private String m_unlessProperty=""; 358 private ValueTransform m_T= ValueTransform.NONE; 359 private ExportScope m_scope = ExportScope.PROJECT; 360 } 361 362 363 | Popular Tags |