Exemplo n.º 1
0
 /**
  * Filter the package to add dist and other meta information.
  */
 function filterPackage(CompletePackage $package)
 {
     list($vendor, $shortName) = explode('/', $package->getName());
     // try to get the plugin info - may return an array or null/false
     try {
         $info = $this->getPluginInfo($shortName);
     } catch (RuntimeException $e) {
         if ($io->isVerbose()) {
             $io->writeError($e->getMessage());
         }
         // this allows us to try again for this plugin
         return;
     }
     if ($info) {
         // set the dist info
         $package->setDistType('zip');
         // strip out "tags", "trunk", slashes, and spaces
         $version = preg_replace('/tags|trunk|[\\/ ]/', '', $package->getSourceReference());
         // if there is a version identifier, prepend with a period
         $version = $version ? ".{$version}" : '';
         // set the dist url
         $package->setDistUrl('https://downloads.wordpress.org/plugin/' . urlencode($shortName . $version) . '.zip');
         // set some additional meta info
         // this is inconsequential to the solver, but it gets stored in composer.lock
         // and appears when running `composer show vendor/package`
         if (isset($info['short_description'])) {
             $package->setDescription($info['short_description']);
         }
         if (!empty($info['contributors'])) {
             $authors = [];
             foreach ($info['contributors'] as $name => $homepage) {
                 $authors[] = ['name' => $name, 'homepage' => $homepage];
             }
             $package->setAuthors($authors);
         }
         if (!empty($info['tags'])) {
             $package->setKeywords($info['tags']);
         }
         // URL-ready slug
         $pluginSlug = urlencode($shortName);
         $package->setSupport(['forum' => "https://wordpress.org/support/plugin/{$pluginSlug}/", 'source' => "http://plugins.trac.wordpress.org/browser/{$pluginSlug}/", 'docs' => "https://wordpress.org/plugins/{$pluginSlug}/"]);
         $package->setHomepage("https://wordpress.org/plugins/{$pluginSlug}/");
     } else {
         // null means the package is no longer active
         $package->setAbandoned(true);
     }
 }
Exemplo n.º 2
0
 /**
  * Filter the package to add dist and other meta information.
  */
 function filterPackage(CompletePackage $package)
 {
     list($vendor, $shortName) = explode('/', $package->getName());
     if (($themeInfo = $this->getThemeInfo()) && isset($themeInfo[$shortName])) {
         $info = $themeInfo[$shortName];
         // set the dist info
         $package->setDistType('zip');
         $package->setDistUrl($info['download_uri']);
         // additional meta info
         $package->setDescription($info['description']);
         $package->setAuthors([['name' => $info['author'], 'homepage' => $info['author_uri']]]);
         $package->setHomepage($info['theme_uri']);
         // is this theme retired?
         if (in_array($shortName, $this->getRetiredThemes())) {
             $package->setAbandoned(true);
         }
     }
 }
Exemplo n.º 3
0
 static function filterPackage(CompletePackage $package)
 {
     // strip out "tags", slashes, and spaces
     $version = preg_replace('/tags|[\\/ ]/', '', $package->getSourceReference());
     // trunk does not have a dist version
     if ($version !== 'trunk') {
         // set the dist info
         $package->setDistType('zip');
         // if there is a version identifier, prepend with a period
         $version = "-{$version}";
         // set the dist url
         $package->setDistUrl('https://wordpress.org/wordpress' . urlencode($version) . '.zip');
     }
     // set some additional meta info
     // this is inconsequential to the solver, but it gets stored in composer.lock
     // and appears when running `composer show vendor/package`
     $package->setDescription('WordPress is web software you can use to create a beautiful website, blog, or app.');
     $package->setSupport(['forum' => 'https://wordpress.org/support/', 'source' => 'https://core.trac.wordpress.org/browser/' . $package->getSourceReference(), 'docs' => 'https://codex.wordpress.org/Main_Page']);
     $package->setHomepage('https://wordpress.org/');
 }
 public function testShouldCreatePackages()
 {
     $reader = $this->getMockBuilder('\\Composer\\Repository\\PearRepository')->disableOriginalConstructor()->getMock();
     $ref = new \ReflectionMethod($reader, 'buildComposerPackages');
     $ref->setAccessible(true);
     $channelInfo = new ChannelInfo('test.loc', 'test', array(new PackageInfo('test.loc', 'sample', 'license', 'shortDescription', 'description', array('1.0.0.1' => new ReleaseInfo('stable', new DependencyInfo(array(new DependencyConstraint('required', '> 5.2.0.0', 'php', ''), new DependencyConstraint('conflicts', '== 2.5.6.0', 'pear.php.net', 'broken')), array('*' => array(new DependencyConstraint('optional', '*', 'ext', 'xml')))))))));
     $packages = $ref->invoke($reader, $channelInfo, new VersionParser());
     $expectedPackage = new CompletePackage('pear-test.loc/sample', '1.0.0.1', '1.0.0.1');
     $expectedPackage->setType('pear-library');
     $expectedPackage->setDistType('file');
     $expectedPackage->setDescription('description');
     $expectedPackage->setDistUrl("http://test.loc/get/sample-1.0.0.1.tgz");
     $expectedPackage->setAutoload(array('classmap' => array('')));
     $expectedPackage->setIncludePaths(array('/'));
     $expectedPackage->setRequires(array(new Link('pear-test.loc/sample', 'php', $this->createConstraint('>', '5.2.0.0'), 'required', '> 5.2.0.0')));
     $expectedPackage->setConflicts(array(new Link('pear-test.loc/sample', 'pear-pear.php.net/broken', $this->createConstraint('==', '2.5.6.0'), 'conflicts', '== 2.5.6.0')));
     $expectedPackage->setSuggests(array('*-ext-xml' => '*'));
     $expectedPackage->setReplaces(array(new Link('pear-test.loc/sample', 'pear-test/sample', new VersionConstraint('==', '1.0.0.1'), 'replaces', '== 1.0.0.1')));
     $this->assertCount(1, $packages);
     $this->assertEquals($expectedPackage, $packages[0], 0, 1);
 }
