<commit_before>package urchin.cli;

import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import urchin.exception.CommandException;

import java.util.Optional;

import static java.nio.charset.Charset.defaultCharset;

public abstract class BasicCommand {

    protected final Logger log = LoggerFactory.getLogger(this.getClass().getName());

    private final Runtime runtime;

    protected BasicCommand(Runtime runtime) {
        this.runtime = runtime;
    }

    protected Optional<String> executeCommand(String command) {
        return executeCommand(command.split(" "));
    }

    protected Optional<String> executeCommand(String[] command) {
        try {
            Process process = runtime.exec(command);
            process.waitFor();

            if (process.exitValue() != 0) {
                String error = IOUtils.toString(process.getErrorStream(), defaultCharset());
                log.error("Process returned error: {}", error);
                throw new CommandException(this.getClass(), process.exitValue());
            }

            String response = IOUtils.toString(process.getInputStream(), defaultCharset());
            if (response.length() > 0) {
                log.debug("Response: {}", response);
                return Optional.of(response);<commit_msg>added timeout on execute cli commands<commit_after>package urchin.cli;

import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import urchin.exception.CommandException;

import java.util.Optional;
import java.util.concurrent.TimeUnit;

import static java.nio.charset.Charset.defaultCharset;

public abstract class BasicCommand {

    protected final Logger log = LoggerFactory.getLogger(this.getClass().getName());

    private final Runtime runtime;

    protected BasicCommand(Runtime runtime) {
        this.runtime = runtime;
    }

    protected Optional<String> executeCommand(String command) {
        return executeCommand(command.split(" "));
    }

    protected Optional<String> executeCommand(String[] command) {
        try {
            Process process = runtime.exec(command);
            process.waitFor(10, TimeUnit.SECONDS);

            if (process.exitValue() != 0) {
                String error = IOUtils.toString(process.getErrorStream(), defaultCharset());
                log.error("Process returned error: {}", error);
                throw new CommandException(this.getClass(), process.exitValue());
            }

            String response = IOUtils.toString(process.getInputStream(), defaultCharset());
            if (response.length() > 0) {
                log.debug("Response: {}", response);
                return Optional.of(response);
{'fraction_non_alphanumeric': 0.11151603498542274, 'fraction_numerical': 0.0036443148688046646, 'mean_word_length': 2.927038626609442, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4928141', 'n_tokens_mistral': 710, 'n_tokens_neox': 694, 'n_words': 155}