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

ck.wirespec.plugin.maven.wirespec-maven-plugin.0.10.5.source-code.CompileMojo.kt Maven / Gradle / Ivy

There is a newer version: 0.10.17
Show newest version
package community.flock.wirespec.plugin.maven

import community.flock.wirespec.plugin.Language
import community.flock.wirespec.plugin.PackageName
import community.flock.wirespec.plugin.mapEmitter
import community.flock.wirespec.plugin.parse
import community.flock.wirespec.plugin.writeToFiles
import java.io.File
import org.apache.maven.plugins.annotations.LifecyclePhase
import org.apache.maven.plugins.annotations.Mojo
import org.apache.maven.plugins.annotations.Parameter

@Mojo(name = "compile", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
open class CompileMojo : BaseMojo() {

    @Parameter
    protected var languages: List? = null

    @Parameter
    protected var shared: Boolean = true

    override fun execute() {
        project.addCompileSourceRoot(output)
        val outputFile = File(output)
        val packageNameValue = PackageName(packageName)
        val content = getFilesContent().parse(logger)
        languages
            ?.map { it.mapEmitter(packageNameValue, logger) }
            ?.forEach { (emitter, ext, sharedData) ->
                content.forEach { (fileName, ast) ->
                    emitter.emit(ast).forEach {
                        it.writeToFiles(
                            output = outputFile,
                            packageName = packageNameValue,
                            shared = if (shared) sharedData else null,
                            fileName = if (emitter.split) null else fileName,
                            ext = ext
                        )
                    }
                }
            }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy