Skip to content

Commit

Permalink
Revert 'com.android.library' support (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
qwwdfsad committed Oct 26, 2022
1 parent 3f37b63 commit 3a9d921
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 64 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ dependencies {
implementation("org.ow2.asm:asm-tree:9.2")
implementation("com.googlecode.java-diff-utils:diffutils:1.3.0")
compileOnly("org.jetbrains.kotlin.multiplatform:org.jetbrains.kotlin.multiplatform.gradle.plugin:1.6.0")
compileOnly("com.android.tools.build:gradle:${androidGradlePluginVersion}")
// compileOnly("com.android.tools.build:gradle:${androidGradlePluginVersion}")

// The test needs the full kotlin multiplatform plugin loaded as it has no visibility of previously loaded plugins,
// unlike the regular way gradle loads plugins.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ package kotlinx.validation.test

import kotlinx.validation.api.*
import org.junit.Assume
import org.junit.Ignore
import org.junit.Test
import java.io.File

@Ignore // Leftovers after revert of #94
internal class AndroidLibraryTest : BaseKotlinGradleTest() {

// region Kotlin Android Library
Expand Down
64 changes: 1 addition & 63 deletions src/main/kotlin/BinaryCompatibilityValidatorPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@

package kotlinx.validation

import com.android.build.gradle.LibraryExtension
import org.gradle.api.*
import org.gradle.api.plugins.*
import org.gradle.api.provider.*
import org.gradle.api.tasks.*
import org.gradle.api.tasks.compile.JavaCompile
import org.jetbrains.kotlin.gradle.dsl.*
import org.jetbrains.kotlin.gradle.plugin.*
import java.io.*
Expand Down Expand Up @@ -111,15 +109,8 @@ class BinaryCompatibilityValidatorPlugin : Plugin<Project> {
project: Project,
extension: ApiValidationExtension
) {
val kotlinPluginPresent = project.plugins
.withType(KotlinAndroidPluginWrapper::class.java)
.isEmpty().not()
configureAndroidPluginForKotlinLibrary(project, extension)

if (kotlinPluginPresent) {
configureAndroidPluginForKotlinLibrary(project, extension)
} else {
configureAndroidPluginForJavaLibrary(project, extension)
}
}

private fun configureAndroidPluginForKotlinLibrary(
Expand All @@ -135,18 +126,6 @@ class BinaryCompatibilityValidatorPlugin : Plugin<Project> {
}
}

private fun configureAndroidPluginForJavaLibrary(
project: Project,
extension: ApiValidationExtension
) = configurePlugin("com.android.library", project, extension) {
val androidExtension = project.extensions.getByType(LibraryExtension::class.java)
androidExtension.libraryVariants.matching {
it.name == "release"
}.all {
project.configureJavaCompilation(it.javaCompileProvider, extension)
}
}

private fun configureKotlinPlugin(
project: Project,
extension: ApiValidationExtension
Expand Down Expand Up @@ -242,39 +221,6 @@ internal val Project.apiValidationExtensionOrNull: ApiValidationExtension?
.map { it.extensions.findByType(ApiValidationExtension::class.java) }
.firstOrNull { it != null }

private fun Project.configureJavaCompilation(
configurableFileCollection: TaskProvider<JavaCompile>,
extension: ApiValidationExtension,
targetConfig: TargetConfig = TargetConfig(this),
) {
val projectName = project.name
val apiDirProvider = targetConfig.apiDir
val apiBuildDir = apiDirProvider.map { buildDir.resolve(it) }

val apiBuild = task<KotlinApiBuildTask>(targetConfig.apiTaskName("Build")) {
isEnabled = apiCheckEnabled(projectName, extension)
// 'group' is not specified deliberately, so it will be hidden from ./gradlew tasks
description = "Builds Java API for 'main' compilations of $projectName. " +
"Complementary task and shouldn't be called manually"
inputClassesDirs = files(provider<Any> {
if (isEnabled) configurableFileCollection.get().outputs.files
else emptyList<Any>()
})
inputDependencies = files(provider<Any> {
if (isEnabled) configurableFileCollection.get().outputs.files
else emptyList<Any>()
})
outputApiDir = apiBuildDir.get()
}

configureCheckTasks(
apiBuildDir,
apiBuild,
extension,
targetConfig
)
}

fun apiCheckEnabled(projectName: String, extension: ApiValidationExtension): Boolean =
projectName !in extension.ignoredProjects && !extension.validationDisabled

Expand Down Expand Up @@ -341,11 +287,3 @@ inline fun <reified T : Task> Project.task(
name: String,
noinline configuration: T.() -> Unit,
): TaskProvider<T> = tasks.register(name, T::class.java, Action(configuration))

inline fun <reified T : Task> Project.task(
name: String,
extension: ApiValidationExtension,
noinline configuration: T.() -> Unit,
): TaskProvider<T> = tasks.register(name, T::class.java, extension).also {
it.configure(Action(configuration))
}

0 comments on commit 3a9d921

Please sign in to comment.