All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.autonomousapps.tasks.DetectRedundantJvmPluginTask.kt Maven / Gradle / Ivy

There is a newer version: 2.0.2
Show newest version
package com.autonomousapps.tasks

import com.autonomousapps.TASK_GROUP_DEP_INTERNAL
import com.autonomousapps.advice.PluginAdvice
import com.autonomousapps.extension.Behavior
import com.autonomousapps.extension.Ignore
import com.autonomousapps.internal.utils.bufferWriteJsonSet
import com.autonomousapps.internal.utils.getAndDelete
import org.gradle.api.DefaultTask
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction

/**
 * Runs if both java-library and kotlin-jvm plugins have been applied. Checks for presence of java
 * and kotlin source. Suggests removing kotlin-jvm if there is no Kotlin source.
 */
@CacheableTask
abstract class DetectRedundantJvmPluginTask : DefaultTask() {

  init {
    group = TASK_GROUP_DEP_INTERNAL
    description = "Produces a report about redundant jvm plugins that have been applied"
  }

  @get:Input
  abstract val hasJava: Property

  @get:Input
  abstract val hasKotlin: Property

  @get:Input
  abstract val redundantPluginsBehavior: Property

  @get:OutputFile
  abstract val output: RegularFileProperty

  @TaskAction fun action() {
    // Outputs
    val outputFile = output.getAndDelete()

    val behavior = redundantPluginsBehavior.get()
    val shouldIgnore = behavior is Ignore

    val pluginAdvices =
      if (!hasKotlin.get() && !shouldIgnore) mutableSetOf(PluginAdvice.redundantKotlinJvm())
      else mutableSetOf()

    pluginAdvices.removeIf {
      behavior.filter.contains(it.redundantPlugin)
    }

    outputFile.bufferWriteJsonSet(pluginAdvices)
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy