Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix connect and disconnect to not throw NPE #702

Merged
merged 3 commits into from
Jan 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.0.15</version>
<version>3.0.21</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> parameters = new ArrayList<String>();
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 )
{
Expand All @@ -51,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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 )
{
Expand All @@ -50,4 +52,4 @@ public void execute() throws MojoExecutionException, MojoFailureException
}
}
}
}
}