Exemplo n.º 1
0
 public function installProject(IOInterface $io, $packageName, $directory = null, $version = null, $preferSource = false, $installDevPackages = false, $repositoryUrl = null, $disableCustomInstallers = false, $noScripts = false)
 {
     $dm = $this->createDownloadManager($io);
     if ($preferSource) {
         $dm->setPreferSource(true);
     }
     $config = Factory::createConfig();
     if (null === $repositoryUrl) {
         $sourceRepo = new CompositeRepository(Factory::createDefaultRepositories($io, $config));
     } elseif ("json" === pathinfo($repositoryUrl, PATHINFO_EXTENSION)) {
         $sourceRepo = new FilesystemRepository(new JsonFile($repositoryUrl, new RemoteFilesystem($io)));
     } elseif (0 === strpos($repositoryUrl, 'http')) {
         $sourceRepo = new ComposerRepository(array('url' => $repositoryUrl), $io, $config);
     } else {
         throw new \InvalidArgumentException("Invalid repository url given. Has to be a .json file or an http url.");
     }
     $candidates = $sourceRepo->findPackages($packageName, $version);
     if (!$candidates) {
         throw new \InvalidArgumentException("Could not find package {$packageName}" . ($version ? " with version {$version}." : ''));
     }
     if (null === $directory) {
         $parts = explode("/", $packageName, 2);
         $directory = getcwd() . DIRECTORY_SEPARATOR . array_pop($parts);
     }
     // select highest version if we have many
     $package = $candidates[0];
     foreach ($candidates as $candidate) {
         if (version_compare($package->getVersion(), $candidate->getVersion(), '<')) {
             $package = $candidate;
         }
     }
     $io->write('<info>Installing ' . $package->getName() . ' (' . VersionParser::formatVersion($package, false) . ')</info>', true);
     if ($disableCustomInstallers) {
         $io->write('<info>Custom installers have been disabled.</info>');
     }
     if (0 === strpos($package->getPrettyVersion(), 'dev-') && in_array($package->getSourceType(), array('git', 'hg'))) {
         $package->setSourceReference(substr($package->getPrettyVersion(), 4));
     }
     $projectInstaller = new ProjectInstaller($directory, $dm);
     $projectInstaller->install(new InstalledFilesystemRepository(new JsonFile('php://memory')), $package);
     if ($package->getRepository() instanceof NotifiableRepositoryInterface) {
         $package->getRepository()->notifyInstall($package);
     }
     $io->write('<info>Created project in ' . $directory . '</info>', true);
     chdir($directory);
     putenv('COMPOSER_ROOT_VERSION=' . $package->getPrettyVersion());
     $composer = Factory::create($io);
     $installer = Installer::create($io, $composer);
     $installer->setPreferSource($preferSource)->setDevMode($installDevPackages)->setRunScripts(!$noScripts);
     if ($disableCustomInstallers) {
         $installer->disableCustomInstallers();
     }
     $installer->run();
 }
Exemplo n.º 2
0
 public function testSearchWithType()
 {
     $repoConfig = array('url' => 'http://example.org');
     $result = array('results' => array(array('name' => 'foo', 'description' => null)));
     $rfs = $this->getMockBuilder('Composer\\Util\\RemoteFilesystem')->disableOriginalConstructor()->getMock();
     $rfs->expects($this->at(0))->method('getContents')->with('example.org', 'http://example.org/packages.json', false)->willReturn(json_encode(array('search' => '/search.json?q=%query%&type=%type%')));
     $rfs->expects($this->at(1))->method('getContents')->with('example.org', 'http://example.org/search.json?q=foo&type=composer-plugin', false)->willReturn(json_encode($result));
     $repository = new ComposerRepository($repoConfig, new NullIO(), FactoryMock::createConfig(), null, $rfs);
     $this->assertSame(array(array('name' => 'foo', 'description' => null)), $repository->search('foo', RepositoryInterface::SEARCH_FULLTEXT, 'composer-plugin'));
     $this->assertEmpty($repository->search('foo', RepositoryInterface::SEARCH_FULLTEXT, 'library'));
 }
 protected function createPackage(array $data, $class = 'Composer\\Package\\CompletePackage')
 {
     if (isset($data['source']['type']) && $data['source']['type'] === 'svn') {
         $data['source']['type'] = 'svn-export';
     }
     return parent::createPackage($data, $class);
 }
