001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2015 ForgeRock AS. 015 */ 016package org.forgerock.doc.maven.pre; 017 018import org.apache.maven.plugin.MojoExecutionException; 019import org.forgerock.doc.maven.AbstractDocbkxMojo; 020import org.twdata.maven.mojoexecutor.MojoExecutor; 021 022/** 023 * Converts Asciidoc source files to DocBook 5 XML. 024 */ 025public class AsciidocToDocBook { 026 027 /** 028 * The Mojo that holds configuration and related methods. 029 */ 030 private AbstractDocbkxMojo m; 031 032 /** 033 * The Executor to run the resources plugin. 034 */ 035 private final Executor executor; 036 037 /** 038 * Constructor setting the Mojo that holds the configuration. 039 * 040 * @param mojo The Mojo that holds the configuration. 041 */ 042 public AsciidocToDocBook(final AbstractDocbkxMojo mojo) { 043 m = mojo; 044 this.executor = new Executor(); 045 } 046 047 /** 048 * Copies arbitrary resources from sources to pre-site output for HTML formats. 049 * 050 * @throws MojoExecutionException Failed to copy files 051 */ 052 public void execute() throws MojoExecutionException { 053 executor.convert(); 054 } 055 056 /** 057 * Enclose methods to run plugins. 058 */ 059 class Executor extends MojoExecutor { 060 061 /** 062 * Converts Asciidoc source files to DocBook 5 XML. 063 * 064 * @throws MojoExecutionException Failed to convert files 065 */ 066 public void convert() throws MojoExecutionException { 067 if (!m.getAsciidocSourceDirectory().exists()) { 068 return; 069 } 070 071 executeMojo( 072 plugin( 073 groupId("org.asciidoctor"), 074 artifactId("asciidoctor-maven-plugin"), 075 version(m.getAsciidoctorPluginVersion())), 076 goal("process-asciidoc"), 077 configuration( 078 element("baseDir", m.path(m.getAsciidocSourceDirectory())), 079 element("outputDirectory", m.path(m.getDocbkxModifiableSourcesDirectory())), 080 element("preserveDirectories", "true"), 081 element("extensions", 082 element("extension", ".ad"), 083 element("extension", ".adoc"), 084 element("extension", ".asciidoc"), 085 element("extension", ".txt")), 086 element("backend", "docbook"), 087 element("doctype", "book")), 088 executionEnvironment(m.getProject(), m.getSession(), m.getPluginManager())); 089 } 090 } 091}