Example #1
0
 /**
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $processExecutor = new \Composer\Util\ProcessExecutor();
     $repositoryName = $input->getArgument('name');
     $repositoryDir = ROOT . '/repositories/' . $repositoryName;
     if (file_exists($repositoryDir)) {
         $output->writeln('Removing repository ' . $repositoryName);
         $processExecutor->execute('rm -rf ' . $repositoryDir);
     } else {
         throw new \Exception('Repository ' . $repositoryName . ' does not exist.');
     }
 }
Example #2
0
 /**
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $processExecutor = new \Composer\Util\ProcessExecutor();
     $composerUrl = $input->getArgument('composerUrl');
     $repositoryName = $input->getArgument('name');
     $repositoryUrl = rtrim($input->getOption('base-url'), '/') . '/' . $repositoryName;
     $targetDir = rtrim($input->getOption('base-dir'), '/') . '/' . $repositoryName;
     $cacheDir = rtrim($input->getOption('cache-dir'), '/') . '/' . $repositoryName;
     if ($input->getOption('clean-cache')) {
         $output->writeln('Cleaning cached sources');
         $processExecutor->execute('rm -rf ' . escapeshellarg($cacheDir));
     }
     $output->writeln(sprintf('Creating repository "%s"', $repositoryName));
     if (!is_dir($cacheDir)) {
         mkdir($cacheDir, 0777, true);
     }
     putenv('COMPOSER_VENDOR_DIR=' . $cacheDir);
     putenv('COMPOSER_BIN_DIR=' . $cacheDir . '/bin');
     $output->writeln(sprintf('Loading composer file "%s"', $composerUrl));
     $json = new \Composer\Json\JsonFile($composerUrl);
     $jsonData = $originalJsonData = $json->read();
     // if 'require-only-dependencies-of' is found, rewrite json data to composer format
     if (isset($originalJsonData['require-only-dependencies-of'])) {
         $jsonData['require'] += $jsonData['require-only-dependencies-of'];
         unset($jsonData['require-only-dependencies-of']);
         $composerUrl = $cacheDir . '/broker.json';
         $composerJson = new \Composer\Json\JsonFile($composerUrl);
         $composerJson->write($jsonData);
     }
     $io = new \Composer\IO\ConsoleIO($input, $output, $this->getHelperSet());
     $composer = \Composer\Factory::create($io, $composerUrl);
     /*
      * add custom pear installer to fix binary and setup issues
      */
     $customPearInstaller = new \rg\broker\customizations\PearInstaller($io, $composer, 'pear-library');
     $composer->getInstallationManager()->addInstaller($customPearInstaller);
     $composer->setLocker(new \rg\broker\customizations\Locker());
     $installer = \Composer\Installer::create($io, $composer);
     $installer->setRunScripts(false);
     $installer->setPreferDist(true);
     $installer->setUpdate(true);
     if (!$installer->run()) {
         $output->writeln('Composer installer failed!');
         return 1;
     }
     if (file_exists($targetDir)) {
         $processExecutor->execute('rm -rf ' . $targetDir);
     }
     mkdir($targetDir, 0777, true);
     mkdir($targetDir . '/dists');
     $packages = array('packages' => array());
     $dumper = new \Composer\Package\Dumper\ArrayDumper();
     $installedPackages = $this->getInstalledPackages($cacheDir);
     $localRepo = $composer->getRepositoryManager()->getLocalRepository();
     $output->writeln('Creating dists for packages');
     foreach ($installedPackages as $installedPackage) {
         /** @var \Composer\Package\PackageInterface $package  */
         $package = $localRepo->findPackage($installedPackage['name'], $installedPackage['version']);
         // skip if package was in 'require-only-dependencies-of' section
         if (isset($originalJsonData['require-only-dependencies-of'][$package->getName()]) || isset($originalJsonData['require-only-dependencies-of'][$package->getPrettyName()])) {
             continue;
         }
         $zipfileName = $this->createZipFile($cacheDir, $targetDir, $package, $output, $processExecutor);
         $packageArray = $this->getPackageArray($targetDir, $repositoryUrl, $dumper, $package, $zipfileName);
         $packages['packages'][$package->getPrettyName()][$package->getPrettyVersion()] = $packageArray;
     }
     ksort($packages['packages'], SORT_STRING);
     $output->writeln('Writing packages.json');
     $repoJson = new \Composer\Json\JsonFile($targetDir . '/packages.json');
     $repoJson->write($packages);
 }
Example #3
0
 /**
  * @param string $source
  * @param string $target
  * @param bool $copyOnFailure
  * @param bool $makeRelative Create a relative link instead of an absolute
  */
 public function symlink($source, $target, $copyOnFailure = TRUE, $makeRelative = TRUE)
 {
     if (!file_exists($source)) {
         throw new \InvalidArgumentException('The symlink source "' . $source . '" is not available.');
     }
     if (file_exists($target)) {
         throw new \InvalidArgumentException('The symlink target "' . $target . '" already exists.');
     }
     // As Windows needs a relative path with backslashes, we ensure the proper directory separator is used
     $symlinkSource = strtr($makeRelative ? $this->findShortestPath($target, $source) : $source, '/', DIRECTORY_SEPARATOR);
     $symlinkTarget = strtr($target, '/', DIRECTORY_SEPARATOR);
     $symlinkSuccessfull = @symlink($symlinkSource, $symlinkTarget);
     if (!$symlinkSuccessfull && !stristr(PHP_OS, 'darwin') && !stristr(PHP_OS, 'cygwin') && stristr(PHP_OS, 'win')) {
         // Try fallback to mklink for Windows, because symlink can't handle relative paths starting with "..\"
         $output = NULL;
         $parameter = is_dir($source) ? ' /D' : '';
         $processExecutor = new \Composer\Util\ProcessExecutor();
         $symlinkSuccessfull = $processExecutor->execute('mklink' . $parameter . ' ' . escapeshellarg($symlinkTarget) . ' ' . escapeshellarg($symlinkSource), $output) === 0;
     }
     if (!$symlinkSuccessfull && !$copyOnFailure) {
         throw new \RuntimeException('Symlinking target "' . $symlinkTarget . '" to source "' . $symlinkSource . '" ("' . $source . '")  failed.', 1430494084);
     } elseif (!$symlinkSuccessfull && $copyOnFailure) {
         try {
             $this->copy($symlinkSource, $symlinkTarget);
         } catch (\Exception $exception) {
             throw new \RuntimeException('Neiter symlinking nor copying target "' . $symlinkTarget . '" to source "' . $symlinkSource . '" ("' . $source . '") worked.', 1430494090);
         }
     }
 }