annotate extra/soundsoftware/extract-javadoc.sh @ 203:1e55195bca45 feature_20

Pull doc extractor script out into separate javadoc, doxygen, and controller scripts
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Mon, 07 Feb 2011 16:46:28 +0000
parents 0d1c6fa50d3a
children c3544e9fd588
rev   line source
chris@203 1 #!/bin/bash
chris@168 2
chris@203 3 hgdir="/var/hg"
chris@203 4 docdir="/var/doc"
chris@168 5
chris@203 6 project="$1"
chris@203 7 targetdir="$2"
chris@168 8
chris@203 9 projectdir="$hgdir/$project"
chris@203 10
chris@203 11 if [ -z "$project" ] || [ -z "$targetdir" ]; then
chris@203 12 echo "Usage: $0 <project> <targetdir>"
chris@203 13 exit 2
chris@168 14 fi
chris@168 15
chris@203 16 if [ ! -d "$projectdir" ] || [ ! -d "$projectdir/.hg" ]; then
chris@203 17 echo "No hg repo found at $projectdir"
chris@203 18 exit 1
chris@203 19 fi
chris@168 20
chris@203 21 if [ ! -d "$targetdir" ]; then
chris@203 22 echo "Target dir $targetdir not found"
chris@203 23 exit 1
chris@203 24 fi
chris@168 25
chris@203 26 if [ -f "$targetdir/index.html" ]; then
chris@203 27 echo "Target dir $targetdir already contains index.html"
chris@203 28 exit 1
chris@178 29 fi
chris@168 30
chris@191 31 # Identify Java files whose packages match the trailing parts of their
chris@191 32 # paths, and list the resulting packages and the path prefixes with
chris@191 33 # the packages removed (so as to find code in subdirs,
chris@191 34 # e.g. src/com/example/...)
chris@191 35
chris@191 36 # Regexp match is very rough; check what is actually permitted for
chris@191 37 # package declarations
chris@191 38
chris@203 39 find "$projectdir" -type f -name \*.java \
chris@203 40 -exec grep '^ *package [a-zA-Z][a-zA-Z0-9\._-]*; *$' \{\} /dev/null \; |
chris@191 41 sed -e 's/\/[^\/]*: *package */:/' -e 's/; *$//' |
chris@191 42 sort | uniq | (
chris@191 43 current_prefix=
chris@191 44 current_packages=
chris@191 45 while IFS=: read filepath package; do
chris@191 46 echo "Looking at $package in $filepath"
chris@191 47 packagepath=${package//./\/}
chris@191 48 prefix=${filepath%$packagepath}
chris@203 49 prefix=${prefix:=$projectdir}
chris@191 50 if [ "$prefix" = "$filepath" ]; then
chris@191 51 echo "Package $package does not match suffix of path $filepath, skipping"
chris@191 52 continue
chris@191 53 fi
chris@191 54 if [ "$prefix" != "$current_prefix" ]; then
chris@191 55 if [ -n "$current_packages" ]; then
chris@191 56 echo "Running Javadoc for packages $current_packages from prefix $current_prefix"
chris@203 57 javadoc -sourcepath "$current_prefix" -d "$targetdir" -subpackages $current_packages
chris@191 58 fi
chris@191 59 current_prefix="$prefix"
chris@191 60 current_packages=
chris@191 61 else
chris@191 62 current_packages="$current_packages $package"
chris@191 63 fi
chris@191 64 done
chris@203 65 prefix=${prefix:=$projectdir}
chris@191 66 if [ -n "$current_packages" ]; then
chris@191 67 echo "Running Javadoc for packages $current_packages in prefix $current_prefix"
chris@203 68 javadoc -sourcepath "$current_prefix" -d "$targetdir" -subpackages $current_packages
chris@191 69 fi
chris@191 70 )
chris@191 71
chris@203 72 # for exit code:
chris@203 73 [ -f "$targetdir/index.html" ]
chris@168 74