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

com.mobgen.halo.android.plugin.sdk.HaloExtension.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.modules.CoreModule
import com.mobgen.halo.android.plugin.sdk.modules.ModuleContainer
import com.mobgen.halo.android.plugin.sdk.modules.network.NetworkCache
import com.mobgen.halo.android.plugin.sdk.modules.network.Timeout
import com.mobgen.halo.android.plugin.sdk.modules.user.PushModule
import org.gradle.api.Project

/**
 * The halo extension to configure the plugin.
 */
public class HaloExtension extends ProjectExtension {
    /**
     * The list of modules.
     */
    private List modules

    /**
     * The module closure that contains all the modules and its versions.
     */
    private ModuleContainer moduleContainer

    /**
     * Contains the debug variants that will be applied as debug builds
     */
    public boolean development

    /**
     * The client id
     */
    public String clientId

    /**
     * The client secret
     */
    public String clientSecret

    /**
     * The client id used for debug builds.
     */
    public String clientIdDebug

    /**
     * The client secret used for debug builds.
     */
    public String clientSecretDebug

    public Timeout timeoutConfig;

    public NetworkCache cacheConfig

    /**
     * Halo extension constructor.
     */
    public HaloExtension(Project project){
        super(project)
        moduleContainer = new ModuleContainer(project)
    }

    /**
     * Closure API for the convention object.
     * @param modulesClosure module closure.
     */
    def modules(Closure modulesClosure) {
        project.configure(moduleContainer, modulesClosure)
    }

    /**
     * Sets the debug variant names so they can be used to determine if the build is a development build or it is not.
     * @param variants The variants.
     */
    def debugVariants(String... debugVariants){
        development = false
        for(String name : project.gradle.startParameter.taskNames){
            for(String variantName : debugVariants) {
                development = development || name.toLowerCase().contains(variantName.toLowerCase())
            }
        }
    }

    /**
     * Stores the api key for halo.
     * @param clientId The api key
     */
    def clientId(String clientId){
        this.clientId = clientId
    }

    /**
     * The client id that will be used for debug builds.
     * @param clientId The client id that will be used for debug builds.
     */
    def clientIdDebug(String clientId){
        this.clientIdDebug = clientId
    }

    /**
     * The client secret.
     * @param clientSecret The client secret.
     */
    def clientSecret(String clientSecret){
        this.clientSecret = clientSecret
    }

    /**
     * The client secret used for debug builds.
     * @param clientSecretDebug The client secret.
     */
    def clientSecretDebug(String clientSecredDebug){
        this.clientSecretDebug = clientSecredDebug;
    }

    /**
     * The development variable.
     * @return True if the development is active.
     */
    boolean development(){
        return development
    }

    def timeout(Closure closure){
        timeoutConfig = new Timeout()
        project.configure(timeoutConfig, closure)
    }

    def cache(Closure closure){
        cacheConfig = new NetworkCache()
        project.configure(cacheConfig, closure)
    }

    /**
     * Builds all the modules configuring them based on the properties.
     */
    public void buildHalo(){
        modules = CoreModule.CoreBuilder.create()
                .project(project)
                .extension(this)
                .build(moduleContainer.pushModule)
    }

    /**
     * Provides the modules.
     * @return The modules.
     */
    public List getModules(){
        return modules
    }

    /**
     * Provides the push module.
     * @return The push module.
     */
    public PushModule pushModule(){
        return moduleContainer.pushModule
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy