Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function download(PackageInterface $package, $path)
 {
     $url = $package->getDistUrl();
     $realUrl = realpath($url);
     if (false === $realUrl || !file_exists($realUrl) || !is_dir($realUrl)) {
         throw new \RuntimeException(sprintf('Source path "%s" is not found for package %s', $url, $package->getName()));
     }
     if (strpos(realpath($path) . DIRECTORY_SEPARATOR, $realUrl . DIRECTORY_SEPARATOR) === 0) {
         throw new \RuntimeException(sprintf('Package %s cannot install to "%s" inside its source at "%s"', $package->getName(), realpath($path), $realUrl));
     }
     $fileSystem = new Filesystem();
     $this->filesystem->removeDirectory($path);
     $this->io->writeError(sprintf('  - Installing <info>%s</info> (<comment>%s</comment>)', $package->getName(), $package->getFullPrettyVersion()));
     try {
         if (Platform::isWindows()) {
             // Implement symlinks as NTFS junctions on Windows
             $this->filesystem->junction($realUrl, $path);
             $this->io->writeError(sprintf('    Junctioned from %s', $url));
         } else {
             $shortestPath = $this->filesystem->findShortestPath($path, $realUrl);
             $fileSystem->symlink($shortestPath, $path);
             $this->io->writeError(sprintf('    Symlinked from %s', $url));
         }
     } catch (IOException $e) {
         $fileSystem->mirror($realUrl, $path);
         $this->io->writeError(sprintf('    Mirrored from %s', $url));
     }
     $this->io->writeError('');
 }
 /**
  * Retrieve the pattern for the given package.
  *
  * @param \Composer\Package\PackageInterface $package
  *
  * @return string
  */
 public function getPattern(PackageInterface $package)
 {
     if (isset($this->packages[$package->getName()])) {
         return $this->packages[$package->getName()];
     } elseif (isset($this->packages[$package->getPrettyName()])) {
         return $this->packages[$package->getPrettyName()];
     } elseif (isset($this->types[$package->getType()])) {
         return $this->types[$package->getType()];
     }
 }
Esempio n. 3
0
 private function filterRequiredPackages(RepositoryInterface $repo, PackageInterface $package, $bucket = array())
 {
     $requires = array_keys($package->getRequires());
     $packageListNames = array_keys($bucket);
     $packages = array_filter($repo->getPackages(), function ($package) use($requires, $packageListNames) {
         return in_array($package->getName(), $requires) && !in_array($package->getName(), $packageListNames);
     });
     $bucket = $this->appendPackages($packages, $bucket);
     foreach ($packages as $package) {
         $bucket = $this->filterRequiredPackages($repo, $package, $bucket);
     }
     return $bucket;
 }
 /**
  * @param PackageInterface $package
  * @param string $packageSourcePath
  * @return DeploystrategyAbstract
  */
 public function make(PackageInterface $package, $packageSourcePath)
 {
     $strategyName = $this->config->getModuleSpecificDeployStrategy($package->getName());
     $ns = '\\MagentoHackathon\\Composer\\Magento\\Deploystrategy\\';
     $className = $ns . ucfirst($strategyName);
     if (!class_exists($className)) {
         $className = $ns . 'Symlink';
     }
     $strategy = new $className($packageSourcePath, realpath($this->config->getMagentoRootDir()));
     $strategy->setIgnoredMappings($this->config->getModuleSpecificDeployIgnores($package->getName()));
     $strategy->setIsForced($this->config->getMagentoForceByPackageName($package->getName()));
     $mappingParser = $this->parserFactory->make($package, $packageSourcePath);
     $strategy->setMappings($mappingParser->getMappings());
     return $strategy;
 }
