1 /*
2 * The contents of this file are subject to the terms of the Common Development and
3 * Distribution License (the License). You may not use this file except in compliance with the
4 * License.
5 *
6 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
7 * specific language governing permission and limitations under the License.
8 *
9 * When distributing Covered Software, include this CDDL Header Notice in each file and include
10 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
11 * Header, with the fields enclosed by brackets [] replaced by your own identifying
12 * information: "Portions copyright [year] [name of copyright owner]".
13 *
14 * Copyright 2012-2014 ForgeRock AS
15 */
16
17 package org.forgerock.doc.maven.release;
18
19 import org.apache.commons.io.FileUtils;
20 import org.apache.maven.plugin.MojoExecutionException;
21 import org.forgerock.doc.maven.AbstractDocbkxMojo;
22
23 import java.io.File;
24 import java.io.IOException;
25
26 /**
27 * Replace CSS in release HTML.
28 */
29 public class Css {
30
31 /**
32 * The Mojo that holds configuration and related methods.
33 */
34 private AbstractDocbkxMojo m;
35
36 /**
37 * Constructor setting the Mojo that holds the configuration.
38 *
39 * @param mojo The Mojo that holds the configuration.
40 */
41 public Css(final AbstractDocbkxMojo mojo) {
42 m = mojo;
43 }
44
45 /**
46 * Replace CSS in release HTML.
47 *
48 * @throws MojoExecutionException Failed to replace CSS.
49 */
50 public void execute() throws MojoExecutionException {
51
52 final File newCss = m.getReleaseCss();
53 final File dir = new File(m.getReleaseVersionPath());
54 final String[] ext = {"css"};
55 final boolean isRecursive = true;
56
57 for (File oldCss : FileUtils.listFiles(dir, ext, isRecursive)) {
58 if (m.getPreSiteCss().getName().equals(oldCss.getName())) {
59 try {
60 FileUtils.copyFile(newCss, oldCss);
61 } catch (IOException e) {
62 throw new MojoExecutionException(e.getMessage(), e);
63 }
64 }
65 }
66 }
67 }