for n in `cd src; find . -name "*.java"; cd -`;
do a=`echo $n | cut -d '.' -f2`;
if [[ src/$a.java -nt build/$a.class ]];
then echo src/$a.java;
fi;
done
It lists all the java files in the src tree; then for each one, it removes the suffix ".java" (cut -d '.' -f2
because find .
output is prefixed with .
). It then uses -nt
to test if the java file in the src tree is newer than the corresponding class file in the build tree; if it is newer, it is output. [javac can then use this to compile only the needed src files, instead of using ant
or make
]
The problem is that it is too slow, taking about 275ms. How to make it faster?
Or is there a faster way to do this in bash? I can't see how to do it with find
, diff
, rsync
nor make
(which doesn't seem to traverse trees automatically, and needs explicitly listed source files).
try this: