1#!/bin/bash
2#
3# Copyright 2013 The Android Open Source Project.
4#
5# Retrieves the current Mockito source code into the current directory, excluding portions related
6# to mockito's internal build system and javadoc.
7
8# Force stop on first error.
9set -e
10
11if [ $# -ne 1 ]; then
12    echo "$0 <version>" >&2
13    exit 1;
14fi
15
16if [ -z "$ANDROID_BUILD_TOP" ]; then
17    echo "Missing environment variables. Did you run build/envsetup.sh and lunch?" >&2
18    exit 1
19fi
20
21VERSION=${1}
22
23SOURCE="git://github.com/mockito/mockito.git"
24INCLUDE="
25    LICENSE
26    src
27    subprojects/android
28    subprojects/inline
29    "
30
31EXCLUDE="
32    src/conf
33    src/javadoc
34    "
35
36working_dir="$(mktemp -d)"
37trap "echo \"Removing temporary directory\"; rm -rf $working_dir" EXIT
38
39echo "Fetching Mockito source into $working_dir"
40git clone $SOURCE $working_dir/source
41(cd $working_dir/source; git checkout $VERSION)
42
43for include in ${INCLUDE}; do
44  echo "Updating $include"
45  rm -rf $include
46  mkdir -p $(dirname $include)
47  cp -R $working_dir/source/$include $include
48done;
49
50for exclude in ${EXCLUDE}; do
51  echo "Excluding $exclude"
52  rm -r $exclude
53done;
54
55echo "Done"
56
57# Update the version.
58perl -pi -e "s|^Version: .*$|Version: ${VERSION}|" "README.version"
59
60# Remove any documentation about local modifications.
61mv README.version README.tmp
62grep -B 100 "Local Modifications" README.tmp > README.version
63echo "        None" >> README.version
64rm README.tmp
65
66echo "Done"
67