public static function formatVersion(PackageInterface $package, $truncate = true) { if (!$package->isDev() || !in_array($package->getSourceType(), array('hg', 'git'))) { return $package->getPrettyVersion(); } return $package->getPrettyVersion() . ' ' . ($truncate ? substr($package->getSourceReference(), 0, 6) : $package->getSourceReference()); }
public static function formatVersion(PackageInterface $package, $truncate = true) { if (!$package->isDev() || !in_array($package->getSourceType(), array('hg', 'git'))) { return $package->getPrettyVersion(); } // if source reference is a sha1 hash -- truncate if ($truncate && strlen($package->getSourceReference()) === 40) { return $package->getPrettyVersion() . ' ' . substr($package->getSourceReference(), 0, 7); } return $package->getPrettyVersion() . ' ' . $package->getSourceReference(); }
/** * Try to determine the build number from a composer package * * @param \Composer\Package\PackageInterface $package * * @return string */ public static function determineBuildNumberFromPackage(PackageInterface $package) { if ($package->isDev()) { $buildNumber = self::determineBuildNumberFromBrowscapBuildFile(); if (is_null($buildNumber)) { $buildNumber = substr($package->getSourceReference(), 0, 8); } } else { $installedVersion = $package->getPrettyVersion(); // SemVer supports build numbers, but fall back to just using // version number if not available; at time of writing, composer // did not support SemVer 2.0.0 build numbers fully: // @see https://github.com/composer/composer/issues/2422 $plusPos = strpos($installedVersion, '+'); if ($plusPos !== false) { $buildNumber = substr($installedVersion, $plusPos + 1); } else { $buildNumber = self::determineBuildNumberFromBrowscapBuildFile(); if (is_null($buildNumber)) { $buildNumber = $installedVersion; } } } return $buildNumber; }
public function doUpdate(PackageInterface $initial, PackageInterface $target, $path) { $this->cleanEnv(); $path = $this->normalizePath($path); if (!is_dir($path . '/.git')) { throw new \RuntimeException('The .git directory is missing from ' . $path . ', see http://getcomposer.org/commit-deps for more information'); } $ref = $target->getSourceReference(); $this->io->write(" Checking out " . $ref); $command = 'git remote set-url composer %s && git fetch composer && git fetch --tags composer'; $this->process->execute('git remote -v', $output, $path); if (preg_match('{^(?:composer|origin)\\s+https?://(.+):(.+)@([^/]+)}im', $output, $match)) { $this->io->setAuthentication($match[3], urldecode($match[1]), urldecode($match[2])); } $commandCallable = function ($url) use($command) { return sprintf($command, escapeshellarg($url)); }; $this->runCommand($commandCallable, $target->getSourceUrl(), $path); if ($newRef = $this->updateToCommit($path, $ref, $target->getPrettyVersion(), $target->getReleaseDate())) { if ($target->getDistReference() === $target->getSourceReference()) { $target->setDistReference($newRef); } $target->setSourceReference($newRef); } }
/** * {@inheritDoc} */ public function doUpdate(PackageInterface $initial, PackageInterface $target, $path, $url) { GitUtil::cleanEnv(); if (!$this->hasMetadataRepository($path)) { throw new \RuntimeException('The .git directory is missing from ' . $path . ', see https://getcomposer.org/commit-deps for more information'); } $updateOriginUrl = false; if (0 === $this->process->execute('git remote -v', $output, $path) && preg_match('{^origin\\s+(?P<url>\\S+)}m', $output, $originMatch) && preg_match('{^composer\\s+(?P<url>\\S+)}m', $output, $composerMatch)) { if ($originMatch['url'] === $composerMatch['url'] && $composerMatch['url'] !== $target->getSourceUrl()) { $updateOriginUrl = true; } } $ref = $target->getSourceReference(); $this->io->writeError(" Checking out " . $ref); $command = 'git remote set-url composer %s && git fetch composer && git fetch --tags composer'; $commandCallable = function ($url) use($command) { return sprintf($command, ProcessExecutor::escape($url)); }; $this->gitUtil->runCommand($commandCallable, $url, $path); if ($newRef = $this->updateToCommit($path, $ref, $target->getPrettyVersion(), $target->getReleaseDate())) { if ($target->getDistReference() === $target->getSourceReference()) { $target->setDistReference($newRef); } $target->setSourceReference($newRef); } if ($updateOriginUrl) { $this->updateOriginUrl($path, $target->getSourceUrl()); } }
/** * {@inheritDoc} */ public function update(PackageInterface $initial, PackageInterface $target, $path) { if (!$target->getSourceReference()) { throw new \InvalidArgumentException('Package ' . $target->getPrettyName() . ' is missing reference information'); } $name = $target->getName(); if ($initial->getPrettyVersion() == $target->getPrettyVersion()) { $from = $initial->getSourceReference(); $to = $target->getSourceReference(); $name .= ' ' . $initial->getPrettyVersion(); } else { $from = $initial->getFullPrettyVersion(); $to = $target->getFullPrettyVersion(); } $this->io->writeError(" - Updating <info>" . $name . "</info> (<comment>" . $from . "</comment> => <comment>" . $to . "</comment>)"); $urls = $target->getSourceUrls(); while ($url = array_shift($urls)) { try { if (Filesystem::isLocalPath($url)) { $url = realpath($url); } $this->doUpdate($initial, $target, $path, $url); break; } catch (\Exception $e) { if ($this->io->isDebug()) { $this->io->writeError('Failed: [' . get_class($e) . '] ' . $e->getMessage()); } elseif (count($urls)) { $this->io->writeError(' Failed, trying the next URL'); } else { throw $e; } } } $this->io->writeError(''); }
/** * {@inheritDoc} */ public function remove(PackageInterface $package, $path) { $this->enforceCleanDirectory($path); $this->io->write(" - Removing <info>" . $package->getName() . "</info> (<comment>" . $package->getPrettyVersion() . "</comment>)"); if (!$this->filesystem->removeDirectory($path)) { throw new \RuntimeException('Could not completely delete ' . $path . ', aborting.'); } }
/** * Constructor. * * @param string $name * @param string $type * @param PackageInterface $package * @param Link $link * @param Dependency[]|false $children */ public function __construct($name, $type, PackageInterface $package, Link $link, $children) { $this->name = $name; $this->type = $type; $this->package = $package; $this->link = $link; $this->setChildren($children); $this->relationship = (new DependencyRelationship())->setSourceName($package->getPrettyName())->setSourceVersion($package->getPrettyVersion())->setTargetName($link->getTarget())->setTargetVersion($link->getPrettyConstraint())->setReason($link->getDescription()); }
/** * {@inheritDoc} */ public function update(PackageInterface $initial, PackageInterface $target, $path) { if (!$target->getSourceReference()) { throw new \InvalidArgumentException('Package ' . $target->getPrettyName() . ' is missing reference information'); } $this->io->write(" - Package <info>" . $target->getName() . "</info> (<comment>" . $target->getPrettyVersion() . "</comment>)"); $this->enforceCleanDirectory($path); $this->doUpdate($initial, $target, $path); $this->io->write(''); }
public function remove(PackageInterface $package, $path) { $this->io->write(" - Removing <info>" . $package->getName() . "</info> (<comment>" . $package->getPrettyVersion() . "</comment>)"); $this->cleanChanges($package, $path, false); if (!$this->filesystem->removeDirectory($path)) { if (!defined('PHP_WINDOWS_VERSION_BUILD') || usleep(250) && !$this->filesystem->removeDirectory($path)) { throw new \RuntimeException('Could not completely delete ' . $path . ', aborting.'); } } }
public function dump(PackageInterface $package) { $keys = array('binaries' => 'bin', 'type', 'extra', 'installationSource' => 'installation-source', 'autoload', 'notificationUrl' => 'notification-url', 'includePaths' => 'include-path'); $data = array(); $data['name'] = $package->getPrettyName(); $data['version'] = $package->getPrettyVersion(); $data['version_normalized'] = $package->getVersion(); if ($package->getTargetDir()) { $data['target-dir'] = $package->getTargetDir(); } if ($package->getSourceType()) { $data['source']['type'] = $package->getSourceType(); $data['source']['url'] = $package->getSourceUrl(); $data['source']['reference'] = $package->getSourceReference(); } if ($package->getDistType()) { $data['dist']['type'] = $package->getDistType(); $data['dist']['url'] = $package->getDistUrl(); $data['dist']['reference'] = $package->getDistReference(); $data['dist']['shasum'] = $package->getDistSha1Checksum(); } if ($package->getArchiveExcludes()) { $data['archive']['exclude'] = $package->getArchiveExcludes(); } foreach (BasePackage::$supportedLinkTypes as $type => $opts) { if ($links = $package->{'get' . ucfirst($opts['method'])}()) { foreach ($links as $link) { $data[$type][$link->getTarget()] = $link->getPrettyConstraint(); } ksort($data[$type]); } } if ($packages = $package->getSuggests()) { ksort($packages); $data['suggest'] = $packages; } if ($package->getReleaseDate()) { $data['time'] = $package->getReleaseDate()->format('Y-m-d H:i:s'); } $data = $this->dumpValues($package, $keys, $data); if ($package instanceof CompletePackageInterface) { $keys = array('scripts', 'license', 'authors', 'description', 'homepage', 'keywords', 'repositories', 'support'); $data = $this->dumpValues($package, $keys, $data); if (isset($data['keywords']) && is_array($data['keywords'])) { sort($data['keywords']); } } if ($package instanceof RootPackageInterface) { $minimumStability = $package->getMinimumStability(); if ($minimumStability) { $data['minimum-stability'] = $minimumStability; } } return $data; }
/** * {@inheritDoc} */ public function download(PackageInterface $package, $path) { $url = $package->getDistUrl(); $checksum = $package->getDistSha1Checksum(); if (!is_dir($path)) { if (file_exists($path)) { throw new \UnexpectedValueException($path . ' exists and is not a directory'); } if (!mkdir($path, 0777, true)) { throw new \UnexpectedValueException($path . ' does not exist and could not be created'); } } $fileName = rtrim($path . '/' . md5(time() . rand()) . '.' . pathinfo($url, PATHINFO_EXTENSION), '.'); $this->io->write(" - Package <info>" . $package->getName() . "</info> (<comment>" . $package->getPrettyVersion() . "</comment>)"); if (!extension_loaded('openssl') && (0 === strpos($url, 'https:') || 0 === strpos($url, 'http://github.com'))) { // bypass https for github if openssl is disabled if (preg_match('{^https?://(github.com/[^/]+/[^/]+/(zip|tar)ball/[^/]+)$}i', $url, $match)) { $url = 'http://nodeload.' . $match[1]; } else { throw new \RuntimeException('You must enable the openssl extension to download files via https'); } } $rfs = new RemoteFilesystem($this->io); $rfs->copy($package->getSourceUrl(), $url, $fileName); $this->io->write(''); if (!file_exists($fileName)) { throw new \UnexpectedValueException($url . ' could not be saved to ' . $fileName . ', make sure the' . ' directory is writable and you have internet connectivity'); } if ($checksum && hash_file('sha1', $fileName) !== $checksum) { throw new \UnexpectedValueException('The checksum verification of the archive failed (downloaded from ' . $url . ')'); } $this->io->write(' Unpacking archive'); $this->extract($fileName, $path); $this->io->write(' Cleaning up'); unlink($fileName); // If we have only a one dir inside it suppose to be a package itself $contentDir = glob($path . '/*'); if (1 === count($contentDir)) { $contentDir = $contentDir[0]; // Rename the content directory to avoid error when moving up // a child folder with the same name $temporaryName = md5(time() . rand()); rename($contentDir, $temporaryName); $contentDir = $temporaryName; foreach (array_merge(glob($contentDir . '/.*'), glob($contentDir . '/*')) as $file) { if (trim(basename($file), '.')) { rename($file, $path . '/' . basename($file)); } } rmdir($contentDir); } $this->io->write(''); }
/** * {@inheritDoc} */ public function notifyInstall(PackageInterface $package) { if (!$this->notifyUrl || !$this->config->get('notify-on-install')) { return; } // TODO use an optional curl_multi pool for all the notifications $url = str_replace('%package%', $package->getPrettyName(), $this->notifyUrl); $params = array('version' => $package->getPrettyVersion(), 'version_normalized' => $package->getVersion()); $opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => http_build_query($params, '', '&'), 'timeout' => 3)); $context = stream_context_create($opts); @file_get_contents($url, false, $context); }
/** * Convert a package version into string representation. * * @param PackageInterface $package The package to extract the version from. * * @param bool $fullReference Flag if the complete reference shall be added or an abbreviated form. * * @return string * * @throws \RuntimeException If the package is a dev package and does not have valid reference information. */ public static function convertPackageVersion(PackageInterface $package, $fullReference = false) { $version = $package->getPrettyVersion(); if ('dev' === $package->getStability()) { if (null === ($reference = $package->getDistReference())) { if (null === ($reference = $package->getSourceReference())) { throw new \RuntimeException('Unable to determine reference for ' . $package->getPrettyName()); } } $version .= '#' . (!$fullReference ? substr($reference, 0, 8) : $reference); } return $version; }
public function doDownload(PackageInterface $package, $path) { $ref = $package->getSourceReference(); $label = $package->getPrettyVersion(); $this->io->write(' Cloning ' . $ref); $this->initPerforce($package, $path); $this->perforce->setStream($ref); $this->perforce->p4Login($this->io); $this->perforce->writeP4ClientSpec(); $this->perforce->connectClient(); $this->perforce->syncCodeBase($label); $this->perforce->cleanupClientSpec(); }
/** * Generate a distinct filename for a particular version of a package. * * @param PackageInterface $package The package to get a name for * * @return string A filename without an extension */ public function getPackageFilename(PackageInterface $package) { $nameParts = array(preg_replace('#[^a-z0-9-_.]#i', '-', $package->getName())); if (preg_match('{^[a-f0-9]{40}$}', $package->getDistReference())) { $nameParts = array_merge($nameParts, array($package->getDistReference(), $package->getDistType())); } else { $nameParts = array_merge($nameParts, array($package->getPrettyVersion(), $package->getDistReference())); } if ($package->getSourceReference()) { $nameParts[] = substr(sha1($package->getSourceReference()), 0, 6); } return implode('-', array_filter($nameParts, function ($p) { return !empty($p); })); }
/** * {@inheritDoc} */ public function doUpdate(PackageInterface $initial, PackageInterface $target, $path) { $ref = $target->getSourceReference(); $this->io->write(" Checking out " . $ref); $command = 'cd %s && git remote set-url composer %s && git fetch composer && git fetch --tags composer'; // capture username/password from github URL if there is one $this->process->execute(sprintf('cd %s && git remote -v', escapeshellarg($path)), $output); if (preg_match('{^composer\\s+https://(.+):(.+)@github.com/}im', $output, $match)) { $this->io->setAuthorization('github.com', $match[1], $match[2]); } $commandCallable = function ($url) use($ref, $path, $command) { return sprintf($command, escapeshellarg($path), escapeshellarg($url), escapeshellarg($ref)); }; $this->runCommand($commandCallable, $target->getSourceUrl()); $this->updateToCommit($path, $ref, $target->getPrettyVersion(), $target->getReleaseDate()); }
public function dump(PackageInterface $package) { $keys = array('binaries' => 'bin', 'scripts', 'type', 'extra', 'installationSource' => 'installation-source', 'license', 'authors', 'description', 'homepage', 'keywords', 'autoload', 'repositories', 'includePaths' => 'include-path', 'support'); $data = array(); $data['name'] = $package->getPrettyName(); $data['version'] = $package->getPrettyVersion(); $data['version_normalized'] = $package->getVersion(); if ($package->getTargetDir()) { $data['target-dir'] = $package->getTargetDir(); } if ($package->getReleaseDate()) { $data['time'] = $package->getReleaseDate()->format('Y-m-d H:i:s'); } if ($package->getSourceType()) { $data['source']['type'] = $package->getSourceType(); $data['source']['url'] = $package->getSourceUrl(); $data['source']['reference'] = $package->getSourceReference(); } if ($package->getDistType()) { $data['dist']['type'] = $package->getDistType(); $data['dist']['url'] = $package->getDistUrl(); $data['dist']['reference'] = $package->getDistReference(); $data['dist']['shasum'] = $package->getDistSha1Checksum(); } foreach (BasePackage::$supportedLinkTypes as $type => $opts) { if ($links = $package->{'get' . ucfirst($opts['method'])}()) { foreach ($links as $link) { $data[$type][$link->getTarget()] = $link->getPrettyConstraint(); } } } if ($packages = $package->getSuggests()) { $data['suggest'] = $packages; } foreach ($keys as $method => $key) { if (is_numeric($method)) { $method = $key; } $getter = 'get' . ucfirst($method); $value = $package->{$getter}(); if (null !== $value && !(is_array($value) && 0 === count($value))) { $data[$key] = $value; } } return $data; }
/** * Given a concrete version, this returns a ~ constraint (when possible) * that should be used, for example, in composer.json. * * For example: * * 1.2.1 -> ~1.2 * * 1.2 -> ~1.2 * * v3.2.1 -> ~3.2 * * 2.0-beta.1 -> ~2.0@beta * * dev-master -> ~2.1@dev (dev version with alias) * * dev-master -> dev-master (dev versions are untouched) * * @param PackageInterface $package * @return string */ public function findRecommendedRequireVersion(PackageInterface $package) { $version = $package->getVersion(); if (!$package->isDev()) { return $this->transformVersion($version, $package->getPrettyVersion(), $package->getStability()); } $loader = new ArrayLoader($this->getParser()); $dumper = new ArrayDumper(); $extra = $loader->getBranchAlias($dumper->dump($package)); if ($extra) { $extra = preg_replace('{^(\\d+\\.\\d+\\.\\d+)(\\.9999999)-dev$}', '$1.0', $extra, -1, $count); if ($count) { $extra = str_replace('.9999999', '.0', $extra); return $this->transformVersion($extra, $extra, 'dev'); } } return $package->getPrettyVersion(); }
/** * {@inheritDoc} */ public function doUpdate(PackageInterface $initial, PackageInterface $target, $path) { $ref = $target->getSourceReference(); $this->io->write(" Checking out " . $ref); $command = 'cd %s && git remote set-url composer %s && git fetch composer && git fetch --tags composer'; // capture username/password from URL if there is one $this->process->execute(sprintf('cd %s && git remote -v', escapeshellarg($path)), $output); if (preg_match('{^(?:composer|origin)\\s+https?://(.+):(.+)@([^/]+)}im', $output, $match)) { $this->io->setAuthentication($match[3], urldecode($match[1]), urldecode($match[2])); } // added in git 1.7.1, prevents prompting the user putenv('GIT_ASKPASS=echo'); $commandCallable = function ($url) use($ref, $path, $command) { return sprintf($command, escapeshellarg($path), escapeshellarg($url), escapeshellarg($ref)); }; $this->runCommand($commandCallable, $target->getSourceUrl()); $this->updateToCommit($path, $ref, $target->getPrettyVersion(), $target->getReleaseDate()); }
/** * {@inheritDoc} */ public function doUpdate(PackageInterface $initial, PackageInterface $target, $path, $url) { GitUtil::cleanEnv(); if (!$this->hasMetadataRepository($path)) { throw new \RuntimeException('The .git directory is missing from ' . $path . ', see https://getcomposer.org/commit-deps for more information'); } $ref = $target->getSourceReference(); $this->io->writeError(" Checking out " . $ref); $command = 'git remote set-url composer %s && git fetch composer && git fetch --tags composer'; $commandCallable = function ($url) use($command) { return sprintf($command, ProcessExecutor::escape($url)); }; $this->gitUtil->runCommand($commandCallable, $url, $path); if ($newRef = $this->updateToCommit($path, $ref, $target->getPrettyVersion(), $target->getReleaseDate())) { if ($target->getDistReference() === $target->getSourceReference()) { $target->setDistReference($newRef); } $target->setSourceReference($newRef); } }
/** * @return \Composer\Semver\Constraint\ConstraintInterface */ public function getLatestVersion() { return $this->versionParser->parseConstraints($this->latestPackage->getPrettyVersion()); }
private function updateInformation(Package $package, PackageInterface $data, $flags) { $em = $this->doctrine->getManager(); $version = new Version(); $normVersion = $data->getVersion(); $existingVersion = $package->getVersion($normVersion); if ($existingVersion) { $source = $existingVersion->getSource(); // update if the right flag is set, or the source reference has changed (re-tag or new commit on branch) if ($source['reference'] !== $data->getSourceReference() || $flags & self::UPDATE_EQUAL_REFS) { $version = $existingVersion; } else { // mark it updated to avoid it being pruned $existingVersion->setUpdatedAt(new \DateTime()); return false; } } $version->setName($package->getName()); $version->setVersion($data->getPrettyVersion()); $version->setNormalizedVersion($normVersion); $version->setDevelopment($data->isDev()); $em->persist($version); $descr = $this->sanitize($data->getDescription()); $version->setDescription($descr); $package->setDescription($descr); $version->setHomepage($data->getHomepage()); $version->setLicense($data->getLicense() ?: array()); $version->setPackage($package); $version->setUpdatedAt(new \DateTime()); $version->setReleasedAt($data->getReleaseDate()); if ($data->getSourceType()) { $source['type'] = $data->getSourceType(); $source['url'] = $data->getSourceUrl(); $source['reference'] = $data->getSourceReference(); $version->setSource($source); } else { $version->setSource(null); } if ($data->getDistType()) { $dist['type'] = $data->getDistType(); $dist['url'] = $data->getDistUrl(); $dist['reference'] = $data->getDistReference(); $dist['shasum'] = $data->getDistSha1Checksum(); $version->setDist($dist); } else { $version->setDist(null); } if ($data->getType()) { $type = $this->sanitize($data->getType()); $version->setType($type); if ($type !== $package->getType()) { $package->setType($type); } } $version->setTargetDir($data->getTargetDir()); $version->setAutoload($data->getAutoload()); $version->setExtra($data->getExtra()); $version->setBinaries($data->getBinaries()); $version->setIncludePaths($data->getIncludePaths()); $version->setSupport($data->getSupport()); if ($data->getKeywords()) { $keywords = array(); foreach ($data->getKeywords() as $keyword) { $keywords[mb_strtolower($keyword, 'UTF-8')] = $keyword; } $existingTags = []; foreach ($version->getTags() as $tag) { $existingTags[mb_strtolower($tag->getName(), 'UTF-8')] = $tag; } foreach ($keywords as $tagKey => $keyword) { if (isset($existingTags[$tagKey])) { unset($existingTags[$tagKey]); continue; } $tag = Tag::getByName($em, $keyword, true); if (!$version->getTags()->contains($tag)) { $version->addTag($tag); } } foreach ($existingTags as $tag) { $version->getTags()->removeElement($tag); } } elseif (count($version->getTags())) { $version->getTags()->clear(); } $authorRepository = $this->doctrine->getRepository('PackagistWebBundle:Author'); $version->getAuthors()->clear(); if ($data->getAuthors()) { foreach ($data->getAuthors() as $authorData) { $author = null; foreach (array('email', 'name', 'homepage', 'role') as $field) { if (isset($authorData[$field])) { $authorData[$field] = trim($authorData[$field]); if ('' === $authorData[$field]) { $authorData[$field] = null; } } else { $authorData[$field] = null; } } // skip authors with no information if (!isset($authorData['email']) && !isset($authorData['name'])) { continue; } $author = $authorRepository->findOneBy(array('email' => $authorData['email'], 'name' => $authorData['name'], 'homepage' => $authorData['homepage'], 'role' => $authorData['role'])); if (!$author) { $author = new Author(); $em->persist($author); } foreach (array('email', 'name', 'homepage', 'role') as $field) { if (isset($authorData[$field])) { $author->{'set' . $field}($authorData[$field]); } } // only update the author timestamp once a month at most as the value is kinda unused if ($author->getUpdatedAt() === null || $author->getUpdatedAt()->getTimestamp() < time() - 86400 * 30) { $author->setUpdatedAt(new \DateTime()); } if (!$version->getAuthors()->contains($author)) { $version->addAuthor($author); } if (!$author->getVersions()->contains($version)) { $author->addVersion($version); } } } // handle links foreach ($this->supportedLinkTypes as $linkType => $opts) { $links = array(); foreach ($data->{$opts['method']}() as $link) { $constraint = $link->getPrettyConstraint(); if (false !== strpos($constraint, ',') && false !== strpos($constraint, '@')) { $constraint = preg_replace_callback('{([><]=?\\s*[^@]+?)@([a-z]+)}i', function ($matches) { if ($matches[2] === 'stable') { return $matches[1]; } return $matches[1] . '-' . $matches[2]; }, $constraint); } $links[$link->getTarget()] = $constraint; } foreach ($version->{'get' . $linkType}() as $link) { // clear links that have changed/disappeared (for updates) if (!isset($links[$link->getPackageName()]) || $links[$link->getPackageName()] !== $link->getPackageVersion()) { $version->{'get' . $linkType}()->removeElement($link); $em->remove($link); } else { // clear those that are already set unset($links[$link->getPackageName()]); } } foreach ($links as $linkPackageName => $linkPackageVersion) { $class = 'Packagist\\WebBundle\\Entity\\' . $opts['entity']; $link = new $class(); $link->setPackageName($linkPackageName); $link->setPackageVersion($linkPackageVersion); $version->{'add' . $linkType . 'Link'}($link); $link->setVersion($version); $em->persist($link); } } // handle suggests if ($suggests = $data->getSuggests()) { foreach ($version->getSuggest() as $link) { // clear links that have changed/disappeared (for updates) if (!isset($suggests[$link->getPackageName()]) || $suggests[$link->getPackageName()] !== $link->getPackageVersion()) { $version->getSuggest()->removeElement($link); $em->remove($link); } else { // clear those that are already set unset($suggests[$link->getPackageName()]); } } foreach ($suggests as $linkPackageName => $linkPackageVersion) { $link = new SuggestLink(); $link->setPackageName($linkPackageName); $link->setPackageVersion($linkPackageVersion); $version->addSuggestLink($link); $link->setVersion($version); $em->persist($link); } } elseif (count($version->getSuggest())) { // clear existing suggests if present foreach ($version->getSuggest() as $link) { $em->remove($link); } $version->getSuggest()->clear(); } if (!$package->getVersions()->contains($version)) { $package->addVersions($version); } return true; }
/** * prints all available versions of this package and highlights the installed one if any */ protected function printVersions(InputInterface $input, OutputInterface $output, PackageInterface $package, RepositoryInterface $installedRepo, RepositoryInterface $repos) { if ($input->getArgument('version')) { $output->writeln('<info>version</info> : ' . $package->getPrettyVersion()); return; } $versions = array(); foreach ($repos->findPackages($package->getName()) as $version) { $versions[$version->getPrettyVersion()] = $version->getVersion(); } uasort($versions, 'version_compare'); $versions = implode(', ', array_keys(array_reverse($versions))); // highlight installed version if ($installedRepo->hasPackage($package)) { $versions = str_replace($package->getPrettyVersion(), '<info>* ' . $package->getPrettyVersion() . '</info>', $versions); } $output->writeln('<info>versions</info> : ' . $versions); }
/** * Write a notice to IO * * @param string $action * @param \Netresearch\Composer\Patches\Patch $patch * @param \Composer\Package\PackageInterface $package */ protected function writePatchNotice($action, Patch $patch, PackageInterface $package) { $adverbMap = array('test' => 'on', 'apply' => 'to', 'revert' => 'from'); if ($action == 'test' && !$this->io->isVeryVerbose()) { return; } $msg = ' - ' . ucfirst($action) . 'ing patch'; if ($this->io->isVerbose() || !isset($patch->title)) { $msg .= ' <info>' . $patch->getChecksum() . '</info>'; } $msg .= ' ' . $adverbMap[$action]; $msg .= ' <info>' . $package->getName() . '</info>'; if ($this->io->isVerbose()) { ' (<comment>' . $package->getPrettyVersion() . '</comment>)'; } if (isset($patch->title)) { $msg .= ': <comment>' . $patch->title . '</comment>'; } $this->io->write($msg); }
/** * {@inheritdoc} */ public function getPrettyVersion() { return $this->package->getPrettyVersion(); }
private function addCommandsFromPackage(PackageInterface $package) { $extra = $package->getExtra(); if (empty($extra['plow']) || !is_array($extra['plow'])) { return; } $this->packages[$package->getPrettyName()] = ['version' => $package->getPrettyVersion(), 'classes' => $extra['plow']]; $this->madeChanges = true; }
/** * {@inheritDoc} */ public function addPackage(PackageInterface $package) { // Skip if overridden if (isset($this->overrides[strtolower($package->getName())])) { $overrider = $this->findPackage($package->getName(), '*'); $overrider->setDescription($overrider->getDescription() . ' (actual: ' . $package->getPrettyVersion() . ')'); return; } parent::addPackage($package); }
/** * Convert a package to array information used by json API. * * @param PackageInterface $package The package to convert. * * @param null|PackageInterface $upgrade The package to show as upgradable to. * * @return JsonArray */ public function convertPackageToArray(PackageInterface $package, PackageInterface $upgrade = null) { $name = $package->getPrettyName(); $data = new JsonArray(['name' => $name, 'version' => $this->convertPackageVersion($package), 'constraint' => $this->getConstraint($name), 'type' => $package->getType(), 'locked' => $this->isLocked($name)]); if (null !== ($releaseDate = $package->getReleaseDate())) { $data->set('time', $releaseDate->format(\DateTime::ATOM)); } if (null !== $upgrade) { $data->set('upgrade_version', $upgrade->getPrettyVersion()); if (null !== ($upgradeReleaseDate = $upgrade->getReleaseDate())) { $data->set('upgrade_time', $upgradeReleaseDate->format(\DateTime::ATOM)); } } if ($package instanceof CompletePackageInterface) { $this->convertCompletePackage($package, $data); } return $data; }
/** * Display the tree * * @param PackageInterface|string $package * @param RepositoryInterface $installedRepo * @param RepositoryInterface $distantRepos */ protected function displayPackageTree(PackageInterface $package, RepositoryInterface $installedRepo, RepositoryInterface $distantRepos) { $io = $this->getIO(); $io->write(sprintf('<info>%s</info>', $package->getPrettyName()), false); $io->write(' ' . $package->getPrettyVersion(), false); $io->write(' ' . strtok($package->getDescription(), "\r\n")); if (is_object($package)) { $requires = $package->getRequires(); $treeBar = '├'; $j = 0; $total = count($requires); foreach ($requires as $requireName => $require) { $j++; if ($j == 0) { $this->writeTreeLine($treeBar); } if ($j == $total) { $treeBar = '└'; } $level = 1; $color = $this->colors[$level]; $info = sprintf('%s──<%s>%s</%s> %s', $treeBar, $color, $requireName, $color, $require->getPrettyConstraint()); $this->writeTreeLine($info); $treeBar = str_replace('└', ' ', $treeBar); $packagesInTree = array($package->getName(), $requireName); $this->displayTree($requireName, $require, $installedRepo, $distantRepos, $packagesInTree, $treeBar, $level + 1); } } }