Skip to content

Commit

Permalink
Merge pull request #777 from witekkij/pathToEmulator
Browse files Browse the repository at this point in the history
Path to emulator
  • Loading branch information
mosabua authored Mar 10, 2019
2 parents aef1c48 + 87f1236 commit b900c07
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<groupId>com.simpligility.maven.plugins</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>4.5.1-SNAPSHOT</version>
<version>4.5.2-SNAPSHOT</version>
<packaging>maven-plugin</packaging>

<name>Android Maven Plugin - android-maven-plugin</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public abstract class AbstractEmulatorMojo extends AbstractAndroidMojo
* &lt;wait&gt;20000&lt;/wait&gt;
* &lt;options&gt;-no-skin&lt;/options&gt;
* &lt;executable&gt;emulator-arm&lt;/executable&gt;
* &lt;location&gt;C:/SDK/emulator&lt;/location&gt;
* &lt;/emulator&gt;
* </pre>
* or configure as properties on the command line as android.emulator.avd, android.emulator.wait,
Expand Down Expand Up @@ -143,7 +144,6 @@ public abstract class AbstractEmulatorMojo extends AbstractAndroidMojo
@Parameter( property = "android.emulator.options" )
private String emulatorOptions;


/**
* Override default emulator executable. Default uses just "emulator".
*
Expand All @@ -152,21 +152,34 @@ public abstract class AbstractEmulatorMojo extends AbstractAndroidMojo
@Parameter( property = "android.emulator.executable" )
private String emulatorExecutable;

/**
* Override default path to emulator folder.
*/
@Parameter( property = "android.emulator.location" )
private String emulatorLocation;

/**
* parsed value for avd that will be used for the invocation.
*/
private String parsedAvd;

/**
* parsed value for options that will be used for the invocation.
*/
private String parsedOptions;

/**
* parsed value for wait that will be used for the invocation.
*/
private String parsedWait;

private String parsedExecutable;

/**
* parsed value for location that will be used for the invocation.
*/
private String parsedEmulatorLocation;

private static final String START_EMULATOR_MSG = "Starting android emulator with script: ";
private static final String START_EMULATOR_WAIT_MSG = "Waiting for emulator start:";

Expand Down Expand Up @@ -264,7 +277,7 @@ protected void startAndroidEmulator() throws MojoExecutionException
throw new MojoExecutionException( "", e );
}
}

/**
* Unlocks the emulator.
* @param androidDebugBridge
Expand Down Expand Up @@ -767,7 +780,15 @@ public Boolean call() throws IOException
*/
private String assembleStartCommandLine() throws MojoExecutionException
{
String emulatorPath = new File ( getAndroidSdk().getToolsPath(), parsedExecutable ).getAbsolutePath();
String emulatorPath;
if ( !"SdkTools".equals( parsedEmulatorLocation ) )
{
emulatorPath = new File( parsedEmulatorLocation, parsedExecutable ).getAbsolutePath();
}
else
{
emulatorPath = new File( getAndroidSdk().getToolsPath(), parsedExecutable ).getAbsolutePath();
}
StringBuilder startCommandline = new StringBuilder( "\"\"" ).append( emulatorPath ).append( "\"\"" )
.append( " -avd " ).append( parsedAvd ).append( " " );
if ( !StringUtils.isEmpty( parsedOptions ) )
Expand All @@ -789,7 +810,7 @@ private void parseParameters()
parsedAvd = emulator.getAvd();
}
else
{
{
parsedAvd = determineAvd();
}
// <emulator><options> exists in pom file
Expand All @@ -798,7 +819,7 @@ private void parseParameters()
parsedOptions = emulator.getOptions();
}
else
{
{
parsedOptions = determineOptions();
}
// <emulator><wait> exists in pom file
Expand All @@ -807,7 +828,7 @@ private void parseParameters()
parsedWait = emulator.getWait();
}
else
{
{
parsedWait = determineWait();
}
// <emulator><emulatorExecutable> exists in pom file
Expand All @@ -816,9 +837,18 @@ private void parseParameters()
parsedExecutable = emulator.getExecutable();
}
else
{
{
parsedExecutable = determineExecutable();
}
// <emulator><location> exists in pom file
if ( emulator.getLocation() != null )
{
parsedEmulatorLocation = emulator.getLocation();
}
else
{
parsedEmulatorLocation = determineEmulatorLocation();
}
}
// commandline options
else
Expand All @@ -827,6 +857,7 @@ private void parseParameters()
parsedOptions = determineOptions();
parsedWait = determineWait();
parsedExecutable = determineExecutable();
parsedEmulatorLocation = determineEmulatorLocation();
}
}

Expand Down Expand Up @@ -905,4 +936,24 @@ String determineAvd()
}
return avd;
}

/**
* Get location value for emulator from command line option.
*
* @return if available return command line value otherwise return default value ("SdkTools").
*/
String determineEmulatorLocation()
{
String location;
if ( emulatorLocation != null )
{
location = emulatorLocation;
}
else
{
location = "SdkTools";
}
return location;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ public class Emulator
*/
private String executable;

public String getLocation()
{
return location;
}

private String location;

public String getAvd()
{
return avd;
Expand Down

0 comments on commit b900c07

Please sign in to comment.