blob: 3c4efc56faddf9c0d82996ea26e7afaad38eb30e [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:
Chiao Chengac0a18e2012-07-12 18:27:23 -070019# 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 Chengd7a603c2012-09-07 13:35:41 -070026# 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 Chengac0a18e2012-07-12 18:27:23 -070029#
30# Only tested on linux. Should work for macs but have not tried.
31#
32set -e
33
Chiao Chengac0a18e2012-07-12 18:27:23 -070034progname=`basename $0`
Chiao Chengc8201d52013-06-13 13:41:24 -070035if [ $# -lt 2 ]
Chiao Chengac0a18e2012-07-12 18:27:23 -070036then
Chiao Chengc8201d52013-06-13 13:41:24 -070037 echo "Usage: $progname project_dir module_dir <module_dir>..."
Chiao Chengac0a18e2012-07-12 18:27:23 -070038 exit 1
39fi
Chiao Chengc8201d52013-06-13 13:41:24 -070040project_dir=${PWD}/$1
41shift
42module_dirs=$@
43echo $module_dirs
Chiao Chengd7a603c2012-09-07 13:35:41 -070044script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
45root_dir=$PWD
46if [ ! -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
52fi
53index_file=$root_dir/module-index.txt
54idegenjar=$script_dir/idegen.jar
55if [ ! -e $idegenjar ]; then
56 # See if the jar is in the build directory.
Evan Charltonffa82452014-05-20 10:55:54 -070057 platform="linux"
58 if [ "Darwin" = "$(uname)" ]; then
59 platform="darwin"
60 fi
61 idegenjar="$root_dir/out/host/$platform-x86/framework/idegen.jar"
Chiao Chengd7a603c2012-09-07 13:35:41 -070062fi
63
Chiao Chengac0a18e2012-07-12 18:27:23 -070064if [ ! -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
68fi
69
70echo "Checking for $idegenjar"
71if [ -e "$idegenjar" ]; then
Chiao Chengc8201d52013-06-13 13:41:24 -070072 echo "Generating project files for $module_dirs"
73 cmd="java -cp $idegenjar com.android.idegen.IntellijProject $index_file $project_dir $module_dirs"
Chiao Chengac0a18e2012-07-12 18:27:23 -070074 echo $cmd
75 $cmd
76else
77 echo "Couldn't find idegen.jar. Please run make first."
78fi