1 package org.apache.maven.plugin.reactor;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
34
35
36
37
38 public class SimpleInvoker
39 {
40
41
42
43
44
45
46
47
48
49 void runReactor( String[] reactorIncludes, List goalList, Invoker invoker, boolean printOnly, Log log )
50 throws InvokerExecutionException
51 {
52 InvocationRequest request = new DefaultInvocationRequest();
53 request.activateReactor( reactorIncludes, null
54 request.setGoals( goalList );
55 request.setRecursive( false );
56 try
57 {
58 log.info( "Executing: " + new MavenCommandLineBuilder().build( request ) );
59 }
60 catch ( CommandLineConfigurationException e )
61 {
62 throw new InvokerExecutionException( "Failed to display command line", e );
63 }
64
65 if ( !printOnly )
66 {
67 try
68 {
69 InvocationResult result = invoker.execute( request );
70 if ( result.getExecutionException() != null )
71 throw result.getExecutionException();
72 if ( result.getExitCode() != 0 )
73 throw new InvokerExecutionException( "Exit code was " + result.getExitCode() );
74 }
75 catch ( Exception e )
76 {
77 throw new InvokerExecutionException( "Maven build failed: " + e.getLocalizedMessage(), e );
78 }
79 }
80 }
81
82 class InvokerExecutionException extends MojoExecutionException {
83
84 private static final long serialVersionUID = 1L;
85
86 public InvokerExecutionException( Object source, String shortMessage, String longMessage )
87 {
88 super( source, shortMessage, longMessage );
89 }
90
91 public InvokerExecutionException( String message, Exception cause )
92 {
93 super( message, cause );
94 }
95
96 public InvokerExecutionException( String message, Throwable cause )
97 {
98 super( message, cause );
99 }
100
101 public InvokerExecutionException( String message )
102 {
103 super( message );
104 }
105
106 }
107 }