5
5
6
6
package kotlinx.validation
7
7
8
- import com.android.build.gradle.LibraryExtension
9
8
import org.gradle.api.*
10
9
import org.gradle.api.plugins.*
11
10
import org.gradle.api.provider.*
12
11
import org.gradle.api.tasks.*
13
- import org.gradle.api.tasks.compile.JavaCompile
14
12
import org.jetbrains.kotlin.gradle.dsl.*
15
13
import org.jetbrains.kotlin.gradle.plugin.*
16
14
import java.io.*
@@ -111,15 +109,8 @@ class BinaryCompatibilityValidatorPlugin : Plugin<Project> {
111
109
project : Project ,
112
110
extension : ApiValidationExtension
113
111
) {
114
- val kotlinPluginPresent = project.plugins
115
- .withType(KotlinAndroidPluginWrapper ::class .java)
116
- .isEmpty().not ()
112
+ configureAndroidPluginForKotlinLibrary(project, extension)
117
113
118
- if (kotlinPluginPresent) {
119
- configureAndroidPluginForKotlinLibrary(project, extension)
120
- } else {
121
- configureAndroidPluginForJavaLibrary(project, extension)
122
- }
123
114
}
124
115
125
116
private fun configureAndroidPluginForKotlinLibrary (
@@ -135,18 +126,6 @@ class BinaryCompatibilityValidatorPlugin : Plugin<Project> {
135
126
}
136
127
}
137
128
138
- private fun configureAndroidPluginForJavaLibrary (
139
- project : Project ,
140
- extension : ApiValidationExtension
141
- ) = configurePlugin(" com.android.library" , project, extension) {
142
- val androidExtension = project.extensions.getByType(LibraryExtension ::class .java)
143
- androidExtension.libraryVariants.matching {
144
- it.name == " release"
145
- }.all {
146
- project.configureJavaCompilation(it.javaCompileProvider, extension)
147
- }
148
- }
149
-
150
129
private fun configureKotlinPlugin (
151
130
project : Project ,
152
131
extension : ApiValidationExtension
@@ -242,39 +221,6 @@ internal val Project.apiValidationExtensionOrNull: ApiValidationExtension?
242
221
.map { it.extensions.findByType(ApiValidationExtension ::class .java) }
243
222
.firstOrNull { it != null }
244
223
245
- private fun Project.configureJavaCompilation (
246
- configurableFileCollection : TaskProvider <JavaCompile >,
247
- extension : ApiValidationExtension ,
248
- targetConfig : TargetConfig = TargetConfig (this),
249
- ) {
250
- val projectName = project.name
251
- val apiDirProvider = targetConfig.apiDir
252
- val apiBuildDir = apiDirProvider.map { buildDir.resolve(it) }
253
-
254
- val apiBuild = task<KotlinApiBuildTask >(targetConfig.apiTaskName(" Build" )) {
255
- isEnabled = apiCheckEnabled(projectName, extension)
256
- // 'group' is not specified deliberately, so it will be hidden from ./gradlew tasks
257
- description = " Builds Java API for 'main' compilations of $projectName . " +
258
- " Complementary task and shouldn't be called manually"
259
- inputClassesDirs = files(provider<Any > {
260
- if (isEnabled) configurableFileCollection.get().outputs.files
261
- else emptyList<Any >()
262
- })
263
- inputDependencies = files(provider<Any > {
264
- if (isEnabled) configurableFileCollection.get().outputs.files
265
- else emptyList<Any >()
266
- })
267
- outputApiDir = apiBuildDir.get()
268
- }
269
-
270
- configureCheckTasks(
271
- apiBuildDir,
272
- apiBuild,
273
- extension,
274
- targetConfig
275
- )
276
- }
277
-
278
224
fun apiCheckEnabled (projectName : String , extension : ApiValidationExtension ): Boolean =
279
225
projectName !in extension.ignoredProjects && ! extension.validationDisabled
280
226
@@ -341,11 +287,3 @@ inline fun <reified T : Task> Project.task(
341
287
name : String ,
342
288
noinline configuration : T .() -> Unit ,
343
289
): TaskProvider <T > = tasks.register(name, T ::class .java, Action (configuration))
344
-
345
- inline fun <reified T : Task > Project.task (
346
- name : String ,
347
- extension : ApiValidationExtension ,
348
- noinline configuration : T .() -> Unit ,
349
- ): TaskProvider <T > = tasks.register(name, T ::class .java, extension).also {
350
- it.configure(Action (configuration))
351
- }
0 commit comments