blob: 424b0ba97f2d1347e81c04780c153d98743dae89 [file] [log] [blame]
Janak Ramakrishnanee85e552015-04-18 20:14:04 +00001#!/bin/bash
Damien Martin-Guillerezf88f4d82015-09-25 13:56:55 +00002# Copyright 2015 The Bazel Authors. All rights reserved.
Janak Ramakrishnanee85e552015-04-18 20:14:04 +00003#
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">
Carmi Grushkod30ae4d2015-11-19 14:07:21 +000052 <processor name="com.google.auto.value.processor.AutoValueProcessor" />
Janak025b1892015-07-13 15:15:31 +000053 <processorPath useClasspath="true" />
54 </profile>
55 </annotationProcessing>
56 </component>
57</project>
58EOF
Janak Ramakrishnanee85e552015-04-18 20:14:04 +000059
60readonly iml_file=bazel.iml
Carmi Grushkod30ae4d2015-11-19 14:07:21 +000061# Code generated by AutoValue is put in $MODULE_DIR/out/generated; adding it as a Source Root
62# allows IntelliJ to find it while editing. (that is, generated classes won't be marked as unknown.)
Janak Ramakrishnanee85e552015-04-18 20:14:04 +000063cat > $iml_file <<EOH
64<?xml version="1.0" encoding="UTF-8"?>
65<module type="JAVA_MODULE" version="4">
66 <component name="NewModuleRootManager">
Janak025b1892015-07-13 15:15:31 +000067 <output url="file://\$MODULE_DIR\$/out" />
Carmi Grushkod30ae4d2015-11-19 14:07:21 +000068 <content url="file://\$MODULE_DIR$/out/generated">
69 <sourceFolder url="file://\$MODULE_DIR$/out/generated" isTestSource="false" generated="true" />
70 </content>
Janak Ramakrishnanee85e552015-04-18 20:14:04 +000071 <orderEntry type="inheritedJdk" />
Janak Ramakrishnanee85e552015-04-18 20:14:04 +000072 <content url="file://\$MODULE_DIR\$/src">
73EOH
74
75for source in ${JAVA_PATHS}; do
76 if [[ $source == *"javatests" ]]; then
77 is_test_source="true"
78 elif [[ $source == *"test/java" ]]; then
79 is_test_source="true"
80 else
81 is_test_source="false"
82 fi
83 echo ' <sourceFolder url="file://$MODULE_DIR$/'"${source}\" isTestSource=\"${is_test_source}\" />" >> $iml_file
84done
85cat >> $iml_file <<'EOF'
86 </content>
87 <content url="file://$MODULE_DIR$/third_party/java">
88EOF
89
90THIRD_PARTY_JAVA_PATHS="$(ls third_party/java | sort -u | sed -e 's%$%/java%')"
91
92for third_party_java_path in ${THIRD_PARTY_JAVA_PATHS}; do
93 echo ' <sourceFolder url="file://$MODULE_DIR$/third_party/java/'${third_party_java_path}'" isTestSource="false" />' >> $iml_file
94done
95cat >> $iml_file <<'EOF'
96 </content>
97 <orderEntry type="sourceFolder" forTests="false" />
98EOF
99
Janak025b1892015-07-13 15:15:31 +0000100# Write a module-library entry, usually a jar file but occasionally a directory.
Janak Ramakrishnanee85e552015-04-18 20:14:04 +0000101function write_jar_entry() {
Janak025b1892015-07-13 15:15:31 +0000102 local root_file=$1
Janak Ramakrishnanee85e552015-04-18 20:14:04 +0000103 if [[ $# > 1 ]]; then
104 local source_path=$2
105 else
106 local source_path=""
107 fi
Janak025b1892015-07-13 15:15:31 +0000108 local protocol="file"
109 local file_end=""
110 if [[ $root_file == *.jar ]]; then
111 protocol="jar"
112 file_end="!"
113 fi
114 local readonly basename=${root_file##*/}
Janak Ramakrishnanee85e552015-04-18 20:14:04 +0000115 cat >> $iml_file <<EOF
116 <orderEntry type="module-library">
117 <library name="${basename}">
118 <CLASSES>
Janak025b1892015-07-13 15:15:31 +0000119 <root url="${protocol}://\$MODULE_DIR\$/${root_file}${file_end}/" />
Janak Ramakrishnanee85e552015-04-18 20:14:04 +0000120 </CLASSES>
121 <JAVADOC />
122EOF
123 if [[ -z "${source_path}" ]]; then
124 echo " <SOURCES />" >> $iml_file
125 else
126 cat >> $iml_file <<EOF
127 <SOURCES>
128 <root url="jar:/\$MODULE_DIR\$/${source_path}!/" />
129 </SOURCES>
130EOF
131 fi
Janak025b1892015-07-13 15:15:31 +0000132 if [[ $protocol == "file" ]]; then
133 cat >> $iml_file <<EOF
134 <jarDirectory url="file://\$MODULE_DIR\$/${root_file}" recursive="false" />
135EOF
136 fi
Janak Ramakrishnanee85e552015-04-18 20:14:04 +0000137 cat >> $iml_file <<'EOF'
138 </library>
139 </orderEntry>
140EOF
141}
142
143for jar in ${THIRD_PARTY_JAR_PATHS}; do
144 write_jar_entry $jar
145done
146
Janak Ramakrishnanee85e552015-04-18 20:14:04 +0000147for path_pair in ${GENERATED_PATHS}; do
148 write_jar_entry ${path_pair//:/ }
149done
150
Janak025b1892015-07-13 15:15:31 +0000151write_jar_entry "bazel-bin/src/main/protobuf"
152
Janak Ramakrishnanee85e552015-04-18 20:14:04 +0000153cat >> $iml_file <<'EOF'
154 </component>
155</module>
156EOF
Carmi Grushkod30ae4d2015-11-19 14:07:21 +0000157
158echo
159echo Done. Project file: $iml_file