Skip to content

Commit

Permalink
Provide host IP to android device for integration tests
Browse files Browse the repository at this point in the history
Used so the device can hit a local git server running in the maven-running
host device.
  • Loading branch information
rtyley committed May 3, 2012
1 parent ab224e3 commit f1aa88c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 16 deletions.
40 changes: 40 additions & 0 deletions agit-integration-tests/pom.xml
Expand Up @@ -67,6 +67,46 @@
<extractDuplicates>true</extractDuplicates>
</configuration>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>get-local-ip</id>
<phase>initialize</phase>
<goals>
<goal>script</goal>
</goals>
<configuration>
<scalaVersion>2.9.1</scalaVersion>
<script>
import scala.collection.JavaConversions._
import com.android.ddmlib._

def run() {
val ipAddresses = java.net.NetworkInterface.getNetworkInterfaces().filter { !_.isLoopback }.flatMap { _.getInetAddresses }.map { _.getHostAddress }.mkString(",")
AndroidDebugBridge.init(false)
val androidDebugBridge = AndroidDebugBridge.createBridge
androidDebugBridge.getDevices.filter { !_.isEmulator } foreach { d =>
val command = "echo gitserver.host.address="+ipAddresses+" > "+d.getMountPoint(IDevice.MNT_EXTERNAL_STORAGE)+"/agit-integration-test.properties"

d.executeShellCommand(command, NullOutputReceiver.getReceiver)
}
println ("Provided host ip addresses : "+ipAddresses)
}
</script>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.android.ddmlib</groupId>
<artifactId>ddmlib</artifactId>
<version>r16</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
Expand Down
34 changes: 18 additions & 16 deletions agit-test-utils/src/main/java/com/madgag/agit/GitTestUtils.java
Expand Up @@ -19,12 +19,10 @@

package com.madgag.agit;

import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import android.os.Environment;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryCache;
import org.eclipse.jgit.storage.file.FileRepository;
import org.eclipse.jgit.transport.URIish;
import org.eclipse.jgit.util.FS;
import android.util.Log;

import java.io.File;
import java.io.FileNotFoundException;
Expand All @@ -35,27 +33,31 @@
import java.net.UnknownHostException;
import java.util.Properties;

import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryCache;
import org.eclipse.jgit.storage.file.FileRepository;
import org.eclipse.jgit.transport.URIish;
import org.eclipse.jgit.util.FS;

public class GitTestUtils {
public static final String RSA_USER = "rsa_user", DSA_USER = "dsa_user";
private static final String TAG = "GitTestUtils";

public static String gitServerHostAddress() throws IOException,
FileNotFoundException, UnknownHostException {
public static String gitServerHostAddress() throws IOException, UnknownHostException {
File bang = new File(Environment.getExternalStorageDirectory(),
"agit-integration-test.properties");
Properties properties = new Properties();
if (bang.exists()) {
properties.load(new FileReader(bang));
}
String hostAddress = properties.getProperty("gitserver.host.address",
"10.0.2.2");
InetAddress address = InetAddress.getByName(hostAddress);
assertThat("Test gitserver host " + hostAddress + " is reachable",
address.isReachable(1000), is(true));
return hostAddress;
String[] hostAddresses = properties.getProperty("gitserver.host.address", "10.0.2.2").split(",");
for (String hostAddress : hostAddresses) {
if (InetAddress.getByName(hostAddress).isReachable(1000)) {
Log.d(TAG, "Using git server host : "+hostAddress);
return hostAddress;
}
}
throw new RuntimeException("No reachable addresses in "+hostAddresses);
}

public static URIish integrationGitServerURIFor(String repoPath)
Expand Down

0 comments on commit f1aa88c

Please sign in to comment.