blob: a7cfd05fa6e35c598597061619210004260f5d2b [file] [log] [blame]
Brett Chabot4bd67d52011-02-07 11:54:37 -08001#!/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
20checkPath() {
21 if ! type -P $1 &> /dev/null; then
22 echo "Unable to find $1 in path."
23 exit
24 fi;
25}
26
Brett Chabot19d2db12011-02-23 15:26:03 -080027checkFile() {
28 if [ ! -f "$1" ]; then
29 echo "Unable to locate $1"
30 exit
31 fi;
32}
33
Brett Chabot4bd67d52011-02-07 11:54:37 -080034checkPath adb
Brett Chabot4bd67d52011-02-07 11:54:37 -080035checkPath java
36
37# check java version
Omari Stephens7d42c4e2012-10-23 18:45:42 -070038java_version_string=$(java -version 2>&1)
39JAVA_VERSION=$(echo "$java_version_string" | grep '[ "]1\.[67][\. "$$]')
Brett Chabot4bd67d52011-02-07 11:54:37 -080040if [ "${JAVA_VERSION}" == "" ]; then
41 echo "Wrong java version. 1.6 is required."
42 exit
Omari Stephens7d42c4e2012-10-23 18:45:42 -070043else
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 Chabot4bd67d52011-02-07 11:54:37 -080050fi
51
Guang Zhuc5637f72011-07-24 13:15:24 -070052# check debug flag and set up remote debugging
53if [ -n "${TF_DEBUG}" ]; then
Brett Chabot9229f382012-06-14 18:01:03 -070054 if [ -z "${TF_DEBUG_PORT}" ]; then
55 TF_DEBUG_PORT=10088
56 fi
Omari Stephens96eccb42012-06-18 21:10:58 -070057 RDBG_FLAG="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=${TF_DEBUG_PORT}"
Guang Zhuc5637f72011-07-24 13:15:24 -070058fi
59
Brett Chabot9229f382012-06-14 18:01:03 -070060# first try to find TF jars in same dir as this script
Omari Stephens96eccb42012-06-18 21:10:58 -070061CUR_DIR=$(dirname "$0")
Brett Chabot9229f382012-06-14 18:01:03 -070062if [ -f "${CUR_DIR}/tradefed.jar" ]; then
Omari Stephens96eccb42012-06-18 21:10:58 -070063 tf_path="${CUR_DIR}/*"
64elif [ ! -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 Chabot9229f382012-06-14 18:01:03 -070072 fi
73fi
74
75if [ -z "${tf_path}" ]; then
Omari Stephens96eccb42012-06-18 21:10:58 -070076 echo "ERROR: Could not find tradefed jar files"
Brett Chabot9229f382012-06-14 18:01:03 -070077 exit
78fi
79
Brett Chabot4bd67d52011-02-07 11:54:37 -080080
Omari Stephens96eccb42012-06-18 21:10:58 -070081# Note: must leave ${RDBG_FLAG} unquoted so that it goes away when unset
Brett Chabotaa230502013-01-02 10:22:06 -080082java ${RDBG_FLAG} -XX:+HeapDumpOnOutOfMemoryError \
Omari Stephens96eccb42012-06-18 21:10:58 -070083 -cp "${ddmlib_path}:${tf_path}" com.android.tradefed.command.Console "$@"