Skip to main content

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

Build

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">
            <classpath>
                <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"/>
            </classpath>
        </taskdef>
       <-- add all svn settings -->
        <svnSetting
          svnkit="true"
          javahl="true"
          username="build_user"
          password="build_user_password" failonerror="true"
          id="svn.settings"/>
        <-- Get all the svn info into ant properties-->
        <svn refid="svn.settings">
          <info target="${basedir}"/>
        </svn>
    <-- Record deploy time in a property -->
    <tstamp>
      <format property="deploy.time" pattern="dd MMM yyyy hh:mm aa"/>
    </tstamp>
    <mkdir dir="deploy/META-INF"/>
    <-- Add all the info into a properties file -->
    <propertyfile
      file="deploy/META-INF/version.properties"
      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="svn.build.number" value="${svn.info.lastRev}" operation="+"/>
      <entry key="ci.build.number" value="${build.number}" operation="+"/>
      <entry key="deploy.time" value="${deploy.time}" operation="+"/>
  </propertyfile>
</target>

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/version.properties" prefix="META-INF/"/>
  </jar>
</target>

Screen

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 version.properties 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/version.properties");
try {
  Properties props = new Properties();
  props.load(is);
  version =
      String.format("%s.%s.%s", props.getProperty("major.release"),
      props.getProperty("minor.release"),
      props.getProperty("patch.release"));
  build =
  String.format("%s (%s) @ %s", props.getProperty("svn.build.number"),
      props.getProperty("ci.build.number"), props.getProperty("deploy.time"));
} finally {
  is.close();
}

for team city users
http://devnet.jetbrains.net/thread/282763

Comments

Popular posts from this blog

ADF sort of generic screen for tables with the same structure

We have a couple (about a hundred) of tables with the same structure (Code, Description, Create Date, Update Date). So I wanted to do something simple so that I did not have to create all these screens 1) EO   I created the EO based on one of the tables I had that had the above columns. I then Added a transient attribute called table name to my EO based on a groovy expression. (the expression needs to change as I am reading web tier stuff from the model layer but I will fix this later) I then generated a java class for my EO. And added the following overriden method to my newly created java class. protected StringBuffer buildDMLStatement(int i, AttributeDefImpl[] attributeDefImpl,   AttributeDefImpl[] attributeDefImpl2, AttributeDefImpl[] attributeDefImpl3, boolean b) {   StringBuffer statement = super.buildDMLStatement(   i, attributeDefImpl, attributeDefImpl2, attributeDefImpl3, b); return new StringBuffer(StringUtils.replace(statement.to...

Util code

public static MethodExpression getMethodExpression( String expr, Class returnType, Class[] argTypes){ FacesContext fc = FacesContext.getCurrentInstance(); ELContext elctx = fc.getELContext(); ExpressionFactory elFactory = fc.getApplication().getExpressionFactory(); return elFactory.createMethodExpression( elctx, expr, returnType, argTypes); } public static javax.faces.el.MethodBinding getMethodBinding( String expr, Class[] argTypes){ FacesContext fc = FacesContext.getCurrentInstance(); ELContext elctx = fc.getELContext(); return fc.getApplication().createMethodBinding(expr, argTypes); } SetPropertyListener listener = new SetPropertyListener( ActionEvent.class.getName()); listener.setFrom(link.getRoute()); listener.setValueExpression("to", JSFUtils.getValueExpression("#{pageFlowScope.route}", String.class)); action.addActionListener(listener); AdfFacesContext.getCurrentInstance().getPageFlowScope() .put("route", lin...

MANIFEST.MF merge JDeveloper for an executable jar

Goto your project > properties. Then click on deployment in the menu. Edit or add a jar deployment profile. Fill in the details under jar options (select Include manifest and give it a main class name) Also remember that the merge functionality only works with a BLANK line at the end of the merge file. REALLY this caught me. My merge file contents: Class-Path: commons-codec-1.3.jar [...empty line here CRLF...]