1 package org.codehaus.mojo.wagon;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.plugin.MojoExecutionException;
23 import org.apache.maven.plugins.annotations.Mojo;
24 import org.apache.maven.plugins.annotations.Parameter;
25 import org.apache.maven.wagon.CommandExecutor;
26 import org.apache.maven.wagon.Streams;
27 import org.apache.maven.wagon.Wagon;
28 import org.apache.maven.wagon.WagonException;
29 import org.apache.maven.wagon.providers.ssh.jsch.AbstractJschWagon;
30
31
32
33
34 @Mojo( name = "sshexec")
35 public class SshExecMojo
36 extends AbstractSingleWagonMojo
37 {
38
39
40
41
42 @Parameter(required = true)
43 private String[] commands;
44
45
46
47
48 @Parameter(defaultValue = "true")
49 private boolean failOnError = true;
50
51
52
53
54 @Parameter(defaultValue = "false")
55 private boolean displayCommandOutputs = true;
56
57 @Override
58 protected void execute( final Wagon wagon )
59 throws MojoExecutionException
60 {
61 if ( commands != null )
62 {
63 for ( String command : commands )
64 {
65 try
66 {
67 Streams stream;
68 if ( wagon instanceof AbstractJschWagon )
69 {
70 stream = ( (AbstractJschWagon) wagon ).executeCommand( command, true, false );
71 } else
72 {
73 stream = ( (CommandExecutor) wagon ).executeCommand( command, false );
74 }
75 this.getLog().info( "sshexec: " + command + " ..." );
76 if ( displayCommandOutputs )
77 {
78 System.out.println( stream.getOut() );
79 System.out.println( stream.getErr() );
80 }
81 } catch ( final WagonException e )
82 {
83 if ( this.failOnError )
84 {
85 throw new MojoExecutionException( "Unable to execute remote command", e );
86 }
87 else
88 {
89 this.getLog().warn( e );
90 }
91 }
92
93 }
94 }
95 }
96 }