<commit_before>package jetbrains.buildServer.autotools.agent;

import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.VisibleForTesting;
import com.intellij.execution.configurations.GeneralCommandLine;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import jetbrains.buildServer.ExecResult;
import jetbrains.buildServer.SimpleCommandLineProcessRunner;
import jetbrains.buildServer.agent.*;
import jetbrains.buildServer.util.EventDispatcher;
import org.jetbrains.annotations.NotNull;
import static jetbrains.buildServer.autotools.common.AutotoolsBuildConstants.*;

/**
 * Created on 26.07.2017.
 * Author     : <NAME>
 */
public class AutotoolsLifeCycleListener extends AgentLifeCycleAdapter {

  /**
   * Does autotools test report
   */
  private AutotoolsTestsReporter testReporter;
  AutotoolsLifeCycleListener(EventDispatcher<AgentLifeCycleListener> dispatcher) {
    dispatcher.addListener(this);
  }


  /**
   * Returns true if version v1 < version v2.
   * @param v1 first version
   * @param v2 second version
   * @return true if version v1 < version, v2 else false
   */
  @NotNull
  @VisibleForTesting
  static boolean compareVersions(@NotNull final String v1,@NotNull final String v2){
    final String[] v1mas = v1.split(".");
    final String[] v2mas = v2.split(".");
    for (int i = 0; i < Math.min(v1mas.length, v2mas.length); i++){
      if (Integer.parseInt(v1mas[i]) != Integer.parseInt(v2mas[i])){
        return Integer.parseInt(v1mas[i]) < Integer.parseInt(v2mas[i]);
      }
    }
    return v1mas.length < v2mas.length;
  }

  /**
   * Find runtest tool
   * @param runner BuildRunnerContext
   */
  private static void findToolRuntest(@NotNull final BuildRunnerContext runner){
    final GeneralCommandLine commandLine = new GeneralCommandLine();
    commandLine.setExePath("runtest");
    commandLine.addParameter("--version");
    final ExecResult execResult = SimpleCommandLineProcessRunner.runCommand(commandLine, (byte[])null);
    if (execResult.getExitCode() != 0) {
      return;
    }
    String version = "";
    for (final String line : execResult.getOutLines()) {
      if (!line.startsWith("DejaGnu version")) continue;
      Matcher matcher = Pattern.compile("\\d+(\\.\\d+)+").matcher(line);
      if (matcher.find()) {
        version = matcher.group();
      }
    }
    runner.addRunnerParameter(HAS_RUNTEST_VAR, "1");
    runner.addRunnerParameter(RUNTEST_XML_FILE_VAR, Boolean.toString(compareVersions(version, "1.6")));
  }

  @Override
  public void beforeRunnerStart(@NotNull final BuildRunnerContext runner) {
    findToolRuntest(runner);
    testReporter = new AutotoolsTestsReporter(System.currentTimeMillis(), runner.getBuild().getBuildLogger(),
                                              runner.getBuild().getCheckoutDirectory().getAbsolutePath() + "/",<commit_msg>remove findToolRuntest and  compareVersions from AutotoolsLifeCycleListener<commit_after>package jetbrains.buildServer.autotools.agent;

import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.VisibleForTesting;
import com.intellij.execution.configurations.GeneralCommandLine;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import jetbrains.buildServer.ExecResult;
import jetbrains.buildServer.SimpleCommandLineProcessRunner;
import jetbrains.buildServer.agent.*;
import jetbrains.buildServer.util.EventDispatcher;
import org.jetbrains.annotations.NotNull;
import static jetbrains.buildServer.autotools.common.AutotoolsBuildConstants.*;

/**
 * Created on 26.07.2017.
 * Author     : <NAME>
 */
public class AutotoolsLifeCycleListener extends AgentLifeCycleAdapter {

  /**
   * Does autotools test report
   */
  private AutotoolsTestsReporter testReporter;
  AutotoolsLifeCycleListener(EventDispatcher<AgentLifeCycleListener> dispatcher) {
    dispatcher.addListener(this);
  }


  }

  @Override
  public void beforeRunnerStart(@NotNull final BuildRunnerContext runner) {
    myRuntestToolProvider = (RuntestToolProvider) myProvidersRegistry.findToolProvider(TOOL_RUNTEST);
                                              runner.getBuild().getCheckoutDirectory().getAbsolutePath() + "/",
{'fraction_non_alphanumeric': 0.10855263157894737, 'fraction_numerical': 0.00963345864661654, 'mean_word_length': 4.3682219419924335, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3442080', 'n_tokens_mistral': 1255, 'n_tokens_neox': 1222, 'n_words': 235}