package org.implab.gradle.common.tasks;

import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.logging.Logger;
import org.gradle.api.specs.Spec;
import org.gradle.api.tasks.Internal;

/** Task methods available by default, this interface is used by mixins to
 * interact with their task.
 */
public interface TaskExtra {
    @Internal
    Project getProject();

    void onlyIf(Spec<? super Task> spec);

    @Internal
    Logger getLogger();

    default void onlyIfReason(String skipReason, Spec<? super Task> spec) {
        onlyIf(self -> {
            var satisfied = spec.isSatisfiedBy(self);
            if (!satisfied)
                getLogger().info("SKIP: {}", skipReason);
            return satisfied;
        });
    }
}
