<commit_before>/*
 * Copyright 2012 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.gradle.launcher.daemon.client;

import org.gradle.api.GradleException;
import org.gradle.api.specs.Spec;
import org.gradle.initialization.BuildClientMetaData;
import org.gradle.initialization.GradleLauncherAction;
import org.gradle.internal.UncheckedException;
import org.gradle.launcher.daemon.context.DaemonContext;
import org.gradle.launcher.daemon.protocol.Build;
import org.gradle.launcher.daemon.protocol.BuildAndStop;
import org.gradle.launcher.daemon.protocol.BuildStarted;
import org.gradle.launcher.daemon.protocol.DaemonBusy;
import org.gradle.launcher.daemon.protocol.Failure;
import org.gradle.launcher.exec.BuildActionParameters;
import org.gradle.logging.internal.OutputEventListener;
import org.gradle.messaging.remote.internal.Connection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.InputStream;

public class SingleUseDaemonClient extends DaemonClient {
    private static final Logger LOGGER = LoggerFactory.getLogger(SingleUseDaemonClient.class);

    public SingleUseDaemonClient(DaemonConnector connector, BuildClientMetaData clientMetaData, OutputEventListener outputEventListener, Spec<DaemonContext> compatibilitySpec, InputStream buildStandardInput) {
        super(connector, clientMetaData, outputEventListener, compatibilitySpec, buildStandardInput);
    }

    @Override
    public <T> T execute(GradleLauncherAction<T> action, BuildActionParameters parameters) {
        LOGGER.warn("Note: in order to honour the org.gradle.jvmargs and/or org.gradle.java.home values specified for this build, it is necessary to fork a new JVM.");
        LOGGER.warn("In order to avoid the slowdown associated with this extra process, you might want to consider running Gradle with --daemon.");
        Build build = new BuildAndStop(action, parameters);

        DaemonConnection daemonConnection = connector.createConnection();
        Connection<Object> connection = daemonConnection.getConnection();

        Object firstResult;
        LOGGER.info("Connected to the remote build process. Dispatching {} request.", build);
        connection.dispatch(build);
        firstResult = connection.receive();

        if (firstResult instanceof BuildStarted) {
            return (T) monitorBuild(build, connection).getValue();
        } else if (firstResult instanceof Failure) {
            // Could potentially distinguish between CommandFailure and DaemonFailure here.
            throw UncheckedException.throwAsUncheckedException(((Failure) firstResult).getValue());
        } else if (firstResult instanceof DaemonBusy) {
            throw new GradleException("Single use daemon process responded as busy: this should never happen.");
        } else if (firstResult == null) {
            throw new GradleException("Could not connect to remote build process. The process probably died immediately after connection.");
        } else {
            throw new IllegalStateException(String.format(
                "The first result from the remote build process: %s is a Result of a type we don't have a strategy to handle."
                + "Earlier, %s request was sent to the process.", firstResult, build));
        }
    }
}<commit_msg>Minor patch after merging<commit_after>/*
 * Copyright 2012 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.gradle.launcher.daemon.client;

import org.gradle.api.GradleException;
import org.gradle.api.specs.Spec;
import org.gradle.initialization.BuildClientMetaData;
import org.gradle.initialization.GradleLauncherAction;
import org.gradle.internal.UncheckedException;
import org.gradle.launcher.daemon.context.DaemonContext;
import org.gradle.launcher.daemon.protocol.*;
import org.gradle.launcher.exec.BuildActionParameters;
import org.gradle.logging.internal.OutputEventListener;
import org.gradle.messaging.remote.internal.Connection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.InputStream;

public class SingleUseDaemonClient extends DaemonClient {
    private static final Logger LOGGER = LoggerFactory.getLogger(SingleUseDaemonClient.class);

    public SingleUseDaemonClient(DaemonConnector connector, BuildClientMetaData clientMetaData, OutputEventListener outputEventListener, Spec<DaemonContext> compatibilitySpec, InputStream buildStandardInput) {
        super(connector, clientMetaData, outputEventListener, compatibilitySpec, buildStandardInput);
    }

    @Override
    public <T> T execute(GradleLauncherAction<T> action, BuildActionParameters parameters) {
        LOGGER.warn("Note: in order to honour the org.gradle.jvmargs and/or org.gradle.java.home values specified for this build, it is necessary to fork a new JVM.");
        LOGGER.warn("In order to avoid the slowdown associated with this extra process, you might want to consider running Gradle with --daemon.");
        Build build = new BuildAndStop(action, parameters);

        DaemonConnection daemonConnection = connector.createConnection();
        Connection<Object> connection = daemonConnection.getConnection();

        Object firstResult;
        LOGGER.info("Connected to the remote build process. Dispatching {} request.", build);
        connection.dispatch(build);
        firstResult = connection.receive();

        if (firstResult instanceof BuildStarted) {
            return (T) monitorBuild(build, ((BuildStarted) firstResult).getDiagnostics(), connection).getValue();
        } else if (firstResult instanceof Failure) {
            // Could potentially distinguish between CommandFailure and DaemonFailure here.
            throw UncheckedException.throwAsUncheckedException(((Failure) firstResult).getValue());
        } else if (firstResult instanceof DaemonBusy) {
            throw new GradleException("Single use daemon process responded as busy: this should never happen.");
        } else if (firstResult == null) {
            throw new GradleException("Could not connect to remote build process. The process probably died immediately after connection.");
        } else {
            throw new IllegalStateException(String.format(
                "The first result from the remote build process: %s is a Result of a type we don't have a strategy to handle."
                + "Earlier, %s request was sent to the process.", firstResult, build));
        }
    }
}
{'fraction_non_alphanumeric': 0.07990928495197439, 'fraction_numerical': 0.0026680896478121665, 'mean_word_length': 3.994670219853431, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1121563', 'n_tokens_mistral': 1888, 'n_tokens_neox': 1824, 'n_words': 641}