How would you write a build.xml
file, using neither custom code nor external dependencies (such as a shell script), that:
Additionally:
Bonus:
git
revision number (like a subversion revision number).Clarification:
Thank you for any examples. Here are some related sites that describe how to perform similar tasks:
This “MAJOR. minor. revision-build” is the way PKP uses to name a version and is a variant of something called “Semantic versioning”. To make it clear, let's take some real examples and see how they look like: Version tag.
Reading version numbers For example: 1.2. 3 These numbers have names. The leftmost number (1) is called the major version. The middle number (2) is called the minor version. The rightmost number (3) is called the revision but it may also be referred to as a "point release" or "subminor version".
A version number is a unique sequence of numbers which identifies the state of development of computer software.
There are simple rules that indicate when you must increment each of these versions: MAJOR is incremented when you make breaking API changes. MINOR is incremented when you add new functionality without breaking the existing API or functionality. PATCH is incremented when you make backwards-compatible bug fixes.
The build_info.properties
file:
build.major.number=00 build.revision.number=00 build.minor.number=00
The build.xml
file:
<?xml version="1.0" encoding="UTF-8"?> <project name="project" default="current-number"> <property file="build_info.properties"/> <property name="build.number" value="${build.major.number}.${build.minor.number}.${build.revision.number}"/> <target name="current-number"> <echo>Current build number:${build.number}</echo> </target> <target name="compile"> <antcall target="revision"></antcall> </target> <target name="dist"> <antcall target="minor"></antcall> </target> <target name="revision"> <propertyfile file="build_info.properties"> <entry key="build.revision.number" type="int" operation="+" value="1" pattern="00"/> </propertyfile> </target> <target name="minor"> <propertyfile file="build_info.properties"> <entry key="build.minor.number" type="int" operation="+" value="1" pattern="00"/> <entry key="build.revision.number" type="int" value="0" pattern="00"/> </propertyfile> </target> <target name="major"> <propertyfile file="build_info.properties"> <entry key="build.major.number" type="int" operation="+" value="1" pattern="00"/> <entry key="build.minor.number" type="int" value="0" pattern="00"/> <entry key="build.revision.number" type="int" value="0" pattern="00"/> </propertyfile> </target> <target name="all"> <propertyfile file="build_info.properties"> <entry key="build.major.number" type="int" operation="+" value="1" pattern="00"/> <entry key="build.minor.number" type="int" operation="+" value="1" pattern="00"/> <entry key="build.revision.number" type="int" operation="+" value="1" pattern="00"/> </propertyfile> </target> </project>
This solution does increment minor or revision number automatically if a compile or a dist target has been selected. The incrementation can be switched off if one of the following properties has been set:
If the property inc.major has been set, then the major number will be incremented and the other both values will be set to zero. The SHA-1 checksum is being calculated by the textual representation of the version file.
By the way: If would have been allowed, you could create your own ant task in java script, which is included in JDK 6.
Now here's the ant file
<?xml version="1.0" encoding="UTF-8"?> <project name="Numbers" default="dist" basedir="."> <property name="version.file" location="${basedir}/version.properties"/> <target name="inc.revision.properties" unless="no.increment.revision"> <propertyfile file="${version.file}"> <entry key="minor.number" default="00" operation="=" pattern="00" type="int"/> <entry key="major.number" default="00" operation="=" pattern="00" type="int"/> <entry key="build.number" default="00" operation="+" pattern="00" type="int"/> </propertyfile> </target> <target name="inc.minor.properties" unless="no.increment.minor"> <propertyfile file="${version.file}"> <entry key="minor.number" default="00" operation="+" pattern="00" type="int"/> <entry key="major.number" default="00" operation="=" pattern="00" type="int"/> <entry key="build.number" value="00" operation="=" type="int"/> </propertyfile> </target> <target name="inc.major" if="inc.major"> <property name="no.increment.minor" value="true" /> <property name="no.increment.revision" value="true" /> <propertyfile file="${version.file}"> <entry key="minor.number" value="00" operation="=" pattern="00" type="int"/> <entry key="major.number" default="00" operation="+" pattern="00" type="int"/> <entry key="build.number" value="00" operation="=" pattern="00" type="int"/> </propertyfile> <load.version.info/> </target> <target name="inc.minor" depends="inc.major,inc.minor.properties"> <property name="no.increment.revision" value="true"/> <load.version.info/> </target> <target name="inc.revision" depends="inc.major,inc.revision.properties"> <load.version.info/> </target> <macrodef name="load.version.info"> <sequential> <property file="${version.file}"/> <checksum file="${version.file}" property="sha1.number" algorithm="SHA" format="CHECKSUM"/> <echo>Version: ${major.number}.${minor.number}.${build.number}</echo> <echo>SHA1: ${sha1.number}</echo> </sequential> </macrodef> <target name="compile" depends="inc.revision" description="Compile Task"/> <target name="dist" depends="inc.minor, compile" description="Dest Task"/> </project>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With