blob: 171b846ef3a939ef0a0d0b02d17cdc590899571a [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
Ray Milkey5063f5b2018-08-15 16:22:30 -070015JAVA_DOCS = "-link https://docs.oracle.com/javase/8/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
24 jar = ctx.outputs.jar
25
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
42 cmd = [
43 "mkdir src; cd src",
44 "for s in %s; do jar xf ../$s; done" % src_list,
45 "rm -f META-INF/MANIFEST.MF",
46 "cd ..",
47 "cp -r docs/src/main/javadoc/* .",
48 "ls -lR doc-files overview.html",
49 ]
50
51 if ctx.attr.internal:
52 cmd += ["find src -type f | egrep -v 'src/(OSGI|WEB)-INF' >> FILES"]
53 else:
54 cmd += ["find src -type f | egrep -v 'src/(OSGI|WEB)-INF' | egrep -v '/(impl|internal)/' >> FILES"]
55
56 cmd += [
Ray Milkey5063f5b2018-08-15 16:22:30 -070057 "javadoc -encoding UTF-8 -overview overview.html -doctitle '%s' -windowtitle '%s' %s -d apidocs -classpath %s -sourcepath src %s @FILES" %
58 (ctx.attr.title, ctx.attr.title, group_list, classpath.replace(":", "", 1), JAVA_DOCS),
Thomas Vachuskac3226e92018-07-25 12:00:57 -070059 "cp -r doc-files apidocs/doc-files",
60 "jar cf %s apidocs" % jar.path,
61 ]
62
63 ctx.action(
64 inputs = ctx.files.srcs + ctx.files.deps,
65 outputs = [jar],
Ray Milkey5063f5b2018-08-15 16:22:30 -070066 progress_message = "Generating javadocs jar for %s" % ctx.attr.name,
67 command = ";\n".join(cmd),
Thomas Vachuskac3226e92018-07-25 12:00:57 -070068 )
69
70project_javadoc = rule(
71 attrs = {
72 "title": attr.string(),
73 "overview": attr.string(default = "src/main/javadoc/overview.html"),
74 "groups": attr.string_list_dict(),
75 "deps": attr.label_list(allow_files = True),
76 "srcs": attr.label_list(allow_files = True),
77 "internal": attr.bool(default = False),
78 },
79 implementation = _impl,
Ray Milkey5063f5b2018-08-15 16:22:30 -070080 outputs = {"jar": "%{name}.jar"},
Thomas Vachuskac3226e92018-07-25 12:00:57 -070081)