All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jayway.maven.plugins.android.standalonemojos.ConnectMojo Maven / Gradle / Ivy

There is a newer version: 4.0.0-rc.2
Show newest version
package com.jayway.maven.plugins.android.standalonemojos;

import com.jayway.maven.plugins.android.AbstractAndroidMojo;
import com.jayway.maven.plugins.android.CommandExecutor;
import com.jayway.maven.plugins.android.ExecutionException;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;

import java.util.ArrayList;
import java.util.List;

/**
 * Connect external IP addresses to the ADB server.
 *
 * @author [email protected]
 */
@Mojo( name = "connect", requiresProject = false )
public class ConnectMojo extends AbstractAndroidMojo
{

    @Override
    public void execute() throws MojoExecutionException, MojoFailureException
    {

        if ( ips.length > 0 )
        {
            CommandExecutor executor = CommandExecutor.Factory.createDefaultCommmandExecutor();

            for ( String ip : ips )
            {
                getLog().debug( "Connecting " + ip );

                // It would be better to use the AndroidDebugBridge class 
                // rather than calling the command line tool
                String command = getAndroidSdk().getAdbPath();
                List parameters = new ArrayList();
                parameters.add( "connect" );
                parameters.add( ip );

                try
                {
                    executor.setCaptureStdOut( true );
                    executor.executeCommand( command, parameters );
                }
                catch ( ExecutionException e )
                {
                    throw new MojoExecutionException( String.format( "Can not connect %s", ip ), e );
                }
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy