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 2013-2015 ForgeRock AS. 015 */ 016 017package org.forgerock.doc.maven.pre; 018 019import org.apache.maven.plugin.MojoExecutionException; 020import org.forgerock.doc.maven.AbstractDocbkxMojo; 021import org.twdata.maven.mojoexecutor.MojoExecutor; 022 023/** 024 * Use <a href="http://plantuml.sourceforge.net/">PlantUML</a> to generate images. 025 * 026 * <p> 027 * 028 * This class expects .txt files in the DocBook XML sources 029 * that contain PlantUML diagrams. 030 * 031 * <p> 032 * 033 * It transforms the files to images in the same directories as the files. 034 */ 035public class PlantUml { 036 037 /** 038 * The Mojo that holds configuration and related methods. 039 */ 040 private AbstractDocbkxMojo m; 041 042 /** 043 * The Executor to run the resources plugin. 044 */ 045 private final Executor executor; 046 047 /** 048 * Constructor setting the Mojo that holds the configuration. 049 * 050 * @param mojo The Mojo that holds the configuration. 051 */ 052 public PlantUml(final AbstractDocbkxMojo mojo) { 053 m = mojo; 054 this.executor = new Executor(); 055 } 056 057 /** 058 * Run PlantUML on .txt files in the DocBook source files. 059 * 060 * @throws MojoExecutionException Failed to run PlantUML. 061 */ 062 public void execute() throws MojoExecutionException { 063 064 // JCite to a temporary directory... 065 executor.runPlantUml(); 066 } 067 068 /** 069 * Enclose methods to run plugins. 070 */ 071 class Executor extends MojoExecutor { 072 073 /** 074 * Run PlantUML on .txt files in the DocBook source files. 075 * 076 * @throws MojoExecutionException Failed to run PlantUml. 077 */ 078 void runPlantUml() throws MojoExecutionException { 079 080 final String directory = m.path(m.getDocbkxModifiableSourcesDirectory()); 081 082 executeMojo( 083 plugin( 084 groupId("com.github.jeluard"), 085 artifactId("plantuml-maven-plugin"), 086 version("1.0"), 087 dependencies( 088 dependency( 089 groupId("net.sourceforge.plantuml"), 090 artifactId("plantuml"), 091 version(m.getPlantUmlVersion())))), 092 goal("generate"), 093 configuration( 094 element(name("sourceFiles"), 095 element(name("directory"), directory), 096 element(name("includes"), 097 element(name("include"), "**/*.txt"))), 098 element(name("outputInSourceDirectory"), "true"), 099 element(name("verbose"), "false")), 100 executionEnvironment(m.getProject(), m.getSession(), m.getPluginManager())); 101 } 102 } 103}