2020-03-11 11:09:26 -04:00
/ *
* Licensed to the Apache Software Foundation ( ASF ) under one or more
* contributor license agreements . See the NOTICE file distributed with
* this work for additional information regarding copyright ownership .
* The ASF licenses this file to You under the Apache License , Version 2.0
* ( the "License" ) ; you may not use this file except in compliance with
* the License . You may obtain a copy of the License at
*
* http: //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS IS" BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
* /
2020-04-08 19:44:07 -04:00
// generate javadocs by calling javadoc tool
// see https://docs.oracle.com/en/java/javase/11/tools/javadoc.html
// utility function to convert project path to document dir
// e.g.: ':lucene:analysis:common' => 'analysis/common'
def pathToDocdir = { path - > path . split ( ':' ) . drop ( 2 ) . join ( '/' ) }
2020-03-11 11:09:26 -04:00
allprojects {
plugins . withType ( JavaPlugin ) {
2020-04-12 06:55:56 -04:00
// We disable the default javadoc task and have our own
// javadoc rendering task below. The default javadoc task
// will just invoke 'renderJavadoc' (to allow people to call
// conventional task name).
tasks . matching { it . name = = "javadoc" } . all {
enabled = false
dependsOn "renderJavadoc"
}
2020-03-11 11:09:26 -04:00
task renderJavadoc {
2020-04-08 19:44:07 -04:00
description "Generates Javadoc API documentation for the main source code. This directly invokes javadoc tool."
2020-03-11 11:09:26 -04:00
group "documentation"
ext {
2020-04-08 19:44:07 -04:00
linksource = false
2020-03-11 11:09:26 -04:00
linkJUnit = false
2020-04-08 19:44:07 -04:00
linkLuceneProjects = [ ]
linkSorlProjects = [ ]
2020-03-11 11:09:26 -04:00
}
dependsOn sourceSets . main . compileClasspath
inputs . files { sourceSets . main . java . asFileTree }
2020-04-08 19:44:07 -04:00
outputs . dir project . javadoc . destinationDir
2020-03-11 11:09:26 -04:00
def libName = project . path . startsWith ( ":lucene" ) ? "Lucene" : "Solr"
def title = "${libName} ${project.version} ${project.name} API" . toString ( )
2020-04-08 19:44:07 -04:00
// absolute urls for "-linkoffline" option
def javaSEDocUrl = "https://docs.oracle.com/en/java/javase/11/docs/api/"
def junitDocUrl = "https://junit.org/junit4/javadoc/4.12/"
def luceneDocUrl = "https://lucene.apache.org/core/${project.version.replace(" . ", " _ ")}" . toString ( )
def solrDocUrl = "https://lucene.apache.org/solr/${project.version.replace(" . ", " _ ")}" . toString ( )
def javadocCmd = org . gradle . internal . jvm . Jvm . current ( ) . getJavadocExecutable ( )
2020-03-11 11:09:26 -04:00
doFirst {
def srcDirs = sourceSets . main . java . srcDirs . findAll { dir - > dir . exists ( ) }
2020-04-11 04:36:18 -04:00
def optionsFile = file ( "${getTemporaryDir()}/javadoc-options.txt" )
2020-03-11 11:09:26 -04:00
2020-04-08 19:44:07 -04:00
def opts = [ ]
opts + = [ "-overview ${file(" src /java/ overview . html ").toString()}" ]
opts + = [ "-sourcepath ${srcDirs.join(' ')}" ]
opts + = [ "-subpackages ${project.path.startsWith(':lucene') ? 'org.apache.lucene' : 'org.apache.solr'}" ]
opts + = [ "-d ${project.javadoc.destinationDir.toString()}" ]
opts + = [ "-protected" ]
opts + = [ "-encoding UTF-8" ]
opts + = [ "-charset UTF-8" ]
opts + = [ "-docencoding UTF-8" ]
opts + = [ "-noindex" ]
opts + = [ "-author" ]
opts + = [ "-version" ]
if ( linksource ) {
opts + = [ "-linksource" ]
}
opts + = [ "-use" ]
opts + = [ "-locale en_US" ]
opts + = [ "-windowtitle '${title}'" ]
opts + = [ "-doctitle '${title}'" ]
if ( ! sourceSets . main . compileClasspath . isEmpty ( ) ) {
opts + = [ "-classpath ${sourceSets.main.compileClasspath.asPath}" ]
}
opts + = [ "-bottom '<i>Copyright © 2000-${buildYear} Apache Software Foundation. All Rights Reserved.</i>'" ]
2020-03-11 11:09:26 -04:00
2020-04-08 19:44:07 -04:00
opts + = [ "-tag 'lucene.experimental:a:WARNING: This API is experimental and might change in incompatible ways in the next release.'" ]
opts + = [ "-tag 'lucene.internal:a:NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.'" ]
opts + = [ "-tag 'lucene.spi:t:SPI Name (case-insensitive: if the name is 'htmlStrip', 'htmlstrip' can be used when looking up the service).'" ]
2020-03-11 11:09:26 -04:00
2020-04-08 19:44:07 -04:00
// resolve links to JavaSE and JUnit API
opts + = [ "-linkoffline ${javaSEDocUrl} ${project(':lucene').file('tools/javadoc/java11/').toString()}" ]
if ( linkJUnit ) {
opts + = [ "-linkoffline ${junitDocUrl} ${project(':lucene').file('tools/javadoc/junit').toURL()}" ]
}
// resolve inter-project links
linkLuceneProjects . collect { path - >
opts + = [ "-linkoffline ${luceneDocUrl}/${pathToDocdir(path)} ${file(project(path).javadoc.destinationDir).toString()}" ]
}
linkSorlProjects . collect { path - >
opts + = [ "-linkoffline ${solrDocUrl}/${pathToDocdir(path)} ${file(project(path).javadoc.destinationDir).toString()}" ]
}
opts + = [ "--release 11" ]
opts + = [ "-Xdoclint:all,-missing" ]
// Temporary file that holds all javadoc options for the current task.
optionsFile . write ( opts . join ( "\n" ) , "UTF-8" )
def outputFile = file ( "${getTemporaryDir()}/javadoc-output.txt" )
def result
outputFile . withOutputStream { output - >
result = project . exec {
executable javadocCmd
standardOutput = output
errorOutput = output
args + = [ "@${optionsFile}" ]
// -J flags can't be passed via options file... (an error "javadoc: error - invalid flag: -J-Xmx512m" occurs.)
args + = [ "-J-Xmx512m" ]
// force locale to be "en_US" (fix for: https://bugs.openjdk.java.net/browse/JDK-8222793)
args + = [ "-J-Duser.language=en -J-Duser.country=US" ]
ignoreExitValue true
2020-03-11 11:09:26 -04:00
}
2020-04-08 19:44:07 -04:00
}
2020-03-11 11:09:26 -04:00
2020-04-08 19:44:07 -04:00
if ( result . getExitValue ( ) ! = 0 ) {
// Pipe the output to console. Intentionally skips any encoding conversion
// and pumps raw bytes.
System . out . write ( outputFile . bytes )
2020-03-11 11:09:26 -04:00
2020-04-08 19:44:07 -04:00
def cause
try {
result . rethrowFailure ( )
} catch ( ex ) {
cause = ex
}
throw new GradleException ( "Javadoc generation failed for ${project.path},\n Options file at: ${optionsFile}\n Command output at: ${outputFile}" , cause )
2020-03-11 11:09:26 -04:00
}
// append some special table css, prettify css
2020-04-08 19:44:07 -04:00
ant . concat ( destfile: "${project.javadoc.destinationDir}/stylesheet.css" , append: "true" , fixlastline: "true" , encoding: "UTF-8" ) {
2020-03-11 11:09:26 -04:00
filelist ( dir: project ( ":lucene" ) . file ( "tools/javadoc" ) , files: "table_padding.css" )
filelist ( dir: project ( ":lucene" ) . file ( "tools/prettify" ) , files: "prettify.css" )
}
// append prettify to scripts
2020-04-08 19:44:07 -04:00
ant . concat ( destfile: "${project.javadoc.destinationDir}/script.js" , append: "true" , fixlastline: "true" , encoding: "UTF-8" ) {
2020-03-11 11:09:26 -04:00
filelist ( dir: project ( ':lucene' ) . file ( "tools/prettify" ) , files: "prettify.js inject-javadocs.js" )
}
2020-04-08 19:44:07 -04:00
ant . fixcrlf ( srcdir: project . javadoc . destinationDir , includes: "stylesheet.css script.js" , eol: "lf" , fixlast: "true" , encoding: "UTF-8" )
2020-03-11 11:09:26 -04:00
}
}
}
}
configure ( subprojects . findAll { it . path . startsWith ( ':lucene' ) & & it . path ! = ':lucene:core' } ) {
plugins . withType ( JavaPlugin ) {
renderJavadoc {
2020-04-08 19:44:07 -04:00
[ ':lucene:core' ] . collect { path - >
dependsOn "${path}:renderJavadoc"
linkLuceneProjects + = [ path ]
}
2020-03-11 11:09:26 -04:00
doLast {
// fix for Java 11 Javadoc tool that cannot handle split packages between modules correctly (by removing all the packages which are part of lucene-core)
// problem description: [https://issues.apache.org/jira/browse/LUCENE-8738?focusedCommentId=16818106&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-16818106]
ant . local ( name: "element-list-regex" ) // contains a regex for all package names which are in lucene-core's javadoc
2020-04-08 19:44:07 -04:00
ant . loadfile ( property: "element-list-regex" , srcFile: "${project(':lucene:core').javadoc.destinationDir}/element-list" , encoding: "utf-8" ) {
2020-03-11 11:09:26 -04:00
filterchain {
tokenfilter ( delimoutput: "|" ) {
replacestring ( from: "." , to: "\\." )
}
}
}
ant . replaceregexp (
encoding: "UTF-8" ,
2020-04-08 19:44:07 -04:00
file: "${project.javadoc.destinationDir}/element-list" ,
2020-03-11 11:09:26 -04:00
byline: "true" ,
match: "^(\${element-list-regex})\$" ,
replace: "" )
}
}
}
}
2020-04-08 19:44:07 -04:00
configure ( subprojects . findAll { it . path . startsWith ( ':lucene:analysis' ) & & it . path ! = ':lucene:analysis:common' } ) {
2020-03-11 11:09:26 -04:00
plugins . withType ( JavaPlugin ) {
renderJavadoc {
2020-04-08 19:44:07 -04:00
[ ':lucene:analysis:common' ] . collect { path - >
dependsOn "${path}:renderJavadoc"
linkLuceneProjects + = [ path ]
2020-03-11 11:09:26 -04:00
}
}
}
}
configure ( project ( ':lucene:benchmark' ) ) {
plugins . withType ( JavaPlugin ) {
renderJavadoc {
[ ':lucene:memory' ,
':lucene:highlighter' ,
':lucene:analysis:common' ,
':lucene:queryparser' ,
':lucene:facet' ,
':lucene:spatial-extras' ] . collect { path - >
dependsOn "${path}:renderJavadoc"
2020-04-08 19:44:07 -04:00
linkLuceneProjects + = [ path ]
2020-03-11 11:09:26 -04:00
}
}
}
}
configure ( project ( ':lucene:classification' ) ) {
plugins . withType ( JavaPlugin ) {
renderJavadoc {
[ ':lucene:queries' , ':lucene:analysis:common' , ':lucene:grouping' ] . collect { path - >
dependsOn "${path}:renderJavadoc"
2020-04-08 19:44:07 -04:00
linkLuceneProjects + = [ path ]
2020-03-11 11:09:26 -04:00
}
}
}
}
configure ( project ( ':lucene:demo' ) ) {
plugins . withType ( JavaPlugin ) {
renderJavadoc {
[ ':lucene:analysis:common' ,
':lucene:queryparser' ,
':lucene:queries' ,
':lucene:facet' ,
':lucene:expressions' ] . collect { path - >
dependsOn "${path}:renderJavadoc"
2020-04-08 19:44:07 -04:00
linkLuceneProjects + = [ path ]
2020-03-11 11:09:26 -04:00
}
// we link the example source in the javadocs, as it's ref'ed elsewhere
2020-04-08 19:44:07 -04:00
linksource = true
2020-03-11 11:09:26 -04:00
}
}
}
configure ( project ( ':lucene:grouping' ) ) {
plugins . withType ( JavaPlugin ) {
renderJavadoc {
2020-04-08 19:44:07 -04:00
[ ':lucene:queries' ] . collect { path - >
dependsOn "${path}:renderJavadoc"
linkLuceneProjects + = [ path ]
}
2020-03-11 11:09:26 -04:00
}
}
}
configure ( project ( ':lucene:highlighter' ) ) {
plugins . withType ( JavaPlugin ) {
renderJavadoc {
2020-04-08 19:44:07 -04:00
[ ':lucene:memory' ] . collect { path - >
dependsOn "${path}:renderJavadoc"
linkLuceneProjects + = [ path ]
}
2020-03-11 11:09:26 -04:00
}
}
}
configure ( project ( ':lucene:monitor' ) ) {
plugins . withType ( JavaPlugin ) {
renderJavadoc {
[ ':lucene:memory' , ':lucene:analysis:common' , ':lucene:queryparser' ] . collect { path - >
dependsOn "${path}:renderJavadoc"
2020-04-08 19:44:07 -04:00
linkLuceneProjects + = [ path ]
2020-03-11 11:09:26 -04:00
}
}
}
}
configure ( project ( ':lucene:queryparser' ) ) {
plugins . withType ( JavaPlugin ) {
renderJavadoc {
[ ':lucene:queries' , ':lucene:sandbox' ] . collect { path - >
dependsOn "${path}:renderJavadoc"
2020-04-08 19:44:07 -04:00
linkLuceneProjects + = [ path ]
2020-03-11 11:09:26 -04:00
}
}
}
}
configure ( project ( ':lucene:replicator' ) ) {
plugins . withType ( JavaPlugin ) {
renderJavadoc {
2020-04-08 19:44:07 -04:00
[ ':lucene:facet' ] . collect { path - >
dependsOn "${path}:renderJavadoc"
linkLuceneProjects + = [ path ]
}
2020-03-11 11:09:26 -04:00
}
}
}
configure ( project ( ':lucene:spatial-extras' ) ) {
plugins . withType ( JavaPlugin ) {
renderJavadoc {
2020-04-08 19:44:07 -04:00
[ ':lucene:spatial3d' ] . collect { path - >
dependsOn "${path}:renderJavadoc"
linkLuceneProjects + = [ path ]
}
2020-03-11 11:09:26 -04:00
}
}
}
configure ( project ( ':lucene:suggest' ) ) {
plugins . withType ( JavaPlugin ) {
renderJavadoc {
2020-04-08 19:44:07 -04:00
[ ':lucene:analysis:common' ] . collect { path - >
dependsOn "${path}:renderJavadoc"
linkLuceneProjects + = [ path ]
}
2020-03-11 11:09:26 -04:00
}
}
}
configure ( project ( ':lucene:test-framework' ) ) {
plugins . withType ( JavaPlugin ) {
2020-04-08 19:44:07 -04:00
2020-03-11 11:09:26 -04:00
renderJavadoc {
2020-04-08 19:44:07 -04:00
[ ':lucene:codecs' ] . collect { path - >
dependsOn "${path}:renderJavadoc"
linkLuceneProjects + = [ path ]
}
2020-03-11 11:09:26 -04:00
linkJUnit = true
}
}
}
configure ( subprojects . findAll { it . path . startsWith ( ':solr' ) } ) {
plugins . withType ( JavaPlugin ) {
def hasJavdocsTask = project . tasks . collect { it . name } . contains ( 'renderJavadoc' )
if ( hasJavdocsTask ) {
renderJavadoc {
2020-04-08 19:44:07 -04:00
[ ':lucene:core' ,
':lucene:analysis:common' ,
':lucene:analysis:icu' ,
':lucene:analysis:kuromoji' ,
':lucene:analysis:nori' ,
':lucene:analysis:morfologik' ,
':lucene:analysis:phonetic' ,
':lucene:analysis:smartcn' ,
':lucene:analysis:stempel' ,
':lucene:backward-codecs' ,
':lucene:codecs' ,
':lucene:expressions' ,
':lucene:suggest' ,
':lucene:grouping' ,
':lucene:join' ,
':lucene:queries' ,
':lucene:queryparser' ,
':lucene:highlighter' ,
':lucene:memory' ,
':lucene:misc' ,
':lucene:classification' ,
':lucene:spatial-extras' ] . collect { path - >
dependsOn "${path}:renderJavadoc"
linkLuceneProjects + = [ path ]
}
2020-03-11 11:09:26 -04:00
}
}
}
}
configure ( project ( ':solr:core' ) ) {
plugins . withType ( JavaPlugin ) {
// specialized to ONLY depend on solrj
renderJavadoc {
2020-04-08 19:44:07 -04:00
[ ':solr:solrj' ] . collect { path - >
dependsOn "${path}:renderJavadoc"
linkSorlProjects + = [ path ]
}
2020-03-11 11:09:26 -04:00
}
}
}
configure ( subprojects . findAll { it . path . startsWith ( ':solr:contrib' ) } ) {
plugins . withType ( JavaPlugin ) {
renderJavadoc {
2020-04-08 19:44:07 -04:00
[ ':solr:solrj' , ':solr:core' ] . collect { path - >
dependsOn "${path}:renderJavadoc"
linkSorlProjects + = [ path ]
}
2020-03-11 11:09:26 -04:00
}
}
}
configure ( project ( ':solr:contrib:dataimporthandler-extras' ) ) {
plugins . withType ( JavaPlugin ) {
renderJavadoc {
2020-04-08 19:44:07 -04:00
[ ':solr:contrib:dataimporthandler' ] . collect { path - >
dependsOn "${path}:renderJavadoc"
linkSorlProjects + = [ path ]
}
2020-03-11 11:09:26 -04:00
}
}
}
configure ( project ( ':solr:test-framework' ) ) {
plugins . withType ( JavaPlugin ) {
renderJavadoc {
linkJUnit = true
}
}
}
configure ( subprojects . findAll { it . path in [ ':solr:solr-ref-guide' , ':solr:server' , ':solr:webapp' ] } ) {
afterEvaluate {
project . tasks . findByPath ( "renderJavadoc" ) . enabled = false
}
}