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

com.deploygate.gradle.plugins.Processor.groovy Maven / Gradle / Ivy

package com.deploygate.gradle.plugins

import com.deploygate.gradle.plugins.internal.agp.AndroidGradlePlugin
import com.deploygate.gradle.plugins.internal.agp.IApplicationVariant
import com.deploygate.gradle.plugins.tasks.factory.*
import com.google.common.annotations.VisibleForTesting
import org.gradle.api.Project

import javax.annotation.Nonnull

/**
 * A processor class to generate tasks, etc.
 *
 * Do not touch the actual classes from Android DSL directly
 */
class Processor {

    @Nonnull
    private final Project project

    @Nonnull
    private final LoginTaskFactory loginTaskFactory

    @Nonnull
    private final LogoutTaskFactory logoutTaskFactory

    @Nonnull
    private final UploadArtifactTaskFactory applicationVariantBasedUploadApkTaskFactory

    @Nonnull
    private final UploadArtifactTaskFactory applicationVariantBasedUploadAabTaskFactory

    @Nonnull
    private final UploadArtifactTaskFactory stringBasedUploadApkTaskFactory

    @Nonnull
    private final UploadArtifactTaskFactory stringBasedUploadAabTaskFactory

    def declaredNames = new HashSet()

    Processor(@Nonnull Project project) {
        this(
                project,
                new LoginTaskFactoryImpl(project),
                new LogoutTaskFactoryImpl(project),
                new AGPBasedUploadApkTaskFactory(project),
                new AGPBasedUploadAabTaskFactory(project),
                new DSLBasedUploadApkTaskFactory(project),
                new DSLBasedUploadAabTaskFactory(project)
        )
    }

    @VisibleForTesting
    Processor(
            @Nonnull Project project,
            @Nonnull LoginTaskFactory loginTaskFactory,
            @Nonnull LogoutTaskFactory logoutTaskFactory,
            @Nonnull UploadArtifactTaskFactory applicationVariantBasedUploadApkTaskFactory,
            @Nonnull UploadArtifactTaskFactory applicationVariantBasedUploadAabTaskFactory,
            @Nonnull UploadArtifactTaskFactory stringBasedUploadApkTaskFactory,
            @Nonnull UploadArtifactTaskFactory stringBasedUploadAabTaskFactory
    ) {
        this.project = project
        this.loginTaskFactory = loginTaskFactory
        this.logoutTaskFactory = logoutTaskFactory
        this.applicationVariantBasedUploadApkTaskFactory = applicationVariantBasedUploadApkTaskFactory
        this.applicationVariantBasedUploadAabTaskFactory = applicationVariantBasedUploadAabTaskFactory
        this.stringBasedUploadApkTaskFactory = stringBasedUploadApkTaskFactory
        this.stringBasedUploadAabTaskFactory = stringBasedUploadAabTaskFactory
    }

    boolean canProcessVariantAware() {
        return AndroidGradlePlugin.isApplied(project)
    }

    def addVariantOrCustomName(@Nonnull String variantOrCustomName) {
        if (variantOrCustomName) {
            project.logger.debug("${variantOrCustomName} is declared")
            declaredNames.add(variantOrCustomName)
        } else {
            project.logger.warn("the given argument was empty")
        }
    }

    def registerLoginTask() {
        loginTaskFactory.registerLoginTask()
    }

    def registerLogoutTask() {
        logoutTaskFactory.registerLogoutTask()
    }

    def registerDeclarationAwareUploadApkTask(String variantOrCustomName) {
        stringBasedUploadApkTaskFactory.registerUploadArtifactTask(variantOrCustomName, *dependencyAncestorOfUploadTaskNames)
    }

    def registerDeclarationAwareUploadAabTask(String variantOrCustomName) {
        stringBasedUploadAabTaskFactory.registerUploadArtifactTask(variantOrCustomName, *dependencyAncestorOfUploadTaskNames)
    }

    def registerAggregatedDeclarationAwareUploadApkTask(Collection variantOrCustomNames) {
        stringBasedUploadApkTaskFactory.registerAggregatedUploadArtifactTask(variantOrCustomNames.collect {
            DeployGateTaskFactory.uploadApkTaskName(it)
        })
    }

    def registerAggregatedDeclarationAwareUploadAabTask(Collection variantOrCustomNames) {
        stringBasedUploadAabTaskFactory.registerAggregatedUploadArtifactTask(variantOrCustomNames.collect {
            DeployGateTaskFactory.uploadApkTaskName(it)
        })
    }

    def registerVariantAwareUploadApkTask(@Nonnull IApplicationVariant variant) {
        if (!canProcessVariantAware()) {
            project.logger.error("android gradle plugin not found but tried to create android-specific tasks. Ignored...")
            return
        }

        applicationVariantBasedUploadApkTaskFactory.registerUploadArtifactTask(variant, *dependencyAncestorOfUploadTaskNames)
    }

    def registerVariantAwareUploadAabTask(@Nonnull IApplicationVariant variant) {
        if (!canProcessVariantAware()) {
            project.logger.error("android gradle plugin not found but tried to create android-specific tasks. Ignored...")
            return
        }

        applicationVariantBasedUploadAabTaskFactory.registerUploadArtifactTask(variant, *dependencyAncestorOfUploadTaskNames)
    }

    @VisibleForTesting
    static String[] getDependencyAncestorOfUploadTaskNames() {
        return [LoginTaskFactory.TASK_NAME]
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy