public function resolveFeatureBranch(Event $event) { if (empty($this->featureBranchRepositories)) { $this->io->write('No feature branches configured, continuing!'); return; } $package = $this->composer->getPackage(); if ($package->isDev()) { $featureBranchConstraint = new Constraint('=', $this->versionParser->normalize($package->getVersion())); $featureBranchConstraint->setPrettyString($package->getVersion()); $requires = $package->getRequires(); $this->io->write(sprintf("<info>Checking for feature branch '%s'</info>", $featureBranchConstraint->getPrettyString())); foreach ($requires as $key => $require) { if ($this->hasFeatureBranch($require, $featureBranchConstraint)) { $requires[$key] = new Link($require->getSource(), $require->getTarget(), $featureBranchConstraint, 'requires', $featureBranchConstraint->getPrettyString()); } else { $fallbackBranch = $this->getFallbackBranch($require); if ($fallbackBranch !== false) { $fallbackConstraint = new Constraint('=', $this->versionParser->normalize($fallbackBranch)); $fallbackConstraint->setPrettyString($fallbackBranch); $requires[$key] = new Link($require->getSource(), $require->getTarget(), $fallbackConstraint, 'requires', $fallbackConstraint->getPrettyString()); } } $this->io->write(''); } $package->setRequires($requires); } }
public static function getPackageInstallPath(PackageInterface $package, Composer $composer) { $prettyName = $package->getPrettyName(); if (strpos($prettyName, '/') !== false) { list($vendor, $name) = explode('/', $prettyName); } else { $vendor = ''; $name = $prettyName; } $availableVars = compact('name', 'vendor'); $extra = $package->getExtra(); if (!empty($extra['installer-name'])) { $availableVars['name'] = $extra['installer-name']; } if ($composer->getPackage()) { $extra = $composer->getPackage()->getExtra(); if (!empty($extra['installer-paths'])) { $customPath = self::mapCustomInstallPaths($extra['installer-paths'], $prettyName); if (false !== $customPath) { return self::templatePath($customPath, $availableVars); } } } return NULL; }
public function onPostUpdate(Event $event) { $requires = []; $overrides = []; $resolutions = []; if ($event->isDevMode()) { $extra = $this->composer->getPackage()->getExtra(); $bower = isset($extra['bower']) ? $extra['bower'] : []; if (isset($bower['require-dev'])) { $requires = $this->_mergeDependencyVersions($requires, $bower['require-dev']); } } $packages = [$this->composer->getPackage()]; $packages = array_merge($packages, $this->composer->getRepositoryManager()->getLocalRepository()->getCanonicalPackages()); foreach ($packages as $package) { if ($package instanceof CompletePackage) { $extra = $package->getExtra(); $bower = isset($extra['bower']) ? $extra['bower'] : []; if (isset($bower['require'])) { $requires = $this->_mergeDependencyVersions($requires, $bower['require']); } if (isset($bower['overrides'])) { $overrides = array_merge_recursive($overrides, $bower['overrides']); } if (isset($bower['resolutions'])) { $resolutions = $bower['resolutions']; } } } if (!$requires) { $this->info("No Bower packages are required by the application or by any installed Composer package"); } $dependencies = $this->_installBower($requires, $overrides, $resolutions); $this->info((count($dependencies) ?: "No") . " bower packages are installed"); }
public static function getConsoleCommands(Composer $composer) { $commands = array(array('yiic', 'migrate')); if ($composer->getPackage()) { $extra = $composer->getPackage()->getExtra(); if (!empty($extra['yiicomposer-console-commands'])) { $tmp = $extra['yiicomposer-console-commands']; } if (!empty($tmp)) { $commands = array(); foreach ($tmp as $c) { $command = array(); $command[] = 'yiic'; $command[] = $c['controller']; if (!empty($c['action'])) { $command[] = $c['action']; } if (!empty($c['params'])) { $command = array_merge($command, $c['params']); } if (!empty($c['params'])) { foreach ($c['params'] as $k => $v) { $command[] = '--' . $k . '=' . $v; } } $commands[] = $command; } } } return $commands; }
public function __construct(PackageInterface $package = null, Composer $composer = null, IOInterface $io = null) { if (null === $package) { $package = $composer->getPackage(); } $extraOxidRoot = $extraModuleVendor = false; if (null !== $package) { $extra = $package->getExtra(); if (isset($extra['oxid-root'])) { foreach ($this->locations as $name => $location) { $this->locations[$name] = "{$extra['oxid-root']}/{$location}"; } $extraOxidRoot = true; } if (isset($extra['module-vendor'])) { $this->locations['module'] = str_replace('modules/', "modules/{$extra['module-vendor']}/", $this->locations['module']); $extraModuleVendor = true; } } $composerPackage = $composer->getPackage(); if (null !== $composerPackage) { $extra = $composerPackage->getExtra(); if (isset($extra['oxid-root']) && !$extraOxidRoot) { foreach ($this->locations as $name => $location) { $this->locations[$name] = "{$extra['oxid-root']}/{$location}"; } } if (isset($extra['module-vendor']) && !$extraModuleVendor) { $this->locations['module'] = str_replace('modules/', "modules/{$extra['module-vendor']}/", $this->locations['module']); } } parent::__construct($package, $composer, $io); }
public function activate(Composer $composer, IOInterface $io) { $config = json_decode(file_get_contents(getcwd() . '/composer.json'), true); if (!in_array('--no-dev', $_SERVER['argv']) && isset($config['scripts-dev'])) { $scripts = array_merge_recursive($composer->getPackage()->getScripts(), $config['scripts-dev']); $composer->getPackage()->setScripts($scripts); } }
public function dumpFiles() { $extraConfig = $this->composer->getPackage()->getExtra(); if (!array_key_exists('include_files', $extraConfig) || !is_array($extraConfig['include_files'])) { return; } $this->generator->dumpFiles($this->composer, $extraConfig['include_files']); }
public function activate(Composer $composer, IOInterface $io) { $this->composer = $composer; $this->io = $io; $extra = $this->composer->getPackage()->getExtra(); if (isset($extra['composer-constant-prefix'])) { $this->constantPrefix = $extra['composer-constant-prefix']; } }
protected function runWith($expected, $extra) { $mapSources = new \ReflectionMethod($this->installerStub, 'getSourcesSpec'); $mapSources->setAccessible(true); /** @var RootPackage $package */ $package = clone $this->composer->getPackage(); $package->setExtra($extra); $this->assertEquals($expected, $mapSources->invokeArgs($this->installerStub, array($package))); }
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(); }
public function runGruntTasks(Composer $composer, $isDevMode = null) { $isDevMode = (bool) $isDevMode; $this->io()->write('<info>Running Grunt tasks for root project</info>'); if ($this->isDependantPackage($composer->getPackage(), $isDevMode)) { $this->client()->runTask($this->getTask($composer->getPackage())); } else { $this->io()->write('Nothing to grunt'); } $this->installForVendors($composer); }
public static function getYiiPaths(Composer $composer) { $yiiPaths = array('module' => '{vendor}' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . '{name}', 'extension' => '{vendor}' . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . '{name}', 'framework' => '{vendor}' . DIRECTORY_SEPARATOR . 'framework', 'yiisoft/yii' => '$framework$'); if ($composer->getPackage()) { $extra = $composer->getPackage()->getExtra(); if (!empty($extra['yiicomposer-paths'])) { $yiiPaths = array_merge($yiiPaths, $extra['yiicomposer-paths']); } } return $yiiPaths; }
public function start(Event $e) { $package = $this->composer->getPackage(); $fetches = array_merge($this->getFetchesInExtra($package, self::EXTRA_KEY), $this->findFetchesInRequire($package)); $this->baseDir = $this->determineBaseDir($fetches, self::DEFAULT_BASE_DIR); $this->targets = $this->processFetches($package, $fetches); if ($e->isDevMode()) { $devFetches = array_merge($this->getFetchesInExtra($package, self::EXTRA_KEY_DEV), $this->findFetchesInRequireDev($package)); $this->baseDirDev = $this->determineBaseDir($devFetches, self::DEFAULT_BASE_DIR_DEV); $this->targetsDev = $this->processFetches($package, $devFetches); } }
/** * {@inheritdoc} * * @throws \InvalidArgumentException * @throws \RuntimeException */ public function activate(Composer $composer, IOInterface $io) { $this->composer = $composer; $this->io = $io; $this->config = $config = new Config\PluginConfig((array) $composer->getConfig()->get(self::CONFIG_KEY)); $this->cleaner = $config->isDebug() ? new FakeCleaner($io) : $config->getCleaner(); $this->matcher = $config->getMatcher(); $this->normalizer = $config->getNormalizer(); if (($extra = $this->composer->getPackage()->getExtra()) && isset($extra[self::EXTRA_KEY])) { $this->devFiles = $this->normalizer->normalize((array) $extra[self::EXTRA_KEY]); } }
public function onPostUpdate(Event $event) { // Load global plugin configuration $globalCfg = $this->getGlobalConfig(); if ($globalCfg) { $extra = self::get($globalCfg, 'extra', []); $myConfig = self::get($extra, self::EXTRA_KEY, []); if ($myConfig) { $this->info("Global configuration loaded"); } } else { $myConfig = []; } // Merge project-specific configuration. // Ignore it if Composer is running in global mode. $package = $this->composer->getPackage(); if ($package->getName() != '__root__') { $projCfg = self::get($package->getExtra(), self::EXTRA_KEY, []); $myConfig = array_merge_recursive($myConfig, $projCfg); $this->info("Project-specific configuration loaded"); } // Setup $rules = array_unique(self::get($myConfig, self::RULES_KEY, [])); $sharedDir = str_replace('~', getenv('HOME'), self::get($myConfig, self::SHARED_DIR_KEY, self::DEFAULT_SHARED_DIR)); $packages = $this->composer->getRepositoryManager()->getLocalRepository()->getCanonicalPackages(); $rulesInfo = implode(', ', $rules); $this->info("Shared directory: <info>{$sharedDir}</info>"); $this->info("Match packages: <info>{$rulesInfo}</info>"); $fsUtil = new FilesystemUtil(); $fs = new Filesystem(); // Do useful work $count = 0; foreach ($packages as $package) { $srcDir = $this->getInstallPath($package); $packageName = $package->getName(); if (self::globMatchAny($rules, $packageName) && !$fsUtil->isSymlinkedDirectory($srcDir)) { $destPath = "{$sharedDir}/{$packageName}"; if (!file_exists($destPath)) { $fsUtil->copyThenRemove($srcDir, $destPath); $this->info("Moved <info>{$packageName}</info> to shared directory and symlinked to it"); } else { $fs->remove($srcDir); $this->info("Symlinked to existing <info>{$packageName}</info> on shared directory"); } $fs->symlink($destPath, $srcDir); ++$count; } } if (!$count) { $this->info("No packages matched"); } }
/** * @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!'); }
/** * Apply plugin modifications to Composer * * @param Composer $composer * @param IOInterface $io */ public function activate(Composer $composer, IOInterface $io) { $this->io = $io; $this->composer = $composer; $rootDir = realpath($this->composer->getConfig()->get('vendor-dir') . '/../'); $settings = $this->composer->getPackage()->getExtra()['application'] ?? []; $this->appInfo = new AppInfo($rootDir, $settings); $this->componentInstaller = new ComponentInstaller($this->appInfo, $io, $composer); $this->assetsInstaller = new AssetsInstaller($this->appInfo, $io, $composer); $manager = $this->composer->getInstallationManager(); $manager->addInstaller($this->componentInstaller); $manager->addInstaller($this->assetsInstaller); }
/** * @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); }
/** * Override the default patch dir from composer.json or env if needed. */ public function configure() { // Set the patch dir from 'extra' if present. $extra = $this->composer->getPackage()->getExtra(); if (isset($extra['marketo_patch_dir'])) { $this->patchDir = $extra['marketo_patch_dir']; } // Set the patch dir from the environment if present. if (getenv('marketo_patch_dir') !== FALSE) { $this->patchDir = $extra['marketo_patch_dir']; } // Expand the path. $this->patchDir = getcwd() . DIRECTORY_SEPARATOR . $this->patchDir; }
/** * Returns the installation path which is defined in the root package. * * Returns null if the root package does not define a path for the * provided package. * * @param PackageInterface $package * @return string|null */ protected function getInstallPathFromRoot(PackageInterface $package) { $rootPackageConfig = $this->composer->getPackage()->getExtra(); if (isset($rootPackageConfig['installation-paths'][$package->getPrettyName()])) { return $rootPackageConfig['installation-paths'][$package->getPrettyName()]; } // The attribute "installer-paths" is checked to guarantee backwards compatibility // with version 0.1.1. if (isset($rootPackageConfig['installer-paths'][$package->getPrettyName()])) { return $rootPackageConfig['installer-paths'][$package->getPrettyName()]; } // No path defined in the root package. return null; }
/** * Search config in the local root package. * * @param string $key * * @return bool */ private function locateLocal($key) { $composerConfig = $this->composer->getConfig(); // Sorry for this, I couldn't find any way to get the path of the current root package $reflection = new \ReflectionClass($composerConfig); $property = $reflection->getProperty('baseDir'); $property->setAccessible(true); $path = $property->getValue($composerConfig); $localComposerExtra = $this->composer->getPackage()->getExtra(); if (array_key_exists($key, $localComposerExtra)) { $this->cache[$key] = ['found' => true, 'config' => $localComposerExtra[$key], 'path' => $path]; return true; } return false; }
/** * 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) { /* @var InstalledFilesystemRepository $installedRepository */ $installedRepository = $composer->getRepositoryManager()->getLocalRepository(); $this->composer = $composer; $this->io = $io; $this->packageFilter = new VcsPackageFilter($composer->getPackage(), $composer->getInstallationManager(), $installedRepository); $extra = $composer->getPackage()->getExtra(); $rm = $composer->getRepositoryManager(); AssetPlugin::addRegistryRepositories($rm, $this->packageFilter, $extra); AssetPlugin::setVcsTypeRepositories($rm); if (isset($extra['asset-repositories']) && is_array($extra['asset-repositories'])) { $this->addRepositories($rm, $extra['asset-repositories']); } AssetPlugin::addInstallers($composer, $io); }
/** * @inheritdoc */ public function activate(Composer $composer, IOInterface $io) { $this->io = $io; //Extend download manager $dm = $composer->getDownloadManager(); $executor = new ProcessExecutor($io); $fs = new Filesystem($executor); $config = $composer->getConfig(); $dm->setDownloader('svn-export', new Downloader($io, $config, $executor, $fs)); //Extend RepositoryManager Classes $rm = $composer->getRepositoryManager(); $rm->setRepositoryClass('svn-export', 'LinearSoft\\Composer\\SvnExport\\Repository\\VcsRepository'); $rm->setRepositoryClass('svn-export-composer', 'LinearSoft\\Composer\\SvnExport\\Repository\\ComposerRepository'); //Load Extra Data $extra = $composer->getPackage()->getExtra(); if (isset($extra['svn-export-repositories']) && is_array($extra['svn-export-repositories'])) { foreach ($extra['svn-export-repositories'] as $index => $repoConfig) { $this->validateRepositories($index, $repoConfig); if (isset($repoConfig['name'])) { $name = $repoConfig['name']; } else { $name = is_int($index) ? preg_replace('{^https?://}i', '', $repoConfig['url']) : $index; } if ($repoConfig['type'] === 'svn') { $repoConfig['type'] = 'svn-export'; } else { $repoConfig['type'] = 'svn-export-composer'; } $repo = $rm->createRepository($repoConfig['type'], $repoConfig); $rm->addRepository($repo); $this->io->write("Added SvnExport repo: {$name}"); } } }
/** * Check that the root composer.json file use the post-autoload-dump hook * * If not, warn the user they need to update their application's composer file. * Do nothing if the main project is not a project (if it's a plugin in development). * * @param Composer $composer object * @return void */ public function checkUsage(Composer $composer) { if (static::$checkUsage === false) { return; } static::$checkUsage = false; $package = $composer->getPackage(); if (!$package || $package->getType() !== 'project') { return; } $scripts = $composer->getPackage()->getScripts(); $postAutoloadDump = 'Cake\\Composer\\Installer\\PluginInstaller::postAutoloadDump'; if (!isset($scripts['post-autoload-dump']) || !in_array($postAutoloadDump, $scripts['post-autoload-dump'])) { $this->warnUser('Action required!', 'The CakePHP plugin installer has been changed, please update your' . ' application composer.json file to add the post-autoload-dump hook.' . ' See the changes in https://github.com/cakephp/app/pull/216 for more' . ' info.'); } }
/** * Returns the PhantomJS version number. * * Firstly, we search for a version number in the local repository, * secondly, in the root package. * A version specification of "dev-master#<commit-reference>" is disallowed. * * @param Composer $composer * @return string $version Version */ public static function getVersion($composer) { $packages = $composer->getRepositoryManager()->getLocalRepository()->getCanonicalPackages(); $os = self::getOS(); foreach ($packages as $package) { if ($package->getName() === 'triplekdev/phantomjs-installer') { $version = $package->getPrettyVersion(); } } // version was not found in the local repository, let's take a look at the root package if ($version == null) { $version = self::getRequiredVersion($composer->getPackage(), 'triplekdev/phantomjs-installer'); } // fallback to a hardcoded version number, if "dev-master" was set if ($version === 'dev-master') { return $os === 'macosx' ? '2.0.1' : '1.9.8'; } // grab version from commit-reference, e.g. "dev-master#<commit-ref> as version" if (preg_match('/dev-master#(?:.*)(\\d.\\d.\\d)/i', $version, $matches)) { return $matches[1]; } // grab version from a git version tag with a patch level, like "1.9.8-2" if (preg_match('/(\\d.\\d.\\d)(?:(?:-\\d)?)/i', $version, $matches)) { return $matches[1]; } // grab version from a Composer patch version tag with a patch level, like "1.9.8-p02" if (preg_match('/(\\d.\\d.\\d)(?:(?:-p\\d{2})?)/i', $version, $matches)) { return $matches[1]; } return $version; }
/** * @param Composer $composer * @param IOInterface $io */ public function activate(Composer $composer, IOInterface $io) { $repositoryManager = $composer->getRepositoryManager(); $extra = $composer->getPackage()->getExtra(); if (!isset($extra['connect-packages'])) { return; } $versionParser = new VersionParser(); $links = []; foreach ($extra['connect-packages'] as $connectPackage => $version) { try { $releases = $this->getVersionsForPackage($connectPackage); } catch (InvalidArgumentException $e) { $message = '<error>Could not find release manifest for module with extension key: "%s". '; $message .= 'Did you get the casing right? Error: "%s"</error>'; $io->writeError(sprintf($message, $connectPackage, $e->getMessage()), true); continue; } catch (UnexpectedValueException $e) { $message = '<error>Non valid XML return from connect for module with extension key: "%s".</error>'; $message .= $e->getMessage(); $io->writeError(sprintf($message, $connectPackage), true); continue; } $repository = $this->addPackages($releases, $connectPackage); $repositoryManager->addRepository($repository); $constraint = $versionParser->parseConstraints($version); $links[] = new Link($composer->getPackage()->getName(), $connectPackage, $constraint); } if (!empty($links)) { $requires = $composer->getPackage()->getRequires(); $requires = array_merge($requires, $links); $composer->getPackage()->setRequires($requires); } }
public function testSetGetPackage() { $composer = new Composer(); $package = $this->getMock('Composer\\Package\\RootPackageInterface'); $composer->setPackage($package); $this->assertSame($package, $composer->getPackage()); }
/** * Find configuration files matching the configured glob patterns and * merge their contents with the master package. * * @param array $config */ protected function mergePackages(array $config) { $root = $this->composer->getPackage(); foreach (array_reduce(array_map('glob', $config['include']), 'array_merge', array()) as $path) { $this->loadFile($root, $path); } }
private function adoptComposerName(array $puliPackages) { $rootDir = $this->rootDir; /** @var PuliPackage[] $rootPackages */ $rootPackages = array_filter($puliPackages, function (PuliPackage $package) use($rootDir) { return !$package->getInstallerName() && $rootDir === $package->getInstallPath(); }); if (0 === count($rootPackages)) { // This should never happen $this->printWarning('No root package could be found'); return; } if (count($rootPackages) > 1) { // This should never happen $this->printWarning('More than one root package was found'); return; } /** @var PuliPackage $rootPackage */ $rootPackage = reset($rootPackages); $name = $rootPackage->getName(); $newName = $this->composer->getPackage()->getName(); // Rename the root package after changing the name in composer.json if ($name !== $newName) { try { $this->renamePackage($name, $newName); } catch (PuliRunnerException $e) { $this->printWarning(sprintf('Could not rename root package to "%s"', $newName), $e); } } }