[go: nahoru, domu]

blob: 6ba0f23ff31461978df34536760acaab1156890a [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
Jeff Gastond25425c2020-12-02 09:53:57 -050026 echo " a, all"
Jeff Gaston4ac74c32021-01-29 12:12:20 -050027 echo " Open the project subset all"
Jeff Gastond25425c2020-12-02 09:53:57 -050028 echo
29 exit 1
30}
31
Jeff Gaston1db6bb82020-12-22 13:12:23 -050032cd "$(dirname $0)"
33
34subsetArg=""
35clean=false
36reinstall=false
37projectSubset=""
38while [ "$1" != "" ]; do
39 arg="$1"
40 shift
41 # parse options
42 if [ "$arg" == "--clean" ]; then
43 clean=true
44 continue
45 fi
46 if [ "$arg" == "--reinstall" ]; then
47 clean=true
48 reinstall=true
49 continue
50 fi
51 # parse arguments
52 subsetArg="$arg"
53 newSubset=""
54 if [ "$subsetArg" == "m" -o "$subsetArg" == "main" ]; then
Jeff Gaston4ac74c32021-01-29 12:12:20 -050055 newSubset=main
Jeff Gaston1db6bb82020-12-22 13:12:23 -050056 fi
57 if [ "$subsetArg" == "c" -o "$subsetArg" == "compose" ]; then
Jeff Gaston4ac74c32021-01-29 12:12:20 -050058 newSubset=compose
Jeff Gaston1db6bb82020-12-22 13:12:23 -050059 fi
60 if [ "$subsetArg" == "f" -o "$subsetArg" == "flan" ]; then
Jeff Gaston4ac74c32021-01-29 12:12:20 -050061 newSubset=flan
Jeff Gaston1db6bb82020-12-22 13:12:23 -050062 fi
Gyumin Simff92d182021-02-02 19:27:59 +090063 if [ "$subsetArg" == "media" ]; then
64 newSubset=media
65 fi
Jeff Gaston1db6bb82020-12-22 13:12:23 -050066 if [ "$subsetArg" == "a" -o "$subsetArg" == "all" ]; then
Jeff Gaston4ac74c32021-01-29 12:12:20 -050067 newSubset=all
Jeff Gaston1db6bb82020-12-22 13:12:23 -050068 fi
69 if [ "$newSubset" == "" ]; then
70 echo "Unrecognized argument: '$subsetArg'"
71 usage
72 fi
73 if [ "$projectSubset" != "" ]; then
74 echo "Unrecognized argument '$subsetArg', cannot specify project subset more than once"
75 usage
76 fi
77 projectSubset=$newSubset
78done
79
80if [ "$projectSubset" == "" ]; then
81 echo "Project subset is required"
Jeff Gastond25425c2020-12-02 09:53:57 -050082 usage
83fi
84
Jeff Gaston1db6bb82020-12-22 13:12:23 -050085export ANDROIDX_PROJECTS=$projectSubset
86
87# ensures the nonexistence of a file or directory, and makes a backup
88function remove() {
89 path="$1"
90 backup="$(dirname $path)/studio-backup/$(basename $path)"
91 if [ -e "$path" ]; then
92 echo "Moving $path to $backup"
93 rm "$backup" -rf
94 mkdir -p "$(dirname $backup)"
95 mv "$path" "$backup"
96 fi
97}
98
99if [ "$reinstall" == "true" ]; then
100 # remove Studio itself so Gradle will re-download it
101 rm studio -rf
Jeff Gastond25425c2020-12-02 09:53:57 -0500102fi
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500103
104if [ "$clean" == "true" ]; then
105 # remove studio-specific caches
106
107 # make backups of files that users might have customized
108 remove ~/.AndroidStudioAndroidX
109 remove ~/.AndroidStudioAndroidXPlayground
110 remove ~/.android
111 # delete (without backup) files that users won't have customized
112 git clean -fdX .idea/
113 # remove gradle caches too and build
114 ./cleanBuild.sh -y studio
115else
116 # ask gradle to launch studio
117 ./gradlew studio
118fi