Janak Ramakrishnan | ee85e55 | 2015-04-18 20:14:04 +0000 | [diff] [blame] | 1 | #!/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 | |
| 18 | set -o errexit |
| 19 | cd $(dirname "$0") |
| 20 | cd .. |
| 21 | |
| 22 | mkdir -p .idea/ |
| 23 | cp -R scripts/resources/idea/*.* .idea/ |
| 24 | source scripts/get_all_bazel_paths.sh |
| 25 | |
Janak | 025b189 | 2015-07-13 15:15:31 +0000 | [diff] [blame] | 26 | readonly compiler_file=.idea/compiler.xml |
| 27 | cat >$compiler_file <<'EOH' |
| 28 | <?xml version="1.0" encoding="UTF-8"?> |
| 29 | <project version="4"> |
| 30 | <component name="CompilerConfiguration"> |
| 31 | <excludeFromCompile> |
| 32 | EOH |
| 33 | for android_file in $ANDROID_IMPORTING_FILES; do |
| 34 | echo " <file url=\"\$PROJECT_DIR\$/${android_file}\" />" >> $compiler_file |
| 35 | done |
| 36 | cat >>$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> |
| 57 | EOF |
Janak Ramakrishnan | ee85e55 | 2015-04-18 20:14:04 +0000 | [diff] [blame] | 58 | |
| 59 | readonly iml_file=bazel.iml |
| 60 | # The content root output/classes is used for generated sources, specifically |
| 61 | # AutoValue. |
| 62 | cat > $iml_file <<EOH |
| 63 | <?xml version="1.0" encoding="UTF-8"?> |
| 64 | <module type="JAVA_MODULE" version="4"> |
| 65 | <component name="NewModuleRootManager"> |
Janak | 025b189 | 2015-07-13 15:15:31 +0000 | [diff] [blame] | 66 | <output url="file://\$MODULE_DIR\$/out" /> |
Janak Ramakrishnan | ee85e55 | 2015-04-18 20:14:04 +0000 | [diff] [blame] | 67 | <orderEntry type="inheritedJdk" /> |
Janak Ramakrishnan | ee85e55 | 2015-04-18 20:14:04 +0000 | [diff] [blame] | 68 | <content url="file://\$MODULE_DIR\$/src"> |
| 69 | EOH |
| 70 | |
| 71 | for 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 |
| 80 | done |
| 81 | cat >> $iml_file <<'EOF' |
| 82 | </content> |
| 83 | <content url="file://$MODULE_DIR$/third_party/java"> |
| 84 | EOF |
| 85 | |
| 86 | THIRD_PARTY_JAVA_PATHS="$(ls third_party/java | sort -u | sed -e 's%$%/java%')" |
| 87 | |
| 88 | for 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 |
| 90 | done |
| 91 | cat >> $iml_file <<'EOF' |
| 92 | </content> |
| 93 | <orderEntry type="sourceFolder" forTests="false" /> |
| 94 | EOF |
| 95 | |
Janak | 025b189 | 2015-07-13 15:15:31 +0000 | [diff] [blame] | 96 | # Write a module-library entry, usually a jar file but occasionally a directory. |
Janak Ramakrishnan | ee85e55 | 2015-04-18 20:14:04 +0000 | [diff] [blame] | 97 | function write_jar_entry() { |
Janak | 025b189 | 2015-07-13 15:15:31 +0000 | [diff] [blame] | 98 | local root_file=$1 |
Janak Ramakrishnan | ee85e55 | 2015-04-18 20:14:04 +0000 | [diff] [blame] | 99 | if [[ $# > 1 ]]; then |
| 100 | local source_path=$2 |
| 101 | else |
| 102 | local source_path="" |
| 103 | fi |
Janak | 025b189 | 2015-07-13 15:15:31 +0000 | [diff] [blame] | 104 | 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 Ramakrishnan | ee85e55 | 2015-04-18 20:14:04 +0000 | [diff] [blame] | 111 | cat >> $iml_file <<EOF |
| 112 | <orderEntry type="module-library"> |
| 113 | <library name="${basename}"> |
| 114 | <CLASSES> |
Janak | 025b189 | 2015-07-13 15:15:31 +0000 | [diff] [blame] | 115 | <root url="${protocol}://\$MODULE_DIR\$/${root_file}${file_end}/" /> |
Janak Ramakrishnan | ee85e55 | 2015-04-18 20:14:04 +0000 | [diff] [blame] | 116 | </CLASSES> |
| 117 | <JAVADOC /> |
| 118 | EOF |
| 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> |
| 126 | EOF |
| 127 | fi |
Janak | 025b189 | 2015-07-13 15:15:31 +0000 | [diff] [blame] | 128 | if [[ $protocol == "file" ]]; then |
| 129 | cat >> $iml_file <<EOF |
| 130 | <jarDirectory url="file://\$MODULE_DIR\$/${root_file}" recursive="false" /> |
| 131 | EOF |
| 132 | fi |
Janak Ramakrishnan | ee85e55 | 2015-04-18 20:14:04 +0000 | [diff] [blame] | 133 | cat >> $iml_file <<'EOF' |
| 134 | </library> |
| 135 | </orderEntry> |
| 136 | EOF |
| 137 | } |
| 138 | |
| 139 | for jar in ${THIRD_PARTY_JAR_PATHS}; do |
| 140 | write_jar_entry $jar |
| 141 | done |
| 142 | |
Janak Ramakrishnan | ee85e55 | 2015-04-18 20:14:04 +0000 | [diff] [blame] | 143 | for path_pair in ${GENERATED_PATHS}; do |
| 144 | write_jar_entry ${path_pair//:/ } |
| 145 | done |
| 146 | |
Janak | 025b189 | 2015-07-13 15:15:31 +0000 | [diff] [blame] | 147 | write_jar_entry "bazel-bin/src/main/protobuf" |
| 148 | |
Janak Ramakrishnan | ee85e55 | 2015-04-18 20:14:04 +0000 | [diff] [blame] | 149 | cat >> $iml_file <<'EOF' |
| 150 | </component> |
| 151 | </module> |
| 152 | EOF |