Broken path to include file does not break publishing process
In case an AsciiDoc file contains a broken include path using the include::-macro, the publishing process does not fail, but only logs a warning:
asciidoctor: WARNING: <stdin>: line 19: include file not found: /.../asciidoc-confluence-publisher-doc/etc/docs/files/_included-page.adoc
This leads to a Unresolved directive in <stdin> - include::... text on the corresponding Confluence page.
Ideally, the publishing process should fail, if the path to the included file is not correct.
Unfortunately I haven't found any configuration option for Asciidoctor to fail the conversion process if include directive is broken.
To resolve the same issue asciidoctor-maven-plugin has failIf property that can be configured either for containsText or Asciidoctor's severity message. I suppose this can be done the same way in confluence-publisher.
Also include file not found was changed to ERROR severity in this issue: https://github.com/asciidoctor/asciidoctor/issues/2424
@cstettler what do you think?
I was able to get such functionality using PostProcessor:
import org.asciidoctor.ast.Document;
import org.asciidoctor.extension.Postprocessor;
public class UnresolvedDirectivePostprocessor extends Postprocessor {
@Override
public String process(Document document, String output) {
if (output.contains("Unresolved directive in ")) {
throw new IllegalStateException("Unresolved directive in document: " + document.getDoctitle());
}
return output;
}
}
You need to register it:
import org.asciidoctor.Asciidoctor;
import org.asciidoctor.extension.JavaExtensionRegistry;
import org.asciidoctor.jruby.extension.spi.ExtensionRegistry;
public class MyExtension implements ExtensionRegistry {
@Override
public void register(Asciidoctor asciidoctor) {
JavaExtensionRegistry extensionRegistry = asciidoctor.javaExtensionRegistry();
extensionRegistry.postprocessor(UnresolvedDirectivePostprocessor.class);
}
}
Create file org.asciidoctor.jruby.extension.spi.ExtensionRegistry under src/main/resources/META-INF/services
setup.here.full.package.to.MyExtension
After that you can add this depedency to the Confluence Publisher Maven Plugin as a dependency.
Thank you @Aloren for the idea of this approach. That approach should be easily implementable as part of the Confluence Publisher already. I will put in on the list.
I've implemented this feature internally and just for the case made this feature togglable. I can open a PR with my implementation. What do you think?