To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / extra / soundsoftware / extract-javadoc.sh @ 1015:52be96e83080
History | View | Annotate | Download (2.53 KB)
| 1 |
#!/bin/bash |
|---|---|
| 2 |
|
| 3 |
docdir="/var/doc" |
| 4 |
|
| 5 |
project="$1" |
| 6 |
projectdir="$2" |
| 7 |
targetdir="$3" |
| 8 |
|
| 9 |
if [ -z "$project" ] || [ -z "$targetdir" ] || [ -z "$projectdir" ]; then |
| 10 |
echo "Usage: $0 <project> <projectdir> <targetdir>" |
| 11 |
exit 2 |
| 12 |
fi |
| 13 |
|
| 14 |
if [ ! -d "$projectdir" ]; then |
| 15 |
echo "Project directory $projectdir not found" |
| 16 |
exit 1 |
| 17 |
fi |
| 18 |
|
| 19 |
if [ ! -d "$targetdir" ]; then |
| 20 |
echo "Target dir $targetdir not found" |
| 21 |
exit 1 |
| 22 |
fi |
| 23 |
|
| 24 |
if [ -f "$targetdir/index.html" ]; then |
| 25 |
echo "Target dir $targetdir already contains index.html" |
| 26 |
exit 1 |
| 27 |
fi |
| 28 |
|
| 29 |
# Identify Java files whose packages match the trailing parts of their |
| 30 |
# paths, and list the resulting packages and the path prefixes with |
| 31 |
# the packages removed (so as to find code in subdirs, |
| 32 |
# e.g. src/com/example/...) |
| 33 |
|
| 34 |
# Regexp match is very rough; check what is actually permitted for |
| 35 |
# package declarations |
| 36 |
|
| 37 |
find "$projectdir" -type f -name \*.java \ |
| 38 |
-exec egrep '^ *package +[a-zA-Z][a-zA-Z0-9\._-]*;.*$' \{\} /dev/null \; |
|
| 39 |
sed -e 's/\/[^\/]*: *package */:/' -e 's/;.*$//' | |
| 40 |
sort | uniq | ( |
| 41 |
current_prefix= |
| 42 |
current_packages= |
| 43 |
while IFS=: read filepath package; do |
| 44 |
echo "Looking at $package in $filepath" |
| 45 |
packagepath=${package//./\/}
|
| 46 |
prefix=${filepath%$packagepath}
|
| 47 |
prefix=${prefix:=$projectdir}
|
| 48 |
if [ "$prefix" = "$filepath" ]; then |
| 49 |
echo "Package $package does not match suffix of path $filepath, skipping" |
| 50 |
continue |
| 51 |
fi |
| 52 |
if [ "$prefix" != "$current_prefix" ]; then |
| 53 |
echo "Package $package matches file path and has new prefix $prefix" |
| 54 |
if [ -n "$current_packages" ]; then |
| 55 |
echo "Running Javadoc for packages $current_packages from prefix $current_prefix" |
| 56 |
echo "Command is: javadoc -sourcepath "$current_prefix" -d "$targetdir" -subpackages $current_packages" |
| 57 |
javadoc -sourcepath "$current_prefix" -d "$targetdir" -subpackages $current_packages |
| 58 |
fi |
| 59 |
current_prefix="$prefix" |
| 60 |
current_packages="$package" |
| 61 |
else |
| 62 |
echo "Package $package matches file path with same prefix as previous file" |
| 63 |
current_packages="$current_packages $package" |
| 64 |
fi |
| 65 |
done |
| 66 |
prefix=${prefix:=$projectdir}
|
| 67 |
if [ -n "$current_packages" ]; then |
| 68 |
echo "Running Javadoc for packages $current_packages in prefix $current_prefix" |
| 69 |
echo "Command is: javadoc -sourcepath "$current_prefix" -d "$targetdir" -subpackages $current_packages" |
| 70 |
javadoc -sourcepath "$current_prefix" -d "$targetdir" -subpackages $current_packages |
| 71 |
fi |
| 72 |
) |
| 73 |
|
| 74 |
if [ -f "$targetdir"/overview-tree.html ]; then |
| 75 |
cp "$targetdir"/overview-tree.html "$targetdir"/index.html |
| 76 |
fi |
| 77 |
|
| 78 |
# for exit code: |
| 79 |
[ -f "$targetdir/index.html" ] |
| 80 |
|