From e2addaae29f892dd8cb1056aa3bed72a615fc1bb Mon Sep 17 00:00:00 2001 From: Sergey Boishtyan Date: Thu, 1 Oct 2020 16:51:45 +0300 Subject: [PATCH] Add kotlin-android, kapt plugins to the TestProjectGenerator.kt (#586) --- .../artifactory-app-backup/build.gradle.kts | 1 - .../ArtifactoryAppBackupPluginTest.kt | 4 +- .../com/avito/bitbucket/BitbucketImplTest.kt | 2 +- .../build_metrics/BuildMetricsPluginTest.kt | 8 +- .../android/info/BuildPropertiesPluginTest.kt | 4 +- .../build_param_check/UniqueRClassesTest.kt | 4 +- .../IncrementalKaptTaskTest.kt | 5 +- .../kotlin/com/avito/ci/CiStepsDynamicTest.kt | 2 +- .../kotlin/com/avito/ci/CiStepsPluginTest.kt | 4 +- .../ci/ProjectForImpactAnalysisGenerator.kt | 4 +- .../com/avito/ci/steps/ArtifactsTest.kt | 2 +- .../steps/MarkReportAsSourceForTMSStepTest.kt | 2 +- .../avito/ci/steps/SignerIntegrationTest.kt | 2 +- .../UploadCdBuildResultIntegrationTest.kt | 2 +- .../com/avito/ci/steps/UploadToQappsTest.kt | 2 +- .../kotlin/com/avito/utils/logging/Gradle.kt | 9 +- .../android/CodeOwnershipValidationTest.kt | 4 +- .../avito/android/PlatformDependencyTest.kt | 4 +- .../com/avito/impact/ImpactAnalysisTest.kt | 12 +- .../com/avito/impact/SourceSetsImpactTest.kt | 6 +- .../instrumentation/impact/util/Project.kt | 6 +- .../InstrumentationParamsBuildingTest.kt | 2 +- .../InstrumentationTestsPluginCIFalseTests.kt | 2 +- .../InstrumentationTestsPluginTest.kt | 6 +- .../avito/android/ModuleTypesPluginTest.kt | 4 +- .../com/avito/android/ModuleTypesRules.kt | 2 +- .../NamespacedResourcesFixerPluginTest.kt | 4 +- .../src/test/kotlin/ProsectorPluginTest.kt | 4 +- .../plugin/QAppsPluginIntegrationTest.kt | 3 +- .../com/avito/plugin/QAppsPluginTest.kt | 3 +- .../android/plugin/RobolectricPluginTest.kt | 4 +- .../android/plugin/RoomConfigPluginTest.kt | 2 +- .../com/avito/plugin/SignServicePluginTest.kt | 3 +- .../com/avito/test/gradle/GradleTestKit.kt | 11 +- .../avito/test/gradle/TestProjectGenerator.kt | 336 +----------------- .../test/gradle/files/AndroidManifest.kt | 12 + .../avito/test/gradle/files/BuildGradle.kt | 6 + .../test/gradle/files/InstrumentationTest.kt | 23 ++ .../test/gradle/module/AndroidAppModule.kt | 139 ++++++++ .../test/gradle/module/AndroidLibModule.kt | 84 +++++ .../avito/test/gradle/module/AndroidModule.kt | 6 + .../avito/test/gradle/module/FolderModule.kt | 22 ++ .../avito/test/gradle/module/KotlinModule.kt | 48 +++ .../com/avito/test/gradle/module/Module.kt | 10 + .../test/gradle/module/ParentGradleModule.kt | 27 ++ .../test/gradle/module/PlatformModule.kt | 31 ++ .../test/gradle/TestProjectGeneratorTest.kt | 76 +++- 47 files changed, 569 insertions(+), 390 deletions(-) create mode 100644 subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/files/AndroidManifest.kt create mode 100644 subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/files/BuildGradle.kt create mode 100644 subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/files/InstrumentationTest.kt create mode 100644 subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/AndroidAppModule.kt create mode 100644 subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/AndroidLibModule.kt create mode 100644 subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/AndroidModule.kt create mode 100644 subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/FolderModule.kt create mode 100644 subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/KotlinModule.kt create mode 100644 subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/Module.kt create mode 100644 subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/ParentGradleModule.kt create mode 100644 subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/PlatformModule.kt diff --git a/subprojects/gradle/artifactory-app-backup/build.gradle.kts b/subprojects/gradle/artifactory-app-backup/build.gradle.kts index f86f04d261..2d3722f5e0 100644 --- a/subprojects/gradle/artifactory-app-backup/build.gradle.kts +++ b/subprojects/gradle/artifactory-app-backup/build.gradle.kts @@ -10,7 +10,6 @@ dependencies { implementation(project(":gradle:signer")) implementation(project(":gradle:android")) implementation(project(":gradle:upload-cd-build-result")) - implementation(Dependencies.gradle.androidPlugin) testImplementation(project(":gradle:test-project")) testImplementation(project(":gradle:artifactory-app-backup-test-fixtures")) diff --git a/subprojects/gradle/artifactory-app-backup/src/test/kotlin/com/avito/android/plugin/artifactory/ArtifactoryAppBackupPluginTest.kt b/subprojects/gradle/artifactory-app-backup/src/test/kotlin/com/avito/android/plugin/artifactory/ArtifactoryAppBackupPluginTest.kt index c418cc6278..7240208059 100644 --- a/subprojects/gradle/artifactory-app-backup/src/test/kotlin/com/avito/android/plugin/artifactory/ArtifactoryAppBackupPluginTest.kt +++ b/subprojects/gradle/artifactory-app-backup/src/test/kotlin/com/avito/android/plugin/artifactory/ArtifactoryAppBackupPluginTest.kt @@ -1,8 +1,8 @@ package com.avito.android.plugin.artifactory -import com.avito.test.gradle.AndroidAppModule import com.avito.test.gradle.TestProjectGenerator import com.avito.test.gradle.ciRun +import com.avito.test.gradle.module.AndroidAppModule import com.avito.test.http.Mock import com.avito.test.http.MockDispatcher import com.avito.test.http.MockWebServerFactory @@ -31,6 +31,7 @@ internal class ArtifactoryAppBackupPluginTest { TestProjectGenerator( modules = listOf( AndroidAppModule( + enableKotlinAndroidPlugin = false, versionCode = "90", versionName = "10", name = moduleName, @@ -109,6 +110,7 @@ internal class ArtifactoryAppBackupPluginTest { TestProjectGenerator( modules = listOf( AndroidAppModule( + enableKotlinAndroidPlugin = false, versionCode = "90", versionName = "10", name = moduleName, diff --git a/subprojects/gradle/bitbucket/src/test/kotlin/com/avito/bitbucket/BitbucketImplTest.kt b/subprojects/gradle/bitbucket/src/test/kotlin/com/avito/bitbucket/BitbucketImplTest.kt index bc24936774..c642967ba7 100644 --- a/subprojects/gradle/bitbucket/src/test/kotlin/com/avito/bitbucket/BitbucketImplTest.kt +++ b/subprojects/gradle/bitbucket/src/test/kotlin/com/avito/bitbucket/BitbucketImplTest.kt @@ -1,6 +1,6 @@ package com.avito.bitbucket -import com.avito.test.gradle.KotlinModule +import com.avito.test.gradle.module.KotlinModule import com.avito.test.gradle.TestProjectGenerator import com.avito.test.gradle.commit import com.avito.test.gradle.file diff --git a/subprojects/gradle/build-metrics/src/test/kotlin/com/avito/android/plugin/build_metrics/BuildMetricsPluginTest.kt b/subprojects/gradle/build-metrics/src/test/kotlin/com/avito/android/plugin/build_metrics/BuildMetricsPluginTest.kt index d223a9090c..436daebfa6 100644 --- a/subprojects/gradle/build-metrics/src/test/kotlin/com/avito/android/plugin/build_metrics/BuildMetricsPluginTest.kt +++ b/subprojects/gradle/build-metrics/src/test/kotlin/com/avito/android/plugin/build_metrics/BuildMetricsPluginTest.kt @@ -1,10 +1,10 @@ package com.avito.android.plugin.build_metrics import com.avito.git.Git -import com.avito.test.gradle.AndroidAppModule import com.avito.test.gradle.TestProjectGenerator import com.avito.test.gradle.TestResult import com.avito.test.gradle.gradlew +import com.avito.test.gradle.module.AndroidAppModule import com.avito.utils.logging.CILogger import com.google.common.truth.Truth.assertWithMessage import org.junit.jupiter.api.BeforeEach @@ -15,6 +15,9 @@ import org.junit.jupiter.api.TestFactory import org.junit.jupiter.api.io.TempDir import java.io.File +private const val rootAppName = "root" +private const val loggerPrefix = "[$rootAppName] statsd:" + class BuildMetricsPluginTest { private lateinit var tempDir: File @@ -26,6 +29,7 @@ class BuildMetricsPluginTest { fun setup(@TempDir tempDir: File) { this.tempDir = tempDir TestProjectGenerator( + name = rootAppName, plugins = listOf("com.avito.android.build-metrics"), modules = listOf( AndroidAppModule(name = "app") @@ -162,5 +166,3 @@ class BuildMetricsPluginTest { } } - -private const val loggerPrefix = "statsd:" diff --git a/subprojects/gradle/build-properties/src/test/kotlin/com/avito/android/info/BuildPropertiesPluginTest.kt b/subprojects/gradle/build-properties/src/test/kotlin/com/avito/android/info/BuildPropertiesPluginTest.kt index 212a0d20df..a16571bc9b 100644 --- a/subprojects/gradle/build-properties/src/test/kotlin/com/avito/android/info/BuildPropertiesPluginTest.kt +++ b/subprojects/gradle/build-properties/src/test/kotlin/com/avito/android/info/BuildPropertiesPluginTest.kt @@ -1,8 +1,8 @@ package com.avito.android.info -import com.avito.test.gradle.AndroidAppModule import com.avito.test.gradle.TestProjectGenerator import com.avito.test.gradle.gradlew +import com.avito.test.gradle.module.AndroidAppModule import com.google.common.truth.Truth.assertThat import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test @@ -26,6 +26,7 @@ class BuildPropertiesPluginTest { modules = listOf( AndroidAppModule( "app", + enableKotlinAndroidPlugin = false, plugins = listOf("com.avito.android.build-properties"), buildGradleExtra = """ buildProperties { @@ -51,6 +52,7 @@ class BuildPropertiesPluginTest { modules = listOf( AndroidAppModule( "app", + enableKotlinAndroidPlugin = false, plugins = listOf("com.avito.android.build-properties"), buildGradleExtra = """ buildInfo { diff --git a/subprojects/gradle/buildchecks/src/test/kotlin/com/avito/android/plugin/build_param_check/UniqueRClassesTest.kt b/subprojects/gradle/buildchecks/src/test/kotlin/com/avito/android/plugin/build_param_check/UniqueRClassesTest.kt index 49d56a3982..fd3b2b3697 100644 --- a/subprojects/gradle/buildchecks/src/test/kotlin/com/avito/android/plugin/build_param_check/UniqueRClassesTest.kt +++ b/subprojects/gradle/buildchecks/src/test/kotlin/com/avito/android/plugin/build_param_check/UniqueRClassesTest.kt @@ -1,7 +1,7 @@ package com.avito.android.plugin.build_param_check -import com.avito.test.gradle.AndroidAppModule -import com.avito.test.gradle.AndroidLibModule +import com.avito.test.gradle.module.AndroidAppModule +import com.avito.test.gradle.module.AndroidLibModule import com.avito.test.gradle.TestProjectGenerator import com.avito.test.gradle.gradlew import org.junit.jupiter.api.Test diff --git a/subprojects/gradle/buildchecks/src/test/kotlin/com/avito/android/plugin/build_param_check/incremental_check/IncrementalKaptTaskTest.kt b/subprojects/gradle/buildchecks/src/test/kotlin/com/avito/android/plugin/build_param_check/incremental_check/IncrementalKaptTaskTest.kt index a6e363ea41..3413e113bf 100644 --- a/subprojects/gradle/buildchecks/src/test/kotlin/com/avito/android/plugin/build_param_check/incremental_check/IncrementalKaptTaskTest.kt +++ b/subprojects/gradle/buildchecks/src/test/kotlin/com/avito/android/plugin/build_param_check/incremental_check/IncrementalKaptTaskTest.kt @@ -1,12 +1,11 @@ package com.avito.android.plugin.build_param_check.incremental_check -import com.avito.test.gradle.AndroidAppModule import com.avito.test.gradle.TestProjectGenerator import com.avito.test.gradle.gradlew +import com.avito.test.gradle.module.AndroidAppModule import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test - import org.junit.jupiter.api.io.TempDir import java.io.File @@ -100,7 +99,6 @@ internal class IncrementalKaptTaskTest { ":checkIncrementalKapt", "-ParchPersistenceVersion=2.2.4", "-Pkapt.incremental.apt=true", - "-Djava.version=$javaVersion", "-Djava.runtime.version=$javaVersion", "-Djava.vendor=Avito", expectFailure = expectFailure @@ -124,7 +122,6 @@ internal class IncrementalKaptTaskTest { AndroidAppModule( name = "room-test", plugins = listOfNotNull( - "kotlin-android", "kotlin-kapt", if (applyRoomPlugin) "com.avito.android.room-config" else null ) diff --git a/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/CiStepsDynamicTest.kt b/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/CiStepsDynamicTest.kt index 9addc94e7c..13bc595983 100644 --- a/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/CiStepsDynamicTest.kt +++ b/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/CiStepsDynamicTest.kt @@ -1,6 +1,6 @@ package com.avito.ci -import com.avito.test.gradle.KotlinModule +import com.avito.test.gradle.module.KotlinModule import com.avito.test.gradle.TestProjectGenerator import com.avito.test.gradle.file import com.avito.test.gradle.gradlew diff --git a/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/CiStepsPluginTest.kt b/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/CiStepsPluginTest.kt index ae071c32c7..30a9950926 100644 --- a/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/CiStepsPluginTest.kt +++ b/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/CiStepsPluginTest.kt @@ -5,8 +5,8 @@ import com.avito.android.plugin.artifactory.artifactoryPasswordParameterName import com.avito.android.plugin.artifactory.artifactoryUserParameterName import com.avito.cd.uploadCdBuildResultTaskName import com.avito.ci.steps.verifyTaskName -import com.avito.test.gradle.AndroidAppModule -import com.avito.test.gradle.AndroidLibModule +import com.avito.test.gradle.module.AndroidAppModule +import com.avito.test.gradle.module.AndroidLibModule import com.avito.test.gradle.TestProjectGenerator import com.avito.test.gradle.file import com.avito.upload_to_googleplay.deployTaskName diff --git a/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/ProjectForImpactAnalysisGenerator.kt b/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/ProjectForImpactAnalysisGenerator.kt index 79fa5d1479..b6634c44d1 100644 --- a/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/ProjectForImpactAnalysisGenerator.kt +++ b/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/ProjectForImpactAnalysisGenerator.kt @@ -1,7 +1,7 @@ package com.avito.ci -import com.avito.test.gradle.AndroidAppModule -import com.avito.test.gradle.AndroidLibModule +import com.avito.test.gradle.module.AndroidAppModule +import com.avito.test.gradle.module.AndroidLibModule import com.avito.test.gradle.TestProjectGenerator import java.io.File diff --git a/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/steps/ArtifactsTest.kt b/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/steps/ArtifactsTest.kt index 792459fe3f..be24761d48 100644 --- a/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/steps/ArtifactsTest.kt +++ b/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/steps/ArtifactsTest.kt @@ -1,6 +1,6 @@ package com.avito.ci.steps -import com.avito.test.gradle.AndroidAppModule +import com.avito.test.gradle.module.AndroidAppModule import com.avito.test.gradle.TestProjectGenerator import com.avito.test.gradle.file import com.avito.test.gradle.gradlew diff --git a/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/steps/MarkReportAsSourceForTMSStepTest.kt b/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/steps/MarkReportAsSourceForTMSStepTest.kt index 520927a977..6a3bd7c11c 100644 --- a/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/steps/MarkReportAsSourceForTMSStepTest.kt +++ b/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/steps/MarkReportAsSourceForTMSStepTest.kt @@ -1,7 +1,7 @@ package com.avito.ci.steps import com.avito.plugin.tmsPluginId -import com.avito.test.gradle.AndroidAppModule +import com.avito.test.gradle.module.AndroidAppModule import com.avito.test.gradle.TestProjectGenerator import com.avito.test.gradle.ciRun import org.junit.jupiter.api.Test diff --git a/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/steps/SignerIntegrationTest.kt b/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/steps/SignerIntegrationTest.kt index 6339857b8d..66a04e2aab 100644 --- a/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/steps/SignerIntegrationTest.kt +++ b/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/steps/SignerIntegrationTest.kt @@ -1,6 +1,6 @@ package com.avito.ci.steps -import com.avito.test.gradle.AndroidAppModule +import com.avito.test.gradle.module.AndroidAppModule import com.avito.test.gradle.TestProjectGenerator import com.avito.test.gradle.TestResult import com.avito.test.gradle.ciRun diff --git a/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/steps/UploadCdBuildResultIntegrationTest.kt b/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/steps/UploadCdBuildResultIntegrationTest.kt index 1a85778584..4cf3d95681 100644 --- a/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/steps/UploadCdBuildResultIntegrationTest.kt +++ b/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/steps/UploadCdBuildResultIntegrationTest.kt @@ -7,7 +7,7 @@ import com.avito.cd.Providers import com.avito.cd.uploadCdBuildResultTaskName import com.avito.ci.runTask import com.avito.git.Git -import com.avito.test.gradle.AndroidAppModule +import com.avito.test.gradle.module.AndroidAppModule import com.avito.test.gradle.TestProjectGenerator import com.avito.test.gradle.file import com.avito.test.http.Mock diff --git a/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/steps/UploadToQappsTest.kt b/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/steps/UploadToQappsTest.kt index d93ed427ba..e220389895 100644 --- a/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/steps/UploadToQappsTest.kt +++ b/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/steps/UploadToQappsTest.kt @@ -1,6 +1,6 @@ package com.avito.ci.steps -import com.avito.test.gradle.AndroidAppModule +import com.avito.test.gradle.module.AndroidAppModule import com.avito.test.gradle.TestProjectGenerator import com.avito.test.gradle.file import com.avito.test.gradle.gradlew diff --git a/subprojects/gradle/ci-logger/src/main/kotlin/com/avito/utils/logging/Gradle.kt b/subprojects/gradle/ci-logger/src/main/kotlin/com/avito/utils/logging/Gradle.kt index 8e3cc2a75e..51069c17a1 100644 --- a/subprojects/gradle/ci-logger/src/main/kotlin/com/avito/utils/logging/Gradle.kt +++ b/subprojects/gradle/ci-logger/src/main/kotlin/com/avito/utils/logging/Gradle.kt @@ -33,7 +33,7 @@ private fun provideLogger(project: Project, loggerName: String): CILogger { ) }.logger } else { - localBuildLogger(project.gradle.startParameter.logLevel < LogLevel.LIFECYCLE) + localBuildLogger(project.gradle.startParameter.logLevel < LogLevel.LIFECYCLE, loggerName) } } @@ -96,10 +96,14 @@ private fun defaultCILogger( ) } -private fun localBuildLogger(debug: Boolean): CILogger { +private fun localBuildLogger( + debug: Boolean, + name: String +): CILogger { val gradleDebugLogger = if (debug) { CILoggingHandlerImplementation( + formatter = AppendPrefixFormatter(name), destination = StdoutDestination ) } else { @@ -107,6 +111,7 @@ private fun localBuildLogger(debug: Boolean): CILogger { } val stdoutHandler = CILoggingHandlerImplementation( + formatter = AppendPrefixFormatter(name), destination = StdoutDestination ) diff --git a/subprojects/gradle/code-ownership/src/test/kotlin/com/avito/android/CodeOwnershipValidationTest.kt b/subprojects/gradle/code-ownership/src/test/kotlin/com/avito/android/CodeOwnershipValidationTest.kt index 6f8e70baa5..e57076bd6a 100644 --- a/subprojects/gradle/code-ownership/src/test/kotlin/com/avito/android/CodeOwnershipValidationTest.kt +++ b/subprojects/gradle/code-ownership/src/test/kotlin/com/avito/android/CodeOwnershipValidationTest.kt @@ -3,8 +3,8 @@ package com.avito.android import Visibility import com.avito.android.CodeOwnershipValidationTest.Case.NegativeCase import com.avito.android.CodeOwnershipValidationTest.Case.PositiveCase -import com.avito.test.gradle.AndroidAppModule -import com.avito.test.gradle.AndroidLibModule +import com.avito.test.gradle.module.AndroidAppModule +import com.avito.test.gradle.module.AndroidLibModule import com.avito.test.gradle.ManualTempFolder import com.avito.test.gradle.TestProjectGenerator import com.avito.test.gradle.gradlew diff --git a/subprojects/gradle/code-ownership/src/test/kotlin/com/avito/android/PlatformDependencyTest.kt b/subprojects/gradle/code-ownership/src/test/kotlin/com/avito/android/PlatformDependencyTest.kt index 28aecd2fbc..fed910be66 100644 --- a/subprojects/gradle/code-ownership/src/test/kotlin/com/avito/android/PlatformDependencyTest.kt +++ b/subprojects/gradle/code-ownership/src/test/kotlin/com/avito/android/PlatformDependencyTest.kt @@ -1,7 +1,7 @@ package com.avito.android -import com.avito.test.gradle.KotlinModule -import com.avito.test.gradle.PlatformModule +import com.avito.test.gradle.module.KotlinModule +import com.avito.test.gradle.module.PlatformModule import com.avito.test.gradle.TestProjectGenerator import com.avito.test.gradle.gradlew import org.junit.jupiter.api.Test diff --git a/subprojects/gradle/impact/src/test/kotlin/com/avito/impact/ImpactAnalysisTest.kt b/subprojects/gradle/impact/src/test/kotlin/com/avito/impact/ImpactAnalysisTest.kt index d890a16ce2..c172cd0fbd 100644 --- a/subprojects/gradle/impact/src/test/kotlin/com/avito/impact/ImpactAnalysisTest.kt +++ b/subprojects/gradle/impact/src/test/kotlin/com/avito/impact/ImpactAnalysisTest.kt @@ -1,16 +1,16 @@ package com.avito.impact -import com.avito.test.gradle.AndroidAppModule -import com.avito.test.gradle.AndroidLibModule -import com.avito.test.gradle.Module -import com.avito.test.gradle.ParentGradleModule -import com.avito.test.gradle.PlatformModule import com.avito.test.gradle.TestProjectGenerator import com.avito.test.gradle.TestResult import com.avito.test.gradle.commit import com.avito.test.gradle.dir import com.avito.test.gradle.file import com.avito.test.gradle.git +import com.avito.test.gradle.module.AndroidAppModule +import com.avito.test.gradle.module.AndroidLibModule +import com.avito.test.gradle.module.Module +import com.avito.test.gradle.module.ParentGradleModule +import com.avito.test.gradle.module.PlatformModule import com.avito.test.gradle.mutate import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Disabled @@ -134,7 +134,7 @@ class ImpactAnalysisTest { ) with(projectDir) { checkoutSourceBranch() - file("app/$KOTLIN_SOURCE_SET/SomeClass.kt").mutate() + file("app/$KOTLIN_SOURCE_SET/com/app/SomeClass.kt").mutate() } val result = detectChanges() diff --git a/subprojects/gradle/impact/src/test/kotlin/com/avito/impact/SourceSetsImpactTest.kt b/subprojects/gradle/impact/src/test/kotlin/com/avito/impact/SourceSetsImpactTest.kt index 4f0a3bf2af..dfb97bf9f0 100644 --- a/subprojects/gradle/impact/src/test/kotlin/com/avito/impact/SourceSetsImpactTest.kt +++ b/subprojects/gradle/impact/src/test/kotlin/com/avito/impact/SourceSetsImpactTest.kt @@ -1,7 +1,5 @@ package com.avito.impact -import com.avito.test.gradle.AndroidAppModule -import com.avito.test.gradle.AndroidLibModule import com.avito.test.gradle.TestProjectGenerator import com.avito.test.gradle.TestResult import com.avito.test.gradle.commit @@ -10,6 +8,8 @@ import com.avito.test.gradle.file import com.avito.test.gradle.git import com.avito.test.gradle.kotlinClass import com.avito.test.gradle.module +import com.avito.test.gradle.module.AndroidAppModule +import com.avito.test.gradle.module.AndroidLibModule import com.avito.test.gradle.mutate import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test @@ -97,7 +97,7 @@ class SourceSetsImpactTest { fun `change in the implementation main - detects changes in all tests and dependant projects`() { with(projectDir) { git("reset --hard") - file("feature/src/main/kotlin/SomeClass.kt").mutate() + file("feature/src/main/kotlin/com/feature/SomeClass.kt").mutate() } val result = detectChanges() diff --git a/subprojects/gradle/instrumentation-test-impact-analysis/src/test/kotlin/com/avito/instrumentation/impact/util/Project.kt b/subprojects/gradle/instrumentation-test-impact-analysis/src/test/kotlin/com/avito/instrumentation/impact/util/Project.kt index e5e426785c..7b2c985952 100644 --- a/subprojects/gradle/instrumentation-test-impact-analysis/src/test/kotlin/com/avito/instrumentation/impact/util/Project.kt +++ b/subprojects/gradle/instrumentation-test-impact-analysis/src/test/kotlin/com/avito/instrumentation/impact/util/Project.kt @@ -1,14 +1,14 @@ package com.avito.instrumentation.impact.util -import com.avito.test.gradle.AndroidAppModule -import com.avito.test.gradle.AndroidLibModule -import com.avito.test.gradle.KotlinModule import com.avito.test.gradle.TestProjectGenerator import com.avito.test.gradle.append import com.avito.test.gradle.commit import com.avito.test.gradle.dir import com.avito.test.gradle.git import com.avito.test.gradle.kotlinClass +import com.avito.test.gradle.module.AndroidAppModule +import com.avito.test.gradle.module.AndroidLibModule +import com.avito.test.gradle.module.KotlinModule import java.io.File const val projectToChange = "application" diff --git a/subprojects/gradle/instrumentation-tests/src/test/kotlin/com/avito/instrumentation/InstrumentationParamsBuildingTest.kt b/subprojects/gradle/instrumentation-tests/src/test/kotlin/com/avito/instrumentation/InstrumentationParamsBuildingTest.kt index 579427bca8..ef4cdb1f2c 100644 --- a/subprojects/gradle/instrumentation-tests/src/test/kotlin/com/avito/instrumentation/InstrumentationParamsBuildingTest.kt +++ b/subprojects/gradle/instrumentation-tests/src/test/kotlin/com/avito/instrumentation/InstrumentationParamsBuildingTest.kt @@ -2,7 +2,7 @@ package com.avito.instrumentation import com.avito.instrumentation.configuration.InstrumentationPluginConfiguration.GradleInstrumentationPluginConfiguration.Data import com.avito.report.model.RunId -import com.avito.test.gradle.AndroidAppModule +import com.avito.test.gradle.module.AndroidAppModule import com.avito.test.gradle.TestProjectGenerator import com.avito.test.gradle.ciRun import com.avito.test.gradle.file diff --git a/subprojects/gradle/instrumentation-tests/src/test/kotlin/com/avito/instrumentation/InstrumentationTestsPluginCIFalseTests.kt b/subprojects/gradle/instrumentation-tests/src/test/kotlin/com/avito/instrumentation/InstrumentationTestsPluginCIFalseTests.kt index dfb400c22f..4e22c62a80 100644 --- a/subprojects/gradle/instrumentation-tests/src/test/kotlin/com/avito/instrumentation/InstrumentationTestsPluginCIFalseTests.kt +++ b/subprojects/gradle/instrumentation-tests/src/test/kotlin/com/avito/instrumentation/InstrumentationTestsPluginCIFalseTests.kt @@ -1,6 +1,6 @@ package com.avito.instrumentation -import com.avito.test.gradle.AndroidAppModule +import com.avito.test.gradle.module.AndroidAppModule import com.avito.test.gradle.TestProjectGenerator import com.avito.test.gradle.TestResult import com.avito.test.gradle.gradlew diff --git a/subprojects/gradle/instrumentation-tests/src/test/kotlin/com/avito/instrumentation/InstrumentationTestsPluginTest.kt b/subprojects/gradle/instrumentation-tests/src/test/kotlin/com/avito/instrumentation/InstrumentationTestsPluginTest.kt index 907f2f3fe7..5215a025f5 100644 --- a/subprojects/gradle/instrumentation-tests/src/test/kotlin/com/avito/instrumentation/InstrumentationTestsPluginTest.kt +++ b/subprojects/gradle/instrumentation-tests/src/test/kotlin/com/avito/instrumentation/InstrumentationTestsPluginTest.kt @@ -1,8 +1,8 @@ package com.avito.instrumentation -import com.avito.test.gradle.AndroidAppModule -import com.avito.test.gradle.AndroidLibModule -import com.avito.test.gradle.Module +import com.avito.test.gradle.module.AndroidAppModule +import com.avito.test.gradle.module.AndroidLibModule +import com.avito.test.gradle.module.Module import com.avito.test.gradle.TestProjectGenerator import com.avito.test.gradle.ciRun import org.junit.jupiter.api.Test diff --git a/subprojects/gradle/module-types/src/test/kotlin/com/avito/android/ModuleTypesPluginTest.kt b/subprojects/gradle/module-types/src/test/kotlin/com/avito/android/ModuleTypesPluginTest.kt index 74af803d8b..db0ba520f8 100644 --- a/subprojects/gradle/module-types/src/test/kotlin/com/avito/android/ModuleTypesPluginTest.kt +++ b/subprojects/gradle/module-types/src/test/kotlin/com/avito/android/ModuleTypesPluginTest.kt @@ -1,7 +1,7 @@ package com.avito.android -import com.avito.test.gradle.AndroidAppModule -import com.avito.test.gradle.AndroidLibModule +import com.avito.test.gradle.module.AndroidAppModule +import com.avito.test.gradle.module.AndroidLibModule import com.avito.test.gradle.TestProjectGenerator import com.avito.test.gradle.git import com.avito.test.gradle.gradlew diff --git a/subprojects/gradle/module-types/src/test/kotlin/com/avito/android/ModuleTypesRules.kt b/subprojects/gradle/module-types/src/test/kotlin/com/avito/android/ModuleTypesRules.kt index 6cd00f145f..5b86ad3c54 100644 --- a/subprojects/gradle/module-types/src/test/kotlin/com/avito/android/ModuleTypesRules.kt +++ b/subprojects/gradle/module-types/src/test/kotlin/com/avito/android/ModuleTypesRules.kt @@ -6,7 +6,7 @@ import com.avito.android.ModuleType.IMPLEMENTATION import com.avito.android.ModuleType.TEST_LIB import com.avito.android.ModuleTypesRules.Case.NegativeCase import com.avito.android.ModuleTypesRules.Case.PositiveCase -import com.avito.test.gradle.AndroidLibModule +import com.avito.test.gradle.module.AndroidLibModule import com.avito.test.gradle.ManualTempFolder import com.avito.test.gradle.TestProjectGenerator import com.avito.test.gradle.git diff --git a/subprojects/gradle/namespaced-resources-fixer/src/test/kotlin/com/avito/android/plugin/NamespacedResourcesFixerPluginTest.kt b/subprojects/gradle/namespaced-resources-fixer/src/test/kotlin/com/avito/android/plugin/NamespacedResourcesFixerPluginTest.kt index edb7ec35af..446e613c88 100644 --- a/subprojects/gradle/namespaced-resources-fixer/src/test/kotlin/com/avito/android/plugin/NamespacedResourcesFixerPluginTest.kt +++ b/subprojects/gradle/namespaced-resources-fixer/src/test/kotlin/com/avito/android/plugin/NamespacedResourcesFixerPluginTest.kt @@ -1,7 +1,7 @@ package com.avito.android.plugin -import com.avito.test.gradle.AndroidAppModule -import com.avito.test.gradle.AndroidLibModule +import com.avito.test.gradle.module.AndroidAppModule +import com.avito.test.gradle.module.AndroidLibModule import com.avito.test.gradle.TestProjectGenerator import com.avito.test.gradle.file import com.avito.test.gradle.gradlew diff --git a/subprojects/gradle/prosector/src/test/kotlin/ProsectorPluginTest.kt b/subprojects/gradle/prosector/src/test/kotlin/ProsectorPluginTest.kt index 3e41cc7516..0126800f11 100644 --- a/subprojects/gradle/prosector/src/test/kotlin/ProsectorPluginTest.kt +++ b/subprojects/gradle/prosector/src/test/kotlin/ProsectorPluginTest.kt @@ -1,6 +1,7 @@ -import com.avito.test.gradle.AndroidAppModule + import com.avito.test.gradle.TestProjectGenerator import com.avito.test.gradle.TestResult +import com.avito.test.gradle.module.AndroidAppModule import com.avito.test.http.MockWebServerFactory import com.google.common.truth.Truth.assertThat import com.google.gson.Gson @@ -110,6 +111,7 @@ class ProsectorPluginTest { modules = listOf( AndroidAppModule( appModuleName, + enableKotlinAndroidPlugin = false, plugins = listOf("com.avito.android.prosector"), versionName = versionName, packageName = testPackageId, diff --git a/subprojects/gradle/qapps/src/test/kotlin/com/avito/plugin/QAppsPluginIntegrationTest.kt b/subprojects/gradle/qapps/src/test/kotlin/com/avito/plugin/QAppsPluginIntegrationTest.kt index 0e3b577326..4980829d09 100644 --- a/subprojects/gradle/qapps/src/test/kotlin/com/avito/plugin/QAppsPluginIntegrationTest.kt +++ b/subprojects/gradle/qapps/src/test/kotlin/com/avito/plugin/QAppsPluginIntegrationTest.kt @@ -1,9 +1,9 @@ package com.avito.plugin -import com.avito.test.gradle.AndroidAppModule import com.avito.test.gradle.TestProjectGenerator import com.avito.test.gradle.TestResult import com.avito.test.gradle.gradlew +import com.avito.test.gradle.module.AndroidAppModule import com.avito.test.http.MockWebServerFactory import com.google.common.truth.Truth.assertThat import okhttp3.mockwebserver.MockResponse @@ -81,6 +81,7 @@ internal class QAppsPluginIntegrationTest { modules = listOf( AndroidAppModule( "app", + enableKotlinAndroidPlugin = false, plugins = listOf("com.avito.android.qapps"), versionCode = "111", versionName = "12.3", diff --git a/subprojects/gradle/qapps/src/test/kotlin/com/avito/plugin/QAppsPluginTest.kt b/subprojects/gradle/qapps/src/test/kotlin/com/avito/plugin/QAppsPluginTest.kt index ebd79bf4cd..e475a1d78c 100644 --- a/subprojects/gradle/qapps/src/test/kotlin/com/avito/plugin/QAppsPluginTest.kt +++ b/subprojects/gradle/qapps/src/test/kotlin/com/avito/plugin/QAppsPluginTest.kt @@ -1,8 +1,8 @@ package com.avito.plugin -import com.avito.test.gradle.AndroidAppModule import com.avito.test.gradle.TestProjectGenerator import com.avito.test.gradle.gradlew +import com.avito.test.gradle.module.AndroidAppModule import org.junit.jupiter.api.Test import org.junit.jupiter.api.io.TempDir import java.io.File @@ -60,6 +60,7 @@ internal class QAppsPluginTest { modules = listOf( AndroidAppModule( "app", + enableKotlinAndroidPlugin = false, plugins = listOf("com.avito.android.qapps"), buildGradleExtra = """ qapps { diff --git a/subprojects/gradle/robolectric/src/test/kotlin/com/avito/android/plugin/RobolectricPluginTest.kt b/subprojects/gradle/robolectric/src/test/kotlin/com/avito/android/plugin/RobolectricPluginTest.kt index 8914a825d5..039f398e5c 100644 --- a/subprojects/gradle/robolectric/src/test/kotlin/com/avito/android/plugin/RobolectricPluginTest.kt +++ b/subprojects/gradle/robolectric/src/test/kotlin/com/avito/android/plugin/RobolectricPluginTest.kt @@ -1,8 +1,8 @@ package com.avito.android.plugin -import com.avito.test.gradle.AndroidAppModule import com.avito.test.gradle.TestProjectGenerator import com.avito.test.gradle.gradlew +import com.avito.test.gradle.module.AndroidAppModule import org.junit.jupiter.api.Test import org.junit.jupiter.api.io.TempDir import java.io.File @@ -13,7 +13,7 @@ internal class RobolectricPluginTest { fun integration(@TempDir tempDir: File) { TestProjectGenerator( plugins = listOf("com.avito.android.robolectric"), - modules = listOf(AndroidAppModule("app")) + modules = listOf(AndroidAppModule("app", enableKotlinAndroidPlugin = false)) ).generateIn(tempDir) gradlew(tempDir, "help", "-PandroidXTestVersion=1.2.0").assertThat().buildSuccessful() diff --git a/subprojects/gradle/room-config/src/test/kotlin/com/avito/android/plugin/RoomConfigPluginTest.kt b/subprojects/gradle/room-config/src/test/kotlin/com/avito/android/plugin/RoomConfigPluginTest.kt index 9fa76fe6fb..fae1f57c86 100644 --- a/subprojects/gradle/room-config/src/test/kotlin/com/avito/android/plugin/RoomConfigPluginTest.kt +++ b/subprojects/gradle/room-config/src/test/kotlin/com/avito/android/plugin/RoomConfigPluginTest.kt @@ -1,6 +1,6 @@ package com.avito.android.plugin -import com.avito.test.gradle.AndroidLibModule +import com.avito.test.gradle.module.AndroidLibModule import com.avito.test.gradle.TestProjectGenerator import com.avito.test.gradle.gradlew import org.junit.jupiter.api.Test diff --git a/subprojects/gradle/signer/src/test/kotlin/com/avito/plugin/SignServicePluginTest.kt b/subprojects/gradle/signer/src/test/kotlin/com/avito/plugin/SignServicePluginTest.kt index ef74331191..1155fa9d63 100644 --- a/subprojects/gradle/signer/src/test/kotlin/com/avito/plugin/SignServicePluginTest.kt +++ b/subprojects/gradle/signer/src/test/kotlin/com/avito/plugin/SignServicePluginTest.kt @@ -1,9 +1,9 @@ package com.avito.plugin -import com.avito.test.gradle.AndroidAppModule import com.avito.test.gradle.TestProjectGenerator import com.avito.test.gradle.ciRun import com.avito.test.gradle.gradlew +import com.avito.test.gradle.module.AndroidAppModule import com.avito.test.http.MockWebServerFactory import com.google.common.truth.Truth.assertThat import okhttp3.mockwebserver.MockResponse @@ -116,6 +116,7 @@ class SignServicePluginTest { modules = listOf( AndroidAppModule( "app", + enableKotlinAndroidPlugin = false, versionCode = "100", versionName = "22.1", plugins = listOf("com.avito.android.signer"), diff --git a/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/GradleTestKit.kt b/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/GradleTestKit.kt index f46fa048f5..0ba8ffda06 100644 --- a/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/GradleTestKit.kt +++ b/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/GradleTestKit.kt @@ -3,7 +3,7 @@ package com.avito.test.gradle import org.gradle.testkit.runner.BuildResult import org.gradle.testkit.runner.GradleRunner import org.gradle.testkit.runner.TaskOutcome -import org.gradle.testkit.runner.UnexpectedBuildFailure +import org.gradle.testkit.runner.UnexpectedBuildResultException import java.io.File /** @@ -18,7 +18,8 @@ fun gradlew( projectDir: File, vararg args: String, dryRun: Boolean = false, - expectFailure: Boolean = false + expectFailure: Boolean = false, + useModuleClasspath: Boolean = true ): TestResult { val defaultArguments = mutableListOf( @@ -41,7 +42,7 @@ fun gradlew( val builder = GradleRunner.create() .withProjectDir(projectDir) .withArguments(finalArgs) - .withPluginClasspath() + .apply { if(useModuleClasspath) withPluginClasspath() } /** * WARNING! it breaks classpath and causes failures in AGP's tasks * see. MBS-5462 @@ -59,8 +60,8 @@ fun gradlew( } else { TestResult.Success(builder.build(), dryRun) } - } catch (e: UnexpectedBuildFailure) { - throw AssertionError("Build failed unexpectedly", e) + } catch (e: UnexpectedBuildResultException) { + throw AssertionError("Unexpected build result", e) } } diff --git a/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/TestProjectGenerator.kt b/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/TestProjectGenerator.kt index 58183acfa0..739db45c2b 100644 --- a/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/TestProjectGenerator.kt +++ b/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/TestProjectGenerator.kt @@ -1,10 +1,23 @@ package com.avito.test.gradle import com.avito.android.androidHomeFromLocalPropertiesFallback +import com.avito.test.gradle.files.build_gradle +import com.avito.test.gradle.module.AndroidAppModule +import com.avito.test.gradle.module.AndroidLibModule +import com.avito.test.gradle.module.Module import java.io.File import java.io.FileOutputStream import java.util.Properties +internal val sdkVersion: Int by lazy { System.getProperty("compileSdkVersion").toInt() } +internal val buildToolsVersion: String by lazy { System.getProperty("buildToolsVersion") } +internal val agpVersion: String by lazy { System.getProperty("androidGradlePluginVersion") } +internal val kotlinVersion: String by lazy { System.getProperty("kotlinVersion") } + +interface Generator { + fun generateIn(file: File) +} + /** * Кастомизируемый многомодульный проект для тестирования in-house плагинов * используйте TempDirectory junit 5 extension, чтобы сгенерировать временную директорию для тестов @@ -36,15 +49,6 @@ class TestProjectGenerator( const val appB = "appB" const val sharedModule = "shared" const val independentModule = "independent" - const val transitiveModule = "transitive" - - val allModules = setOf( - appA, - appB, - sharedModule, - independentModule, - transitiveModule - ) } override fun generateIn(file: File) { @@ -55,6 +59,7 @@ class TestProjectGenerator( writeText( """ plugins { + id 'com.android.application' apply false id "org.jetbrains.kotlin.jvm" version "$kotlinVersion" apply false ${plugins.joinToString(separator = "\n") { "id '$it'" }} } @@ -135,316 +140,3 @@ private fun generateIncludes(modules: List, prefix: String): String = "include('$prefix:${it.name}')" + "\n" + generateIncludes(it.modules, "$prefix:${it.name}") } -interface Module : Generator { - val name: String - val plugins: List - val buildGradleExtra: String - val modules: List -} - -interface AndroidModule : Module { - val packageName: String -} - -class KotlinModule( - override val name: String, - override val plugins: List = emptyList(), - override val buildGradleExtra: String = "", - override val modules: List = emptyList(), - private val dependencies: String = "", - private val mutator: File.() -> Unit = {} -) : Module { - - override fun generateIn(file: File) { - file.module(name) { - - build_gradle { - writeText( - """ -plugins { - id 'kotlin' - ${plugins.joinToString(separator = "\n") { "id '$it'" }} -} - -$buildGradleExtra - -dependencies { - $dependencies - implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion") -} - """.trimIndent() - ) - } - dir("src/main") { - dir("kotlin") { - kotlinClass("SomeClass") - } - } - this.mutator() - } - } -} - -/** - * никакой полезной нагрузки, только контейнер для других модулей - * :test:utils <- как тут test - */ -class EmptyModule( - override val name: String, - override val modules: List, - override val plugins: List = emptyList(), - override val buildGradleExtra: String = "" -) : Module { - - override fun generateIn(file: File) { - file.module(name) { - modules.forEach { it.generateIn(this) } - } - } -} - -/** - * Пустой модуль для настройки gradle всех дочерних для него модулей - */ -class ParentGradleModule( - override val name: String, - override val modules: List, - override val plugins: List = emptyList(), - override val buildGradleExtra: String = "" -) : Module { - - override fun generateIn(file: File) { - file.module(name) { - build_gradle { - writeText( - "subprojects { afterEvaluate { println(\"\$name project configuration was altered by parent module's build.gradle\") }}".trimIndent() - ) - } - modules.forEach { it.generateIn(this) } - } - } -} - -class PlatformModule( - override val name: String, - override val plugins: List = emptyList(), - override val modules: List = emptyList(), - override val buildGradleExtra: String = "" -) : Module { - - override fun generateIn(file: File) { - val customPlugins = plugins.joinToString(separator = "\n") { "id '$it'" } - - file.module(name) { - build_gradle { - writeText( - """ -plugins { - id 'java-platform' - $customPlugins -} - -$buildGradleExtra -""" - ) - } - } - } -} - -class AndroidLibModule( - override val name: String, - override val packageName: String = "com.$name", - override val plugins: List = emptyList(), - override val buildGradleExtra: String = "", - override val modules: List = emptyList(), - private val dependencies: String = "", - private val mutator: File.() -> Unit = {} -) : AndroidModule { - - override fun generateIn(file: File) { - file.module(name) { - - build_gradle { - writeText( - """ -plugins { - id 'com.android.library' - id 'kotlin-android' - ${plugins.joinToString(separator = "\n") { "id '$it'" }} -} - -$buildGradleExtra - -android { - compileSdkVersion $sdkVersion - buildToolsVersion "$buildToolsVersion" -} - -dependencies { - $dependencies - implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion") -} - """.trimIndent() - ) - } - dir("src/main") { - androidManifest(packageName = packageName) - dir("kotlin") { - kotlinClass("SomeClass") - } - dir("res") { - dir("layout") { - file( - "lib.xml", content = """ - - """.trimIndent() - ) - } - } - } - this.mutator() - } - } -} - -interface Generator { - fun generateIn(file: File) -} - -class InstrumentationTest(val className: String) : Generator { - override fun generateIn(file: File) { - file.kotlinClass(className, content = { - """ - import org.junit.Test - - class $className { - - @Test - fun test() { - //success - } - } - """.trimIndent() - }) - } -} - -class AndroidAppModule( - override val name: String, - override val packageName: String = "com.$name", - override val plugins: List = emptyList(), - override val buildGradleExtra: String = "", - override val modules: List = emptyList(), - private val instrumentationTests: List = emptyList(), - private val dependencies: String = "", - private val versionName: String = "", - private val versionCode: String = "", - private val customScript: String = "", - private val imports: List = emptyList(), - private val mutator: File.() -> Unit = {} -) : AndroidModule { - - override fun generateIn(file: File) { - file.module(name) { - dir("src") { - dir("main") { - androidManifest(packageName = packageName) - dir("kotlin") { - kotlinClass("SomeClass") - } - dir("res") { - dir("values") { - file( - "id.xml", content = """ - - - - """.trimIndent() - ) - } - } - } - dir("androidTest") { - dir("java") { - kotlinClass("SomeClass") - instrumentationTests.forEach { it.generateIn(this) } - } - } - } - - file( - "proguard.pro", """ --ignorewarnings --keep public class * { - public protected *; -} -""".trimIndent() - ) - - build_gradle { - writeText( - """${imports.joinToString(separator = "\n")} -plugins { - id 'com.android.application' -${plugins.joinToString(separator = "\n") { " id '$it'" }} -} - -$buildGradleExtra - -android { - compileSdkVersion $sdkVersion - buildToolsVersion "$buildToolsVersion" - defaultConfig { - applicationId "$packageName" - versionCode $versionCode - versionName "$versionName" - } - buildTypes { - release {} - debug {} - staging { - initWith(debug) - matchingFallbacks = ["debug"] - } - } -} - -afterEvaluate{ - tasks.named("lintVitalRelease").configure { onlyIf { false } } -} - -dependencies { - $dependencies - implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion") -} - -$customScript -""".trimIndent() - ) - } - this.mutator() - } - } -} - -val sdkVersion: Int by lazy { System.getProperty("compileSdkVersion").toInt() } -val buildToolsVersion: String by lazy { System.getProperty("buildToolsVersion") } -val agpVersion: String by lazy { System.getProperty("androidGradlePluginVersion") } -val kotlinVersion: String by lazy { System.getProperty("kotlinVersion") } - -private fun File.build_gradle(mutator: File.() -> Unit = {}) = file("build.gradle").apply(mutator) - -private fun File.androidManifest(packageName: String) = file( - "AndroidManifest.xml", """ - - -""".trimIndent() -) diff --git a/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/files/AndroidManifest.kt b/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/files/AndroidManifest.kt new file mode 100644 index 0000000000..4a45f64831 --- /dev/null +++ b/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/files/AndroidManifest.kt @@ -0,0 +1,12 @@ +package com.avito.test.gradle.files + +import com.avito.test.gradle.file +import java.io.File + +internal fun File.androidManifest(packageName: String) = file( + "AndroidManifest.xml", """ + + +""".trimIndent() +) diff --git a/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/files/BuildGradle.kt b/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/files/BuildGradle.kt new file mode 100644 index 0000000000..c1031d9b1f --- /dev/null +++ b/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/files/BuildGradle.kt @@ -0,0 +1,6 @@ +package com.avito.test.gradle.files + +import com.avito.test.gradle.file +import java.io.File + +internal fun File.build_gradle(mutator: File.() -> Unit = {}) = file("build.gradle").apply(mutator) diff --git a/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/files/InstrumentationTest.kt b/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/files/InstrumentationTest.kt new file mode 100644 index 0000000000..48a359b156 --- /dev/null +++ b/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/files/InstrumentationTest.kt @@ -0,0 +1,23 @@ +package com.avito.test.gradle.files + +import com.avito.test.gradle.Generator +import com.avito.test.gradle.kotlinClass +import java.io.File + +class InstrumentationTest(val className: String) : Generator { + override fun generateIn(file: File) { + file.kotlinClass(className, content = { + """ + import org.junit.Test + + class $className { + + @Test + fun test() { + //success + } + } + """.trimIndent() + }) + } +} diff --git a/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/AndroidAppModule.kt b/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/AndroidAppModule.kt new file mode 100644 index 0000000000..098d083fd4 --- /dev/null +++ b/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/AndroidAppModule.kt @@ -0,0 +1,139 @@ +package com.avito.test.gradle.module + +import com.avito.test.gradle.buildToolsVersion +import com.avito.test.gradle.dir +import com.avito.test.gradle.file +import com.avito.test.gradle.files.InstrumentationTest +import com.avito.test.gradle.files.androidManifest +import com.avito.test.gradle.files.build_gradle +import com.avito.test.gradle.kotlinClass +import com.avito.test.gradle.kotlinVersion +import com.avito.test.gradle.module +import com.avito.test.gradle.sdkVersion +import java.io.File + +class AndroidAppModule( + override val name: String, + override val packageName: String = "com.$name", + override val plugins: List = emptyList(), + override val buildGradleExtra: String = "", + override val modules: List = emptyList(), + override val enableKotlinAndroidPlugin: Boolean = true, + private val enableKapt: Boolean = false, + private val instrumentationTests: List = emptyList(), + private val dependencies: String = "", + private val versionName: String = "", + private val versionCode: String = "", + private val customScript: String = "", + private val imports: List = emptyList(), + private val mutator: File.(AndroidAppModule) -> Unit = {} +) : AndroidModule { + + override fun generateIn(file: File) { + file.module(name) { + dir("src") { + dir("main") { + androidManifest(packageName = packageName) + if(enableKotlinAndroidPlugin || enableKapt) { + dir("kotlin") { + kotlinClass("SomeClass", packageName) + } + } + dir("res") { + dir("values") { + file( + "id.xml", content = """ + + + + """.trimIndent() + ) + } + } + } + dir("androidTest") { + if(enableKotlinAndroidPlugin || enableKapt) { + dir("kotlin") { + kotlinClass("SomeTestClass", packageName) + instrumentationTests.forEach { it.generateIn(this) } + } + } + } + } + + file( + "proguard.pro", """ +-ignorewarnings +-keep public class * { + public protected *; +} +""".trimIndent() + ) + + build_gradle { + writeText( + """${imports.joinToString(separator = "\n")} + + +plugins { + id 'com.android.application' + ${if(enableKotlinAndroidPlugin || enableKapt) "id 'kotlin-android'" else ""} + ${if(enableKapt) "id 'kotlin-kapt'" else ""} +${plugins.joinToString(separator = "\n") { " id '$it'" }} +} + +$buildGradleExtra + +android { + compileSdkVersion $sdkVersion + buildToolsVersion "$buildToolsVersion" + defaultConfig { + applicationId "$packageName" + versionCode $versionCode + versionName "$versionName" + } + buildTypes { + release {} + debug {} + staging { + initWith(debug) + matchingFallbacks = ["debug"] + } + } + ${if(enableKotlinAndroidPlugin || enableKapt) """ + sourceSets { + main { + java.srcDir("src/main/kotlin") + } + test { + java.srcDir("src/test/kotlin") + } + androidTest { + java.srcDir("src/androidTest/kotlin") + } + } + """.trimIndent() else ""} +} + +afterEvaluate{ + tasks.named("lintVitalRelease").configure { onlyIf { false } } +} + +dependencies { + $dependencies + implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion") + testImplementation("junit:junit:4.13") + ${if(enableKapt) """ + implementation("com.google.dagger:dagger:2.29.1") + kapt("com.google.dagger:dagger-compiler:2.29.1") + """.trimIndent() else ""} +} + +$customScript +""".trimIndent() + ) + } + this.mutator(this@AndroidAppModule) + } + } +} diff --git a/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/AndroidLibModule.kt b/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/AndroidLibModule.kt new file mode 100644 index 0000000000..eebd1bd219 --- /dev/null +++ b/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/AndroidLibModule.kt @@ -0,0 +1,84 @@ +package com.avito.test.gradle.module + +import com.avito.test.gradle.buildToolsVersion +import com.avito.test.gradle.dir +import com.avito.test.gradle.file +import com.avito.test.gradle.files.androidManifest +import com.avito.test.gradle.files.build_gradle +import com.avito.test.gradle.kotlinClass +import com.avito.test.gradle.kotlinVersion +import com.avito.test.gradle.module +import com.avito.test.gradle.sdkVersion +import java.io.File + +class AndroidLibModule( + override val name: String, + override val packageName: String = "com.$name", + override val plugins: List = emptyList(), + override val buildGradleExtra: String = "", + override val modules: List = emptyList(), + override val enableKotlinAndroidPlugin: Boolean = true, + private val dependencies: String = "", + private val mutator: File.() -> Unit = {} +) : AndroidModule { + + override fun generateIn(file: File) { + file.module(name) { + + build_gradle { + writeText( + """ +plugins { + id 'com.android.library' + ${if(enableKotlinAndroidPlugin) "id 'kotlin-android'" else ""} + ${plugins.joinToString(separator = "\n") { "id '$it'" }} +} + +$buildGradleExtra + +android { + compileSdkVersion $sdkVersion + buildToolsVersion "$buildToolsVersion" + ${if(enableKotlinAndroidPlugin) """ + sourceSets { + main { + java.srcDir("src/main/kotlin") + } + } + """.trimIndent() else ""} +} + +dependencies { + $dependencies + implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion") +} + """.trimIndent() + ) + } + dir("src/main") { + androidManifest(packageName = packageName) + if(enableKotlinAndroidPlugin) { + dir("kotlin") { + kotlinClass("SomeClass", packageName) + } + } + dir("res") { + dir("layout") { + file( + "lib.xml", content = """ + + """.trimIndent() + ) + } + } + } + this.mutator() + } + } +} diff --git a/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/AndroidModule.kt b/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/AndroidModule.kt new file mode 100644 index 0000000000..c2888063fd --- /dev/null +++ b/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/AndroidModule.kt @@ -0,0 +1,6 @@ +package com.avito.test.gradle.module + +interface AndroidModule : Module { + val packageName: String + val enableKotlinAndroidPlugin: Boolean +} diff --git a/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/FolderModule.kt b/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/FolderModule.kt new file mode 100644 index 0000000000..4ad303731e --- /dev/null +++ b/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/FolderModule.kt @@ -0,0 +1,22 @@ +package com.avito.test.gradle.module + +import com.avito.test.gradle.module +import java.io.File + +/** + * The folder for modules + * :test:utils <- for example + */ +class FolderModule( + override val name: String, + override val modules: List +) : Module { + override val plugins: List = emptyList() + override val buildGradleExtra = "" + + override fun generateIn(file: File) { + file.module(name) { + modules.forEach { it.generateIn(this) } + } + } +} diff --git a/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/KotlinModule.kt b/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/KotlinModule.kt new file mode 100644 index 0000000000..b9a93d0222 --- /dev/null +++ b/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/KotlinModule.kt @@ -0,0 +1,48 @@ +package com.avito.test.gradle.module + +import com.avito.test.gradle.dir +import com.avito.test.gradle.files.build_gradle +import com.avito.test.gradle.kotlinClass +import com.avito.test.gradle.kotlinVersion +import com.avito.test.gradle.module +import java.io.File + +class KotlinModule( + override val name: String, + val packageName: String = "com.$name", + override val plugins: List = emptyList(), + override val buildGradleExtra: String = "", + override val modules: List = emptyList(), + private val dependencies: String = "", + private val mutator: File.() -> Unit = {} +) : Module { + + override fun generateIn(file: File) { + file.module(name) { + + build_gradle { + writeText( + """ +plugins { + id 'kotlin' + ${plugins.joinToString(separator = "\n") { "id '$it'" }} +} + +$buildGradleExtra + +dependencies { + $dependencies + implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion") +} + """.trimIndent() + ) + } + dir("src/main") { + dir("kotlin") { + kotlinClass("SomeClass", packageName) + } + } + this.mutator() + } + } +} diff --git a/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/Module.kt b/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/Module.kt new file mode 100644 index 0000000000..7709f84712 --- /dev/null +++ b/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/Module.kt @@ -0,0 +1,10 @@ +package com.avito.test.gradle.module + +import com.avito.test.gradle.Generator + +interface Module : Generator { + val name: String + val plugins: List + val buildGradleExtra: String + val modules: List +} diff --git a/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/ParentGradleModule.kt b/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/ParentGradleModule.kt new file mode 100644 index 0000000000..6f889bf82a --- /dev/null +++ b/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/ParentGradleModule.kt @@ -0,0 +1,27 @@ +package com.avito.test.gradle.module + +import com.avito.test.gradle.files.build_gradle +import com.avito.test.gradle.module +import java.io.File + +/** + * Empty module. It setups build.gradle for all child modules + */ +class ParentGradleModule( + override val name: String, + override val modules: List, + override val plugins: List = emptyList(), + override val buildGradleExtra: String = "" +) : Module { + + override fun generateIn(file: File) { + file.module(name) { + build_gradle { + writeText( + "subprojects { afterEvaluate { println(\"\$name project configuration was altered by parent module's build.gradle\") }}".trimIndent() + ) + } + modules.forEach { it.generateIn(this) } + } + } +} diff --git a/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/PlatformModule.kt b/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/PlatformModule.kt new file mode 100644 index 0000000000..bf0aad4a2a --- /dev/null +++ b/subprojects/gradle/test-project/src/main/kotlin/com/avito/test/gradle/module/PlatformModule.kt @@ -0,0 +1,31 @@ +package com.avito.test.gradle.module + +import com.avito.test.gradle.files.build_gradle +import com.avito.test.gradle.module +import java.io.File + +class PlatformModule( + override val name: String, + override val plugins: List = emptyList(), + override val buildGradleExtra: String = "" +) : Module { + override val modules: List = emptyList() + override fun generateIn(file: File) { + val customPlugins = plugins.joinToString(separator = "\n") { "id '$it'" } + + file.module(name) { + build_gradle { + writeText( + """ +plugins { + id 'java-platform' + $customPlugins +} + +$buildGradleExtra +""" + ) + } + } + } +} diff --git a/subprojects/gradle/test-project/src/test/kotlin/com/avito/test/gradle/TestProjectGeneratorTest.kt b/subprojects/gradle/test-project/src/test/kotlin/com/avito/test/gradle/TestProjectGeneratorTest.kt index 8849bdfb7c..0b54303ab9 100644 --- a/subprojects/gradle/test-project/src/test/kotlin/com/avito/test/gradle/TestProjectGeneratorTest.kt +++ b/subprojects/gradle/test-project/src/test/kotlin/com/avito/test/gradle/TestProjectGeneratorTest.kt @@ -1,5 +1,11 @@ package com.avito.test.gradle +import com.avito.test.gradle.module.AndroidAppModule +import com.avito.test.gradle.module.AndroidLibModule +import com.avito.test.gradle.module.FolderModule +import com.avito.test.gradle.module.KotlinModule +import com.avito.test.gradle.module.ParentGradleModule +import com.avito.test.gradle.module.PlatformModule import com.google.common.truth.Truth.assertThat import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test @@ -27,10 +33,10 @@ class TestProjectGeneratorTest { fun `settings include generated for inner module`() { TestProjectGenerator( modules = listOf( - EmptyModule( + FolderModule( "one", modules = listOf( - EmptyModule( + FolderModule( "two", modules = emptyList() ) @@ -50,13 +56,13 @@ class TestProjectGeneratorTest { fun `settings include generated for inner inner module`() { TestProjectGenerator( modules = listOf( - EmptyModule( + FolderModule( "one", modules = listOf( - EmptyModule( + FolderModule( "two", modules = listOf( - EmptyModule( + FolderModule( "three", modules = emptyList() ) @@ -74,4 +80,64 @@ class TestProjectGeneratorTest { "include(':one:two:three')" ) } + + @Test + fun `generating default test project is successful`() { + TestProjectGenerator().generateIn(projectDir) + gradlew( + projectDir, + "help", + useModuleClasspath = false + ).assertThat() + .buildSuccessful() + } + + @Test + fun `generating empty test project is successful`() { + TestProjectGenerator( + modules = emptyList() + ).generateIn(projectDir) + gradlew( + projectDir, + "help", + useModuleClasspath = false + ).assertThat() + .buildSuccessful() + } + + @Test + fun `generating test project with all module types is successful`() { + val androidApp = AndroidAppModule("app", dependencies = """ + implementation project(':parent:empty:library') + implementation project(':parent:empty:kotlin') + implementation project(':parent:empty:platform') + """.trimIndent()) + val androidLibrary = AndroidLibModule("library") + val platform = PlatformModule("platform") + val kotlin = KotlinModule("kotlin") + val empty = FolderModule( + name = "empty", + modules = listOf( + androidApp, + androidLibrary, + kotlin, + platform + ) + ) + val parent = ParentGradleModule( + name = "parent", + modules = listOf(empty) + ) + TestProjectGenerator( + modules = listOf( + parent + ) + ).generateIn(projectDir) + gradlew( + projectDir, + "assembleDebug", + useModuleClasspath = false + ).assertThat() + .buildSuccessful() + } }