1 /* 2 * The contents of this file are subject to the terms of the Common Development and 3 * Distribution License (the License). You may not use this file except in compliance with the 4 * License. 5 * 6 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 7 * specific language governing permission and limitations under the License. 8 * 9 * When distributing Covered Software, include this CDDL Header Notice in each file and include 10 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 11 * Header, with the fields enclosed by brackets [] replaced by your own identifying 12 * information: "Portions copyright [year] [name of copyright owner]". 13 * 14 * Copyright 2013-2015 ForgeRock AS. 15 */ 16 17 package org.forgerock.doc.maven.pre; 18 19 import org.apache.maven.plugin.MojoExecutionException; 20 import org.forgerock.doc.maven.AbstractDocbkxMojo; 21 import org.twdata.maven.mojoexecutor.MojoExecutor; 22 23 /** 24 * Use <a href="http://plantuml.sourceforge.net/">PlantUML</a> to generate images. 25 * 26 * <p> 27 * 28 * This class expects .txt files in the DocBook XML sources 29 * that contain PlantUML diagrams. 30 * 31 * <p> 32 * 33 * It transforms the files to images in the same directories as the files. 34 */ 35 public class PlantUml { 36 37 /** 38 * The Mojo that holds configuration and related methods. 39 */ 40 private AbstractDocbkxMojo m; 41 42 /** 43 * The Executor to run the resources plugin. 44 */ 45 private final Executor executor; 46 47 /** 48 * Constructor setting the Mojo that holds the configuration. 49 * 50 * @param mojo The Mojo that holds the configuration. 51 */ 52 public PlantUml(final AbstractDocbkxMojo mojo) { 53 m = mojo; 54 this.executor = new Executor(); 55 } 56 57 /** 58 * Run PlantUML on .txt files in the DocBook source files. 59 * 60 * @throws MojoExecutionException Failed to run PlantUML. 61 */ 62 public void execute() throws MojoExecutionException { 63 64 // JCite to a temporary directory... 65 executor.runPlantUml(); 66 } 67 68 /** 69 * Enclose methods to run plugins. 70 */ 71 class Executor extends MojoExecutor { 72 73 /** 74 * Run PlantUML on .txt files in the DocBook source files. 75 * 76 * @throws MojoExecutionException Failed to run PlantUml. 77 */ 78 void runPlantUml() throws MojoExecutionException { 79 80 final String directory = m.path(m.getDocbkxModifiableSourcesDirectory()); 81 82 executeMojo( 83 plugin( 84 groupId("com.github.jeluard"), 85 artifactId("plantuml-maven-plugin"), 86 version("1.0"), 87 dependencies( 88 dependency( 89 groupId("net.sourceforge.plantuml"), 90 artifactId("plantuml"), 91 version(m.getPlantUmlVersion())))), 92 goal("generate"), 93 configuration( 94 element(name("sourceFiles"), 95 element(name("directory"), directory), 96 element(name("includes"), 97 element(name("include"), "**/*.txt"))), 98 element(name("outputInSourceDirectory"), "true"), 99 element(name("verbose"), "false")), 100 executionEnvironment(m.getProject(), m.getSession(), m.getPluginManager())); 101 } 102 } 103 }