Brett Chabot | 4bd67d5 | 2011-02-07 11:54:37 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Copyright (C) 2010 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 | # A helper script that launches TradeFederation from the current build |
| 18 | # environment. |
| 19 | |
| 20 | checkPath() { |
| 21 | if ! type -P $1 &> /dev/null; then |
| 22 | echo "Unable to find $1 in path." |
| 23 | exit |
| 24 | fi; |
| 25 | } |
| 26 | |
Brett Chabot | 19d2db1 | 2011-02-23 15:26:03 -0800 | [diff] [blame] | 27 | checkFile() { |
| 28 | if [ ! -f "$1" ]; then |
| 29 | echo "Unable to locate $1" |
| 30 | exit |
| 31 | fi; |
| 32 | } |
| 33 | |
Brett Chabot | 4bd67d5 | 2011-02-07 11:54:37 -0800 | [diff] [blame] | 34 | checkPath adb |
Brett Chabot | 4bd67d5 | 2011-02-07 11:54:37 -0800 | [diff] [blame] | 35 | checkPath java |
| 36 | |
| 37 | # check java version |
Omari Stephens | 7d42c4e | 2012-10-23 18:45:42 -0700 | [diff] [blame] | 38 | java_version_string=$(java -version 2>&1) |
| 39 | JAVA_VERSION=$(echo "$java_version_string" | grep '[ "]1\.[67][\. "$$]') |
Brett Chabot | 4bd67d5 | 2011-02-07 11:54:37 -0800 | [diff] [blame] | 40 | if [ "${JAVA_VERSION}" == "" ]; then |
| 41 | echo "Wrong java version. 1.6 is required." |
| 42 | exit |
Omari Stephens | 7d42c4e | 2012-10-23 18:45:42 -0700 | [diff] [blame] | 43 | else |
| 44 | # We have 1.6 or 1.7. Now print a warning if the version was 1.7 |
| 45 | java_version_17=$(echo "$java_version_string" | grep '[ "]1\.7[\. "$$]') |
| 46 | if [ "${java_version_17}" != "" ]; then |
| 47 | echo "WARNING: Trade Federation is not heavily tested under Java version 1.7" |
| 48 | echo |
| 49 | fi |
Brett Chabot | 4bd67d5 | 2011-02-07 11:54:37 -0800 | [diff] [blame] | 50 | fi |
| 51 | |
Guang Zhu | c5637f7 | 2011-07-24 13:15:24 -0700 | [diff] [blame] | 52 | # check debug flag and set up remote debugging |
| 53 | if [ -n "${TF_DEBUG}" ]; then |
Brett Chabot | 9229f38 | 2012-06-14 18:01:03 -0700 | [diff] [blame] | 54 | if [ -z "${TF_DEBUG_PORT}" ]; then |
| 55 | TF_DEBUG_PORT=10088 |
| 56 | fi |
Omari Stephens | 96eccb4 | 2012-06-18 21:10:58 -0700 | [diff] [blame] | 57 | RDBG_FLAG="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=${TF_DEBUG_PORT}" |
Guang Zhu | c5637f7 | 2011-07-24 13:15:24 -0700 | [diff] [blame] | 58 | fi |
| 59 | |
Brett Chabot | 9229f38 | 2012-06-14 18:01:03 -0700 | [diff] [blame] | 60 | # first try to find TF jars in same dir as this script |
Omari Stephens | 96eccb4 | 2012-06-18 21:10:58 -0700 | [diff] [blame] | 61 | CUR_DIR=$(dirname "$0") |
Brett Chabot | 9229f38 | 2012-06-14 18:01:03 -0700 | [diff] [blame] | 62 | if [ -f "${CUR_DIR}/tradefed.jar" ]; then |
Omari Stephens | 96eccb4 | 2012-06-18 21:10:58 -0700 | [diff] [blame] | 63 | tf_path="${CUR_DIR}/*" |
| 64 | elif [ ! -z "${ANDROID_HOST_OUT}" ]; then |
| 65 | # in an Android build env, tradefed.jar should be in |
| 66 | # $ANDROID_HOST_OUT/tradefed/ |
| 67 | if [ -f "${ANDROID_HOST_OUT}/tradefed/tradefed.jar" ]; then |
| 68 | # We intentionally pass the asterisk through without shell expansion |
| 69 | tf_path="${ANDROID_HOST_OUT}/tradefed/*" |
| 70 | # ddmlib-prebuilt is in the framework subdir |
| 71 | ddmlib_path="${ANDROID_HOST_OUT}/framework/ddmlib-prebuilt.jar" |
Brett Chabot | 9229f38 | 2012-06-14 18:01:03 -0700 | [diff] [blame] | 72 | fi |
| 73 | fi |
| 74 | |
| 75 | if [ -z "${tf_path}" ]; then |
Omari Stephens | 96eccb4 | 2012-06-18 21:10:58 -0700 | [diff] [blame] | 76 | echo "ERROR: Could not find tradefed jar files" |
Brett Chabot | 9229f38 | 2012-06-14 18:01:03 -0700 | [diff] [blame] | 77 | exit |
| 78 | fi |
| 79 | |
Brett Chabot | 4bd67d5 | 2011-02-07 11:54:37 -0800 | [diff] [blame] | 80 | |
Omari Stephens | 96eccb4 | 2012-06-18 21:10:58 -0700 | [diff] [blame] | 81 | # Note: must leave ${RDBG_FLAG} unquoted so that it goes away when unset |
Brett Chabot | aa23050 | 2013-01-02 10:22:06 -0800 | [diff] [blame] | 82 | java ${RDBG_FLAG} -XX:+HeapDumpOnOutOfMemoryError \ |
Omari Stephens | 96eccb4 | 2012-06-18 21:10:58 -0700 | [diff] [blame] | 83 | -cp "${ddmlib_path}:${tf_path}" com.android.tradefed.command.Console "$@" |