diff --git a/pom.xml b/pom.xml index 2e564cfeb..42b0dd467 100644 --- a/pom.xml +++ b/pom.xml @@ -220,7 +220,7 @@ org.codehaus.plexus plexus-utils - 3.0.15 + 3.0.21 diff --git a/src/main/java/com/simpligility/maven/plugins/android/standalonemojos/ConnectMojo.java b/src/main/java/com/simpligility/maven/plugins/android/standalonemojos/ConnectMojo.java index 77de01c3a..85cee0948 100644 --- a/src/main/java/com/simpligility/maven/plugins/android/standalonemojos/ConnectMojo.java +++ b/src/main/java/com/simpligility/maven/plugins/android/standalonemojos/ConnectMojo.java @@ -26,23 +26,43 @@ public void execute() throws MojoExecutionException, MojoFailureException if ( ips.length > 0 ) { - CommandExecutor executor = CommandExecutor.Factory.createDefaultCommmandExecutor(); + CommandExecutor executor = getExecutor(); for ( String ip : ips ) { getLog().debug( "Connecting " + ip ); - // It would be better to use the AndroidDebugBridge class + // It would be better to use the AndroidDebugBridge class // rather than calling the command line tool String command = getAndroidSdk().getAdbPath(); + // We first have to the put the bridge in tcpip mode or else it will fail to connect + // First make sure everything is clean ... List parameters = new ArrayList(); - parameters.add( "connect" ); - parameters.add( ip ); + parameters.add( "kill-server" ); try { - executor.setCaptureStdOut( true ); - executor.executeCommand( command, parameters ); + executor.executeCommand( command, parameters, false ); + parameters.clear(); + // initial connect to get adb in the right frame of mind + // http://stackoverflow.com/questions/14899935/set-adb-in-tcp-ip-mode-device-not-found + executor = getExecutor(); + parameters.add( "connect" ); + parameters.add( ip ); + executor.executeCommand( command, parameters, false ); + parameters.clear(); + // ... now put in wireless mode ... + executor = getExecutor(); + String hostport[] = ip.split( ":" ); + parameters.add( "tcpip" ); + parameters.add( hostport[1] ); + executor.executeCommand( command, parameters, false ); + parameters.clear(); + // ... and finally really connect + executor = getExecutor(); + parameters.add( "connect" ); + parameters.add( ip ); + executor.executeCommand( command, parameters, false ); } catch ( ExecutionException e ) { @@ -51,4 +71,12 @@ public void execute() throws MojoExecutionException, MojoFailureException } } } -} \ No newline at end of file + + private CommandExecutor getExecutor() + { + CommandExecutor executor = CommandExecutor.Factory.createDefaultCommmandExecutor(); + executor.setLogger( this.getLog() ); + executor.setCaptureStdOut( true ); + return executor; + } +} diff --git a/src/main/java/com/simpligility/maven/plugins/android/standalonemojos/DisconnectMojo.java b/src/main/java/com/simpligility/maven/plugins/android/standalonemojos/DisconnectMojo.java index 1b2ad466c..59aea788d 100644 --- a/src/main/java/com/simpligility/maven/plugins/android/standalonemojos/DisconnectMojo.java +++ b/src/main/java/com/simpligility/maven/plugins/android/standalonemojos/DisconnectMojo.java @@ -25,11 +25,13 @@ public void execute() throws MojoExecutionException, MojoFailureException if ( ips.length > 0 ) { CommandExecutor executor = CommandExecutor.Factory.createDefaultCommmandExecutor(); + executor.setLogger( this.getLog() ); for ( String ip : ips ) { getLog().debug( "Disconnecting " + ip ); + // It would be better to use the AndroidDebugBridge class // rather than calling the command line tool String command = getAndroidSdk().getAdbPath(); @@ -41,7 +43,7 @@ public void execute() throws MojoExecutionException, MojoFailureException try { executor.setCaptureStdOut( true ); - executor.executeCommand( command, parameters ); + executor.executeCommand( command, parameters, false ); } catch ( ExecutionException e ) { @@ -50,4 +52,4 @@ public void execute() throws MojoExecutionException, MojoFailureException } } } -} \ No newline at end of file +}