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

com.mobgen.halo.android.plugin.sdk.HaloPlugin.groovy Maven / Gradle / Ivy

There is a newer version: 2.9.3
Show newest version
package com.mobgen.halo.android.plugin.sdk
import com.mobgen.halo.android.plugin.sdk.tasks.HaloConfigurationTask
import com.mobgen.halo.android.plugin.sdk.tasks.ProcessPushManifestTask
import com.mobgen.halo.android.plugin.sdk.utils.Utils
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
/**
 * Halo plugin that is in charge to manage dependencies and all the configuration that must be
 * applied to a project using the M framework.
 */
public class HaloPlugin implements Plugin {

    /**
     * Halo convention object name.
     */
    private static final String EXTENSION_NAME = "halo"

    /**
     * The current project instance.
     */
    private Project project
    /**
     * The halo extension plugin.
     */
    private HaloExtension halo;

	@Override
	public void apply (Project project) {
        this.project = project
        if(Utils.isAndroidPlugin(project)){
            //Create the extension
            halo = project.extensions.create(EXTENSION_NAME, HaloExtension, project)
            project.afterEvaluate {
                halo.buildHalo()
                //Lets ensure that the given environment contains the Android plugin
                createConfigurationTask()
                createPushManifestTasks()
            }
        }
	}

    def createPushManifestTasks() {
       Utils.getVariants(project).all { variant ->
           //Create push notifications task to add to the manifest the permissions
           if(halo.pushModule() && halo.pushModule().isEnabled()){
               Task task = project.tasks.create("${variant.getName()}PushManifest", ProcessPushManifestTask, {
                   androidVariant = variant
                   pushModule = halo.pushModule()
                   group = "halo"
                   description = "Process the manifest to inject the push information for Halo"
               })
               project.tasks.getByName("process${variant.getName().capitalize()}Manifest") << {
                   task.execute()
               }
           }
       }
    }

    def createConfigurationTask(){
        String haloTaskName = "createHaloConfig"
        HaloConfigurationTask task = project.tasks.create(haloTaskName, HaloConfigurationTask)
        task.group = "halo"
        task.setExtension(halo)
        //Add after pre-build the moment to create the file
        project.tasks.findByName("preBuild").dependsOn task
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy