blob: c459f7d75b362ebc6546e8c3c445025e280ad2fe [file] [log] [blame]
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -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
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -070017def _impl(ctx):
Ray Milkey5063f5b2018-08-15 16:22:30 -070018 dir = ctx.label.name
Carmelo Casconed33d3b42019-06-18 12:12:36 -070019 outjar = ctx.outputs.jar
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -070020
Ray Milkey5063f5b2018-08-15 16:22:30 -070021 dep_list = []
22 for dep in ctx.files.deps:
23 dep_list += [dep.path]
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -070024
Ray Milkey5063f5b2018-08-15 16:22:30 -070025 src_list = []
26 for src in ctx.files.srcs:
27 src_list += [src.path]
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -070028
Carmelo Casconed33d3b42019-06-18 12:12:36 -070029 java_runtime = ctx.attr._jdk[java_common.JavaRuntimeInfo]
30 jar_exe_path = "%s/bin/jar" % java_runtime.java_home
31
Ray Milkey5063f5b2018-08-15 16:22:30 -070032 cmd = [
33 "mkdir %s" % dir,
34 "javadoc -encoding UTF-8 -quiet -tag onos.rsModel:a:\"onos model\" %s -d %s -cp %s %s" %
35 (JAVA_DOCS, dir, ":".join(dep_list), " ".join(src_list)),
Carmelo Casconed33d3b42019-06-18 12:12:36 -070036 "%s cf %s -C %s ." % (jar_exe_path, outjar.path, dir),
Ray Milkey5063f5b2018-08-15 16:22:30 -070037 ]
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -070038
Ray Milkey5063f5b2018-08-15 16:22:30 -070039 ctx.action(
40 inputs = ctx.files.srcs + ctx.files.deps,
Carmelo Casconed33d3b42019-06-18 12:12:36 -070041 outputs = [outjar],
Ray Milkey5063f5b2018-08-15 16:22:30 -070042 progress_message = "Generating javadocs jar for %s" % ctx.attr.name,
43 command = ";\n".join(cmd),
Carmelo Casconed33d3b42019-06-18 12:12:36 -070044 tools = java_runtime.files,
Ray Milkey5063f5b2018-08-15 16:22:30 -070045 )
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -070046
47javadoc = rule(
48 attrs = {
49 "deps": attr.label_list(allow_files = True),
50 "srcs": attr.label_list(allow_files = True),
Carmelo Casconed33d3b42019-06-18 12:12:36 -070051 "_jdk": attr.label(
52 default = Label("@bazel_tools//tools/jdk:current_java_runtime"),
53 providers = [java_common.JavaRuntimeInfo],
54 ),
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -070055 },
56 implementation = _impl,
Ray Milkey5063f5b2018-08-15 16:22:30 -070057 outputs = {"jar": "%{name}.jar"},
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -070058)