Thursday, December 15, 2011

ANT, ADF: Adding version info to my build and help about screen


I added two steps to my build (after everything was built) one to create the properties file and the other to package it:
<antcall target="create-version-property" inheritAll="true" inheritRefs="true"/>
<antcall target="inject-version-file" inheritAll="true" inheritRefs="true"/>

Creating the file.
  <target name="create-version-property">
   <-- check that the jar file is available -->
    <available file="${build.file.location}/lib/svnant.jar" property="SVN_ANT_AVAILABLE" />
        <fail unless="SVN_ANT_AVAILABLE" message="Run jar target to generate the required task"/>
       <-- load the svn ant plugin classpath -->
        <taskdef resource="org/tigris/subversion/svnant/svnantlib.xml">
                <pathelement location="${build.file.location}/lib/svnant.jar"/>
                <pathelement location="${build.file.location}/lib/svnClientAdapter.jar"/>
                <pathelement location="${build.file.location}/lib/svnjavahl.jar"/>
                <pathelement location="${build.file.location}/lib/svnkit.jar"/>
       <-- add all svn settings -->
          password="build_user_password" failonerror="true"
        <-- Get all the svn info into ant properties-->
        <svn refid="svn.settings">
          <info target="${basedir}"/>
    <-- Record deploy time in a property -->
      <format property="deploy.time" pattern="dd MMM yyyy hh:mm aa"/>
    <mkdir dir="deploy/META-INF"/>
    <-- Add all the info into a properties file -->
      comment="Version properties">
      <entry key="minor.release" value="${minor.version}" operation="+"/>
      <entry key="major.release" value="${major.version}" operation="+"/>
      <entry key="patch.release" value="${revision.version}" operation="+"/>
      <entry key="" value="${}" operation="+"/>
      <entry key="" value="${build.number}" operation="+"/>
      <entry key="deploy.time" value="${deploy.time}" operation="+"/>

Adding the file to the end artifact:
<target name="inject-version-file">
  <jar destfile="${the.jar.filename.and.location}" update="true">
      <zipfileset file="deploy/META-INF/" prefix="META-INF/"/>


I wrote a simple popup screen with all this info in with a link in our template (so it will be available on all screens).

The info is gleened from the file the following code is in the backing bean for the about screen. (This code was taken from code written by a collegue - thanks Hannes)

FacesContext fc = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest) fc.getExternalContext().getRequest();
ServletContext servletContext = request.getSession().getServletContext();

// extract the application name from the ADFContext
String appName = ADFContext.getCurrent().getApplicationName();
if((appName != null) && (!"".equals(appName))) {
  applicationName = appName;
} else {
 applicationName = "|WesbankADF|";

String clientMachine = request.getRemoteHost();
String clientIP = request.getRemoteAddr();

InputStream is = getClass().getResourceAsStream("/META-INF/");
try {
  Properties props = new Properties();
  version =
      String.format("%s.%s.%s", props.getProperty("major.release"),
  build =
  String.format("%s (%s) @ %s", props.getProperty(""),
      props.getProperty(""), props.getProperty("deploy.time"));
} finally {

for team city users

No comments:

Post a Comment