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;
|
$usableArchiver = null;
|
||||||
$sourceType = $package->getSourceType();
|
|
||||||
|
|
||||||
foreach ($this->archivers as $archiver) {
|
foreach ($this->archivers as $archiver) {
|
||||||
if ($archiver->supports($format, $package->getSourceType())) {
|
if ($archiver->supports($format, $package->getSourceType())) {
|
||||||
$usableArchiver = $archiver;
|
$usableArchiver = $archiver;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,20 +81,20 @@ class ArchiveManager
|
||||||
throw new \RuntimeException(sprintf('No archiver found to support %s format', $format));
|
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
|
// 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);
|
$filesystem->ensureDirectoryExists($sources);
|
||||||
|
|
||||||
// Archive filename
|
// Archive filename
|
||||||
$target = $this->buildDir.DIRECTORY_SEPARATOR.$packageName.'.'.$format;
|
$target = $this->buildDir.'/'.$packageName.'.'.$format;
|
||||||
$filesystem->ensureDirectoryExists(dirname($this->buildDir.$target));
|
$filesystem->ensureDirectoryExists(dirname($this->buildDir.$target));
|
||||||
|
|
||||||
// Download sources
|
// Download sources
|
||||||
$this->downloadManager->download($package, $sources, true);
|
$this->downloadManager->download($package, $sources, true);
|
||||||
|
|
||||||
|
// Create the archive
|
||||||
$sourceRef = $package->getSourceReference();
|
$sourceRef = $package->getSourceReference();
|
||||||
$usableArchiver->archive($sources, $target, $format, $sourceRef);
|
$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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -34,7 +34,7 @@ class GitArchiver implements ArchiverInterface
|
||||||
{
|
{
|
||||||
// Since git-archive no longer works with a commit ID in git 1.7.10,
|
// Since git-archive no longer works with a commit ID in git 1.7.10,
|
||||||
// use by default the HEAD reference instead of the commit sha1
|
// use by default the HEAD reference instead of the commit sha1
|
||||||
if (null === $sourceRef || preg_match('/^[0-9a-f]{40}$/i',$sourceRef)) {
|
if (null === $sourceRef || preg_match('/^[0-9a-f]{40}$/i', $sourceRef)) {
|
||||||
$sourceRef = 'HEAD';
|
$sourceRef = 'HEAD';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ class GitArchiver implements ArchiverInterface
|
||||||
|
|
||||||
if (0 !== $exitCode) {
|
if (0 !== $exitCode) {
|
||||||
throw new \RuntimeException(
|
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)
|
public function supports($format, $sourceType)
|
||||||
{
|
{
|
||||||
return 'git' === $sourceType && in_array($format, array(
|
return 'git' === $sourceType && in_array($format, array('zip', 'tar', 'tgz'));
|
||||||
'zip',
|
|
||||||
'tar',
|
|
||||||
'tgz',
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -47,7 +47,7 @@ class MercurialArchiver implements ArchiverInterface
|
||||||
|
|
||||||
if (0 !== $exitCode) {
|
if (0 !== $exitCode) {
|
||||||
throw new \RuntimeException(
|
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)
|
public function supports($format, $sourceType)
|
||||||
{
|
{
|
||||||
return 'hg' === $sourceType && in_array($format, array(
|
return 'hg' === $sourceType && in_array($format, array('tar', 'tbz2', 'tgz', 'uzip', 'zip'));
|
||||||
'tar',
|
|
||||||
'tbz2',
|
|
||||||
'tgz',
|
|
||||||
'uzip',
|
|
||||||
'zip',
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -19,9 +19,9 @@ use Composer\Package\PackageInterface;
|
||||||
* @author Till Klampaeckel <till@php.net>
|
* @author Till Klampaeckel <till@php.net>
|
||||||
* @author Matthieu Moquet <matthieu@moquet.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,
|
'zip' => \Phar::ZIP,
|
||||||
'tar' => \Phar::TAR,
|
'tar' => \Phar::TAR,
|
||||||
);
|
);
|
||||||
|
@ -31,7 +31,6 @@ class PharArchiver extends BaseArchiver
|
||||||
*/
|
*/
|
||||||
public function archive($sources, $target, $format, $sourceRef = null)
|
public function archive($sources, $target, $format, $sourceRef = null)
|
||||||
{
|
{
|
||||||
// source reference is useless for this archiver
|
|
||||||
$this->createPharArchive($sources, $target, static::$formats[$format]);
|
$this->createPharArchive($sources, $target, static::$formats[$format]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +39,29 @@ class PharArchiver extends BaseArchiver
|
||||||
*/
|
*/
|
||||||
public function supports($format, $sourceType)
|
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