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 */
016
017package org.forgerock.doc.maven;
018
019import org.apache.maven.plugin.MojoExecutionException;
020import org.apache.maven.plugin.MojoFailureException;
021import org.apache.maven.plugins.annotations.LifecyclePhase;
022import org.apache.maven.plugins.annotations.Mojo;
023import org.forgerock.doc.maven.pre.ArtifactBuilder;
024import org.forgerock.doc.maven.pre.AsciidocToDocBook;
025import org.forgerock.doc.maven.pre.Branding;
026import org.forgerock.doc.maven.pre.CommonContent;
027import org.forgerock.doc.maven.pre.ConditionalText;
028import org.forgerock.doc.maven.pre.CurrentDocId;
029import org.forgerock.doc.maven.pre.CustomCss;
030import org.forgerock.doc.maven.pre.CreateThumbs;
031import org.forgerock.doc.maven.pre.Dpi;
032import org.forgerock.doc.maven.pre.Filter;
033import org.forgerock.doc.maven.pre.HeaderColor;
034import org.forgerock.doc.maven.pre.ImageData;
035import org.forgerock.doc.maven.pre.JCite;
036import org.forgerock.doc.maven.pre.KeepTogether;
037import org.forgerock.doc.maven.pre.ModifiableCopy;
038import org.forgerock.doc.maven.pre.PlantUml;
039import org.forgerock.doc.maven.pre.XCite;
040
041/**
042 * Call other classes to pre-process documentation sources.
043 */
044@Mojo(name = "process", defaultPhase = LifecyclePhase.PRE_SITE)
045public class PreProcessMojo extends AbstractDocbkxMojo {
046
047    /**
048     * Call other classes to pre-process documentation sources.
049     *
050     * @throws MojoExecutionException   Failed to process successfully.
051     * @throws MojoFailureException     Failed to process successfully.
052     */
053    @Override
054    public void execute() throws MojoExecutionException, MojoFailureException {
055
056        if (getBuildDirectory() == null) {
057            throw new MojoExecutionException("No build directory available.");
058        }
059
060        if (!getBuildDirectory().exists()) {
061            if (!getBuildDirectory().mkdir()) {
062                throw new MojoExecutionException("Could not create build directory");
063            }
064        }
065
066        // Get branding.
067        new Branding(this).execute();
068
069        // Make a copy of the source files that the plugin can edit.
070        new ModifiableCopy(this).execute();
071        new ConditionalText(this).execute();
072
073        if (!doUsePreProcessedSources()) {  // Sources require pre-processing.
074            new CommonContent(this).execute();
075            new AsciidocToDocBook(this).execute();
076            new JCite(this).execute();
077            new XCite(this).execute();
078            new Filter(this).execute();
079            new ImageData(this).execute();
080            new HeaderColor(this).execute();
081            new PlantUml(this).execute();
082            if (getFormats().contains(Format.pdf) || getFormats().contains(Format.rtf)) {
083                new KeepTogether(this).execute();
084                new Dpi(this).execute();
085            }
086            if (getFormats().contains(Format.bootstrap)) {
087                new CreateThumbs(this).execute();
088            }
089            new CurrentDocId(this).execute();
090            new CustomCss(this).execute();
091        }
092
093        if (doCreateArtifacts()) {
094            new ArtifactBuilder(this).execute();
095        }
096    }
097}