1#!/bin/bash
2#
3# Copyright (C) 2007 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# Set up prog to be the path of this script, including following symlinks,
18# and set up progdir to be the fully-qualified pathname of its directory.
19prog="$0"
20while [ -h "${prog}" ]; do
21    newProg=`/bin/ls -ld "${prog}"`
22    newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
23    if expr "x${newProg}" : 'x/' >/dev/null; then
24        prog="${newProg}"
25    else
26        progdir=`dirname "${prog}"`
27        prog="${progdir}/${newProg}"
28    fi
29done
30oldwd=`pwd`
31progdir=`dirname "${prog}"`
32cd "${progdir}"
33progdir=`pwd`
34prog="${progdir}"/`basename "${prog}"`
35cd "${oldwd}"
36
37jarfile=BugReport.jar
38libdir="$progdir"
39
40if [ ! -r "$libdir/$jarfile" ]; then
41    # set jar location for the Android tree case
42    libdir=`dirname "$progdir"`/framework
43fi
44
45if [ ! -r "$libdir/$jarfile" ]; then
46    # set jar location for the SDK case
47    libdir="$libdir/lib"
48fi
49
50if [ ! -r "$progdir" ]; then
51    # set jar location for the manually distributed case
52    libdir="$progdir"
53fi
54
55if [ ! -r "$libdir/$jarfile" ]; then
56    echo `basename "$prog"`": can't find $jarfile"
57    exit 1
58fi
59
60# By default, give a max heap size of 1 gig. This can be overridden
61# by using a "-J" option (see below).
62# defaultMx="-Xmx1024M"
63
64# The following will extract any initial parameters of the form
65# "-J<stuff>" from the command line and pass them to the Java
66# invocation (instead of to the cmd). This makes it possible for you to add
67# a command-line parameter such as "-JXmx256M" in your scripts, for
68# example. "java" (with no args) and "java -X" give a summary of
69# available options.
70
71javaOpts=""
72
73while expr "x$1" : 'x-J' >/dev/null; do
74    opt=`expr "x$1" : 'x-J\(.*\)'`
75    javaOpts="${javaOpts} -${opt}"
76    if expr "x${opt}" : "xXmx[0-9]" >/dev/null; then
77        defaultMx="no"
78    fi
79    shift
80done
81
82if [ "${defaultMx}" != "no" ]; then
83    javaOpts="${javaOpts} ${defaultMx}"
84fi
85
86if [ "$OSTYPE" = "cygwin" ]; then
87    # For Cygwin, convert the jarfile path into native Windows style.
88    jarpath=`cygpath -w "$libdir/$jarfile"`
89else
90    jarpath="$libdir/$jarfile"
91fi
92
93exec java $javaOpts -jar "$jarpath" "$@"
94