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