From 191868148d5a7ab8955ad87142675c3aba794c74 Mon Sep 17 00:00:00 2001 From: Andy Piper Date: Mon, 7 Dec 2015 15:34:41 +0000 Subject: [PATCH 1/3] Fix connect and disconnect to do the right thing. --- .../android/standalonemojos/ConnectMojo.java | 21 +++++++++++++++---- .../standalonemojos/DisconnectMojo.java | 4 +++- 2 files changed, 20 insertions(+), 5 deletions(-) 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..eefdd60cb 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 @@ -27,22 +27,35 @@ 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( "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 ); + // ... now put in wireless mode ... + String hostport[] = ip.split( ":" ); + parameters.add( "tcpip" ); + parameters.add( hostport[1] ); + executor.setCaptureStdOut( true ); + executor.executeCommand( command, parameters ); + // ... and finally connect + parameters.clear(); + parameters.add( "connect" ); + parameters.add( ip ); + executor.executeCommand( command, parameters ); } catch ( ExecutionException e ) { @@ -51,4 +64,4 @@ public void execute() throws MojoExecutionException, MojoFailureException } } } -} \ No newline at end of file +} 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..5e0116afd 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(); @@ -50,4 +52,4 @@ public void execute() throws MojoExecutionException, MojoFailureException } } } -} \ No newline at end of file +} From d6a2da2abb946fddb4438d292c42e9de15b1fac4 Mon Sep 17 00:00:00 2001 From: Andy Piper Date: Fri, 11 Dec 2015 11:18:39 +0000 Subject: [PATCH 2/3] Make sure kill-server goes on a separate command. --- .../maven/plugins/android/standalonemojos/ConnectMojo.java | 1 + 1 file changed, 1 insertion(+) 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 eefdd60cb..889250996 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 @@ -45,6 +45,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { executor.setCaptureStdOut( true ); executor.executeCommand( command, parameters ); + parameters.clear(); // ... now put in wireless mode ... String hostport[] = ip.split( ":" ); parameters.add( "tcpip" ); From 6e8f59c64794d6d0dc828b4304f032a80647f573 Mon Sep 17 00:00:00 2001 From: Andy Piper Date: Fri, 11 Dec 2015 14:03:51 +0000 Subject: [PATCH 3/3] plexus-utils version wasn't quoting the command-line properly. Account for stderr output when connecting. --- pom.xml | 2 +- .../android/standalonemojos/ConnectMojo.java | 30 ++++++++++++++----- .../standalonemojos/DisconnectMojo.java | 2 +- 3 files changed, 24 insertions(+), 10 deletions(-) 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 889250996..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,8 +26,7 @@ public void execute() throws MojoExecutionException, MojoFailureException if ( ips.length > 0 ) { - CommandExecutor executor = CommandExecutor.Factory.createDefaultCommmandExecutor(); - executor.setLogger( this.getLog() ); + CommandExecutor executor = getExecutor(); for ( String ip : ips ) { @@ -43,20 +42,27 @@ public void execute() throws MojoExecutionException, MojoFailureException 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.setCaptureStdOut( true ); - executor.executeCommand( command, parameters ); - // ... and finally connect + executor.executeCommand( command, parameters, false ); parameters.clear(); + // ... and finally really connect + executor = getExecutor(); parameters.add( "connect" ); parameters.add( ip ); - executor.executeCommand( command, parameters ); + executor.executeCommand( command, parameters, false ); } catch ( ExecutionException e ) { @@ -65,4 +71,12 @@ public void execute() throws MojoExecutionException, MojoFailureException } } } + + 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 5e0116afd..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 @@ -43,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 ) {