uiautomatorviewer revision 4c3b19c11bed6972f2ebf758af4025607b41b11b
1#!/bin/bash
2#
3# Copyright 2012, 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}"`
32progname=`basename "${prog}"`
33cd "${progdir}"
34progdir=`pwd`
35prog="${progdir}"/"${progname}"
36cd "${oldwd}"
37
38jarfile=uiautomatorviewer.jar
39frameworkdir="$progdir"
40libdir="$progdir"
41if [ ! -r "$frameworkdir/$jarfile" ]
42then
43    frameworkdir=`dirname "$progdir"`/tools/lib
44    libdir=`dirname "$progdir"`/tools/lib
45fi
46if [ ! -r "$frameworkdir/$jarfile" ]
47then
48    frameworkdir=`dirname "$progdir"`/framework
49    libdir=`dirname "$progdir"`/lib
50fi
51if [ ! -r "$frameworkdir/$jarfile" ]
52then
53    echo "${progname}: can't find $jarfile"
54    exit 1
55fi
56
57javaCmd="java"
58
59os=`uname`
60if [ $os == 'Darwin' ]; then
61  javaOpts="-Xmx1600M -XstartOnFirstThread"
62else
63  javaOpts="-Xmx1600M"
64fi
65
66if [ `uname` = "Linux" ]; then
67    export GDK_NATIVE_WINDOWS=true
68fi
69
70while expr "x$1" : 'x-J' >/dev/null; do
71    opt=`expr "x$1" : 'x-J\(.*\)'`
72    javaOpts="${javaOpts} -${opt}"
73    shift
74done
75
76jarpath="$frameworkdir/$jarfile"
77
78# Figure out the path to the swt.jar for the current architecture.
79# if ANDROID_SWT is defined, then just use this.
80# else, if running in the Android source tree, then look for the correct swt folder in prebuilt
81# else, look for the correct swt folder in the SDK under tools/lib/
82swtpath=""
83if [ -n "$ANDROID_SWT" ]; then
84    swtpath="$ANDROID_SWT"
85else
86    vmarch=`${javaCmd} -jar "${frameworkdir}"/archquery.jar`
87    if [ -n "$ANDROID_BUILD_TOP" ]; then
88        osname=`uname -s | tr A-Z a-z`
89        swtpath="${ANDROID_BUILD_TOP}/prebuilts/tools/${osname}-${vmarch}/swt"
90    else
91        swtpath="${frameworkdir}/${vmarch}"
92    fi
93fi
94
95# Combine the swtpath and the framework dir path.
96if [ -d "$swtpath" ]; then
97    frameworkdir="${swtpath}:${frameworkdir}"
98else
99    echo "SWT folder '${swtpath}' does not exist."
100    echo "Please export ANDROID_SWT to point to the folder containing swt.jar for your platform."
101    exit 1
102fi
103
104exec "${javaCmd}" $javaOpts -Djava.ext.dirs="$frameworkdir" -Dcom.android.uiautomator.bindir="$progdir" -jar "$jarpath" "$@"
105