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

nebula.plugin.responsible.FixJavaPlugin.groovy Maven / Gradle / Ivy

There is a newer version: 11.0.0
Show newest version
package nebula.plugin.responsible

import org.apache.commons.lang3.reflect.FieldUtils
import org.gradle.api.GradleException
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.BasePlugin

/**
 * Restores status of project after Java plugin runs. The one caveat is that this plugin has to be run before the
 * BasePlugin is applied, else we can't restore the status.
 */
class FixJavaPlugin implements Plugin {

    def savedStatus
    void apply(Project project) {

        if (project.plugins.hasPlugin(BasePlugin)) {
            throw new GradleException("Unable to intercept BasePlugin before it explicitly set the status to release")
        }

        // Save status in case BasePlugin comes in and destroys it
        savedStatus = FieldUtils.readField(project, 'status', true)

        // Force it's hand by running right away
        project.plugins.apply(BasePlugin)

        project.plugins.withType(BasePlugin) {
            // can be null
            project.status = savedStatus
        }

    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy