View Javadoc
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   * Disconnect external IP addresses from the ADB server.
16   *
17   * @author demey.emmanuel@gmail.com
18   */
19  @Mojo( name = "disconnect", requiresProject = false )
20  public class DisconnectMojo extends AbstractAndroidMojo
21  {
22      @Override
23      public void execute() throws MojoExecutionException, MojoFailureException
24      {
25          if ( ips.length > 0 )
26          {
27              CommandExecutor executor = CommandExecutor.Factory.createDefaultCommmandExecutor();
28              executor.setLogger( this.getLog() );
29  
30              for ( String ip : ips )
31              {
32                  getLog().debug( "Disconnecting " + ip );
33  
34  
35                  // It would be better to use the AndroidDebugBridge class 
36                  // rather than calling the command line tool
37                  String command = getAndroidSdk().getAdbPath();
38  
39                  List<String> parameters = new ArrayList<String>();
40                  parameters.add( "disconnect" );
41                  parameters.add( ip );
42  
43                  try
44                  {
45                      executor.setCaptureStdOut( true );
46                      executor.executeCommand( command, parameters, false );
47                  }
48                  catch ( ExecutionException e )
49                  {
50                      throw new MojoExecutionException( String.format( "Can not disconnect %s", ip ), e );
51                  }
52              }
53          }
54      }
55  }