Gradle version in Jenkins build

Out of the box Jenkins can extract the metadata from Maven build for use as environment variables in the build steps, but it doesn’t have the same support for Gradle. This can be achieved using the EnvInject plugin, and a custom task in your build.gradle file. The first step is to setup a task in build.gradle that will print out the project name and version in a format that can be used directly in a properties file....

August 31, 2017 · Nigel Sim

The strange beast of PyTZ and datetime

Update A good explaintation of what is happening is provided here. In this day and age dateutil.tz is the better solution to timezones, as it works as expected with datetime. TL;DR The crux of this post is, make sure to never use datetime.replace(tzinfo=...) when working with PyTZ, use tz.localize(...) instead, otherwise you’ll end up with some very strange times. The PyTZ docs do mention this helper method as a way to fix incorrect conversion across timezones, but out of the box PyTZ timezones seem odd....

November 11, 2014 · Nigel Sim

Simple type checking using property()

Python usually relies of duck typing for type safety, but from time to time it can be handy to enforce some type checking, particularly when new users are going to be using your objects. The following are three utility methods for applying type checking to class properties, using the new style object property() method. def deleter(attr): """Deleter closure, used to remove the inner variable""" def deleter_real(self): return delattr(self, attr) return deleter_real def getter(attr): """Getter closure, used to simply return the inner variable""" def getter_real(self): return getattr(self, attr) return getter_real def setter(attr, valid_types): """Setter closure, used to do type checking before storing var""" def setter_real(self, var): if not isinstance(var, valid_types): raise TypeError("Not of required type: "+str(valid_types)) setattr(self,attr,var) return setter_real def typed(attr, valid_types, docs=""): """Wrapper around property() so that we can easily apply type checking to properties""" return property(getter(attr), setter(attr, valid_types), deleter(attr), docs) # Example class class A(object): a = typed("_a", int) # Testing output a1 = A() a1....

January 8, 2013 · Nigel Sim

Programmatically getting the Maven version of your project

It is often handy to be able to extract the Maven version of your project at run time, either for displaying in an about box, or in debugging information. One option is to read /META-INF/maven/${groupId}/${artifactId}/pom.properties. However, this file is only available in the packaged version of your project, so during development the method will fail. The approach I’ve taken to fulfil this requirement is to create a text (properties) file in the project resources, and have Maven process this....

August 31, 2011 · Nigel Sim

Projects for the new year

These are some project idea’s I’ve been sitting on all year and have not yet started, but hope to in the new year. 1. Python CMS framework in the vein of Drupal, based on Repoze BFG So Drupal is quite a popular community building framework, with good plugin system, and a data model which seems to work well. But I don’t think PHP is the way of the future, at least for me....

December 24, 2008 · Nigel Sim

Zope3 Component Architecture (CA) style Adapters for Java

After programming for Zope3/Plone for the past year I’ve come to really admire the flexibility and elegance that their implementation of the adapter pattern gives us. And, after Martin Aspeli put the call out almost a year ago, and it has not yet been answered, I thought it was time to give it a go. How hard could it be. So, what I’ve developed is a very simple, no dependency, maven available library which should greatly improve the flexibility of your code....

October 15, 2008 · Nigel Sim

Hibernate, spring, and different jars

The situation is this. I had a working application which used Hibernate annotated classes, and JTA for data bindings, within a spring framework. Then I moved the annotated classes into a Jar file, and the application stopped working. Hibernate knew nothing about the classes because the PersistenceAnnotationBeanPostProcessor does not traverse into the JARS on the classpath. Further neither the entity manager or HibernateJpaVendorAdapter have options to specify the explicit paths to the classes....

November 25, 2007 · Nigel Sim

Maven-Ant hybrid

Some brief background. Ant is the stock standard Java build system, much as Make is for C/C++. Maven is a newer Java build system which tried to, amongst other things, solver the Jar dependency hell problem, as well as make a standard project directory layout. From the Maven guide: <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.9</version> </dependency> Now when you go to compile with maven it goes and gets all the dependencies, puts them in your local repository (~/....

July 20, 2007 · Nigel Sim

Multi-node PBS script for non-mpi jobs

function spawn() { NODE=$1 COUNT=$2 echo Spawning $COUNT on $NODE rsh $NODE -n “~/mark.sh” & #rsh $NODE -n “cd $PWD ; ./run.sh –agent –threads $COUNT” & } LAST= COUNT=0 for N in $NODES ; do if [ “$N” = “$LAST” ] ; then COUNT=$[COUNT+1] else if [ 0 -ne $COUNT ] ; then spawn $LAST $COUNT fi COUNT=1 LAST=$N fi done if [ 0 -ne $COUNT ] ; then spawn $LAST $COUNT fi...

July 5, 2007 · Nigel Sim