net.twisterrob.gradle.common.BaseQualityExtension.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of twister-quality-common Show documentation
Show all versions of twister-quality-common Show documentation
Shared classes between checkers. (Not to be consumed directly.)
package net.twisterrob.gradle.common
import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.internal.file.pattern.PatternMatcherFactory
import org.gradle.api.tasks.SourceTask
import org.gradle.api.tasks.util.PatternSet
open class BaseQualityExtension(
private val project: Project,
internal var taskConfigurator: Action> = Action {}
) where T : SourceTask {
fun taskConfigurator(closure: Action>) {
taskConfigurator = closure
}
}
class TaskConfigurator(val task: T) where T : SourceTask {
/**
* @param basePrefix Directory pattern to exclude, no trailing slash
* @param relativeExceptions relative to `basePrefix`, no trailing slash
*/
fun excludeExcept(basePrefix: String, vararg relativeExceptions: String) {
val exactException = PatternMatcherFactory.compile(true, "${basePrefix}/*")
val exceptions = PatternSet()
.include("${basePrefix}/*")
.exclude(relativeExceptions.map { "${basePrefix}/${it}" })
task.source.matching(exceptions).visit {
if (it.isDirectory && exactException.matches(it.relativePath.segments, 0)) {
task.exclude(it.relativePath.pathString + "/**")
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy