ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eddie Espino" <ed...@tascola.com>
Subject RE: Extracting Version
Date Tue, 04 Sep 2001 21:39:43 GMT
Thomas Christen,

I saw your use of the incremented build number.  Pretty cool.  However,
I noticed that the build number value that is incremented and stored in
the property file (build.${os.name}.${name}.properties") isn't used
during the currently running ant build.  The newly incremented value is
not used until the next build when it is read from the property file
with "<property file="build.${os.name}.${name}.properties"/> during the
subsequent Ant invocation.  Can you confirm this behavior?

-Ed Espino

-----Original Message-----
From: chr [mailto:chr@active.ch]
Sent: Friday, August 31, 2001 12:07 PM
To: ant-user@jakarta.apache.org
Subject: RE: Extracting Version


I do it different. First I provide you the file content of several files
and 
below you will find additional explanations.

Build.xml :

<project name="csa" default="usage" basedir="..">

  <property file="build.${os.name}.properties"/>

  <property name="name"              value="csa"/>
  <property name="Name"              value="XYZ (XYZ)"/>
  <property name="Longname"          value="Your Long Name"/>
  <property name="year"              value="2001"/>

  <property file="build.${os.name}.${name}.properties"/>

  <!-- package versions -->

  <property name="version"            value="2.0"/>
  <property name="version.spec"       value="2.0.0"/>
  <property name="version.impl"       value="2.0.2"/>

  <!-- generic properties -->

  <property name="dir.src"              value="${basedir}/${name}"/>
  <property name="dir.src.docs"         value="${dir.src}/docs"/>
  <property name="dir.src.lib"          value="${dir.src}/lib"/>
  <property name="dir.src.bin"          value="${dir.src}/src/bin"/>
  <property name="dir.src.etc"          value="${dir.src}/src/etc"/>
  <property name="dir.src.main"         value="${dir.src}/src/main"/>
  <property name="dir.src.sql"          value="${dir.src}/src/sql"/>
  <property name="dir.src.testcases"
value="${dir.src}/src/testcases"/>
  <property name="dir.src.webpages"
value="${dir.src}/src/webpages"/>
  <property name="dir.src.reports"      value="${dir.src}/src/reports"/>

  <property name="dir.build"
value="${basedir}/build/${name}"/>
  <property name="dir.build.bin"        value="${dir.build}/bin"/>
  <property name="dir.build.etc"        value="${dir.build}/etc"/>
  <property name="dir.build.classes"    value="${dir.build}/classes"/>
  <property name="dir.build.javadocs"   value="${dir.build}/javadocs"/>
  <property name="dir.build.lib"        value="${dir.build}/lib"/>
  <property name="dir.build.testcases"  value="${dir.build}/testcases"/>
  <property name="dir.build.webapps"    value="${dir.build}/webapps"/>

  <property name="dir.dist"
value="${basedir}/dist/${name}"/>
  <property name="dir.dist.bin"         value="${dir.dist}/bin"/>
  <property name="dir.dist.docs"        value="${dir.dist}/docs"/>
  <property name="dir.dist.lib"         value="${dir.dist}/lib"/>
  <property name="dir.dist.src"         value="${dir.dist}/src"/>
  <property name="dir.dist.webapps"     value="${dir.dist}/webapps"/>

  <property name="manifest"
value="${dir.build.etc}/manifest"/>
  <property name="manifest.applet"      value="${manifest}_applet"/>

  <!-- compiler-related properties -->
  <property name="build.compiler"  value="modern"/>
  <property name="optimize"        value="off"/>
  <property name="deprecation"     value="on"/>
  <property name="debug"           value="on"/>

  <!-- jarsigning-related properties -->
  <property file="${basedir}/sign.properties"/>
  <property name="keystore"        value="${basedir}/xyz.keystore"/>
  <property name="storepass"       value="${XYZ.storepass}"/>
  <property name="keypass"         value="${XYZ.keypass}"/>
  <property name="alias.1"         value="XYZApplicationProd"/>
  <property name="alias.2"         value="XYZAppletProd"/>


  <!-- javadoc-related properties -->
  <property name="packages"        value="csa.*"/>
  <property name="doc.author"      value="on"/>
  <property name="doc.version"     value="on"/>
  <property name="doc.splitindex"  value="on"/>
  <property name="doc.maxmemory"   value="64m"/>

  <patternset id="exclude.most">
    <exclude name="**/vssver.scc"/>
    <exclude name="**/*.*~"/>
    <exclude name="**/*.bak"/>
  </patternset>

  <patternset id="filter.csa">
    <include name="csa/**/*"/>
  </patternset>

  <patternset id="filter.csa.application">
    <include name="csa/**/*"/>
    <include name="reports/**/*"/>
    <exclude name="**/test/**"/>
    <exclude name="**/*BeanInfo*.class"/>
  </patternset>

  <patternset id="filter.csa.applet">
    <include name="csa/**/*"/>
    <include name="reports/**/*"/>
    <exclude name="**/test/**"/>
    <exclude name="**/*BeanInfo*.class"/>
    <exclude name="**/csaClient.class"/>
  </patternset>

  <patternset id="filter.csa.dt">
    <include name="csa/**/*BeanInfo*.class"/>
  </patternset>

  <path id="classpath">
    <fileset dir="${dir.src.lib}">
      <include name="**/*.jar" />
    </fileset>
<!--
    <fileset dir="${java.home}/../lib">
      <include name="dt.jar" />
    </fileset>
-->
  </path>

  <target name="prepare"
          description="initialization routines and properties">
    <propertyfile file="build.${os.name}.${name}.properties">
      <entry key="build.count" type="int" operation="+" value="1" 
pattern="0000"/>
    </propertyfile>
    <echo 
message="---------------------------------------------------------------
------
---------"/>
    <echo message= "${Name} ${version} Build ${build.count} [${year}]"/>
    <echo message=""/>

    <mkdir dir="${dir.build}"/>
    <tstamp />
  </target>

  <target name="info"
          depends="prepare"
          description="print info about your build environment">
    <echo message="Your Build Environment:"/>
    <echo 
message="---------------------------------------------------------------
------
---------"/>
    <echo message=""/>
    <echo message="Working Directory:      ${basedir}"/>
    <echo message="Source Directory:       ${dir.src}"/>
    <echo message="Build Directory:        ${dir.build}"/>
    <echo message="Distribution Directory: ${dir.dist}"/>
    <echo message="Java Home:              ${java.home}"/>
    <echo message="User Home:              ${user.home}"/>
    <echo message="Java Runtime:           ${java.runtime.name}"/>
    <echo message="Java Spec Version:
${java.specification.version}"/>
    <echo message="Path Separator:         ${path.separator}"/>
    <echo message="File Separator:         /"/>
    <echo message="Processor Arch:         ${os.arch}"/>
    <echo message="OS Name:                ${os.name}"/>
    <echo message="OS Version:             ${os.version}"/>
    <echo message=""/>
  </target>

  <target name="usage"
          depends="prepare"
          description="how to use this build file">
    <echo message=""/>
    <echo message="${Name} Build Instructions"/>
    <echo 
message="---------------------------------------------------------------
------
---------"/>
    <echo message=""/>
    <echo message="The following distributions can be built with this 
buildfile:"/>
    <echo message=""/>
    <echo message="  all:           the complete ${Name} package"/>
    <echo message="  build:         only compile and jar"/>
    <echo message="  dist:          build everything and package it
up"/>
    <echo message="  clean:         remove all files from build- and 
dist-processes"/>
    <echo message=""/>
    <echo 
message="---------------------------------------------------------------
------
---------"/>
    <echo message=""/>
  </target>

  <target name="all"
          depends="prepare,build,dist"
          description="build everything and package it">
    <echo message="   [target] all: all dependencies met"/>
  </target>

  <target name="build"
          depends="prepare,compile.all,jar.all,sign.all"
          description="build everything and package it">
    <echo message="   [target] build: all dependencies met"/>
  </target>

  <target name="dist"
          depends="prepare,build,dist.all"
          description="Creates the distribution">
    <echo message="   [target] dist: all dependencies met"/>
  </target>

  <target name="clean"
          depends="prepare,clean.build,clean.dist"
          description="clean up the archive to it's initial state">
  </target>

  <target name="clean.dist"
          depends="prepare"
          description="clean up distribution directories">
    <delete dir="${dir.dist}"/>
    <echo message="   [target] clean.dist: all dependencies met"/>
  </target>

  <target name="clean.build"
          depends="prepare"
          description="clean up build directories">
    <delete dir="${dir.build}"/>
    <delete>
      <fileset dir="${dir.src}">
        <patternset>
          <include name="*.zip"/>
          <include name="*.log"/>
        </patternset>
      </fileset>
    </delete>
    <echo message="   [target] clean.build: all dependencies met"/>
  </target>

  <target name="clean.src"
          depends="prepare"
          description="clean up source directories">
    <delete dir="${dir.src}"/>
    <echo message="   [target] clean.src: all dependencies met"/>
  </target>

  <!--
=================================================================== -->
  <!-- Compiles the source code
-->
  <!--
=================================================================== -->
  <target name="compile.all"
          depends="prepare">
    <mkdir dir="${dir.build.classes}"/>

    <javac srcdir="${dir.src.main}"
           destdir="${dir.build.classes}"
           debug="${debug}"
           deprecation="${deprecation}"
           optimize="${optimize}" >
      <classpath refid="classpath" />
    </javac>

    <copy todir="${dir.build.classes}">
      <fileset dir="${dir.src.main}">
        <include name="**/*.properties" />
        <include name="**/*.gif" />
        <include name="**/*.jpg" />
        <include name="**/*.xml" />
      </fileset>
    </copy>

    <copy todir="${dir.build.classes}/reports">
      <fileset dir="${dir.src.reports}">
        <include name="**/*.gif" />
        <include name="**/*.jpg" />
        <include name="**/*.xml" />
      </fileset>
    </copy>

    <filter token="VERSION" value="${version}" />
    <filter token="VERSION_IMPL" value="${version.impl}" />
    <filter token="VERSION_SPEC" value="${version.spec}" />
    <filter token="BUILD" value="${build.count}" />
    <filter token="DATE" value="${TODAY}" />
    <filter token="TIME" value="${TSTAMP}" />
    <copy    todir="${dir.build.classes}"
             overwrite="true"
             filtering="on">
      <fileset dir="${dir.src.main}">
        <include name="**/version.txt" />
        <include name="**/defaultManifest.mf" />
      </fileset>
    </copy>
    <mkdir dir="${dir.build.etc}"/>
    <copy    todir="${dir.build.etc}"
             overwrite="true"
             filtering="on">
      <fileset dir="${dir.src.etc}">
        <include name="**/*.mf" />
      </fileset>
    </copy>
  </target>

  <!--
=================================================================== -->
  <!-- Creates the jar archive
-->
  <!--
=================================================================== -->
  <target name="jar.all"
          depends="compile.all">
    <mkdir dir="${dir.build.lib}"/>
    <jar jarfile="${dir.build.lib}/${name}.jar"
         manifest="${manifest}.mf" >
      <fileset dir="${dir.build.classes}">
        <patternset refid="filter.csa.application" />
      </fileset>
    </jar>
    <jar jarfile="${dir.build.lib}/${name}-${version.impl}.jar"
         manifest="${manifest}.mf" >
      <fileset dir="${dir.build.classes}">
        <patternset refid="filter.csa.application" />
      </fileset>
    </jar>
    <jar jarfile="${dir.build.lib}/${name}_applet.jar"
         manifest="${manifest.applet}.mf" >
      <fileset dir="${dir.build.classes}">
        <patternset refid="filter.csa.applet" />
      </fileset>
    </jar>
<!-- currently no dt
    <jar jarfile="${dir.build.lib}/${name}_dt.jar"
         manifest="${manifest}.mf" >
      <fileset dir="${dir.build.classes}">
        <patternset refid="filter.csa.dt" />
      </fileset>
    </jar>
-->
  </target>

  <!--
=================================================================== -->
  <!-- Signs the jar archive
-->
  <!--
=================================================================== -->
  <target name="sign.all" depends="jar.all" if="keypass">
    <signjar jar="${dir.build.lib}/${name}.jar"
             keystore="${keystore}"
             storepass="${storepass}"
             alias="${alias.1}"
             keypass="${keypass}" />
    <signjar jar="${dir.build.lib}/${name}-${version.impl}.jar"
             keystore="${keystore}"
             storepass="${storepass}"
             alias="${alias.1}"
             keypass="${keypass}" />
    <signjar jar="${dir.build.lib}/${name}_applet.jar"
             keystore="${keystore}"
             storepass="${storepass}"
             alias="${alias.2}"
             keypass="${keypass}" />
<!-- currently no dt
    <signjar jar="${dir.build.lib}/${name}_dt.jar"
             keystore="${keystore}"
             storepass="${storepass}"
             alias="${alias}"
             keypass="${keypass}" />
-->
    <echo message="   [target] sign.all: all dependencies met"/>
  </target>

  <!--
=================================================================== -->
  <!-- Creates the API documentation
-->
  <!--
=================================================================== -->
  <target name="javadocs.all"
          depends="prepare">
    <mkdir dir="${dir.build.javadocs}"/>
    <javadoc sourcepath="${dir.src.main}"
             packagenames="${packages}"
             package="Yes"
             destdir="${dir.build.javadocs}"
             author="${doc.author}"
             version="${doc.version}"
             splitindex="${doc.splitindex}"
             windowtitle="${Longname} ${version} API"
             doctitle="${Longname}&lt;br&gt;API Documentation and 
Specification"
             header="&lt;b&gt;${Name}
${version}&lt;/b&gt;&lt;br&gt;&lt;font 
size&#061;-1&gt;Final&lt;/font&gt;"
             bottom="&lt;font size&#061;-1&gt;&lt;br&gt;Copyright &#169;

1998-2001 XYZ&lt;br&gt;CH-80XX Zuerich, Switzerland   All Rights 
Reserved.&lt;/font&gt;"
             maxmemory="${doc.maxmemory}">
      <classpath refid="classpath" />
      <group title="${Name}" packages="csa:csa.*" />
    </javadoc>
  </target>

  <!--
=================================================================== -->
  <!-- Creates the distribution
-->
  <!--
=================================================================== -->
  <target name="dist.all"
          depends="prepare,build,javadocs.all"
          description="Creates the distribution">
    <mkdir dir="${dir.dist}"/>
    <mkdir dir="${dir.dist.bin}"/>
    <mkdir dir="${dir.dist.lib}"/>
    <mkdir dir="${dir.dist.docs}"/>
    <mkdir dir="${dir.dist.docs}/api"/>
    <mkdir dir="${dir.dist.src}"/>

    <jar jarfile="${dir.dist.src}/${name}-src.jar" >
      <fileset dir="${dir.src.main}">
        <patternset refid="filter.csa" />
        <patternset refid="exclude.most" />
      </fileset>
    </jar>

    <copy todir="${dir.dist.lib}">
      <fileset dir="${dir.src.lib}">
        <patternset refid="exclude.most" />
      </fileset>
      <fileset dir="${dir.build.lib}"/>
    </copy>

    <copy file="${dir.src}/build.xml"
tofile="${dir.dist.lib}/build.xml"/>
    <copy todir="${dir.dist.bin}">
      <fileset dir="${dir.src.bin}">
        <patternset refid="exclude.most" />
      </fileset>
    </copy>
    <copy todir="${dir.dist.docs}">
      <fileset dir="${dir.src.docs}">
        <patternset refid="exclude.most" />
      </fileset>
    </copy>
    <copy todir="${dir.dist.docs}/api">
      <fileset dir="${dir.build.javadocs}"/>
    </copy>

    <fixcrlf srcdir="${dir.dist.bin}" includes="ant,antRun"
cr="remove"/>
    <fixcrlf srcdir="${dir.dist.bin}" includes="*.bat" cr="add"/>

    <copy file="${dir.dist.bin}/README" tofile="${dir.dist}/README"/>
    <copy file="${dir.dist.bin}/WHATSNEW"
tofile="${dir.dist}/WHATSNEW"/>
    <copy file="${dir.dist.bin}/TODO" tofile="${dir.dist}/TODO"/>
    <copy file="${dir.dist.bin}/LICENSE" tofile="${dir.dist}/LICENSE"/>
    <zip zipfile="${dir.src}/${name}-${version}.zip"
basedir="${dir.dist}" 
includes="**"/>
  </target>

</project>

And here is the Version-File (version.txt) :

VERSION=@VERSION@
VERSION.SPEC=@VERSION_SPEC@
VERSION.IMPL=@VERSION_IMPL@
BUILD=@BUILD@
DATE=@DATE@

Finaly the Manifest :

Manifest-Version: 1.0
Extension-Name: csa
Specification-Vendor: XYZ-Corp
Specification-Version: @VERSION-SPEC@
Implementation-Vendor-Id: com.xyz-corp
Implementation-Vendor: XYZ-Corp
Implementation-Version: @VERSION-IMPL@
Main-Class: csa.csaClient
Class-Path: here goes your class-path

==================================================
Explanations :

First the

<property file="build.${os.name}.properties"/>

will load the former Build-Number etc.

Then

    <propertyfile file="build.${os.name}.${name}.properties">
      <entry key="build.count" type="int" operation="+" value="1" 
pattern="0000"/>
    </propertyfile>

will increment the Build-Counter.

The part

    <filter token="VERSION" value="${version}" />
    <filter token="VERSION_IMPL" value="${version.impl}" />
    <filter token="VERSION_SPEC" value="${version.spec}" />
    <filter token="BUILD" value="${build.count}" />
    <filter token="DATE" value="${TODAY}" />
    <filter token="TIME" value="${TSTAMP}" />
    <copy    todir="${dir.build.classes}"
             overwrite="true"
             filtering="on">
      <fileset dir="${dir.src.main}">
        <include name="**/version.txt" />
        <include name="**/defaultManifest.mf" />
      </fileset>
    </copy>

does insert the Version-Numbers und Build-Counter in a Version-File
(witch the 
application later will read in as Properties) and the Manifest witch
will be 
used to jar the whole stuff together.

If you plan a new Version (lets say a final build) you need to update
the 
build.xml and set the Versions to a suitable value for your release and
run a 
normal build. If you re-run the build - only the Build-Counter will
reflect 
the new build.

P.S.: The build.xml from above also shows a directory structure widely
used in 
bigger projects.

Regards
Thomas Christen
>===== Original Message From ant-user@jakarta.apache.org =====
>Hi,
>
>The way I do it in my application is store the version information in
the
>Manifest file and have it included in the jar file.
>
>I'm not sure whether this is the best way of doing it. Will be glad to
know
>about other ways of doing it.
>
>Regards,
>Deepa.
>
>-----Original Message-----
>From: Sachin Shah [mailto:Sachin_Shah@kaleconsultants.com]
>Sent: Thursday, August 30, 2001 10:36 PM
>To: ant-user@jakarta.apache.org
>Subject: Extracting Version
>
>
>Hi,
>
>I have an application developed i want to incorporate the version and
build
>information within the application such that everytime i release the
>application i can get the exact version and build information. does any
one
>has idea how to implement this. Is this possible using ant. if yes can
>anyone has code to do the same.
>
>Thanks in advance
>Sachin


Mime
View raw message