Alan Viverette | a693ece | 2020-11-17 16:23:42 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Alan Viverette | a693ece | 2020-11-17 16:23:42 -0500 | [diff] [blame] | 2 | |
Jeff Gaston | d25425c | 2020-12-02 09:53:57 -0500 | [diff] [blame] | 3 | function usage() { |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 4 | echo "Usage: studiow [--clean] [--reinstall] [<project subset>]" |
| 5 | echo |
| 6 | echo "OPTIONS" |
| 7 | echo " --clean" |
| 8 | echo " Clear (with backup) generated files (settings, caches, etc) before launching" |
| 9 | echo |
| 10 | echo " --reinstall" |
| 11 | echo " Remove and re-download Studio itself. Also implies --clean" |
Jeff Gaston | d25425c | 2020-12-02 09:53:57 -0500 | [diff] [blame] | 12 | echo |
| 13 | echo "Project subsets:" |
| 14 | echo " m, main" |
Jeff Gaston | 4ac74c3 | 2021-01-29 12:12:20 -0500 | [diff] [blame] | 15 | echo " Open the project subset main: non-Compose Jetpack libraries" |
Jeff Gaston | d25425c | 2020-12-02 09:53:57 -0500 | [diff] [blame] | 16 | echo |
| 17 | echo " c, compose" |
Jeff Gaston | 4ac74c3 | 2021-01-29 12:12:20 -0500 | [diff] [blame] | 18 | echo " Open the project subset compose" |
Jeff Gaston | d25425c | 2020-12-02 09:53:57 -0500 | [diff] [blame] | 19 | echo |
| 20 | echo " f, flan" |
Jeff Gaston | 4ac74c3 | 2021-01-29 12:12:20 -0500 | [diff] [blame] | 21 | echo " Open the project subset flan: Fragment, Lifecycle, Activity, and Navigation" |
Jeff Gaston | d25425c | 2020-12-02 09:53:57 -0500 | [diff] [blame] | 22 | echo |
Gyumin Sim | ff92d18 | 2021-02-02 19:27:59 +0900 | [diff] [blame] | 23 | echo " media" |
| 24 | echo " Open the project subset media: Media, Media2, and MediaRouter" |
| 25 | echo |
Flavio Lerda | 726911b | 2021-01-18 18:15:06 +0000 | [diff] [blame] | 26 | echo " w, wear" |
| 27 | echo " Open the project subset for Wear OS libraries" |
| 28 | echo |
Jeff Gaston | d25425c | 2020-12-02 09:53:57 -0500 | [diff] [blame] | 29 | echo " a, all" |
Jeff Gaston | 4ac74c3 | 2021-01-29 12:12:20 -0500 | [diff] [blame] | 30 | echo " Open the project subset all" |
Jeff Gaston | d25425c | 2020-12-02 09:53:57 -0500 | [diff] [blame] | 31 | echo |
| 32 | exit 1 |
| 33 | } |
| 34 | |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 35 | cd "$(dirname $0)" |
| 36 | |
| 37 | subsetArg="" |
| 38 | clean=false |
| 39 | reinstall=false |
| 40 | projectSubset="" |
| 41 | while [ "$1" != "" ]; do |
| 42 | arg="$1" |
| 43 | shift |
| 44 | # parse options |
| 45 | if [ "$arg" == "--clean" ]; then |
| 46 | clean=true |
| 47 | continue |
| 48 | fi |
| 49 | if [ "$arg" == "--reinstall" ]; then |
| 50 | clean=true |
| 51 | reinstall=true |
| 52 | continue |
| 53 | fi |
| 54 | # parse arguments |
| 55 | subsetArg="$arg" |
| 56 | newSubset="" |
| 57 | if [ "$subsetArg" == "m" -o "$subsetArg" == "main" ]; then |
Jeff Gaston | 4ac74c3 | 2021-01-29 12:12:20 -0500 | [diff] [blame] | 58 | newSubset=main |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 59 | fi |
| 60 | if [ "$subsetArg" == "c" -o "$subsetArg" == "compose" ]; then |
Jeff Gaston | 4ac74c3 | 2021-01-29 12:12:20 -0500 | [diff] [blame] | 61 | newSubset=compose |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 62 | fi |
| 63 | if [ "$subsetArg" == "f" -o "$subsetArg" == "flan" ]; then |
Jeff Gaston | 4ac74c3 | 2021-01-29 12:12:20 -0500 | [diff] [blame] | 64 | newSubset=flan |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 65 | fi |
Gyumin Sim | ff92d18 | 2021-02-02 19:27:59 +0900 | [diff] [blame] | 66 | if [ "$subsetArg" == "media" ]; then |
| 67 | newSubset=media |
| 68 | fi |
Flavio Lerda | 726911b | 2021-01-18 18:15:06 +0000 | [diff] [blame] | 69 | if [ "$subsetArg" == "w" -o "$subsetArg" == "wear" ]; then |
| 70 | newSubset=wear |
| 71 | fi |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 72 | if [ "$subsetArg" == "a" -o "$subsetArg" == "all" ]; then |
Jeff Gaston | 4ac74c3 | 2021-01-29 12:12:20 -0500 | [diff] [blame] | 73 | newSubset=all |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 74 | fi |
| 75 | if [ "$newSubset" == "" ]; then |
| 76 | echo "Unrecognized argument: '$subsetArg'" |
| 77 | usage |
| 78 | fi |
| 79 | if [ "$projectSubset" != "" ]; then |
| 80 | echo "Unrecognized argument '$subsetArg', cannot specify project subset more than once" |
| 81 | usage |
| 82 | fi |
| 83 | projectSubset=$newSubset |
| 84 | done |
| 85 | |
| 86 | if [ "$projectSubset" == "" ]; then |
| 87 | echo "Project subset is required" |
Jeff Gaston | d25425c | 2020-12-02 09:53:57 -0500 | [diff] [blame] | 88 | usage |
| 89 | fi |
| 90 | |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 91 | export ANDROIDX_PROJECTS=$projectSubset |
| 92 | |
| 93 | # ensures the nonexistence of a file or directory, and makes a backup |
| 94 | function remove() { |
| 95 | path="$1" |
| 96 | backup="$(dirname $path)/studio-backup/$(basename $path)" |
| 97 | if [ -e "$path" ]; then |
| 98 | echo "Moving $path to $backup" |
| 99 | rm "$backup" -rf |
| 100 | mkdir -p "$(dirname $backup)" |
| 101 | mv "$path" "$backup" |
| 102 | fi |
| 103 | } |
| 104 | |
| 105 | if [ "$reinstall" == "true" ]; then |
| 106 | # remove Studio itself so Gradle will re-download it |
| 107 | rm studio -rf |
Jeff Gaston | d25425c | 2020-12-02 09:53:57 -0500 | [diff] [blame] | 108 | fi |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 109 | |
| 110 | if [ "$clean" == "true" ]; then |
| 111 | # remove studio-specific caches |
| 112 | |
| 113 | # make backups of files that users might have customized |
| 114 | remove ~/.AndroidStudioAndroidX |
| 115 | remove ~/.AndroidStudioAndroidXPlayground |
| 116 | remove ~/.android |
| 117 | # delete (without backup) files that users won't have customized |
| 118 | git clean -fdX .idea/ |
| 119 | # remove gradle caches too and build |
| 120 | ./cleanBuild.sh -y studio |
| 121 | else |
| 122 | # ask gradle to launch studio |
Aurimas Liutikas | 0db0572 | 2021-07-20 13:06:27 -0700 | [diff] [blame] | 123 | ./gradlew :studio |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 124 | fi |