Archive for November, 2009
My “utility belt” now open-sourced…
Posted by rn in Java, Software Engineering on November 17th, 2009
Most programmers over the course of their careers accumulate a “utility belt” of sorts.
Well I just open-sourced mine – http://code.google.com/p/visural-common/
Primarily this is to support visural-wicket and another open-source project I’m working on a little. Also, I end up rewriting this stuff at pretty much every job in some form or other. So if this code is open-source I won’t have to write it again – at least in theory
My “belt” used to be a lot bigger, but there’s more and more other open implementations of these sorts of things which I’m really happy with, and happy not to have to maintain by own version of. This is stuff that’s left over, and for a large part is just part of my style of code writing.
There’s not much of great interest in there – I personally think some of the small “helper” methods that are in there can make code read very elegantly, but hey, this is my “utility belt”, so I’m biased.
In any case – my reasons for open-sourcing this are purely pragmatic, but take a look through and take out the stuff you like.
Automatic release packaging w/ version numbers for Netbeans Java Projects…
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.

