Build: check external asciidoc links
* Check external links have a description * Use Groovy regex instead of Java * Add source file name to exception message * Add 'checkAsciiDocLinks' to Travis build
This commit is contained in:
committed by
Artem Bilan
parent
374b4b70f1
commit
2a50a26252
@@ -15,4 +15,4 @@ install: true
|
||||
env:
|
||||
- TERM=dumb SI_FATAL_WHEN_NO_BEANFACTORY=true NO_REFERENCE_TASK=true
|
||||
script:
|
||||
- ./gradlew check --refresh-dependencies --no-daemon
|
||||
- ./gradlew check checkAsciiDocLinks --refresh-dependencies --no-daemon
|
||||
|
||||
39
build.gradle
39
build.gradle
@@ -855,8 +855,45 @@ task prepareAsciidocBuild(type: Sync) {
|
||||
into "$buildDir/asciidoc"
|
||||
}
|
||||
|
||||
task('makePDF', type: org.asciidoctor.gradle.AsciidoctorTask) {
|
||||
task checkAsciidocLinks {
|
||||
dependsOn prepareAsciidocBuild
|
||||
inputs.dir("$buildDir/asciidoc")
|
||||
doLast {
|
||||
inputs.files.filter{ f -> f.path.endsWith('.adoc') }.each { file ->
|
||||
def doc = file.text
|
||||
Set<String> anchors = new HashSet<>()
|
||||
def matcher = (doc =~ /\[\[([^]]+)\]\]/)
|
||||
while (matcher.find()) {
|
||||
anchors.add(matcher.group(1))
|
||||
}
|
||||
matcher = (doc =~ /<<([^>]+)>>/)
|
||||
while (matcher.find()) {
|
||||
String anchor = matcher.group(1);
|
||||
def hasComma = anchor.contains(",")
|
||||
if (!anchor.startsWith("./")) {
|
||||
if (hasComma) {
|
||||
anchor = anchor.substring(0, anchor.indexOf(","));
|
||||
}
|
||||
if (!anchors.contains(anchor)) {
|
||||
throw new InvalidUserDataException("Anchor '" + anchor
|
||||
+ "' not found in '" + file.name
|
||||
+ "', if in another file, it needs to be qualified with './fileName.adoc#'")
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!hasComma) {
|
||||
throw new InvalidUserDataException("External anchor '" + anchor
|
||||
+ "' in '" + file.name
|
||||
+ "' should have a textual description (,...)")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task('makePDF', type: org.asciidoctor.gradle.AsciidoctorTask) {
|
||||
dependsOn checkAsciidocLinks
|
||||
backends 'pdf'
|
||||
sourceDir "$buildDir/asciidoc"
|
||||
sources {
|
||||
|
||||
@@ -23,7 +23,7 @@ https://github.com/SpringSource/spring-integration-samples[https://github.com/Sp
|
||||
In order to check out or clone the samples, you must have a Git client installed on your system.
|
||||
There are several GUI-based products available for many platforms (such as https://eclipse.org/egit/[EGit] for the Eclipse IDE).
|
||||
A simple Google search can help you find them.
|
||||
You can also use the command line interface for <<https://git-scm.com/,Git>>.
|
||||
You can also use the command line interface for https://git-scm.com/[Git].
|
||||
|
||||
NOTE: If you need more information on how to install or use Git, visit: https://git-scm.com/[https://git-scm.com/].
|
||||
|
||||
|
||||
Reference in New Issue
Block a user