Downloads specific package into specific folder

VCS repository will be created in a separated folder.

@param PackageInterface $package
@param string $path
@param string $url
@throws FilesystemException
168879
public function doDownload(PackageInterface $package, $path, $url)
    {
        GitUtil::cleanEnv();
        $path = $this->normalizePath($path);

        if (!$this->isRequiredRepository($path, $url)) {
            throw new FilesystemException('Unknown repository installed into ' . $path);
        }

        $ref = $package->getSourceReference();
        if ($this->io->isVerbose()) {
            $this->io->write('    Multi-repository path: ' . $path);
        }
        if (!$this->isRepositoryCloned($path)) {
            $this->io->write('    Multi-repository GIT directory not found. Cloning...');
            $this->cloneRepository($package, $path, $url);
        } else {
            $this->io->write('    Multi-repository GIT directory found. Fetching changes...');
            $this->fetchRepositoryUpdates($package, $path, $url);
        }

        if ($newRef = $this->updateToCommit($path, $ref, $package->getPrettyVersion(), $package->getReleaseDate())) {
            if ($package->getDistReference() === $package->getSourceReference()) {
                $package->setDistReference($newRef);
            }
            $package->setSourceReference($newRef);
        }

        //copy file into required directory
        $this->copyFilesToDefaultPath($path);
    }
289458
public function addPublicDirectory(string $package, string $path) : self
    {
        $this->publicDirectories->put($package, $path);

        return $this;
    }
559820
public function updatePackage(PackageInterface $package, InstallerInterface $installer)
    {
        if (!$this->isPackageInstalled($package)) {
            throw new RuntimeException(sprintf('Package %s is not installed.', $package->getName()));
        }
        if (is_null($package->getRequiredVersion())) {
            $decode = $this->config->getBowerFileContent();
            if (empty($decode['dependencies']) || empty($decode['dependencies'][$package->getName()])) {
                throw new InvalidArgumentException(sprintf('Package %s not found in bower.json', $package->getName()));
            }
            $package->setRequiredVersion($decode['dependencies'][$package->getName()]);
        }

        $bower = $this->config->getPackageBowerFileContent($package);
        $package->setInfo($bower);
        $package->setVersion($bower['version']);
        $package->setRequires(isset($bower['dependencies']) ? $bower['dependencies'] : null);

        $packageTag = $this->getPackageTag($package);
        $this->output->writelnInfoPackage($package, 'validate', sprintf('%s against %s#%s', $packageTag, $package->getName(), $package->getRequiredVersion()));

        $package->setRepository($this->repository);
        if ($packageTag == $package->getVersion()) {
            // if version is fully matching, there's no need to update
            return;
        }
        $package->setVersion($packageTag);

        $this->cachePackage($package);

        $this->output->writelnUpdatingPackage($package);
        $installer->update($package);

        $overrides = $this->config->getOverrideFor($package->getName());
        if (array_key_exists('dependencies', $overrides)) {
            $dependencies = $overrides['dependencies'];
        } else {
            $dependencies = $package->getRequires();
        }
        if (!empty($dependencies)) {
            foreach ($dependencies as $name => $requiredVersion) {
                $depPackage = new Package($name, $requiredVersion);
                if (!$this->isPackageInstalled($depPackage)) {
                    $this->installPackage($depPackage, $installer, true);
                } elseif ($this->isNeedUpdate($depPackage)) {
                    $this->updatePackage($depPackage, $installer);
                }
            }
        }
    }
581726
protected function uninstallEntryFiles(PackageInterface $package)
    {
        foreach ($this->getEntryFileLocations($package) as $dest) {
            $unlinked = $this->filesystem->unlinkFile($dest);

            $this->io->notice(
                sprintf(
                    '    <fg=default>Removing <fg=magenta>%1$s</> -</> %2$s',
                    $dest,
                    $unlinked ? '<fg=green>OK</>' : '<fg=red>FAILED</>'
                )
            );

            if (! $unlinked) {
                throw new RuntimeException('Cannot unlink ' . $dest);
            }
        }
    }
