annotate extra/soundsoftware/extract-javadoc.sh @ 191:0d1c6fa50d3a feature_20

* Handle Java source found in subdirectories (e.g. under src/)
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Fri, 04 Feb 2011 18:40:21 +0000
parents fc1ffeca7437
children 1e55195bca45
rev   line source
chris@168 1 #!/bin/sh
chris@168 2
chris@168 3 # Run this script from /var/doc/<project-name>
chris@168 4
chris@191 5 # Find Hg repo and update it. We should separate this process into
chris@191 6 # two, first the update (run as www-data) and then the extraction (run
chris@191 7 # as an otherwise totally unprivileged user without write permission
chris@191 8 # on www-data/code stuff)
chris@168 9
chris@168 10 docdir=$(pwd)
chris@168 11 name=$(basename $(pwd))
chris@168 12 hgdir="/var/hg/$name"
chris@168 13 echo "Extracting doc for $name"
chris@168 14 if [ ! -d "$hgdir" ]; then
chris@168 15 echo "Error: No $hgdir found for project $name"
chris@168 16 exit 1
chris@168 17 fi
chris@168 18 ( cd "$hgdir" ; hg update ) || exit 1
chris@168 19
chris@168 20 # Identify either a Doxyfile or some Java packages
chris@168 21
chris@168 22 # TODO: Doxyfile
chris@168 23
chris@178 24 doxyfile=`find "$hgdir" -type f -name Doxyfile -print | head -1`
chris@178 25
chris@178 26 if [ -z "$doxyfile" ]; then
chris@178 27 echo "No Doxyfile: skipping"
chris@178 28 else
chris@191 29 echo "This project contains a Doxyfile:"
chris@191 30 echo "$doxyfile"
chris@191 31
chris@178 32
chris@178 33 # hmm. should be a whitelist
chris@178 34
chris@180 35 ( cd "$hgdir" && grep -vi OUTPUT_DIRECTORY "$doxyfile" | grep -vi HTML_OUTPUT | grep -vi SEARCHENGINE | grep -vi HAVE_DOT | grep -vi DOT_FONTNAME | grep -vi DOT_FONTPATH | grep -vi DOT_TRANSPARENT | \
chris@181 36 sed -e '$a OUTPUT_DIRECTORY='"$docdir" -e '$a HTML_OUTPUT = .' -e '$a SEARCHENGINE = NO' -e '$a HAVE_DOT = YES' -e '$a DOT_FONTNAME = FreeMono' -e '$a DOT_FONTPATH = /usr/share/fonts/truetype/freefont' -e '$a DOT_TRANSPARENT = YES' | doxygen - )
chris@178 37
chris@178 38 fi
chris@168 39
chris@191 40 # Identify Java files whose packages match the trailing parts of their
chris@191 41 # paths, and list the resulting packages and the path prefixes with
chris@191 42 # the packages removed (so as to find code in subdirs,
chris@191 43 # e.g. src/com/example/...)
chris@191 44
chris@191 45 # Regexp match is very rough; check what is actually permitted for
chris@191 46 # package declarations
chris@191 47
chris@191 48 find "$hgdir" -type f -name \*.java -exec grep '^ *package [a-zA-Z][a-zA-Z0-9\._-]*; *$' \{\} /dev/null \; |
chris@191 49 sed -e 's/\/[^\/]*: *package */:/' -e 's/; *$//' |
chris@191 50 sort | uniq | (
chris@191 51 current_prefix=
chris@191 52 current_packages=
chris@191 53 while IFS=: read filepath package; do
chris@191 54 echo "Looking at $package in $filepath"
chris@191 55 packagepath=${package//./\/}
chris@191 56 prefix=${filepath%$packagepath}
chris@191 57 prefix=${prefix:=$hgdir}
chris@191 58 if [ "$prefix" = "$filepath" ]; then
chris@191 59 echo "Package $package does not match suffix of path $filepath, skipping"
chris@191 60 continue
chris@191 61 fi
chris@191 62 if [ "$prefix" != "$current_prefix" ]; then
chris@191 63 if [ -n "$current_packages" ]; then
chris@191 64 echo "Running Javadoc for packages $current_packages from prefix $current_prefix"
chris@191 65 javadoc -sourcepath "$current_prefix" -d . -subpackages $current_packages
chris@191 66 fi
chris@191 67 current_prefix="$prefix"
chris@191 68 current_packages=
chris@191 69 else
chris@191 70 current_packages="$current_packages $package"
chris@191 71 fi
chris@191 72 done
chris@191 73 prefix=${prefix:=$hgdir}
chris@191 74 if [ -n "$current_packages" ]; then
chris@191 75 echo "Running Javadoc for packages $current_packages in prefix $current_prefix"
chris@191 76 javadoc -sourcepath "$current_prefix" -d . -subpackages $current_packages
chris@191 77 fi
chris@191 78 )
chris@191 79
chris@168 80 # This is very rough; check what is actually permitted for package
chris@168 81 # declarations
chris@168 82
chris@191 83 # java_packages=`find "$hgdir" -type f -name \*.java -print | \
chris@191 84 # xargs grep -h '^ *package [a-zA-Z][a-zA-Z0-9\._-]* *; *' | \
chris@191 85 # sort | uniq | \
chris@191 86 # sed -e 's/^ *package //' -e 's/ *; *$//'`
chris@168 87
chris@191 88 # echo "This project contains Java packages:"
chris@191 89 # echo "$java_packages"
chris@168 90
chris@191 91 # if [ -z "$java_packages" ]; then
chris@191 92 # echo "No Java packages: skipping"
chris@191 93 # exit 0
chris@191 94 # fi
chris@178 95
chris@178 96
chris@191 97 # # This won't work if code is in a subdir,
chris@191 98 # # e.g. src/com/example/project/Hello.java
chris@168 99
chris@191 100 # # We need to convert the package name back to a path, and check
chris@191 101 # # whether that matches the tail of the path to a java file that
chris@191 102 # # declares itself to be in that package... but we don't have that list
chris@191 103 # # of java files to hand here... hm
chris@168 104
chris@191 105 # javadoc -sourcepath "$hgdir" -d . -subpackages $java_packages -verbose
chris@191 106
chris@191 107 # # If we have just written something to a doc directory that was
chris@191 108 # # previously empty, we should switch on Embedded for this project