Skip to content

Commit

Permalink
Merge pull request #19 from gradle/lptr/support-android-3.0.1
Browse files Browse the repository at this point in the history
Support Android plugin 3.0.1
  • Loading branch information
lptr authored Nov 29, 2017
2 parents 819f63c + a143638 commit eccf668
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 18 deletions.
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ version = ["git", "describe", "--match", "[0-9]*", "--dirty"].execute().text.tri

// Maps supported Android plugin versions to the versions of Gradle that should support it
def supportedVersions = [
"3.1.0-alpha04": ["4.4-20171031235950+0000"],
"3.0.0": ["4.1", "4.2", "4.2.1", "4.3", "4.3.1"],
"3.1.0-alpha04": ["4.4-rc-4"],
"3.0.0": ["4.1", "4.2", "4.2.1", "4.3", "4.3.1", "4.4-rc-4"],
"3.0.1": ["4.1", "4.2", "4.2.1", "4.3", "4.3.1", "4.4-rc-4"],
]

repositories {
Expand Down
31 changes: 22 additions & 9 deletions src/main/groovy/org/gradle/android/AndroidCacheFixPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.android.build.gradle.tasks.ExtractAnnotations
import com.android.build.gradle.tasks.ProcessAndroidResources
import com.android.build.gradle.tasks.factory.AndroidJavaCompile
import com.android.builder.model.Version
import com.google.common.collect.ImmutableList
import groovy.transform.CompileStatic
import groovy.transform.TypeCheckingMode
import org.gradle.api.Plugin
Expand All @@ -15,6 +16,7 @@ import org.gradle.api.tasks.PathSensitivity
import org.gradle.internal.Factory
import org.gradle.util.DeprecationLogger
import org.gradle.util.GradleVersion
import org.gradle.util.VersionNumber
import org.slf4j.Logger
import org.slf4j.LoggerFactory

Expand Down Expand Up @@ -50,24 +52,35 @@ class AndroidCacheFixPlugin implements Plugin<Project> {
}
}

getWorkaroundsToApply(currentAndroidVersion).each { Workaround workaround ->
LOGGER.debug("Applying Android workaround {} to {}", workaround.getClass().simpleName, project)
workaround.apply(project)
}
}

static List<Workaround> getWorkaroundsToApply(VersionNumber androidVersion) {
def workarounds = ImmutableList.<Workaround>builder()
for (def workaround : WORKAROUNDS) {
def androidIssue = workaround.class.getAnnotation(AndroidIssue)
def introducedIn = android(androidIssue.introducedIn())
if (currentAndroidVersion < introducedIn) {
if (androidVersion < introducedIn) {
continue
}
if (androidIssue.fixedIn().any { String supportedAndroidVersion -> currentAndroidVersion == android(supportedAndroidVersion) }) {
if (androidIssue.fixedIn().any { String fixedInVersionString ->
def fixedInVersion = android(fixedInVersionString)
androidVersion.baseVersion == fixedInVersion.baseVersion && androidVersion >= fixedInVersion
}) {
continue
}
LOGGER.debug("Applying Android workaround {} to {}", workaround.getClass().simpleName, project)
workaround.apply(project)
workarounds.add(workaround)
}
workarounds.build()
}

/**
* Fix {@link org.gradle.api.tasks.compile.CompileOptions#getBootClasspath()} introducing relocatability problems for {@link AndroidJavaCompile}.
*/
@AndroidIssue(introducedIn = "3.0.0", fixedIn = ["3.1.0-alpha02", "3.1.0-alpha03", "3.1.0-alpha04"], link = "https://issuetracker.google.com/issues/68392933")
@AndroidIssue(introducedIn = "3.0.0", link = "https://issuetracker.google.com/issues/68392933")
static class AndroidJavaCompile_BootClasspath_Workaround implements Workaround {
@Override
@CompileStatic(TypeCheckingMode.SKIP)
Expand Down Expand Up @@ -119,7 +132,7 @@ class AndroidCacheFixPlugin implements Plugin<Project> {
/**
* Override path sensitivity for {@link AndroidJavaCompile#getProcessorListFile()} to {@link PathSensitivity#NONE}.
*/
@AndroidIssue(introducedIn = "3.0.0", link = "https://issuetracker.google.com/issues/68759178")
@AndroidIssue(introducedIn = "3.0.0", fixedIn = "3.1.0-alpha01", link = "https://issuetracker.google.com/issues/68759178")
static class AndroidJavaCompile_ProcessorListFile_Workaround implements Workaround {
@CompileStatic(TypeCheckingMode.SKIP)
@Override
Expand Down Expand Up @@ -147,7 +160,7 @@ class AndroidCacheFixPlugin implements Plugin<Project> {
/**
* Override path sensitivity for {@link ExtractAnnotations#getSource()} to {@link PathSensitivity#RELATIVE}.
*/
@AndroidIssue(introducedIn = "3.0.0", link = "https://issuetracker.google.com/issues/68759476")
@AndroidIssue(introducedIn = "3.0.0", fixedIn = "3.1.0-alpha01", link = "https://issuetracker.google.com/issues/68759476")
static class ExtractAnnotations_Source_Workaround implements Workaround {
@CompileStatic(TypeCheckingMode.SKIP)
@Override
Expand Down Expand Up @@ -176,7 +189,7 @@ class AndroidCacheFixPlugin implements Plugin<Project> {
/**
* Fix {@link IncrementalTask#getCombinedInput()} and {@link StreamBasedTask#getCombinedInput()} relocatability.
*/
@AndroidIssue(introducedIn = "3.0.0", fixedIn = ["3.1.0-alpha04"], link = "https://issuetracker.google.com/issues/68771542")
@AndroidIssue(introducedIn = "3.0.0", fixedIn = ["3.0.1", "3.1.0-alpha04"], link = "https://issuetracker.google.com/issues/68771542")
static class CombinedInput_Workaround implements Workaround {
@CompileStatic(TypeCheckingMode.SKIP)
@Override
Expand Down Expand Up @@ -207,7 +220,7 @@ class AndroidCacheFixPlugin implements Plugin<Project> {
/**
* {@link ProcessAndroidResources#getMergeBlameLogFolder()} shouldn't be an {@literal @}{@link org.gradle.api.tasks.Input}.
*/
@AndroidIssue(introducedIn = "3.0.0", fixedIn = "3.0.1", link = "https://issuetracker.google.com/issues/68385486")
@AndroidIssue(introducedIn = "3.0.0", fixedIn = ["3.0.1", "3.1.0-alpha02"], link = "https://issuetracker.google.com/issues/68385486")
static class ProcessAndroidResources_MergeBlameLogFolder_Workaround implements Workaround {
@CompileStatic(TypeCheckingMode.SKIP)
@Override
Expand Down
17 changes: 10 additions & 7 deletions src/test/groovy/org/gradle/android/RelocationTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class RelocationTest extends AbstractTest {
assert gradleVersion instanceof GradleVersion
assert androidVersion instanceof VersionNumber

println "> Using Android plugin $androidVersion"
println "> Running with $gradleVersion"

def originalDir = temporaryFolder.newFolder()
new SimpleAndroidApp(originalDir, cacheDir, androidVersion).writeProject()

Expand Down Expand Up @@ -64,7 +67,7 @@ class RelocationTest extends AbstractTest {
}

String describe() {
"Expecting ${outcomes.values().count(FROM_CACHE)} tasks out of ${outcomes.size()} to be cached"
"> Expecting ${outcomes.values().count(FROM_CACHE)} tasks out of ${outcomes.size()} to be cached"
}

boolean verify(BuildResult result) {
Expand Down Expand Up @@ -140,19 +143,19 @@ class RelocationTest extends AbstractTest {

if (androidVersion <= android("3.0.1")) {
builder.put(':app:transformClassesWithPreDexForRelease', SUCCESS)
builder.put(':app:transformDexArchiveWithDexMergerForDebug',
Boolean.getBoolean("travis") && gradleVersion <= gradle("4.1")
? SUCCESS
: FROM_CACHE
)
builder.put(':app:transformDexWithDexForRelease', SUCCESS)
} else {
builder.put(':app:transformClassesWithDexBuilderForRelease', SUCCESS)
builder.put(':app:transformDexArchiveWithDexMergerForDebug', SUCCESS)
builder.put(':app:transformDexArchiveWithDexMergerForRelease', SUCCESS)
builder.put(':app:transformDexArchiveWithExternalLibsDexMergerForRelease', SUCCESS)
}

builder.put(':app:transformDexArchiveWithDexMergerForDebug',
androidVersion != android("3.0.0") || Boolean.getBoolean("travis") && gradleVersion <= gradle("4.1")
? SUCCESS
: FROM_CACHE
)

builder.put(':app:transformNativeLibsWithMergeJniLibsForDebug', SUCCESS)
builder.put(':app:transformNativeLibsWithMergeJniLibsForRelease', SUCCESS)
builder.put(':app:transformResourcesWithMergeJavaResForDebug', SUCCESS)
Expand Down
24 changes: 24 additions & 0 deletions src/test/groovy/org/gradle/android/WorkaroundTest.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.gradle.android

import spock.lang.Specification
import spock.lang.Unroll

import static Versions.android

class WorkaroundTest extends Specification {

@Unroll
def "applies the right workarounds for Android #androidVersion"() {
def workarounds = AndroidCacheFixPlugin.getWorkaroundsToApply(android(androidVersion))
expect:
workarounds.collect { it.class.simpleName.replaceAll(/_Workaround/, "") } == expectedWorkarounds
where:
androidVersion | expectedWorkarounds
"3.0.0" | ["AndroidJavaCompile_BootClasspath", "AndroidJavaCompile_AnnotationProcessorSource", "AndroidJavaCompile_ProcessorListFile", "ExtractAnnotations_Source", "CombinedInput", "ProcessAndroidResources_MergeBlameLogFolder", "CheckManifest_Manifest"]
"3.0.1" | ["AndroidJavaCompile_BootClasspath", "AndroidJavaCompile_AnnotationProcessorSource", "AndroidJavaCompile_ProcessorListFile", "ExtractAnnotations_Source", "CheckManifest_Manifest"]
"3.1.0-alpha01" | ["AndroidJavaCompile_BootClasspath", "AndroidJavaCompile_AnnotationProcessorSource", "CombinedInput", "ProcessAndroidResources_MergeBlameLogFolder", "CheckManifest_Manifest"]
"3.1.0-alpha02" | ["AndroidJavaCompile_BootClasspath", "AndroidJavaCompile_AnnotationProcessorSource", "CombinedInput", "CheckManifest_Manifest"]
"3.1.0-alpha03" | ["AndroidJavaCompile_BootClasspath", "AndroidJavaCompile_AnnotationProcessorSource", "CombinedInput", "CheckManifest_Manifest"]
"3.1.0-alpha04" | ["AndroidJavaCompile_BootClasspath", "AndroidJavaCompile_AnnotationProcessorSource", "CheckManifest_Manifest"]
}
}

0 comments on commit eccf668

Please sign in to comment.