Files
spring-integration/gradle/docs.gradle
2023-11-14 10:40:57 -05:00

115 lines
2.7 KiB
Groovy

ext {
backendVersion = '0.0.5'
}
configurations {
asciidoctorExtensions
}
dependencies {
asciidoctorExtensions "io.spring.asciidoctor.backends:spring-asciidoctor-backends:$backendVersion"
}
task checkAsciidocLinks {
inputs.dir('src/reference/asciidoc')
doLast {
def errors = new ArrayList<>();
errors.add('*** Anchor reference errors found:')
inputs.files.filter{ f -> f.path.endsWith('.adoc') }.each { file ->
def doc = file.text
def anchors = new HashSet<>()
def matcher = (doc =~ /\[\[([^]]+)]]/)
while (matcher.find()) {
anchors.add(matcher.group(1))
}
matcher = (doc =~ /<<([^>]+)>>/)
while (matcher.find()) {
def anchor = matcher.group(1);
def hasComma = anchor.contains(',')
if (!anchor.startsWith('./')) {
if (hasComma) {
anchor = anchor.substring(0, anchor.indexOf(","));
}
if (!anchors.contains(anchor)) {
errors.add("\nAnchor '$anchor' not found in '${file.name}', " +
"if in another file, it needs to be qualified with './fileName.adoc#'")
}
}
else {
if (!hasComma) {
errors.add("\nExternal anchor '$anchor' in '${file.name}' should have a textual description (,...)")
}
}
}
}
if (errors.size() > 1) {
throw new InvalidUserDataException(errors.toString())
}
}
}
asciidoctorPdf {
dependsOn checkAsciidocLinks
baseDirFollowsSourceFile()
configurations 'asciidoctorExtensions'
asciidoctorj {
sourceDir "$buildDir/asciidoc"
inputs.dir(sourceDir)
sources {
include 'index-single.adoc'
}
options doctype: 'book'
attributes 'icons': 'font',
'sectanchors': '',
'sectnums': '',
'toc': '',
'source-highlighter' : 'coderay',
revnumber: project.version,
'project-version': project.version
}
}
asciidoctorj {
version = '2.5.2'
options doctype: 'book', eruby: 'erubis'
attributes 'docinfo': 'shared',
stylesdir: 'css/',
stylesheet: 'stylesheet.css',
'linkcss': true,
'copycss': false,
'icons': 'font',
'sectanchors': '',
'source-highlighter': 'highlight.js',
'highlightjsdir': 'js/highlight',
'highlightjs-theme': 'github',
'idprefix': '',
'idseparator': '-',
'allow-uri-read': '',
'toc': 'left',
'toclevels': '4',
revnumber: project.version,
'project-version': project.version
}
asciidoctor {
dependsOn asciidoctorPdf
baseDirFollowsSourceFile()
configurations 'asciidoctorExtensions'
sourceDir "$buildDir/asciidoc"
inputs.dir(sourceDir)
resources {
from(sourceDir) {
include 'images/*', 'css/**', 'js/**'
}
}
}
task reference(dependsOn: asciidoctor) {
group = 'Documentation'
description = 'Generate the reference documentation'
}
reference.onlyIf { 'true' != System.env['NO_REFERENCE_TASK'] || project.hasProperty('ignoreEnvToStopReference') }