Skip to content

Commit 3b5e583

Browse files
committed
Add copy of javadoc script for local testing
1 parent af370fe commit 3b5e583

File tree

2 files changed

+102
-2
lines changed

2 files changed

+102
-2
lines changed

tools/build_java_api_docs.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from tensorflow_docs.api_generator import gen_java
3030

3131
FLAGS = flags.FLAGS
32+
NDARRAY_VERSION = 'v1.0.0'
3233

3334
# These flags are required by infrastructure, not all of them are used.
3435
flags.DEFINE_string('output_dir', '/tmp/java_api/',
@@ -58,7 +59,7 @@ def checkout_ndarray():
5859
else:
5960
local_repo = Repo(local_repo_path)
6061
local_repo.remotes['origin'].fetch()
61-
local_repo.git.checkout('v1.0.0')
62+
local_repo.git.checkout(NDARRAY_VERSION)
6263

6364

6465
def overlay(from_root, to_root):
@@ -90,7 +91,8 @@ def main(unused_argv):
9091
source_path=merged_source / 'java',
9192
output_dir=pathlib.Path(FLAGS.output_dir),
9293
site_path=pathlib.Path(FLAGS.site_path),
93-
script_path=pathlib.Path(REPO_ROOT/'tools/run-javadoc-for-tf.sh'), # FIXME use default one??
94+
# Uncomment for local testing:
95+
# script_path=pathlib.Path(REPO_ROOT/'tools/run-javadoc-for-tf-local.sh'),
9496
)
9597

9698

tools/run-javadoc-for-tf-local.sh

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/bin/bash
2+
set -ex
3+
4+
export JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home # Or change to any JDK 11 home path
5+
6+
# https://android.googlesource.com/platform/external/doclava/
7+
# There's a debian package:
8+
# https://packages.debian.org/unstable/doclava-aosp
9+
# Install with:
10+
#
11+
# $ sudo apt install doclava-aosp #v 6.0.1+r55-1+build1
12+
#
13+
# https://unix.stackexchange.com/questions/594841/how-do-i-assign-a-value-to-a-bash-variable-iff-that-variable-is-null-unassigned
14+
DOCLAVA_JAR=${DOCLAVA_JAR:-'lib/doclava.jar'} # Build lib locally
15+
16+
# Install java clear silver templates with:
17+
#
18+
# $ sudo apt install libjsilver-aosp-java #v 6.0.1+r55-1+build1
19+
JSILVER_JAR=${JSILVER_JAR:-'lib/jsilver.jar'} # Build lib locally
20+
21+
22+
######### DELETE OUTPUT_DIR #################
23+
24+
# Empty the output directory in case a class has been deleted
25+
rm -rf "${OUTPUT_DIR:?}"/*
26+
############ RUN DOCLAVA ###################
27+
28+
# $FEDERATED_DOCS is a space-separated string of url,file pairs.
29+
read -a api_pairs <<< "${FEDERATED_DOCS}"
30+
FEDERATED_PARAMS=""
31+
for i in "${!api_pairs[@]}"; do
32+
api_pair_str="${api_pairs[$i]}" # "url,api.txt"
33+
read -a api_pair <<< "${api_pair_str//,/ }"
34+
# Using the index as the API "name", build the federation params. Note that
35+
# using 0 as an API name will evaluate to false and cause rendering bugs,
36+
# so we preface with "api_".
37+
FEDERATED_PARAMS+=" -federate api_${i} ${api_pair[0]}"
38+
FEDERATED_PARAMS+=" -federationapi api_${i} ${api_pair[1]}"
39+
done
40+
41+
# To install javadoc, for example, use
42+
#
43+
# sudo apt install openjdk-11-jdk
44+
#
45+
# doclava doesn't work with openjdk-13
46+
# ```
47+
# javadoc: error - Class com.google.doclava.Doclava is not a valid doclet.
48+
# Note: As of JDK 13, the com.sun.javadoc API is no longer supported.
49+
# ```
50+
# It's used here: https://android.googlesource.com/platform/external/doclava/+/refs/heads/master/src/com/google/doclava/Doclava.java
51+
52+
# Each package in $PACKAGE needs to prefaced with -subpackages, so do that.
53+
SUBPACKAGES=""
54+
read -r -a packages <<< "${PACKAGE}"
55+
for pkg in "${packages[@]}"; do
56+
SUBPACKAGES+=" -subpackages ${pkg}"
57+
done
58+
( # Capture the return code. it may be non-zero for minor errors.
59+
javadoc \
60+
-sourcepath "${SOURCE_PATH}" \
61+
-docletpath "${DOCLAVA_JAR}:${JSILVER_JAR}" \
62+
-doclet com.google.doclava.Doclava \
63+
-d "${OUTPUT_DIR}" \
64+
-toroot "${SITE_PATH}"/ \
65+
-yaml _toc.yaml \
66+
-templatedir "${TEMPLATES}" \
67+
-public \
68+
-devsite \
69+
${FEDERATED_PARAMS} \
70+
${SUBPACKAGES}
71+
)
72+
73+
74+
mv "${OUTPUT_DIR}"/reference/* "${OUTPUT_DIR}"
75+
76+
###################################################################
77+
################### START OF POST-PROCESSING ######################
78+
###################################################################
79+
rm "${OUTPUT_DIR}/navtree_data.js" || true
80+
rm "${OUTPUT_DIR}/hierarchy.html" || true
81+
82+
find ${OUTPUT_DIR} -name "*.html" | xargs sed -i '' "s|${SITE_PATH}/reference|${SITE_PATH}|g"
83+
find ${OUTPUT_DIR} -name "*.yaml" | xargs sed -i '' "s|${SITE_PATH}/reference|${SITE_PATH}|g"
84+
find ${OUTPUT_DIR} -name "*.html" | xargs sed -i '' "s|a href=\"reference/org/tensorflow|a href=\"${SITE_PATH}/org/tensorflow|g"
85+
find ${OUTPUT_DIR} -name "*.html" | xargs sed -i '' "s|a href=\"reference/com/google|a href=\"${SITE_PATH}/com/google|g"
86+
87+
JAVA_LANG=https://docs.oracle.com/javase/8/docs/api
88+
find ${OUTPUT_DIR} -name "*.html" | xargs sed -i '' "s|a href=\"reference/java/lang|a href=\"${JAVA_LANG}/java/lang|g"
89+
90+
find ${OUTPUT_DIR} -name "*.html" | xargs sed -i '' 's|<pre><code>|<pre class="prettyprint"><code>|g'
91+
92+
rm ${OUTPUT_DIR}/timestamp.js || true
93+
rm ${OUTPUT_DIR}/lists.js || true
94+
rm ${OUTPUT_DIR}/index.html || true
95+
96+
cp ${TEMPLATES}/screen.css ${OUTPUT_DIR}/
97+
98+

0 commit comments

Comments
 (0)