Exemplo n.º 4
0
 public function installProject(IOInterface $io, $packageName, $directory = null, $version = null, $preferSource = false, $repositoryUrl = null)
 {
     $dm = $this->createDownloadManager($io);
     if ($preferSource) {
         $dm->setPreferSource(true);
     }
     if (null === $repositoryUrl) {
         $sourceRepo = new ComposerRepository(array('url' => 'http://packagist.org'));
     } elseif (".json" === substr($repositoryUrl, -5)) {
         $sourceRepo = new FilesystemRepository($repositoryUrl);
     } elseif (0 === strpos($repositoryUrl, 'http')) {
         $sourceRepo = new ComposerRepository(array('url' => $repositoryUrl));
     } else {
         throw new \InvalidArgumentException("Invalid repository url given. Has to be a .json file or an http url.");
     }
     $candidates = $sourceRepo->findPackages($packageName, $version);
     if (!$candidates) {
         throw new \InvalidArgumentException("Could not find package {$packageName}" . ($version ? " with version {$version}." : ''));
     }
     if (null === $directory) {
         $parts = explode("/", $packageName, 2);
         $directory = getcwd() . DIRECTORY_SEPARATOR . array_pop($parts);
     }
     // select highest version if we have many
     $package = $candidates[0];
     foreach ($candidates as $candidate) {
         if (version_compare($package->getVersion(), $candidate->getVersion(), '<')) {
             $package = $candidate;
         }
     }
     $io->write('<info>Installing ' . $package->getName() . ' as new project.</info>', true);
     $projectInstaller = new ProjectInstaller($directory, $dm);
     $projectInstaller->install($package);
     $io->write('<info>Created project into directory ' . $directory . '</info>', true);
     chdir($directory);
     $composer = Factory::create($io);
     $installer = Installer::create($io, $composer);
     $installer->run($preferSource);
 }
 /**
  * Constructor.
  *
  * @param array           $repoConfig
  * @param IOInterface     $io
  * @param Config          $config
  * @param EventDispatcher $eventDispatcher
  */
 public function __construct(array $repoConfig, IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null)
 {
     $repoConfig = array_merge($repoConfig, array('url' => $this->getUrl()));
     $this->repositoryManager = $repoConfig['repository-manager'];
     parent::__construct($repoConfig, $io, $config, $eventDispatcher);
     $this->assetType = Assets::createType($this->getType());
     $this->lazyProvidersUrl = $this->getPackageUrl();
     $this->providersUrl = $this->lazyProvidersUrl;
     $this->searchUrl = $this->getSearchUrl();
     $this->hasProviders = true;
     $this->rm = $repoConfig['repository-manager'];
     $this->packageFilter = isset($repoConfig['vcs-package-filter']) ? $repoConfig['vcs-package-filter'] : null;
     $this->repos = array();
     $this->searchable = (bool) $this->getOption($repoConfig['asset-options'], 'searchable', true);
     $this->fallbackProviders = false;
 }
 /**
  * 
  * @param \Composer\Repository\ComposerRepository $repository
  */
 protected function parseRepository($repository)
 {
     foreach ($repository->getPackages() as $package) {
     }
 }
