Exemple #1
0
 public function getComposerInformation($identifier)
 {
     $this->buildNameMapping();
     $composerInformation = parent::getComposerInformation($identifier);
     if (!$composerInformation) {
         $resource = sprintf('%s:ext_emconf.php', escapeshellarg($identifier));
         $this->process->execute(sprintf('git show %s', $resource), $emConf, $this->repoDir);
         if (!trim($emConf)) {
             // No emconf at all, we skip
             return;
         }
         $emConfConverter = new EmConfReader();
         $extensionConfig = $emConfConverter->readFromString($emConf);
         if (empty($extensionConfig) || !preg_match('/^[\\d]+\\.[\\d]+(\\.[\\d])*$/', str_replace('-dev', '', $extensionConfig['version']))) {
             // Could not read extension config or invalid version number, we skip
             return;
         }
         $composerInformation = $this->getComposerInformationFromEmConf($extensionConfig, $identifier);
         if (false === json_encode($composerInformation, 448)) {
             // Most likely wrong encoding (not UTF-8) which we cannot fix here
             return;
         }
         if (preg_match('{[a-f0-9]{40}}i', $identifier)) {
             $this->cache->write($identifier, json_encode($composerInformation));
         }
         $this->infoCache[$identifier] = $composerInformation;
     }
     return $composerInformation;
 }
 /**
  * {@inheritDoc}
  */
 public function getComposerInformation($identifier)
 {
     if ($this->gitDriver) {
         return $this->gitDriver->getComposerInformation($identifier);
     }
     if (preg_match('{[a-f0-9]{40}}i', $identifier) && ($res = $this->cache->read($identifier))) {
         $this->infoCache[$identifier] = JsonFile::parseJson($res);
     }
     if (!isset($this->infoCache[$identifier])) {
         try {
             $composer = $this->getContents($this->getScheme() . '://raw.github.com/' . $this->owner . '/' . $this->repository . '/' . $identifier . '/composer.json');
         } catch (TransportException $e) {
             if (404 !== $e->getCode()) {
                 throw $e;
             }
             $composer = false;
         }
         if ($composer) {
             $composer = JsonFile::parseJson($composer);
             if (!isset($composer['time'])) {
                 $commit = JsonFile::parseJson($this->getContents($this->getScheme() . '://api.github.com/repos/' . $this->owner . '/' . $this->repository . '/commits/' . $identifier));
                 $composer['time'] = $commit['commit']['committer']['date'];
             }
         }
         if (preg_match('{[a-f0-9]{40}}i', $identifier)) {
             $this->cache->write($identifier, json_encode($composer));
         }
         $this->infoCache[$identifier] = $composer;
     }
     return $this->infoCache[$identifier];
 }
