blob: 144d8c220b85fc7be87ecf9913dcf766a1a80fa5 [file] [log] [blame]
Damien Martin-Guillerezf9971e62015-04-20 13:51:07 +00001#!/bin/bash
Damien Martin-Guillerezf88f4d82015-09-25 13:56:55 +00002# Copyright 2015 The Bazel Authors. All rights reserved.
Damien Martin-Guillerezf9971e62015-04-20 13:51:07 +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 eclipse files for Bazel
17
18set -eu
19
20progname=$0
21function usage() {
22 echo "Usage: $progname command args..." >&2
23 echo "Possible commands are:" >&2
24 echo " classpath java_paths lib_paths jre output_path" >&2
25 echo " factorypath project_name plugin_paths" >&2
26 echo " project project_name" >&2
27 echo " apt_settings output_path" >&2
28 exit 1
29}
30
31function read_entry() {
32 if [[ -e "${1// /_}" ]]; then
33 cat "$1"
34 else
35 echo "$1"
36 fi
37}
38
39function generate_classpath() {
40 if [[ "$#" != 4 ]]; then
41 usage
42 fi
43
44 java_paths="$(read_entry "$1")"
45 lib_paths="$(read_entry "$2")"
46 jre="$3"
47 output_path="$4"
48
49 cat <<EOF
50<?xml version="1.0" encoding="UTF-8"?>
51<classpath>
52EOF
53
54 for path in $java_paths; do
55 echo " <classpathentry kind=\"src\" path=\"$path\"/>"
56 done
57
58 for path_pair in $lib_paths; do
59 path_arr=(${path_pair//:/ })
60 jar=${path_arr[0]}
61 source_path=${path_arr[1]-}
62 if [ -n "${source_path}" ]; then
63 echo " <classpathentry kind=\"lib\" path=\"${jar}\" sourcepath=\"${source_path}\"/>"
64 else
65 echo " <classpathentry kind=\"lib\" path=\"${jar}\"/>"
66 fi
67 done
68
69 # Write the end of the .classpath file
70 cat <<EOF
71 <classpathentry kind="output" path="${output_path}"/>
72 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/${jre}">
73 <accessrules>
74 <accessrule kind="accessible" pattern="**"/>
75 </accessrules>
76 </classpathentry>
77</classpath>
78EOF
79}
80
81function generate_factorypath() {
82 if [ "$#" != 2 ]; then
83 usage
84 fi
85 project_name="$1"
86 plugin_paths="$(read_entry "$2")"
87
88 cat <<EOF
89<?xml version="1.0" encoding="UTF-8"?>
90<factorypath>
91EOF
92
93 for path in $plugin_paths; do
94 echo " <factorypathentry kind=\"WKSPJAR\" id=\"/${project_name}/${path}\" enabled=\"true\" runInBatchMode=\"false\" />"
95 done
96
97 # Write the end of the .factorypath file
98 cat <<EOF
99</factorypath>
100EOF
101}
102
103function generate_project() {
104 if [ "$#" != 1 ]; then
105 usage
106 fi
107 project_name=$1
108 cat <<EOF
109<?xml version="1.0" encoding="UTF-8"?>
110<projectDescription>
111 <name>${project_name}</name>
112 <comment></comment>
113 <projects>
114 </projects>
115 <buildSpec>
116 <buildCommand>
117 <name>org.eclipse.jdt.core.javabuilder</name>
118 <arguments>
119 </arguments>
120 </buildCommand>
121 </buildSpec>
122 <natures>
123 <nature>org.eclipse.jdt.core.javanature</nature>
124 </natures>
125</projectDescription>
126EOF
127}
128
129function generate_apt_settings() {
130 if [ "$#" != 1 ]; then
131 usage
132 fi
133 output_path=$1
134 cat <<EOF
135eclipse.preferences.version=1
136org.eclipse.jdt.apt.aptEnabled=true
137org.eclipse.jdt.apt.genSrcDir=${output_path}
138org.eclipse.jdt.apt.reconcileEnabled=true
139EOF
140}
141
142command=$1
143shift
144case "${command}" in
145 classpath)
146 generate_classpath "$@"
147 ;;
148 factorypath)
149 generate_factorypath "$@"
150 ;;
151 project)
152 generate_project "$@"
153 ;;
154 apt_settings)
155 generate_apt_settings "$@"
156 ;;
157 *)
158 usage
159 ;;
160esac