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: |
Chiao Cheng | ac0a18e | 2012-07-12 18:27:23 -0700 | [diff] [blame] | 19 | # intellij-gen.sh <module name> |
| 20 | # |
| 21 | # where module name is the LOCAL_PACKAGE_NAME in Android.mk for the project. |
| 22 | # |
| 23 | # For example, to generate a project for Contacts, use: |
| 24 | # intellij-gen.sh Contacts |
| 25 | # |
Chiao Cheng | d7a603c | 2012-09-07 13:35:41 -0700 | [diff] [blame] | 26 | # The project directory (.idea) will be put in the root directory of |
| 27 | # the module. Sharable iml files will be put into each respective |
| 28 | # module directory. |
Chiao Cheng | ac0a18e | 2012-07-12 18:27:23 -0700 | [diff] [blame] | 29 | # |
| 30 | # Only tested on linux. Should work for macs but have not tried. |
| 31 | # |
| 32 | set -e |
| 33 | |
Chiao Cheng | ac0a18e | 2012-07-12 18:27:23 -0700 | [diff] [blame] | 34 | progname=`basename $0` |
Chiao Cheng | c8201d5 | 2013-06-13 13:41:24 -0700 | [diff] [blame] | 35 | if [ $# -lt 2 ] |
Chiao Cheng | ac0a18e | 2012-07-12 18:27:23 -0700 | [diff] [blame] | 36 | then |
Chiao Cheng | c8201d5 | 2013-06-13 13:41:24 -0700 | [diff] [blame] | 37 | echo "Usage: $progname project_dir module_dir <module_dir>..." |
Chiao Cheng | ac0a18e | 2012-07-12 18:27:23 -0700 | [diff] [blame] | 38 | exit 1 |
| 39 | fi |
Chiao Cheng | c8201d5 | 2013-06-13 13:41:24 -0700 | [diff] [blame] | 40 | project_dir=${PWD}/$1 |
| 41 | shift |
| 42 | module_dirs=$@ |
| 43 | echo $module_dirs |
Chiao Cheng | d7a603c | 2012-09-07 13:35:41 -0700 | [diff] [blame] | 44 | script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 45 | root_dir=$PWD |
| 46 | if [ ! -e $root_dir/.repo ]; then |
| 47 | root_dir=$PWD/../../.. |
| 48 | if [ ! -e $root_dir/.repo ]; then |
| 49 | echo "Repo root not found. Run this script from your repo root or the idegen directory." |
| 50 | exit 1 |
| 51 | fi |
| 52 | fi |
| 53 | index_file=$root_dir/module-index.txt |
| 54 | idegenjar=$script_dir/idegen.jar |
| 55 | if [ ! -e $idegenjar ]; then |
| 56 | # See if the jar is in the build directory. |
Evan Charlton | ffa8245 | 2014-05-20 10:55:54 -0700 | [diff] [blame] | 57 | platform="linux" |
| 58 | if [ "Darwin" = "$(uname)" ]; then |
| 59 | platform="darwin" |
| 60 | fi |
| 61 | idegenjar="$root_dir/out/host/$platform-x86/framework/idegen.jar" |
Chiao Cheng | d7a603c | 2012-09-07 13:35:41 -0700 | [diff] [blame] | 62 | fi |
| 63 | |
Chiao Cheng | ac0a18e | 2012-07-12 18:27:23 -0700 | [diff] [blame] | 64 | if [ ! -e "$index_file" ]; then |
| 65 | echo "Module index file missing; generating this is only done the first time." |
| 66 | echo "If any dependencies change, you should generate a new index file by running index-gen.sh." |
| 67 | $script_dir/index-gen.sh |
| 68 | fi |
| 69 | |
| 70 | echo "Checking for $idegenjar" |
| 71 | if [ -e "$idegenjar" ]; then |
Chiao Cheng | c8201d5 | 2013-06-13 13:41:24 -0700 | [diff] [blame] | 72 | echo "Generating project files for $module_dirs" |
| 73 | 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] | 74 | echo $cmd |
| 75 | $cmd |
| 76 | else |
| 77 | echo "Couldn't find idegen.jar. Please run make first." |
| 78 | fi |