Skip to content

Commit

Permalink
Fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsonlee authored and neighbWang committed Dec 2, 2022
1 parent 41d7282 commit 1e13de6
Show file tree
Hide file tree
Showing 44 changed files with 168 additions and 327 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,27 @@ jobs:
with:
name: booster-android-gradle-v7_2
path: booster-android-gradle-v7_2/build/reports/tests/integrationTest

integration-test-agp-v7_3:
name: AGP 7.3 Integration Test
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '11'
cache: 'gradle'
- uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ github.run_number }}
- shell: bash
run: ./gradlew booster-android-gradle-v7_3:integrationTest -S --no-daemon -Pversion=${{ github.run_number }}
- uses: actions/upload-artifact@v3
if: failure()
with:
name: booster-android-gradle-v7_3
path: booster-android-gradle-v7_3/build/reports/tests/integrationTest

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.gradle.api.UnknownTaskException
import org.gradle.api.artifacts.ArtifactCollection
import org.gradle.api.artifacts.result.ResolvedArtifactResult
import org.gradle.api.file.FileCollection
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.TaskProvider
import java.io.File

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.didiglobal.booster.gradle

import com.android.build.api.transform.TransformInvocation
import com.android.build.gradle.api.BaseVariant
import com.android.builder.model.ApiVersion
import org.gradle.api.Project
import java.io.File

Expand All @@ -21,6 +22,9 @@ val TransformInvocation.project: Project
val TransformInvocation.variant: BaseVariant
get() = AGP.run { variant }

val TransformInvocation.targetSdkVersion: ApiVersion
get() = AGP.run { variant.targetSdkVersion }

