chris@168: #!/bin/sh chris@168: chris@168: # Run this script from /var/doc/ chris@168: chris@191: # Find Hg repo and update it. We should separate this process into chris@191: # two, first the update (run as www-data) and then the extraction (run chris@191: # as an otherwise totally unprivileged user without write permission chris@191: # on www-data/code stuff) chris@168: chris@168: docdir=$(pwd) chris@168: name=$(basename $(pwd)) chris@168: hgdir="/var/hg/$name" chris@168: echo "Extracting doc for $name" chris@168: if [ ! -d "$hgdir" ]; then chris@168: echo "Error: No $hgdir found for project $name" chris@168: exit 1 chris@168: fi chris@168: ( cd "$hgdir" ; hg update ) || exit 1 chris@168: chris@168: # Identify either a Doxyfile or some Java packages chris@168: chris@168: # TODO: Doxyfile chris@168: chris@178: doxyfile=`find "$hgdir" -type f -name Doxyfile -print | head -1` chris@178: chris@178: if [ -z "$doxyfile" ]; then chris@178: echo "No Doxyfile: skipping" chris@178: else chris@191: echo "This project contains a Doxyfile:" chris@191: echo "$doxyfile" chris@191: chris@178: chris@178: # hmm. should be a whitelist chris@178: chris@180: ( 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: 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: chris@178: fi chris@168: chris@191: # Identify Java files whose packages match the trailing parts of their chris@191: # paths, and list the resulting packages and the path prefixes with chris@191: # the packages removed (so as to find code in subdirs, chris@191: # e.g. src/com/example/...) chris@191: chris@191: # Regexp match is very rough; check what is actually permitted for chris@191: # package declarations chris@191: chris@191: find "$hgdir" -type f -name \*.java -exec grep '^ *package [a-zA-Z][a-zA-Z0-9\._-]*; *$' \{\} /dev/null \; | chris@191: sed -e 's/\/[^\/]*: *package */:/' -e 's/; *$//' | chris@191: sort | uniq | ( chris@191: current_prefix= chris@191: current_packages= chris@191: while IFS=: read filepath package; do chris@191: echo "Looking at $package in $filepath" chris@191: packagepath=${package//./\/} chris@191: prefix=${filepath%$packagepath} chris@191: prefix=${prefix:=$hgdir} chris@191: if [ "$prefix" = "$filepath" ]; then chris@191: echo "Package $package does not match suffix of path $filepath, skipping" chris@191: continue chris@191: fi chris@191: if [ "$prefix" != "$current_prefix" ]; then chris@191: if [ -n "$current_packages" ]; then chris@191: echo "Running Javadoc for packages $current_packages from prefix $current_prefix" chris@191: javadoc -sourcepath "$current_prefix" -d . -subpackages $current_packages chris@191: fi chris@191: current_prefix="$prefix" chris@191: current_packages= chris@191: else chris@191: current_packages="$current_packages $package" chris@191: fi chris@191: done chris@191: prefix=${prefix:=$hgdir} chris@191: if [ -n "$current_packages" ]; then chris@191: echo "Running Javadoc for packages $current_packages in prefix $current_prefix" chris@191: javadoc -sourcepath "$current_prefix" -d . -subpackages $current_packages chris@191: fi chris@191: ) chris@191: chris@168: # This is very rough; check what is actually permitted for package chris@168: # declarations chris@168: chris@191: # java_packages=`find "$hgdir" -type f -name \*.java -print | \ chris@191: # xargs grep -h '^ *package [a-zA-Z][a-zA-Z0-9\._-]* *; *' | \ chris@191: # sort | uniq | \ chris@191: # sed -e 's/^ *package //' -e 's/ *; *$//'` chris@168: chris@191: # echo "This project contains Java packages:" chris@191: # echo "$java_packages" chris@168: chris@191: # if [ -z "$java_packages" ]; then chris@191: # echo "No Java packages: skipping" chris@191: # exit 0 chris@191: # fi chris@178: chris@178: chris@191: # # This won't work if code is in a subdir, chris@191: # # e.g. src/com/example/project/Hello.java chris@168: chris@191: # # We need to convert the package name back to a path, and check chris@191: # # whether that matches the tail of the path to a java file that chris@191: # # declares itself to be in that package... but we don't have that list chris@191: # # of java files to hand here... hm chris@168: chris@191: # javadoc -sourcepath "$hgdir" -d . -subpackages $java_packages -verbose chris@191: chris@191: # # If we have just written something to a doc directory that was chris@191: # # previously empty, we should switch on Embedded for this project