#!/bin/bash# (C) Richard Whitty 2008# A few bash functions which will probably come in useful to java programmers.CLASSPATH=lib:lib/jogl.jar:lib/gluegenrt.jar:.BINDIR=bin# finds files with the extention provided.# $1 the extenstion to look for# if we are to be verbosefunction find_by_extenstion { find -name \*.$1}# gets a list of all class filesfunction get_class { find_by_extenstion class}# gets a list of all class filesfunction get_src { find_by_extenstion java}# removes class filesfunction clean { get_class | while read do rm $OPTIONS "$REPLY" done}# checks if a source file is due for a rebuild.function needs_rebuild { local srcfile="$1" local binfile="${BINDIR}/${srcfile:0:${#srcfile}-4}class" if [[ "$srcfile" -nt "$binfile" ]] then return 1 else return 0 fi}function get_sources_to_be_updated { get_src|while read srcfile do needs_rebuild "$srcfile" if (( $? == 1 )) then echo $srcfile fi done}# only does the ones that have been updatedfunction rebuild { get_sources_to_be_updated | while read do echo "javac -cp \"$CLASSPATH\" -d $BINDIR \"$REPLY\"" javac -cp $CLASSPATH -d $BINDIR "$REPLY" || break; done}# builds the sources starting from the current directory.function build {cleanrebuild}function tbuild { time build}# prints a handy word/line/char count for the source files.function wordcount { if [[ $VERBOSE == 0 ]] then find -name \*.java -print0 |wc -l --files0-from=- else find -name \*.java -print0 |wc --files0-from=- fi}VERBOSE=0for arg in $@do if [[ "$arg" == "-v" ]] then OPTIONS=" -v " VERBOSE="1" else $arg fidone