print_syntax() {
echo "Syntax:/n/t$(basename $0) [option]"
echo "/nOptions:"
echo "/t-l prints available versions"
echo "/t-v builds jar file with sources of specified version"
echo "/t-c cleans up the sources from the temp directory/n"
exit 1
}
error() {
echo "Error:" $1
exit 1
}
download_sources() {
if [[ ! -d $SRC_DIR ]]; then
git clone git://git.source.android.com/platform/frameworks/base $SRC_DIR
fi
}
if ! which git > /dev/null ; then
error "git not installed (or not in the PATH)"
fi
if ! which jar > /dev/null ; then
error "jar not installed (or not in the PATH)"
fi
if [[ "$1" == "-l" ]]; then
download_sources
cd $SRC_DIR
git tag -l
exit 0;
fi
if [[ "$1" == "-c" ]]; then
rm -rf $SRC_DIR
exit 0;
fi
if [[ "$1" == "-v" && ! -z "$2" ]]; then
JAR_FILE=$(pwd)/$2-src.jar
download_sources
cd $SRC_DIR
if ! git tag -l | grep $2 ; then
echo "Version /"$2/" not found"
exit 1;
fi
git checkout $2
touch $JAR_FILE
find . -depth 2 -name "java" -type d -exec jar uf $JAR_FILE -C {} . /;
exit 0
fi