Skip to content

Commit

Permalink
Ability to choose which build tools version to use
Browse files Browse the repository at this point in the history
  • Loading branch information
Shusshu committed Jun 5, 2015
1 parent cb52625 commit a52d218
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 5 deletions.
Expand Up @@ -1107,10 +1107,12 @@ protected AndroidSdk getAndroidSdk() throws MojoExecutionException
{ {
File chosenSdkPath; File chosenSdkPath;
String chosenSdkPlatform; String chosenSdkPlatform;
String buildToolsVersion = null;


if ( sdk != null ) if ( sdk != null )
{ {
// An <sdk> tag exists in the pom. // An <sdk> tag exists in the pom.
buildToolsVersion = sdk.getBuildTools();


if ( sdk.getPath() != null ) if ( sdk.getPath() != null )
{ {
Expand Down Expand Up @@ -1164,7 +1166,7 @@ protected AndroidSdk getAndroidSdk() throws MojoExecutionException
chosenSdkPlatform = sdkPlatform; chosenSdkPlatform = sdkPlatform;
} }


return new AndroidSdk( chosenSdkPath, chosenSdkPlatform ); return new AndroidSdk( chosenSdkPath, chosenSdkPlatform, buildToolsVersion );
} }


private String getAndroidHomeOrThrow() throws MojoExecutionException private String getAndroidHomeOrThrow() throws MojoExecutionException
Expand Down
Expand Up @@ -16,11 +16,13 @@
package com.simpligility.maven.plugins.android; package com.simpligility.maven.plugins.android;


import com.android.SdkConstants; import com.android.SdkConstants;
import com.android.annotations.Nullable;
import com.android.sdklib.AndroidTargetHash; import com.android.sdklib.AndroidTargetHash;
import com.android.sdklib.AndroidVersion; import com.android.sdklib.AndroidVersion;
import com.android.sdklib.BuildToolInfo; import com.android.sdklib.BuildToolInfo;
import com.android.sdklib.IAndroidTarget; import com.android.sdklib.IAndroidTarget;
import com.android.sdklib.SdkManager; import com.android.sdklib.SdkManager;
import com.android.sdklib.repository.FullRevision;
import com.android.utils.NullLogger; import com.android.utils.NullLogger;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;


Expand All @@ -42,7 +44,7 @@ public class AndroidSdk
* the default API level for the SDK used as a fall back if none is supplied, * the default API level for the SDK used as a fall back if none is supplied,
* should ideally point to the latest available version * should ideally point to the latest available version
*/ */
private static final String DEFAULT_ANDROID_API_LEVEL = "19"; private static final String DEFAULT_ANDROID_API_LEVEL = "22";
/** /**
* property file in each platform folder with details about platform. * property file in each platform folder with details about platform.
*/ */
Expand All @@ -69,10 +71,17 @@ public class AndroidSdk
private final IAndroidTarget androidTarget; private final IAndroidTarget androidTarget;
private SdkManager sdkManager; private SdkManager sdkManager;
private int sdkMajorVersion; private int sdkMajorVersion;
private String buildToolsVersion;


public AndroidSdk( File sdkPath, String apiLevel ) public AndroidSdk( File sdkPath, String apiLevel )
{
this( sdkPath, apiLevel, null );
}

public AndroidSdk( File sdkPath, String apiLevel, @Nullable String buildToolsVersion )
{ {
this.sdkPath = sdkPath; this.sdkPath = sdkPath;
this.buildToolsVersion = buildToolsVersion;


if ( sdkPath != null ) if ( sdkPath != null )
{ {
Expand Down Expand Up @@ -253,12 +262,17 @@ private String getPathForBuildTool( BuildToolInfo.PathId pathId )


private BuildToolInfo getBuildToolInfo() private BuildToolInfo getBuildToolInfo()
{ {
if ( buildToolsVersion != null && !buildToolsVersion.equals( "" ) )
{
return sdkManager.getBuildTool( FullRevision.parseRevision( buildToolsVersion ) );
}

if ( androidTarget != null ) if ( androidTarget != null )
{ {
BuildToolInfo buildToolInfo = androidTarget.getBuildToolInfo(); BuildToolInfo buildToolInfo = androidTarget.getBuildToolInfo();
if ( buildToolInfo != null ) if ( buildToolInfo != null )
{ {
return androidTarget.getBuildToolInfo(); return buildToolInfo;
} }
} }
// if no valid target is defined, or it has no build tools installed, try to use the latest // if no valid target is defined, or it has no build tools installed, try to use the latest
Expand Down
Expand Up @@ -43,6 +43,13 @@ public class Sdk
@Parameter ( property = "android.sdk.platform" ) @Parameter ( property = "android.sdk.platform" )
private String platform; private String platform;


/**
* <p>Chosen Build-Tools version. Valid values are whichever build-tools are available in the SDK,
* under the directory <code>buildTools</code>. Defaults to the latest available one if not set.</p>
*/
@Parameter ( property = "android.sdk.buildTools" )
private String buildTools;

public File getPath() public File getPath()
{ {
return path; return path;
Expand All @@ -52,4 +59,9 @@ public String getPlatform()
{ {
return platform; return platform;
} }

public String getBuildTools()
{
return buildTools;
}
} }
Expand Up @@ -76,16 +76,62 @@ public void givenPlatformNullThenPlatformisSomethingValidLooking() throws Illega
* for this test to pass including the obsolete ones. * for this test to pass including the obsolete ones.
*/ */
@Test @Test
public void validPlatformsAndApiLevels() { public void validPlatformsAndApiLevels1() {
// Remember to add further platforms to .travis.yml if you add more platforms here, otherwise ci build fails // Remember to add further platforms to .travis.yml if you add more platforms here, otherwise ci build fails
final AndroidSdk sdk19 = new AndroidSdk(new File(sdkTestSupport.getEnv_ANDROID_HOME()), "19"); final AndroidSdk sdk19 = new AndroidSdk(new File(sdkTestSupport.getEnv_ANDROID_HOME()), "19");
} }


@Test
public void validPlatformsAndApiLevels2() {
// Remember to add further platforms to .travis.yml if you add more platforms here, otherwise ci build fails
final AndroidSdk sdk21 = new AndroidSdk(new File(sdkTestSupport.getEnv_ANDROID_HOME()), "21", null);
Assert.assertTrue( sdk21.getAaptPath() != null && !sdk21.getAaptPath().equals( "" ) );
}

@Test
public void validPlatformsAndApiLevels3() {
// Remember to add further platforms to .travis.yml if you add more platforms here, otherwise ci build fails
final AndroidSdk sdk22 = new AndroidSdk( new File( sdkTestSupport.getEnv_ANDROID_HOME()), "22", "22.0.0" );
Assert.assertTrue( sdk22.getAaptPath() != null && !sdk22.getAaptPath().equals( "" ) );
}

@Test
public void validPlatformsAndApiLevels4() {
// Remember to add further platforms to .travis.yml if you add more platforms here, otherwise ci build fails
final AndroidSdk sdk19 = new AndroidSdk( new File( sdkTestSupport.getEnv_ANDROID_HOME() ), "22", "22.0.0" );
Assert.assertTrue( sdk19.getAaptPath() != null && !sdk19.getAaptPath().equals( "" ) );
}

@Test(expected = InvalidSdkException.class) @Test(expected = InvalidSdkException.class)
public void invalidPlatformAndApiLevels() { public void invalidPlatformAndApiLevels() {
final AndroidSdk invalid = new AndroidSdk(new File(sdkTestSupport.getEnv_ANDROID_HOME()), "invalid"); final AndroidSdk invalid = new AndroidSdk (new File( sdkTestSupport.getEnv_ANDROID_HOME() ), "invalid" );
}

@Test(expected = NumberFormatException.class)
public void invalidBuildTools() {
final AndroidSdk invalid = new AndroidSdk (new File( sdkTestSupport.getEnv_ANDROID_HOME() ), "19", "invalid" );
invalid.getAaptPath();
}

@Test
public void validPlatformsAndApiLevelsWithDiffBuildTools1() {
// Remember to add further platforms to .travis.yml if you add more platforms here, otherwise ci build fails
final AndroidSdk sdk = new AndroidSdk( new File( sdkTestSupport.getEnv_ANDROID_HOME() ), "19", "22" );
Assert.assertTrue( sdk.getAaptPath() != null && !sdk.getAaptPath().equals( "" ) );
}


@Test
public void validPlatformsAndApiLevelsWithDiffBuildTools2() {
// Remember to add further platforms to .travis.yml if you add more platforms here, otherwise ci build fails
final AndroidSdk sdk = new AndroidSdk( new File( sdkTestSupport.getEnv_ANDROID_HOME() ), "19", "22.0.0" );
Assert.assertTrue( sdk.getAaptPath() != null && !sdk.getAaptPath().equals( "" ) );
} }


@Test
public void validPlatformsAndApiLevelsWithDiffBuildToolsMinor() {
// Remember to add further platforms to .travis.yml if you add more platforms here, otherwise ci build fails
final AndroidSdk sdk = new AndroidSdk( new File( sdkTestSupport.getEnv_ANDROID_HOME() ), "19", "21.1.2" );
Assert.assertTrue( sdk.getAaptPath() != null && !sdk.getAaptPath().equals( "" ) );
}


} }

0 comments on commit a52d218

Please sign in to comment.