วันพุธที่ 23 ธันวาคม พ.ศ. 2558

ant

Dir
<mkdir dir="${what.ever.dir}">
<delete dir="${what.ever.dir}">
<delete includeemptydirs="true">
     
    </delete>
<move file="file/name" tofile="file/name"></move>
<move todir="dest/dir">
     <fileset dir="whatever/dir/it/is">
      <include name="**/*" />
     </fileset>
    </move>
<copy overwrite="true" failonerror="false" file="whatever/file" tofile="whatever/file" />
check file exists
<available file="whatever/file" property="property.is.set.to.true.if.file.exists"/>
Replace content inside the file
<replace file="file/to/replace">
     <replacefilter token="FindWord" value="wordToReplace" />
    </replace>
Execute command
<exec executable="${whatever.command}" failonerror="true" dir="whatever" outputproperty="whatever.property" >
     <arg value="--whatever" />
    </exec>
If
<if>
      <not>
      <equals arg1="${if.this}" arg2="equal.this" />
      </not>
      <then>
</then>
<else>
</else>
</if>
Call the other ant
<target name="newTarget" depends="otherTarget,otherTarget2" />
or
<antcall target="whatever">
     <param name="paramname" value="value" />
    </antcall>
or
<ant dir="whatever/dir" target="executionTarget"/>
define new tag with Macrodef
<macrodef name="macrodefName">
  <attribute name="paramname" />
                ... do whatever @{paramname}...
                </macrodef>
usage
<macrodefName paramname="whatever"/>
Condition set value to the property if true or false
<condition property="whatever.property.to.set" value="value.if.true" else="value.if.false">
      <or>
             <not>
                  <length string="blabla" when="gt" length="10"/>
             </not>
             <isset property="whatever"/>
      </or>
</condition>
PropertyCopy
<propertycopy name="name" from="another.prop"/>
PropertyRegex Regular expression operations on an input string, and sets the results to a property
<propertyregex property="pack.name"
              input="package.ABC.name"
              regexp="package\.([^\.]*)\.name"
              select="\1"
              override="true" />
result : pack.name=ABC var
<var name="whatever.name" value="val" />
remove property as it never been set
<var name="x" unset="true"/>
javac
<javac srcdir="src.dir" destdir="build.dir" />
jar
<jar destfile="dest.jar.name">
 <fileset dir="build.dir" includes="**/*.class" />
 <fileset dir="conf.dir" includes="*.properties" />
</jar>
<jar update="true" destfile="dest.jar.name" basedir="whatever_base_dir" includes="whatever.properties, whatever2.properties, can/be/directory/" />
for
<for list="${lists}" param="whateverparam" parallel="true" threadCount="4" keepgoing="false">
</pre>
sleep
<sleep seconds="5"/>
Timestamp to property
<tstamp>
   <format property="whatever.property" pattern="MM/dd/yy HH:mm:ss" offset="-30" unit="minute"/>
  </tstamp>
Raise build error
<fail unless="this.property.is.false">Error message</fail>
or
<fail>Message
   <condition>
    <not>
     <matches pattern="whatevr" string="whatever" multiline="true" />
    </not>
   </condition>
  </fail>
SSH
<sshexec host="host" trust="true" keyfile="whateverkey"
   username="username" passphrase=""
   command="echo 'Hello'" />
SCP
<scp
   file="whatever/file"
   remotetodir="remote/file"
   trust="true" keyfile="whateverkey" passphrase="" />
zip
<zip destfile="whatever" basedir="dir" includes="**/*" excludes="whatever,*.log" />
ant contribute ref : http://ant-contrib.sourceforge.net/ Installation
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
Usage Example is TryCatch method ref : http://nant.sourceforge.net/release/0.92/help/tasks/index.html Taskdef
<path id="myPathId">
        <fileset dir="target/whatever" includes="**/*.jar" />
        <fileset file="target/whatever.jar" />
    </path>
<taskdef name="myTask" classname="whatever.java.Class" classpathref="myPathId" />
checksum
<checksum algorithm="md5" toDir="whatever">
  <fileset dir="dirctory">
  </fileset>
</checksum>
script
<script language="javascript"> <![CDATA[
...
]]></script>
possible method
projectName.getProperty('whatever.property');
projectName.setProperty('whatever.property', 'value');
example calling target="echo" NOTE : internal tag could be added by
var whatevertagNode = project.createDataType('whatevertag');
whatevertagNode.setWhateverAttr("whatever");
checksum.addWhateverTag(groupFileset);
var o = projectName.createTask('echo');
o.setMessage('whatever');
o.perform();
importClass(java.io.File);
var f = new File(basedir);
f.isDirectory();
 
var touchTask = projectName.createTask('touch');
touchTask.setDatetime("06/28/2000 2:02:17 pm");
var groupFileset = fileHasher.createDataType('fileset');
groupFileset.setDir(file);
touchTask.addFileset(groupFileset);
touchTask.perform(); 
post
<post failonerror="true" verbose="true" to="http://xxx.com?whatever=value" maxwait="600">
    <prop name="param" value="whatever" />
   </post>
uptodate Check if a target file or set of target files is more up-to-date than a source file or set of source files.A set of source files is specified using the nested elements.
<uptodate property="isUpToDate" targetfile="whatever">
      <srcfiles dir="whatever" includes="**/*"/>
    </uptodate>

ไม่มีความคิดเห็น:

LinkWithin

Related Posts Plugin for WordPress, Blogger...