public function getInstallDate()
 {
     //get the composer.json file of the package to check its modified-date
     $repository = $this->installedPackage->getRepository();
     $reflection = new \ReflectionClass('Composer\\Repository\\FilesystemRepository');
     $p = $reflection->getProperty('file');
     $p->setAccessible(true);
     $file = $p->getValue($repository);
     $installDate = filemtime($file->getPath());
     return \DateTime::createFromFormat('U', $installDate);
 }
Exemple #2
0
 /**
  * @param CompletePackageInterface $package
  */
 private function processPackageDependencies(CompletePackageInterface $package)
 {
     $dependencies = $package->getRequires();
     if (is_array($dependencies)) {
         foreach ($dependencies as $packageLink) {
             if ($packageLink instanceof Link) {
                 $this->processPackageLink($packageLink);
             }
         }
     }
 }
Exemple #3
0
 /**
  * @param CompletePackageInterface $package
  *
  * @return Package
  */
 public static function createFromComposerPackage(CompletePackageInterface $package)
 {
     $class = new self();
     $class->type = $package->getType();
     $class->name = $package->getPrettyName();
     $class->description = $package->getDescription();
     $class->authors = $package->getAuthors();
     $class->keywords = $package->getKeywords();
     if ($package->getVersion() === '9999999-dev') {
         $class->version = sprintf('%s (%s)', $package->getPrettyVersion(), substr($package->getSourceReference(), 0, 6));
     } else {
         $class->version = $package->getPrettyVersion();
     }
     return $class;
 }
 public function setUp()
 {
     $this->composerMock = $this->getMockBuilder(Composer::class)->disableOriginalConstructor()->getMock();
     $this->lockerMock = $this->getMockBuilder(Locker::class)->disableOriginalConstructor()->getMock();
     $this->lockerRepositoryMock = $this->getMockForAbstractClass(\Composer\Repository\RepositoryInterface::class);
     $this->packageMock = $this->getMockForAbstractClass(\Composer\Package\CompletePackageInterface::class);
     $this->lockerMock->method('getLockedRepository')->willReturn($this->lockerRepositoryMock);
     $this->packageMock->method('getType')->willReturn('metapackage');
     $this->packageMock->method('getPrettyName')->willReturn('magento/product-test-package-name');
     $this->packageMock->method('getName')->willReturn('magento/product-test-package-name');
     $this->packageMock->method('getPrettyVersion')->willReturn('123.456.789');
     $this->lockerRepositoryMock->method('getPackages')->willReturn([$this->packageMock]);
     $objectManager = new ObjectManager($this);
     $this->composerInformation = $objectManager->getObject(\Magento\Framework\Composer\ComposerInformation::class, ['composer' => $this->composerMock, 'locker' => $this->lockerMock]);
 }
 private function handlePackage(CompletePackageInterface $package, $showHomepage, $showOnly)
 {
     $support = $package->getSupport();
     $url = isset($support['source']) ? $support['source'] : $package->getSourceUrl();
     if (!$url || $showHomepage) {
         $url = $package->getHomepage();
     }
     if (!$url || !filter_var($url, FILTER_VALIDATE_URL)) {
         return false;
     }
     if ($showOnly) {
         $this->getIO()->write(sprintf('<info>%s</info>', $url));
     } else {
         $this->openBrowser($url);
     }
     return true;
 }
Exemple #6
0
    private function packageExpects($method, $value)
    {
        $this->package
            ->expects($this->any())
            ->method($method)
            ->will($this->returnValue($value));

        return $this;
    }
Exemple #7
0
 /**
  * Convert the data of a complete package to the passed json array.
  *
  * @param CompletePackageInterface $package The package to process.
  *
  * @param JsonArray                $data    The json array to push the data to.
  *
  * @return void
  */
 private function convertCompletePackage(CompletePackageInterface $package, $data)
 {
     $data->set('description', $package->getDescription());
     $data->set('license', $package->getLicense());
     if ($keywords = $package->getKeywords()) {
         $data->set('keywords', $keywords);
     }
     if ($homepage = $package->getHomepage()) {
         $data->set('homepage', $homepage);
     }
     if ($authors = $package->getAuthors()) {
         $data->set('authors', $authors);
     }
     if ($support = $package->getSupport()) {
         $data->set('support', $support);
     }
     if ($extra = $package->getExtra()) {
         $data->set('extra', $extra);
     }
     $data->set('abandoned', $package->isAbandoned());
     if ($package->isAbandoned()) {
         $data->set('replacement', $package->getReplacementPackage());
     }
 }
