Visualise your ANT build with Grand

Ever had the feeling that your build file was a tad complex?

The above is a visualisation provided by the excellent program grand. This particular build script utilises the ASL ant library. I think it might need some love.

Producing the visualisation is very easy. Simply download the jar file and then some ant scripting…

You need to have GraphViz installed which should give you a command line program called “dot”. You can simply try :

dot –help

On the command line to see if you have it installed.

I have a working version on github

Share

Installing JRuby with Intellij (OS X)

GET it from http://jruby.org/

There is a download page, download and exract the tar file somehwere.

I put it in /System/Library/Frameworks/JRuby.framework/jruby-1.5.1

I then created a symbolic link to jruby_current

ln -s jruby-1.5.1/ jruby_current

And then simply add it to my ~/.bash_profile

$vi ~/.bash_profile
export PATH=/System/Library/Frameworks/JRuby.framework/jruby_current/bin:$PATH
#Reload the profile…
$. ~/.bash_profile
#Try out jruby…
$jruby -v
jruby 1.5.1 (ruby 1.8.7 patchlevel 249) (2010-06-06 f3a3480) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_17) [x86_64-java]

Now you can add the JRuby SDK to your Java Module in Intellij:

Now you can have ruby and Java in the same project. Awesome.

Share

Colorised Build Success Message

My current project has a neat trick we picked up where the build has a red or green banner at the end when you run it locally to give good feedback about the build status. I’m not sure who originated it, but thanks!

I just had to tweak it a bit to get it working on OS X so I thought I would document the trick here.

run.sh - OS X

CMD=”./tools/ant/bin/ant -lib ./asl/lib/jdepend $@”
echo “Running command [${CMD}] …”
$CMD
if [ “$?” -ne 0 ]; then
    echo -e “`tput setab 1`  `cat ./ci/failed.txt` `tput setab 0`”
    exit 1
else
    echo -e “`tput setab 2`  `cat ./ci/passed.txt`  `tput setab 0`”
    exit 0
fi

This assumes you have two supporting files ./ci/passed.txt and ./ci/failed.txt which contain the message. You can generate messages to your taste here.

I have provided the files in this example here :

passed.txt

failed.txt

It has also been run under Ubuntu where the following works (it didnt work on OS X which is why I adapted it), but the tput should also work on Ubuntu. I’ve not explicitly tested this one!

if [ “$?” -ne 0 ]; then
    echo -e “\E[30;41m”
    cat ./ci/failed.txt
    echo -e “\E[0m”
    exit 1
else
    echo -e “\E[30;42m”
    cat ./ci/passed.txt
    echo -e “\E[0m”
    exit 0
fi

Under windows you can actually make the entire screen of the terminal change color:

run.bat - WINDOWS

CALL tools\ant\bin\ant %*
IF ERRORLEVEL 1 GOTO RedBuild
IF ERRORLEVEL 0 GOTO GreenBuild
:RedBuild
color 4F
GOTO TheEnd
:GreenBuild
color 2F
:TheEnd
PAUSE
color 07
Share

Passing System Properties and Environment Variables to unit tests in Maven – Update

Unfortunately there was an bug in my previous post.

I had naively assumed that the syntax for environment variables was the same as for system properties but alas not.

The correct code is:


    package
        <plugins>
        <plugin>
               org.apache.maven.plugins
               maven-surefire-plugin
               2.4.2
               
                   
                       some value
                   
                   
                       <property>
                           acceptance.test.host
                           ${acceptance.test.host}
                       </property>
                   
                
           </plugin>
       </plugins>

Share

Passing System Properties and Environment Variables to unit tests in Maven

This is a bit of dark magic …

<pre>
<build>
<defaultGoal>package</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<environmentVariables>
<SOME_ENV_VARIABLE>some value</SOME_ENV_VARIABLE>
</environmentVariables>
<systemProperties>
<property>
<name>someSystemProperty</name>
<value>${thisCanBePassedIn}</value>
</property>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>

I’m afraid I had to update this post as initially I naively assumed that the syntax for environment variables was the same as for system properties. As you can see from above, you have to actually put a separate xml tag in there for the variable.

By putting the value in ${} you can then pass it in with -DsomeSystemProperty from the command line when you do mvn clean install

e.g. :

mvn -DsomeSystemProperty=foobar clean install
Share