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.commons.io.IOUtils; 021import org.apache.maven.plugin.MojoExecutionException; 022import org.forgerock.doc.maven.AbstractDocbkxMojo; 023 024import java.io.File; 025import java.io.IOException; 026 027/** 028 * Add an index.html file to the release layout. 029 */ 030public class IndexHtml { 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 IndexHtml(final AbstractDocbkxMojo mojo) { 043 m = mojo; 044 } 045 046 /** 047 * Add an index.html file to the release layout. 048 * 049 * @throws MojoExecutionException Failed to copy file. 050 */ 051 public void execute() throws MojoExecutionException { 052 if (!m.keepCustomIndexHtml()) { 053 final File indexHtml = new File(m.getReleaseVersionPath(), "index.html"); 054 FileUtils.deleteQuietly(indexHtml); 055 056 try { 057 String content = IOUtils.toString(getClass().getResource("/dfo.index.html"), "UTF-8"); 058 content = content.replace("PRODUCT", m.getProjectName().toLowerCase()); 059 content = content.replace("VERSION", m.getReleaseVersion()); 060 061 FileUtils.writeStringToFile(indexHtml, content, "UTF-8"); 062 } catch (IOException e) { 063 throw new MojoExecutionException(e.getMessage(), e); 064 } 065 } 066 } 067}