Coverage Report - org.apache.maven.plugin.coreit.ParameterImplementationMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
ParameterImplementationMojo
0 %
0/17
0 %
0/2
4
 
 1  
 package org.apache.maven.plugin.coreit;
 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.File;
 23  
 import java.io.FileOutputStream;
 24  
 import java.io.IOException;
 25  
 import java.util.Properties;
 26  
 
 27  
 import org.apache.maven.plugin.AbstractMojo;
 28  
 import org.apache.maven.plugin.MojoExecutionException;
 29  
 
 30  
 /**
 31  
  * Check that we correctly use the implementation parameter.
 32  
  *
 33  
  * @goal param-implementation
 34  
  */
 35  0
 public class ParameterImplementationMojo
 36  
     extends AbstractMojo
 37  
 {
 38  
 
 39  
     /**
 40  
      * The path to the properties file for the parameter information.
 41  
      * 
 42  
      * @parameter
 43  
      */
 44  
     private File outputFile;
 45  
 
 46  
     /**
 47  
      * A parameter whose type is an interface but with a default implementation class.
 48  
      * 
 49  
      * @parameter implementation="org.apache.maven.plugin.coreit.sub.AnImplementation"
 50  
      */
 51  
     private AnInterface theParameter;
 52  
 
 53  
     public void execute()
 54  
         throws MojoExecutionException
 55  
     {
 56  0
         Properties props = new Properties();
 57  
 
 58  0
         if ( theParameter != null )
 59  
         {
 60  0
             getLog().info( "[MAVEN-CORE-IT-LOG] theParameter = " + theParameter );
 61  
 
 62  0
             props.setProperty( "theParameter.class", theParameter.getClass().getName() );
 63  0
             props.setProperty( "theParameter.string", theParameter.toString() );
 64  
         }
 65  
 
 66  0
         getLog().info( "[MAVEN-CORE-IT-LOG] Creating output file " + outputFile );
 67  
 
 68  
         try
 69  
         {
 70  0
             outputFile.getParentFile().mkdirs();
 71  
 
 72  0
             FileOutputStream os = new FileOutputStream( outputFile );
 73  
             try
 74  
             {
 75  0
                 props.store( os, "[MAVEN-CORE-IT-LOG]" );
 76  
             }
 77  
             finally
 78  
             {
 79  0
                 os.close();
 80  0
             }
 81  
         }
 82  0
         catch ( IOException e )
 83  
         {
 84  0
             throw new MojoExecutionException( "Failed to create output file " + outputFile + ": " + e.getMessage(), e );
 85  0
         }
 86  
 
 87  0
         getLog().info( "[MAVEN-CORE-IT-LOG] Created output file " + outputFile );
 88  0
     }
 89  
 
 90  
 }