Skip to content

Commit

Permalink
Merge pull request #103 from h4cc/master
Browse files Browse the repository at this point in the history
Added a flag to "skip-errors" while dumping.
  • Loading branch information
Seldaek committed Dec 6, 2013
2 parents ba0c2d6 + c990e67 commit eddb78d
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/Composer/Satis/Command/BuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ protected function configure()
new InputArgument('file', InputArgument::OPTIONAL, 'Json file to use', './satis.json'),
new InputArgument('output-dir', InputArgument::OPTIONAL, 'Location where to output built files', null),
new InputOption('no-html-output', null, InputOption::VALUE_NONE, 'Turn off HTML view'),
new InputOption('skip-errors', null, InputOption::VALUE_NONE, 'Skip Download or Archive errors'),
))
->setHelp(<<<EOT
The <info>build</info> command reads the given json file
Expand Down Expand Up @@ -135,7 +136,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

if (isset($config['archive']['directory'])) {
$this->dumpDownloads($config, $packages, $output, $outputDir);
$skipErrors = (bool)$input->getOption('skip-errors');
$this->dumpDownloads($config, $packages, $output, $outputDir, $skipErrors);
}

$filename = $outputDir.'/packages.json';
Expand Down Expand Up @@ -255,10 +257,11 @@ private function selectPackages(Composer $composer, OutputInterface $output, $ve
* @param array $packages Reference to packages so we can rewrite the JSON.
* @param OutputInterface $output
* @param string $outputDir
* @param bool $skipErrors If true, any exception while dumping a package will be ignored.
*
* @return void
*/
private function dumpDownloads(array $config, array &$packages, OutputInterface $output, $outputDir)
private function dumpDownloads(array $config, array &$packages, OutputInterface $output, $outputDir, $skipErrors)
{
if (isset($config['archive']['absolute-directory'])) {
$directory = $config['archive']['absolute-directory'];
Expand Down Expand Up @@ -303,13 +306,20 @@ private function dumpDownloads(array $config, array &$packages, OutputInterface

$output->writeln(sprintf("<info>Dumping '%s'.</info>", $name));

$path = $archiveManager->archive($package, $format, $directory);
$archive = basename($path);
$distUrl = sprintf('%s/%s/%s', $endpoint, $config['archive']['directory'], $archive);
$package->setDistType($format);
$package->setDistUrl($distUrl);
$package->setDistSha1Checksum(hash_file('sha1', $path));
$package->setDistReference($package->getSourceReference());
try {
$path = $archiveManager->archive($package, $format, $directory);
$archive = basename($path);
$distUrl = sprintf('%s/%s/%s', $endpoint, $config['archive']['directory'], $archive);
$package->setDistType($format);
$package->setDistUrl($distUrl);
$package->setDistSha1Checksum(hash_file('sha1', $path));
$package->setDistReference($package->getSourceReference());
} catch(\Exception $exception) {
if(!$skipErrors) {
throw $exception;
}
$output->writeln(sprintf("<error>Skipping Exception '%s'.</error>", $exception->getMessage()));
}
}
}

Expand Down

0 comments on commit eddb78d

Please sign in to comment.