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

dev.gradleplugins.runnerkit.providers.BuildScriptProvider Maven / Gradle / Ivy

There is a newer version: 0.0.148
Show newest version
package dev.gradleplugins.runnerkit.providers;

import dev.gradleplugins.runnerkit.GradleExecutionContext;
import dev.gradleplugins.runnerkit.InvalidRunnerConfigurationException;

import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public final class BuildScriptProvider extends AbstractGradleExecutionProvider implements GradleExecutionCommandLineProvider {
    public static BuildScriptProvider unset() {
        return noValue(BuildScriptProvider.class);
    }

    public static BuildScriptProvider of(File buildScript) {
        return fixed(BuildScriptProvider.class, buildScript);
    }

    @Override
    public List getAsArguments() {
        return map(BuildScriptProvider::asArguments).orElseGet(Collections::emptyList);
    }

    private static List asArguments(File buildScript) {
        return Arrays.asList("--build-file", buildScript.getAbsolutePath());
    }

    @Override
    public void validate(GradleExecutionContext context) {
        if (context.getArguments().get().stream().anyMatch(it -> it.equals("-b") || it.startsWith("--build-file"))) {
            throw new InvalidRunnerConfigurationException("Please use GradleRunner#usingBuildScript(File) instead of using the command line flags.");
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy