Fixed several typos
- break at first archiver supports - use standard directory separator - change exception message - remove the BaseArchiver since tar & zip archivers have been merged - plus coding stylepull/1567/head
parent
a733d76b33
commit
d1d77dd13d
|
@ -69,11 +69,10 @@ class ArchiveManager
|
|||
}
|
||||
|
||||
$usableArchiver = null;
|
||||
$sourceType = $package->getSourceType();
|
||||
|
||||
foreach ($this->archivers as $archiver) {
|
||||
if ($archiver->supports($format, $package->getSourceType())) {
|
||||
$usableArchiver = $archiver;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,20 +81,20 @@ class ArchiveManager
|
|||
throw new \RuntimeException(sprintf('No archiver found to support %s format', $format));
|
||||
}
|
||||
|
||||
$filesystem = new Filesystem();
|
||||
$packageName = str_replace('/', DIRECTORY_SEPARATOR, $package->getUniqueName());
|
||||
|
||||
// Directory used to download the sources
|
||||
$sources = sys_get_temp_dir().DIRECTORY_SEPARATOR.$packageName;
|
||||
$filesystem = new Filesystem();
|
||||
$packageName = $package->getUniqueName();
|
||||
$sources = sys_get_temp_dir().'/'.$packageName;
|
||||
$filesystem->ensureDirectoryExists($sources);
|
||||
|
||||
// Archive filename
|
||||
$target = $this->buildDir.DIRECTORY_SEPARATOR.$packageName.'.'.$format;
|
||||
$target = $this->buildDir.'/'.$packageName.'.'.$format;
|
||||
$filesystem->ensureDirectoryExists(dirname($this->buildDir.$target));
|
||||
|
||||
// Download sources
|
||||
$this->downloadManager->download($package, $sources, true);
|
||||
|
||||
// Create the archive
|
||||
$sourceRef = $package->getSourceReference();
|
||||
$usableArchiver->archive($sources, $target, $format, $sourceRef);
|
||||
}
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
* Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Composer\Package\Archiver;
|
||||
|
||||
use Composer\Package\BasePackage;
|
||||
use Composer\Package\PackageInterface;
|
||||
|
||||
/**
|
||||
* @author Till Klampaeckel <till@php.net>
|
||||
* @author Matthieu Moquet <matthieu@moquet.net>
|
||||
*/
|
||||
abstract class BaseArchiver implements ArchiverInterface
|
||||
{
|
||||
/**
|
||||
* Create a PHAR archive.
|
||||
*
|
||||
* @param string $sources Path of the directory to archive
|
||||
* @param string $target Path of the file archive to create
|
||||
* @param int $format Format of the archive
|
||||
*/
|
||||
protected function createPharArchive($sources, $target, $format)
|
||||
{
|
||||
try {
|
||||
$phar = new \PharData($target, null, null, $format);
|
||||
$phar->buildFromDirectory($sources);
|
||||
} catch (\UnexpectedValueException $e) {
|
||||
$message = sprintf("Could not create archive '%s' from '%s': %s",
|
||||
$target,
|
||||
$sources,
|
||||
$e->getMessage()
|
||||
);
|
||||
|
||||
throw new \RuntimeException($message, $e->getCode(), $e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -49,7 +49,7 @@ class GitArchiver implements ArchiverInterface
|
|||
|
||||
if (0 !== $exitCode) {
|
||||
throw new \RuntimeException(
|
||||
sprintf('The command `%s` returned %s', $command, $exitCode)
|
||||
sprintf('Impossible to build the archive: `%s` returned %s', $command, $exitCode)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -59,10 +59,6 @@ class GitArchiver implements ArchiverInterface
|
|||
*/
|
||||
public function supports($format, $sourceType)
|
||||
{
|
||||
return 'git' === $sourceType && in_array($format, array(
|
||||
'zip',
|
||||
'tar',
|
||||
'tgz',
|
||||
));
|
||||
return 'git' === $sourceType && in_array($format, array('zip', 'tar', 'tgz'));
|
||||
}
|
||||
}
|
|
@ -47,7 +47,7 @@ class MercurialArchiver implements ArchiverInterface
|
|||
|
||||
if (0 !== $exitCode) {
|
||||
throw new \RuntimeException(
|
||||
sprintf('The command `%s` returned %s', $command, $exitCode)
|
||||
sprintf('Impossible to build the archive: `%s` returned %s', $command, $exitCode)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -57,12 +57,6 @@ class MercurialArchiver implements ArchiverInterface
|
|||
*/
|
||||
public function supports($format, $sourceType)
|
||||
{
|
||||
return 'hg' === $sourceType && in_array($format, array(
|
||||
'tar',
|
||||
'tbz2',
|
||||
'tgz',
|
||||
'uzip',
|
||||
'zip',
|
||||
));
|
||||
return 'hg' === $sourceType && in_array($format, array('tar', 'tbz2', 'tgz', 'uzip', 'zip'));
|
||||
}
|
||||
}
|
|
@ -19,9 +19,9 @@ use Composer\Package\PackageInterface;
|
|||
* @author Till Klampaeckel <till@php.net>
|
||||
* @author Matthieu Moquet <matthieu@moquet.net>
|
||||
*/
|
||||
class PharArchiver extends BaseArchiver
|
||||
class PharArchiver implements ArchiverInterface
|
||||
{
|
||||
static public $formats = array(
|
||||
static protected $formats = array(
|
||||
'zip' => \Phar::ZIP,
|
||||
'tar' => \Phar::TAR,
|
||||
);
|
||||
|
@ -31,7 +31,6 @@ class PharArchiver extends BaseArchiver
|
|||
*/
|
||||
public function archive($sources, $target, $format, $sourceRef = null)
|
||||
{
|
||||
// source reference is useless for this archiver
|
||||
$this->createPharArchive($sources, $target, static::$formats[$format]);
|
||||
}
|
||||
|
||||
|
@ -40,6 +39,29 @@ class PharArchiver extends BaseArchiver
|
|||
*/
|
||||
public function supports($format, $sourceType)
|
||||
{
|
||||
return in_array($format, array_keys(static::$formats));
|
||||
return isset(static::$formats[$format]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a PHAR archive.
|
||||
*
|
||||
* @param string $sources Path of the directory to archive
|
||||
* @param string $target Path of the file archive to create
|
||||
* @param int $format Format of the archive
|
||||
*/
|
||||
protected function createPharArchive($sources, $target, $format)
|
||||
{
|
||||
try {
|
||||
$phar = new \PharData($target, null, null, $format);
|
||||
$phar->buildFromDirectory($sources);
|
||||
} catch (\UnexpectedValueException $e) {
|
||||
$message = sprintf("Could not create archive '%s' from '%s': %s",
|
||||
$target,
|
||||
$sources,
|
||||
$e->getMessage()
|
||||
);
|
||||
|
||||
throw new \RuntimeException($message, $e->getCode(), $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue