blob: 7c706d0bac7754af85e536b19b062b763e4689f1 [file] [log] [blame]
Thomas Vachuskac3226e92018-07-25 12:00:57 -07001# Copyright 2015 The Bazel Authors. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Carmelo Casconed33d3b42019-06-18 12:12:36 -070015JAVA_DOCS = "-link https://docs.oracle.com/javase/11/docs/api/"
Thomas Vachuskac3226e92018-07-25 12:00:57 -070016
17def dump(obj):
Ray Milkey5063f5b2018-08-15 16:22:30 -070018 print(dir(obj))
Thomas Vachuskac3226e92018-07-25 12:00:57 -070019 for attr in dir(obj):
20 print("obj.%s = %r" % (attr, getattr(obj, attr)))
21
22def _impl(ctx):
23 dir = ctx.label.name
Carmelo Casconed33d3b42019-06-18 12:12:36 -070024 outjar = ctx.outputs.jar
Thomas Vachuskac3226e92018-07-25 12:00:57 -070025
26 classpath = ""
27 for dep in ctx.files.deps:
28 classpath += ":" + dep.path
29
30 src_list = ""
31 for src in ctx.files.srcs:
32 if src.path.endswith(".jar"):
33 src_list += " " + src.path
34
35 group_list = ""
36 for group in ctx.attr.groups:
37 packages = ""
38 for p in ctx.attr.groups[group]:
39 packages += ":" + p
40 group_list += " -group \"%s\" %s" % (group, packages.replace(":", "", 1))
41
Carmelo Casconed33d3b42019-06-18 12:12:36 -070042 java_runtime = ctx.attr._jdk[java_common.JavaRuntimeInfo]
43 jar_exe_path = "%s/bin/jar" % java_runtime.java_home
44 javadoc_exe_path = "%s/bin/javadoc" % java_runtime.java_home
45
Thomas Vachuskac3226e92018-07-25 12:00:57 -070046 cmd = [
47 "mkdir src; cd src",
Carmelo Casconed33d3b42019-06-18 12:12:36 -070048 "for s in %s; do ../%s xf ../$s; done" % (src_list, jar_exe_path),
Thomas Vachuskac3226e92018-07-25 12:00:57 -070049 "rm -f META-INF/MANIFEST.MF",
50 "cd ..",
51 "cp -r docs/src/main/javadoc/* .",
52 "ls -lR doc-files overview.html",
53 ]
54
55 if ctx.attr.internal:
56 cmd += ["find src -type f | egrep -v 'src/(OSGI|WEB)-INF' >> FILES"]
57 else:
58 cmd += ["find src -type f | egrep -v 'src/(OSGI|WEB)-INF' | egrep -v '/(impl|internal)/' >> FILES"]
59
60 cmd += [
Carmelo Casconed33d3b42019-06-18 12:12:36 -070061 "%s -encoding UTF-8 -overview overview.html -doctitle '%s' -windowtitle '%s' %s -d apidocs -classpath %s -sourcepath src %s @FILES" %
62 (javadoc_exe_path, ctx.attr.title, ctx.attr.title, group_list, classpath.replace(":", "", 1), JAVA_DOCS),
Thomas Vachuskac3226e92018-07-25 12:00:57 -070063 "cp -r doc-files apidocs/doc-files",
Carmelo Casconed33d3b42019-06-18 12:12:36 -070064 "%s cf %s apidocs" % (jar_exe_path, outjar.path),
Thomas Vachuskac3226e92018-07-25 12:00:57 -070065 ]
66
Carmelo Casconed33d3b42019-06-18 12:12:36 -070067 ctx.actions.run_shell(
Thomas Vachuskac3226e92018-07-25 12:00:57 -070068 inputs = ctx.files.srcs + ctx.files.deps,
Carmelo Casconed33d3b42019-06-18 12:12:36 -070069 outputs = [outjar],
Ray Milkey5063f5b2018-08-15 16:22:30 -070070 progress_message = "Generating javadocs jar for %s" % ctx.attr.name,
71 command = ";\n".join(cmd),
Carmelo Casconed33d3b42019-06-18 12:12:36 -070072 tools = java_runtime.files,
Thomas Vachuskac3226e92018-07-25 12:00:57 -070073 )
74
75project_javadoc = rule(
76 attrs = {
77 "title": attr.string(),
78 "overview": attr.string(default = "src/main/javadoc/overview.html"),
79 "groups": attr.string_list_dict(),
80 "deps": attr.label_list(allow_files = True),
81 "srcs": attr.label_list(allow_files = True),
82 "internal": attr.bool(default = False),
Carmelo Casconed33d3b42019-06-18 12:12:36 -070083 "_jdk": attr.label(
84 default = Label("@bazel_tools//tools/jdk:current_java_runtime"),
85 providers = [java_common.JavaRuntimeInfo],
86 ),
Thomas Vachuskac3226e92018-07-25 12:00:57 -070087 },
88 implementation = _impl,
Ray Milkey5063f5b2018-08-15 16:22:30 -070089 outputs = {"jar": "%{name}.jar"},
Thomas Vachuskac3226e92018-07-25 12:00:57 -070090)