Пример #1
0
 /**
  * {@inheritDoc}
  */
 public function getComposerInformation($identifier)
 {
     if ($this->fallbackDriver) {
         return $this->fallbackDriver->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 bitbucket
         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);
         }
         $this->infoCache[$identifier] = $composer;
         if ($this->shouldCache($identifier)) {
             $this->cache->write($identifier, json_encode($composer));
         }
     }
     return $this->infoCache[$identifier];
 }
Пример #2
0
 /**
  * Check if the driver must find the new url.
  *
  * @param string $url The url
  *
  * @return bool
  */
 protected function hasRedirectUrl($url)
 {
     if (null === $this->redirectApi && 0 === strpos($url, $this->getRepositoryApiUrl())) {
         $this->redirectApi = $this->getNewRepositoryUrl();
         if (is_string($this->redirectApi)) {
             $this->cache->write('redirect-api', $this->redirectApi);
         }
     }
     return is_string($this->redirectApi);
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function 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);
         if ($this->shouldCache($identifier)) {
             $this->cache->write($identifier, json_encode($composer));
         }
         $this->infoCache[$identifier] = $composer;
     }
     return $this->infoCache[$identifier];
 }
Пример #4
0
 public function write($file, $contents)
 {
     $absPath = $this->getRoot() . $file;
     if ($this->isEnabled() && !is_dir(dirname($absPath))) {
         @mkdir(dirname($absPath), 0777, true);
     }
     parent::write($file, $contents);
 }
Пример #5
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $config = Factory::createConfig();
     $io = $this->getIO();
     $cachePath = realpath($config->get('cache-repo-dir'));
     if (!$cachePath) {
         $io->write('<info>Cache directory does not exist.</info>');
         return;
     }
     $cache = new Cache($io, $cachePath);
     if (!$cache->isEnabled()) {
         $io->write('<info>Cache is not enabled.</info>');
         return;
     }
     $io->write('<info>Clearing cache in: ' . $cachePath . '</info>');
     $cache->gc(0, 0);
     $io->write('<info>Cache cleared.</info>');
 }
Пример #6
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $config = Factory::createConfig();
     $io = $this->getIO();
     $cachePaths = array('cache-dir' => $config->get('cache-dir'), 'cache-files-dir' => $config->get('cache-files-dir'), 'cache-repo-dir' => $config->get('cache-repo-dir'), 'cache-vcs-dir' => $config->get('cache-vcs-dir'));
     foreach ($cachePaths as $key => $cachePath) {
         $cachePath = realpath($cachePath);
         if (!$cachePath) {
             $io->writeError("<info>Cache directory does not exist ({$key}): {$cachePath}</info>");
             continue;
         }
         $cache = new Cache($io, $cachePath);
         if (!$cache->isEnabled()) {
             $io->writeError("<info>Cache is not enabled ({$key}): {$cachePath}</info>");
             continue;
         }
         $io->writeError("<info>Clearing cache ({$key}): {$cachePath}</info>");
         $cache->gc(0, 0);
     }
     $io->writeError('<info>All caches cleared.</info>');
 }
