Exemplo n.º 1
0
 /**
  * Builds the archives of the repository.
  *
  * @param array $packages List of packages to dump
  */
 public function dump(array $packages)
 {
     $helper = new ArchiveBuilderHelper($this->output, $this->config['archive']);
     $directory = $helper->getDirectory($this->outputDir);
     $this->output->writeln(sprintf("<info>Creating local downloads in '%s'</info>", $directory));
     $format = isset($this->config['archive']['format']) ? $this->config['archive']['format'] : 'zip';
     $endpoint = isset($this->config['archive']['prefix-url']) ? $this->config['archive']['prefix-url'] : $this->config['homepage'];
     $includeArchiveChecksum = isset($this->config['archive']['checksum']) ? (bool) $this->config['archive']['checksum'] : true;
     $composerConfig = Factory::createConfig();
     $factory = new Factory();
     $io = new ConsoleIO($this->input, $this->output, $this->helperSet);
     $io->loadConfiguration($composerConfig);
     /* @var \Composer\Downloader\DownloadManager $downloadManager */
     $downloadManager = $factory->createDownloadManager($io, $composerConfig);
     /* @var \Composer\Package\Archiver\ArchiveManager $archiveManager */
     $archiveManager = $factory->createArchiveManager($composerConfig, $downloadManager);
     $archiveManager->setOverwriteFiles(false);
     shuffle($packages);
     /* @var \Composer\Package\CompletePackage $package */
     foreach ($packages as $package) {
         if ($helper->isSkippable($package)) {
             continue;
         }
         $this->output->writeln(sprintf("<info>Dumping '%s'.</info>", $package->getName()));
         try {
             if ('pear-library' === $package->getType()) {
                 // PEAR packages are archives already
                 $filesystem = new Filesystem();
                 $packageName = $archiveManager->getPackageFilename($package);
                 $path = realpath($directory) . '/' . $packageName . '.' . pathinfo($package->getDistUrl(), PATHINFO_EXTENSION);
                 if (!file_exists($path)) {
                     $downloadDir = sys_get_temp_dir() . '/composer_archiver/' . $packageName;
                     $filesystem->ensureDirectoryExists($downloadDir);
                     $downloadManager->download($package, $downloadDir, false);
                     $filesystem->ensureDirectoryExists($directory);
                     $filesystem->rename($downloadDir . '/' . pathinfo($package->getDistUrl(), PATHINFO_BASENAME), $path);
                     $filesystem->removeDirectory($downloadDir);
                 }
                 // Set archive format to `file` to tell composer to download it as is
                 $archiveFormat = 'file';
             } else {
                 $path = $archiveManager->archive($package, $format, $directory);
                 $archiveFormat = $format;
             }
             $archive = basename($path);
             $distUrl = sprintf('%s/%s/%s', $endpoint, $this->config['archive']['directory'], $archive);
             $package->setDistType($archiveFormat);
             $package->setDistUrl($distUrl);
             if ($includeArchiveChecksum) {
                 $package->setDistSha1Checksum(hash_file('sha1', $path));
             }
             $package->setDistReference($package->getSourceReference());
         } catch (\Exception $exception) {
             if (!$this->skipErrors) {
                 throw $exception;
             }
             $this->output->writeln(sprintf("<error>Skipping Exception '%s'.</error>", $exception->getMessage()));
         }
     }
 }
Exemplo n.º 2
0
 private function getDownloadManager()
 {
     if (!$this->downloadManager) {
         $config = Factory::createConfig();
         $factory = new Factory();
         $this->downloadManager = $factory->createDownloadManager($this->getIO(), $config);
     }
     return $this->downloadManager;
 }
Exemplo n.º 3
0
 protected function archive(IOInterface $io, Config $config, $packageName = null, $version = null, $format = 'tar', $dest = '.')
 {
     $factory = new Factory();
     $downloadManager = $factory->createDownloadManager($io, $config);
     $archiveManager = $factory->createArchiveManager($config, $downloadManager);
     if ($packageName) {
         $package = $this->selectPackage($io, $packageName, $version);
         if (!$package) {
             return 1;
         }
     } else {
         $package = $this->getComposer()->getPackage();
     }
     $io->writeError('<info>Creating the archive into "' . $dest . '".</info>');
     $archiveManager->archive($package, $format, $dest);
     return 0;
 }
