protected function assembleFiles(ComponentCollection $component_collection, $files) {
    $return = array();

    foreach ($files as $file_id => $file_info) {
      if (!empty($file_info['path'])) {
        $filepath = $file_info['path'] . '/' . $file_info['filename'];
      }
      else {
        $filepath = $file_info['filename'];
      }

      $code = implode("\n", $file_info['body']);

      // Replace tokens in file contents and file path.
      // We get the tokens from the root component that was the nearest
      // requester.
      // TODO: consider changing this to be nearest root component; though
      // would require a change to File::containingComponent() among other
      // things.
      $file_component = $component_collection->getComponent($file_info['source_component_id']);
      $closest_requesting_root = $component_collection->getClosestRequestingRootComponent($file_component);
      $variables = $closest_requesting_root->getReplacements();
      $code = strtr($code, $variables);
      $filepath = strtr($filepath, $variables);

      $return[$filepath] = $code;
    }

    return $return;
  }