Skip to content

Instantly share code, notes, and snippets.

@hannestyden
Forked from christoffer/andr
Last active April 8, 2018 01:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save hannestyden/6682767 to your computer and use it in GitHub Desktop.
Save hannestyden/6682767 to your computer and use it in GitHub Desktop.
#!/bin/bash
function _andr_push {
echo "Pushing $1"
adb $target_flag push $1 $books_dir
}
function _andr_delete {
echo "Removing $1"
adb $target_flag shell "rm $books_dir/$1"
}
function _andr_list {
adb $target_flag shell "ls $books_dir"
}
# Clean redeploy
function _andr_redeploy {
mvn -pl app clean
mvn -Dandroid.device=${maven_device_selector} -pl app package android:deploy
}
# Quick deploy
function _andr_deploy {
mvn -Dandroid.device=${maven_device_selector} -DskipTests -DskipNdkBuild -pl app package android:deploy android:run
}
# Clean before running instrumentation
function _andr_reinstrument {
mvn -pl app clean install
mvn -pl it clean
_andr_instrument $1
}
# Run instrumentation tests with an optional class filter.
# instrument "MyClass,AnotherClass" (runs tests from classes MyClass and AnotherClass)
# instrument (runs all tests)
# Note that this will use the currently installed (as in: mvn install) version of the
# app. Use reinstrument if you've made changes to the app that you need to test.
function _andr_instrument {
classfilter=""
if [ ! -z $1 ]
then
classfilter="-Dandroid.test.classes=$1 "
fi
mvn $classfilter-Dandroid.device=${maven_device_selector} -pl it package android:deploy android:instrument
}
function _andr_exit_with_usage {
echo "Usage: $0 list|delete|push|instrument|deploy|redeploy <arguments>"
exit
}
function _andr_print_target {
case "$target_flag" in
-e ) echo "(=> Emulator)" ;;
-d ) echo "(=> Device)" ;;
esac
}
function _andr_print_package {
echo "(package: ${ANDR_PACKAGE})"
}
function andr {
set -e
if [ $# -lt 1 ]
then
_andr_exit_with_usage
fi
if [[ -z $ANDR_TARGET ]]
then
ANDR_TARGET="emulator"
fi
if [[ $ANDR_TARGET = "device" ]]
then
target_flag="-d"
maven_device_selector="usb"
elif [[ $ANDR_TARGET = "emulator" ]]
then
target_flag="-e"
maven_device_selector="emulator"
elif [[ ! -z $ANDR_TARGET ]]
then
echo "Unknown ANDR_TARGET: $ANDR_TARGET"
echo "Valid values: 'device' or 'emulator'"
exit
fi
default_package="com.readmill.android.dev"
if [ -z $ANDR_PACKAGE ]
then
ANDR_PACKAGE=$default_package
fi
books_dir=/mnt/sdcard/Android/data/${ANDR_PACKAGE}/files/books
_andr_print_target
if [[ $ANDR_PACKAGE != $default_package ]]
then
_andr_print_package
fi
case "$1" in
list ) _andr_list
;;
delete ) _andr_delete $2
;;
push ) _andr_push $2
;;
deploy ) _andr_deploy
;;
redeploy ) _andr_redeploy
;;
reinstrument ) _andr_reinstrument $2
;;
instrument ) _andr_instrument $2
;;
* ) _andr_exit_with_usage
esac
}
@hannestyden
Copy link
Author

I prefer putting shell scripts in functions. That way it doesn't matter where they live on the FS and they don't require any privileges, and I just source them when needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment