1313# See the License for the specific language governing permissions and
1414# limitations under the License.
1515# ==============================================================================
16+
17+ ######################################################################################################################
18+ # IMPORTANT: Files in legacy_tools are no longer used to generate the TensorFlow-Java API docs as there are unfixed issues
19+ # when using DocLava outside of the Google environment. We are keeping these for reference in case they are useful later.
20+ ######################################################################################################################
21+
22+
1623"""Generate TensorFlow Java reference docs for TensorFlow.org."""
1724from __future__ import absolute_import
1825from __future__ import division
2128import pathlib
2229import shutil
2330import tempfile
31+ import io
32+ import requests
33+ import zipfile
2434from git import Repo
2535
2636from absl import app
2939from tensorflow_docs .api_generator import gen_java
3040
3141FLAGS = flags .FLAGS
42+
3243NDARRAY_VERSION = 'v1.0.0'
44+ JAVACPP_VERSION = '1.5.11'
45+ PROTOBUF_VERSION = 'v3.21.9'
46+
47+ # __file__ is the path to this file
48+ TOOLS_DIR = pathlib .Path (__file__ ).resolve ().parent
49+ DOCS_DIR = TOOLS_DIR .parent
50+ REPO_ROOT = DOCS_DIR .parent
51+ DOC_OUTPUT_DIR = DOCS_DIR .joinpath ("output" )
52+
53+ SECTION_LABELS = {
54+ 'org.tensorflow' : 'Core' ,
55+ 'org.tensorflow.ndarray' : 'NdArray' ,
56+ 'org.tensorflow.framework' : 'Framework' ,
57+ }
3358
3459# These flags are required by infrastructure, not all of them are used.
35- flags .DEFINE_string ('output_dir' , '/tmp/java_api/' ,
60+ flags .DEFINE_string ('output_dir' , f" { DOC_OUTPUT_DIR } " ,
3661 ("Use this branch as the root version and don't"
3762 ' create in version directory' ))
3863
39- flags .DEFINE_string ('site_path' , 'java/ api_docs/java ' ,
64+ flags .DEFINE_string ('site_path' , 'api_docs/' ,
4065 'Path prefix in the _toc.yaml' )
4166
4267flags .DEFINE_string ('code_url_prefix' , None ,
4671 'search_hints' , True ,
4772 '[UNUSED] Include metadata search hints in the generated files' )
4873
49- # __file__ is the path to this file
50- TOOLS_DIR = pathlib .Path (__file__ ).resolve ().parent
51- REPO_ROOT = TOOLS_DIR .parent
52-
5374
54- def checkout_ndarray ():
55- repo_url = 'https://github.com/tensorflow/java-ndarray'
56- local_repo_path = REPO_ROOT / 'ndarray'
75+ def checkout_repo (repo_url : str , target_dir_name : str , version : str ):
76+ local_repo_path = f"{ REPO_ROOT } /{ target_dir_name } "
5777 if not pathlib .Path (local_repo_path ).exists ():
5878 local_repo = Repo .clone_from (repo_url , local_repo_path )
5979 else :
6080 local_repo = Repo (local_repo_path )
6181 local_repo .remotes ['origin' ].fetch ()
62- local_repo .git .checkout (NDARRAY_VERSION )
82+ local_repo .git .checkout (version )
6383
6484
6585def overlay (from_root , to_root ):
@@ -74,25 +94,36 @@ def overlay(from_root, to_root):
7494
7595
7696def main (unused_argv ):
77- checkout_ndarray ()
97+ checkout_repo ('https://github.com/tensorflow/java-ndarray' , 'ndarray' , NDARRAY_VERSION )
98+ checkout_repo ('https://github.com/bytedeco/javacpp' , 'javacpp' , JAVACPP_VERSION )
99+ response = requests .get ('https://repo1.maven.org/maven2/com/google/protobuf/protobuf-java/3.21.9/protobuf-java-3.21.9-sources.jar' )
100+ with zipfile .ZipFile (io .BytesIO (response .content )) as z :
101+ z .extractall (f"{ REPO_ROOT } /protobuf" )
102+ response = requests .get ('https://repo1.maven.org/maven2/org/osgi/osgi.annotation/8.1.0/osgi.annotation-8.1.0-sources.jar' )
103+ with zipfile .ZipFile (io .BytesIO (response .content )) as z :
104+ z .extractall (f"{ REPO_ROOT } /osgi" )
105+
78106 merged_source = pathlib .Path (tempfile .mkdtemp ())
79107 (merged_source / 'java/org' ).mkdir (parents = True )
80-
81108 shutil .copytree (REPO_ROOT / 'tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/' , merged_source / 'java/org/tensorflow' )
82109 overlay (REPO_ROOT / 'tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow' , merged_source / 'java/org/tensorflow' )
83- shutil . copytree (REPO_ROOT / 'tensorflow-core/tensorflow-core-native /src/gen/java /org/tensorflow/proto ' , merged_source / 'java/org/tensorflow/proto ' )
84- shutil . copytree (REPO_ROOT / 'tensorflow-core/tensorflow-core-native/src/main /java/org/tensorflow/exceptions ' , merged_source / 'java/org/tensorflow/exceptions ' )
85- shutil . copytree (REPO_ROOT / 'tensorflow-core/tensorflow-core-native/src/gen /java/org/tensorflow/internal/c_api ' , merged_source / 'java/org/tensorflow/internal/c_api ' )
110+ overlay (REPO_ROOT / 'tensorflow-core/tensorflow-core-api /src/gen/annotations /org/tensorflow' , merged_source / 'java/org/tensorflow' )
111+ overlay (REPO_ROOT / 'tensorflow-core/tensorflow-core-native/src/gen /java/org/tensorflow/' , merged_source / 'java/org/tensorflow/' )
112+ overlay (REPO_ROOT / 'tensorflow-core/tensorflow-core-native/src/main /java/org/tensorflow/' , merged_source / 'java/org/tensorflow/' )
86113 shutil .copytree (REPO_ROOT / 'tensorflow-framework/src/main/java/org/tensorflow/framework' , merged_source / 'java/org/tensorflow/framework' )
87114 shutil .copytree (REPO_ROOT / 'ndarray/ndarray/src/main/java/org/tensorflow/ndarray' , merged_source / 'java/org/tensorflow/ndarray' )
115+ shutil .copytree (REPO_ROOT / 'javacpp/src/main/java/org/bytedeco' , merged_source / 'java/org/bytedeco' )
116+ shutil .copytree (REPO_ROOT / 'protobuf/com/' , merged_source / 'java/com' )
117+ shutil .copytree (REPO_ROOT / 'osgi/org/osgi' , merged_source / 'java/org/osgi' )
88118
89119 gen_java .gen_java_docs (
90120 package = 'org.tensorflow' ,
91121 source_path = merged_source / 'java' ,
92122 output_dir = pathlib .Path (FLAGS .output_dir ),
93123 site_path = pathlib .Path (FLAGS .site_path ),
124+ section_labels = SECTION_LABELS ,
94125 # Uncomment for local testing:
95- # script_path=pathlib.Path(REPO_ROOT/'tools/ run-javadoc-for-tf-local.sh'),
126+ script_path = pathlib .Path (TOOLS_DIR , ' run-javadoc-for-tf-local.sh' ),
96127 )
97128
98129
0 commit comments