chris@203: #!/bin/bash chris@168: chris@203: docdir="/var/doc" chris@168: chris@203: project="$1" chris@223: projectdir="$2" chris@223: targetdir="$3" chris@168: chris@223: if [ -z "$project" ] || [ -z "$targetdir" ] || [ -z "$projectdir" ]; then chris@223: echo "Usage: $0 " chris@203: exit 2 chris@168: fi chris@168: chris@223: if [ ! -d "$projectdir" ]; then chris@223: echo "Project directory $projectdir not found" chris@203: exit 1 chris@203: fi chris@168: chris@203: if [ ! -d "$targetdir" ]; then chris@203: echo "Target dir $targetdir not found" chris@203: exit 1 chris@203: fi chris@168: chris@203: if [ -f "$targetdir/index.html" ]; then chris@203: echo "Target dir $targetdir already contains index.html" chris@203: exit 1 chris@178: fi chris@168: chris@191: # Identify Java files whose packages match the trailing parts of their chris@191: # paths, and list the resulting packages and the path prefixes with chris@191: # the packages removed (so as to find code in subdirs, chris@191: # e.g. src/com/example/...) chris@191: chris@191: # Regexp match is very rough; check what is actually permitted for chris@191: # package declarations chris@191: chris@203: find "$projectdir" -type f -name \*.java \ chris@203: -exec grep '^ *package [a-zA-Z][a-zA-Z0-9\._-]*; *$' \{\} /dev/null \; | chris@191: sed -e 's/\/[^\/]*: *package */:/' -e 's/; *$//' | chris@191: sort | uniq | ( chris@191: current_prefix= chris@191: current_packages= chris@191: while IFS=: read filepath package; do chris@191: echo "Looking at $package in $filepath" chris@191: packagepath=${package//./\/} chris@191: prefix=${filepath%$packagepath} chris@203: prefix=${prefix:=$projectdir} chris@191: if [ "$prefix" = "$filepath" ]; then chris@191: echo "Package $package does not match suffix of path $filepath, skipping" chris@191: continue chris@191: fi chris@191: if [ "$prefix" != "$current_prefix" ]; then Chris@450: echo "Package $package matches file path and has new prefix $prefix" chris@191: if [ -n "$current_packages" ]; then chris@191: echo "Running Javadoc for packages $current_packages from prefix $current_prefix" Chris@450: echo "Command is: javadoc -sourcepath "$current_prefix" -d "$targetdir" -subpackages $current_packages" chris@203: javadoc -sourcepath "$current_prefix" -d "$targetdir" -subpackages $current_packages chris@191: fi chris@191: current_prefix="$prefix" Chris@450: current_packages="$package" chris@191: else Chris@450: echo "Package $package matches file path with same prefix as previous file" chris@191: current_packages="$current_packages $package" chris@191: fi chris@191: done chris@203: prefix=${prefix:=$projectdir} chris@191: if [ -n "$current_packages" ]; then chris@191: echo "Running Javadoc for packages $current_packages in prefix $current_prefix" Chris@450: echo "Command is: javadoc -sourcepath "$current_prefix" -d "$targetdir" -subpackages $current_packages" chris@203: javadoc -sourcepath "$current_prefix" -d "$targetdir" -subpackages $current_packages chris@191: fi chris@191: ) chris@191: Chris@450: if [ -f "$targetdir"/overview-tree.html ]; then Chris@450: cp "$targetdir"/overview-tree.html "$targetdir"/index.html Chris@450: fi Chris@450: chris@203: # for exit code: chris@203: [ -f "$targetdir/index.html" ] chris@168: