Coverage Report - org.apache.maven.plugin.coreit.AbstractPomMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractPomMojo
0 %
0/19
0 %
0/4
2,333
 
 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 org.apache.maven.plugin.AbstractMojo;
 23  
 import org.apache.maven.plugin.MojoExecutionException;
 24  
 import org.apache.maven.project.MavenProject;
 25  
 import org.apache.maven.project.MavenProjectBuilder;
 26  
 
 27  
 import java.io.File;
 28  
 import java.io.FileOutputStream;
 29  
 import java.io.IOException;
 30  
 import java.util.Properties;
 31  
 
 32  
 /**
 33  
  * @author Benjamin Bentmann
 34  
  */
 35  0
 public abstract class AbstractPomMojo
 36  
     extends AbstractMojo
 37  
 {
 38  
 
 39  
     /**
 40  
      * The project builder.
 41  
      * 
 42  
      * @component
 43  
      */
 44  
     protected MavenProjectBuilder builder;
 45  
 
 46  
     protected void dump( Properties props, String key, MavenProject project )
 47  
     {
 48  0
         put( props, key + "project.id", project.getId() );
 49  0
         put( props, key + "project.name", project.getName() );
 50  0
         put( props, key + "project.description", project.getDescription() );
 51  0
         if ( project.getArtifact() != null )
 52  
         {
 53  0
             put( props, key + "artifact.id", project.getArtifact().getId() );
 54  
         }
 55  0
     }
 56  
 
 57  
     protected void put( Properties props, String key, Object value )
 58  
     {
 59  0
         if ( value != null )
 60  
         {
 61  0
             props.setProperty( key, value.toString() );
 62  
         }
 63  0
     }
 64  
 
 65  
     protected void store( Properties props, File file )
 66  
         throws MojoExecutionException
 67  
     {
 68  
         try
 69  
         {
 70  0
             file.getParentFile().mkdirs();
 71  
 
 72  0
             FileOutputStream os = new FileOutputStream( file );
 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 dump POMs: " + e.getMessage(), e );
 85  0
         }
 86  0
     }
 87  
 
 88  
 }