Coverage Report - org.apache.maven.plugin.reactor.SimpleInvoker
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleInvoker
10%
2/20
0%
0/6
2.8
SimpleInvoker$InvokerExecutionException
0%
0/12
N/A
2.8
 
 1  
 package org.apache.maven.plugin.reactor;
 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.util.List;
 23  
 
 24  
 import org.apache.maven.plugin.MojoExecutionException;
 25  
 import org.apache.maven.plugin.logging.Log;
 26  
 import org.apache.maven.shared.invoker.CommandLineConfigurationException;
 27  
 import org.apache.maven.shared.invoker.DefaultInvocationRequest;
 28  
 import org.apache.maven.shared.invoker.InvocationRequest;
 29  
 import org.apache.maven.shared.invoker.InvocationResult;
 30  
 import org.apache.maven.shared.invoker.Invoker;
 31  
 import org.apache.maven.shared.invoker.MavenCommandLineBuilder;
 32  
 
 33  
 /** Simplified wrapper for Maven invoker
 34  
  * 
 35  
  * @author <a href="mailto:dfabulich@apache.org">Dan Fabulich</a>
 36  
  *
 37  
  */
 38  4
 public class SimpleInvoker
 39  
 {
 40  
     /** Runs a "mvn --reactor" build with the specified includes
 41  
      * 
 42  
      * @param reactorIncludes the list of include patterns for --reactor
 43  
      * @param goalList the list of goals (you can also pass other flags in here; they're just command-line args)
 44  
      * @param invoker the Maven Invoker (let Maven provide to you as a component)
 45  
      * @param printOnly if true, don't actually run anything, just log a message
 46  
      * @param log logger
 47  
      * @throws InvokerExecutionException if build fails for any reason
 48  
      */
 49  
     void runReactor( String[] reactorIncludes, List goalList, Invoker invoker, boolean printOnly, Log log )
 50  
         throws InvokerExecutionException
 51  
     {
 52  0
         InvocationRequest request = new DefaultInvocationRequest();
 53  0
         request.activateReactor( reactorIncludes, null/* excludes */);
 54  0
         request.setGoals( goalList );
 55  0
         request.setRecursive( false );
 56  
         try
 57  
         {
 58  0
             log.info( "Executing: " + new MavenCommandLineBuilder().build( request ) );
 59  
         }
 60  0
         catch ( CommandLineConfigurationException e )
 61  
         {
 62  0
             throw new InvokerExecutionException( "Failed to display command line", e );
 63  0
         }
 64  
 
 65  0
         if ( !printOnly )
 66  
         {
 67  
             try
 68  
             {
 69  0
                 InvocationResult result = invoker.execute( request );
 70  0
                 if ( result.getExecutionException() != null )
 71  0
                     throw result.getExecutionException();
 72  0
                 if ( result.getExitCode() != 0 )
 73  0
                     throw new InvokerExecutionException( "Exit code was " + result.getExitCode() );
 74  
             }
 75  0
             catch ( Exception e )
 76  
             {
 77  0
                 throw new InvokerExecutionException( "Maven build failed: " + e.getLocalizedMessage(), e );
 78  0
             }
 79  
         }
 80  0
     }
 81  
     
 82  4
     class InvokerExecutionException extends MojoExecutionException {
 83  
 
 84  
         private static final long serialVersionUID = 1L;
 85  
 
 86  
         public InvokerExecutionException( Object source, String shortMessage, String longMessage )
 87  0
         {
 88  0
             super( source, shortMessage, longMessage );
 89  0
         }
 90  
 
 91  
         public InvokerExecutionException( String message, Exception cause )
 92  0
         {
 93  0
             super( message, cause );
 94  0
         }
 95  
 
 96  
         public InvokerExecutionException( String message, Throwable cause )
 97  0
         {
 98  0
             super( message, cause );
 99  0
         }
 100  
 
 101  
         public InvokerExecutionException( String message )
 102  0
         {
 103  0
             super( message );
 104  0
         }
 105  
         
 106  
     }
 107  
 }