blob: 462e232fa1d85bbe170ee432434b2c5ee7c2df7a [file] [log] [blame]
Chiao Chengac0a18e2012-07-12 18:27:23 -07001#!/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 Chengd7a603c2012-09-07 13:35:41 -070017# To use, run the following command from either your repo root or
18# development/tools/idegen:
Xiaohui Chenaa5d1492015-08-03 15:50:32 -070019# intellij-gen.sh project_dir <module_dir>...
Chiao Chengac0a18e2012-07-12 18:27:23 -070020#
Xiaohui Chenaa5d1492015-08-03 15:50:32 -070021# if no module_dir is provided, we assume project_dir is also a module_dir.
Chiao Chengac0a18e2012-07-12 18:27:23 -070022#
Xiaohui Chenaa5d1492015-08-03 15:50:32 -070023# For example, to generate a project for framework/base, use:
24# intellij-gen.sh framework/base
Chiao Chengac0a18e2012-07-12 18:27:23 -070025#
Xiaohui Chenaa5d1492015-08-03 15:50:32 -070026# The project directory (.idea) will be put in the project_dir. Sharable
27# iml files will be put into each respective module directory.
Chiao Chengac0a18e2012-07-12 18:27:23 -070028#
29# Only tested on linux. Should work for macs but have not tried.
30#
31set -e
32
Chiao Chengac0a18e2012-07-12 18:27:23 -070033progname=`basename $0`
Xiaohui Chenaa5d1492015-08-03 15:50:32 -070034if [ $# -lt 1 ]; then
35 echo "Usage: $progname project_dir <module_dir>..."
36 exit 1
Chiao Chengac0a18e2012-07-12 18:27:23 -070037fi
Xiaohui Chenaa5d1492015-08-03 15:50:32 -070038project_dir=$1
Chiao Chengc8201d52013-06-13 13:41:24 -070039shift
Xiaohui Chenaa5d1492015-08-03 15:50:32 -070040if [ -z $@ ]; then
41 module_dirs=${project_dir}
42else
43 module_dirs=$@
44fi
Chiao Chengc8201d52013-06-13 13:41:24 -070045echo $module_dirs
Chiao Chengd7a603c2012-09-07 13:35:41 -070046script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
47root_dir=$PWD
48if [ ! -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
54fi
55index_file=$root_dir/module-index.txt
56idegenjar=$script_dir/idegen.jar
57if [ ! -e $idegenjar ]; then
58 # See if the jar is in the build directory.
Evan Charltonffa82452014-05-20 10:55:54 -070059 platform="linux"
60 if [ "Darwin" = "$(uname)" ]; then
61 platform="darwin"
62 fi
63 idegenjar="$root_dir/out/host/$platform-x86/framework/idegen.jar"
Chiao Chengd7a603c2012-09-07 13:35:41 -070064fi
65
Chiao Chengac0a18e2012-07-12 18:27:23 -070066if [ ! -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
70fi
71
72echo "Checking for $idegenjar"
73if [ -e "$idegenjar" ]; then
Chiao Chengc8201d52013-06-13 13:41:24 -070074 echo "Generating project files for $module_dirs"
75 cmd="java -cp $idegenjar com.android.idegen.IntellijProject $index_file $project_dir $module_dirs"
Chiao Chengac0a18e2012-07-12 18:27:23 -070076 echo $cmd
77 $cmd
78else
79 echo "Couldn't find idegen.jar. Please run make first."
80fi