Posts Tagged automation

Automatic release packaging w/ version numbers for Netbeans Java Projects…

http://www.flickr.com/photos/lrargerich/3029485203/I just did a nice little Netbeans build.xml hack for the visural-wicket project to add a build target which packages a release of the library for distribution (e.g. on Google Code).

A version number is added to the project in the root level file version.properties

#  Copyright 2009 Richard Nichols.
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
#  under the License.

project.version=0.1

A licence file to be copied into the distribution archive is also added in licence.txt

Then finally the build.xml target

    <target name="-pre-init">
        <property file="version.properties"/>
        <property name="dist.jar" value="dist/${ant.project.name}-${project.version}.jar"/>
    </target>

    <target name="package_for_release" depends="jar,javadoc">
        <mkdir dir="build/release"/>
        <copy file="${dist.jar}" todir="build/release/"/>
        <copy file="licence.txt" todir="build/release/"/>
        <mkdir dir="build/release/doc"/>
        <copy todir="build/release/doc">
            <fileset dir="dist/javadoc" includes="**"/>
        </copy>
        <mkdir dir="build/release/src"/>
        <copy todir="build/release/src">
            <fileset dir="src" includes="**"/>
        </copy>
        <mkdir dir="build/release/test"/>
        <copy todir="build/release/test">
            <fileset dir="test" includes="**"/>
        </copy>
        <zip basedir="build/release/" includes="**" destfile="dist/${ant.project.name}-${project.version}.zip"/>
    </target>

Basically all we do here is to create a new temp folder in build/release, which will copy all the distro files into and then zip into a final archive. We also do a hack to change the dist.jar property to include the version number extracted from the version.properties file. This needs to be “-pre-init” as properties in Ant are immutable once set.

The task copies through the Javadocs, source, tests, binary JAR and licence and packages it into an appropriately named .ZIP.

The target & associated files are appropriate to be used in any Netbeans Java project – there is no hard-reference to visural-wicket.

, , ,

No Comments

Add Package (or Class) Filtering To Your Findbugs Ant Task

Following on from my last post about using hbm2java to generate a @Entity bean DAO layer for our application, Findbugs, the great automatic bug finding tool, will find a lot of issues with Hibernate’s auto-generated code (primarily around exposing internal Date objects to callers). So long as this is something we are aware of and don’t have a problem with, we don’t want find bugs to tell us about this stuff. It’s possible to filter out an entire package or class tree with the use of Findbugs’ filters.

For example, say we wanted to filter out the classes in the package com.mycom.dbautodao, we could create a findbugs_filter.xml which contains:

<FindBugsFilter>
  <Match>
    <Package name="~com\.mycom\.dbautodao\..*"/>
  </Match>
</FindBugsFilter>

This uses a regular expression to filter out checks against all contents and sub-packages of the com.mycom.dbautodao package.

Similarly it’s possible to do the same with a <class name=”myregex”/> element rather than a <package/> element for finer control.

To enable the filtering we just need modify the tag in our Ant build file to include the filter, e.g.

<findbugs home="${findbugs.home}" output="xml" outputFile="${basedir}/dist/findbugs/findbugs.xml" excludefilter="findbugs_filter.xml">

While on the topic of regular expressions, I often find myself using this online regex checker tool which uses Java’s regex syntax – http://www.fileformat.info/tool/regex.htm. It’s a really quick and handy way of writing and testing a regular expression, since you can enter test string which provide both positive and negative test cases to develop against.

, , , , ,

No Comments