package org.implab.gradle.common.sources;

import org.gradle.api.GradleException;
import org.gradle.api.Plugin;
import org.gradle.api.Project;

public abstract class VariantsPlugin implements Plugin<Project> {
    public static final String VARIANTS_EXTENSION_NAME = "variants";

    @Override
    public void apply(Project target) {
        var variants = target.getObjects().newInstance(BuildVariantsExtension.class);
        target.getExtensions().add(VARIANTS_EXTENSION_NAME, variants);
    }

    public static BuildVariantsExtension getVariantsExtension(Project target) {
        var extensions = target.getExtensions();

        var extension = extensions.getByType(BuildVariantsExtension.class);

        if (extension == null)
            throw new GradleException("Variants extension isn't found");
        return extension;
    }

}
