Back to home page

OSCL-LXR

 
 

    


0001 #
0002 # Licensed to the Apache Software Foundation (ASF) under one or more
0003 # contributor license agreements.  See the NOTICE file distributed with
0004 # this work for additional information regarding copyright ownership.
0005 # The ASF licenses this file to You under the Apache License, Version 2.0
0006 # (the "License"); you may not use this file except in compliance with
0007 # the License.  You may obtain a copy of the License at
0008 #
0009 #    http://www.apache.org/licenses/LICENSE-2.0
0010 #
0011 # Unless required by applicable law or agreed to in writing, software
0012 # distributed under the License is distributed on an "AS IS" BASIS,
0013 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014 # See the License for the specific language governing permissions and
0015 # limitations under the License.
0016 #
0017 
0018 require 'fileutils'
0019 include FileUtils
0020 
0021 if not (ENV['SKIP_API'] == '1')
0022   if not (ENV['SKIP_SCALADOC'] == '1')
0023     # Build Scaladoc for Scala and Javadoc for Java
0024 
0025     puts "Moving to project root and building API docs."
0026     curr_dir = pwd
0027     cd("..")
0028 
0029     puts "Running 'build/sbt -Pkinesis-asl clean compile unidoc' from " + pwd + "; this may take a few minutes..."
0030     system("build/sbt -Pkinesis-asl clean compile unidoc") || raise("Unidoc generation failed")
0031 
0032     puts "Moving back into docs dir."
0033     cd("docs")
0034 
0035     puts "Removing old docs"
0036     puts `rm -rf api`
0037 
0038     # Copy over the unified ScalaDoc for all projects to api/scala.
0039     # This directory will be copied over to _site when `jekyll` command is run.
0040     source = "../target/scala-2.12/unidoc"
0041     dest = "api/scala"
0042 
0043     puts "Making directory " + dest
0044     mkdir_p dest
0045 
0046     # From the rubydoc: cp_r('src', 'dest') makes src/dest, but this doesn't.
0047     puts "cp -r " + source + "/. " + dest
0048     cp_r(source + "/.", dest)
0049 
0050     # Append custom JavaScript
0051     js = File.readlines("./js/api-docs.js")
0052     js_file = dest + "/lib/template.js"
0053     File.open(js_file, 'a') { |f| f.write("\n" + js.join()) }
0054 
0055     # Append custom CSS
0056     css = File.readlines("./css/api-docs.css")
0057     css_file = dest + "/lib/template.css"
0058     File.open(css_file, 'a') { |f| f.write("\n" + css.join()) }
0059 
0060     # Copy over the unified JavaDoc for all projects to api/java.
0061     source = "../target/javaunidoc"
0062     dest = "api/java"
0063 
0064     puts "Making directory " + dest
0065     mkdir_p dest
0066 
0067     puts "cp -r " + source + "/. " + dest
0068     cp_r(source + "/.", dest)
0069 
0070     # Begin updating JavaDoc files for badge post-processing
0071     puts "Updating JavaDoc files for badge post-processing"
0072     js_script_start = '<script defer="defer" type="text/javascript" src="'
0073     js_script_end = '.js"></script>'
0074 
0075     javadoc_files = Dir["./" + dest + "/**/*.html"]
0076     javadoc_files.each do |javadoc_file|
0077       # Determine file depths to reference js files
0078       slash_count = javadoc_file.count "/"
0079       i = 3
0080       path_to_js_file = ""
0081       while (i < slash_count) do
0082         path_to_js_file = path_to_js_file + "../"
0083         i += 1
0084       end
0085 
0086       # Create script elements to reference js files
0087       javadoc_jquery_script = js_script_start + path_to_js_file + "lib/jquery" + js_script_end;
0088       javadoc_api_docs_script = js_script_start + path_to_js_file + "lib/api-javadocs" + js_script_end;
0089       javadoc_script_elements = javadoc_jquery_script + javadoc_api_docs_script
0090 
0091       # Add script elements to JavaDoc files
0092       javadoc_file_content = File.open(javadoc_file, "r") { |f| f.read }
0093       javadoc_file_content = javadoc_file_content.sub("</body>", javadoc_script_elements + "</body>")
0094       File.open(javadoc_file, "w") { |f| f.puts(javadoc_file_content) }
0095 
0096     end
0097     # End updating JavaDoc files for badge post-processing
0098 
0099     puts "Copying jquery.min.js from Scala API to Java API for page post-processing of badges"
0100     jquery_src_file = "./api/scala/lib/jquery.min.js"
0101     jquery_dest_file = "./api/java/lib/jquery.min.js"
0102     mkdir_p("./api/java/lib")
0103     cp(jquery_src_file, jquery_dest_file)
0104 
0105     puts "Copying api_javadocs.js to Java API for page post-processing of badges"
0106     api_javadocs_src_file = "./js/api-javadocs.js"
0107     api_javadocs_dest_file = "./api/java/lib/api-javadocs.js"
0108     cp(api_javadocs_src_file, api_javadocs_dest_file)
0109 
0110     puts "Appending content of api-javadocs.css to JavaDoc stylesheet.css for badge styles"
0111     css = File.readlines("./css/api-javadocs.css")
0112     css_file = dest + "/stylesheet.css"
0113     File.open(css_file, 'a') { |f| f.write("\n" + css.join()) }
0114   end
0115 
0116   if not (ENV['SKIP_PYTHONDOC'] == '1')
0117     # Build Sphinx docs for Python
0118 
0119     puts "Moving to python/docs directory and building sphinx."
0120     cd("../python/docs")
0121     system("make html") || raise("Python doc generation failed")
0122 
0123     puts "Moving back into docs dir."
0124     cd("../../docs")
0125 
0126     puts "Making directory api/python"
0127     mkdir_p "api/python"
0128 
0129     puts "cp -r ../python/docs/_build/html/. api/python"
0130     cp_r("../python/docs/_build/html/.", "api/python")
0131   end
0132 
0133   if not (ENV['SKIP_RDOC'] == '1')
0134     # Build SparkR API docs
0135 
0136     puts "Moving to R directory and building roxygen docs."
0137     cd("../R")
0138     system("./create-docs.sh") || raise("R doc generation failed")
0139 
0140     puts "Moving back into docs dir."
0141     cd("../docs")
0142 
0143     puts "Making directory api/R"
0144     mkdir_p "api/R"
0145 
0146     puts "cp -r ../R/pkg/html/. api/R"
0147     cp_r("../R/pkg/html/.", "api/R")
0148 
0149     puts "cp ../R/pkg/DESCRIPTION api"
0150     cp("../R/pkg/DESCRIPTION", "api")
0151   end
0152 
0153   if not (ENV['SKIP_SQLDOC'] == '1')
0154     # Build SQL API docs
0155 
0156     puts "Moving to project root and building API docs."
0157     curr_dir = pwd
0158     cd("..")
0159 
0160     puts "Running 'build/sbt clean package -Phive' from " + pwd + "; this may take a few minutes..."
0161     system("build/sbt clean package -Phive") || raise("SQL doc generation failed")
0162 
0163     puts "Moving back into docs dir."
0164     cd("docs")
0165 
0166     puts "Moving to SQL directory and building docs."
0167     cd("../sql")
0168     system("./create-docs.sh") || raise("SQL doc generation failed")
0169 
0170     puts "Moving back into docs dir."
0171     cd("../docs")
0172 
0173     puts "Making directory api/sql"
0174     mkdir_p "api/sql"
0175 
0176     puts "cp -r ../sql/site/. api/sql"
0177     cp_r("../sql/site/.", "api/sql")
0178   end
0179 
0180 end