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