Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.apache.maven.plugins.help;
  
  /*
   * 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.util.List;
Displays the effective POM as an XML for this build, with the active profiles factored in.

Version:
$Id: EffectivePomMojo.java 1423092 2012-12-17 18:53:49Z hboutemy $
Since:
2.0
 
 @Mojo( name = "effective-pom", aggregator = true )
 public class EffectivePomMojo
     extends AbstractEffectiveMojo
 {
     // ----------------------------------------------------------------------
     // Mojo parameters
     // ----------------------------------------------------------------------
 
    
The Maven project.

Since:
2.0.2
 
     @Component
     private MavenProject project;

    
The projects in the current build. The effective-POM for each of these projects will written.
 
     @Parameter( defaultValue = "${reactorProjects}", required = true, readonly = true )
     private List<MavenProjectprojects;
 
     // ----------------------------------------------------------------------
     // Public methods
     // ----------------------------------------------------------------------
 
    
 
     public void execute()
         throws MojoExecutionException
     {
         StringWriter w = new StringWriter();
         XMLWriter writer =
             new PrettyPrintXMLWriterw, StringUtils.repeat" ". ),
                                       .getModel().getModelEncoding(), null );
 
         writeHeaderwriter );
 
         String effectivePom;
         if ( .get( 0 ).equals ) && .size() > 1 )
         {
             // outer root element
             writer.startElement"projects" );
             for ( MavenProject subProject :  )
             {
                 writeEffectivePomsubProjectwriter );
             }
             writer.endElement();
 
            effectivePom = w.toString();
            effectivePom = prettyFormateffectivePom );
        }
        else
        {
            writeEffectivePomwriter );
            effectivePom = w.toString();
        }
        if (  != null )
        {
            try
            {
                writeXmlFileeffectivePom.getModel().getModelEncoding() );
            }
            catch ( IOException e )
            {
                throw new MojoExecutionException"Cannot write effective-POM to output: " + e );
            }
            if ( getLog().isInfoEnabled() )
            {
                getLog().info"Effective-POM written to: " +  );
            }
        }
        else
        {
            StringBuilder message = new StringBuilder();
            message.append"\nEffective POMs, after inheritance, interpolation, and profiles are applied:\n\n" );
            message.appendeffectivePom );
            message.append"\n" );
            if ( getLog().isInfoEnabled() )
            {
                getLog().infomessage.toString() );
            }
        }
    }
    // ----------------------------------------------------------------------
    // Private methods
    // ----------------------------------------------------------------------

    
Method for writing the effective pom informations of the current build.

Parameters:
project the project of the current build, not null.
writer the XML writer , not null, not null.
Throws:
org.apache.maven.plugin.MojoExecutionException if any
    private static void writeEffectivePomMavenProject projectXMLWriter writer )
        throws MojoExecutionException
    {
        Model pom = project.getModel();
        cleanModelpom );
        String effectivePom;
        StringWriter sWriter = new StringWriter();
        MavenXpp3Writer pomWriter = new MavenXpp3Writer();
        try
        {
            pomWriter.writesWriterpom );
        }
        catch ( IOException e )
        {
            throw new MojoExecutionException"Cannot serialize POM to XML."e );
        }
        effectivePom = addMavenNamespacesWriter.toString(), true );
        writeCommentwriter"Effective POM for project \'" + project.getId() + "\'" );
        writer.writeMarkupeffectivePom );
    }

    
Apply some logic to clean the model before writing it.

Parameters:
pom not null
    private static void cleanModelModel pom )
    {
        Properties properties = new SortedProperties();
        properties.putAllpom.getProperties() );
        pom.setPropertiesproperties );
    }

    

Parameters:
effectivePom not null
Returns:
pretty format of the xml or the original effectivePom if an error occurred.
    private static String prettyFormatString effectivePom )
    {
        SAXBuilder builder = new SAXBuilder();
        try
        {
            Document effectiveDocument = builder.buildnew StringReadereffectivePom ) );
            StringWriter w = new StringWriter();
            Format format = Format.getPrettyFormat();
            XMLOutputter out = new XMLOutputterformat );
            out.outputeffectiveDocumentw );
            return w.toString();
        }
        catch ( JDOMException e )
        {
            return effectivePom;
        }
        catch ( IOException e )
        {
            return effectivePom;
        }
    }
New to GrepCode? Check out our FAQ X