val TransformInvocation.bootClasspath: Collection<File>
get() = AGP.run { bootClasspath }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,15 @@ interface AGPInterface {

val BaseVariant.variantScope: VariantScope

@Deprecated(
message = "Use BaseVariant.namespace instead",
replaceWith = ReplaceWith(expression = "variant.namespace"),
)
val BaseVariant.originalApplicationId: String

val BaseVariant.hasDynamicFeature: Boolean

@Deprecated(message = "Deprecated, don't use it")
val BaseVariant.rawAndroidResources: FileCollection

val BaseVariant.javaCompilerTaskProvider: TaskProvider<out Task>
Expand Down Expand Up @@ -181,6 +186,7 @@ interface AGPInterface {
)
val Project.aapt2Enabled: Boolean

@Suppress("DEPRECATION")
val Project.isAapt2Enabled: Boolean
get() = aapt2Enabled

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.android.build.gradle.AppExtension
import com.android.build.gradle.BaseExtension
import com.android.build.gradle.LibraryExtension
import com.android.build.gradle.api.BaseVariant
import com.android.builder.core.VariantTypeImpl
import com.android.sdklib.BuildToolInfo
import com.didiglobal.booster.gradle.AGP
import com.didiglobal.booster.gradle.getAndroid
Expand All @@ -31,12 +30,11 @@ import kotlin.test.assertNotNull
import kotlin.test.assertTrue
import kotlin.test.fail

private const val MIN_SDK_VERSION = 18
private val MIN_SDK_VERSION = System.getProperty("android.minsdk.version").toInt()

private const val TARGET_SDK_VERSION = 26

private val ARGS = arrayOf(
"assemble", "-S",
private val ARGS = System.getProperty("gradle.args").split("\\s+".toRegex()) + listOf(
"-Pbooster_version=${Build.VERSION}",
"-Pandroid_gradle_version=3.3.0",
"-Pcompile_sdk_version=28",
Expand All @@ -53,7 +51,7 @@ abstract class V33IntegrationTest(private val isLib: Boolean) {
@get:Rule
val ruleChain: TestRule = rule(projectDir) {
rule(LocalProperties(projectDir::getRoot)) {
GradleExecutor(projectDir::getRoot, "4.10.1", *ARGS)
GradleExecutor(projectDir::getRoot, "4.10.1", *ARGS.toTypedArray())
}
}

Expand Down Expand Up @@ -139,10 +137,6 @@ abstract class V33IntegrationTest(private val isLib: Boolean) {
@Case(TargetSdkVersionTestUnit::class)
fun `test AGPInterface#targetSdkVersion`() = Unit

@Test
@Case(VariantTypeTestUnit::class)
fun `test AGPInterface#variantType`() = Unit

@Test
@Case(AarTestUnit::class)
fun `test AGPInterface#aar`() = Unit
Expand Down Expand Up @@ -328,18 +322,6 @@ class TargetSdkVersionTestUnit : VariantTestCase() {
}
}

class VariantTypeTestUnit : VariantTestCase() {
override fun apply(variant: BaseVariant) {
val project = AGP.run { variant.project }
val variantType = AGP.run { variant.variantType }
if (project.plugins.hasPlugin("com.android.application")) {
assertEquals(VariantTypeImpl.BASE_APK, variantType)
} else if (project.plugins.hasPlugin("com.android.library")) {
assertEquals(VariantTypeImpl.LIBRARY, variantType)
}
}
}

class AarTestUnit : VariantTestCase() {
override fun apply(project: Project) {
if (project.plugins.hasPlugin("com.android.library")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.android.build.gradle.AppExtension
import com.android.build.gradle.BaseExtension
import com.android.build.gradle.LibraryExtension
import com.android.build.gradle.api.BaseVariant
import com.android.builder.core.VariantTypeImpl
import com.android.sdklib.BuildToolInfo
import com.didiglobal.booster.gradle.AGP
import com.didiglobal.booster.gradle.getAndroid
Expand All @@ -31,12 +30,11 @@ import kotlin.test.assertNotNull
import kotlin.test.assertTrue
import kotlin.test.fail

private const val MIN_SDK_VERSION = 18
private val MIN_SDK_VERSION = System.getProperty("android.minsdk.version").toInt()

private const val TARGET_SDK_VERSION = 26

private val ARGS = arrayOf(
"assemble", "-S",
private val ARGS = System.getProperty("gradle.args").split("\\s+".toRegex()) + listOf(
"-Pbooster_version=${Build.VERSION}",
"-Pandroid_gradle_version=3.4.0",
"-Pcompile_sdk_version=28",
Expand All @@ -53,7 +51,7 @@ abstract class V34IntegrationTest(private val isLib: Boolean) {
@get:Rule
val ruleChain: TestRule = rule(projectDir) {
rule(LocalProperties(projectDir::getRoot)) {
GradleExecutor(projectDir::getRoot, "5.1.1", *ARGS)
GradleExecutor(projectDir::getRoot, "5.1.1", *ARGS.toTypedArray())
}
}

Expand Down Expand Up @@ -139,10 +137,6 @@ abstract class V34IntegrationTest(private val isLib: Boolean) {
@Case(TargetSdkVersionTestUnit::class)
fun `test AGPInterface#targetSdkVersion`() = Unit

@Test
@Case(VariantTypeTestUnit::class)
fun `test AGPInterface#variantType`() = Unit

@Test
@Case(AarTestUnit::class)
fun `test AGPInterface#aar`() = Unit
Expand Down Expand Up @@ -328,18 +322,6 @@ class TargetSdkVersionTestUnit : VariantTestCase() {
}
}

class VariantTypeTestUnit : VariantTestCase() {
override fun apply(variant: BaseVariant) {
val project = AGP.run { variant.project }
val variantType = AGP.run { variant.variantType }
if (project.plugins.hasPlugin("com.android.application")) {
assertEquals(VariantTypeImpl.BASE_APK, variantType)
} else if (project.plugins.hasPlugin("com.android.library")) {
assertEquals(VariantTypeImpl.LIBRARY, variantType)
}
}
}

class AarTestUnit : VariantTestCase() {
override fun apply(project: Project) {
if (project.plugins.hasPlugin("com.android.library")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.android.build.gradle.AppExtension
import com.android.build.gradle.BaseExtension
import com.android.build.gradle.LibraryExtension
import com.android.build.gradle.api.BaseVariant
import com.android.builder.core.VariantTypeImpl
import com.android.sdklib.BuildToolInfo
import com.didiglobal.booster.gradle.AGP
import com.didiglobal.booster.gradle.getAndroid
Expand All @@ -31,18 +30,17 @@ import kotlin.test.assertNotNull
import kotlin.test.assertTrue
import kotlin.test.fail

private const val MIN_SDK_VERSION = 18
private val MIN_SDK_VERSION = System.getProperty("android.minsdk.version").toInt()

private const val TARGET_SDK_VERSION = 26

private val ARGS = arrayOf(
"assemble", "-S",
private val ARGS = System.getProperty("gradle.args").split("\\s+".toRegex()) + listOf(
"-Pbooster_version=${Build.VERSION}",
"-Pandroid_gradle_version=3.5.0",
"-Pcompile_sdk_version=28",
"-Pbuild_tools_version=26.0.3",
"-Pmin_sdk_version=${MIN_SDK_VERSION}",
"-Ptarget_sdk_version=${TARGET_SDK_VERSION}"
"-Ptarget_sdk_version=${TARGET_SDK_VERSION}",
)

@Suppress("RemoveCurlyBracesFromTemplate", "FunctionName")
Expand All @@ -53,7 +51,7 @@ abstract class V35IntegrationTest(private val isLib: Boolean) {
@get:Rule
val ruleChain: TestRule = rule(projectDir) {
rule(LocalProperties(projectDir::getRoot)) {
GradleExecutor(projectDir::getRoot, "5.4.1", *ARGS)
GradleExecutor(projectDir::getRoot, "5.4.1", *ARGS.toTypedArray())
}
}

Expand Down Expand Up @@ -139,10 +137,6 @@ abstract class V35IntegrationTest(private val isLib: Boolean) {
@Case(TargetSdkVersionTestUnit::class)
fun `test AGPInterface#targetSdkVersion`() = Unit

@Test
@Case(VariantTypeTestUnit::class)
fun `test AGPInterface#variantType`() = Unit

@Test
@Case(AarTestUnit::class)
fun `test AGPInterface#aar`() = Unit
Expand Down Expand Up @@ -328,18 +322,6 @@ class TargetSdkVersionTestUnit : VariantTestCase() {
}
}

class VariantTypeTestUnit : VariantTestCase() {
override fun apply(variant: BaseVariant) {
val project = AGP.run { variant.project }
val variantType = AGP.run { variant.variantType }
if (project.plugins.hasPlugin("com.android.application")) {
assertEquals(VariantTypeImpl.BASE_APK, variantType)
} else if (project.plugins.hasPlugin("com.android.library")) {
assertEquals(VariantTypeImpl.LIBRARY, variantType)
}
}
}

class AarTestUnit : VariantTestCase() {
override fun apply(project: Project) {
if (project.plugins.hasPlugin("com.android.library")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import com.android.build.api.artifact.ArtifactType
import com.android.build.api.artifact.BuildArtifactType
import com.android.build.api.transform.Context
import com.android.build.api.transform.QualifiedContent
import com.android.build.gradle.AppPlugin
import com.android.build.gradle.DynamicFeaturePlugin
import com.android.build.gradle.LibraryPlugin
import com.android.build.gradle.api.ApplicationVariant
import com.android.build.gradle.api.BaseVariant
import com.android.build.gradle.api.LibraryVariant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.android.build.gradle.AppExtension
import com.android.build.gradle.BaseExtension
import com.android.build.gradle.LibraryExtension
import com.android.build.gradle.api.BaseVariant
import com.android.builder.core.VariantTypeImpl
import com.android.sdklib.BuildToolInfo
import com.didiglobal.booster.gradle.AGP
import com.didiglobal.booster.gradle.getAndroid
Expand All @@ -31,12 +30,11 @@ import kotlin.test.assertNotNull
import kotlin.test.assertTrue
import kotlin.test.fail

private const val MIN_SDK_VERSION = 18
private val MIN_SDK_VERSION = System.getProperty("android.minsdk.version").toInt()

private const val TARGET_SDK_VERSION = 26

private val ARGS = arrayOf(
"assemble", "-S",
private val ARGS = System.getProperty("gradle.args").split("\\s+".toRegex()) + listOf(
"-Pbooster_version=${Build.VERSION}",
"-Pandroid_gradle_version=3.6.0",
"-Pcompile_sdk_version=28",
Expand All @@ -53,7 +51,7 @@ abstract class V36IntegrationTest(private val isLib: Boolean) {
@get:Rule
val ruleChain: TestRule = rule(projectDir) {
rule(LocalProperties(projectDir::getRoot)) {
GradleExecutor(projectDir::getRoot, "5.6.4", *ARGS)
GradleExecutor(projectDir::getRoot, "5.6.4", *ARGS.toTypedArray())
}
}

Expand Down Expand Up @@ -139,10 +137,6 @@ abstract class V36IntegrationTest(private val isLib: Boolean) {
@Case(TargetSdkVersionTestUnit::class)
fun `test AGPInterface#targetSdkVersion`() = Unit

@Test
@Case(VariantTypeTestUnit::class)
fun `test AGPInterface#variantType`() = Unit

@Test
@Case(AarTestUnit::class)
fun `test AGPInterface#aar`() = Unit
Expand Down Expand Up @@ -328,18 +322,6 @@ class TargetSdkVersionTestUnit : VariantTestCase() {
}
}

class VariantTypeTestUnit : VariantTestCase() {
override fun apply(variant: BaseVariant) {
val project = AGP.run { variant.project }
val variantType = AGP.run { variant.variantType }
if (project.plugins.hasPlugin("com.android.application")) {
assertEquals(VariantTypeImpl.BASE_APK, variantType)
} else if (project.plugins.hasPlugin("com.android.library")) {
assertEquals(VariantTypeImpl.LIBRARY, variantType)
}
}
}

class AarTestUnit : VariantTestCase() {
override fun apply(project: Project) {
if (project.plugins.hasPlugin("com.android.library")) {
Expand Down
Loading

0 comments on commit 1e13de6

Please sign in to comment.