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

net.twisterrob.gradle.common.BaseQualityExtension.kt Maven / Gradle / Ivy

There is a newer version: 0.17
Show newest version
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