1
0
Fork 0

added verbose logging for artifact directory scan

pull/1728/head
Serge Smertin 2013-03-25 00:41:10 +01:00
parent 0aad11801e
commit 586911f7a1
2 changed files with 41 additions and 28 deletions

View File

@ -12,42 +12,36 @@
namespace Composer\Repository;
use Composer\IO\IOInterface;
use Composer\Json\JsonFile;
use Composer\Package\Loader\ArrayLoader;
/**
* @author Serge Smertin <serg.smertin@gmail.com>
*/
use Composer\IO\IOInterface;
use Composer\Config;
use Composer\Json\JsonFile;
use Composer\Package\Loader\LoaderInterface;
use Composer\Package\Version\VersionParser;
use Composer\Package\Loader\ArrayLoader;
class ArtifactRepository extends ArrayRepository
{
protected $path;
/** @var LoaderInterface */
protected $loader;
public function __construct(array $repoConfig, IOInterface $io, Config $config, array $drivers = null)
protected $lookup;
public function __construct(array $repoConfig, IOInterface $io)
{
$this->path = $repoConfig['url'];
$this->loader = new ArrayLoader();
$this->lookup = $repoConfig['url'];
$this->io = $io;
}
protected function initialize()
{
parent::initialize();
$this->versionParser = new VersionParser;
if (!$this->loader) {
$this->loader = new ArrayLoader($this->versionParser);
$this->scanDirectory($this->lookup);
}
$this->getDirectoryPackages($this->path);
}
private function getDirectoryPackages($path)
private function scanDirectory($path)
{
$io = $this->io;
foreach (new \RecursiveDirectoryIterator($path) as $file) {
/* @var $file \SplFileInfo */
if (!$file->isFile()) {
@ -56,11 +50,18 @@ class ArtifactRepository extends ArrayRepository
$package = $this->getComposerInformation($file);
if (!$package) {
$this->io->write("File <comment>{$file->getBasename()}</comment> doesn't seem to hold a package");
if ($io->isVerbose()) {
$msg = "File <comment>{$file->getBasename()}</comment> doesn't seem to hold a package";
$io->write($msg);
}
continue;
}
$package = $this->loader->load($package);
if ($io->isVerbose()) {
$template = 'Found package <info>%s</info> (<comment>%s</comment>) in file <info>%s</info>';
$msg = sprintf($template, $package->getName(), $package->getPrettyVersion(), $file->getBasename());
$io->write($msg);
}
$this->addPackage($package);
}
@ -68,12 +69,22 @@ class ArtifactRepository extends ArrayRepository
private function getComposerInformation(\SplFileInfo $file)
{
$config = "zip://{$file->getPathname()}#composer.json";
$json = @file_get_contents($config);
$composerFile = "zip://{$file->getPathname()}#composer.json";
$json = @file_get_contents($composerFile);
if (!$json) {
return false;
}
return JsonFile::parseJson($json, $config);
$package = JsonFile::parseJson($json, $composerFile);
$package['dist'] = array(
'type' => 'zip',
'url' => $file->getRealPath(),
'reference' => $file->getBasename(),
'shasum' => sha1_file($file->getRealPath())
);
$package = $this->loader->load($package);
return $package;
}
}

View File

@ -1,4 +1,5 @@
<?php
/*
* This file is part of Composer.
*
@ -18,7 +19,8 @@ use Composer\Package\Package;
class ArtifactRepositoryTest extends TestCase
{
public function testExtractsConfigsFromZipArchives() {
public function testExtractsConfigsFromZipArchives()
{
$expectedPackages = array(
'vendor0/package0-0.0.1',
'vendor1/package2-4.3.2',