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

nebula.test.functional.internal.classpath.ClasspathInjectingGradleHandleFactory.groovy Maven / Gradle / Ivy

package nebula.test.functional.internal.classpath

import groovy.transform.CompileStatic
import nebula.test.functional.internal.GradleHandle
import nebula.test.functional.internal.GradleHandleFactory
import org.gradle.util.GFileUtils

import java.util.function.Predicate

@CompileStatic
class ClasspathInjectingGradleHandleFactory implements GradleHandleFactory {
    private final ClassLoader classLoader;
    private final GradleHandleFactory delegateFactory;
    private Predicate classpathFilter

    public ClasspathInjectingGradleHandleFactory(ClassLoader classLoader, GradleHandleFactory delegateFactory, Predicate classpathFilter) {
        this.classpathFilter = classpathFilter;
        this.classLoader = classLoader;
        this.delegateFactory = delegateFactory;
    }

    @Override
    public GradleHandle start(File projectDir, List arguments, List jvmArguments = []) {
        File testKitDir = new File(projectDir, ".gradle-test-kit");
        if (!testKitDir.exists()) {
            GFileUtils.mkdirs(testKitDir);
        }

        File initScript = new File(testKitDir, "init.gradle");
        ClasspathAddingInitScriptBuilder.build(initScript, classLoader, classpathFilter);

        List ammendedArguments = new ArrayList(arguments.size() + 2);
        ammendedArguments.add("--init-script");
        ammendedArguments.add(initScript.getAbsolutePath());
        ammendedArguments.addAll(arguments);
        return delegateFactory.start(projectDir, ammendedArguments, jvmArguments);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy