All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.squareup.spoon.SpoonCoverageMerger Maven / Gradle / Ivy

The newest version!
package com.squareup.spoon;

import com.google.common.base.Function;
import org.jacoco.core.tools.ExecFileLoader;

import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Set;

import static com.google.common.collect.Collections2.transform;
import static com.squareup.spoon.SpoonDeviceRunner.COVERAGE_DIR;
import static com.squareup.spoon.SpoonDeviceRunner.COVERAGE_FILE;
import static com.squareup.spoon.SpoonUtils.sanitizeSerial;

final class SpoonCoverageMerger {
  private static final String MERGED_COVERAGE_FILE = "merged-coverage.ec";
  private ExecFileLoader execFileLoader;

  public SpoonCoverageMerger() {
    this.execFileLoader = new ExecFileLoader();
  }

  public void mergeCoverageFiles(Set serials, File outputDirectory) throws IOException {
    Collection sanitizeSerials = transform(serials, toSanitizeSerials());
    for (String serial : sanitizeSerials) {
      String coverageFilePath = COVERAGE_DIR + "/" + serial + "/" + COVERAGE_FILE;
      execFileLoader.load(new File(outputDirectory, coverageFilePath));
    }
    String mergedCoverageFile = COVERAGE_DIR + "/" + MERGED_COVERAGE_FILE;
    execFileLoader.save(new File(outputDirectory, mergedCoverageFile), false);
  }

  private Function toSanitizeSerials() {
    return new Function() {
      @Override
      public String apply(String serials) {
        return sanitizeSerial(serials);
      }
    };
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy