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

ru.astrainteractive.gradleplugin.processor.platform.VelocityResourceProcessor.kt Maven / Gradle / Ivy

The newest version!
package ru.astrainteractive.gradleplugin.processor.platform

import org.gradle.api.Project
import org.gradle.api.file.DuplicatesStrategy
import org.gradle.kotlin.dsl.named
import org.gradle.language.jvm.tasks.ProcessResources
import ru.astrainteractive.gradleplugin.model.Developer
import ru.astrainteractive.gradleplugin.processor.core.ResourceProcessor
import ru.astrainteractive.gradleplugin.property.extension.ModelPropertyValueExt.requireProjectInfo
import java.util.Locale

internal class VelocityResourceProcessor(
    private val project: Project
) : ResourceProcessor {

    data class Info(
        val main: String,
        val name: String,
        val version: String,
        val url: String,
        val authors: List,
        val id: String,
    ) : ResourceProcessor.ProcessorInfo

    override fun getProcessorInfo(): Info {
        val projectInfo = project.requireProjectInfo
        return Info(
            main = "${projectInfo.group}.${projectInfo.name}",
            name = projectInfo.name,
            version = projectInfo.versionString,
            url = projectInfo.url,
            authors = projectInfo.developersList,
            id = projectInfo.name.lowercase(Locale.getDefault())
        )
    }

    override fun getDefaultProperties(): Map {
        val processorInfo = getProcessorInfo()
        return mapOf(
            "id" to processorInfo.id,
            "name" to processorInfo.name,
            "version" to processorInfo.version,
            "url" to processorInfo.url,
            "authors" to processorInfo.authors.map(Developer::id).joinToString("\",\""),
            "main" to processorInfo.main
        )
    }

    override fun process(
        customProperties: Map,
        configuration: ProcessResources.() -> Unit
    ) {
        project.tasks.named("processResources") {
            filteringCharset = "UTF-8"
            duplicatesStrategy = DuplicatesStrategy.WARN
            filesMatching("velocity-plugin.json") {
                expand(getDefaultProperties().plus(customProperties))
            }
            configuration.invoke(this)
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy