Coverage Report - org.apache.maven.plugins.help.SystemMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
SystemMojo
0%
0/48
0%
0/12
10
 
 1  
 package org.apache.maven.plugins.help;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.io.IOException;
 23  
 import java.util.Date;
 24  
 import java.util.Iterator;
 25  
 import java.util.Properties;
 26  
 
 27  
 import org.apache.maven.plugin.MojoExecutionException;
 28  
 import org.codehaus.plexus.util.StringUtils;
 29  
 import org.codehaus.plexus.util.cli.CommandLineUtils;
 30  
 
 31  
 /**
 32  
  * Displays a list of the platform details like system properties and environment variables.
 33  
  *
 34  
  * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
 35  
  * @version $Id: SystemMojo.java 689770 2008-08-28 09:47:18Z vsiveton $
 36  
  * @since 2.1
 37  
  * @goal system
 38  
  * @requiresProject false
 39  
  */
 40  0
 public class SystemMojo
 41  
     extends AbstractHelpMojo
 42  
 {
 43  
     /** Magic number to beautify the output */
 44  
     private static final int REPEAT = 25;
 45  
 
 46  
     // ----------------------------------------------------------------------
 47  
     // Public methods
 48  
     // ----------------------------------------------------------------------
 49  
 
 50  
     /** {@inheritDoc} */
 51  
     public void execute()
 52  
         throws MojoExecutionException
 53  
     {
 54  0
         StringBuffer message = new StringBuffer();
 55  
 
 56  0
         message.append( '\n' );
 57  0
         message.append( StringUtils.repeat( "=", LINE_LENGTH ) ).append( '\n' );
 58  0
         message.append( StringUtils.repeat( "=", REPEAT ) );
 59  0
         message.append( " Platform Properties Details " );
 60  0
         message.append( StringUtils.repeat( "=", REPEAT ) ).append( '\n' );
 61  0
         message.append( StringUtils.repeat( "=", LINE_LENGTH ) ).append( '\n' );
 62  0
         message.append( '\n' );
 63  
 
 64  0
         message.append( StringUtils.repeat( "=", LINE_LENGTH ) ).append( '\n' );
 65  0
         message.append( "System Properties" ).append( '\n' );
 66  0
         message.append( StringUtils.repeat( "=", LINE_LENGTH ) ).append( '\n' );
 67  
 
 68  0
         Properties systemProperties = System.getProperties();
 69  0
         for ( Iterator it = systemProperties.keySet().iterator(); it.hasNext(); )
 70  
         {
 71  0
             String key = it.next().toString();
 72  0
             message.append( "\n" );
 73  0
             message.append( key ).append( "=" ).append( systemProperties.get( key ) );
 74  0
         }
 75  
 
 76  0
         message.append( '\n' ).append( '\n' );
 77  0
         message.append( StringUtils.repeat( "=", LINE_LENGTH ) ).append( '\n' );
 78  0
         message.append( "Environment Variables" ).append( '\n' );
 79  0
         message.append( StringUtils.repeat( "=", LINE_LENGTH ) ).append( '\n' );
 80  
         try
 81  
         {
 82  0
             Properties envVars = CommandLineUtils.getSystemEnvVars();
 83  0
             for ( Iterator it2 = envVars.keySet().iterator(); it2.hasNext(); )
 84  
             {
 85  0
                 String key = it2.next().toString();
 86  0
                 message.append( "\n" );
 87  0
                 message.append( key ).append( "=" ).append( envVars.get( key ) );
 88  0
             }
 89  
         }
 90  0
         catch ( IOException e )
 91  
         {
 92  0
             if ( getLog().isWarnEnabled() )
 93  
             {
 94  0
                 getLog().warn( "IOException: " + e.getMessage() );
 95  
             }
 96  0
         }
 97  
 
 98  0
         message.append( "\n" );
 99  
 
 100  0
         if ( output != null )
 101  
         {
 102  0
             StringBuffer sb = new StringBuffer();
 103  0
             sb.append( "Created by: " + getClass().getName() ).append( "\n" );
 104  0
             sb.append( "Created on: " + new Date() ).append( "\n" ).append( "\n" );
 105  0
             sb.append( message.toString() );
 106  
 
 107  
             try
 108  
             {
 109  0
                 writeFile( output, sb );
 110  
             }
 111  0
             catch ( IOException e )
 112  
             {
 113  0
                 throw new MojoExecutionException( "Cannot write system report to output: " + output, e );
 114  0
             }
 115  
 
 116  0
             if ( getLog().isInfoEnabled() )
 117  
             {
 118  0
                 getLog().info( "System report written to: " + output );
 119  
             }
 120  0
         }
 121  
         else
 122  
         {
 123  0
             if ( getLog().isInfoEnabled() )
 124  
             {
 125  0
                 getLog().info( message );
 126  
             }
 127  
         }
 128  0
     }
 129  
 }