You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2010/07/02 00:18:11 UTC
svn commit: r959796 - in /maven/plugins/branches/maven-site-plugin-3.x:
pom.xml src/main/java/org/apache/maven/plugins/site/EffectiveSiteMojo.java
src/site/apt/index.apt
Author: hboutemy
Date: Thu Jul 1 22:18:10 2010
New Revision: 959796
URL: http://svn.apache.org/viewvc?rev=959796&view=rev
Log:
[MSITE-465] added site:effective-site goal (similar to help:effective-pom) (merged from trunk r959794)
Added:
maven/plugins/branches/maven-site-plugin-3.x/src/main/java/org/apache/maven/plugins/site/EffectiveSiteMojo.java (with props)
Modified:
maven/plugins/branches/maven-site-plugin-3.x/pom.xml
maven/plugins/branches/maven-site-plugin-3.x/src/site/apt/index.apt
Modified: maven/plugins/branches/maven-site-plugin-3.x/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-site-plugin-3.x/pom.xml?rev=959796&r1=959795&r2=959796&view=diff
==============================================================================
--- maven/plugins/branches/maven-site-plugin-3.x/pom.xml (original)
+++ maven/plugins/branches/maven-site-plugin-3.x/pom.xml Thu Jul 1 22:18:10 2010
@@ -365,7 +365,7 @@ under the License.
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
- <version>1.5.1</version>
+ <version>1.5.10</version>
</dependency>
<dependency>
Added: maven/plugins/branches/maven-site-plugin-3.x/src/main/java/org/apache/maven/plugins/site/EffectiveSiteMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-site-plugin-3.x/src/main/java/org/apache/maven/plugins/site/EffectiveSiteMojo.java?rev=959796&view=auto
==============================================================================
--- maven/plugins/branches/maven-site-plugin-3.x/src/main/java/org/apache/maven/plugins/site/EffectiveSiteMojo.java (added)
+++ maven/plugins/branches/maven-site-plugin-3.x/src/main/java/org/apache/maven/plugins/site/EffectiveSiteMojo.java Thu Jul 1 22:18:10 2010
@@ -0,0 +1,207 @@
+package org.apache.maven.plugins.site;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+
+import org.apache.maven.doxia.site.decoration.DecorationModel;
+import org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Writer;
+import org.apache.maven.doxia.siterenderer.SiteRenderingContext;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.WriterFactory;
+import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
+import org.codehaus.plexus.util.xml.XMLWriter;
+import org.codehaus.plexus.util.xml.XmlWriterUtil;
+
+/**
+ * Displays the effective site descriptor as an XML for this build, after inheritance and interpolation of
+ * <code>site.xml</code>.
+ *
+ * @author <a href="mailto:hboutemy@apache.org">Hervé Boutemy</a>
+ * @version $Id$
+ * @goal effective-site
+ */
+public class EffectiveSiteMojo
+ extends AbstractSiteRenderingMojo
+{
+ /**
+ * Optional parameter to write the output of this help in a given file, instead of writing to the console.
+ * <br/>
+ * <b>Note</b>: Could be a relative path.
+ *
+ * @parameter expression="${output}"
+ */
+ protected File output;
+
+ /**
+ * {@inheritDoc}
+ */
+ public void execute()
+ throws MojoExecutionException, MojoFailureException
+ {
+ String effectiveSite;
+
+ try
+ {
+ List<Locale> localesList = siteTool.getAvailableLocales( locales );
+
+ SiteRenderingContext context = createSiteRenderingContext( localesList.get( 0 ) );
+
+ DecorationModel decorationModel = context.getDecoration();
+
+ StringWriter w = new StringWriter();
+ XMLWriter writer =
+ new PrettyPrintXMLWriter( w, StringUtils.repeat( " ", XmlWriterUtil.DEFAULT_INDENTATION_SIZE ),
+ decorationModel.getModelEncoding(), null );
+
+ writeHeader( writer );
+
+ writeEffectiveSite( decorationModel, writer );
+
+ effectiveSite = w.toString();
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( "Error during site descriptor calculation", e );
+ }
+
+ if ( output != null )
+ {
+ try
+ {
+ writeXmlFile( output, effectiveSite );
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( "Cannot write effective site descriptor to output: " + output, e );
+ }
+
+ if ( getLog().isInfoEnabled() )
+ {
+ getLog().info( "Effective site descriptor written to: " + output );
+ }
+ }
+ else
+ {
+ StringBuffer message = new StringBuffer();
+
+ message.append( "\nEffective site descriptor, after inheritance and interpolation:\n\n" );
+ message.append( effectiveSite );
+ message.append( "\n" );
+
+ if ( getLog().isInfoEnabled() )
+ {
+ getLog().info( message.toString() );
+ }
+ }
+ }
+
+ /**
+ * Write comments in the Effective POM/settings header.
+ *
+ * @param writer not null
+ */
+ protected static void writeHeader( XMLWriter writer )
+ {
+ XmlWriterUtil.writeCommentLineBreak( writer );
+ XmlWriterUtil.writeComment( writer, " " );
+ // Use ISO8601-format for date and time
+ DateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd'T'hh:mm:ss" );
+ XmlWriterUtil.writeComment( writer,
+ "Generated by Maven Site Plugin on "
+ + dateFormat.format( new Date( System.currentTimeMillis() ) ) );
+ XmlWriterUtil.writeComment( writer, "See: http://maven.apache.org/plugins/maven-site-plugin/" );
+ XmlWriterUtil.writeComment( writer, " " );
+ XmlWriterUtil.writeCommentLineBreak( writer );
+
+ XmlWriterUtil.writeLineBreak( writer );
+ }
+
+ /**
+ * Write comments in a normalize way.
+ *
+ * @param writer not null
+ * @param comment not null
+ */
+ protected static void writeComment( XMLWriter writer, String comment )
+ {
+ XmlWriterUtil.writeCommentLineBreak( writer );
+ XmlWriterUtil.writeComment( writer, " " );
+ XmlWriterUtil.writeComment( writer, comment );
+ XmlWriterUtil.writeComment( writer, " " );
+ XmlWriterUtil.writeCommentLineBreak( writer );
+
+ XmlWriterUtil.writeLineBreak( writer );
+ }
+
+ private void writeEffectiveSite( DecorationModel decorationModel, XMLWriter writer )
+ throws MojoExecutionException
+ {
+ String effectiveSite;
+
+ StringWriter sWriter = new StringWriter();
+ DecorationXpp3Writer siteWriter = new DecorationXpp3Writer();
+ try
+ {
+ siteWriter.write( sWriter, decorationModel );
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( "Cannot serialize site descriptor to XML.", e );
+ }
+
+ effectiveSite = sWriter.toString();
+
+ writeComment( writer, "Effective site descriptor for project \'" + project.getId() + "\'" );
+
+ writer.writeMarkup( effectiveSite );
+ }
+
+ protected static void writeXmlFile( File output, String content )
+ throws IOException
+ {
+ Writer out = null;
+ try
+ {
+ output.getParentFile().mkdirs();
+
+ out = WriterFactory.newXmlWriter( output );
+
+ out.write( content );
+
+ out.flush();
+ }
+ finally
+ {
+ IOUtil.close( out );
+ }
+ }
+}
Propchange: maven/plugins/branches/maven-site-plugin-3.x/src/main/java/org/apache/maven/plugins/site/EffectiveSiteMojo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/branches/maven-site-plugin-3.x/src/main/java/org/apache/maven/plugins/site/EffectiveSiteMojo.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: maven/plugins/branches/maven-site-plugin-3.x/src/main/java/org/apache/maven/plugins/site/EffectiveSiteMojo.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: maven/plugins/branches/maven-site-plugin-3.x/src/site/apt/index.apt
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-site-plugin-3.x/src/site/apt/index.apt?rev=959796&r1=959795&r2=959796&view=diff
==============================================================================
--- maven/plugins/branches/maven-site-plugin-3.x/src/site/apt/index.apt (original)
+++ maven/plugins/branches/maven-site-plugin-3.x/src/site/apt/index.apt Thu Jul 1 22:18:10 2010
@@ -59,6 +59,9 @@ Maven Site Plugin
* {{{./jar-mojo.html}site:jar}} bundles the site output into a JAR so that it can be deployed to a repository.
+ * {{{./effective-site-mojo.html}site:effective-site}} calculates effective site descriptor, after inheritance and
+ interpolation.
+
* Usage
General instructions on how to use the Site Plugin can be found on the {{{./usage.html}usage page}}. Some more