Coverage Report - org.apache.maven.plugin.invoker.VerifyMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
VerifyMojo
0 %
0/22
0 %
0/8
11
 
 1  
 package org.apache.maven.plugin.invoker;
 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.plugin.MojoFailureException;
 25  
 import org.apache.maven.plugin.invoker.model.io.xpp3.BuildJobXpp3Reader;
 26  
 import org.codehaus.plexus.util.ReaderFactory;
 27  
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 28  
 
 29  
 import java.io.File;
 30  
 import java.io.IOException;
 31  
 
 32  
 /**
 33  
  * Checks the results of maven-invoker-plugin based integration tests and fails the build if any tests failed.
 34  
  *
 35  
  * @goal verify
 36  
  * @phase verify
 37  
  * @threadSafe
 38  
  * @author <a href="mailto:olamy@apache.org">olamy</a>
 39  
  * @since 1.4
 40  
  */
 41  0
 public class VerifyMojo extends AbstractMojo
 42  
 {
 43  
 
 44  
     /**
 45  
      * Flag used to suppress certain invocations. This is useful in tailoring the build using profiles.
 46  
      *
 47  
      * @parameter expression="${invoker.skip}" default-value="false"
 48  
      * @since 1.1
 49  
      */
 50  
     private boolean skipInvocation;
 51  
 
 52  
     /**
 53  
      * Base directory where all build reports are read from.
 54  
      *
 55  
      * @parameter expression="${invoker.reportsDirectory}" default-value="${project.build.directory}/invoker-reports"
 56  
      * @since 1.4
 57  
      */
 58  
     private File reportsDirectory;
 59  
 
 60  
     /**
 61  
      * A flag controlling whether failures of the sub builds should fail the main build, too. If set to
 62  
      * <code>true</code>, the main build will proceed even if one or more sub builds failed.
 63  
      *
 64  
      * @parameter expression="${maven.test.failure.ignore}" default-value="false"
 65  
      * @since 1.3
 66  
      */
 67  
     private boolean ignoreFailures;
 68  
 
 69  
     /**
 70  
      * Flag used to suppress the summary output notifying of successes and failures. If set to <code>true</code>, the
 71  
      * only indication of the build's success or failure will be the effect it has on the main build (if it fails, the
 72  
      * main build should fail as well).
 73  
      *
 74  
      * @parameter default-value="false"
 75  
      */
 76  
     private boolean suppressSummaries;
 77  
 
 78  
     /**
 79  
      * Invokes Maven on the configured test projects.
 80  
      *
 81  
      * @throws org.apache.maven.plugin.MojoExecutionException If the goal encountered severe errors.
 82  
      * @throws org.apache.maven.plugin.MojoFailureException If any of the Maven builds failed.
 83  
      */
 84  
     public void execute()
 85  
         throws MojoExecutionException, MojoFailureException
 86  
     {
 87  0
         if ( skipInvocation )
 88  
         {
 89  0
             getLog().info( "Skipping invocation per configuration."
 90  
                 + " If this is incorrect, ensure the skipInvocation parameter is not set to true." );
 91  0
             return;
 92  
         }
 93  
 
 94  0
         File[] reportFiles = ReportUtils.getReportFiles( reportsDirectory );
 95  0
         if ( reportFiles.length <= 0 )
 96  
         {
 97  0
             getLog().info( "No invoker report files found, nothing to check." );
 98  0
             return;
 99  
         }
 100  
 
 101  0
         InvokerSession invokerSession = new InvokerSession();
 102  0
         for ( int i = 0, size = reportFiles.length; i < size; i++ )
 103  
         {
 104  0
             File reportFile = reportFiles[i];
 105  
             try
 106  
             {
 107  0
                 BuildJobXpp3Reader reader = new BuildJobXpp3Reader();
 108  0
                 invokerSession.addJob( reader.read( ReaderFactory.newXmlReader( reportFile ) ) );
 109  
             }
 110  0
             catch ( XmlPullParserException e )
 111  
             {
 112  0
                 throw new MojoExecutionException( "Failed to parse report file: " + reportFile, e );
 113  
             }
 114  0
             catch ( IOException e )
 115  
             {
 116  0
                 throw new MojoExecutionException( "Failed to read report file: " + reportFile, e );
 117  0
             }
 118  
         }
 119  
 
 120  0
         if ( !suppressSummaries )
 121  
         {
 122  0
             invokerSession.logSummary( getLog(), ignoreFailures );
 123  
         }
 124  
 
 125  0
         invokerSession.handleFailures( getLog(), ignoreFailures );
 126  0
     }
 127  
 
 128  
 }