Home | History | Annotate | Download | only in scripts
      1 #!/bin/bash
      2 
      3 OLD="$1"
      4 NEW="$2"
      5 
      6 # sanity check in input args
      7 if [ -z "$OLD" ] || [ -z "$NEW" ]; then
      8     cat <<EOF
      9 Usage: $0 <old> <new>
     10 Changes the ADT plugin revision number.
     11 Example:
     12   cd sdk/eclipse
     13   scripts/update_version.sh 0.1.2 0.2.3
     14 EOF
     15     exit 1
     16 fi
     17 
     18 # sanity check on current dir
     19 if [ `basename "$PWD"` != "eclipse" ]; then
     20     echo "Please run this from sdk/eclipse."
     21     exit 1
     22 fi
     23 
     24 # sanity check the new version number
     25 if [[ "$NEW" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
     26   echo "## Version $NEW: seems valid."
     27 else
     28   echo "## Version $NEW: does not conform to major.mino.micro format."
     29   exit 1
     30 fi
     31 
     32 function 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
     46 SED_OLD="${OLD//./\.}\.qualifier"
     47 SED_NEW="${NEW//./\.}\.qualifier"
     48 
     49 for 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
     53 done
     54 
     55 # ---2--- Change unqualified version numbers in specific files
     56 SED_OLD="${OLD//./\.}"
     57 SED_NEW="${NEW//./\.}"
     58 for 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
     69 done
     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.
     75 echo
     76 echo "#### ----------------"
     77 echo "#### Remaining instances of $OLD"
     78 echo
     79 grep -r "$OLD" * | grep -v -E "/build.xml:|/javaCompiler\.\.\.args:"
     80 
     81