public function mapContrib(InstallationManager $im, RepositoryManager $rm) { $typePathMap = $this->getTypePathMap(); $typeInstallMap = []; $packages = $rm->getLocalRepository()->getCanonicalPackages(); foreach ($packages as $package) { if ($drupalType = $this->getDrupalType($package)) { if (!isset($typePathMap[$drupalType])) { continue; } $installPath = self::changeSlashes($im->getInstaller($package->getType())->getInstallPath($package)); if (strpos($installPath, $root = $this->getRoot()) !== false) { $installPath = self::changeSlashes($this->getFS()->makePathRelative($installPath, $root)); } $name = explode('/', $package->getPrettyName())[1]; $mapRef =& $typeInstallMap[$drupalType][rtrim($installPath, DIRECTORY_SEPARATOR)]; if (in_array($drupalType, ['module', 'theme'])) { $mapRef = sprintf($typePathMap[$drupalType] . DIRECTORY_SEPARATOR . '%s', 'contrib', $name); } else { $mapRef = sprintf($typePathMap[$drupalType], $name); } } } return array_intersect_key($typeInstallMap, $typePathMap); }
protected function setUp() { $this->fs = new Filesystem(); $that = $this; $this->workingDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'cmptest-' . md5(uniqid('', true)); $this->fs->ensureDirectoryExists($this->workingDir); $this->vendorDir = $this->workingDir . DIRECTORY_SEPARATOR . 'composer-test-autoload'; $this->ensureDirectoryExistsAndClear($this->vendorDir); $this->config = $this->getMock('Composer\\Config'); $this->config->expects($this->at(0))->method('get')->with($this->equalTo('vendor-dir'))->will($this->returnCallback(function () use($that) { return $that->vendorDir; })); $this->config->expects($this->at(1))->method('get')->with($this->equalTo('vendor-dir'))->will($this->returnCallback(function () use($that) { return $that->vendorDir; })); $this->origDir = getcwd(); chdir($this->workingDir); $this->im = $this->getMockBuilder('Composer\\Installer\\InstallationManager')->disableOriginalConstructor()->getMock(); $this->im->expects($this->any())->method('getInstallPath')->will($this->returnCallback(function ($package) use($that) { $targetDir = $package->getTargetDir(); return $that->vendorDir . '/' . $package->getName() . ($targetDir ? '/' . $targetDir : ''); })); $this->repository = $this->getMock('Composer\\Repository\\InstalledRepositoryInterface'); $this->eventDispatcher = $this->getMockBuilder('Composer\\EventDispatcher\\EventDispatcher')->disableOriginalConstructor()->getMock(); $this->generator = new AutoloadGenerator($this->eventDispatcher); }
public function build($rootDirectory, $optimize = false, $noDevMode = false) { $packages = $this->loadPackages($rootDirectory); $evm = new EventDispatcher(new Composer(), $this->io); $generator = new AutoloadGenerator($evm, $this->io); $generator->setDevMode(!$noDevMode); $installationManager = new InstallationManager(); $installationManager->addInstaller(new FiddlerInstaller()); $this->io->write('Building fiddler.json projects.'); foreach ($packages as $packageName => $config) { if (strpos($packageName, 'vendor') === 0) { continue; } $this->io->write(' [Build] <info>' . $packageName . '</info>'); $mainPackage = new Package($packageName, "@stable", "@stable"); $mainPackage->setType('fiddler'); $mainPackage->setAutoload($config['autoload']); $mainPackage->setDevAutoload($config['autoload-dev']); $localRepo = new FiddlerInstalledRepository(); $this->resolvePackageDependencies($localRepo, $packages, $packageName); $composerConfig = new Config(true, $rootDirectory); $composerConfig->merge(array('config' => array('vendor-dir' => $config['path'] . '/vendor'))); $generator->dump($composerConfig, $localRepo, $mainPackage, $installationManager, 'composer', $optimize); } }
/** * @param string $packageName * @param string $sourceDirectory * @param string $targetDirectory */ protected static function mirrorDirectory($packageName, $sourceDirectory, $targetDirectory) { $packages = static::$localRepository->findPackages($packageName, null); foreach ($packages as $package) { if (static::$installationManager->getInstaller($package->getType())->isInstalled(static::$localRepository, $package)) { static::getFileSystem()->mirror(static::$installationManager->getInstallPath($package) . '/' . ltrim($sourceDirectory, '/'), $targetDirectory, null, ['copy_on_windows']); return; } } }
protected function setUp() { $this->package = $this->getMockBuilder('Composer\\Package\\RootPackageInterface')->getMock(); $this->assetType = $this->getMockBuilder('Fxp\\Composer\\AssetPlugin\\Type\\AssetTypeInterface')->getMock(); $versionConverter = $this->getMockBuilder('Fxp\\Composer\\AssetPlugin\\Converter\\VersionConverterInterface')->getMock(); $versionConverter->expects($this->any())->method('convertVersion')->will($this->returnCallback(function ($value) { return $value; })); $this->assetType->expects($this->any())->method('getVersionConverter')->will($this->returnValue($versionConverter)); $this->installationManager = $this->getMockBuilder('Composer\\Installer\\InstallationManager')->disableOriginalConstructor()->getMock(); $this->installationManager->expects($this->any())->method('isPackageInstalled')->will($this->returnValue(true)); }
/** * Apply plugin modifications to composer * * @param \Composer\Composer $composer * @param \Composer\IO\IOInterface $io * @return void */ public function activate(Composer $composer, IOInterface $io) { $this->io = $io; $this->composer = $composer; $this->factory = $this->getFactory(); $this->manager = $this->getInstallationManager($composer); // The connection factory is used to create the actual connection instances on // the database. We will inject the factory into the manager so that it may // make the connections while they are actually needed and not of before. $installers = $this->factory->getInstallers(); foreach ($installers as $name) { $this->manager->addInstaller($this->factory->make($name, $composer, $io)); } }
protected function setUp() { $this->tempDir = TestUtil::makeTempDir('puli-composer-plugin', __CLASS__); $filesystem = new Filesystem(); $filesystem->mirror(__DIR__ . '/Fixtures/root', $this->tempDir); $this->io = $this->getMock('Composer\\IO\\IOInterface'); $this->config = new Config(false, $this->tempDir); $this->config->merge(array('config' => array('vendor-dir' => 'the-vendor'))); $this->installationManager = $this->getMockBuilder('Composer\\Installer\\InstallationManager')->disableOriginalConstructor()->getMock(); $this->installationManager->expects($this->any())->method('getInstallPath')->will($this->returnCallback(array($this, 'getInstallPath'))); $this->rootPackage = new RootPackage('vendor/root', '1.0', '1.0'); $this->rootPackage->setRequires(array('vendor/package1' => new Link('vendor/root', 'vendor/package1'), 'vendor/package2' => new Link('vendor/root', 'vendor/package2'))); $this->localRepository = new TestLocalRepository(array(new Package('vendor/package1', '1.0', '1.0'), new Package('vendor/package2', '1.0', '1.0'))); $this->repositoryManager = new RepositoryManager($this->io, $this->config); $this->repositoryManager->setLocalRepository($this->localRepository); $this->installPaths = array(); $this->composer = new Composer(); $this->composer->setRepositoryManager($this->repositoryManager); $this->composer->setInstallationManager($this->installationManager); $this->composer->setConfig($this->config); $this->composer->setPackage($this->rootPackage); $this->puliRunner = $this->getMockBuilder('Puli\\ComposerPlugin\\PuliRunner')->disableOriginalConstructor()->getMock(); $this->previousWd = getcwd(); chdir($this->tempDir); $this->plugin = new PuliPlugin($this->puliRunner); }
protected function setUp() { while (false === mkdir($this->tempDir = sys_get_temp_dir() . '/puli-plugin/PuliPluginTest_root' . rand(10000, 99999), 0777, true)) { } $filesystem = new Filesystem(); $filesystem->mirror(__DIR__ . '/Fixtures/root', $this->tempDir); $this->io = $this->getMock('Composer\\IO\\IOInterface'); $this->config = new Config(false, $this->tempDir); $this->config->merge(array('config' => array('vendor-dir' => 'the-vendor'))); $this->installationManager = $this->getMockBuilder('Composer\\Installer\\InstallationManager')->disableOriginalConstructor()->getMock(); $this->installationManager->expects($this->any())->method('getInstallPath')->will($this->returnCallback(array($this, 'getInstallPath'))); $this->rootPackage = new RootPackage('vendor/root', '1.0', '1.0'); $this->localRepository = new TestLocalRepository(array(new Package('vendor/package1', '1.0', '1.0'), new Package('vendor/package2', '1.0', '1.0'))); $this->repositoryManager = new RepositoryManager($this->io, $this->config); $this->repositoryManager->setLocalRepository($this->localRepository); $this->installPaths = array(); $this->composer = new Composer(); $this->composer->setRepositoryManager($this->repositoryManager); $this->composer->setInstallationManager($this->installationManager); $this->composer->setConfig($this->config); $this->composer->setPackage($this->rootPackage); $this->puliRunner = $this->getMockBuilder('Puli\\ComposerPlugin\\PuliRunner')->disableOriginalConstructor()->getMock(); $this->previousWd = getcwd(); chdir($this->tempDir); $this->plugin = new PuliPlugin($this->puliRunner); }
function getInstaller($packageType) { // if we don't support this type at all, move along to the rest of the installers if (!$this->wpInstaller->supports($packageType)) { $this->io->write("Composer-WP installer does not support {$packageType}", true, IOInterface::DEBUG); return parent::getInstaller($packageType); } // if we explicitly support this type, return the WP installer if ($this->wpInstaller->prioritySupports($packageType)) { $this->io->write("Composer-WP installer explicitly supports {$packageType}", true, IOInterface::DEBUG); return $this->wpInstaller; } // otherwise, check to see if there is another installer that supports this type before we claim it try { // this may throw an InvalidArgumentException if no installer is found, but // LibraryInstaller is a floozie and will take any package it can get its hands on $installer = parent::getInstaller($packageType); $class = get_class($installer); // is the selected installer just the default one? if ($class === 'Composer\\Installer\\LibraryInstaller') { throw new \InvalidArgumentException(); } $this->io->write("Composer-WP installer supports {$packageType} but gives priority to {$class}", true, IOInterface::DEBUG); // set the path to false so we do not try again $this->wpInstaller->setPath($packageType, false); return $installer; } catch (\InvalidArgumentException $e) { $this->io->write("Composer-WP installer claims support for {$packageType}", true, IOInterface::DEBUG); // no custom installer, let's take charge! $this->wpInstaller->setPath($packageType); return $this->wpInstaller; } }
protected function setUp() { $this->fs = new Filesystem(); $that = $this; $this->workingDir = $this->getUniqueTmpDirectory(); $this->vendorDir = $this->workingDir . DIRECTORY_SEPARATOR . 'composer-test-autoload'; $this->ensureDirectoryExistsAndClear($this->vendorDir); $this->config = $this->getMock('Composer\\Config'); $this->configValueMap = array('vendor-dir' => function () use($that) { return $that->vendorDir; }); $this->config->expects($this->atLeastOnce())->method('get')->will($this->returnCallback(function ($arg) use($that) { $ret = null; if (isset($that->configValueMap[$arg])) { $ret = $that->configValueMap[$arg]; if (is_callable($ret)) { $ret = $ret(); } } return $ret; })); $this->origDir = getcwd(); chdir($this->workingDir); $this->im = $this->getMockBuilder('Composer\\Installer\\InstallationManager')->disableOriginalConstructor()->getMock(); $this->im->expects($this->any())->method('getInstallPath')->will($this->returnCallback(function ($package) use($that) { $targetDir = $package->getTargetDir(); return $that->vendorDir . '/' . $package->getName() . ($targetDir ? '/' . $targetDir : ''); })); $this->repository = $this->getMock('Composer\\Repository\\InstalledRepositoryInterface'); $this->eventDispatcher = $this->getMockBuilder('Composer\\EventDispatcher\\EventDispatcher')->disableOriginalConstructor()->getMock(); $this->generator = new AutoloadGenerator($this->eventDispatcher); }
public function mapContrib(InstallationManager $im, RepositoryManager $rm) { $typePathMap = $this->getTypePathMap(); $typeInstallMap = []; $packages = $rm->getLocalRepository()->getCanonicalPackages(); foreach ($packages as $package) { if ($drupalType = $this->getDrupalType($package)) { $installPath = $im->getInstaller($package->getType())->getInstallPath($package); if (strpos($installPath, $root = $this->getRoot()) !== false) { $installPath = $this->getFS()->makePathRelative($installPath, $root); } $name = explode('/', $package->getPrettyName())[1]; $typeInstallMap[$drupalType][rtrim($installPath, '/')] = sprintf($typePathMap[$drupalType] . '/%s', 'contrib', $name); } } return array_intersect_key($typeInstallMap, $typePathMap); }
/** * Return the install path based on package type. * * @param PackageInterface $package * @return string */ public function getInstallPath(PackageInterface $package) { $path = $this->installManager->getInstallPath($package); if (!$this->filesystem->isAbsolutePath($path)) { return realpath('.') . DIRECTORY_SEPARATOR . rtrim($path, '/'); } return $path; }
/** * @test * * @depends testInstallerCreationShouldNotCreateVendorDirectory * @depends testInstallerCreationShouldNotCreateBinDirectory */ public function updateFull() { /** @var InstallationManager|\PHPUnit_Framework_MockObject_MockObject $im */ $this->im->expects($this->once())->method('uninstall'); $this->im->expects($this->once())->method('install'); $installer = $this->createInstaller(); $initial = $this->createPackageMock('letudiant/bar-foo'); $target = $this->createPackageMock(); $installer->update($this->repository, $initial, $target); }
public static function install(Event $event) { if (!self::init($event)) { return; } $notInstalled = 0; if (!empty(self::$toInstall)) { self::$io->write('<info>Installing platform-specific dependencies</info>'); foreach (self::$toInstall as $package) { if (!self::$installer->isPackageInstalled(self::$localRepo, $package)) { self::$installer->install(self::$localRepo, new InstallOperation($package)); self::updateBinary($package); } else { $notInstalled++; } } } if (empty(self::$toInstall) || $notInstalled > 0) { self::$io->write('Nothing to install or update in platform-specific dependencies'); } }
public function build($rootDirectory, $optimize = false, $noDevMode = false) { $this->io->write(sprintf('<info>Generating autoload files for monorepo sub-packages %s dev-dependencies.</info>', $noDevMode ? 'without' : 'with')); $start = microtime(true); $packages = $this->loadPackages($rootDirectory); $evm = new EventDispatcher(new Composer(), $this->io); $generator = new AutoloadGenerator($evm, $this->io); $generator->setDevMode(!$noDevMode); $installationManager = new InstallationManager(); $installationManager->addInstaller(new MonorepoInstaller()); foreach ($packages as $packageName => $config) { if (strpos($packageName, 'vendor') === 0) { continue; } $this->io->write(sprintf(' [Subpackage] <comment>%s</comment>', $packageName)); $mainPackage = new Package($packageName, "@stable", "@stable"); $mainPackage->setType('monorepo'); $mainPackage->setAutoload($config['autoload']); $mainPackage->setDevAutoload($config['autoload-dev']); $localRepo = new MonorepoInstalledRepository(); $this->resolvePackageDependencies($localRepo, $packages, $packageName); $composerConfig = new Config(true, $rootDirectory); $composerConfig->merge(array('config' => array('vendor-dir' => $config['path'] . '/vendor'))); $generator->dump($composerConfig, $localRepo, $mainPackage, $installationManager, 'composer', $optimize); $binDir = $config['path'] . '/vendor/bin'; // remove old symlinks array_map('unlink', glob($binDir . '/*')); foreach ($localRepo->getPackages() as $package) { foreach ($package->getBinaries() as $binary) { if (!is_dir($binDir)) { mkdir($binDir, 0755, true); } $binFile = $binDir . '/' . basename($binary); symlink($rootDirectory . '/' . $binary, $binFile); } } } $duration = microtime(true) - $start; $this->io->write(sprintf('Monorepo subpackage autoloads generated in <comment>%0.2f</comment> seconds.', $duration)); }
/** * @param PackageInterface[] $packages * @param string $command * * @return string */ protected function executeBatchCommand(array $packages, $command) { $paths = []; foreach ($packages as $package) { $paths[] = $this->installationManager->getInstallPath($package); } $commands = $this->makeCommands($paths, $command); $output = ''; foreach ($commands as $command) { $output .= $this->runCommand($command); } return $output; }
public function setUp() { $this->filesystem = new Filesystem(); $this->composer = new Composer(); $this->config = new Config(); $this->io = new NullIO(); $this->componentDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'component-installer-componentDir'; $this->vendorDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'component-installer-vendorDir'; $this->binDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'component-installer-binDir'; foreach (array($this->componentDir, $this->vendorDir, $this->binDir) as $dir) { if (is_dir($dir)) { $this->filesystem->removeDirectory($dir); } $this->filesystem->ensureDirectoryExists($dir); } $this->config->merge(array('config' => array('vendor-dir' => $this->vendorDir, 'component-dir' => $this->componentDir, 'bin-dir' => $this->binDir))); $this->composer->setConfig($this->config); // Set up the Installation Manager. $this->installationManager = new InstallationManager(); $this->installationManager->addInstaller(new LibraryInstaller($this->io, $this->composer)); $this->installationManager->addInstaller(new Installer($this->io, $this->composer)); $this->composer->setInstallationManager($this->installationManager); }
public function build($rootDirectory, $optimize = false, $noDevMode = false) { $packages = $this->loadPackages($rootDirectory); $evm = new EventDispatcher(new Composer(), $this->io); $generator = new AutoloadGenerator($evm, $this->io); $generator->setDevMode(!$noDevMode); $installationManager = new InstallationManager(); $installationManager->addInstaller(new FiddlerInstaller()); $this->io->write('Building fiddler.json projects.'); foreach ($packages as $packageName => $config) { if (strpos($packageName, 'vendor') === 0) { continue; } $this->io->write(' [Build] <info>' . $packageName . '</info>'); $mainPackage = new Package($packageName, "@stable", "@stable"); $mainPackage->setType('fiddler'); $mainPackage->setAutoload($config['autoload']); $mainPackage->setDevAutoload($config['autoload-dev']); $localRepo = new FiddlerInstalledRepository(); $this->resolvePackageDependencies($localRepo, $packages, $packageName); $composerConfig = new Config(true, $rootDirectory); $composerConfig->merge(array('config' => array('vendor-dir' => $config['path'] . '/vendor'))); $generator->dump($composerConfig, $localRepo, $mainPackage, $installationManager, 'composer', $optimize); $binDir = $config['path'] . '/vendor/bin'; // remove old symlinks array_map('unlink', glob($binDir . '/*')); foreach ($localRepo->getPackages() as $package) { foreach ($package->getBinaries() as $binary) { if (!is_dir($binDir)) { mkdir($binDir, 0755, true); } $binFile = $binDir . '/' . basename($binary); symlink($rootDirectory . '/' . $binary, $binFile); } } } }
/** * Retrieves the given package's vendor directory, where it's installed. * * @param array $package * The package to retrieve the vendor directory for. * @return string */ public function getVendorDir(array $package) { // The root package vendor directory is not handled by getInstallPath(). if (isset($package['is-root']) && $package['is-root'] === true) { $path = getcwd(); if (!file_exists($path . DIRECTORY_SEPARATOR . 'composer.json')) { for ($temp = __DIR__; strlen($temp) > 3; $temp = dirname($temp)) { if (file_exists($temp . DIRECTORY_SEPARATOR . 'composer.json')) { $path = $temp; } } } return $path; } if (!isset($package['version'])) { $package['version'] = '1.0.0'; } $loader = new ArrayLoader(); $completePackage = $loader->load($package); return $this->installationManager->getInstallPath($completePackage); }
/** * Disables custom installers. * * Call this if you want to ensure that third-party code never gets * executed. The default is to automatically install, and execute * custom third-party installers. * * @return Installer */ public function disableCustomInstallers() { $this->installationManager->disableCustomInstallers(); return $this; }
/** * Disables plugins. * * Call this if you want to ensure that third-party code never gets * executed. The default is to automatically install, and execute * custom third-party installers. * * @return Installer */ public function disablePlugins() { $this->installationManager->disablePlugins(); return $this; }
/** * @param WritableRepositoryInterface $repo repository to purge packages from * @param Installer\InstallationManager $im manager to check whether packages are still installed */ protected function purgePackages(WritableRepositoryInterface $repo, Installer\InstallationManager $im) { foreach ($repo->getPackages() as $package) { if (!$im->isPackageInstalled($repo, $package)) { $repo->removePackage($package); } } }
public function buildPackageMap(InstallationManager $installationManager, PackageInterface $mainPackage, array $packages) { // build package => install path map $packageMap = array(); array_unshift($packages, $mainPackage); foreach ($packages as $package) { if ($package instanceof AliasPackage) { continue; } if ($package === $mainPackage) { $packageMap[] = array($mainPackage, ''); continue; } $packageMap[] = array($package, $installationManager->getInstallPath($package)); } return $packageMap; }
public function buildPackageMap(InstallationManager $installationManager, PackageInterface $mainPackage, array $packages) { // build package => install path map $packageMap = array(); $packages[] = $mainPackage; // sort packages by dependencies usort($packages, function (PackageInterface $a, PackageInterface $b) { foreach (array_merge($a->getRequires(), $a->getDevRequires()) as $link) { if (in_array($link->getTarget(), $b->getNames())) { return 1; } } foreach (array_merge($b->getRequires(), $b->getDevRequires()) as $link) { if (in_array($link->getTarget(), $a->getNames())) { return -1; } } return strcmp($a->getName(), $b->getName()); }); foreach ($packages as $package) { if ($package instanceof AliasPackage) { continue; } if ($package === $mainPackage) { $packageMap[] = array($mainPackage, ''); continue; } $packageMap[] = array($package, $installationManager->getInstallPath($package)); } return $packageMap; }
protected function doInstall($localRepo, $installedRepo, $aliases, $devMode = false) { // creating repository pool $pool = new Pool(); $pool->addRepository($installedRepo); foreach ($this->repositoryManager->getRepositories() as $repository) { $pool->addRepository($repository); } // creating requirements request $installFromLock = false; $request = new Request($pool); if ($this->update) { $this->io->write('<info>Updating ' . ($devMode ? 'dev ' : '') . 'dependencies</info>'); $request->updateAll(); $links = $devMode ? $this->package->getDevRequires() : $this->package->getRequires(); foreach ($links as $link) { $request->install($link->getTarget(), $link->getConstraint()); } } elseif ($this->locker->isLocked($devMode)) { $installFromLock = true; $this->io->write('<info>Installing ' . ($devMode ? 'dev ' : '') . 'dependencies from lock file</info>'); if (!$this->locker->isFresh() && !$devMode) { $this->io->write('<warning>Your lock file is out of sync with your composer.json, run "composer.phar update" to update dependencies</warning>'); } foreach ($this->locker->getLockedPackages($devMode) as $package) { $version = $package->getVersion(); foreach ($aliases as $alias) { if ($alias['package'] === $package->getName() && $alias['version'] === $package->getVersion()) { $version = $alias['alias']; break; } } $constraint = new VersionConstraint('=', $version); $request->install($package->getName(), $constraint); } } else { $this->io->write('<info>Installing ' . ($devMode ? 'dev ' : '') . 'dependencies</info>'); $links = $devMode ? $this->package->getDevRequires() : $this->package->getRequires(); foreach ($links as $link) { $request->install($link->getTarget(), $link->getConstraint()); } } // fix the version all installed packages that are not in the current local repo to prevent rogue updates foreach ($installedRepo->getPackages() as $package) { if ($package->getRepository() === $localRepo || $package->getRepository() instanceof PlatformRepository) { continue; } $constraint = new VersionConstraint('=', $package->getVersion()); $request->install($package->getName(), $constraint); } // prepare solver $policy = new DefaultPolicy(); $solver = new Solver($policy, $pool, $installedRepo); // solve dependencies try { $operations = $solver->solve($request); } catch (SolverProblemsException $e) { $this->io->write('<error>Your requirements could not be solved to an installable set of packages.</error>'); $this->io->write($e->getMessage()); return false; } // force dev packages to be updated if we update or install from a (potentially new) lock if ($this->update || $installFromLock) { foreach ($localRepo->getPackages() as $package) { // skip non-dev packages if (!$package->isDev()) { continue; } // skip packages that will be updated/uninstalled foreach ($operations as $operation) { if ('update' === $operation->getJobType() && $operation->getInitialPackage()->equals($package) || 'uninstall' === $operation->getJobType() && $operation->getPackage()->equals($package)) { continue 2; } } // force update to latest on update if ($this->update) { $newPackage = $this->repositoryManager->findPackage($package->getName(), $package->getVersion()); if ($newPackage && $newPackage->getSourceReference() !== $package->getSourceReference()) { $operations[] = new UpdateOperation($package, $newPackage); } } elseif ($installFromLock) { // force update to locked version if it does not match the installed version $lockData = $this->locker->getLockData(); unset($lockedReference); foreach ($lockData['packages'] as $lockedPackage) { if (!empty($lockedPackage['source-reference']) && strtolower($lockedPackage['package']) === $package->getName()) { $lockedReference = $lockedPackage['source-reference']; break; } } if (isset($lockedReference) && $lockedReference !== $package->getSourceReference()) { // changing the source ref to update to will be handled in the operations loop below $operations[] = new UpdateOperation($package, $package); } } } } // anti-alias local repository to allow updates to work fine foreach ($localRepo->getPackages() as $package) { if ($package instanceof AliasPackage) { $package->getRepository()->addPackage(clone $package->getAliasOf()); $package->getRepository()->removePackage($package); } } // execute operations if (!$operations) { $this->io->write('Nothing to install or update'); } foreach ($operations as $operation) { if ($this->verbose) { $this->io->write((string) $operation); } // collect suggestions if ('install' === $operation->getJobType()) { foreach ($operation->getPackage()->getSuggests() as $target => $reason) { $this->suggestedPackages[] = array('source' => $operation->getPackage()->getPrettyName(), 'target' => $target, 'reason' => $reason); } } if (!$this->dryRun) { $this->eventDispatcher->dispatchPackageEvent(constant('Composer\\Script\\ScriptEvents::PRE_PACKAGE_' . strtoupper($operation->getJobType())), $operation); // if installing from lock, restore dev packages' references to their locked state if ($installFromLock) { $package = null; if ('update' === $operation->getJobType()) { $package = $operation->getTargetPackage(); } elseif ('install' === $operation->getJobType()) { $package = $operation->getPackage(); } if ($package && $package->isDev()) { $lockData = $this->locker->getLockData(); foreach ($lockData['packages'] as $lockedPackage) { if (!empty($lockedPackage['source-reference']) && strtolower($lockedPackage['package']) === $package->getName()) { $package->setSourceReference($lockedPackage['source-reference']); break; } } } } $this->installationManager->execute($localRepo, $operation); $this->eventDispatcher->dispatchPackageEvent(constant('Composer\\Script\\ScriptEvents::POST_PACKAGE_' . strtoupper($operation->getJobType())), $operation); $localRepo->write(); } } // reload local repository for the dev pass to work ok with aliases since it was anti-aliased above if (!$devMode) { $localRepo->reload(); } return true; }
public function markAliasUninstalled(RepositoryInterface $repo, MarkAliasUninstalledOperation $operation) { $this->uninstalled[] = $operation->getPackage(); $this->trace[] = (string) $operation; parent::markAliasUninstalled($repo, $operation); }
public function buildPackageMap(InstallationManager $installationManager, PackageInterface $mainPackage, array $packages) { // build package => install path map $packageMap = array(); // add main package $packageMap[] = array($mainPackage, ''); foreach ($packages as $package) { $packageMap[] = array($package, $installationManager->getInstallPath($package)); } return $packageMap; }
/** * @param Repository\RepositoryManager $rm * @param Installer\InstallationManager $im */ protected function purgePackages(Repository\RepositoryManager $rm, Installer\InstallationManager $im) { $repo = $rm->getLocalRepository(); foreach ($repo->getPackages() as $package) { if (!$im->isPackageInstalled($repo, $package)) { $repo->removePackage($package); } } }
public function buildPackageMap(InstallationManager $installationManager, PackageInterface $mainPackage, array $packages) { // build package => install path map $packageMap = array(array($mainPackage, '')); foreach ($packages as $package) { if ($package instanceof AliasPackage) { continue; } $this->validatePackage($package); $packageMap[] = array($package, $installationManager->getInstallPath($package)); } return $packageMap; }
/** * Get the filter root constraint operator. * * @param PackageInterface $package * * @return string */ private function getFilterOperator(PackageInterface $package) { return $this->installationManager->isPackageInstalled($this->installedRepository, $package) ? '>' : '>='; }