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 | 4 | 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 | 0 | InvocationRequest request = new DefaultInvocationRequest(); |
53 | 0 | request.activateReactor( reactorIncludes, null); |
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 | |
} |