Search in sources :

Example 1 with InvalidRunnerConfigurationException

use of org.gradle.testkit.runner.InvalidRunnerConfigurationException in project gradle by gradle.

the class DefaultGradleRunner method run.

private BuildResult run(Action<GradleExecutionResult> resultVerification) {
    if (projectDirectory == null) {
        throw new InvalidRunnerConfigurationException("Please specify a project directory before executing the build");
    }
    if (environment != null && debug) {
        throw new InvalidRunnerConfigurationException("Debug mode is not allowed when environment variables are specified. " + "Debug mode runs 'in process' but we need to fork a separate process to pass environment variables. " + "To run with debug mode, please remove environment variables.");
    }
    File testKitDir = createTestKitDir(testKitDirProvider);
    GradleProvider effectiveDistribution = gradleProvider == null ? findGradleInstallFromGradleRunner() : gradleProvider;
    List<String> effectiveArguments = new ArrayList<>();
    if (OperatingSystem.current().isWindows()) {
        // When using file system watching in Windows tests it becomes harder to delete the project directory,
        // since file system watching on Windows adds a lock on the watched directory, which is currently the project directory.
        // After deleting the contents of the watched directory, Gradle will stop watching the directory and release the file lock.
        // That may require a retry to delete the watched directory.
        // To avoid those problems for TestKit tests on Windows, we disable file system watching there.
        effectiveArguments.add("-D" + StartParameterBuildOptions.WatchFileSystemOption.GRADLE_PROPERTY + "=false");
    }
    effectiveArguments.addAll(arguments);
    GradleExecutionResult execResult = gradleExecutor.run(new GradleExecutionParameters(effectiveDistribution, testKitDir, projectDirectory, effectiveArguments, jvmArguments, classpath, debug, standardOutput, standardError, standardInput, environment));
    resultVerification.execute(execResult);
    return createBuildResult(execResult);
}
Also used : ArrayList(java.util.ArrayList) InvalidRunnerConfigurationException(org.gradle.testkit.runner.InvalidRunnerConfigurationException) File(java.io.File)

Example 2 with InvalidRunnerConfigurationException

use of org.gradle.testkit.runner.InvalidRunnerConfigurationException in project gradle by gradle.

the class DefaultGradleRunner method findGradleInstallFromGradleRunner.

private static GradleProvider findGradleInstallFromGradleRunner() {
    GradleInstallation gradleInstallation = CurrentGradleInstallation.get();
    if (gradleInstallation == null) {
        if ("embedded".equals(System.getProperty("org.gradle.integtest.executer"))) {
            return GradleProvider.embedded();
        }
        String messagePrefix = "Could not find a Gradle installation to use based on the location of the GradleRunner class";
        try {
            File classpathForClass = ClasspathUtil.getClasspathForClass(GradleRunner.class);
            messagePrefix += ": " + classpathForClass.getAbsolutePath();
        } catch (Exception ignore) {
        // ignore
        }
        throw new InvalidRunnerConfigurationException(messagePrefix + ". Please specify a Gradle runtime to use via GradleRunner.withGradleVersion() or similar.");
    }
    return GradleProvider.installation(gradleInstallation.getGradleHome());
}
Also used : CurrentGradleInstallation(org.gradle.internal.installation.CurrentGradleInstallation) GradleInstallation(org.gradle.internal.installation.GradleInstallation) File(java.io.File) InvalidRunnerConfigurationException(org.gradle.testkit.runner.InvalidRunnerConfigurationException) InvalidRunnerConfigurationException(org.gradle.testkit.runner.InvalidRunnerConfigurationException)

Example 3 with InvalidRunnerConfigurationException

use of org.gradle.testkit.runner.InvalidRunnerConfigurationException in project gradle by gradle.

the class ToolingApiGradleExecutor method run.