Exemple #8
0
 /**
  * tries to find a token within the name/keywords/description
  *
  * @param  CompletePackageInterface $package
  * @param  string                   $token
  * @return boolean
  */
 private function matchPackage(CompletePackageInterface $package, $token)
 {
     $score = 0;
     if (false !== stripos($package->getName(), $token)) {
         $score += 5;
     }
     if (!$this->onlyName && false !== stripos(join(',', $package->getKeywords() ?: array()), $token)) {
         $score += 3;
     }
     if (!$this->onlyName && false !== stripos($package->getDescription(), $token)) {
         $score += 1;
     }
     return $score;
 }
Exemple #9
0
 /**
  * prints package meta data
  */
 protected function printMeta(InputInterface $input, OutputInterface $output, CompletePackageInterface $package, array $versions, RepositoryInterface $installedRepo, RepositoryInterface $repos)
 {
     $output->writeln('<info>name</info>     : ' . $package->getPrettyName());
     $output->writeln('<info>descrip.</info> : ' . $package->getDescription());
     $output->writeln('<info>keywords</info> : ' . join(', ', $package->getKeywords() ?: array()));
     $this->printVersions($input, $output, $package, $versions, $installedRepo, $repos);
     $output->writeln('<info>type</info>     : ' . $package->getType());
     $output->writeln('<info>license</info>  : ' . implode(', ', $package->getLicense()));
     $output->writeln('<info>source</info>   : ' . sprintf('[%s] <comment>%s</comment> %s', $package->getSourceType(), $package->getSourceUrl(), $package->getSourceReference()));
     $output->writeln('<info>dist</info>     : ' . sprintf('[%s] <comment>%s</comment> %s', $package->getDistType(), $package->getDistUrl(), $package->getDistReference()));
     $output->writeln('<info>names</info>    : ' . implode(', ', $package->getNames()));
     if ($package->getSupport()) {
         $output->writeln("\n<info>support</info>");
         foreach ($package->getSupport() as $type => $value) {
             $output->writeln('<comment>' . $type . '</comment> : ' . $value);
         }
     }
     if ($package->getAutoload()) {
         $output->writeln("\n<info>autoload</info>");
         foreach ($package->getAutoload() as $type => $autoloads) {
             $output->writeln('<comment>' . $type . '</comment>');
             if ($type === 'psr-0') {
                 foreach ($autoloads as $name => $path) {
                     $output->writeln(($name ?: '*') . ' => ' . (is_array($path) ? implode(', ', $path) : ($path ?: '.')));
                 }
             } elseif ($type === 'psr-4') {
                 foreach ($autoloads as $name => $path) {
                     $output->writeln(($name ?: '*') . ' => ' . (is_array($path) ? implode(', ', $path) : ($path ?: '.')));
                 }
             } elseif ($type === 'classmap') {
                 $output->writeln(implode(', ', $autoloads));
             }
         }
         if ($package->getIncludePaths()) {
             $output->writeln('<comment>include-path</comment>');
             $output->writeln(implode(', ', $package->getIncludePaths()));
         }
     }
 }
Exemple #10
0
 /**
  * Prints the licenses of a package with metadata
  *
  * @param CompletePackageInterface $package
  */
 protected function printLicenses(CompletePackageInterface $package)
 {
     $spdxLicenses = new SpdxLicenses();
     $licenses = $package->getLicense();
     $io = $this->getIO();
     foreach ($licenses as $licenseId) {
         $license = $spdxLicenses->getLicenseByIdentifier($licenseId);
         // keys: 0 fullname, 1 osi, 2 url
         if (!$license) {
             $out = $licenseId;
         } else {
             // is license OSI approved?
             if ($license[1] === true) {
                 $out = sprintf('%s (%s) (OSI approved) %s', $license[0], $licenseId, $license[2]);
             } else {
                 $out = sprintf('%s (%s) %s', $license[0], $licenseId, $license[2]);
             }
         }
         $io->write('<info>license</info>  : ' . $out);
     }
 }