Exemplo n.º 7
0
 /**
  * Runs the script: connect to packagist, download everything it can!
  */
 public function run()
 {
     // TODO: each package is there twice. Find why.
     $filesystem = new Filesystem();
     if (file_exists(DOWNLOAD_DIR . "/last_analyzed_package")) {
         $lastAnalyzedPackage = file_get_contents(DOWNLOAD_DIR . "/last_analyzed_package");
     } else {
         $lastAnalyzedPackage = "";
     }
     $providerNames = $this->packagistRepository->getProviderNames();
     // If analyzis is over, let's start from the beginning again.
     if ($lastAnalyzedPackage >= $providerNames[count($providerNames) - 1]) {
         $lastAnalyzedPackage = '';
     }
     $this->logger->debug("Starting script.");
     $found = false;
     sort($providerNames);
     foreach ($providerNames as $packageName) {
         if ($this->forcedPackage && $this->forcedPackage != $packageName) {
             continue;
         } else {
             $found = true;
         }
         if (!$this->forcedPackage && $packageName <= $lastAnalyzedPackage) {
             continue;
         }
         // Let's write the name of the last package we are going to analyze
         // We will use it to start again from next package in case this package fails.
         if (!$this->forcedPackage) {
             file_put_contents(DOWNLOAD_DIR . "/last_analyzed_package", $packageName);
         }
         $this->logger->debug("Analyzing {packageName}.", array("packageName" => $packageName));
         //if ($packageName != '10up/wp_mock') continue;
         //var_dump($packagistRepo->findPackages($packageName));
         $packages = $this->packagistRepository->findPackages($packageName);
         $packages = array_filter($packages, function ($package) use($packageName) {
             return $package->getName() == $packageName;
         });
         // Warning: findPackages uses "whatProvides". For instance: symfony/symonfy provides symfony/finder.
         // When a new version of finder is released, we don't want to remove symfony. Therefore, we need to restrict
         // the packages returned by "findPackages"
         $importantPackages = $this->getImportantVersions($packages);
         // DELETE PACKAGES VERSION BEFORE REINSERTION!
         // Only delete packages that are not important anymore.
         $notImportantPackages = array_diff($packages, $importantPackages);
         foreach ($notImportantPackages as $notImportantPackage) {
             if ($this->packageDao->get($notImportantPackage->getName(), $notImportantPackage->getPrettyVersion())) {
                 $this->logger->info("Removing {packageName} {version}. A newer package is available.", array("packageName" => $notImportantPackage->getPrettyName(), "version" => $notImportantPackage->getPrettyVersion()));
                 $this->itemDao->deletePackage($notImportantPackage->getName(), $notImportantPackage->getPrettyVersion());
                 $this->packageDao->deletePackage($notImportantPackage->getName(), $notImportantPackage->getPrettyVersion());
                 $downloadPath = DOWNLOAD_DIR . "/" . $notImportantPackage->getName() . "/" . $notImportantPackage->getPrettyVersion();
                 $filesystem->removeDirectory($downloadPath);
             }
         }
         foreach ($importantPackages as $package) {
             /* @var $package PackageInterface */
             try {
                 // Let's reset to null (in case an exception happens on first line).
                 $packageVersionEntity = null;
                 // Let's get the update date of each version and let's compare it with the one we stored.
                 $packageVersion = $this->packageDao->get($package->getName(), $package->getPrettyVersion());
                 if (!$this->force && (!isset($packageVersion['refresh']) || !$packageVersion['refresh'])) {
                     if ($packageVersion && $packageVersion['releaseDate']->sec == $package->getReleaseDate()->getTimestamp()) {
                         if (isset($packageVersion['onError'])) {
                             if ($packageVersion['onError'] == false || $packageVersion['onError'] == true && !$this->retryOnError) {
                                 $this->logger->debug("{packageName} {version} has not moved since last run. Ignoring.", array("packageName" => $package->getPrettyName(), "version" => $package->getPrettyVersion()));
                                 continue;
                             }
                         }
                     }
                 }
                 $this->itemDao->deletePackage($package->getName(), $package->getPrettyVersion());
                 $this->packageDao->deletePackage($package->getName(), $package->getPrettyVersion());
                 $this->logger->info("Downloading {packageName} {version}{additional}", array("packageName" => $package->getPrettyName(), "version" => $package->getPrettyVersion(), "additional" => isset($packageVersion['refresh']) && $packageVersion['refresh'] ? " (forced via force-refresh)" : ""));
                 //var_dump($package->getDistUrls());
                 //var_dump($package->getSourceUrls());
                 $downloadPath = DOWNLOAD_DIR . "/" . $package->getName() . "/" . $package->getPrettyVersion();
                 $this->downloadManager->download($package, $downloadPath);
                 $packageVersion = $this->packageDao->createOrUpdatePackage($package);
                 $this->classesDetector->storePackage($downloadPath, $packageVersion);
                 $packageVersion['onError'] = false;
                 $packageVersion['errorMsg'] = '';
                 unset($packageVersion['refresh']);
             } catch (\Exception $e) {
                 if (!$packageVersion) {
                     $packageVersion = $this->packageDao->createOrUpdatePackage($package);
                 }
                 $this->logger->error("Package {packageName} {version} failed to download. Exception: " . $e->getMessage() . " - " . $e->getTraceAsString(), array("packageName" => $package->getName(), "version" => $package->getPrettyVersion(), "exception" => $e));
                 $packageVersion['packageName'] = $package->getName();
                 $packageVersion['packageVersion'] = $package->getPrettyVersion();
                 $packageVersion['onError'] = true;
                 $packageVersion['errorMsg'] = $e->getMessage() . "\n" . $e->getTraceAsString();
             }
             $this->packageDao->save($packageVersion);
         }
     }
     if ($this->forcedPackage && !$found) {
         $this->logger->error("Unable to find package '{packageName}'", ['packageName' => $this->forcedPackage]);
     }
     //var_dump("Nb packages: ".count($repositories->getPackages()));
 }
 /**
  * Search for dependencies in multiple packages.
  *
  * @param string[]           $packageNames The package names.
  * @param ComposerRepository $repository   The repository.
  *
  * @return void
  */
 private function searchInPackageNames($packageNames, ComposerRepository $repository)
 {
     foreach ($packageNames as $packageName) {
         try {
             $packages = $repository->findPackages($packageName);
             $this->searchInPackages($packages);
         } catch (\Exception $e) {
             $this->application->renderException($e, $this->output);
         }
     }
 }
