summaryrefslogtreecommitdiffstats
path: root/tools/idegen/intellij-gen.sh
blob: 462e232fa1d85bbe170ee432434b2c5ee7c2df7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
#
# Copyright (C) 2012 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# To use, run the following command from either your repo root or
# development/tools/idegen:
#   intellij-gen.sh project_dir <module_dir>...
#
# if no module_dir is provided, we assume project_dir is also a module_dir.
#
# For example, to generate a project for framework/base, use:
#   intellij-gen.sh framework/base
#
# The project directory (.idea) will be put in the project_dir.  Sharable
# iml files will be put into each respective module directory.
#
# Only tested on linux.  Should work for macs but have not tried.
#
set -e

progname=`basename $0`
if [ $# -lt 1 ]; then
  echo "Usage: $progname project_dir <module_dir>..."
  exit 1
fi
project_dir=$1
shift
if [ -z $@ ]; then
  module_dirs=${project_dir}
else
  module_dirs=$@
fi
echo $module_dirs
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
root_dir=$PWD
if [ ! -e $root_dir/.repo ]; then
  root_dir=$PWD/../../..
  if [ ! -e $root_dir/.repo ]; then
    echo "Repo root not found. Run this script from your repo root or the idegen directory."
    exit 1
  fi
fi
index_file=$root_dir/module-index.txt
idegenjar=$script_dir/idegen.jar
if [ ! -e $idegenjar ]; then
  # See if the jar is in the build directory.
  platform="linux"
  if [ "Darwin" = "$(uname)" ]; then
    platform="darwin"
  fi
  idegenjar="$root_dir/out/host/$platform-x86/framework/idegen.jar"
fi

if [ ! -e "$index_file" ]; then
  echo "Module index file missing; generating this is only done the first time."
  echo "If any dependencies change, you should generate a new index file by running index-gen.sh."
  $script_dir/index-gen.sh
fi

echo "Checking for $idegenjar"
if [ -e "$idegenjar" ]; then
  echo "Generating project files for $module_dirs"
  cmd="java -cp $idegenjar com.android.idegen.IntellijProject $index_file $project_dir $module_dirs"
  echo $cmd
  $cmd
else
  echo "Couldn't find idegen.jar. Please run make first."
fi