Reuse operation formatting logic in downloaders
parent
aaef3ff5ff
commit
83c64a9d19
|
@ -61,7 +61,12 @@ class InstallOperation extends SolverOperation
|
|||
*/
|
||||
public function show($lock)
|
||||
{
|
||||
return ($lock ? 'Locking ' : 'Installing ').'<info>'.$this->package->getPrettyName().'</info> (<comment>'.$this->package->getFullPrettyVersion().'</comment>)';
|
||||
return self::format($this->package, $lock);
|
||||
}
|
||||
|
||||
public static function format(PackageInterface $package, $lock = false)
|
||||
{
|
||||
return ($lock ? 'Locking ' : 'Installing ').'<info>'.$package->getPrettyName().'</info> (<comment>'.$package->getFullPrettyVersion().'</comment>)';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -61,7 +61,12 @@ class UninstallOperation extends SolverOperation
|
|||
*/
|
||||
public function show($lock)
|
||||
{
|
||||
return 'Removing <info>'.$this->package->getPrettyName().'</info> (<comment>'.$this->package->getFullPrettyVersion().'</comment>)';
|
||||
return self::format($this->package, $lock);
|
||||
}
|
||||
|
||||
public static function format(PackageInterface $package, $lock = false)
|
||||
{
|
||||
return 'Removing <info>'.$package->getPrettyName().'</info> (<comment>'.$package->getFullPrettyVersion().'</comment>)';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -75,20 +75,25 @@ class UpdateOperation extends SolverOperation
|
|||
*/
|
||||
public function show($lock)
|
||||
{
|
||||
$fromVersion = $this->initialPackage->getFullPrettyVersion();
|
||||
$toVersion = $this->targetPackage->getFullPrettyVersion();
|
||||
|
||||
if ($fromVersion === $toVersion && $this->initialPackage->getSourceReference() !== $this->targetPackage->getSourceReference()) {
|
||||
$fromVersion = $this->initialPackage->getFullPrettyVersion(true, PackageInterface::DISPLAY_SOURCE_REF);
|
||||
$toVersion = $this->targetPackage->getFullPrettyVersion(true, PackageInterface::DISPLAY_SOURCE_REF);
|
||||
} elseif ($fromVersion === $toVersion && $this->initialPackage->getDistReference() !== $this->targetPackage->getDistReference()) {
|
||||
$fromVersion = $this->initialPackage->getFullPrettyVersion(true, PackageInterface::DISPLAY_DIST_REF);
|
||||
$toVersion = $this->targetPackage->getFullPrettyVersion(true, PackageInterface::DISPLAY_DIST_REF);
|
||||
return self::format($this->initialPackage, $this->targetPackage, $lock);
|
||||
}
|
||||
|
||||
$actionName = VersionParser::isUpgrade($this->initialPackage->getVersion(), $this->targetPackage->getVersion()) ? 'Upgrading' : 'Downgrading';
|
||||
public static function format(PackageInterface $initialPackage, PackageInterface $targetPackage, $lock = false)
|
||||
{
|
||||
$fromVersion = $initialPackage->getFullPrettyVersion();
|
||||
$toVersion = $targetPackage->getFullPrettyVersion();
|
||||
|
||||
return $actionName.' <info>'.$this->initialPackage->getPrettyName().'</info> (<comment>'.$fromVersion.'</comment> => <comment>'.$toVersion.'</comment>)';
|
||||
if ($fromVersion === $toVersion && $initialPackage->getSourceReference() !== $targetPackage->getSourceReference()) {
|
||||
$fromVersion = $initialPackage->getFullPrettyVersion(true, PackageInterface::DISPLAY_SOURCE_REF);
|
||||
$toVersion = $targetPackage->getFullPrettyVersion(true, PackageInterface::DISPLAY_SOURCE_REF);
|
||||
} elseif ($fromVersion === $toVersion && $initialPackage->getDistReference() !== $targetPackage->getDistReference()) {
|
||||
$fromVersion = $initialPackage->getFullPrettyVersion(true, PackageInterface::DISPLAY_DIST_REF);
|
||||
$toVersion = $targetPackage->getFullPrettyVersion(true, PackageInterface::DISPLAY_DIST_REF);
|
||||
}
|
||||
|
||||
$actionName = VersionParser::isUpgrade($initialPackage->getVersion(), $targetPackage->getVersion()) ? 'Upgrading' : 'Downgrading';
|
||||
|
||||
return $actionName.' <info>'.$initialPackage->getPrettyName().'</info> (<comment>'.$fromVersion.'</comment> => <comment>'.$toVersion.'</comment>)';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,6 +17,7 @@ use Symfony\Component\Finder\Finder;
|
|||
use Composer\IO\IOInterface;
|
||||
use Composer\Exception\IrrecoverableDownloadException;
|
||||
use React\Promise\PromiseInterface;
|
||||
use Composer\DependencyResolver\Operation\InstallOperation;
|
||||
|
||||
/**
|
||||
* Base downloader for archives
|
||||
|
@ -40,7 +41,7 @@ abstract class ArchiveDownloader extends FileDownloader
|
|||
public function install(PackageInterface $package, $path, $output = true)
|
||||
{
|
||||
if ($output) {
|
||||
$this->io->writeError(" - Installing <info>" . $package->getName() . "</info> (<comment>" . $package->getFullPrettyVersion() . "</comment>): Extracting archive");
|
||||
$this->io->writeError(" - " . InstallOperation::format($package).": Extracting archive");
|
||||
} else {
|
||||
$this->io->writeError('Extracting archive', false);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,9 @@ use Composer\Factory;
|
|||
use Composer\IO\IOInterface;
|
||||
use Composer\IO\NullIO;
|
||||
use Composer\Package\Comparer\Comparer;
|
||||
use Composer\DependencyResolver\Operation\UpdateOperation;
|
||||
use Composer\DependencyResolver\Operation\InstallOperation;
|
||||
use Composer\DependencyResolver\Operation\UninstallOperation;
|
||||
use Composer\Package\PackageInterface;
|
||||
use Composer\Package\Version\VersionParser;
|
||||
use Composer\Plugin\PluginEvents;
|
||||
|
@ -284,7 +287,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
|
|||
public function install(PackageInterface $package, $path, $output = true)
|
||||
{
|
||||
if ($output) {
|
||||
$this->io->writeError(" - Installing <info>" . $package->getName() . "</info> (<comment>" . $package->getFullPrettyVersion() . "</comment>)");
|
||||
$this->io->writeError(" - " . InstallOperation::format($package));
|
||||
}
|
||||
|
||||
$this->filesystem->emptyDirectory($path);
|
||||
|
@ -332,12 +335,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
|
|||
*/
|
||||
public function update(PackageInterface $initial, PackageInterface $target, $path)
|
||||
{
|
||||
$name = $target->getName();
|
||||
$from = $initial->getFullPrettyVersion();
|
||||
$to = $target->getFullPrettyVersion();
|
||||
|
||||
$actionName = VersionParser::isUpgrade($initial->getVersion(), $target->getVersion()) ? 'Upgrading' : 'Downgrading';
|
||||
$this->io->writeError(" - " . $actionName . " <info>" . $name . "</info> (<comment>" . $from . "</comment> => <comment>" . $to . "</comment>): ", false);
|
||||
$this->io->writeError(" - " . UpdateOperation::format($initial, $target) . ": ", false);
|
||||
|
||||
$promise = $this->remove($initial, $path, false);
|
||||
if (!$promise instanceof PromiseInterface) {
|
||||
|
@ -360,7 +358,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
|
|||
public function remove(PackageInterface $package, $path, $output = true)
|
||||
{
|
||||
if ($output) {
|
||||
$this->io->writeError(" - Removing <info>" . $package->getName() . "</info> (<comment>" . $package->getFullPrettyVersion() . "</comment>)");
|
||||
$this->io->writeError(" - " . UninstallOperation::format($package));
|
||||
}
|
||||
if (!$this->filesystem->removeDirectory($path)) {
|
||||
throw new \RuntimeException('Could not completely delete '.$path.', aborting.');
|
||||
|
|
|
@ -27,6 +27,9 @@ use Composer\Util\Filesystem;
|
|||
use Composer\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\Filesystem\Exception\IOException;
|
||||
use Symfony\Component\Filesystem\Filesystem as SymfonyFilesystem;
|
||||
use Composer\DependencyResolver\Operation\UpdateOperation;
|
||||
use Composer\DependencyResolver\Operation\InstallOperation;
|
||||
use Composer\DependencyResolver\Operation\UninstallOperation;
|
||||
|
||||
/**
|
||||
* Download a package from a local path.
|
||||
|
@ -82,11 +85,7 @@ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInter
|
|||
|
||||
if (realpath($path) === $realUrl) {
|
||||
if ($output) {
|
||||
$this->io->writeError(sprintf(
|
||||
' - Installing <info>%s</info> (<comment>%s</comment>): Source already present',
|
||||
$package->getName(),
|
||||
$package->getFullPrettyVersion()
|
||||
));
|
||||
$this->io->writeError(" - " . InstallOperation::format($package).': Source already present');
|
||||
} else {
|
||||
$this->io->writeError('Source already present', false);
|
||||
}
|
||||
|
@ -124,11 +123,7 @@ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInter
|
|||
$this->filesystem->removeDirectory($path);
|
||||
|
||||
if ($output) {
|
||||
$this->io->writeError(sprintf(
|
||||
' - Installing <info>%s</info> (<comment>%s</comment>): ',
|
||||
$package->getName(),
|
||||
$package->getFullPrettyVersion()
|
||||
), false);
|
||||
$this->io->writeError(" - " . InstallOperation::format($package).': ', false);
|
||||
}
|
||||
|
||||
$isFallback = false;
|
||||
|
@ -187,7 +182,7 @@ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInter
|
|||
|
||||
if ($path === $realUrl) {
|
||||
if ($output) {
|
||||
$this->io->writeError(" - Removing <info>" . $package->getName() . "</info> (<comment>" . $package->getFullPrettyVersion() . "</comment>), source is still present in $path");
|
||||
$this->io->writeError(" - " . UninstallOperation::format($package).", source is still present in $path");
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -200,7 +195,7 @@ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInter
|
|||
*/
|
||||
if (Platform::isWindows() && $this->filesystem->isJunction($path)) {
|
||||
if ($output) {
|
||||
$this->io->writeError(" - Removing junction for <info>" . $package->getName() . "</info> (<comment>" . $package->getFullPrettyVersion() . "</comment>)");
|
||||
$this->io->writeError(" - " . UninstallOperation::format($package).", source is still present in $path");
|
||||
}
|
||||
if (!$this->filesystem->removeJunction($path)) {
|
||||
$this->io->writeError(" <warning>Could not remove junction at " . $path . " - is another process locking it?</warning>");
|
||||
|
|
|
@ -21,6 +21,9 @@ use Composer\Util\ProcessExecutor;
|
|||
use Composer\IO\IOInterface;
|
||||
use Composer\Util\Filesystem;
|
||||
use React\Promise\PromiseInterface;
|
||||
use Composer\DependencyResolver\Operation\UpdateOperation;
|
||||
use Composer\DependencyResolver\Operation\InstallOperation;
|
||||
use Composer\DependencyResolver\Operation\UninstallOperation;
|
||||
|
||||
/**
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
|
@ -120,7 +123,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
|
|||
throw new \InvalidArgumentException('Package '.$package->getPrettyName().' is missing reference information');
|
||||
}
|
||||
|
||||
$this->io->writeError(" - Installing <info>" . $package->getName() . "</info> (<comment>" . $package->getFullPrettyVersion() . "</comment>): ", false);
|
||||
$this->io->writeError(" - " . InstallOperation::format($package).': ', false);
|
||||
|
||||
$urls = $this->prepareUrls($package->getSourceUrls());
|
||||
while ($url = array_shift($urls)) {
|
||||
|
@ -153,23 +156,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
|
|||
throw new \InvalidArgumentException('Package '.$target->getPrettyName().' is missing reference information');
|
||||
}
|
||||
|
||||
$name = $target->getName();
|
||||
if ($initial->getPrettyVersion() == $target->getPrettyVersion()) {
|
||||
if ($target->getSourceType() === 'svn') {
|
||||
$from = $initial->getSourceReference();
|
||||
$to = $target->getSourceReference();
|
||||
} else {
|
||||
$from = substr($initial->getSourceReference(), 0, 7);
|
||||
$to = substr($target->getSourceReference(), 0, 7);
|
||||
}
|
||||
$name .= ' '.$initial->getPrettyVersion();
|
||||
} else {
|
||||
$from = $initial->getFullPrettyVersion();
|
||||
$to = $target->getFullPrettyVersion();
|
||||
}
|
||||
|
||||
$actionName = VersionParser::isUpgrade($initial->getVersion(), $target->getVersion()) ? 'Upgrading' : 'Downgrading';
|
||||
$this->io->writeError(" - " . $actionName . " <info>" . $name . "</info> (<comment>" . $from . "</comment> => <comment>" . $to . "</comment>): ", false);
|
||||
$this->io->writeError(" - " . UpdateOperation::format($initial, $target).': ', false);
|
||||
|
||||
$urls = $this->prepareUrls($target->getSourceUrls());
|
||||
|
||||
|
@ -227,7 +214,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
|
|||
*/
|
||||
public function remove(PackageInterface $package, $path)
|
||||
{
|
||||
$this->io->writeError(" - Removing <info>" . $package->getName() . "</info> (<comment>" . $package->getPrettyVersion() . "</comment>)");
|
||||
$this->io->writeError(" - " . UninstallOperation::format($package));
|
||||
if (!$this->filesystem->removeDirectory($path)) {
|
||||
throw new \RuntimeException('Could not completely delete '.$path.', aborting.');
|
||||
}
|
||||
|
|
|
@ -16,6 +16,9 @@ use Composer\Repository\InstalledRepositoryInterface;
|
|||
use Composer\Package\PackageInterface;
|
||||
use Composer\Package\Version\VersionParser;
|
||||
use Composer\IO\IOInterface;
|
||||
use Composer\DependencyResolver\Operation\UpdateOperation;
|
||||
use Composer\DependencyResolver\Operation\InstallOperation;
|
||||
use Composer\DependencyResolver\Operation\UninstallOperation;
|
||||
|
||||
/**
|
||||
* Metapackage installation manager.
|
||||
|
@ -76,7 +79,7 @@ class MetapackageInstaller implements InstallerInterface
|
|||
*/
|
||||
public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
|
||||
{
|
||||
$this->io->writeError(" - Installing <info>" . $package->getName() . "</info> (<comment>" . $package->getFullPrettyVersion() . "</comment>)");
|
||||
$this->io->writeError(" - " . InstallOperation::format($package));
|
||||
|
||||
$repo->addPackage(clone $package);
|
||||
}
|
||||
|
@ -90,11 +93,7 @@ class MetapackageInstaller implements InstallerInterface
|
|||
throw new \InvalidArgumentException('Package is not installed: '.$initial);
|
||||
}
|
||||
|
||||
$name = $target->getName();
|
||||
$from = $initial->getFullPrettyVersion();
|
||||
$to = $target->getFullPrettyVersion();
|
||||
$actionName = VersionParser::isUpgrade($initial->getVersion(), $target->getVersion()) ? 'Upgrading' : 'Downgrading';
|
||||
$this->io->writeError(" - " . $actionName . " <info>" . $name . "</info> (<comment>" . $from . "</comment> => <comment>" . $to . "</comment>)");
|
||||
$this->io->writeError(" - " . UpdateOperation::format($initial, $target));
|
||||
|
||||
$repo->removePackage($initial);
|
||||
$repo->addPackage(clone $target);
|
||||
|
@ -109,7 +108,7 @@ class MetapackageInstaller implements InstallerInterface
|
|||
throw new \InvalidArgumentException('Package is not installed: '.$package);
|
||||
}
|
||||
|
||||
$this->io->writeError(" - Removing <info>" . $package->getName() . "</info> (<comment>" . $package->getFullPrettyVersion() . "</comment>)");
|
||||
$this->io->writeError(" - " . UninstallOperation::format($package));
|
||||
|
||||
$repo->removePackage($package);
|
||||
}
|
||||
|
|
|
@ -233,7 +233,7 @@ abstract class BasePackage implements PackageInterface
|
|||
}
|
||||
|
||||
// if source reference is a sha1 hash -- truncate
|
||||
if ($truncate && \strlen($reference) === 40) {
|
||||
if ($truncate && \strlen($reference) === 40 && $this->getSourceType() !== 'svn') {
|
||||
return $this->getPrettyVersion() . ' ' . substr($reference, 0, 7);
|
||||
}
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ class BasePackageTest extends TestCase
|
|||
$createPackage = function ($arr) use ($self) {
|
||||
$package = $self->getMockForAbstractClass('\Composer\Package\BasePackage', array(), '', false);
|
||||
$package->expects($self->once())->method('isDev')->will($self->returnValue(true));
|
||||
$package->expects($self->once())->method('getSourceType')->will($self->returnValue('git'));
|
||||
$package->expects($self->any())->method('getSourceType')->will($self->returnValue('git'));
|
||||
$package->expects($self->once())->method('getPrettyVersion')->will($self->returnValue('PrettyVersion'));
|
||||
$package->expects($self->any())->method('getSourceReference')->will($self->returnValue($arr['sourceReference']));
|
||||
|
||||
|
|
Loading…
Reference in New Issue