Chiao Cheng | ac0a18e | 2012-07-12 18:27:23 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) 2012 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # |
Chiao Cheng | d7a603c | 2012-09-07 13:35:41 -0700 | [diff] [blame] | 17 | # To use, run the following command from either your repo root or |
| 18 | # development/tools/idegen: |
Xiaohui Chen | aa5d149 | 2015-08-03 15:50:32 -0700 | [diff] [blame] | 19 | # intellij-gen.sh project_dir <module_dir>... |
Chiao Cheng | ac0a18e | 2012-07-12 18:27:23 -0700 | [diff] [blame] | 20 | # |
Xiaohui Chen | aa5d149 | 2015-08-03 15:50:32 -0700 | [diff] [blame] | 21 | # if no module_dir is provided, we assume project_dir is also a module_dir. |
Chiao Cheng | ac0a18e | 2012-07-12 18:27:23 -0700 | [diff] [blame] | 22 | # |
Xiaohui Chen | aa5d149 | 2015-08-03 15:50:32 -0700 | [diff] [blame] | 23 | # For example, to generate a project for framework/base, use: |
| 24 | # intellij-gen.sh framework/base |
Chiao Cheng | ac0a18e | 2012-07-12 18:27:23 -0700 | [diff] [blame] | 25 | # |
Xiaohui Chen | aa5d149 | 2015-08-03 15:50:32 -0700 | [diff] [blame] | 26 | # The project directory (.idea) will be put in the project_dir. Sharable |
| 27 | # iml files will be put into each respective module directory. |
Chiao Cheng | ac0a18e | 2012-07-12 18:27:23 -0700 | [diff] [blame] | 28 | # |
| 29 | # Only tested on linux. Should work for macs but have not tried. |
| 30 | # |
| 31 | set -e |
| 32 | |
Chiao Cheng | ac0a18e | 2012-07-12 18:27:23 -0700 | [diff] [blame] | 33 | progname=`basename $0` |
Xiaohui Chen | aa5d149 | 2015-08-03 15:50:32 -0700 | [diff] [blame] | 34 | if [ $# -lt 1 ]; then |
| 35 | echo "Usage: $progname project_dir <module_dir>..." |
| 36 | exit 1 |
Chiao Cheng | ac0a18e | 2012-07-12 18:27:23 -0700 | [diff] [blame] | 37 | fi |
Xiaohui Chen | aa5d149 | 2015-08-03 15:50:32 -0700 | [diff] [blame] | 38 | project_dir=$1 |
Chiao Cheng | c8201d5 | 2013-06-13 13:41:24 -0700 | [diff] [blame] | 39 | shift |
Xiaohui Chen | aa5d149 | 2015-08-03 15:50:32 -0700 | [diff] [blame] | 40 | if [ -z $@ ]; then |
| 41 | module_dirs=${project_dir} |
| 42 | else |
| 43 | module_dirs=$@ |
| 44 | fi |
Chiao Cheng | c8201d5 | 2013-06-13 13:41:24 -0700 | [diff] [blame] | 45 | echo $module_dirs |
Chiao Cheng | d7a603c | 2012-09-07 13:35:41 -0700 | [diff] [blame] | 46 | script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 47 | root_dir=$PWD |
| 48 | if [ ! -e $root_dir/.repo ]; then |
| 49 | root_dir=$PWD/../../.. |
| 50 | if [ ! -e $root_dir/.repo ]; then |
| 51 | echo "Repo root not found. Run this script from your repo root or the idegen directory." |
| 52 | exit 1 |
| 53 | fi |
| 54 | fi |
| 55 | index_file=$root_dir/module-index.txt |
| 56 | idegenjar=$script_dir/idegen.jar |
| 57 | if [ ! -e $idegenjar ]; then |
| 58 | # See if the jar is in the build directory. |
Evan Charlton | ffa8245 | 2014-05-20 10:55:54 -0700 | [diff] [blame] | 59 | platform="linux" |
| 60 | if [ "Darwin" = "$(uname)" ]; then |
| 61 | platform="darwin" |
| 62 | fi |
| 63 | idegenjar="$root_dir/out/host/$platform-x86/framework/idegen.jar" |
Chiao Cheng | d7a603c | 2012-09-07 13:35:41 -0700 | [diff] [blame] | 64 | fi |
| 65 | |
Chiao Cheng | ac0a18e | 2012-07-12 18:27:23 -0700 | [diff] [blame] | 66 | if [ ! -e "$index_file" ]; then |
| 67 | echo "Module index file missing; generating this is only done the first time." |
| 68 | echo "If any dependencies change, you should generate a new index file by running index-gen.sh." |
| 69 | $script_dir/index-gen.sh |
| 70 | fi |
| 71 | |
| 72 | echo "Checking for $idegenjar" |
| 73 | if [ -e "$idegenjar" ]; then |
Chiao Cheng | c8201d5 | 2013-06-13 13:41:24 -0700 | [diff] [blame] | 74 | echo "Generating project files for $module_dirs" |
| 75 | cmd="java -cp $idegenjar com.android.idegen.IntellijProject $index_file $project_dir $module_dirs" |
Chiao Cheng | ac0a18e | 2012-07-12 18:27:23 -0700 | [diff] [blame] | 76 | echo $cmd |
| 77 | $cmd |
| 78 | else |
| 79 | echo "Couldn't find idegen.jar. Please run make first." |
| 80 | fi |