[go: nahoru, domu]

blob: e0110f9b27300f06819cadcd595c75a3f6cb444c [file] [log] [blame]
Alan Viverettea693ece2020-11-17 16:23:42 -05001#!/usr/bin/env bash
Alan Viverettea693ece2020-11-17 16:23:42 -05002
Jeff Gastond25425c2020-12-02 09:53:57 -05003function usage() {
Jeff Gaston1db6bb82020-12-22 13:12:23 -05004 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 Gastond25425c2020-12-02 09:53:57 -050012 echo
13 echo "Project subsets:"
14 echo " m, main"
Jeff Gaston4ac74c32021-01-29 12:12:20 -050015 echo " Open the project subset main: non-Compose Jetpack libraries"
Jeff Gastond25425c2020-12-02 09:53:57 -050016 echo
17 echo " c, compose"
Jeff Gaston4ac74c32021-01-29 12:12:20 -050018 echo " Open the project subset compose"
Jeff Gastond25425c2020-12-02 09:53:57 -050019 echo
20 echo " f, flan"
Jeff Gaston4ac74c32021-01-29 12:12:20 -050021 echo " Open the project subset flan: Fragment, Lifecycle, Activity, and Navigation"
Jeff Gastond25425c2020-12-02 09:53:57 -050022 echo
Gyumin Simff92d182021-02-02 19:27:59 +090023 echo " media"
24 echo " Open the project subset media: Media, Media2, and MediaRouter"
25 echo
Flavio Lerda726911b2021-01-18 18:15:06 +000026 echo " w, wear"
27 echo " Open the project subset for Wear OS libraries"
28 echo
Jeff Gastond25425c2020-12-02 09:53:57 -050029 echo " a, all"
Jeff Gaston4ac74c32021-01-29 12:12:20 -050030 echo " Open the project subset all"
Jeff Gastond25425c2020-12-02 09:53:57 -050031 echo
32 exit 1
33}
34
Jeff Gaston1db6bb82020-12-22 13:12:23 -050035cd "$(dirname $0)"
36
37subsetArg=""
38clean=false
39reinstall=false
40projectSubset=""
41while [ "$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 Gaston4ac74c32021-01-29 12:12:20 -050058 newSubset=main
Jeff Gaston1db6bb82020-12-22 13:12:23 -050059 fi
60 if [ "$subsetArg" == "c" -o "$subsetArg" == "compose" ]; then
Jeff Gaston4ac74c32021-01-29 12:12:20 -050061 newSubset=compose
Jeff Gaston1db6bb82020-12-22 13:12:23 -050062 fi
63 if [ "$subsetArg" == "f" -o "$subsetArg" == "flan" ]; then
Jeff Gaston4ac74c32021-01-29 12:12:20 -050064 newSubset=flan
Jeff Gaston1db6bb82020-12-22 13:12:23 -050065 fi
Gyumin Simff92d182021-02-02 19:27:59 +090066 if [ "$subsetArg" == "media" ]; then
67 newSubset=media
68 fi
Flavio Lerda726911b2021-01-18 18:15:06 +000069 if [ "$subsetArg" == "w" -o "$subsetArg" == "wear" ]; then
70 newSubset=wear
71 fi
Jeff Gaston1db6bb82020-12-22 13:12:23 -050072 if [ "$subsetArg" == "a" -o "$subsetArg" == "all" ]; then
Jeff Gaston4ac74c32021-01-29 12:12:20 -050073 newSubset=all
Jeff Gaston1db6bb82020-12-22 13:12:23 -050074 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
84done
85
86if [ "$projectSubset" == "" ]; then
87 echo "Project subset is required"
Jeff Gastond25425c2020-12-02 09:53:57 -050088 usage
89fi
90
Jeff Gaston1db6bb82020-12-22 13:12:23 -050091export ANDROIDX_PROJECTS=$projectSubset
92
93# ensures the nonexistence of a file or directory, and makes a backup
94function 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
105if [ "$reinstall" == "true" ]; then
106 # remove Studio itself so Gradle will re-download it
107 rm studio -rf
Jeff Gastond25425c2020-12-02 09:53:57 -0500108fi
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500109
110if [ "$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
121else
122 # ask gradle to launch studio
Aurimas Liutikas0db05722021-07-20 13:06:27 -0700123 ./gradlew :studio
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500124fi