Exemplo n.º 9
0
 public function search($query, $mode = 0)
 {
     // if the query exactly matches one of our vendors, return the whole list!
     if (isset($this->vendors[$query])) {
         // make sure the vendor that shows is the vendor they want
         $this->defaultVendor = $query;
         $out = [];
         foreach ($this->getProviderNames() as $provider) {
             $out[] = ['name' => $provider];
         }
         return $out;
     }
     // try running the search handler - see if we get anything
     $results = Util::callFilter($this->repoConfig->get('search-handler'), $query);
     // if the these are the same, default to the normal provider name search
     if ($results === $query) {
         return parent::search($query, $mode);
     }
     return $results;
 }
Exemplo n.º 10
0
 public function installProject(IOInterface $io, $packageName, $directory = null, $packageVersion = null, $preferSource = false, $preferDist = false, $installDevPackages = false, $repositoryUrl = null, $disableCustomInstallers = false, $noScripts = false, $keepVcs = false)
 {
     $config = Factory::createConfig();
     $dm = $this->createDownloadManager($io, $config);
     if ($preferSource) {
         $dm->setPreferSource(true);
     }
     if (null === $repositoryUrl) {
         $sourceRepo = new CompositeRepository(Factory::createDefaultRepositories($io, $config));
     } elseif ("json" === pathinfo($repositoryUrl, PATHINFO_EXTENSION)) {
         $sourceRepo = new FilesystemRepository(new JsonFile($repositoryUrl, new RemoteFilesystem($io)));
     } elseif (0 === strpos($repositoryUrl, 'http')) {
         $sourceRepo = new ComposerRepository(array('url' => $repositoryUrl), $io, $config);
     } else {
         throw new \InvalidArgumentException("Invalid repository url given. Has to be a .json file or an http url.");
     }
     $candidates = array();
     $name = strtolower($packageName);
     if ($packageVersion === null) {
         $sourceRepo->filterPackages(function ($package) use(&$candidates, $name) {
             if ($package->getName() === $name) {
                 $candidates[] = $package;
             }
         });
     } else {
         $parser = new VersionParser();
         $version = $parser->normalize($packageVersion);
         $sourceRepo->filterPackages(function ($package) use(&$candidates, $name, $version) {
             if ($package->getName() === $name && $version === $package->getVersion()) {
                 $candidates[] = $package;
                 return false;
             }
         });
     }
     if (!$candidates) {
         throw new \InvalidArgumentException("Could not find package {$packageName}" . ($packageVersion ? " with version {$packageVersion}." : ''));
     }
     if (null === $directory) {
         $parts = explode("/", $packageName, 2);
         $directory = getcwd() . DIRECTORY_SEPARATOR . array_pop($parts);
     }
     // select highest version if we have many
     $package = $candidates[0];
     foreach ($candidates as $candidate) {
         if (version_compare($package->getVersion(), $candidate->getVersion(), '<')) {
             $package = $candidate;
         }
     }
     unset($candidates);
     $io->write('<info>Installing ' . $package->getName() . ' (' . VersionParser::formatVersion($package, false) . ')</info>');
     if ($disableCustomInstallers) {
         $io->write('<info>Custom installers have been disabled.</info>');
     }
     if (0 === strpos($package->getPrettyVersion(), 'dev-') && in_array($package->getSourceType(), array('git', 'hg'))) {
         $package->setSourceReference(substr($package->getPrettyVersion(), 4));
     }
     $dm->setPreferSource($preferSource)->setPreferDist($preferDist);
     $projectInstaller = new ProjectInstaller($directory, $dm);
     $projectInstaller->install(new InstalledFilesystemRepository(new JsonFile('php://memory')), $package);
     if ($package->getRepository() instanceof NotifiableRepositoryInterface) {
         $package->getRepository()->notifyInstall($package);
     }
     $installedFromVcs = 'source' === $package->getInstallationSource();
     $io->write('<info>Created project in ' . $directory . '</info>');
     chdir($directory);
     putenv('COMPOSER_ROOT_VERSION=' . $package->getPrettyVersion());
     // clean up memory
     unset($dm, $config, $projectInstaller, $sourceRepo, $package);
     // install dependencies of the created project
     $composer = Factory::create($io);
     $installer = Installer::create($io, $composer);
     $installer->setPreferSource($preferSource)->setPreferDist($preferDist)->setDevMode($installDevPackages)->setRunScripts(!$noScripts);
     if ($disableCustomInstallers) {
         $installer->disableCustomInstallers();
     }
     if (!$installer->run()) {
         return 1;
     }
     if (!$keepVcs && $installedFromVcs && (!$io->isInteractive() || $io->askConfirmation('<info>Do you want to remove the existing VCS (.git, .svn..) history?</info> [<comment>Y,n</comment>]? ', true))) {
         $finder = new Finder();
         $finder->depth(0)->directories()->in(getcwd())->ignoreVCS(false)->ignoreDotFiles(false);
         foreach (array('.svn', '_svn', 'CVS', '_darcs', '.arch-params', '.monotone', '.bzr', '.git', '.hg') as $vcsName) {
             $finder->name($vcsName);
         }
         try {
             $fs = new Filesystem();
             $dirs = iterator_to_array($finder);
             unset($finder);
             foreach ($dirs as $dir) {
                 if (!$fs->removeDirectory($dir)) {
                     throw new \RuntimeException('Could not remove ' . $dir);
                 }
             }
         } catch (\Exception $e) {
             $io->write('<error>An error occurred while removing the VCS metadata: ' . $e->getMessage() . '</error>');
         }
     }
     return 0;
 }