JReleaseInfo

JReleaseInfo Task

Parameter

AttributeDescriptionRequired
targetDirDirectory path where java source file should be stored (see hints)Yes
classNameName of the class to be generated, e.g. AppReleaseInfoYes
packageNamePackage of the class to be generatedNo
buildnumFileFilepath of Buildnumber-File (see hints)No
buildNumIncrementIncrement for the Buildnumber (Default is 1)No
buildNumPropertyProperty name for build numberNo
projectName of the Project/Product (also used in viewer title bar)No
versionVersion of the Project/Product (also used in viewer title bar)No
withViewerEmbed code for Swing-Viewer (true/false=default)No

Nested elements

Parameter

You can use nested <Parameter>elements to specify fields (and methods) in the BuildInfo file. Parameter is an ANT built-in type with the attributes name, type, value.

AttributeDescriptionRequired
nameName of the property name/value pairYes
valueValue of the property name/value pairYes
typeType of the value (for now: String, int, boolean, Integer, Boolean) String is DefaultNo

Examples

Definition of Task

First define the task with "taskdef". The attribute "name" defines the name under which the task will be called, "classname" is the name of the ant task name in jreleaseinfo-1.3.0.jar and "location" in the <classpath> elements shows where jreleaseinfo-1.3.0.jar can be found.

Note: If you use a property like in the example ${lib.dir} which is defined in another target, be sure it was already processed. Embed your taskdef in a target which is dependend from the definition target.

<taskdef 
   name="jreleaseinfo" 
   classname="ch.oscg.jreleaseinfo.anttask.JReleaseInfoAntTask"
   classpath="${lib.dir}/jreleaseinfo-1.3.0.jar" />
            

Minimal example

<jreleaseinfo targetDir="${basedir}/src/java" className="MyReleaseInfo" />
            

After running, the file src/java/MyBuildInfo.java will provide with no package defined, but with the following single method:

final public static Date getBuildDate();
            

Example of an extended Definition

This example contains the build-number, which is automatically generated. Furthermore getter methods for version, revision and other flags are defined. The build-number is stored in the "buildnumFile" for further use. If the file defined in the attribute "buildnumFile" does not exist, it will be generated and the number set to 1.

<jreleaseinfo 
   className="MyReleaseInfo" 
   packageName="com.mypack"
   targetDir="${basedir}/src/java" 
   project="MyProject"
   version="1.3"
   withViewer="true" 
   buildNumFile="${basedir}/buildnum.properties"
   buildNumProperty="buildnum"
   >
   <parameter name="VersionNum"  type="int"      value="1" />
   <parameter name="RevisionNum" type="Integer"  value="3" />
   <parameter name="Debug"       type="boolean"  value="false" />
   <parameter name="Open"        type="Boolean"  value="true" />
</jreleaseinfo>
            

After running the file MyReleaseInfo.java in the package com.mypack in the directoy src/java will expose the following methods, and an embedded viewer:

final public static Date    getBuildDate();

final public static String  getProject();

final public static String  getVersion();

final public static int     getBuildNumber();

final public static int     getVersionNum();

final public static Integer getRevisionNum();

final public static boolean isDebug();

final public static Boolean isOpen();

public static void main(String[] args);
            

buildNumFile (optional)

If this attribute is set, a running build number is embedded. The build number is stored in the defined file. If the file does not yet exist, it will be created and the build number will be set to 1.

buildNumIncrement (optional)

With this attribute the increment can be set. Typically the increment is 1, which also is the default. There are cases where a project and its subproject will use the same BuildNumFile, but all should get the same buildNumber. So the subproject have to set the increment to 0.

buildNumProperty (optional)

If you provide a name with this attribute (and the buildNumFile is set!) the build number is also assigned to the property and can be accessed from within Ant:

      <echo message="Build-Number: ${buildnum}" />
            

withViewer (optional)

With this attribute, a viewer class is embedded. If you set the generated ReleaseInfoFile as Main-class in your jar file, you can show the release information in a window application.

Example of using JReleaseInfo in an Ant-Build file

Each call to JReleaseInfo AntTasks results in a new source file. We want a new MyReleaseInfo.java file when we are building a new release. We made the release-target dependent from update_jreleaseinfo-target.

            
   <!-- ================================================================ -->
   <!-- JReleaseInfo                                                     -->
   <!-- ================================================================ -->
   <target name="update_jreleaseinfo" depends="init">
      <echo  message="creating JReleaseInfo File in ${src.dir}" />
      <taskdef 
         name="jreleaseinfo" 
         classname="ch.oscg.jreleaseinfo.anttask.JReleaseInfoAntTask"
         classpath="${lib.dir}/jreleaseinfo-1.3.0.jar" />

      <jreleaseinfo 
         className="MyReleaseInfo" 
         packageName="${packagename}"
         targetDir="${src.dir}/java" 
         project="${project}"
         version=${version}"
         withViewer="true" 
         buildNumFile="${basedir}/buildnum.properties"
         buildNumProperty="buildnum"
         >
         <parameter name="company"        value="${company}"/>
         <parameter name="buildTimeStamp" value="${tstamp_build}" />
         <parameter name="home"           value="${web}" />
         <parameter name="mail"           value="${mail}" />
         <parameter name="copyright"      value="${copyright}"/>
      </jreleaseinfo>
   </target>

   <!-- ================================================================ -->
   <!-- Jar                                                              -->
   <!-- ================================================================ -->
   <target name="jar" depends="init">
      ...
      <jar jarfile="${build.dir}/${project}-${version}.jar">
         <manifest>      
            <attribute name="Main-class"   value="${packagename}.MyReleaseInfo"/>
         </manifest>
         ...
      </jar>
   </target>

   <!-- ================================================================ -->
   <!-- Release                                                          -->
   <!-- ================================================================ -->
   <target name="release" depends="clean, update_jreleaseinfo, jar">
      ...
   </target>
            

Hints

Path definitions

You should not use relative path definitions (e.g. for TargetDir and BuildNumFile). Instead use the ant variable ${basedir} or a fully qualified path.

Demo Project

The distribution contains a small demo project, containing only the (generated) releaseinfo class.

The target show_info in the ant buildfile demo_build results in the following steps:

  • delete subdirectory demo if it exists
  • generate the JReleaseInfo sourcefile using a new buildNumber
  • compile the sourcefile
  • pack it in a jar file
  • call the Main-class of the jar file
          
C:\proj\oscg\jreleaseinfo>ant  -f demo_build.xml show_info
Buildfile: demo_build.xml

init:

clean:
   [delete] Deleting directory C:\proj\oscg\jreleaseinfo\demo

update_jreleaseinfo:
   [echo] creating JReleaseInfo File in C:\proj\oscg\jreleaseinfo/demo/src
   [echo] The current build number is 12

compile:
   [mkdir] Created dir: C:\proj\oscg\jreleaseinfo\demo\classes
   [javac] Compiling 1 source file to C:\proj\oscg\jreleaseinfo\demo\classes

jar:
   [jar] Building jar: C:\proj\oscg\jreleaseinfo\demo\jreleaseinfo_demo-1.0.0.jar

release:

show_info:

BUILD SUCCESSFUL

As a result, the well known info window will appear:

JReleaseInfo-Viewer