diff 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
line wrap: on
line diff
--- a/extra/soundsoftware/extract-javadoc.sh	Fri Feb 04 18:40:21 2011 +0000
+++ b/extra/soundsoftware/extract-javadoc.sh	Mon Feb 07 16:46:28 2011 +0000
@@ -1,40 +1,31 @@
-#!/bin/sh
+#!/bin/bash
 
-# Run this script from /var/doc/<project-name>
+hgdir="/var/hg"
+docdir="/var/doc"
 
-# Find Hg repo and update it.  We should separate this process into
-# two, first the update (run as www-data) and then the extraction (run
-# as an otherwise totally unprivileged user without write permission
-# on www-data/code stuff)
+project="$1"
+targetdir="$2"
 
-docdir=$(pwd)
-name=$(basename $(pwd))
-hgdir="/var/hg/$name"
-echo "Extracting doc for $name"
-if [ ! -d "$hgdir" ]; then
-   echo "Error: No $hgdir found for project $name"
-   exit 1
+projectdir="$hgdir/$project"
+
+if [ -z "$project" ] || [ -z "$targetdir" ]; then
+    echo "Usage: $0 <project> <targetdir>"
+    exit 2
 fi
-( cd "$hgdir" ; hg update ) || exit 1
 
-# Identify either a Doxyfile or some Java packages
+if [ ! -d "$projectdir" ] || [ ! -d "$projectdir/.hg" ]; then
+    echo "No hg repo found at $projectdir"
+    exit 1
+fi
 
-# TODO: Doxyfile
+if [ ! -d "$targetdir" ]; then
+    echo "Target dir $targetdir not found"
+    exit 1
+fi
 
-doxyfile=`find "$hgdir" -type f -name Doxyfile -print | head -1`
-
-if [ -z "$doxyfile" ]; then
-    echo "No Doxyfile: skipping"
-else
-    echo "This project contains a Doxyfile:"
-    echo "$doxyfile"
-
-
-# hmm. should be a whitelist
-
-    ( 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 | \
-	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 - )
-
+if [ -f "$targetdir/index.html" ]; then
+    echo "Target dir $targetdir already contains index.html"
+    exit 1
 fi
 
 # Identify Java files whose packages match the trailing parts of their
@@ -45,7 +36,8 @@
 # Regexp match is very rough; check what is actually permitted for
 # package declarations
 
-find "$hgdir" -type f -name \*.java -exec grep '^ *package [a-zA-Z][a-zA-Z0-9\._-]*; *$' \{\} /dev/null \; |
+find "$projectdir" -type f -name \*.java \
+    -exec grep '^ *package [a-zA-Z][a-zA-Z0-9\._-]*; *$' \{\} /dev/null \; |
     sed -e 's/\/[^\/]*: *package */:/' -e 's/; *$//' |
     sort | uniq | (
 	current_prefix=
@@ -54,7 +46,7 @@
 	    echo "Looking at $package in $filepath"
 	    packagepath=${package//./\/}
 	    prefix=${filepath%$packagepath}
-	    prefix=${prefix:=$hgdir}
+	    prefix=${prefix:=$projectdir}
 	    if [ "$prefix" = "$filepath" ]; then
 		echo "Package $package does not match suffix of path $filepath, skipping"
 		continue
@@ -62,7 +54,7 @@
 	    if [ "$prefix" != "$current_prefix" ]; then
 		if [ -n "$current_packages" ]; then
 		    echo "Running Javadoc for packages $current_packages from prefix $current_prefix"
-		    javadoc -sourcepath "$current_prefix" -d . -subpackages $current_packages
+		    javadoc -sourcepath "$current_prefix" -d "$targetdir" -subpackages $current_packages
 		fi
 		current_prefix="$prefix"
 		current_packages=
@@ -70,39 +62,13 @@
 		current_packages="$current_packages $package"
 	    fi
 	done
-	prefix=${prefix:=$hgdir}
+	prefix=${prefix:=$projectdir}
 	if [ -n "$current_packages" ]; then
 	    echo "Running Javadoc for packages $current_packages in prefix $current_prefix"
-	    javadoc -sourcepath "$current_prefix" -d . -subpackages $current_packages
+	    javadoc -sourcepath "$current_prefix" -d "$targetdir" -subpackages $current_packages
 	fi
     )
 
-# This is very rough; check what is actually permitted for package
-# declarations
+# for exit code:
+[ -f "$targetdir/index.html" ]
 
-# java_packages=`find "$hgdir" -type f -name \*.java -print | \
-#     xargs grep -h '^ *package [a-zA-Z][a-zA-Z0-9\._-]* *; *' | \
-#     sort | uniq | \
-#     sed -e 's/^ *package //' -e 's/ *; *$//'`
-
-# echo "This project contains Java packages:"
-# echo "$java_packages"
-
-# if [ -z "$java_packages" ]; then
-#     echo "No Java packages: skipping"
-#     exit 0
-# fi
-
-
-# # This won't work if code is in a subdir,
-# # e.g. src/com/example/project/Hello.java
-
-# # We need to convert the package name back to a path, and check
-# # whether that matches the tail of the path to a java file that
-# # declares itself to be in that package... but we don't have that list
-# # of java files to hand here... hm
-
-# javadoc -sourcepath "$hgdir" -d . -subpackages $java_packages -verbose
-
-# # If we have just written something to a doc directory that was
-# # previously empty, we should switch on Embedded for this project