Thomas Vachuska | 6b33126 | 2015-04-27 11:09:07 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | #------------------------------------------------------------------------------- |
| 3 | # Java Package Dependency viewer |
Thomas Vachuska | 6b33126 | 2015-04-27 11:09:07 -0700 | [diff] [blame] | 4 | #------------------------------------------------------------------------------- |
| 5 | |
Thomas Vachuska | 812c092 | 2017-07-06 14:55:37 -0700 | [diff] [blame] | 6 | VER=${JDVUE_VERSION:-2.2} |
Thomas Vachuska | c356210 | 2016-06-16 03:02:22 -0700 | [diff] [blame] | 7 | JAR=~/.m2/repository/org/onosproject/jdvue/$VER/jdvue-$VER.jar |
Thomas Vachuska | 6b33126 | 2015-04-27 11:09:07 -0700 | [diff] [blame] | 8 | |
Thomas Vachuska | c356210 | 2016-06-16 03:02:22 -0700 | [diff] [blame] | 9 | # Download the jdvue binary if needed |
| 10 | if [ ! -f $JAR ]; then |
| 11 | printf "Downloading jdvue binary..." |
| 12 | aux=/tmp/stc-$$.log |
| 13 | mvn dependency:get -Dartifact=org.onosproject:jdvue:$VER -Dtransitive=false -B >$aux || fgrep '[ERROR]' $aux |
| 14 | rm -f $aux |
| 15 | [ -f $JAR ] && printf "Done.\n" |
| 16 | fi |
Thomas Vachuska | 6b33126 | 2015-04-27 11:09:07 -0700 | [diff] [blame] | 17 | |
Thomas Vachuska | 6b33126 | 2015-04-27 11:09:07 -0700 | [diff] [blame] | 18 | # If the -n option is specified use the next argument as the catalog name |
| 19 | [ "$1" = "-n" -a $# -ge 2 ] && name=$2 && shift 2 |
| 20 | |
Thomas Vachuska | 812c092 | 2017-07-06 14:55:37 -0700 | [diff] [blame] | 21 | # If the -t option is specified, use only test sources; -a use all sources |
| 22 | # If the -m option is specified, use only main sources; default. |
| 23 | [ "$1" = "-m" ] && srcPattern="/src/main/java/" && shift 1 |
| 24 | [ "$1" = "-t" ] && srcPattern="/src/test/java/" && shift 1 |
| 25 | [ "$1" = "-a" ] && srcPattern="/src/(main|test)/java/" && shift 1 |
| 26 | |
| 27 | # Assume default project to be the base-name of the argument or of current dir |
| 28 | name=$(basename ${1:-$PWD}) |
| 29 | |
Thomas Vachuska | 6b33126 | 2015-04-27 11:09:07 -0700 | [diff] [blame] | 30 | # Use the rest of the arguments as paths to scan for sources to build catalog |
| 31 | find "${@:-.}" -type f -name \*.java \ |
Thomas Vachuska | 812c092 | 2017-07-06 14:55:37 -0700 | [diff] [blame] | 32 | | grep -E "${srcPattern:-/src/main/java}" \ |
Thomas Vachuska | 6b33126 | 2015-04-27 11:09:07 -0700 | [diff] [blame] | 33 | | grep -v -E '/lost+found/|/target/|archetype-resources' \ |
| 34 | | xargs grep -E "^[ \t]*import .*;.*|^[ \t]*package .*;.*" \ |
| 35 | | tr -d '\r' > $name.db |
| 36 | |
Thomas Vachuska | e006e7d | 2017-06-23 09:39:47 -0700 | [diff] [blame] | 37 | DEBUG_OPTS="-agentlib:jdwp=transport=dt_socket,address=5005,server=y,suspend=y" |
| 38 | |
Thomas Vachuska | 6b33126 | 2015-04-27 11:09:07 -0700 | [diff] [blame] | 39 | # Now run the Java Dependency Viewer jar on the catalog |
Thomas Vachuska | e006e7d | 2017-06-23 09:39:47 -0700 | [diff] [blame] | 40 | [ -z "$jdvueDebug" ] && DEBUG_OPTS="" |
| 41 | java $DEBUG_OPTS -jar ${JAR} $name && rm $name.db && open $name.html |