You are here

public static function Composer::vendorTestCodeCleanup in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Composer/Composer.php \Drupal\Core\Composer\Composer::vendorTestCodeCleanup()

Remove possibly problematic test files from vendored projects.

Parameters

\Composer\Script\Event $event:

File

core/lib/Drupal/Core/Composer/Composer.php, line 147
Contains \Drupal\Core\Composer\Composer.

Class

Composer
Provides static functions for composer script events.

Namespace

Drupal\Core\Composer

Code

public static function vendorTestCodeCleanup(PackageEvent $event) {
  $vendor_dir = $event
    ->getComposer()
    ->getConfig()
    ->get('vendor-dir');
  $op = $event
    ->getOperation();
  if ($op
    ->getJobType() == 'update') {
    $package = $op
      ->getTargetPackage();
  }
  else {
    $package = $op
      ->getPackage();
  }
  $package_key = static::findPackageKey($package
    ->getName());
  if ($package_key) {
    foreach (static::$packageToCleanup[$package_key] as $path) {
      $dir_to_remove = $vendor_dir . '/' . $package_key . '/' . $path;
      if (is_dir($dir_to_remove)) {
        if (!static::deleteRecursive($dir_to_remove)) {
          throw new \RuntimeException(sprintf("Failure removing directory '%s' in package '%s'.", $path, $package
            ->getPrettyName()));
        }
      }
      else {
        throw new \RuntimeException(sprintf("The directory '%s' in package '%s' does not exist.", $path, $package
          ->getPrettyName()));
      }
    }
  }
}