/** * {@inheritdoc} */ public function __construct(Composer $composer = null, IOInterface $io = null) { $this->composer = isset($composer) ? $composer : new Composer(); $this->io = isset($io) ? $io : new NullIO(); $this->fs = new Filesystem(); $this->installationManager = $this->composer->getInstallationManager(); }
/** * @param PackageEvent $event */ public function __invoke(PackageEvent $event) { $publicPath = sprintf('%s/public', $this->projectPath); if (!is_dir($publicPath)) { // No public path in the project; nothing to remove return; } $gitignoreFile = sprintf('%s/.gitignore', $publicPath); if (!file_exists($gitignoreFile)) { // No .gitignore rules; nothing to remove return; } $package = $event->getOperation()->getPackage(); $installer = $this->composer->getInstallationManager(); $packagePath = $installer->getInstallPath($package); $packageConfigPath = sprintf('%s/config/module.config.php', $packagePath); if (!file_exists($packageConfigPath)) { // No module configuration defined; nothing to remove return; } $packageConfig = (include $packageConfigPath); if (!is_array($packageConfig) || !isset($packageConfig['asset_manager']['resolver_configs']['paths']) || !is_array($packageConfig['asset_manager']['resolver_configs']['paths'])) { // No assets defined; nothing to remove return; } $this->gitignore = $this->fetchIgnoreRules($gitignoreFile); $paths = $packageConfig['asset_manager']['resolver_configs']['paths']; foreach ($paths as $path) { $this->removeAssets($path, $publicPath); } file_put_contents($gitignoreFile, implode("\n", $this->gitignore)); }
public function activate(Composer $composer, IOInterface $io) { // Add the Innomatic legacy platform installer $composer->getInstallationManager()->addInstaller(new LegacyPlatformInstaller($io, $composer)); // Add the Innomatic legacy application installer $composer->getInstallationManager()->addInstaller(new LegacyApplicationInstaller($io, $composer)); }
/** * Before running composer install, * @param Event $event */ public function checkPatches(Event $event) { try { $repositoryManager = $this->composer->getRepositoryManager(); $localRepository = $repositoryManager->getLocalRepository(); $installationManager = $this->composer->getInstallationManager(); $packages = $localRepository->getPackages(); $tmp_patches = $this->grabPatches(); if ($tmp_patches == FALSE) { $this->io->write('<info>No patches supplied.</info>'); return; } foreach ($packages as $package) { $extra = $package->getExtra(); $patches = isset($extra['patches']) ? $extra['patches'] : array(); $tmp_patches = array_merge_recursive($tmp_patches, $patches); } // Remove packages for which the patch set has changed. foreach ($packages as $package) { if (!$package instanceof AliasPackage) { $package_name = $package->getName(); $extra = $package->getExtra(); $has_patches = isset($tmp_patches[$package_name]); $has_applied_patches = isset($extra['patches_applied']); if ($has_patches && !$has_applied_patches || !$has_patches && $has_applied_patches || $has_patches && $has_applied_patches && $tmp_patches[$package_name] !== $extra['patches_applied']) { $uninstallOperation = new UninstallOperation($package, 'Removing package so it can be re-installed and re-patched.'); $this->io->write('<info>Removing package ' . $package_name . ' so that it can be re-installed and re-patched.</info>'); $installationManager->uninstall($localRepository, $uninstallOperation); } } } } catch (\LogicException $e) { return; } }
public function testActivateAddsInstallerSuccessfully() { $plugin = new Plugin(); $plugin->activate($this->composer, $this->io); $installer = $this->composer->getInstallationManager()->getInstaller('git-hook'); // Ensure the installer was added. $this->assertInstanceOf('BernardoSilva\\GitHooksInstallerPlugin\\Composer\\Installer', $installer); }
/** * Apply plugin modifications to composer * * @param \Composer\Composer $composer * @param \Composer\IO\IOInterface $io */ public function activate(\Composer\Composer $composer, \Composer\IO\IOInterface $io) { $core_installer_v7 = new FrameworkInstaller($io, $composer); $composer->getInstallationManager()->addInstaller($core_installer_v7); $core_installer_v8 = new FrameworkInstallerV8($io, $composer); $composer->getInstallationManager()->addInstaller($core_installer_v8); $module_installer = new ModuleInstallerV7($io, $composer); $composer->getInstallationManager()->addInstaller($module_installer); }
/** * {@inheritdoc} */ public function __construct(Composer $composer = null, IOInterface $io = null) { $this->composer = isset($composer) ? $composer : new Composer(); $this->io = isset($io) ? $io : new NullIO(); $this->fs = new Filesystem(); $this->installationManager = $this->composer->getInstallationManager(); // TODO: Break compatibility and expect in interface $args = func_get_args(); $this->options = count($args) > 2 && is_array($args[2]) ? $args[2] : array(); }
private function registerLoader() { $package = $this->composer->getPackage(); $generator = $this->composer->getAutoloadGenerator(); $packages = $this->composer->getRepositoryManager()->getLocalRepository()->getCanonicalPackages(); $packageMap = $generator->buildPackageMap($this->composer->getInstallationManager(), $package, $packages); $map = $generator->parseAutoloads($packageMap, $package); $this->loader = $generator->createLoader($map); $this->loader->register(); }
/** * Retrieve install paths from package installers. * * @param \Composer\Package\PackageInterface[] $packages * * @return string[] */ protected function getInstallPathsFromPackages(array $packages) { /** @var \Composer\Installer\InstallationManager $installationManager */ $installationManager = $this->composer->getInstallationManager(); $paths = array(); foreach ($packages as $package) { $paths[] = $installationManager->getInstallPath($package); } return $this->absolutePaths($paths); }
public function setUp() { $this->projectRoot = vfsStream::setup('project'); $this->installer = new ComponentInstaller(vfsStream::url('project')); $this->composer = $this->prophesize(Composer::class); $this->io = $this->prophesize(IOInterface::class); $this->installer->activate($this->composer->reveal(), $this->io->reveal()); $this->installationManager = $this->prophesize(InstallationManager::class); $this->composer->getInstallationManager()->willReturn($this->installationManager->reveal()); }
/** * {@inheritDoc} */ public function activate(Composer $composer, IOInterface $io) { $filesystem = new Filesystem(); $composer->getInstallationManager()->addInstaller(new CoreInstaller($composer, $filesystem, new CoreInstaller\GetTypo3OrgService($io))); $composer->getInstallationManager()->addInstaller(new ExtensionInstaller($composer, $filesystem)); $cache = null; if ($composer->getConfig()->get('cache-files-ttl') > 0) { $cache = new Cache($io, $composer->getConfig()->get('cache-files-dir'), 'a-z0-9_./'); } $composer->getDownloadManager()->setDownloader('t3x', new Downloader\T3xDownloader($io, $composer->getConfig(), null, $cache)); }
/** * This method tries the find the BundleFile in the root of * the given package. At this moment we don't support bundles * that don't have the Bundle file in the package root. */ protected function findBundleFiles(PackageInterface $package) { $installPath = $this->composer->getInstallationManager()->getInstallPath($package); $autoload = $package->getAutoload(); if (isset($autoload['psr-0'])) { $installPath .= '/' . current($autoload['psr-0']); } if (isset($autoload['psr-4'])) { $installPath .= '/' . current($autoload['psr-4']); } return glob(rtrim($installPath, '/') . '/*Bundle.php'); }
/** * @param bool $optimize * @param bool $reload */ protected function dumpAutoloads($optimize = true, $reload = false) { if ($reload) { $this->composer = Factory::create($this->io, null, $this->disablePluginsByDefault); } $config = $this->composer->getConfig(); $generator = $this->composer->getAutoloadGenerator(); $installationManager = $this->composer->getInstallationManager(); $localRepository = $this->composer->getRepositoryManager()->getLocalRepository(); $package = $this->composer->getPackage(); $generator->dump($config, $localRepository, $package, $installationManager, 'composer', $optimize); $this->info('Composer DumpAutoloads Completed!'); }
/** * @param string $baseDir Root directory of composer package. */ public function __construct($baseDir) { $this->baseDir = $baseDir; $io = new NullIO(); $this->composer = (new Factory())->createComposer($io, $baseDir . '/composer.json', true, $baseDir, false); $generator = new AutoloadGenerator($this->composer->getEventDispatcher(), $io); $generator->setDevMode(true); $packages = $this->composer->getRepositoryManager()->getLocalRepository()->getPackages(); $packageMap = $generator->buildPackageMap($this->composer->getInstallationManager(), $this->composer->getPackage(), $packages); $packageMap[0][1] = $baseDir; // To make root package paths absolute too. $autoloads = $generator->parseAutoloads($packageMap, $this->composer->getPackage()); $this->classLoader = $generator->createLoader($autoloads); }
/** * Before running composer install, * @param Event $event */ public function checkPatches(Event $event) { try { $repositoryManager = $this->composer->getRepositoryManager(); $localRepository = $repositoryManager->getLocalRepository(); $installationManager = $this->composer->getInstallationManager(); $packages = $localRepository->getPackages(); $tmp_patches = array(); // First, try to get the patches from the root composer.json. $extra = $this->composer->getPackage()->getExtra(); if (isset($extra['patches'])) { $this->io->write('<info>Gathering patches for root package.</info>'); $tmp_patches = $extra['patches']; } else { if (isset($extra['patches-file'])) { $this->io->write('<info>Gathering patches from patch file.</info>'); $patches = file_get_contents($extra['patches-file']); $patches = json_decode($patches, TRUE); if (isset($patches['patches'])) { $tmp_patches = $patches['patches']; } } else { // @todo: should we throw an exception here? return; } } foreach ($packages as $package) { $extra = $package->getExtra(); $patches = isset($extra['patches']) ? $extra['patches'] : array(); $tmp_patches = array_merge_recursive($tmp_patches, $patches); } // Remove packages for which the patch set has changed. foreach ($packages as $package) { if (!$package instanceof AliasPackage) { $package_name = $package->getName(); $extra = $package->getExtra(); $has_patches = isset($tmp_patches[$package_name]); $has_applied_patches = isset($extra['patches_applied']); if ($has_patches && !$has_applied_patches || !$has_patches && $has_applied_patches || $has_patches && $has_applied_patches && $tmp_patches[$package_name] !== $extra['patches_applied']) { $uninstallOperation = new UninstallOperation($package, 'Removing package so it can be re-installed and re-patched.'); $this->io->write('<info>Removing package ' . $package_name . ' so that it can be re-installed and re-patched.</info>'); $installationManager->uninstall($localRepository, $uninstallOperation); } } } } catch (\LogicException $e) { return; } }
/** * Get an array of packages that depend on the target package * * @param bool $isDevMode * @return PackageWrapper[] */ public function getDependentPackages($isDevMode) { $packages = []; $rootPackage = $this->composer->getPackage(); if ($this->isDependentPackage($rootPackage, (bool) $isDevMode)) { $packages[] = new PackageWrapper($rootPackage, getcwd()); } $manager = $this->composer->getInstallationManager(); foreach ($this->composer->getRepositoryManager()->getLocalRepository()->getPackages() as $package) { if ($this->isDependentPackage($package, $isDevMode)) { $packages[] = new PackageWrapper($package, $manager->getInstallPath($package)); } } return $packages; }
/** * {@inheritDoc} */ public function activate(Composer $composer, IOInterface $io) { $pluginInstaller = new PluginInstaller($io, $composer); $composer->getInstallationManager()->addInstaller($pluginInstaller); //$themeInstaller = new ThemeInstaller($io, $composer); //$composer->getInstallationManager()->addInstaller($themeInstaller); }
/** * Helper to get the drush directory. * * @return string * The absolute path for the drush directory. */ public function getDrushDir() { $package = $this->getPackage('drush/drush'); if ($package) { return $this->composer->getInstallationManager()->getInstallPath($package); } }
/** * {@inheritdoc} */ public function activate(Composer $composer, IOInterface $io) { foreach (static::$types as $type) { $installer = new WordpressInstaller($io, $composer, $type); $composer->getInstallationManager()->addInstaller($installer); } }
/** * @param \Composer\Composer * @param string * @param string */ public function dumpFiles(Composer $composer, $paths, $targetDir = 'composer') { $installationManager = $composer->getInstallationManager(); $localRepo = $composer->getRepositoryManager()->getLocalRepository(); $mainPackage = $composer->getPackage(); $config = $composer->getConfig(); $filesystem = new Filesystem(); $basePath = $filesystem->normalizePath(realpath(getcwd())); $vendorPath = $filesystem->normalizePath(realpath($config->get('vendor-dir'))); $targetDir = $vendorPath . '/' . $targetDir; $vendorPathCode = $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true); $vendorPathCode52 = str_replace('__DIR__', 'dirname(__FILE__)', $vendorPathCode); $appBaseDirCode = $filesystem->findShortestPathCode($vendorPath, $basePath, true); $appBaseDirCode = str_replace('__DIR__', '$vendorDir', $appBaseDirCode); $packageMap = $this->buildPackageMap($installationManager, $mainPackage, $localRepo->getCanonicalPackages()); $autoloads = $this->parseAutoloads($packageMap, $mainPackage); $paths = $this->parseAutoloadsTypeFiles($paths, $mainPackage); $autoloads['files'] = array_merge($paths, $autoloads['files']); $includeFilesFilePath = $targetDir . '/autoload_files.php'; if ($includeFilesFileContents = $this->getIncludeFilesFile($autoloads['files'], $filesystem, $basePath, $vendorPath, $vendorPathCode52, $appBaseDirCode)) { file_put_contents($includeFilesFilePath, $includeFilesFileContents); } elseif (file_exists($includeFilesFilePath)) { unlink($includeFilesFilePath); } }
/** * Activates plugin and registers installer. * * @param Composer $composer Composer instance. * @param IOInterface $ioc I/O controller * * @return void * @since 0.1.0 */ public function activate(Composer $composer, IOInterface $ioc) { $installer = new Installer($ioc, $composer); /** @type InstallationManager $manager */ $manager = $composer->getInstallationManager(); $manager->addInstaller($installer); }
/** * Apply plugin modifications to composer * TODO: If we get updated by composer there will be 2 instances afterwards. * The old as Xinc\Composer\Plugin and the new one as Xinc\Composer\Plugin_composer_tmp0 * So we activate 2 Installer. * * @param Composer $composer * @param IOInterface $io * @return void */ public function activate(Composer $composer, IOInterface $io) { // Register our own installer $composer->getInstallationManager()->addInstaller(new Installer($io, $composer)); $this->composer = $composer; $this->io = $io; }
/** * @param PackageInterface $package * @throws \Exception */ public function handlePackage(PackageInterface $package) { $packageExtra = $package->getExtra(); $devFiles = (array) $this->devFiles; if (isset($packageExtra[self::EXTRA_KEY])) { $devFiles = array_merge($devFiles, $this->normalizer->normalize((array) $packageExtra[self::EXTRA_KEY])); } if ($devFiles) { $matched = $this->matcher->match($package->getName(), array_keys($devFiles)); if (!$matched) { return; } $this->io->write(sprintf('<info>Clearing the package %s...</info>', $package->getName()), true); try { $files = $this->cleaner->clear($this->composer->getInstallationManager()->getInstallPath($package), array_filter($devFiles, function ($key) use($matched) { return in_array($key, $matched, true); }, ARRAY_FILTER_USE_KEY)); if (!$this->isDebug()) { foreach ($files as $file) { $this->io->write(sprintf('<info>-- removed: %s</info>', $file), true); } } } catch (\Exception $e) { // debug throw $e; } } }
public function testSetGetInstallationManager() { $composer = new Composer(); $manager = $this->getMock('Composer\\Installer\\InstallationManager'); $composer->setInstallationManager($manager); $this->assertSame($manager, $composer->getInstallationManager()); }
/** * @param array $packageNames * * @throws \RuntimeException */ public function uninstall(array $packageNames) { $this->logger->info('Uninstalling begin', $packageNames); array_map(function ($name) { if (!$this->canBeDeleted($name)) { $errorMessage = sprintf('Package %s is not deletable', $name); $this->logger->error($errorMessage); throw new \RuntimeException($errorMessage); } }, $packageNames); $this->maintenance->activate(); $this->removeFromComposerJson($packageNames); $installationManager = $this->composer->getInstallationManager(); $localRepository = $this->getLocalRepository(); $this->composer->getEventDispatcher()->dispatchCommandEvent('cache-clear', false); array_map(function ($name) use($installationManager, $localRepository) { $package = $this->findInstalledPackage($name); $this->scriptRunner->runUninstallScripts($package); $installationManager->uninstall($localRepository, new UninstallOperation($package)); }, $packageNames); $this->scriptRunner->removeCachedFiles(); $this->scriptRunner->clearApplicationCache(); $this->scriptRunner->runPlatformUpdate(); $this->scriptRunner->clearDistApplicationCache(); $this->logger->info('Packages uninstalled', $packageNames); }
/** * Just add the \ComposerSymlinker\LocalInstaller new installer * * @param \Composer\Composer $composer * @param \Composer\IO\IOInterface $io */ public function activate(Composer $composer, IOInterface $io) { if (!empty(getenv('DISABLE_SYMLINKER'))) { $io->write('Found DISABLE_SYMLINKER envvar, disabling symlinker...'); return; } $composer->getInstallationManager()->addInstaller(new LocalInstaller($io, $composer)); }
/** * Activate plugin * * @param Composer $composer * @param IOInterface $IOInterface */ public function activate(Composer $composer, IOInterface $io) { /** @var $installationManager InstallationManager */ $installationManager = $composer->getInstallationManager(); foreach ($this->installers as $class) { $installationManager->addInstaller($this->getInstaller($class, $composer, $io)); } }
public function testAssetInstallers() { $this->package->expects($this->any())->method('getExtra')->will($this->returnValue(array())); $this->plugin->activate($this->composer, $this->io); $im = $this->composer->getInstallationManager(); $this->assertInstanceOf('Fxp\\Composer\\AssetPlugin\\Installer\\BowerInstaller', $im->getInstaller('bower-asset-library')); $this->assertInstanceOf('Fxp\\Composer\\AssetPlugin\\Installer\\AssetInstaller', $im->getInstaller('npm-asset-library')); }
/** * @param Composer $composer * @param IOInterface $io */ public function activate(Composer $composer, IOInterface $io) { $root = $composer->getPackage(); $extra = $root->getExtra(); print_r($extra); // get root glue packages $composer->getInstallationManager()->addInstaller(new GluePluginInstaller($io, $composer)); }
protected static function getPackageLocation(Composer $composer, $name) { $packages = $composer->getRepositoryManager()->getLocalRepository()->findPackages($name); if (empty($packages)) { throw new \RuntimeException(sprintf('Unable to find package %s', $name)); } return $composer->getInstallationManager()->getInstallPath(reset($packages)); }