added --prefer-dist option

main
Mateusz Heleniak 12 years ago
parent a04591bbd7
commit aa0ff14be5

@ -31,6 +31,7 @@ class InstallCommand extends Command
->setDescription('Parses the composer.json file and downloads the needed dependencies.')
->setDefinition(array(
new InputOption('prefer-source', null, InputOption::VALUE_NONE, 'Forces installation from package sources when possible, including VCS information.'),
new InputOption('prefer-dist', null, InputOption::VALUE_NONE, 'Forces installation from package dist even for dev versions.'),
new InputOption('dry-run', null, InputOption::VALUE_NONE, 'Outputs the operations but will not execute anything (implicitly enables --verbose).'),
new InputOption('dev', null, InputOption::VALUE_NONE, 'Enables installation of dev-require packages.'),
new InputOption('no-custom-installers', null, InputOption::VALUE_NONE, 'Disables all custom installers.'),
@ -59,6 +60,7 @@ EOT
->setDryRun($input->getOption('dry-run'))
->setVerbose($input->getOption('verbose'))
->setPreferSource($input->getOption('prefer-source'))
->setPreferDist($input->getOption('prefer-dist'))
->setDevMode($input->getOption('dev'))
->setRunScripts(!$input->getOption('no-scripts'))
;

@ -31,6 +31,7 @@ class UpdateCommand extends Command
->setDefinition(array(
new InputArgument('packages', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, 'Packages that should be updated, if not provided all packages are.'),
new InputOption('prefer-source', null, InputOption::VALUE_NONE, 'Forces installation from package sources when possible, including VCS information.'),
new InputOption('prefer-dist', null, InputOption::VALUE_NONE, 'Forces installation from package dist even for dev versions.'),
new InputOption('dry-run', null, InputOption::VALUE_NONE, 'Outputs the operations but will not execute anything (implicitly enables --verbose).'),
new InputOption('dev', null, InputOption::VALUE_NONE, 'Enables installation of dev-require packages.'),
new InputOption('no-custom-installers', null, InputOption::VALUE_NONE, 'Disables all custom installers.'),
@ -63,6 +64,7 @@ EOT
->setDryRun($input->getOption('dry-run'))
->setVerbose($input->getOption('verbose'))
->setPreferSource($input->getOption('prefer-source'))
->setPreferDist($input->getOption('prefer-dist'))
->setDevMode($input->getOption('dev'))
->setRunScripts(!$input->getOption('no-scripts'))
->setUpdate(true)

@ -23,6 +23,7 @@ use Composer\Util\Filesystem;
*/
class DownloadManager
{
private $preferDist = false;
private $preferSource = false;
private $filesystem;
private $downloaders = array();
@ -51,6 +52,18 @@ class DownloadManager
return $this;
}
/**
* Makes downloader prefer dist installation over the source.
*
* @param bool $preferDist prefer downloading from dist
*/
public function setPreferDist($preferDist)
{
$this->preferDist = $preferDist;
return $this;
}
/**
* Sets installer downloader for a specific installation type.
*
@ -134,12 +147,12 @@ class DownloadManager
$sourceType = $package->getSourceType();
$distType = $package->getDistType();
if (!$package->isDev() && !($preferSource && $sourceType) && $distType) {
if ((!$package->isDev() || $this->preferDist) && !($preferSource && $sourceType) && $distType) {
$package->setInstallationSource('dist');
} elseif ($sourceType) {
$package->setInstallationSource('source');
} elseif ($package->isDev()) {
throw new \InvalidArgumentException('Dev package '.$package.' must have a source specified');
} elseif ($package->isDev() && $distType) {
throw new \InvalidArgumentException('Dev package '.$package.' should have a source specified because for dev packages dist is used only with --prefer-dist option');
} else {
throw new \InvalidArgumentException('Package '.$package.' must have a source or dist specified');
}

@ -91,6 +91,7 @@ class Installer
protected $autoloadGenerator;
protected $preferSource = false;
protected $preferDist = false;
protected $devMode = false;
protected $dryRun = false;
protected $verbose = false;
@ -148,6 +149,9 @@ class Installer
if ($this->preferSource) {
$this->downloadManager->setPreferSource(true);
}
if ($this->preferDist) {
$this->downloadManager->setPreferDist(true);
}
// create installed repo, this contains all local packages + platform packages (php & extensions)
$installedRootPackage = clone $this->package;
@ -679,6 +683,19 @@ class Installer
return $this;
}
/**
* prefer dist installation
*
* @param boolean $preferDist
* @return Installer
*/
public function setPreferDist($preferDist = true)
{
$this->preferDist = (boolean) $preferDist;
return $this;
}
/**
* update packages
*

Loading…
Cancel
Save