501689
protected function installGitignore(PackageInterface $package)
    {
        $installPath = $this->getInstallPath($package) . '/.gitignore';
        $templatePath = $this->getTempPath($package) . '/.gitignore.template';
        
        $data = ['APP_PUBLIC' => $this->plugin->getPublicDirectory()];
        
        if (! file_exists($installPath)) {
            return $this->compileTemplate($templatePath, $installPath, $data);
        }
        
        $downloadGitignore = $this->compileTemplate($templatePath, $data);
        $installGitignore = file_get_contents($installPath);
        
        $gitignore = preg_split('/\r?\n/', $downloadGitignore . PHP_EOL . '# User rules' . PHP_EOL . $installGitignore);
        $group = 'user rules';
        $groups = [];
        $rules = [];
        
        $groups['user rules'] = [];
        
        foreach ($gitignore as $rule) {
            if (preg_match('/^#\s*(.*)/', $rule, $matches)) {
                $group = strtolower($matches[1]);
                
                if (! isset($groups[$group])) {
                    $groups[$group] = [];
                }
            } elseif (! preg_match('/^\s*$/', $rule) && ! in_array($rule, $rules)) {
                $groups[$group][] = $rules[] = $rule;
            }
        }
        
        $gitignore = [];
        
        foreach ($groups as $group => $rules) {
            if (! count($rules) || $group == 'user rules') {
                continue;
            }
            
            $this->sortRules($rules);
            
            $gitignore[] = '# ' . ucfirst($group);
            $gitignore = array_merge($gitignore, $rules);
            $gitignore[] = '';
        }
        
        $this->sortRules($groups['user rules']);
        
        $gitignore[] = '# User rules';
        $gitignore = array_merge($gitignore, $groups['user rules']);
        $gitignore[] = '';
        
        file_put_contents($installPath, implode(PHP_EOL, $gitignore));
    }
898208
public function getFileList( PackageInterface $package, $map ) {
    $directory = $this->getDirectory( $package );
    $result    = [];

    try {

      foreach( $map as $source => $destination ) {
        if( !is_dir( $directory . $source ) ) $result[ $directory . $source ] = Autoload::DIRECTORY . $destination;
        else {

          $iterator = new \RecursiveIteratorIterator(
            new \RecursiveDirectoryIterator( $directory . $source, \RecursiveDirectoryIterator::SKIP_DOTS ),
            \RecursiveIteratorIterator::SELF_FIRST
          );

          foreach( $iterator as $item ) {
            /** @var SplFileInfo $item */
            if( !$item->isDir() ) {
              $result[ $item->getRealPath() ] = Autoload::DIRECTORY . $destination . DIRECTORY_SEPARATOR . call_user_func( [ $iterator, 'getSubPathName' ] );
            }
          }
        }
      }

    } catch( \Throwable $e ) {
      $this->io->writeError( "Spoom\\Composer: Skip {$package->getPrettyName()} public copy, due to an error" );
    }

    return $result;
  }
1030943
protected function postInstallActions($type, $downloadPath, PackageInterface $package){
		switch ($type)
		{
            case 'pff2-module':
                $this->moveConfiguration($downloadPath, $package);
                $this->updatePff();
                break;
            case 'pff2-core':
                $this->initPff();
                $this->updatePff();
                break;
		}
	}
1065098
public function register(string $path, array $data = [], $package = null)
    {
        $packageResolver = $this->getPackageResolver();

        if ($package && !$package instanceof AbstractPackage) {
            $package = $packageResolver->getPackage($package);
        }

        // Workaround that RouteCreator should always be new one.
        $routerCreator = new RouteCreator($packageResolver);

        $routerCreator
            ->group('root')
            ->setOptions($data)
            ->register(function (RouteCreator $router) use ($path) {
                $router->load($path);
            });

        // TODO: Maybe move this handler to outside that support register() twice wothout side effect.
        foreach ($routerCreator->getRoutes() as $name => $route) {
            $route = $this->routeCreator->handleRoute($route);

            $this->addRouteByConfig(
                $route->getName(),
                $route->getOptions(),
                $package ?: $route->getOption('package')
            );
        }

        return $this;
    }
