blob: dc0949b5921322b5d916a77a4c56b03af9f9c9f8 [file] [log] [blame]
Janak Ramakrishnanee85e552015-04-18 20:14:04 +00001#!/bin/bash
2# Copyright 2015 Google Inc. All rights reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16# Generates an IntelliJ project in Bazel.
17
18set -o errexit
19cd $(dirname "$0")
20cd ..
21
22mkdir -p .idea/
23cp -R scripts/resources/idea/*.* .idea/
24source scripts/get_all_bazel_paths.sh
25
Janak025b1892015-07-13 15:15:31 +000026readonly compiler_file=.idea/compiler.xml
27cat >$compiler_file <<'EOH'
28<?xml version="1.0" encoding="UTF-8"?>
29<project version="4">
30 <component name="CompilerConfiguration">
31 <excludeFromCompile>
32EOH
33for android_file in $ANDROID_IMPORTING_FILES; do
34 echo " <file url=\"\$PROJECT_DIR\$/${android_file}\" />" >> $compiler_file
35done
36cat >>$compiler_file <<'EOF'
37 </excludeFromCompile>
38 <resourceExtensions />
39 <wildcardResourcePatterns>
40 <entry name="!?*.java" />
41 <entry name="!?*.form" />
42 <entry name="!?*.class" />
43 <entry name="!?*.groovy" />
44 <entry name="!?*.scala" />
45 <entry name="!?*.flex" />
46 <entry name="!?*.kt" />
47 <entry name="!?*.clj" />
48 <entry name="!?*.aj" />
49 </wildcardResourcePatterns>
50 <annotationProcessing>
51 <profile default="true" name="Default" enabled="true">
52 <processorPath useClasspath="true" />
53 </profile>
54 </annotationProcessing>
55 </component>
56</project>
57EOF
Janak Ramakrishnanee85e552015-04-18 20:14:04 +000058
59readonly iml_file=bazel.iml
60# The content root output/classes is used for generated sources, specifically
61# AutoValue.
62cat > $iml_file <<EOH
63<?xml version="1.0" encoding="UTF-8"?>
64<module type="JAVA_MODULE" version="4">
65 <component name="NewModuleRootManager">
Janak025b1892015-07-13 15:15:31 +000066 <output url="file://\$MODULE_DIR\$/out" />
Janak Ramakrishnanee85e552015-04-18 20:14:04 +000067 <orderEntry type="inheritedJdk" />
Janak Ramakrishnanee85e552015-04-18 20:14:04 +000068 <content url="file://\$MODULE_DIR\$/src">
69EOH
70
71for source in ${JAVA_PATHS}; do
72 if [[ $source == *"javatests" ]]; then
73 is_test_source="true"
74 elif [[ $source == *"test/java" ]]; then
75 is_test_source="true"
76 else
77 is_test_source="false"
78 fi
79 echo ' <sourceFolder url="file://$MODULE_DIR$/'"${source}\" isTestSource=\"${is_test_source}\" />" >> $iml_file
80done
81cat >> $iml_file <<'EOF'
82 </content>
83 <content url="file://$MODULE_DIR$/third_party/java">
84EOF
85
86THIRD_PARTY_JAVA_PATHS="$(ls third_party/java | sort -u | sed -e 's%$%/java%')"
87
88for third_party_java_path in ${THIRD_PARTY_JAVA_PATHS}; do
89 echo ' <sourceFolder url="file://$MODULE_DIR$/third_party/java/'${third_party_java_path}'" isTestSource="false" />' >> $iml_file
90done
91cat >> $iml_file <<'EOF'
92 </content>
93 <orderEntry type="sourceFolder" forTests="false" />
94EOF
95
Janak025b1892015-07-13 15:15:31 +000096# Write a module-library entry, usually a jar file but occasionally a directory.
Janak Ramakrishnanee85e552015-04-18 20:14:04 +000097function write_jar_entry() {
Janak025b1892015-07-13 15:15:31 +000098 local root_file=$1
Janak Ramakrishnanee85e552015-04-18 20:14:04 +000099 if [[ $# > 1 ]]; then
100 local source_path=$2
101 else
102 local source_path=""
103 fi
Janak025b1892015-07-13 15:15:31 +0000104 local protocol="file"
105 local file_end=""
106 if [[ $root_file == *.jar ]]; then
107 protocol="jar"
108 file_end="!"
109 fi
110 local readonly basename=${root_file##*/}
Janak Ramakrishnanee85e552015-04-18 20:14:04 +0000111 cat >> $iml_file <<EOF
112 <orderEntry type="module-library">
113 <library name="${basename}">
114 <CLASSES>
Janak025b1892015-07-13 15:15:31 +0000115 <root url="${protocol}://\$MODULE_DIR\$/${root_file}${file_end}/" />
Janak Ramakrishnanee85e552015-04-18 20:14:04 +0000116 </CLASSES>
117 <JAVADOC />
118EOF
119 if [[ -z "${source_path}" ]]; then
120 echo " <SOURCES />" >> $iml_file
121 else
122 cat >> $iml_file <<EOF
123 <SOURCES>
124 <root url="jar:/\$MODULE_DIR\$/${source_path}!/" />
125 </SOURCES>
126EOF
127 fi
Janak025b1892015-07-13 15:15:31 +0000128 if [[ $protocol == "file" ]]; then
129 cat >> $iml_file <<EOF
130 <jarDirectory url="file://\$MODULE_DIR\$/${root_file}" recursive="false" />
131EOF
132 fi
Janak Ramakrishnanee85e552015-04-18 20:14:04 +0000133 cat >> $iml_file <<'EOF'
134 </library>
135 </orderEntry>
136EOF
137}
138
139for jar in ${THIRD_PARTY_JAR_PATHS}; do
140 write_jar_entry $jar
141done
142
Janak Ramakrishnanee85e552015-04-18 20:14:04 +0000143for path_pair in ${GENERATED_PATHS}; do
144 write_jar_entry ${path_pair//:/ }
145done
146
Janak025b1892015-07-13 15:15:31 +0000147write_jar_entry "bazel-bin/src/main/protobuf"
148
Janak Ramakrishnanee85e552015-04-18 20:14:04 +0000149cat >> $iml_file <<'EOF'
150 </component>
151</module>
152EOF