Exemple #3
0
 /**
  * {@inheritDoc}
  */
 public function getComposerInformation($identifier)
 {
     if ($this->gitDriver) {
         return $this->gitDriver->getComposerInformation($identifier);
     }
     if (!isset($this->infoCache[$identifier])) {
         if ($this->shouldCache($identifier) && ($res = $this->cache->read($identifier))) {
             return $this->infoCache[$identifier] = JsonFile::parseJson($res);
         }
         $composer = $this->getBaseComposerInformation($identifier);
         // specials for github
         if (!isset($composer['support']['source'])) {
             $label = array_search($identifier, $this->getTags()) ?: array_search($identifier, $this->getBranches()) ?: $identifier;
             $composer['support']['source'] = sprintf('https://%s/%s/%s/tree/%s', $this->originUrl, $this->owner, $this->repository, $label);
         }
         if (!isset($composer['support']['issues']) && $this->hasIssues) {
             $composer['support']['issues'] = sprintf('https://%s/%s/%s/issues', $this->originUrl, $this->owner, $this->repository);
         }
         if ($this->shouldCache($identifier)) {
             $this->cache->write($identifier, json_encode($composer));
         }
         $this->infoCache[$identifier] = $composer;
     }
     return $this->infoCache[$identifier];
 }
 /**
  * {@inheritDoc}
  */
 public function getComposerInformation($identifier)
 {
     if ($this->gitDriver) {
         return $this->gitDriver->getComposerInformation($identifier);
     }
     if (preg_match('{[a-f0-9]{40}}i', $identifier) && ($res = $this->cache->read($identifier))) {
         $this->infoCache[$identifier] = JsonFile::parseJson($res);
     }
     if (!isset($this->infoCache[$identifier])) {
         $notFoundRetries = 2;
         while ($notFoundRetries) {
             try {
                 $resource = $this->getApiUrl() . '/repos/' . $this->owner . '/' . $this->repository . '/contents/composer.json?ref=' . urlencode($identifier);
                 $resource = JsonFile::parseJson($this->getContents($resource));
                 if (empty($resource['content']) || $resource['encoding'] !== 'base64' || !($composer = base64_decode($resource['content']))) {
                     throw new \RuntimeException('Could not retrieve composer.json for ' . $identifier);
                 }
                 break;
             } catch (TransportException $e) {
                 if (404 !== $e->getCode()) {
                     throw $e;
                 }
                 // TODO should be removed when possible
                 // retry fetching if github returns a 404 since they happen randomly
                 $notFoundRetries--;
                 $composer = null;
             }
         }
         if ($composer) {
             $composer = JsonFile::parseJson($composer, $resource);
             if (empty($composer['time'])) {
                 $resource = $this->getApiUrl() . '/repos/' . $this->owner . '/' . $this->repository . '/commits/' . urlencode($identifier);
                 $commit = JsonFile::parseJson($this->getContents($resource), $resource);
                 $composer['time'] = $commit['commit']['committer']['date'];
             }
             if (!isset($composer['support']['source'])) {
                 $label = array_search($identifier, $this->getTags()) ?: array_search($identifier, $this->getBranches()) ?: $identifier;
                 $composer['support']['source'] = sprintf('https://%s/%s/%s/tree/%s', $this->originUrl, $this->owner, $this->repository, $label);
             }
             if (!isset($composer['support']['issues']) && $this->hasIssues) {
                 $composer['support']['issues'] = sprintf('https://%s/%s/%s/issues', $this->originUrl, $this->owner, $this->repository);
             }
         }
         if (preg_match('{[a-f0-9]{40}}i', $identifier)) {
             $this->cache->write($identifier, json_encode($composer));
         }
         $this->infoCache[$identifier] = $composer;
     }
     return $this->infoCache[$identifier];
 }
 /**
  * {@inheritDoc}
  */
 public function getComposerInformation($identifier)
 {
     if ($this->gitDriver) {
         return $this->gitDriver->getComposerInformation($identifier);
     }
     if (preg_match('{[a-f0-9]{40}}i', $identifier) && ($res = $this->cache->read($identifier))) {
         $this->infoCache[$identifier] = JsonFile::parseJson($res);
     }
     if (!isset($this->infoCache[$identifier])) {
         try {
             $resource = 'https://api.github.com/repos/' . $this->owner . '/' . $this->repository . '/contents/composer.json?ref=' . urlencode($identifier);
             $composer = JsonFile::parseJson($this->getContents($resource));
             if (empty($composer['content']) || $composer['encoding'] !== 'base64' || !($composer = base64_decode($composer['content']))) {
                 throw new \RuntimeException('Could not retrieve composer.json from ' . $resource);
             }
         } catch (TransportException $e) {
             if (404 !== $e->getCode()) {
                 throw $e;
             }
             $composer = false;
         }
         if ($composer) {
             $composer = JsonFile::parseJson($composer, $resource);
             if (!isset($composer['time'])) {
                 $resource = 'https://api.github.com/repos/' . $this->owner . '/' . $this->repository . '/commits/' . urlencode($identifier);
                 $commit = JsonFile::parseJson($this->getContents($resource), $resource);
                 $composer['time'] = $commit['commit']['committer']['date'];
             }
             if (!isset($composer['support']['source'])) {
                 $label = array_search($identifier, $this->getTags()) ?: array_search($identifier, $this->getBranches()) ?: $identifier;
                 $composer['support']['source'] = sprintf('https://github.com/%s/%s/tree/%s', $this->owner, $this->repository, $label);
             }
             if (!isset($composer['support']['issues']) && $this->hasIssues) {
                 $composer['support']['issues'] = sprintf('https://github.com/%s/%s/issues', $this->owner, $this->repository);
             }
         }
         if (preg_match('{[a-f0-9]{40}}i', $identifier)) {
             $this->cache->write($identifier, json_encode($composer));
         }
         $this->infoCache[$identifier] = $composer;
     }
     return $this->infoCache[$identifier];
 }
 /**
  * {@inheritDoc}
  */
 public function getComposerInformation($identifier)
 {
     if ($this->gitDriver) {
         return $this->gitDriver->getComposerInformation($identifier);
     }
     if (preg_match('{[a-f0-9]{40}}i', $identifier) && ($res = $this->cache->read($identifier))) {
         $this->infoCache[$identifier] = JsonFile::parseJson($res);
     }
     if (!isset($this->infoCache[$identifier])) {
         $resource = $this->getScheme() . '://api.bitbucket.org/1.0/repositories/' . $this->owner . '/' . $this->repository . '/src/' . $identifier . '/composer.json';
         $file = JsonFile::parseJson($this->getContentsWithOAuthCredentials($resource), $resource);
         if (!is_array($file) || !array_key_exists('data', $file)) {
             return array();
         }
         $composer = JsonFile::parseJson($file['data'], $resource);
         if (empty($composer['time'])) {
             $resource = $this->getScheme() . '://api.bitbucket.org/1.0/repositories/' . $this->owner . '/' . $this->repository . '/changesets/' . $identifier;
             $changeset = JsonFile::parseJson($this->getContentsWithOAuthCredentials($resource), $resource);
             $composer['time'] = $changeset['timestamp'];
         }
         if (!isset($composer['support']['source'])) {
             $label = array_search($identifier, $this->getTags()) ?: array_search($identifier, $this->getBranches()) ?: $identifier;
             if (array_key_exists($label, $tags = $this->getTags())) {
                 $hash = $tags[$label];
             } elseif (array_key_exists($label, $branches = $this->getBranches())) {
                 $hash = $branches[$label];
             }
             if (!isset($hash)) {
                 $composer['support']['source'] = sprintf('https://%s/%s/%s/src', $this->originUrl, $this->owner, $this->repository);
             } else {
                 $composer['support']['source'] = sprintf('https://%s/%s/%s/src/%s/?at=%s', $this->originUrl, $this->owner, $this->repository, $hash, $label);
             }
         }
         if (!isset($composer['support']['issues']) && $this->hasIssues) {
             $composer['support']['issues'] = sprintf('https://%s/%s/%s/issues', $this->originUrl, $this->owner, $this->repository);
         }
         if (preg_match('{[a-f0-9]{40}}i', $identifier)) {
             $this->cache->write($identifier, json_encode($composer));
         }
         $this->infoCache[$identifier] = $composer;
     }
     return $this->infoCache[$identifier];
 }