@Override
public GradleExecutionResult run(GradleExecutionParameters parameters) {
    final StreamByteBuffer outputBuffer = new StreamByteBuffer();
    final OutputStream syncOutput = new SynchronizedOutputStream(outputBuffer.getOutputStream());
    final List<BuildTask> tasks = new ArrayList<BuildTask>();
    maybeRegisterCleanup();
    GradleConnector gradleConnector = buildConnector(parameters.getGradleUserHome(), parameters.getProjectDir(), parameters.isEmbedded(), parameters.getGradleProvider());
    ProjectConnection connection = null;
    GradleVersion targetGradleVersion = null;
    try {
        connection = gradleConnector.connect();
        targetGradleVersion = determineTargetGradleVersion(connection);
        if (targetGradleVersion.compareTo(TestKitFeature.RUN_BUILDS.getSince()) < 0) {
            throw new UnsupportedFeatureException(String.format("The version of Gradle you are using (%s) is not supported by TestKit. TestKit supports all Gradle versions 2.6 and later.", targetGradleVersion.getVersion()));
        }
        DefaultBuildLauncher launcher = (DefaultBuildLauncher) connection.newBuild();
        launcher.setStandardOutput(new NoCloseOutputStream(teeOutput(syncOutput, parameters.getStandardOutput())));
        launcher.setStandardError(new NoCloseOutputStream(teeOutput(syncOutput, parameters.getStandardError())));
        if (parameters.getStandardInput() != null) {
            launcher.setStandardInput(parameters.getStandardInput());
        }
        launcher.addProgressListener(new TaskExecutionProgressListener(tasks), OperationType.TASK);
        launcher.withArguments(parameters.getBuildArgs().toArray(new String[0]));
        launcher.setJvmArguments(parameters.getJvmArgs().toArray(new String[0]));
        launcher.setEnvironmentVariables(parameters.getEnvironment());
        if (!parameters.getInjectedClassPath().isEmpty()) {
            if (targetGradleVersion.compareTo(TestKitFeature.PLUGIN_CLASSPATH_INJECTION.getSince()) < 0) {
                throw new UnsupportedFeatureException("support plugin classpath injection", targetGradleVersion, TestKitFeature.PLUGIN_CLASSPATH_INJECTION.getSince());
            }
            launcher.withInjectedClassPath(parameters.getInjectedClassPath());
        }
        launcher.run();
    } catch (UnsupportedVersionException e) {
        throw new InvalidRunnerConfigurationException("The build could not be executed due to a feature not being supported by the target Gradle version", e);
    } catch (BuildException t) {
        return new GradleExecutionResult(new BuildOperationParameters(targetGradleVersion, parameters.isEmbedded()), outputBuffer.readAsString(), tasks, t);
    } catch (GradleConnectionException t) {
        StringBuilder message = new StringBuilder("An error occurred executing build with ");
        if (parameters.getBuildArgs().isEmpty()) {
            message.append("no args");
        } else {
            message.append("args '");
            message.append(CollectionUtils.join(" ", parameters.getBuildArgs()));
            message.append("'");
        }
        message.append(" in directory '").append(parameters.getProjectDir().getAbsolutePath()).append("'");
        String capturedOutput = outputBuffer.readAsString();
        if (!capturedOutput.isEmpty()) {
            message.append(". Output before error:").append(SystemProperties.getInstance().getLineSeparator()).append(capturedOutput);
        }
        throw new IllegalStateException(message.toString(), t);
    } finally {
        if (connection != null) {
            connection.close();
        }
    }
    return new GradleExecutionResult(new BuildOperationParameters(targetGradleVersion, parameters.isEmbedded()), outputBuffer.readAsString(), tasks);
}
Also used : BuildTask(org.gradle.testkit.runner.BuildTask) UnsupportedFeatureException(org.gradle.testkit.runner.UnsupportedFeatureException) GradleConnectionException(org.gradle.tooling.GradleConnectionException) SynchronizedOutputStream(org.gradle.testkit.runner.internal.io.SynchronizedOutputStream) TeeOutputStream(org.apache.commons.io.output.TeeOutputStream) NoCloseOutputStream(org.gradle.testkit.runner.internal.io.NoCloseOutputStream) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) ProjectConnection(org.gradle.tooling.ProjectConnection) StreamByteBuffer(org.gradle.internal.io.StreamByteBuffer) InvalidRunnerConfigurationException(org.gradle.testkit.runner.InvalidRunnerConfigurationException) DefaultBuildLauncher(org.gradle.tooling.internal.consumer.DefaultBuildLauncher) GradleConnector(org.gradle.tooling.GradleConnector) DefaultGradleConnector(org.gradle.tooling.internal.consumer.DefaultGradleConnector) SynchronizedOutputStream(org.gradle.testkit.runner.internal.io.SynchronizedOutputStream) BuildException(org.gradle.tooling.BuildException) GradleVersion(org.gradle.util.GradleVersion) NoCloseOutputStream(org.gradle.testkit.runner.internal.io.NoCloseOutputStream) UnsupportedVersionException(org.gradle.tooling.UnsupportedVersionException)

Aggregations

InvalidRunnerConfigurationException (org.gradle.testkit.runner.InvalidRunnerConfigurationException)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 OutputStream (java.io.OutputStream)1 TeeOutputStream (org.apache.commons.io.output.TeeOutputStream)1 CurrentGradleInstallation (org.gradle.internal.installation.CurrentGradleInstallation)1 GradleInstallation (org.gradle.internal.installation.GradleInstallation)1 StreamByteBuffer (org.gradle.internal.io.StreamByteBuffer)1 BuildTask (org.gradle.testkit.runner.BuildTask)1 UnsupportedFeatureException (org.gradle.testkit.runner.UnsupportedFeatureException)1 NoCloseOutputStream (org.gradle.testkit.runner.internal.io.NoCloseOutputStream)1 SynchronizedOutputStream (org.gradle.testkit.runner.internal.io.SynchronizedOutputStream)1 BuildException (org.gradle.tooling.BuildException)1 GradleConnectionException (org.gradle.tooling.GradleConnectionException)1 GradleConnector (org.gradle.tooling.GradleConnector)1 ProjectConnection (org.gradle.tooling.ProjectConnection)1 UnsupportedVersionException (org.gradle.tooling.UnsupportedVersionException)1 DefaultBuildLauncher (org.gradle.tooling.internal.consumer.DefaultBuildLauncher)1 DefaultGradleConnector (org.gradle.tooling.internal.consumer.DefaultGradleConnector)1 GradleVersion (org.gradle.util.GradleVersion)1