Home | History | Annotate | Download | only in bin
      1 #! /bin/sh
      2 
      3 # Launch FindBugs from the command line.
      4 
      5 escape_arg() {
      6 	echo "$1" | sed -e "s,\\([\\\"' 	]\\),\\\\\\1,g"
      7 }
      8 
      9 program="$0"
     10 
     11 # Follow symlinks until we get to the actual file.
     12 while [ -h "$program" ]; do
     13 	link=`ls -ld "$program"`
     14 	link=`expr "$link" : '.*-> \(.*\)'`
     15 	if [ "`expr "$link" : '/.*'`" = 0 ]; then
     16 		# Relative
     17 		dir=`dirname "$program"`
     18 		program="$dir/$link"
     19 	else
     20 		# Absolute
     21 		program="$link"
     22 	fi
     23 done
     24 
     25 # Assume findbugs home directory is the parent
     26 # of the directory containing the script (which should
     27 # normally be "$findbugs_home/bin").
     28 dir=`dirname "$program"`
     29 findbugs_home="$dir/.."
     30 
     31 # Handle FHS-compliant installations (e.g., Fink)
     32 if [ -d "$findbugs_home/share/findbugs" ]; then
     33 	findbugs_home="$findbugs_home/share/findbugs"
     34 fi
     35 
     36 # Make absolute
     37 findbugs_home=`cd "$findbugs_home" && pwd`
     38 
     39 fb_pathsep=':'
     40 
     41 # Handle cygwin, courtesy of Peter D. Stout
     42 fb_osname=`uname`
     43 if [ `expr "$fb_osname" : CYGWIN` -ne 0 ]; then
     44 	findbugs_home=`cygpath --mixed "$findbugs_home"`
     45 	fb_pathsep=';'
     46 fi
     47 # Handle MKS, courtesy of Kelly O'Hair
     48 if [ "${fb_osname}" = "Windows_NT" ]; then
     49 	fb_pathsep=';'
     50 fi
     51 
     52 if [ ! -d "$findbugs_home" ]; then
     53 	echo "The path $findbugs_home,"
     54 	echo "which is where I think FindBugs is located,"
     55 	echo "does not seem to be a directory."
     56 	exit 1
     57 fi
     58 
     59 # Choose default java binary
     60 fb_javacmd=java
     61 if [ ! -z "$JAVA_HOME" ] && [ -x "$JAVA_HOME/bin/java" ]; then
     62 	if [ `expr "$fb_osname" : CYGWIN` -ne 0 ]; then
     63 		fb_javacmd=`cygpath --mixed "$JAVA_HOME"`/bin/java
     64 	else
     65 		fb_javacmd="$JAVA_HOME/bin/java"
     66 	fi
     67 fi
     68 
     69 
     70 fb_appjar="$findbugs_home/lib/findbugs.jar"
     71 
     72 ShowHelpAndExit() {
     73 	fb_mainclass="edu.umd.cs.findbugs.ShowHelp"
     74 	fb_javacmd=${fb_javacmd:-"java"}
     75 fb_maxheap=${fb_maxheap:-"-Xmx768m"}
     76 fb_appjar=${fb_appjar:-"$findbugs_home/lib/findbugs.jar"}
     77 set -f
     78 #echo command: \
     79 exec "$fb_javacmd" \
     80 	-classpath "$fb_appjar$fb_pathsep$CLASSPATH" \
     81 	-Dfindbugs.home="$findbugs_home"\
     82 	$fb_maxheap $fb_jvmargs $fb_mainclass ${@:+"$@"} $fb_appargs
     83 	exit 0
     84 }
     85 
     86 # Set defaults
     87 fb_mainclass="edu.umd.cs.findbugs.workflow.FB"
     88 user_jvmargs=''
     89 ea_arg=''
     90 debug_arg=''
     91 conservespace_arg=''
     92 workhard_arg=''
     93 user_props=''
     94 
     95 # Handle command line arguments.
     96 while [ $# -gt 0 ]; do
     97 	case $1 in
     98 	-textui)
     99 		fb_mainclass="edu.umd.cs.findbugs.FindBugs2"
    100 		;;
    101 
    102 	-jvmArgs)
    103 		shift
    104 		user_jvmargs="$1"
    105 		;;
    106 		
    107 	-ea)
    108 		ea_arg='-ea'
    109 		;;
    110 
    111 	-maxHeap)
    112 		shift
    113 		fb_maxheap="-Xmx$1m"
    114 		;;
    115 
    116 	-javahome)
    117 		shift
    118 		fb_javacmd="$1/bin/java"
    119 		;;
    120 
    121 	-debug)
    122 		debug_arg="-Dfindbugs.debug=true"
    123 		;;
    124 
    125 	-conserveSpace)
    126 		conservespace_arg="-Dfindbugs.conserveSpace=true"
    127 		;;
    128 
    129 	-property)
    130 		shift
    131 		user_props="-D$1 $user_props"
    132 		;;
    133 	
    134 	-D*=*)
    135 		user_props="$1 $user_props"
    136 		;;
    137 
    138 	-version)
    139 		fb_mainclass=edu.umd.cs.findbugs.Version
    140 		fb_appargs="-release"
    141 		while [ $# -gt 0 ]; do
    142 			shift
    143 		done
    144 		fb_javacmd=${fb_javacmd:-"java"}
    145 fb_maxheap=${fb_maxheap:-"-Xmx768m"}
    146 fb_appjar=${fb_appjar:-"$findbugs_home/lib/findbugs.jar"}
    147 set -f
    148 #echo command: \
    149 exec "$fb_javacmd" \
    150 	-classpath "$fb_appjar$fb_pathsep$CLASSPATH" \
    151 	-Dfindbugs.home="$findbugs_home"\
    152 	$fb_maxheap $fb_jvmargs $fb_mainclass ${@:+"$@"} $fb_appargs
    153 		exit 0
    154 		;;
    155 
    156 	-help)
    157 		ShowHelpAndExit
    158 		;;
    159 
    160 	# All unrecognized arguments will be accumulated and
    161 	# passed to the application.
    162 	*)
    163 		fb_appargs="$fb_appargs `escape_arg "$1"`"
    164 		;;
    165 	esac
    166 
    167 	shift
    168 done
    169 
    170 fb_jvmargs="$user_jvmargs $debug_arg $conservespace_arg $workhard_arg $user_props $ea_arg"
    171 if [ $maxheap ]; then
    172   fb_maxheap="-Xmx${maxheap}m"
    173 fi
    174 
    175 # Extra JVM args for MacOSX.
    176 if [ $fb_osname = "Darwin" ]; then
    177 	fb_jvmargs="$fb_jvmargs \
    178 		-Xdock:name=FindBugs -Xdock:icon=${findbugs_home}/lib/buggy.icns \
    179 		-Dapple.laf.useScreenMenuBar=true"
    180 fi
    181 
    182 fb_javacmd=${fb_javacmd:-"java"}
    183 fb_maxheap=${fb_maxheap:-"-Xmx768m"}
    184 fb_appjar=${fb_appjar:-"$findbugs_home/lib/findbugs.jar"}
    185 set -f
    186 #echo command: \
    187 exec "$fb_javacmd" \
    188 	-classpath "$fb_appjar$fb_pathsep$CLASSPATH" \
    189 	-Dfindbugs.home="$findbugs_home"\
    190 	$fb_maxheap $fb_jvmargs $fb_mainclass ${@:+"$@"} $fb_appargs
    191 
    192 # vim:ts=3
    193