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 project_dir <module_dir>...
20#
21# if no module_dir is provided, we assume project_dir is also a module_dir.
22#
23# For example, to generate a project for framework/base, use:
24#   intellij-gen.sh framework/base
25#
26# The project directory (.idea) will be put in the project_dir.  Sharable
27# iml files will be put into each respective module directory.
28#
29# Only tested on linux.  Should work for macs but have not tried.
30#
31set -e
32
33progname=`basename $0`
34if [ $# -lt 1 ]; then
35  echo "Usage: $progname project_dir <module_dir>..."
36  exit 1
37fi
38project_dir=$1
39shift
40if [ -z $@ ]; then
41  module_dirs=${project_dir}
42else
43  module_dirs=$@
44fi
45echo $module_dirs
46script_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.
59  platform="linux"
60  if [ "Darwin" = "$(uname)" ]; then
61    platform="darwin"
62  fi
63  idegenjar="$root_dir/out/host/$platform-x86/framework/idegen.jar"
64fi
65
66if [ ! -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
74  echo "Generating project files for $module_dirs"
75  cmd="java -cp $idegenjar com.android.idegen.IntellijProject $index_file $project_dir $module_dirs"
76  echo $cmd
77  $cmd
78else
79  echo "Couldn't find idegen.jar. Please run make first."
80fi
81