Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/Composer/Downloader/DownloadManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,14 @@ public function getDownloaderForInstalledPackage(PackageInterface $package)
}

/**
* Downloads package into target dir.
* Sets installation source type "dist" or "source" for given package.
*
* @param PackageInterface $package package instance
* @param string $targetDir target dir
* @param bool $preferSource prefer installation from source
*
* @throws InvalidArgumentException if package have no urls to download from
* @throws InvalidArgumentException if package has no installation source specified
*/
public function download(PackageInterface $package, $targetDir, $preferSource = null)
public function setInstallationSourceForPackage(PackageInterface $package, $preferSource = null)
{
$preferSource = null !== $preferSource ? $preferSource : $this->preferSource;
$sourceType = $package->getSourceType();
Expand All @@ -143,7 +142,20 @@ public function download(PackageInterface $package, $targetDir, $preferSource =
} else {
throw new \InvalidArgumentException('Package '.$package.' must have a source or dist specified');
}
}

/**
* Downloads package into target dir.
*
* @param PackageInterface $package package instance
* @param string $targetDir target dir
* @param bool $preferSource prefer installation from source
*
* @throws InvalidArgumentException if package have no urls to download from
*/
public function download(PackageInterface $package, $targetDir, $preferSource = null)
{
$this->setInstallationSourceForPackage($package, $preferSource);
$this->filesystem->ensureDirectoryExists($targetDir);

$downloader = $this->getDownloaderForInstalledPackage($package);
Expand Down
10 changes: 10 additions & 0 deletions src/Composer/Downloader/DownloaderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,14 @@ public function update(PackageInterface $initial, PackageInterface $target, $pat
* @param string $path download path
*/
public function remove(PackageInterface $package, $path);

/**
* Checks whether downloader can be used (eg required binary executables)
*
* @param PackageInterface $package package instance
* @param string $error any error will be written into this var if passed by ref
*
* @return bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boolean

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pborreli no. Composer does not use this rule of the capital B which confuses the IDEs (they don't recognize it as boolean but as a class name).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok my bad, removing the others keeping this one for the record

*/
public function isAvailable(PackageInterface $package, &$error = null);
}
8 changes: 8 additions & 0 deletions src/Composer/Downloader/FileDownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ public function remove(PackageInterface $package, $path)
}
}

/**
* {@inheritDoc}
*/
public function isAvailable(PackageInterface $package, &$error = null)
{
return true;
}

/**
* Gets file name for specific package
*
Expand Down
17 changes: 17 additions & 0 deletions src/Composer/Downloader/GitDownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@ public function getLocalChanges($path)
return trim($output) ?: null;
}

/**
* {@inheritDoc}
*/
public function isAvailable(PackageInterface $package, &$error = null)
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) { // no check, yet
return true;
}

$command = 'test -x `which git` && echo "OK"';
if (0 !== $this->process->execute($command, $output)) {
$error = 'Did not find executable "git" in $PATH';
return false;
}
return 'OK' === trim($output);
}

protected function updateToCommit($path, $reference, $branch, $date)
{
$template = 'git checkout %s && git reset --hard %1$s';
Expand Down
17 changes: 17 additions & 0 deletions src/Composer/Downloader/HgDownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,21 @@ protected function getCommitLogs($fromReference, $toReference, $path)

return $output;
}

/**
* {@inheritDoc}
*/
public function isAvailable(PackageInterface $package, &$error = null)
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) { // no check, yet
return true;
}

$command = 'test -x `which hg` && echo "OK"';
if (0 !== $this->process->execute($command, $output)) {
$error = 'Did not find executable "hg" in $PATH';
return false;
}
return 'OK' === trim($output);
}
}
17 changes: 17 additions & 0 deletions src/Composer/Downloader/SvnDownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,21 @@ protected function getCommitLogs($fromReference, $toReference, $path)

return $output;
}

/**
* {@inheritDoc}
*/
public function isAvailable(PackageInterface $package, &$error = null)
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) { // no check, yet
return true;
}

$command = 'test -x `which svn` && echo "OK"';
if (0 !== $this->process->execute($command, $output)) {
$error = 'Did not find executable "svn" in $PATH';
return false;
}
return 'OK' === trim($output);
}
}
8 changes: 8 additions & 0 deletions src/Composer/Downloader/VcsDownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ public function remove(PackageInterface $package, $path)
}
}

/**
* {@inheritDoc}
*/
public function isAvailable(PackageInterface $package, &$error = null)
{
return true;
}

/**
* Guarantee that no changes have been made to the local copy
*
Expand Down
25 changes: 25 additions & 0 deletions src/Composer/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ protected function doInstall($localRepo, $installedRepo, $aliases, $devMode = fa
$this->io->write('Nothing to install or update');
}

$executes = array();
foreach ($operations as $operation) {
// collect suggestions
if ('install' === $operation->getJobType()) {
Expand Down Expand Up @@ -484,6 +485,30 @@ protected function doInstall($localRepo, $installedRepo, $aliases, $devMode = fa
$this->io->write(' - ' . $operation);
}


// for install/update check whether downloader is available
if (in_array($operation->getJobType(), array('install', 'update'))) {
// assure installation source set
$package = 'install' === $operation->getJobType()
? $operation->getPackage() : $operation->getTargetPackage();
$this->downloadManager->setInstallationSourceForPackage($package);
$source = $package->getInstallationSource();
$downloadType = 'dist' === $source ? $package->getDistType() : $package->getSourceType();

// check whether downloader can be used
$downloader = $this->downloadManager->getDownloader($downloadType);
if (!$downloader || !$downloader->isAvailable($package, $downloaderError)) {
throw new \RuntimeException(sprintf("Cannot %s package %s: %s",
$operation->getJobType(), $package->getPrettyName(), $downloaderError));
}
}

// add to execute list
$executes[] = array($localRepo, $operation);
}

foreach ($executes as $execute) {
list($localRepo, $operation) = $execute;
$this->installationManager->execute($localRepo, $operation);

$event = 'Composer\Script\ScriptEvents::POST_PACKAGE_'.strtoupper($operation->getJobType());
Expand Down