annotate extra/soundsoftware/extract-javadoc.sh @ 887:f210ac4c5b05 bug_89

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