Skip to content

Commit

Permalink
Fixed issue 141. Tested it in Windows XP
Browse files Browse the repository at this point in the history
Fixed failing tests in windows
Add a Test for AbstractEmulatorMojo (for easy start/stop emulator testing)
  • Loading branch information
ursmurli committed Apr 14, 2011
1 parent 0d798dc commit 9901936
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 10 deletions.
Expand Up @@ -115,7 +115,7 @@ public abstract class AbstractEmulatorMojo extends AbstractAndroidMojo {
/**
* file name for the pid file.
*/
private static final String pidFileName = scriptFolder + "/maven-android-plugin-emulator.pid";
private static final String pidFileName = scriptFolder + System.getProperty("file.separator") + "maven-android-plugin-emulator.pid";

/**
* Are we running on a flavour of Windows.
Expand Down Expand Up @@ -205,7 +205,7 @@ private String getRunningEmulatorName() throws MojoExecutionException, Execution
*/
private String writeEmulatorStartScriptWindows() throws MojoExecutionException {

String filename = scriptFolder + "\\maven-android-plugin-emulator-start.bat";
String filename = scriptFolder + "\\maven-android-plugin-emulator-start.vbs";

File file = new File(filename);
PrintWriter writer = null;
Expand All @@ -217,10 +217,15 @@ private String writeEmulatorStartScriptWindows() throws MojoExecutionException {
// and others.
String command = assembleStartCommandLine();
String uniqueWindowTitle = "MavenAndroidPlugin-AVD" + parsedAvd;
writer.print("START /separate \"" + uniqueWindowTitle + "\" " + command);
writer.println();
writer.println("FOR /F \"tokens=2\" %%I in ('TASKLIST /NH /FI \"WINDOWTITLE eq " + uniqueWindowTitle + "\"' ) DO SET PID=%%I");
writer.println("ECHO %PID% > " + pidFileName);
writer.println("Dim oShell");
writer.println("Set oShell = WScript.CreateObject(\"WScript.shell\")");
String cmd = "cmd.exe /X /C START /SEPARATE \"\""
+ uniqueWindowTitle + "\"\" " + command.trim();
writer.println("oShell.run \"" + cmd + "\"");
writer.println("wscript.sleep 1000");
String cmd1 = "cmd.exe /X /C @ECHO OFF & FOR /F \"\"tokens=2\"\" %I in ('TASKLIST /NH /FI \"\"WINDOWTITLE eq "
+ uniqueWindowTitle + "\"\"') DO ECHO %I> " + pidFileName;
writer.println("oShell.run \"" + cmd1 + "\"");
} catch (IOException e) {
getLog().error("Failure writing file " + filename);
} finally {
Expand Down
Expand Up @@ -157,7 +157,7 @@ public String getPathForTool(String tool) {
for (String possiblePath : possiblePaths) {
File file = new File(possiblePath);
if (file.exists() && !file.isDirectory()){
return possiblePath;
return file.getAbsolutePath();
}
}

Expand Down
@@ -0,0 +1,35 @@
package com.jayway.maven.plugins.android;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

public class AbstractEmulatorMojoTest {

private AbstractEmulatorMojo mockMojo;

@Before
public void setUp() throws Exception {
mockMojo = new mockAbstractEmulatorMojo();
}

@Ignore
@Test
public final void testStartAndStopAndroidEmulator() throws MojoExecutionException {
mockMojo.startAndroidEmulator();
mockMojo.stopAndroidEmulator();
}

private class mockAbstractEmulatorMojo extends AbstractEmulatorMojo {

public void execute() throws MojoExecutionException,
MojoFailureException {
// TODO Auto-generated method stub

}

}

}
Expand Up @@ -42,20 +42,20 @@ public void setUp(){

@Test
public void givenToolAdbThenPathIsPlatformTools() {
final String pathForTool =sdkTestSupport.getSdk_with_platform_1_5().getPathForTool("adb");
final String pathForTool =sdkTestSupport.getSdk_with_platform_1_5().getPathForTool("adb").replaceAll(".exe$", "");
Assert.assertEquals(new File(sdkTestSupport.getEnv_ANDROID_HOME() + "/platform-tools/adb").getAbsolutePath(), pathForTool);
}

@Test
public void givenToolAndroidThenPathIsCommon() {
final String pathForTool =sdkTestSupport.getSdk_with_platform_1_5().getPathForTool("android");
final String pathForTool =sdkTestSupport.getSdk_with_platform_1_5().getPathForTool("android").replaceAll(".bat$", "");;
Assert.assertEquals(new File(sdkTestSupport.getEnv_ANDROID_HOME() + "/tools/android").getAbsolutePath(), pathForTool);
}

@Test
public void givenToolAaptAndPlatform1dot5ThenPathIsPlatformTools() {
final AndroidSdk sdk = new AndroidSdk(new File(sdkTestSupport.getEnv_ANDROID_HOME()), "3");
final String pathForTool = sdk.getPathForTool("aapt");
final String pathForTool = sdk.getPathForTool("aapt").replaceAll(".exe$", "");;
Assert.assertEquals(new File(sdkTestSupport.getEnv_ANDROID_HOME() + "/platform-tools/aapt"), new File(pathForTool));
}

Expand Down

0 comments on commit 9901936

Please sign in to comment.