Apache Ant
Apache - Ant
Apache Ant is
a Java library and command-line tool whose mission is to drive processes described in build
files as targets and extension points dependent upon each other. The main known usage of Ant
is the build of Java applications.
Ant
ant (executable)
An component which is to be installed on computer which is intend to open an build.xml with Ant project
build.xml
This file contains Ant project ant its contents. It is intend to be opened and
executed by ant executable.
Note: To open ant build.xml you usually type command ant -f
build.xml . There are also many other usuable commands especially to put some parameters -
"-Dusername=username -Dpass=password"
Ant project
And project is the root part of document (file) which contains Tasks and other
commands that are interpreted by Apache Ant interpreter. This is example ant
project:
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns:bp="https://procesy5.pl/biale_plamy-schema.xsd"
xmlns:ogc="http://www.opengis.net/ogc"
basedir="." name="biale_plamy-generate_data" default="default">
<tstamp><format property="TODAY_UK" pattern="yyyy-mm-dd"/></tstamp>
<property name="plamy_prefix" value="" /><!-- prefiks dla danych -->
<property name="pointsTable" value="Rozdzielcza_test2_bzyk_punkty_adresowe" />
<property name="origWaysTable" value="Rozdzielcza_test2_bzyk_drogi"/>
<property name="username" value="a.binder"/>
<property name="pass" value="set_as_param_-Dpass=pass" />
<property name="bypass_errors" value="1"/><!-- to continue transform even with errors -->
<property name="build.log" value="build${plamy_prefix}.log"/>
<property name="build.log.old" value="${build.log}.old"/>
<target name="build_log_exists">
<condition taskname="build.log.old_file" property="build_log_exists" value="tak">
<!--<echo>sprawdzam czy jest ${build.log} </echo>-->
<available file="${build.log}" filepath="." />
</condition>
</target>
<target name="build.log.old_file" depends="build_log_exists">
<!--<move file="${build.log}" tofile="${build.log}.old"/>-->
<echo append="true" file="${build.log}"> Archiwizacja loga w dniu ${TODAY_UK}
</echo>
<concat destfile="${build.log.old}" append="true">
<filelist dir="." files="${build.log}"/>
</concat>
<delete file="${build.log}"/>
</target>
<target name="default">
<antcall target="build.log.old_file"/>
<antcall target="biale_plamy-generate_data"/>
</target>
/>
Ant Task
This is part of Ant project
which is intend to group some tasks to be done. The tasks can call each other based on some
conditions.
Task Dependencies Executions
Ant supports to organize different tasks by relating them together, that can be
executed automatically first the one which is in typed in last dependence. Together with
conditions especially with the ant <condition> directive you can easily exectute some ant
target and it will follows needed steps to create it.
And there is target on which it
depends:
So by developing some project when you are targeted step-by-step on executing some transformations and step, with together building ant Project with this tasks, you can forget to which are steps are needed to execute the same scenario. Just type in task Dependency instruction as in example:
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns:bp="https://procesy5.pl/biale_plamy-schema.xsd"
xmlns:ogc="http://www.opengis.net/ogc"
basedir="." name="test_depend" default="import_ssl_certificates_to_system"
<target name="import_ssl_certificates_to_system" depends="import_ssl_certificates_to_system_check" unless="${API_address_cert.installed_exists_ok}" description="It is good to be sure if we are correct keys to ">
<echo> We will upload certificate to ${cacert_dir}/ </echo>
<!--<property name="cacert_dir" value="${java.home}/lib/security/cacerts"/>-->
<delete file="${API_address_cert.txt}"/>
<delete file="${API_address_cert.cert}"/>
<delete file="${API_address_cert.installed}"/>
<exec output="${API_address_cert.txt}" executable="${gnutls-cli}" >
<arg line=" --print-cert ${API_address} < /dev/null "/>
</exec>
<exec input="${API_address_cert.txt}" output="${API_address_cert.cert}" executable="openssl">
<arg line="x509"/>
</exec>
<exec executable="keytool">
<arg line="-import -v -trustcacerts -alias ${API_address} -file ${API_address}.cert -keystore ${cacert_dir} -storepass ${Password_for_cacerts} -noprompt"/>
</exec>
<echoproperties destfile="${API_address_cert.installed}">
<propertyset><propertyref name="API_address"/></propertyset>
</echoproperties>
</target>
<target name="import_ssl_certificates_to_system_check" description="Veryfing to be sure if we have already a certificate. Else we should add it ">
<!-- This is example by Arkadiusz Binder with Procesy5 system workaround example -->
<echo>We check if we have already this SSL certificate - </echo>
<!--<property name="API_address" value="biuro.biall-net.pl"/>-->
<exec command="keytool" output="${API_address_cert.installed}">
<arg value="-list"/>
<arg value="-alias"/>
<arg value="${API_address}"/>
<arg value="-keystore"/>
<arg value="${cacert_dir}"/>
<arg value="-storepass"/>
<arg value="${Password_for_cacerts}"/>
<arg value="-noprompt"/>
</exec>
<loadfile property="API_address_cert.installed_contents" srcfile="${API_address_cert.installed}" />
<condition property="API_address_cert.installed_exists_ok" taskname="import_ssl_certificates_to_system" else="NotInstalled" >
<contains string="${API_address_cert.installed_contents}" substring="${API_address}"/>
</condition>
<echo message="API_address_cert.installed_exists_ok ${API_address_cert.installed_exists_ok} . "/>
</target>
And
the end of XML file </project>