1 package com.simpligility.maven.plugins.android.standalonemojos;
2
3 import com.simpligility.maven.plugins.android.AbstractAndroidMojo;
4 import com.simpligility.maven.plugins.android.CommandExecutor;
5 import com.simpligility.maven.plugins.android.ExecutionException;
6
7 import org.apache.maven.plugin.MojoExecutionException;
8 import org.apache.maven.plugin.MojoFailureException;
9 import org.apache.maven.plugins.annotations.Mojo;
10
11 import java.util.ArrayList;
12 import java.util.List;
13
14
15
16
17
18
19 @Mojo( name = "connect", requiresProject = false )
20 public class ConnectMojo extends AbstractAndroidMojo
21 {
22
23 @Override
24 public void execute() throws MojoExecutionException, MojoFailureException
25 {
26
27 if ( ips.length > 0 )
28 {
29 CommandExecutor executor = getExecutor();
30
31 for ( String ip : ips )
32 {
33 getLog().debug( "Connecting " + ip );
34
35
36
37 String command = getAndroidSdk().getAdbPath();
38
39
40 List<String> parameters = new ArrayList<String>();
41 parameters.add( "kill-server" );
42
43 try
44 {
45 executor.executeCommand( command, parameters, false );
46 parameters.clear();
47
48
49 executor = getExecutor();
50 parameters.add( "connect" );
51 parameters.add( ip );
52 executor.executeCommand( command, parameters, false );
53 parameters.clear();
54
55 executor = getExecutor();
56 String hostport[] = ip.split( ":" );
57 parameters.add( "tcpip" );
58 parameters.add( hostport[1] );
59 executor.executeCommand( command, parameters, false );
60 parameters.clear();
61
62 executor = getExecutor();
63 parameters.add( "connect" );
64 parameters.add( ip );
65 executor.executeCommand( command, parameters, false );
66 }
67 catch ( ExecutionException e )
68 {
69 throw new MojoExecutionException( String.format( "Can not connect %s", ip ), e );
70 }
71 }
72 }
73 }
74
75 private CommandExecutor getExecutor()
76 {
77 CommandExecutor executor = CommandExecutor.Factory.createDefaultCommmandExecutor();
78 executor.setLogger( this.getLog() );
79 executor.setCaptureStdOut( true );
80 return executor;
81 }
82 }