package org.implab.gradle.common.files;

import org.gradle.api.Action;
import org.gradle.api.Named;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.FileCollection;
import org.gradle.api.model.ObjectFactory;
import org.gradle.util.Configurable;
import org.implab.gradle.common.utils.Closures;

import groovy.lang.Closure;

/** Simple wrapper to add {@link Named} to {@link FileCollection} */
public abstract class GenericSourceSetOutput
        implements Named, Configurable<GenericSourceSetOutput> {

    private final String name;

    private final ConfigurableFileCollection outputFileCollection;

    public GenericSourceSetOutput(String name, ObjectFactory objects) {
        this.name = name;
        outputFileCollection = objects.fileCollection();
    }

    public FileCollection getFileCollection() {
        return outputFileCollection;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public GenericSourceSetOutput configure(@SuppressWarnings("rawtypes") Closure cl) {
        Closures.apply(cl, outputFileCollection);
        return this;
    }

    public GenericSourceSetOutput configure(Action<ConfigurableFileCollection> cl) {
        cl.execute(outputFileCollection);
        return this;
    }

}