Exemplo n.º 4
0
 protected function archive(IOInterface $io, Config $config, $packageName = null, $version = null, $format = 'tar', $dest = '.', $fileName = null)
 {
     $factory = new Factory();
     $downloadManager = $factory->createDownloadManager($io, $config);
     $archiveManager = $factory->createArchiveManager($config, $downloadManager);
     if ($packageName) {
         $package = $this->selectPackage($io, $packageName, $version);
         if (!$package) {
             return 1;
         }
     } else {
         $package = $this->getComposer()->getPackage();
     }
     $io->writeError('<info>Creating the archive into "' . $dest . '".</info>');
     $packagePath = $archiveManager->archive($package, $format, $dest, $fileName);
     $fs = new Filesystem();
     $shortPath = $fs->findShortestPath(getcwd(), $packagePath, true);
     $io->writeError('Created: ', false);
     $io->write(strlen($shortPath) < strlen($packagePath) ? $shortPath : $packagePath);
     return 0;
 }
 protected function createDownloadManager(IOInterface $io, Config $config)
 {
     $factory = new Factory();
     return $factory->createDownloadManager($io, $config);
 }
Exemplo n.º 6
0
 /**
  * @param array           $config   Directory where to create the downloads in, prefix-url, etc..
  * @param array           $packages
  * @param InputInterface  $input
  * @param OutputInterface $output
  * @param string          $outputDir
  * @param bool            $skipErrors   If true, any exception while dumping a package will be ignored.
  *
  * @return void
  */
 private function dumpDownloads(array $config, array $packages, InputInterface $input, OutputInterface $output, $outputDir, $skipErrors)
 {
     if (isset($config['archive']['absolute-directory'])) {
         $directory = $config['archive']['absolute-directory'];
     } else {
         $directory = sprintf('%s/%s', $outputDir, $config['archive']['directory']);
     }
     $output->writeln(sprintf("<info>Creating local downloads in '%s'</info>", $directory));
     $format = isset($config['archive']['format']) ? $config['archive']['format'] : 'zip';
     $endpoint = isset($config['archive']['prefix-url']) ? $config['archive']['prefix-url'] : $config['homepage'];
     $skipDev = isset($config['archive']['skip-dev']) ? (bool) $config['archive']['skip-dev'] : false;
     $whitelist = isset($config['archive']['whitelist']) ? (array) $config['archive']['whitelist'] : array();
     $blacklist = isset($config['archive']['blacklist']) ? (array) $config['archive']['blacklist'] : array();
     $includeArchiveChecksum = isset($config['archive']['checksum']) ? (bool) $config['archive']['checksum'] : true;
     $composerConfig = Factory::createConfig();
     $factory = new Factory();
     $io = new ConsoleIO($input, $output, $this->getApplication()->getHelperSet());
     $io->loadConfiguration($composerConfig);
     /* @var \Composer\Downloader\DownloadManager $downloadManager */
     $downloadManager = $factory->createDownloadManager($io, $composerConfig);
     /* @var \Composer\Package\Archiver\ArchiveManager $archiveManager */
     $archiveManager = $factory->createArchiveManager($composerConfig, $downloadManager);
     $archiveManager->setOverwriteFiles(false);
     shuffle($packages);
     /* @var \Composer\Package\CompletePackage $package */
     foreach ($packages as $package) {
         if ('metapackage' === $package->getType()) {
             continue;
         }
         $name = $package->getName();
         if (true === $skipDev && true === $package->isDev()) {
             $output->writeln(sprintf("<info>Skipping '%s' (is dev)</info>", $name));
             continue;
         }
         $names = $package->getNames();
         if ($whitelist && !array_intersect($whitelist, $names)) {
             $output->writeln(sprintf("<info>Skipping '%s' (is not in whitelist)</info>", $name));
             continue;
         }
         if ($blacklist && array_intersect($blacklist, $names)) {
             $output->writeln(sprintf("<info>Skipping '%s' (is in blacklist)</info>", $name));
             continue;
         }
         $output->writeln(sprintf("<info>Dumping '%s'.</info>", $name));
         try {
             if ('pear-library' === $package->getType()) {
                 // PEAR packages are archives already
                 $filesystem = new Filesystem();
                 $packageName = $archiveManager->getPackageFilename($package);
                 $path = realpath($directory) . '/' . $packageName . '.' . pathinfo($package->getDistUrl(), PATHINFO_EXTENSION);
                 if (!file_exists($path)) {
                     $downloadDir = sys_get_temp_dir() . '/composer_archiver/' . $packageName;
                     $filesystem->ensureDirectoryExists($downloadDir);
                     $downloadManager->download($package, $downloadDir, false);
                     $filesystem->ensureDirectoryExists($directory);
                     $filesystem->rename($downloadDir . '/' . pathinfo($package->getDistUrl(), PATHINFO_BASENAME), $path);
                     $filesystem->removeDirectory($downloadDir);
                 }
                 // Set archive format to `file` to tell composer to download it as is
                 $archiveFormat = 'file';
             } else {
                 $path = $archiveManager->archive($package, $format, $directory);
                 $archiveFormat = $format;
             }
             $archive = basename($path);
             $distUrl = sprintf('%s/%s/%s', $endpoint, $config['archive']['directory'], $archive);
             $package->setDistType($archiveFormat);
             $package->setDistUrl($distUrl);
             if ($includeArchiveChecksum) {
                 $package->setDistSha1Checksum(hash_file('sha1', $path));
             }
             $package->setDistReference($package->getSourceReference());
         } catch (\Exception $exception) {
             if (!$skipErrors) {
                 throw $exception;
             }
             $output->writeln(sprintf("<error>Skipping Exception '%s'.</error>", $exception->getMessage()));
         }
     }
 }
Exemplo n.º 7
0
 public function createComposer()
 {
     $cwd = sprintf('%s/%s', getcwd(), '.eva');
     $factory = new Factory();
     if (false) {
         $composer = $factory->createComposer($this->io, $config, true, $cwd);
     }
     //  -----------------
     //  -----------------
     //  -----------------
     $fullLoad = true;
     $composerFile = $cwd . '/manifest.composer.json';
     $file = new JsonFile($composerFile);
     $file->validateSchema(JsonFile::LAX_SCHEMA);
     $localConfig = $file->read();
     //  -----------------
     //  -----------------
     //  -----------------
     // Load config and override with local config/auth config
     //        $config = Factory::createConfig($this->io, $cwd);
     $vendorDir = $cwd . '/manifests/vendor';
     $config = $factory::createConfig($this->io, $cwd);
     $config->merge($localConfig);
     $config->merge(['config' => ['vendor-dir' => $vendorDir]]);
     $localAuthFile = new JsonFile(dirname(realpath($composerFile)) . '/auth.json');
     if ($localAuthFile->exists()) {
         if ($this->io && $this->io->isDebug()) {
             $this->io->writeError('Loading config file ' . $localAuthFile->getPath());
         }
         $config->merge(array('config' => $localAuthFile->read()));
         $config->setAuthConfigSource(new JsonConfigSource($localAuthFile, true));
     }
     // initialize composer
     $composer = new Composer();
     $composer->setConfig($config);
     // initialize event dispatcher
     $dispatcher = new EventDispatcher($composer, $this->io);
     $composer->setEventDispatcher($dispatcher);
     // initialize repository manager
     //        $rm = $this->createRepositoryManager($io, $config, $dispatcher);
     //        $composer->setRepositoryManager($rm);
     $rm = new RepositoryManager($this->io, $config, $dispatcher);
     $rm->setRepositoryClass('composer', ComposerRepository::class);
     $composer->setRepositoryManager($rm);
     // load local repository
     $rm->setLocalRepository(new InstalledFilesystemRepository(new JsonFile($vendorDir . '/composer/installed.json')));
     // load package
     $parser = new VersionParser();
     $guesser = new VersionGuesser($config, new ProcessExecutor($this->io), $parser);
     $loader = new RootPackageLoader($rm, $config, $parser, $guesser);
     $package = $loader->load($localConfig);
     $composer->setPackage($package);
     // initialize installation manager
     $im = new InstallationManager();
     $composer->setInstallationManager($im);
     if ($fullLoad) {
         // initialize download manager
         $dm = $factory->createDownloadManager($this->io, $config, $dispatcher);
         $composer->setDownloadManager($dm);
         // initialize autoload generator
         $generator = new AutoloadGenerator($dispatcher, $this->io);
         $composer->setAutoloadGenerator($generator);
     }
     // add installers to the manager (must happen after download manager is created since they read it out of $composer)
     $im->addInstaller(new Installer\LibraryInstaller($this->io, $composer, null));
     $im->addInstaller(new Installer\PearInstaller($this->io, $composer, 'pear-library'));
     $im->addInstaller(new Installer\PluginInstaller($this->io, $composer));
     $im->addInstaller(new Installer\MetapackageInstaller($this->io));
     //        if ($fullLoad) {
     //            $globalComposer = $this->createGlobalComposer($io, $config, $disablePlugins);
     //            $pm = $this->createPluginManager($io, $composer, $globalComposer);
     //            $composer->setPluginManager($pm);
     //
     //            if (!$disablePlugins) {
     //                $pm->loadInstalledPlugins();
     //            }
     //
     //            // once we have plugins and custom installers we can
     //            // purge packages from local repos if they have been deleted on the filesystem
     //            if ($rm->getLocalRepository()) {
     //                $this->purgePackages($rm->getLocalRepository(), $im);
     //            }
     //        }
     // init locker if possible
     if ($fullLoad && isset($composerFile)) {
         $lockFile = "json" === pathinfo($composerFile, PATHINFO_EXTENSION) ? substr($composerFile, 0, -4) . 'lock' : $composerFile . '.lock';
         $locker = new Locker($this->io, new JsonFile($lockFile, new RemoteFilesystem($this->io, $config)), $rm, $im, file_get_contents($composerFile));
         $composer->setLocker($locker);
     }
     //  -----------------
     //  -----------------
     //  -----------------
     return $composer;
 }