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.pre;
018
019import org.apache.maven.plugin.MojoExecutionException;
020import org.forgerock.doc.maven.AbstractDocbkxMojo;
021import org.forgerock.doc.maven.utils.Profiler;
022
023import java.io.IOException;
024
025/**
026 * Applies profiling to the modifiable copy of DocBook XML sources.
027 */
028public class ConditionalText {
029
030    /**
031     * The Mojo that holds configuration and related methods.
032     */
033    private AbstractDocbkxMojo m;
034
035    /**
036     * Constructor setting the Mojo that holds the configuration.
037     *
038     * @param mojo The Mojo that holds the configuration.
039     */
040    public ConditionalText(final AbstractDocbkxMojo mojo) {
041        m = mojo;
042    }
043
044    /**
045     * Applies profiling to the modifiable copy of DocBook XML sources.
046     *
047     * @throws MojoExecutionException   Failed to apply profiling to an XML file.
048     */
049    public void execute() throws MojoExecutionException {
050
051        try {
052            Profiler profiler = new Profiler(m.getInclusions(), m.getExclusions());
053            profiler.applyProfiles(m.getDocbkxModifiableSourcesDirectory());
054        } catch (IOException e) {
055            throw new MojoExecutionException("Failed to apply profiling.", e);
056        }
057    }
058}