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 2014 ForgeRock AS 015 */ 016 017package org.forgerock.doc.maven.release; 018 019import org.apache.commons.io.IOUtils; 020import org.apache.maven.plugin.MojoExecutionException; 021import org.forgerock.doc.maven.AbstractDocbkxMojo; 022import org.forgerock.doc.maven.utils.HtmlUtils; 023 024import java.io.IOException; 025import java.util.HashMap; 026 027/** 028 * Remove robots meta tag in release HTML. 029 */ 030public class Robots { 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 Robots(final AbstractDocbkxMojo mojo) { 043 m = mojo; 044 } 045 046 /** 047 * Remove robots meta tag in release HTML. 048 * 049 * @throws MojoExecutionException Failed to remove tags. 050 */ 051 public void execute() throws MojoExecutionException { 052 053 HashMap<String, String> replacements = new HashMap<String, String>(); 054 055 try { 056 final String robots = IOUtils.toString( 057 getClass().getResourceAsStream("/robots.txt"), "UTF-8"); 058 059 replacements.put(robots, ""); // Replace the tag with an empty string. 060 HtmlUtils.updateHtml(m.getReleaseVersionPath(), replacements); 061 } catch (IOException e) { 062 throw new MojoExecutionException(e.getMessage(), e); 063 } 064 } 065}