895088
protected function createClassDirectory(Package $package, $directory)
	{
		$path = $directory.'/src/'.$package->vendor.'/'.$package->name;

		if ( ! $this->files->isDirectory($path))
		{
			$this->files->makeDirectory($path, 0777, true);
		}

		return $path;
	}
970181
protected function installLoader(PackageInterface $package)
    {
        $source = $this->getLoaderFilePackagePath($package);
        $target = $this->getLoaderFileInstallPath($package);

        copy($source, $target);
    }
35968
protected function uninstallPackage(PackageInterface $package)
    {
        $uninstallOperation = new UninstallOperation($package, 'Removing package so it can be re-installed and re-patched.');
        $this->io->write('<info>Removing package '.$package->getName().' so that it can be re-installed and re-patched.</info>');
        $installationManager = $this->composer->getInstallationManager();
        $repositoryManager = $this->composer->getRepositoryManager();
        $localRepository = $repositoryManager->getLocalRepository();
        $installationManager->uninstall($localRepository, $uninstallOperation);
    }
421940
protected function collectPatchesFromPackage(PackageInterface $package)
    {
        $collectedPatches = new PatchCollection();
        $extra = $package->getExtra();
        if (isset($extra['patches'])) {
            $this->io->write('<info>Gathering patches from '.$package->getName().' (extra.patches).</info>');
            $collectedPatches->merge($this->resolveExplicitList($package, $extra['patches']));
        }
        if (isset($extra['patches-file'])) {
            $this->io->write('<info>Gathering patches from '.$package->getName().' (extra.patches-file).</info>');
            $collectedPatches->merge($this->resolveJsonFile($package, $extra['patches-file']));
        }

        return $collectedPatches;
    }
186432
public function isPackageInstalled(PackageInterface $package)
    {
        return $this->filesystem->exists($this->config->getInstallDir() . '/' . $package->getName() . '/.bower.json');
    }
93826
protected function _removeAutoloader(PackageInterface $package)
    {
        $path = $this->_getAutoloaderPath($package);

        if(file_exists($path))
        {
            $contents = file_get_contents($path);

            if (strpos($contents, 'This file has been generated automatically by Composer.') !== false) {
                unlink($path);
            }
        }
    }
206328
public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
    {
        $this->logVerbose(sprintf('Installing Contao sources for %s', $package->getName()));

        parent::install($repo, $package);

        $this->addSymlinks($package, $this->getContaoRoot(), $this->getSources($package));
        $this->addCopies($package, $this->getFilesRoot(), $this->getUserFiles($package), self::DUPLICATE_IGNORE);
        $this->addRunonces($package, $this->getRunonces($package));

        $this->logVerbose('');
    }
735736
protected function installRouting(AbstractPackage $package)
    {
        if (!(new BooleanPrompter)->ask('Do your want to add routing profile to <comment>etc/routing.php</comment>? [Y/n]: ',
            true)) {
            return;
        }

        $pattern = (new TextPrompter)->ask('The URL pattern prefix [<info>/' . $package->name . '</info>]: ',
            '/' . $package->name);

        $routing = <<<ROUTE

// Routing of package: %s
\$router->registerPackage('%s', '%s');

ROUTE;

        $routing = sprintf($routing, $package->name, $package->name, $pattern);

        $target = $this->console->get('path.etc') . '/routing.php';

        $content = file_get_contents($target);
        $content .= $routing;

        file_put_contents($target, $content);

        $this->out()->out('  Added routing profile to <comment>etc/routing.php</comment>');
    }
230528
public static function enablePackage(PackageInterface $package)
    {
        $packageRepository = Factory::makePackageRepository($package);
        $bundleFactory = Factory::makeBundleFactory();
        $kernelManipulator = Factory::makeKernelManipulator();

        $composerPackage = $packageRepository->findOneByName($package->getName());
        $bundle = $bundleFactory->make($composerPackage->namespace);

        $kernelManipulator->addBundle($bundle->fullyQualifiedClassname);
    }