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