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 2012-2014 ForgeRock AS 015 */ 016 017package org.forgerock.doc.maven.pre; 018 019import org.apache.commons.io.FileUtils; 020import org.apache.maven.plugin.MojoExecutionException; 021import org.forgerock.doc.maven.AbstractDocbkxMojo; 022 023import java.io.File; 024import java.io.IOException; 025 026/** 027 * Make a modifiable copy of the documentation source files, 028 * rather than working directly on the original source files. 029 */ 030public class ModifiableCopy { 031 032 /** 033 * The Mojo that holds configuration and related methods. 034 */ 035 private AbstractDocbkxMojo m; 036 037 /** 038 * Constructor setting the Mojo that holds the configuration. 039 * 040 * @param mojo The Mojo that holds the configuration. 041 */ 042 public ModifiableCopy(final AbstractDocbkxMojo mojo) { 043 m = mojo; 044 } 045 046 /** 047 * Make a modifiable copy of the original DocBook XML source files. 048 * 049 * @throws MojoExecutionException Failed to copy sources. 050 */ 051 public void execute() throws MojoExecutionException { 052 053 final File sourceDir = m.getDocbkxSourceDirectory(); 054 final File outputDir = m.getDocbkxModifiableSourcesDirectory(); 055 056 try { 057 if (m.doOverwriteModifiableCopy()) { 058 FileUtils.copyDirectory(sourceDir, outputDir); 059 } 060 } catch (IOException e) { 061 throw new MojoExecutionException("Failed to copy sources", e); 062 } 063 } 064}