Ant copy-sync

From HaFrWiki42
Revision as of 19:30, 11 November 2012 by Hjmf (talk | contribs) (Created page with "{{TOCright}} Before reading this page, please read Ant template first. This content is under construction end is far from complete. The purpose of this page is to expla...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Before reading this page, please read Ant template first.

This content is under construction end is far from complete.

The purpose of this page is to explain how you can write complicated scripts using a general and specific scripts. The scripts below are used for instruction. They are the result of scripts used in a larger project and the snippets here are not checked for running together.
This script is useful for copy and synchronization of your all your storage hardware, (removable) (hard) disks and usb-sticks. The scripts has 2 different script-file:

  • Build.xml, a project specific script
  • Common.xml, a general script used by the project script.

Requirements to run the examples are:

For installing ant, java and ant contrib see their websites.

Script start

The steps needed for running are described sequential. The Getting the OS gets your OS and sets properties specific to that OS. The example shows only the windows implementation.
Next, it is necessary to know:

GetOS

Common.xml:

  <target name="getos">
     <condition property="isWindoze">
        <os family="windows"/>
     </condition>
     <condition property="isUnix">
        <os family="unix"/>
     </condition>
  </target>

Build.xml:

  <target name="avail-windows" if="isWindoze" >
     <available file="${env.JAVA_HOME}/bin/java.exe"      property="java.home.found" />
     <available file="${env.JMX_HOME_LIB}/jmxri.jar"      property="jmx.home.found"  />
     <available file="${env.JMXR_HOME_LIB}/jmxremote.jar" property="jmxr.home.found"  />
  </target>


Availability

build.xml (definition):

  <property name="lacie.letter"      value="E:" />
  <property name="lacie.name"        value="LaCie        " />
  <property name="lacie.dpid"        value="usr/LaCie_HJMF" />
  <property name="lacie.user"        value="usr" />

Build.xml (available property):

  <available property="lacie.isaDir"    file="${lacie.letter}/${lacie.dpid}"       type="dir" />

Identification

build.xml (target):

  <target name="availability"
          depends="timestamp,startstopwatch,getos, avail-windows"
          description="Checks availability of required builds/jars, aborts if wrong!">
     <fail unless="java.home.found"  message="No JAVA_HOME specified or wrong!"  />
     <trycatch>
        <try>
           <antcall target="internal.test.availability">
              <param name="param"  value="lacie"/>
           </antcall>
        </try>
        <catch>
           <property name="lacie.isaDir" value="false"/> 
        </catch>
     </trycatch>  
     ...
     </target>

Common.xml:

  <target name="internal.test.availability">
     <propertycopy name="isa.isAvailable" from="${param}.isaDir" />            
  </target>

See also

top

  • Ant, Basic Ant information
  • Ant copy-sync, Copy sync example template
  • Ant template. A template for using ant with common and local XML setting examples.

References

top