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