Exemple #11
0
 protected function printMeta(InputInterface $input, OutputInterface $output, CompletePackageInterface $package, array $versions, RepositoryInterface $installedRepo, RepositoryInterface $repos)
 {
     $this->getIO()->write('<info>name</info>     : ' . $package->getPrettyName());
     $this->getIO()->write('<info>descrip.</info> : ' . $package->getDescription());
     $this->getIO()->write('<info>keywords</info> : ' . join(', ', $package->getKeywords() ?: array()));
     $this->printVersions($input, $output, $package, $versions, $installedRepo, $repos);
     $this->getIO()->write('<info>type</info>     : ' . $package->getType());
     $this->getIO()->write('<info>license</info>  : ' . implode(', ', $package->getLicense()));
     $this->getIO()->write('<info>source</info>   : ' . sprintf('[%s] <comment>%s</comment> %s', $package->getSourceType(), $package->getSourceUrl(), $package->getSourceReference()));
     $this->getIO()->write('<info>dist</info>     : ' . sprintf('[%s] <comment>%s</comment> %s', $package->getDistType(), $package->getDistUrl(), $package->getDistReference()));
     $this->getIO()->write('<info>names</info>    : ' . implode(', ', $package->getNames()));
     if ($package->isAbandoned()) {
         $replacement = $package->getReplacementPackage() !== null ? ' The author suggests using the ' . $package->getReplacementPackage() . ' package instead.' : null;
         $this->getIO()->writeError(sprintf('<error>Attention: This package is abandoned and no longer maintained.%s</error>', $replacement));
     }
     if ($package->getSupport()) {
         $this->getIO()->write("\n<info>support</info>");
         foreach ($package->getSupport() as $type => $value) {
             $this->getIO()->write('<comment>' . $type . '</comment> : ' . $value);
         }
     }
     if ($package->getAutoload()) {
         $this->getIO()->write("\n<info>autoload</info>");
         foreach ($package->getAutoload() as $type => $autoloads) {
             $this->getIO()->write('<comment>' . $type . '</comment>');
             if ($type === 'psr-0') {
                 foreach ($autoloads as $name => $path) {
                     $this->getIO()->write(($name ?: '*') . ' => ' . (is_array($path) ? implode(', ', $path) : ($path ?: '.')));
                 }
             } elseif ($type === 'psr-4') {
                 foreach ($autoloads as $name => $path) {
                     $this->getIO()->write(($name ?: '*') . ' => ' . (is_array($path) ? implode(', ', $path) : ($path ?: '.')));
                 }
             } elseif ($type === 'classmap') {
                 $this->getIO()->write(implode(', ', $autoloads));
             }
         }
         if ($package->getIncludePaths()) {
             $this->getIO()->write('<comment>include-path</comment>');
             $this->getIO()->write(implode(', ', $package->getIncludePaths()));
         }
     }
 }
 /**
  * Returns a package tag list.
  *
  * @param CompletePackageInterface $package
  *
  * @return array
  */
 public function getPackageTags(CompletePackageInterface $package)
 {
     $ds = DIRECTORY_SEPARATOR;
     putenv("COMPOSER_HOME={$this->vendorDir}{$ds}composer");
     $repos = Factory::createDefaultRepositories(new NullIO());
     $compositeRepo = new CompositeRepository($repos);
     $pkgs = $compositeRepo->findPackages($package->getPrettyName());
     $tags = array();
     foreach ($pkgs as $pkg) {
         $tags[] = $pkg->getPrettyVersion();
     }
     return $tags;
 }
    /**
     * Normalize the alias of branch.
     *
     * @param CompletePackageInterface $package The package instance
     *
     * @return string The alias branch name
     */
    protected function normalizeBranchAlias(CompletePackageInterface $package)
    {
        $stability = VersionParser::parseStability($this->versionParser->normalize($this->rootPackageVersion));
        $aliasNormalized = 'dev-' . $this->rootPackageVersion;

        if (BasePackage::STABILITY_STABLE === BasePackage::$stabilities[$stability]
            && null === $this->findPackage($package->getName(), $this->rootPackageVersion)) {
            $aliasNormalized = $this->versionParser->normalize($this->rootPackageVersion);
        }

        return $aliasNormalized;
    }
Exemple #14
0
 /**
  * prints all available versions of this package and highlights the installed one if any
  */
 protected function printVersions(InputInterface $input, OutputInterface $output, CompletePackageInterface $package, array $versions, RepositoryInterface $installedRepo, RepositoryInterface $repos)
 {
     if ($input->getArgument('version')) {
         $output->writeln('<info>version</info>  : ' . $package->getPrettyVersion());
         return;
     }
     uasort($versions, 'version_compare');
     $versions = array_keys(array_reverse($versions));
     // highlight installed version
     if ($installedRepo->hasPackage($package)) {
         $installedVersion = $package->getPrettyVersion();
         $key = array_search($installedVersion, $versions);
         if (false !== $key) {
             $versions[$key] = '<info>* ' . $installedVersion . '</info>';
         }
     }
     $versions = implode(', ', $versions);
     $output->writeln('<info>versions</info> : ' . $versions);
 }
Exemple #15
0
 /**
  * prints all available versions of this package and highlights the installed one if any
  */
 protected function printVersions(InputInterface $input, OutputInterface $output, CompletePackageInterface $package, array $versions, RepositoryInterface $installedRepo, RepositoryInterface $repos)
 {
     if ($input->getArgument('version')) {
         $output->writeln('<info>version</info>  : ' . $package->getPrettyVersion());
         return;
     }
     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);
 }