Home | History | Annotate | Download | only in etc
      1 #!/bin/bash
      2 #
      3 # Copyright (C) 2017 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 # Execute the jdwpgen program
     18 prog="$0"
     19 while [ -h "${prog}" ]; do
     20     newProg=`/bin/ls -ld "${prog}"`
     21     newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
     22     if expr "x${newProg}" : 'x/' >/dev/null; then
     23         prog="${newProg}"
     24     else
     25         progdir=`dirname "${prog}"`
     26         prog="${progdir}/${newProg}"
     27     fi
     28 done
     29 oldwd=`pwd`
     30 progdir=`dirname "${prog}"`
     31 cd "${progdir}"
     32 progdir=`pwd`
     33 prog="${progdir}"/`basename "${prog}"`
     34 cd "${oldwd}"
     35 
     36 jarfile=jdwpgen.jar
     37 libdir="$progdir"
     38 
     39 if [ ! -r "$libdir/$jarfile" ]; then
     40     # set jdwpgen.jar location for the Android tree case
     41     libdir=`dirname "$progdir"`/framework
     42 fi
     43 
     44 if [ ! -r "$libdir/$jarfile" ]; then
     45     echo `basename "$prog"`": can't find $jarfile"
     46     exit 1
     47 fi
     48 
     49 # By default, give jdwpgen a max heap size of 1 gig. This can be overridden
     50 # by using a "-J" option (see below).
     51 defaultMx="-Xmx1024M"
     52 
     53 # The following will extract any initial parameters of the form "-J<stuff>" from
     54 # the command line and pass them to the Java invocation (instead of to jdwpgen).
     55 # This makes it possible for you to add a command-line parameter such as
     56 # "-JXmx256M" in your scripts, for example. "java" (with no args) and "java -X"
     57 # give a summary of available options.
     58 
     59 javaOpts=""
     60 
     61 while expr "x$1" : 'x-J' >/dev/null; do
     62     opt=`expr "x$1" : 'x-J\(.*\)'`
     63     javaOpts="${javaOpts} -${opt}"
     64     if expr "x${opt}" : "xXmx[0-9]" >/dev/null; then
     65         defaultMx="no"
     66     fi
     67     shift
     68 done
     69 
     70 if [ "${defaultMx}" != "no" ]; then
     71     javaOpts="${javaOpts} ${defaultMx}"
     72 fi
     73 
     74 if [ "$OSTYPE" = "cygwin" ]; then
     75     # For Cygwin, convert the jarfile path into native Windows style.
     76     jarpath=`cygpath -w "$libdir/$jarfile"`
     77 else
     78     jarpath="$libdir/$jarfile"
     79 fi
     80 
     81 exec java $javaOpts -jar "$jarpath" "$@"
     82