Пример #7
0
 /**
  * {@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];
 }
Пример #8
0
 /**
  * {@inheritDoc}
  */
 public function getComposerInformation($identifier)
 {
     $identifier = '/' . trim($identifier, '/') . '/';
     if ($res = $this->cache->read($identifier . '.json')) {
         $this->infoCache[$identifier] = JsonFile::parseJson($res);
     }
     if (!isset($this->infoCache[$identifier])) {
         preg_match('{^(.+?)(@\\d+)?/$}', $identifier, $match);
         if (!empty($match[2])) {
             $path = $match[1];
             $rev = $match[2];
         } else {
             $path = $identifier;
             $rev = '';
         }
         try {
             $resource = $path . 'composer.json';
             $output = $this->execute('svn cat', $this->baseUrl . $resource . $rev);
             if (!trim($output)) {
                 return;
             }
         } catch (\RuntimeException $e) {
             throw new TransportException($e->getMessage());
         }
         $composer = JsonFile::parseJson($output, $this->baseUrl . $resource . $rev);
         if (!isset($composer['time'])) {
             $output = $this->execute('svn info', $this->baseUrl . $path . $rev);
             foreach ($this->process->splitLines($output) as $line) {
                 if ($line && preg_match('{^Last Changed Date: ([^(]+)}', $line, $match)) {
                     $date = new \DateTime($match[1], new \DateTimeZone('UTC'));
                     $composer['time'] = $date->format('Y-m-d H:i:s');
                     break;
                 }
             }
         }
         $this->cache->write($identifier . '.json', json_encode($composer));
         $this->infoCache[$identifier] = $composer;
     }
     return $this->infoCache[$identifier];
 }
 /**
  * @dataProvider getAssetTypes
  *
  * @param string $type
  * @param string $filename
  */
 public function testRedirectUrlRepositoryWithCache($type, $filename)
 {
     $originUrl = 'github.com';
     $owner = 'composer-test';
     $repository = 'repo-name';
     $repoUrl = 'http://' . $originUrl . '/' . $owner . '/' . $repository;
     $repoApiUrl = 'https://api.github.com/repos/composer-test/repo-name';
     $repoApiUrlNew = $repoApiUrl . '-new';
     $packageName = $type . '-asset/repo-name';
     $identifier = 'v0.0.0';
     $sha = 'SOMESHA';
     $io = $this->getMockBuilder('Composer\\IO\\IOInterface')->getMock();
     $io->expects($this->any())->method('isInteractive')->will($this->returnValue(true));
     $remoteFilesystem = $this->getMockBuilder('Composer\\Util\\RemoteFilesystem')->setConstructorArgs(array($io))->getMock();
     $remoteFilesystem->expects($this->at(0))->method('getContents')->with($this->equalTo('github.com'), $this->equalTo($repoApiUrlNew), $this->equalTo(false))->will($this->returnValue($this->createJsonComposer(array('master_branch' => 'test_master'))));
     $repoConfig = array('url' => $repoUrl, 'asset-type' => $type, 'filename' => $filename, 'package-name' => $packageName);
     $repoUrl = 'https://github.com/composer-test/repo-name.git';
     /* @var IOInterface $io */
     /* @var RemoteFilesystem $remoteFilesystem */
     $cache = new Cache($io, $this->config->get('cache-repo-dir') . '/' . $originUrl . '/' . $owner . '/' . $repository);
     $cache->write('redirect-api', $repoApiUrlNew);
     $gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, null, $remoteFilesystem);
     $gitHubDriver->initialize();
     $this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha));
     $this->assertEquals('test_master', $gitHubDriver->getRootIdentifier());
     $dist = $gitHubDriver->getDist($sha);
     $this->assertEquals('zip', $dist['type']);
     $this->assertEquals('https://api.github.com/repos/composer-test/repo-name/zipball/SOMESHA', $dist['url']);
     $this->assertEquals($sha, $dist['reference']);
     $source = $gitHubDriver->getSource($sha);
     $this->assertEquals('git', $source['type']);
     $this->assertEquals($repoUrl, $source['url']);
     $this->assertEquals($sha, $source['reference']);
 }
Пример #10
0
 /**
  * @param Cache  $cache      The cache
  * @param string $type       The asset type
  * @param string $identifier The identifier
  * @param array  $composer   The data composer
  * @param bool   $force      Force the write
  */
 public static function writeCache(Cache $cache, $type, $identifier, array $composer, $force = false)
 {
     if (self::isSha($identifier) || $force) {
         $cache->write($type . '-' . $identifier, json_encode($composer));
     }
 }
Пример #11
0
 /**
  * Use the 'newest' themes feed as a form of cache invalidation.
  */
 function cache($providerHash, Cache $cache)
 {
     // get the X newest plugins
     $request = ['browse' => 'new', 'per_page' => self::newestNum, 'fields' => ['name' => false, 'version' => false, 'rating' => false, 'downloaded' => false, 'downloadlink' => false, 'last_updated' => false, 'homepage' => false, 'tags' => false, 'template' => false, 'screenshot_url' => false, 'preview_url' => false, 'author' => false, 'description' => false]];
     try {
         $response = $this->queryAPI('query_themes', $request);
     } catch (RuntimeException $e) {
         if ($this->io->isVerbose()) {
             $this->io->writeError($e->getMessage());
         }
         // invalidate the cache
         return false;
     }
     $newest = [];
     if (!empty($response['themes']) && is_array($response['themes'])) {
         foreach ($response['themes'] as $theme) {
             $newest[] = $theme['slug'];
         }
     }
     // do we even have a provider list and old set of newest to work off of?
     if (is_array($providerHash) && ($lastNewest = $cache->read('newest.json'))) {
         // the newest from the last time we checked
         if ($lastNewest = json_decode($lastNewest)) {
             $newProviders = array_diff($newest, $lastNewest);
             // if the number of new providers is equal to number we pulled, assume there may be more and invalidate the cache
             if (count($newProviders) < self::newestNum) {
                 $url = reset($this->config['url']);
                 foreach ($newProviders as $name) {
                     // full path to this provider in the SVN repo, no trailing slash
                     $providerHash[$name] = "{$url}/{$name}";
                 }
             } else {
                 $providerHash = false;
             }
         } else {
             $providerHash = false;
         }
     }
     // save the newest plugins to the cache
     $cache->write('newest.json', json_encode($newest));
     return $providerHash;
 }