To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / extra / soundsoftware / extract-javadoc.sh @ 1025:02ee54197879

History | View | Annotate | Download (2.53 KB)

1 203:1e55195bca45 chris
#!/bin/bash
2 168:c1e9f2dab1d5 chris
3 203:1e55195bca45 chris
docdir="/var/doc"
4 168:c1e9f2dab1d5 chris
5 203:1e55195bca45 chris
project="$1"
6 223:c3544e9fd588 chris
projectdir="$2"
7
targetdir="$3"
8 168:c1e9f2dab1d5 chris
9 223:c3544e9fd588 chris
if [ -z "$project" ] || [ -z "$targetdir" ] || [ -z "$projectdir" ]; then
10
    echo "Usage: $0 <project> <projectdir> <targetdir>"
11 203:1e55195bca45 chris
    exit 2
12 168:c1e9f2dab1d5 chris
fi
13
14 223:c3544e9fd588 chris
if [ ! -d "$projectdir" ]; then
15
    echo "Project directory $projectdir not found"
16 203:1e55195bca45 chris
    exit 1
17
fi
18 168:c1e9f2dab1d5 chris
19 203:1e55195bca45 chris
if [ ! -d "$targetdir" ]; then
20
    echo "Target dir $targetdir not found"
21
    exit 1
22
fi
23 168:c1e9f2dab1d5 chris
24 203:1e55195bca45 chris
if [ -f "$targetdir/index.html" ]; then
25
    echo "Target dir $targetdir already contains index.html"
26
    exit 1
27 178:2cec5c53cd68 chris
fi
28 168:c1e9f2dab1d5 chris
29 191:0d1c6fa50d3a chris
# 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 203:1e55195bca45 chris
find "$projectdir" -type f -name \*.java \
38 989:3549525ba22a Chris
    -exec egrep '^ *package +[a-zA-Z][a-zA-Z0-9\._-]*;.*$' \{\} /dev/null \; |
39
    sed -e 's/\/[^\/]*: *package */:/' -e 's/;.*$//' |
40 191:0d1c6fa50d3a chris
    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 203:1e55195bca45 chris
	    prefix=${prefix:=$projectdir}
48 191:0d1c6fa50d3a chris
	    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 450:73401a15037b Chris
		echo "Package $package matches file path and has new prefix $prefix"
54 191:0d1c6fa50d3a chris
		if [ -n "$current_packages" ]; then
55
		    echo "Running Javadoc for packages $current_packages from prefix $current_prefix"
56 450:73401a15037b Chris
		    echo "Command is: javadoc -sourcepath "$current_prefix" -d "$targetdir" -subpackages $current_packages"
57 203:1e55195bca45 chris
		    javadoc -sourcepath "$current_prefix" -d "$targetdir" -subpackages $current_packages
58 191:0d1c6fa50d3a chris
		fi
59
		current_prefix="$prefix"
60 450:73401a15037b Chris
		current_packages="$package"
61 191:0d1c6fa50d3a chris
	    else
62 450:73401a15037b Chris
		echo "Package $package matches file path with same prefix as previous file"
63 191:0d1c6fa50d3a chris
		current_packages="$current_packages $package"
64
	    fi
65
	done
66 203:1e55195bca45 chris
	prefix=${prefix:=$projectdir}
67 191:0d1c6fa50d3a chris
	if [ -n "$current_packages" ]; then
68
	    echo "Running Javadoc for packages $current_packages in prefix $current_prefix"
69 450:73401a15037b Chris
  	    echo "Command is: javadoc -sourcepath "$current_prefix" -d "$targetdir" -subpackages $current_packages"
70 203:1e55195bca45 chris
	    javadoc -sourcepath "$current_prefix" -d "$targetdir" -subpackages $current_packages
71 191:0d1c6fa50d3a chris
	fi
72
    )
73
74 450:73401a15037b Chris
if [ -f "$targetdir"/overview-tree.html ]; then
75
    cp "$targetdir"/overview-tree.html "$targetdir"/index.html
76
fi
77
78 203:1e55195bca45 chris
# for exit code:
79
[ -f "$targetdir/index.html" ]