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

com.github.psxpaul.ExecForkPlugin.kt Maven / Gradle / Ivy

There is a newer version: 0.1.4
Show newest version
package com.github.psxpaul

import com.github.psxpaul.task.AbstractExecFork
import com.github.psxpaul.task.ExecJoin
import com.github.psxpaul.task.createNameFor
import org.gradle.BuildAdapter
import org.gradle.BuildResult
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.util.*

class ExecForkPlugin : Plugin {
    val log: Logger = LoggerFactory.getLogger(ExecForkPlugin::class.java)

    override fun apply(project: Project?) {
        val forkTasks: ArrayList = ArrayList()

        project?.tasks?.whenTaskAdded({ task: Task ->
            if (task is AbstractExecFork) {
                val forkTask: AbstractExecFork = task
                val joinTask: ExecJoin = project.tasks.create(createNameFor(forkTask), ExecJoin::class.java)
                joinTask.forkTask = forkTask
                forkTask.joinTask = joinTask

                forkTasks.add(task)
            }
        });

        project?.gradle?.addBuildListener(object: BuildAdapter() {
            override fun buildFinished(result: BuildResult?) {
                for (forkTask: AbstractExecFork in forkTasks) {
                    try {
                        forkTask.stop();
                    } catch (e:InterruptedException) {
                        log.error("Error stopping daemon for {} task '{}'", forkTask.javaClass.simpleName, forkTask.name, e);
                    }
                }
            }
        });
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy