Linux: einfaches Frontend für Apache Ant mit Dialog

Für ein Projekt (hier) arbeite ich ausschliesslich auf der Kommandozeile. Um mir wenigstens den Build-Prozess "schick" zu machen, habe ich mir mit Dialog unter Linux ein kleines Frontend für den Ant-Build gebaut.

Version 1:

#!/bin/sh

########################################
#                                      #
# Simple Build Script Frontend for ANT #
#                                      #
# Author:    Ronny Friedland           #
# Since:     16.08.2011                #
# Version:   1.0                       #
#                                      #
########################################

# change this path to the build script
basedir="/home/ronnyfriedland/dev/projects/foo"
buildscript="$basedir/build.xml"

# please do not modify from here

if [ ! -f $TMPFILE ]; then
 touch $TMPFILE
fi

TMPFILE=`mktemp`
buildfailed="no"
buildlog=""

while [ true ]; do
 dialog --clear --title "Simple Build Management" --inputbox "Execute Buildskript (last build failed: $buildfailed)" 0 0 $buildscript 2> $TMPFILE

 if [ "$?" = 0 ]; then
  # read value from dialog which was written to temp file
  buildscript=`cat $TMPFILE`
  # call ant with buildscript
  buildlog=`ant -buildfile $buildscript`
  # save return code from ant in variable and show error
  if [ "$?" = 0 ]; then
   buildfailed='no'
  else
   buildfailed='yes'
   dialog --clear --title "Simple Build Management" --msgbox "$buildlog" 10 50
  fi
 else
  # break loop
  break
 fi
done;

# cleanup temp file
rm $TMPFILE

exit 0

Startet man das Skript, wird man nach der build.xml gefragt. Der Pfad dahin ist im Skript angegeben, kann aber geändert werden. Es wird der Default-Task ausgeführt.

image0

Version 2, bei der die verfügbaren Targets geparst und über Checkboxen ausgewählt werden.:

#!/bin/sh

########################################
#                                      #
# Simple Build Script Frontend for ANT #
#                                      #
# Author:    Ronny Friedland           #
# Since:     16.08.2011                #
# Version:   2.0                       #
#                                      #
########################################

# change this path to the build script
basedir="/home/ronnyfriedland/dev/projects/foo"
buildscript="$basedir/build.xml"

# please do not modify from here
if [ ! -f $TMPFILE ]; then
 touch $TMPFILE
fi

if [ ! -f $buildscript ]; then
 echo "Cannot find build script: $buildscript"
 exit 1
fi

# parse buildscript for targets
targets=(`grep " $TMPFILE

 if [ "$?" = 0 ]; then
  # read value from dialog which was written to temp file
  target=`cat $TMPFILE | sed 's/"//g'`
  # call ant with buildscript
  buildlog=`ant -buildfile $buildscript $target`
  # save return code from ant in variable and show error
  if [ "$?" = 0 ]; then
   buildfailed='no'
  else
   buildfailed='yes'
   dialog --clear --title "Simple Build Management" --msgbox "$buildlog" 20 50
  fi
 else
  # break loop
  break
 fi
done;

# cleanup temp file
rm $TMPFILE

exit 0

In dieser Version ist der Pfad zur build.xml fest im Skript vorgegeben und kann nicht geändert werden. Allerdings kann hier gewählt werden, welcher Task ausgeführt werden soll. Schön wäre noch gewesen, wenn die Beschreibung aus den Tasks mit angezeigt werden könnte.

image1