in src/main/java/org/apache/tomee/website/PDFify.java [40:75]
public static void generatePdf(final File from, final File targetBase) throws IOException {
final Path sourceBase = from.toPath();
final Asciidoctor asciidoctor = Asciidoctor.Factory.create();
final ExecutorService pool = Executors.newFixedThreadPool(16);
Files.walkFileTree(sourceBase, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
final String fileName = file.getFileName().toString();
if (fileName.endsWith(".adoc")) {
pool.submit(() -> {
final String path = sourceBase.relativize(file).toString();
final File target = new File(targetBase, path.substring(0, path.length() - "adoc".length()) + "pdf");
final File asFile = file.toFile();
final Map<String, Object> attributes = asciidoctor.readDocumentHeader(asFile).getAttributes();
// if we generate the PDF link we need to create the PDF excepted if it is expected to be manual
if (attributes.containsKey("jbake-tomeepdf") && !attributes.containsKey("jbake-tomeepdf-manual")) {
asciidoctor.convertFile(
asFile,
options().docType("article")
.backend
("pdf")
.attributes(AttributesBuilder.attributes().attribute("source-highlighter", "coderay")).toFile(target).get());
System.out.println("Generated " + target);
}
});
}
return super.visitFile(file, attrs);
}
});
pool.shutdown();
try {
pool.awaitTermination(1, TimeUnit.HOURS);
} catch (final InterruptedException e) {
Thread.interrupted();
}
}