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 @ 439:d3faf348b287

History | View | Annotate | Download (2.04 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 grep '^ *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
		if [ -n "$current_packages" ]; then
54
		    echo "Running Javadoc for packages $current_packages from prefix $current_prefix"
55
		    javadoc -sourcepath "$current_prefix" -d "$targetdir" -subpackages $current_packages
56
		fi
57
		current_prefix="$prefix"
58
		current_packages=
59
	    else
60
		current_packages="$current_packages $package"
61
	    fi
62
	done
63
	prefix=${prefix:=$projectdir}
64
	if [ -n "$current_packages" ]; then
65
	    echo "Running Javadoc for packages $current_packages in prefix $current_prefix"
66
	    javadoc -sourcepath "$current_prefix" -d "$targetdir" -subpackages $current_packages
67
	fi
68
    )
69

    
70
# for exit code:
71
[ -f "$targetdir/index.html" ]
72