<commit_before>package build.pluto.builder;

import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import build.pluto.BuildUnit;
import build.pluto.BuildUnit.State;
import build.pluto.dependency.IllegalDependencyException;
import build.pluto.output.Output;
import build.pluto.stamp.Stamp;

public abstract class BuildCycleAtOnceBuilder<In extends Serializable, Out extends Output> extends Builder<ArrayList<In>, Out> {

  public static <X> ArrayList<X> singletonArrayList(X elem) {
    return new ArrayList<X>(Collections.<X> singletonList(elem));
  }

  private final BuilderFactory<ArrayList<In>, Out, ? extends BuildCycleAtOnceBuilder<In, Out>> factory;

  public BuildCycleAtOnceBuilder(In input, BuilderFactory<ArrayList<In>, Out, ? extends BuildCycleAtOnceBuilder<In, Out>> factory) {
    this(singletonArrayList(input), factory);
  }

  public BuildCycleAtOnceBuilder(ArrayList<In> input, BuilderFactory<ArrayList<In>, Out, ? extends BuildCycleAtOnceBuilder<In, Out>> factory) {
    super(input);
    this.factory = factory;
  }

  @Override
  protected CycleSupportFactory getCycleSupport() {
    return (BuildCycle cycle) -> new BuildAtOnceCycleSupport<>(cycle, this.factory);
  }

  protected abstract File singletonPersistencePath(In input);

  protected List<BuildUnit<Out>> cyclicResults;

  @Override
  public void require(File p, Stamp stamp) {
    for (BuildUnit<Out> result : cyclicResults) {
      try {
        result.requires(p, stamp);
      } catch (IllegalDependencyException e) {
        if (e.dep.equals(result.getPersistentPath()))
          try {
            requireBuild(result.getGeneratedBy());
          } catch (IOException e1) {
            throw new RuntimeException(e1);
          }
      }
    }
  }

  @Override
  public void provide(File p) {
    throw new AssertionError("Cannot provide a file. Use provide(In, File) to make clear which input provides which file.");
  }

  public void provide(In input, File p) {
    for (int i = 0; i < this.getInput().size(); i++) {
      if (this.getInput().get(i) == input) {
        this.cyclicResults.get(i).generates(p, defaultStamper().stampOf(p));
        break;
      }
    }
  }

  @Override
  public void setState(State state) {
    for (BuildUnit<Out> result : cyclicResults) {
      result.setState(state);
    }
  }

  @Override
  protected File persistentPath(ArrayList<In> input) {
    if (input.size() == 1) {
      return this.singletonPersistencePath(input.get(0));
    } else {
      throw new AssertionError("Should not occur");
    }
  }

  @Override
  protected Out build(ArrayList<In> input) throws Throwable {
    this.cyclicResults = Collections.singletonList(super.result);
    List<Out> result = this.buildAll(input);
    if (result.size() != 1) {
      throw new AssertionError("buildAll needs to return one output for one input");
    }
    return result.get(0);
  }

  protected abstract List<Out> buildAll(ArrayList<In> input) throws Throwable;

}
<commit_msg>Strange things happen on travis<commit_after>package build.pluto.builder;

import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import build.pluto.BuildUnit;
import build.pluto.BuildUnit.State;
import build.pluto.dependency.IllegalDependencyException;
import build.pluto.output.Output;
import build.pluto.stamp.Stamp;

public abstract class BuildCycleAtOnceBuilder<In extends Serializable, Out extends Output> extends Builder<ArrayList<In>, Out> {

  public static <X> ArrayList<X> singletonArrayList(X elem) {
    return new ArrayList<X>(Collections.<X> singletonList(elem));
  }

  private final BuilderFactory<ArrayList<In>, Out, ? extends BuildCycleAtOnceBuilder<In, Out>> factory;

  public BuildCycleAtOnceBuilder(In input, BuilderFactory<ArrayList<In>, Out, ? extends BuildCycleAtOnceBuilder<In, Out>> factory) {
    this(singletonArrayList(input), factory);
  }

  public BuildCycleAtOnceBuilder(ArrayList<In> input, BuilderFactory<ArrayList<In>, Out, ? extends BuildCycleAtOnceBuilder<In, Out>> factory) {
    super(input);
    this.factory = factory;
  }

  @Override
  protected CycleSupportFactory getCycleSupport() {
    return (BuildCycle cycle) -> new BuildAtOnceCycleSupport<>(cycle, this.factory);
  }

  protected abstract File singletonPersistencePath(In input);

  protected List<BuildUnit<Out>> cyclicResults;

  @Override
  public void require(File p) {
    for (BuildUnit<Out> result : cyclicResults) {
      result.requires(p, defaultStamper().stampOf(p));
    }
  }

  @Override
  public void require(File p, Stamp stamp) {
    for (BuildUnit<Out> result : cyclicResults) {
      try {
        result.requires(p, stamp);
      } catch (IllegalDependencyException e) {
        if (e.dep.equals(result.getPersistentPath()))
          try {
            requireBuild(result.getGeneratedBy());
          } catch (IOException e1) {
            throw new RuntimeException(e1);
          }
      }
    }
  }

  @Override
  public void provide(File p) {
    throw new AssertionError("Cannot provide a file. Use provide(In, File) to make clear which input provides which file.");
  }

  public void provide(In input, File p) {
    for (int i = 0; i < this.getInput().size(); i++) {
      if (this.getInput().get(i) == input) {
        this.cyclicResults.get(i).generates(p, defaultStamper().stampOf(p));
        break;
      }
    }
  }

  @Override
  public void setState(State state) {
    for (BuildUnit<Out> result : cyclicResults) {
      result.setState(state);
    }
  }

  @Override
  protected File persistentPath(ArrayList<In> input) {
    if (input.size() == 1) {
      return this.singletonPersistencePath(input.get(0));
    } else {
      throw new AssertionError("Should not occur");
    }
  }

  @Override
  protected Out build(ArrayList<In> input) throws Throwable {
    this.cyclicResults = Collections.singletonList(super.result);
    List<Out> result = this.buildAll(input);
    if (result.size() != 1) {
      throw new AssertionError("buildAll needs to return one output for one input");
    }
    return result.get(0);
  }

  protected abstract List<Out> buildAll(ArrayList<In> input) throws Throwable;

}

{'fraction_non_alphanumeric': 0.11515343245808289, 'fraction_numerical': 0.002214489085732363, 'mean_word_length': 3.7974203338391503, 'pattern_counts': {'":': 0, '<': 60, '<?xml version=': 0, '>': 60, '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': '5933809', 'n_tokens_mistral': 1922, 'n_tokens_neox': 1866, 'n_words': 463}