<commit_before>package com.coreos.appc;

import static com.google.common.base.CharMatcher.WHITESPACE;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;

import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Ordering;

public class AppcContainerBuilder extends ContainerBuilder {

  final List<ContainerFile> addFiles = Lists.newArrayList();

  final File aciFile;

  public boolean compress = true;

  public AppcContainerBuilder(File aciFile) {
    this.aciFile = aciFile;
  }

  @Override
  public void addFiles(List<ContainerFile> containerFiles) throws IOException {
    addFiles.addAll(containerFiles);
  }

  @Override
  public void buildImage(String imageName, String imageVersion) throws Exception {
    log.info("Building image " + imageName);

    try (AciFileWriter aciFileWriter = new AciFileWriter(aciFile, compress)) {
      AciManifest manifest = createAciManifest(imageName, imageVersion);

      aciFileWriter.addManifest(manifest);

      for (ContainerFile containerFile : addFiles) {
        final Path sourcePath = containerFile.sourcePath;

        String imagePath = containerFile.imagePath;
        log.info(String.format("Writing %s -> %s", sourcePath, imagePath));

        if (imagePath.contains("/")) {
          String dir = imagePath.substring(0, imagePath.lastIndexOf('/'));
          aciFileWriter.mkdirs(dir);
        }

        aciFileWriter.addFile(sourcePath.toFile(), imagePath);

        // // ensure all directories exist because copy operation will fail if they don't
        // Files.createDirectories(destPath.getParent());
        // Files.copy(sourcePath, destPath, StandardCopyOption.REPLACE_EXISTING);
        // Files.setLastModifiedTime(destPath, FileTime.fromMillis(0));
        // // file location relative to docker directory, used later to generate Dockerfile
        // final Path relativePath = Paths.get(containerFile.imagePath);
        // copiedPaths.add(relativePath.toString());
      }
      log.info("Built " + imageName);
    }
  }

  private AciManifest createAciManifest(String imageName, String version) throws IOException {
    AciManifest manifest = new AciManifest();<commit_msg>Better log messages<commit_after>package com.coreos.appc;

import static com.google.common.base.CharMatcher.WHITESPACE;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;

import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Ordering;

public class AppcContainerBuilder extends ContainerBuilder {

  final List<ContainerFile> addFiles = Lists.newArrayList();

  final File aciFile;

  public boolean compress = true;

  public AppcContainerBuilder(File aciFile) {
    this.aciFile = aciFile;
  }

  @Override
  public void addFiles(List<ContainerFile> containerFiles) throws IOException {
    addFiles.addAll(containerFiles);
  }

  @Override
  public void buildImage(String imageName, String imageVersion) throws Exception {
    log.debug("Building image " + imageName);

    try (AciFileWriter aciFileWriter = new AciFileWriter(aciFile, compress)) {
      AciManifest manifest = createAciManifest(imageName, imageVersion);

      aciFileWriter.addManifest(manifest);

      for (ContainerFile containerFile : addFiles) {
        final Path sourcePath = containerFile.sourcePath;

        String imagePath = containerFile.imagePath;
        log.info(String.format("Writing %s -> %s", sourcePath, imagePath));

        if (imagePath.contains("/")) {
          String dir = imagePath.substring(0, imagePath.lastIndexOf('/'));
          aciFileWriter.mkdirs(dir);
        }

        aciFileWriter.addFile(sourcePath.toFile(), imagePath);

        // // ensure all directories exist because copy operation will fail if they don't
        // Files.createDirectories(destPath.getParent());
        // Files.copy(sourcePath, destPath, StandardCopyOption.REPLACE_EXISTING);
        // Files.setLastModifiedTime(destPath, FileTime.fromMillis(0));
        // // file location relative to docker directory, used later to generate Dockerfile
        // final Path relativePath = Paths.get(containerFile.imagePath);
        // copiedPaths.add(relativePath.toString());
      }
      log.info("Built ACI " + imageName + ":" + imageVersion);
    }
  }

  private AciManifest createAciManifest(String imageName, String version) throws IOException {
    AciManifest manifest = new AciManifest();
{'fraction_non_alphanumeric': 0.1019396551724138, 'fraction_numerical': 0.0008620689655172414, 'mean_word_length': 3.764887063655031, 'pattern_counts': {'":': 1, '<': 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': '3223539', 'n_tokens_mistral': 1322, 'n_tokens_neox': 1282, 'n_words': 295}