Total Pageviews

Tuesday, February 12, 2013

Adding custom design tag using Macrodef in ANT



Below we will learn how to use custom design ANT tag,

Macrodef is one of the most powerful ways of reusing Ant code.  Macrodefs allow us to define a “private method” with “parameters”, called attributes. Most uses of "ant calls"can be replaced by macrodefs. Macrodefs allow easier code flow than trying to specify “depends” which increase faster execution of build script.

       

** Note-  "propertyregex " performs regular expression operations on an input string, and sets the results to a property.

Input- The input String to be processed.

Global-Should a replacement operation be performed on the entire string, rather than just the first occurrence .

Benefit of using Macrodef.

Suppose as a user I have to define property java.compile.rversion and I passed compiler value as 1.5 but by mistake a space or tab character comes before the compiler value. If we will use the same it will fail while compiling but if we use "triminputproperty" and pass the compiler value into this it will auto remove the space before and after the passed value string and we can use the correct value.

property name=" java.compile.version" value="  1.5" ( Input with space character) (Removed angle bracket as they are not supported by blogspot)

  (now using trim if you check the value it will 1.5 without any space)
triminputproperty property="java.compiler.trimmed" input="${java.compile.version}"  

Now using echo we can verify the output.
echo message="${java.compiler.trimmed}" 

Cheers !


No comments:

Post a Comment