[go: nahoru, domu]

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