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#
17# To use, run the following command from either your repo root or
18# development/tools/idegen:
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#
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.
29#
30# Only tested on linux.  Should work for macs but have not tried.
31#
32set -e
33
34progname=`basename $0`
35if [ $# -lt 2 ]
36then
37    echo "Usage: $progname project_dir module_dir <module_dir>..."
38    exit 1
39fi
40project_dir=${PWD}/$1
41shift
42module_dirs=$@
43echo $module_dirs
44script_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.
57  platform="linux"
58  if [ "Darwin" = "$(uname)" ]; then
59    platform="darwin"
60  fi
61  idegenjar="$root_dir/out/host/$platform-x86/framework/idegen.jar"
62fi
63
64if [ ! -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
72  echo "Generating project files for $module_dirs"
73  cmd="java -cp $idegenjar com.android.idegen.IntellijProject $index_file $project_dir $module_dirs"
74  echo $cmd
75  $cmd
76else
77  echo "Couldn't find idegen.jar. Please run make first."
78fi
79