annotate extra/soundsoftware/extract-javadoc.sh @ 1474:c4436fec34bf bug_494

Close obsolete branch bug_494
author Chris Cannam
date Sat, 10 Nov 2012 13:57:53 +0000
parents 73401a15037b
children 3549525ba22a
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@450 53 echo "Package $package matches file path and has new prefix $prefix"
chris@191 54 if [ -n "$current_packages" ]; then
chris@191 55 echo "Running Javadoc for packages $current_packages from prefix $current_prefix"
Chris@450 56 echo "Command is: javadoc -sourcepath "$current_prefix" -d "$targetdir" -subpackages $current_packages"
chris@203 57 javadoc -sourcepath "$current_prefix" -d "$targetdir" -subpackages $current_packages
chris@191 58 fi
chris@191 59 current_prefix="$prefix"
Chris@450 60 current_packages="$package"
chris@191 61 else
Chris@450 62 echo "Package $package matches file path with same prefix as previous file"
chris@191 63 current_packages="$current_packages $package"
chris@191 64 fi
chris@191 65 done
chris@203 66 prefix=${prefix:=$projectdir}
chris@191 67 if [ -n "$current_packages" ]; then
chris@191 68 echo "Running Javadoc for packages $current_packages in prefix $current_prefix"
Chris@450 69 echo "Command is: javadoc -sourcepath "$current_prefix" -d "$targetdir" -subpackages $current_packages"
chris@203 70 javadoc -sourcepath "$current_prefix" -d "$targetdir" -subpackages $current_packages
chris@191 71 fi
chris@191 72 )
chris@191 73
Chris@450 74 if [ -f "$targetdir"/overview-tree.html ]; then
Chris@450 75 cp "$targetdir"/overview-tree.html "$targetdir"/index.html
Chris@450 76 fi
Chris@450 77
chris@203 78 # for exit code:
chris@203 79 [ -f "$targetdir/index.html" ]
chris@168 80