Esempio n. 5
0
 /**
  * All descendants' constructors should call this parent constructor
  *
  * @param PackageInterface $aliasOf       The package this package is an alias of
  * @param string           $version       The version the alias must report
  * @param string           $prettyVersion The alias's non-normalized version
  */
 public function __construct(PackageInterface $aliasOf, $version, $prettyVersion)
 {
     parent::__construct($aliasOf->getName());
     $this->version = $version;
     $this->prettyVersion = $prettyVersion;
     $this->aliasOf = $aliasOf;
     $this->stability = VersionParser::parseStability($version);
     $this->dev = $this->stability === 'dev';
     // replace self.version dependencies
     foreach (array('requires', 'devRequires') as $type) {
         $links = $aliasOf->{'get' . ucfirst($type)}();
         foreach ($links as $index => $link) {
             // link is self.version, but must be replacing also the replaced version
             if ('self.version' === $link->getPrettyConstraint()) {
                 $links[$index] = new Link($link->getSource(), $link->getTarget(), new VersionConstraint('=', $this->version), $type, $prettyVersion);
             }
         }
         $this->{$type} = $links;
     }
     // duplicate self.version provides
     foreach (array('conflicts', 'provides', 'replaces') as $type) {
         $links = $aliasOf->{'get' . ucfirst($type)}();
         $newLinks = array();
         foreach ($links as $link) {
             // link is self.version, but must be replacing also the replaced version
             if ('self.version' === $link->getPrettyConstraint()) {
                 $newLinks[] = new Link($link->getSource(), $link->getTarget(), new VersionConstraint('=', $this->version), $type, $prettyVersion);
             }
         }
         $this->{$type} = array_merge($links, $newLinks);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function update(PackageInterface $initial, PackageInterface $target, $path)
 {
     if (!$target->getSourceReference()) {
         throw new \InvalidArgumentException('Package ' . $target->getPrettyName() . ' is missing reference information');
     }
     $name = $target->getName();
     if ($initial->getPrettyVersion() == $target->getPrettyVersion()) {
         $from = $initial->getSourceReference();
         $to = $target->getSourceReference();
         $name .= ' ' . $initial->getPrettyVersion();
     } else {
         $from = $initial->getFullPrettyVersion();
         $to = $target->getFullPrettyVersion();
     }
     $this->io->writeError("  - Updating <info>" . $name . "</info> (<comment>" . $from . "</comment> => <comment>" . $to . "</comment>)");
     $urls = $target->getSourceUrls();
     while ($url = array_shift($urls)) {
         try {
             if (Filesystem::isLocalPath($url)) {
                 $url = realpath($url);
             }
             $this->doUpdate($initial, $target, $path, $url);
             break;
         } catch (\Exception $e) {
             if ($this->io->isDebug()) {
                 $this->io->writeError('Failed: [' . get_class($e) . '] ' . $e->getMessage());
             } elseif (count($urls)) {
                 $this->io->writeError('    Failed, trying the next URL');
             } else {
                 throw $e;
             }
         }
     }
     $this->io->writeError('');
 }
Esempio n. 7
0
 /**
  * Get the installation directory of the package.
  *
  * @param Composer         $composer   The composer instance
  * @param PackageInterface $package    The package instance
  * @param string|null      $installDir The custom installation directory
  *
  * @return string The installation directory
  */
 protected static function getInstallDir(Composer $composer, PackageInterface $package, $installDir = null)
 {
     if (null === $installDir) {
         $installDir = rtrim($composer->getConfig()->get('vendor-dir'), '/') . '/' . $package->getName();
     }
     return rtrim($installDir, '/');
 }
 /**
  * Returns Claromentis application name (folder)
  *
  * @param PackageInterface $package
  *
  * @return string
  */
 protected function getApplicationCode(PackageInterface $package)
 {
     $pkg_name = $package->getName();
     list(, $app_name) = explode('/', $pkg_name);
     $app_name = preg_replace("/-(src|obf|php5?|php7)\$/", '', $app_name);
     return $app_name;
 }
Esempio n. 9
0
 /**
  * Get the primary namespace for a plugin package.
  *
  * @param \Composer\Package\PackageInterface $package composer object
  * @return string The package's primary namespace.
  * @throws \RuntimeException When the package's primary namespace cannot be determined.
  */
 public function primaryNamespace($package)
 {
     $primaryNs = null;
     $autoLoad = $package->getAutoload();
     foreach ($autoLoad as $type => $pathMap) {
         if ($type !== 'psr-4') {
             continue;
         }
         $count = count($pathMap);
         if ($count === 1) {
             $primaryNs = key($pathMap);
             break;
         }
         $matches = preg_grep('#^(\\./)?src/?$#', $pathMap);
         if ($matches) {
             $primaryNs = key($matches);
             break;
         }
         foreach (['', '.'] as $path) {
             $key = array_search($path, $pathMap, true);
             if ($key !== false) {
                 $primaryNs = $key;
             }
         }
         break;
     }
     if (!$primaryNs) {
         throw new RuntimeException(sprintf("Unable to get primary namespace for package %s." . "\nEnsure you have added proper 'autoload' section to your plugin's config", $package->getName()));
     }
     return trim($primaryNs, '\\');
 }
 public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
 {
     $this->initGingerBackend();
     $extra = $package->getExtra();
     $uninstallPluginCommand = new Cqrs\UninstallPluginCommand(array('plugin_name' => $package->getName(), 'plugin_type' => $package->getType(), 'plugin_namespace' => $extra['plugin-namespace'], 'plugin_version' => $package->getVersion()));
     $this->getServiceManager()->get('malocher.cqrs.gate')->getBus()->invokeCommand($uninstallPluginCommand);
     parent::uninstall($repo, $package);
 }
Esempio n. 11
0
 /**
  * Return the install path based on package type.
  *
  * Relies on built-in BaseInstaller behaviour with one exception: silverstripe/framework
  * must be installed to 'sapphire' and not 'framework' if the version is <3.0.0
  *
  * @param  PackageInterface $package
  * @param  string           $frameworkType
  * @return string
  */
 public function getInstallPath(PackageInterface $package, $frameworkType = '')
 {
     if ($package->getName() == 'silverstripe/framework' && preg_match('/^\\d+\\.\\d+\\.\\d+/', $package->getVersion()) && version_compare($package->getVersion(), '2.999.999') < 0) {
         return $this->templatePath($this->locations['module'], array('name' => 'sapphire'));
     } else {
         return parent::getInstallPath($package, $frameworkType);
     }
 }
Esempio n. 12
0
 public function getInstallPath(PackageInterface $package)
 {
     $extra = $package->getExtra();
     if (!$extra['install-name']) {
         throw new \InvalidArgumentException(sprintf('The "%s" application is not set "installer-name" field.' . PHP_EOL . 'Using the following config within your package composer.json will allow this:' . PHP_EOL . '{' . PHP_EOL . '    "name": "vendor/name",' . PHP_EOL . '    "type": "thinksns-app",' . PHP_EOL . '    "extra": {' . PHP_EOL . '        "installer-name": "Demo-Name"' . PHP_EOL . '    }' . PHP_EOL . '}' . PHP_EOL), $package->getName());
     }
     return 'apps/' . $extra['install-name'];
 }
 public function getInstallPath(PackageInterface $package)
 {
     $extra = $this->composer->getPackage()->getExtra();
     if (empty($extra['phpbb-ext-install-dir'])) {
         $extra['phpbb-ext-install-dir'] = 'ext';
     }
     return $extra['phpbb-ext-install-dir'] . '/' . $package->getName();
 }
Esempio n. 14
0
 /**
  * {@inheritDoc}
  */
 public function remove(PackageInterface $package, $path)
 {
     $this->enforceCleanDirectory($path);
     $this->io->write("  - Removing <info>" . $package->getName() . "</info> (<comment>" . $package->getPrettyVersion() . "</comment>)");
     if (!$this->filesystem->removeDirectory($path)) {
         throw new \RuntimeException('Could not completely delete ' . $path . ', aborting.');
     }
 }
 /**
  *
  * @param PackageInterface $package        	
  *
  * @return string a path relative to the root of the composer.json that is being installed.
  */
 public function getInstallPath(PackageInterface $package)
 {
     $type = $package->getType();
     if ($type === 'keeko-core') {
         return 'core';
     }
     return $this->getPackageDir($type) . '/' . $package->getName();
 }
 public function testCreateWithCustomIgnoreSection()
 {
     $extra = array('custom-ignore-files' => array('foo-asset/foo' => array('PATTERN'), 'foo-asset/bar' => array()));
     $this->rootPackage->expects($this->any())->method('getExtra')->will($this->returnValue($extra));
     $manager = IgnoreFactory::create($this->composer, $this->package, null, 'custom-ignore-files');
     $this->assertTrue($manager->isEnabled());
     $this->assertTrue($manager->hasPattern());
     $this->validateInstallDir($manager, $this->config->get('vendor-dir') . '/' . $this->package->getName());
 }
 /**
  * Add symlinks for Contao sources after installing a package.
  *
  * {@inheritdoc}
  */
 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('');
 }
 /**
  *
  * @param PackageInterface $package        	
  *
  * @return string a path relative to the root of the composer.json that is being installed.
  */
 public function getInstallPath(PackageInterface $package)
 {
     // custom install path only when it is the keeko/keeko package
     if ($this->root->getName() == 'keeko/keeko') {
         return 'packages/' . $package->getName();
     }
     // ... anyway return the default
     return parent::getInstallPath($package);
 }
 private function handlePackage(PackageInterface $package)
 {
     $packageId = $package->getName();
     foreach ($this->repo->getPackages() as $repoPackage) {
         if ($packageId === $repoPackage->getName()) {
             return true;
         }
     }
     return false;
 }
 /**
  * getPackageBasePath
  *
  * @param PackageInterface $package package being installed
  *
  * @return string install path relative to composer.json
  */
 public function getInstallPath(PackageInterface $package)
 {
     $moddir = explode('/', $package->getName());
     $xoops_modules = '../modules/';
     $extra = $this->composer->getPackage()->getExtra();
     if (isset($extra['xoops_modules_path'])) {
         $xoops_modules = $extra['xoops_modules_path'];
     }
     return $xoops_modules . $moddir[1];
 }
Esempio n. 21
0
 public function remove(PackageInterface $package, $path)
 {
     $this->io->write("  - Removing <info>" . $package->getName() . "</info> (<comment>" . $package->getPrettyVersion() . "</comment>)");
     $this->cleanChanges($package, $path, false);
     if (!$this->filesystem->removeDirectory($path)) {
         if (!defined('PHP_WINDOWS_VERSION_BUILD') || usleep(250) && !$this->filesystem->removeDirectory($path)) {
             throw new \RuntimeException('Could not completely delete ' . $path . ', aborting.');
         }
     }
 }
Esempio n. 22
0
 /**
  * {@inheritDoc}
  */
 public function update(PackageInterface $initial, PackageInterface $target, $path)
 {
     if (!$target->getSourceReference()) {
         throw new \InvalidArgumentException('Package ' . $target->getPrettyName() . ' is missing reference information');
     }
     $this->io->write("  - Package <info>" . $target->getName() . "</info> (<comment>" . $target->getPrettyVersion() . "</comment>)");
     $this->enforceCleanDirectory($path);
     $this->doUpdate($initial, $target, $path);
     $this->io->write('');
 }
 /**
  * @param PackageInterface $package
  * @param string $packageSourcePath
  * @return DeploystrategyAbstract
  */
 public function make(PackageInterface $package, $packageSourcePath)
 {
     $strategyName = $this->config->getDeployStrategy();
     if ($this->config->hasDeployStrategyOverwrite()) {
         $moduleSpecificDeployStrategies = $this->config->getDeployStrategyOverwrite();
         if (isset($moduleSpecificDeployStrategies[$package->getName()])) {
             $strategyName = $moduleSpecificDeployStrategies[$package->getName()];
         }
     }
     if (!isset(static::$strategies[$strategyName])) {
         $className = static::$strategies['symlink'];
     } else {
         $className = static::$strategies[$strategyName];
     }
     $strategy = new $className($packageSourcePath, realpath($this->config->getMagentoRootDir()));
     $strategy->setIgnoredMappings($this->config->getModuleSpecificDeployIgnores($package->getName()));
     $strategy->setIsForced($this->config->getMagentoForceByPackageName($package->getName()));
     return $strategy;
 }
Esempio n. 24
0
 /**
  * @param PackageInterface $package
  * @param string $packageSourceDirectory
  * @return Entry
  */
 public function make(PackageInterface $package, $packageSourceDirectory)
 {
     $entry = new Entry();
     $entry->setPackageName($package->getName());
     $strategy = $this->deploystrategyFactory->make($package, $packageSourceDirectory);
     $mappingParser = $this->parserFactory->make($package, $packageSourceDirectory);
     $strategy->setMappings($mappingParser->getMappings());
     $entry->setDeployStrategy($strategy);
     return $entry;
 }
Esempio n. 25
0
 /**
  * {@inheritdoc}
  */
 public function download(PackageInterface $package, $path)
 {
     $fileSystem = new Filesystem();
     $this->filesystem->removeDirectory($path);
     $this->io->writeError(sprintf('  - Installing <info>%s</info> (<comment>%s</comment>) from %s', $package->getName(), $package->getFullPrettyVersion(), $package->getDistUrl()));
     try {
         $fileSystem->symlink($package->getDistUrl(), $path);
     } catch (IOException $e) {
         $fileSystem->mirror($package->getDistUrl(), $path);
     }
 }
Esempio n. 26
0
 /**
  * {@inheritDoc}
  */
 public function getInstallPath(PackageInterface $package)
 {
     $packageType = $package->getType();
     if (!isset($this->locations[$packageType])) {
         throw new \InvalidArgumentException(sprintf('Package type "%s" is not supported', $packageType));
     }
     list($vendor, $name) = explode('/', strtolower($package->getName()), 2);
     $extra = $package->getExtra();
     $path = str_replace(['{$vendor}', '{$name}', '{$extra.dir}'], [$vendor, $name, $extra['dir']], $this->locations[$packageType]);
     return $this->vendorDir . '/' . $path;
 }
 /**
  * Retrieve first part of from path
  *
  * @return string
  */
 protected function getFirstPartOfFromPath()
 {
     $mapFrom = $this->getMapFrom();
     if ($mapFrom == '*') {
         $mapFrom = '';
     }
     if (substr($mapFrom, -2, 2) == DIRECTORY_SEPARATOR . '*') {
         $mapFrom = substr($mapFrom, 0, strlen($mapFrom) - 1);
     }
     return 'vendor/' . $this->package->getName() . '/' . $mapFrom;
 }
Esempio n. 28
0
 /**
  * @param PackageInterface $package
  * @param string $sourceDir
  * @return Parser
  * @throws \ErrorException
  */
 public function make(PackageInterface $package, $sourceDir)
 {
     $moduleSpecificMap = $this->config->getMagentoMapOverwrite();
     if (isset($moduleSpecificMap[$package->getName()])) {
         $map = $moduleSpecificMap[$package->getName()];
         return new MapParser($map);
     }
     $extra = $package->getExtra();
     if (isset($extra['map'])) {
         return new MapParser($extra['map']);
     }
     if (isset($extra['package-xml'])) {
         return new PackageXmlParser(sprintf('%s/%s', $sourceDir, $extra['package-xml']));
     }
     $modmanFile = sprintf('%s/modman', $sourceDir);
     if (file_exists($modmanFile)) {
         return new ModmanParser($modmanFile);
     }
     throw new \ErrorException(sprintf('Unable to find deploy strategy for module: "%s" no known mapping' . PHP_EOL . 'sourceDir: "%s"', $package->getName(), $sourceDir));
 }
Esempio n. 29
0
 /**
  * {@inheritDoc}
  */
 public function download(PackageInterface $package, $path)
 {
     $url = $package->getDistUrl();
     $checksum = $package->getDistSha1Checksum();
     if (!is_dir($path)) {
         if (file_exists($path)) {
             throw new \UnexpectedValueException($path . ' exists and is not a directory');
         }
         if (!mkdir($path, 0777, true)) {
             throw new \UnexpectedValueException($path . ' does not exist and could not be created');
         }
     }
     $fileName = rtrim($path . '/' . md5(time() . rand()) . '.' . pathinfo($url, PATHINFO_EXTENSION), '.');
     $this->io->write("  - Package <info>" . $package->getName() . "</info> (<comment>" . $package->getPrettyVersion() . "</comment>)");
     if (!extension_loaded('openssl') && (0 === strpos($url, 'https:') || 0 === strpos($url, 'http://github.com'))) {
         // bypass https for github if openssl is disabled
         if (preg_match('{^https?://(github.com/[^/]+/[^/]+/(zip|tar)ball/[^/]+)$}i', $url, $match)) {
             $url = 'http://nodeload.' . $match[1];
         } else {
             throw new \RuntimeException('You must enable the openssl extension to download files via https');
         }
     }
     $rfs = new RemoteFilesystem($this->io);
     $rfs->copy($package->getSourceUrl(), $url, $fileName);
     $this->io->write('');
     if (!file_exists($fileName)) {
         throw new \UnexpectedValueException($url . ' could not be saved to ' . $fileName . ', make sure the' . ' directory is writable and you have internet connectivity');
     }
     if ($checksum && hash_file('sha1', $fileName) !== $checksum) {
         throw new \UnexpectedValueException('The checksum verification of the archive failed (downloaded from ' . $url . ')');
     }
     $this->io->write('    Unpacking archive');
     $this->extract($fileName, $path);
     $this->io->write('    Cleaning up');
     unlink($fileName);
     // If we have only a one dir inside it suppose to be a package itself
     $contentDir = glob($path . '/*');
     if (1 === count($contentDir)) {
         $contentDir = $contentDir[0];
         // Rename the content directory to avoid error when moving up
         // a child folder with the same name
         $temporaryName = md5(time() . rand());
         rename($contentDir, $temporaryName);
         $contentDir = $temporaryName;
         foreach (array_merge(glob($contentDir . '/.*'), glob($contentDir . '/*')) as $file) {
             if (trim(basename($file), '.')) {
                 rename($file, $path . '/' . basename($file));
             }
         }
         rmdir($contentDir);
     }
     $this->io->write('');
 }
Esempio n. 30
0
 /**
  * All descendants' constructors should call this parent constructor
  *
  * @param PackageInterface $aliasOf       The package this package is an alias of
  * @param string           $version       The version the alias must report
  * @param string           $prettyVersion The alias's non-normalized version
  */
 public function __construct(PackageInterface $aliasOf, $version, $prettyVersion)
 {
     parent::__construct($aliasOf->getName());
     $this->version = $version;
     $this->prettyVersion = $prettyVersion;
     $this->aliasOf = $aliasOf;
     $this->stability = VersionParser::parseStability($version);
     $this->dev = $this->stability === 'dev';
     foreach (array('requires', 'devRequires', 'conflicts', 'provides', 'replaces') as $type) {
         $links = $aliasOf->{'get' . ucfirst($type)}();
         $this->{$type} = $this->replaceSelfVersionDependencies($links, $type);
     }
 }