1
0
Fork 0

Reflow the VcsRepo and prevent exception leakage from breaking the parsing

pull/421/merge
Jordi Boggiano 2012-03-10 00:10:41 +01:00
parent a4f9e03d35
commit 950003bfc3
1 changed files with 85 additions and 65 deletions

View File

@ -83,9 +83,15 @@ class VcsRepository extends ArrayRepository
$this->versionParser = new VersionParser; $this->versionParser = new VersionParser;
$loader = new ArrayLoader(); $loader = new ArrayLoader();
if ($driver->hasComposerFile($driver->getRootIdentifier())) { try {
$data = $driver->getComposerInformation($driver->getRootIdentifier()); if ($driver->hasComposerFile($driver->getRootIdentifier())) {
$this->packageName = !empty($data['name']) ? $data['name'] : null; $data = $driver->getComposerInformation($driver->getRootIdentifier());
$this->packageName = !empty($data['name']) ? $data['name'] : null;
}
} catch (\Exception $e) {
if ($debug) {
$this->io->write('Skipped parsing '.$driver->getRootIdentifier().', '.$e->getMessage());
}
} }
foreach ($driver->getTags() as $tag => $identifier) { foreach ($driver->getTags() as $tag => $identifier) {
@ -96,49 +102,53 @@ class VcsRepository extends ArrayRepository
$this->io->overwrite($msg, false); $this->io->overwrite($msg, false);
} }
$parsedTag = $this->validateTag($tag); if (!$parsedTag = $this->validateTag($tag)) {
if ($parsedTag && $driver->hasComposerFile($identifier)) {
try {
$data = $driver->getComposerInformation($identifier);
} catch (TransportException $e) {
if ($debug) {
$this->io->write('Skipped tag '.$tag.', '.$e->getMessage());
}
continue;
} catch (\Exception $e) {
$this->io->write('Skipped tag '.$tag.', '.$e->getMessage());
continue;
}
// manually versioned package
if (isset($data['version'])) {
$data['version_normalized'] = $this->versionParser->normalize($data['version']);
} else {
// auto-versionned package, read value from tag
$data['version'] = $tag;
$data['version_normalized'] = $parsedTag;
}
// make sure tag packages have no -dev flag
$data['version'] = preg_replace('{[.-]?dev$}i', '', $data['version']);
$data['version_normalized'] = preg_replace('{(^dev-|[.-]?dev$)}i', '', $data['version_normalized']);
// broken package, version doesn't match tag
if ($data['version_normalized'] !== $parsedTag) {
if ($debug) {
$this->io->write('Skipped tag '.$tag.', tag ('.$parsedTag.') does not match version ('.$data['version_normalized'].') in composer.json');
}
continue;
}
if ($debug) { if ($debug) {
$this->io->write('Importing tag '.$tag.' ('.$data['version_normalized'].')'); $this->io->write('Skipped tag '.$tag.', invalid tag name');
} }
continue;
$this->addPackage($loader->load($this->preProcess($driver, $data, $identifier)));
} elseif ($debug) {
$this->io->write('Skipped tag '.$tag.', '.($parsedTag ? 'no composer file was found' : 'invalid name'));
} }
try {
if (!$data = $driver->getComposerInformation($identifier)) {
if ($debug) {
$this->io->write('Skipped tag '.$tag.', no composer file');
}
continue;
}
} catch (\Exception $e) {
if ($debug) {
$this->io->write('Skipped tag '.$tag.', '.$e->getMessage());
}
continue;
}
// manually versioned package
if (isset($data['version'])) {
$data['version_normalized'] = $this->versionParser->normalize($data['version']);
} else {
// auto-versionned package, read value from tag
$data['version'] = $tag;
$data['version_normalized'] = $parsedTag;
}
// make sure tag packages have no -dev flag
$data['version'] = preg_replace('{[.-]?dev$}i', '', $data['version']);
$data['version_normalized'] = preg_replace('{(^dev-|[.-]?dev$)}i', '', $data['version_normalized']);
// broken package, version doesn't match tag
if ($data['version_normalized'] !== $parsedTag) {
if ($debug) {
$this->io->write('Skipped tag '.$tag.', tag ('.$parsedTag.') does not match version ('.$data['version_normalized'].') in composer.json');
}
continue;
}
if ($debug) {
$this->io->write('Importing tag '.$tag.' ('.$data['version_normalized'].')');
}
$this->addPackage($loader->load($this->preProcess($driver, $data, $identifier)));
} }
$this->io->overwrite('', false); $this->io->overwrite('', false);
@ -151,36 +161,46 @@ class VcsRepository extends ArrayRepository
$this->io->overwrite($msg, false); $this->io->overwrite($msg, false);
} }
$parsedBranch = $this->validateBranch($branch); if (!$parsedBranch = $this->validateBranch($branch)) {
if ($driver->hasComposerFile($identifier)) { if ($debug) {
$data = $driver->getComposerInformation($identifier); $this->io->write('Skipped branch '.$branch.', invalid name');
}
continue;
}
if (!$parsedBranch) { try {
if (!$data = $driver->getComposerInformation($identifier)) {
if ($debug) { if ($debug) {
$this->io->write('Skipped branch '.$branch.', invalid name and no composer file was found'); $this->io->write('Skipped branch '.$branch.', no composer file');
} }
continue; continue;
} }
} catch (TransportException $e) {
// branches are always auto-versionned, read value from branch name
$data['version'] = $branch;
$data['version_normalized'] = $parsedBranch;
// make sure branch packages have a dev flag
if ('dev-' === substr($parsedBranch, 0, 4) || '9999999-dev' === $parsedBranch) {
$data['version'] = 'dev-' . $data['version'];
} else {
$data['version'] = $data['version'] . '-dev';
}
if ($debug) { if ($debug) {
$this->io->write('Importing branch '.$branch.' ('.$data['version_normalized'].')'); $this->io->write('Skipped branch '.$branch.', no composer file was found');
} }
continue;
$this->addPackage($loader->load($this->preProcess($driver, $data, $identifier))); } catch (\Exception $e) {
} elseif ($debug) { $this->io->write('Skipped branch '.$branch.', '.$e->getMessage());
$this->io->write('Skipped branch '.$branch.', no composer file was found'); continue;
} }
// branches are always auto-versionned, read value from branch name
$data['version'] = $branch;
$data['version_normalized'] = $parsedBranch;
// make sure branch packages have a dev flag
if ('dev-' === substr($parsedBranch, 0, 4) || '9999999-dev' === $parsedBranch) {
$data['version'] = 'dev-' . $data['version'];
} else {
$data['version'] = $data['version'] . '-dev';
}
if ($debug) {
$this->io->write('Importing branch '.$branch.' ('.$data['version_normalized'].')');
}
$this->addPackage($loader->load($this->preProcess($driver, $data, $identifier)));
} }
$this->io->overwrite('', false); $this->io->overwrite('', false);