Exemple #7
0
 /**
  * {@inheritDoc}
  */
 public function getComposerInformation($identifier)
 {
     if ($this->gitDriver) {
         return $this->gitDriver->getComposerInformation($identifier);
     }
     if (!isset($this->infoCache[$identifier])) {
         $composer = $this->getContents($this->getScheme() . '://raw.github.com/' . $this->owner . '/' . $this->repository . '/' . $identifier . '/composer.json');
         if (!$composer) {
             return;
         }
         $composer = JsonFile::parseJson($composer);
         if (!isset($composer['time'])) {
             $commit = JsonFile::parseJson($this->getContents($this->getScheme() . '://api.github.com/repos/' . $this->owner . '/' . $this->repository . '/commits/' . $identifier));
             $composer['time'] = $commit['commit']['committer']['date'];
         }
         $this->infoCache[$identifier] = $composer;
     }
     return $this->infoCache[$identifier];
 }
 /**
  * {@inheritDoc}
  */
 public function getComposerInformation($identifier)
 {
     $this->identifier = $identifier;
     try {
         $composer = parent::getComposerInformation($identifier);
     } catch (TransportException $e) {
         // There is not composer.json file in the root
     }
     $composer = is_array($composer) ? $composer : array();
     $ref = strlen($this->identifier) == 40 ? $this->lookUpRef($this->identifier) : $this->identifier;
     if ($version = $this->getVersion($ref)) {
         $core = $version->getCore();
         $majorSlug = $this->isCore ? '' : "{$version->getMajor()}.x";
         $devBranch = "dev-{$core}.x-{$majorSlug}";
         $composer['extra']['branch-alias'][$devBranch] = $core . '.' . ($majorSlug ?: 'x') . '-dev';
     } else {
         return [];
     }
     // TODO: make configurable?
     if ($core < 7) {
         return [];
     }
     $project = new Project($this->drupalProjectName, $this, $core);
     if (null != ($drupalInformation = $project->getDrupalInformation())) {
         if (isset($drupalInformation[$this->drupalProjectName])) {
             $topInformation = $drupalInformation[$this->drupalProjectName];
         } else {
             $topInformation = current($drupalInformation);
         }
         foreach (array('replace', 'require', 'suggest') as $link) {
             $composer[$link] = isset($composer[$link]) ? $composer[$link] : array();
         }
         foreach (array('replace', 'require', 'suggest') as $link) {
             if (isset($topInformation[$link])) {
                 foreach ($topInformation[$link] as $package => $version) {
                     if (!isset($composer[$link][$package])) {
                         $composer[$link][$package] = $version;
                     }
                 }
             }
         }
         foreach (array_keys($drupalInformation) as $name) {
             if ($name != $this->drupalProjectName) {
                 $composer['replace']["drupal/{$name}"] = 'self.version';
             }
         }
         foreach ($drupalInformation as $info) {
             if ($info['name'] != $topInformation['name']) {
                 foreach ($info['require'] as $package => $version) {
                     if (!isset($composer['suggest'][$package])) {
                         $composer['suggest'][$package] = 'Required by ' . $info['name'];
                     } else {
                         $composer['suggest'][$package] .= ', ' . $info['name'];
                     }
                 }
             }
         }
         $keys = array_diff(array_keys($composer['require']), array_keys($composer['replace']));
         $composer['require'] = array_intersect_key($composer['require'], array_combine($keys, $keys));
         foreach ($composer['require'] as $name => $constraint) {
             if (preg_match('/^\\d+\\.\\d+\\.\\d+$/', $constraint)) {
                 $composer['require'][$name] = "~{$constraint}";
             }
         }
         $composer += array('description' => null, 'require' => array(), 'type' => 'library');
         foreach (array('description', 'type') as $top) {
             $composer[$top] = isset($topInformation[$top]) ? $topInformation[$top] : $composer[$top];
         }
         $composer['name'] = 'drupal/' . $this->drupalProjectName;
         $composer = $this->mergeDefaultMetadata($composer, $project);
         unset($composer['require'][$composer['name']]);
         unset($composer['suggest'][$composer['name']]);
         unset($composer['suggest']['drupal/drupal']);
     }
     return $composer;
 }