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.release; 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 * Replace CSS in release HTML. 028 */ 029public class Css { 030 031 /** 032 * The Mojo that holds configuration and related methods. 033 */ 034 private AbstractDocbkxMojo m; 035 036 /** 037 * Constructor setting the Mojo that holds the configuration. 038 * 039 * @param mojo The Mojo that holds the configuration. 040 */ 041 public Css(final AbstractDocbkxMojo mojo) { 042 m = mojo; 043 } 044 045 /** 046 * Replace CSS in release HTML. 047 * 048 * @throws MojoExecutionException Failed to replace CSS. 049 */ 050 public void execute() throws MojoExecutionException { 051 052 final File newCss = m.getReleaseCss(); 053 final File dir = new File(m.getReleaseVersionPath()); 054 final String[] ext = {"css"}; 055 final boolean isRecursive = true; 056 057 for (File oldCss : FileUtils.listFiles(dir, ext, isRecursive)) { 058 if (m.getPreSiteCss().getName().equals(oldCss.getName())) { 059 try { 060 FileUtils.copyFile(newCss, oldCss); 061 } catch (IOException e) { 062 throw new MojoExecutionException(e.getMessage(), e); 063 } 064 } 065 } 066 } 067}