1#!/bin/bash 2 3OLD="$1" 4NEW="$2" 5 6# sanity check in input args 7if [ -z "$OLD" ] || [ -z "$NEW" ]; then 8 cat <<EOF 9Usage: $0 <old> <new> 10Changes the ADT plugin revision number. 11Example: 12 cd sdk/eclipse 13 scripts/update_version.sh 0.1.2 0.2.3 14EOF 15 exit 1 16fi 17 18# sanity check on current dir 19if [ `basename "$PWD"` != "eclipse" ]; then 20 echo "Please run this from sdk/eclipse." 21 exit 1 22fi 23 24# sanity check the new version number 25if [[ "$NEW" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then 26 echo "## Version $NEW: seems valid." 27else 28 echo "## Version $NEW: does not conform to major.mino.micro format." 29 exit 1 30fi 31 32function replace() { 33 if [[ -f "$1" ]]; then 34 echo "### Change $SED_OLD => $SED_NEW in $1" 35 if [[ $(uname) == "Linux" ]]; then 36 sed -i "s/$SED_OLD/$SED_NEW/g" "$1" 37 else 38 # sed on Mac doesn't handle -i the same way as on Linux 39 sed -i "" "s/$SED_OLD/$SED_NEW/g" "$1" 40 fi 41 fi 42} 43 44# ---1--- Change Eclipse's qualified version numbers 45# quote dots for regexps 46SED_OLD="${OLD//./\.}\.qualifier" 47SED_NEW="${NEW//./\.}\.qualifier" 48 49for i in $(grep -rl "$OLD" * | grep -E "\.xml$|\.MF$|\.product$"); do 50 if [[ -f "$i" && $(basename "$i") != "build.xml" ]]; then 51 replace "$i" 52 fi 53done 54 55# ---2--- Change unqualified version numbers in specific files 56SED_OLD="${OLD//./\.}" 57SED_NEW="${NEW//./\.}" 58for i in artifacts/*/pom.xml \ 59 monitor/build.gradle \ 60 plugins/com.android.ide.eclipse.adt.package/ide.product \ 61 plugins/com.android.ide.eclipse.monitor/monitor.product \ 62 plugins/com.android.ide.eclipse.monitor/plugin.properties \ 63 plugins/com.android.ide.eclipse.*/pom.xml \ 64 features/com.android.ide.eclipse.*/pom.xml \ 65 features/com.android.ide.eclipse.adt.package/feature.xml ; do 66 if grep -qs "$OLD" "$i"; then 67 replace "$i" 68 fi 69done 70 71# do another grep for older version without the qualifier. We don't 72# want to replace those automatically as it could be something else. 73# Printing out occurence helps find ones to update manually, but exclude 74# some known useless files. 75echo 76echo "#### ----------------" 77echo "#### Remaining instances of $OLD" 78echo 79grep -r "$OLD" * | grep -v -E "/build.xml:|/javaCompiler\.\.\.args:" 80 81