Exemplo n.º 5
0
 /**
  * Builds CompletePackages from PEAR package definition data.
  *
  * @param  ChannelInfo     $channelInfo
  * @param  VersionParser   $versionParser
  * @return CompletePackage
  */
 private function buildComposerPackages(ChannelInfo $channelInfo, VersionParser $versionParser)
 {
     $result = array();
     foreach ($channelInfo->getPackages() as $packageDefinition) {
         foreach ($packageDefinition->getReleases() as $version => $releaseInfo) {
             try {
                 $normalizedVersion = $versionParser->normalize($version);
             } catch (\UnexpectedValueException $e) {
                 if ($this->io->isVerbose()) {
                     $this->io->writeError('Could not load ' . $packageDefinition->getPackageName() . ' ' . $version . ': ' . $e->getMessage());
                 }
                 continue;
             }
             $composerPackageName = $this->buildComposerPackageName($packageDefinition->getChannelName(), $packageDefinition->getPackageName());
             // distribution url must be read from /r/{packageName}/{version}.xml::/r/g:text()
             // but this location is 'de-facto' standard
             $urlBits = parse_url($this->url);
             $scheme = isset($urlBits['scheme']) && 'https' === $urlBits['scheme'] && extension_loaded('openssl') ? 'https' : 'http';
             $distUrl = "{$scheme}://{$packageDefinition->getChannelName()}/get/{$packageDefinition->getPackageName()}-{$version}.tgz";
             $requires = array();
             $suggests = array();
             $conflicts = array();
             $replaces = array();
             // alias package only when its channel matches repository channel,
             // cause we've know only repository channel alias
             if ($channelInfo->getName() == $packageDefinition->getChannelName()) {
                 $composerPackageAlias = $this->buildComposerPackageName($channelInfo->getAlias(), $packageDefinition->getPackageName());
                 $aliasConstraint = new VersionConstraint('==', $normalizedVersion);
                 $replaces[] = new Link($composerPackageName, $composerPackageAlias, $aliasConstraint, 'replaces', (string) $aliasConstraint);
             }
             // alias package with user-specified prefix. it makes private pear channels looks like composer's.
             if (!empty($this->vendorAlias) && ($this->vendorAlias != 'pear-' . $channelInfo->getAlias() || $channelInfo->getName() != $packageDefinition->getChannelName())) {
                 $composerPackageAlias = "{$this->vendorAlias}/{$packageDefinition->getPackageName()}";
                 $aliasConstraint = new VersionConstraint('==', $normalizedVersion);
                 $replaces[] = new Link($composerPackageName, $composerPackageAlias, $aliasConstraint, 'replaces', (string) $aliasConstraint);
             }
             foreach ($releaseInfo->getDependencyInfo()->getRequires() as $dependencyConstraint) {
                 $dependencyPackageName = $this->buildComposerPackageName($dependencyConstraint->getChannelName(), $dependencyConstraint->getPackageName());
                 $constraint = $versionParser->parseConstraints($dependencyConstraint->getConstraint());
                 $link = new Link($composerPackageName, $dependencyPackageName, $constraint, $dependencyConstraint->getType(), $dependencyConstraint->getConstraint());
                 switch ($dependencyConstraint->getType()) {
                     case 'required':
                         $requires[] = $link;
                         break;
                     case 'conflicts':
                         $conflicts[] = $link;
                         break;
                     case 'replaces':
                         $replaces[] = $link;
                         break;
                 }
             }
             foreach ($releaseInfo->getDependencyInfo()->getOptionals() as $group => $dependencyConstraints) {
                 foreach ($dependencyConstraints as $dependencyConstraint) {
                     $dependencyPackageName = $this->buildComposerPackageName($dependencyConstraint->getChannelName(), $dependencyConstraint->getPackageName());
                     $suggests[$group . '-' . $dependencyPackageName] = $dependencyConstraint->getConstraint();
                 }
             }
             $package = new CompletePackage($composerPackageName, $normalizedVersion, $version);
             $package->setType('pear-library');
             $package->setDescription($packageDefinition->getDescription());
             $package->setLicense(array($packageDefinition->getLicense()));
             $package->setDistType('file');
             $package->setDistUrl($distUrl);
             $package->setAutoload(array('classmap' => array('')));
             $package->setIncludePaths(array('/'));
             $package->setRequires($requires);
             $package->setConflicts($conflicts);
             $package->setSuggests($suggests);
             $package->setReplaces($replaces);
             $result[] = $package;
         }
     }
     return $result;
 }
Exemplo n.º 6
0
 private function buildComposerPackages(ChannelInfo $channelInfo, VersionParser $versionParser)
 {
     $result = array();
     foreach ($channelInfo->getPackages() as $packageDefinition) {
         foreach ($packageDefinition->getReleases() as $version => $releaseInfo) {
             try {
                 $normalizedVersion = $versionParser->normalize($version);
             } catch (\UnexpectedValueException $e) {
                 if ($this->io->isVerbose()) {
                     $this->io->write('Could not load ' . $packageDefinition->getPackageName() . ' ' . $version . ': ' . $e->getMessage());
                 }
                 continue;
             }
             $composerPackageName = $this->buildComposerPackageName($packageDefinition->getChannelName(), $packageDefinition->getPackageName());
             $urlBits = parse_url($this->url);
             $scheme = isset($urlBits['scheme']) && 'https' === $urlBits['scheme'] && extension_loaded('openssl') ? 'https' : 'http';
             $distUrl = "{$scheme}://{$packageDefinition->getChannelName()}/get/{$packageDefinition->getPackageName()}-{$version}.tgz";
             $requires = array();
             $suggests = array();
             $conflicts = array();
             $replaces = array();
             if ($channelInfo->getName() == $packageDefinition->getChannelName()) {
                 $composerPackageAlias = $this->buildComposerPackageName($channelInfo->getAlias(), $packageDefinition->getPackageName());
                 $aliasConstraint = new VersionConstraint('==', $normalizedVersion);
                 $replaces[] = new Link($composerPackageName, $composerPackageAlias, $aliasConstraint, 'replaces', (string) $aliasConstraint);
             }
             if (!empty($this->vendorAlias) && ($this->vendorAlias != 'pear-' . $channelInfo->getAlias() || $channelInfo->getName() != $packageDefinition->getChannelName())) {
                 $composerPackageAlias = "{$this->vendorAlias}/{$packageDefinition->getPackageName()}";
                 $aliasConstraint = new VersionConstraint('==', $normalizedVersion);
                 $replaces[] = new Link($composerPackageName, $composerPackageAlias, $aliasConstraint, 'replaces', (string) $aliasConstraint);
             }
             foreach ($releaseInfo->getDependencyInfo()->getRequires() as $dependencyConstraint) {
                 $dependencyPackageName = $this->buildComposerPackageName($dependencyConstraint->getChannelName(), $dependencyConstraint->getPackageName());
                 $constraint = $versionParser->parseConstraints($dependencyConstraint->getConstraint());
                 $link = new Link($composerPackageName, $dependencyPackageName, $constraint, $dependencyConstraint->getType(), $dependencyConstraint->getConstraint());
                 switch ($dependencyConstraint->getType()) {
                     case 'required':
                         $requires[] = $link;
                         break;
                     case 'conflicts':
                         $conflicts[] = $link;
                         break;
                     case 'replaces':
                         $replaces[] = $link;
                         break;
                 }
             }
             foreach ($releaseInfo->getDependencyInfo()->getOptionals() as $group => $dependencyConstraints) {
                 foreach ($dependencyConstraints as $dependencyConstraint) {
                     $dependencyPackageName = $this->buildComposerPackageName($dependencyConstraint->getChannelName(), $dependencyConstraint->getPackageName());
                     $suggests[$group . '-' . $dependencyPackageName] = $dependencyConstraint->getConstraint();
                 }
             }
             $package = new CompletePackage($composerPackageName, $normalizedVersion, $version);
             $package->setType('pear-library');
             $package->setDescription($packageDefinition->getDescription());
             $package->setDistType('file');
             $package->setDistUrl($distUrl);
             $package->setAutoload(array('classmap' => array('')));
             $package->setIncludePaths(array('/'));
             $package->setRequires($requires);
             $package->setConflicts($conflicts);
             $package->setSuggests($suggests);
             $package->setReplaces($replaces);
             $result[] = $package;
         }
     }
     return $result;
 }