protected function setUp() { $this->lazyPackage = $this->getMock('Fxp\\Composer\\AssetPlugin\\Package\\LazyPackageInterface'); $this->assetType = $this->getMock('Fxp\\Composer\\AssetPlugin\\Type\\AssetTypeInterface'); $this->loader = $this->getMock('Composer\\Package\\Loader\\LoaderInterface'); $this->driver = $this->getMock('Composer\\Repository\\Vcs\\VcsDriverInterface'); $this->dispatcher = $this->getMockBuilder('Composer\\EventDispatcher\\EventDispatcher')->disableOriginalConstructor()->getMock(); $this->lazyPackage->expects($this->any())->method('getName')->will($this->returnValue('PACKAGE_NAME')); $this->lazyPackage->expects($this->any())->method('getUniqueName')->will($this->returnValue('PACKAGE_NAME-1.0.0.0')); $this->lazyPackage->expects($this->any())->method('getPrettyVersion')->will($this->returnValue('1.0')); $this->lazyPackage->expects($this->any())->method('getVersion')->will($this->returnValue('1.0.0.0')); $versionConverter = $this->getMock('Fxp\\Composer\\AssetPlugin\\Converter\\VersionConverterInterface'); $versionConverter->expects($this->any())->method('convertVersion')->will($this->returnValue('VERSION_CONVERTED')); $versionConverter->expects($this->any())->method('convertRange')->will($this->returnCallback(function ($value) { return $value; })); $packageConverter = $this->getMock('Fxp\\Composer\\AssetPlugin\\Converter\\PackageConverterInterface'); /* @var LazyPackageInterface $lasyPackage */ $lasyPackage = $this->lazyPackage; $packageConverter->expects($this->any())->method('convert')->will($this->returnCallback(function ($value) use($lasyPackage) { $value['version'] = $lasyPackage->getPrettyVersion(); $value['version_normalized'] = $lasyPackage->getVersion(); return $value; })); $this->assetType->expects($this->any())->method('getComposerVendorName')->will($this->returnValue('ASSET')); $this->assetType->expects($this->any())->method('getComposerType')->will($this->returnValue('ASSET_TYPE')); $this->assetType->expects($this->any())->method('getFilename')->will($this->returnValue('ASSET.json')); $this->assetType->expects($this->any())->method('getVersionConverter')->will($this->returnValue($versionConverter)); $this->assetType->expects($this->any())->method('getPackageConverter')->will($this->returnValue($packageConverter)); $this->driver->expects($this->any())->method('getDist')->will($this->returnCallback(function ($value) { return array('type' => 'vcs', 'url' => 'http://foobar.tld/dist/' . $value); })); $this->driver->expects($this->any())->method('getSource')->will($this->returnCallback(function ($value) { return array('type' => 'vcs', 'url' => 'http://foobar.tld/source/' . $value); })); }
protected function preProcess(VcsDriverInterface $driver, array $data, $identifier) { // keep the name of the main identifier for all packages $data['name'] = $this->packageName ?: $data['name']; if (!isset($data['dist'])) { $data['dist'] = $driver->getDist($identifier); } if (!isset($data['source'])) { $data['source'] = $driver->getSource($identifier); } return $data; }
/** * Initializes the root identifier. * * @param VcsDriverInterface $driver */ protected function initRootIdentifier(VcsDriverInterface $driver) { try { if ($driver->hasComposerFile($driver->getRootIdentifier())) { $data = $driver->getComposerInformation($driver->getRootIdentifier()); $sc = new SemverConverter(); $this->rootPackageVersion = !empty($data['version']) ? $sc->convertVersion(ltrim($data['version'], '^~')) : null; $this->rootData = $data; if (null === $this->packageName) { $this->packageName = !empty($data['name']) ? $data['name'] : null; } } } catch (\Exception $e) { if ($this->verbose) { $this->io->write('<error>Skipped parsing ' . $driver->getRootIdentifier() . ', ' . $e->getMessage() . '</error>'); } } }
/** * Pre process the data of package before the conversion to Package instance. * * @param VcsDriverInterface $driver * @param array $data * @param string $identifier * * @return array */ protected function preProcess(VcsDriverInterface $driver, array $data, $identifier) { $vcsRepos = array(); $data = array_merge($data, $this->packageData); $data = $this->assetType->getPackageConverter()->convert($data, $vcsRepos); $this->dispatchAddVcsEvent($vcsRepos); if (!isset($data['dist'])) { $data['dist'] = $driver->getDist($identifier); } if (!isset($data['source'])) { $data['source'] = $driver->getSource($identifier); } return (array) $data; }
/** * Include the package in the alias package if the branch is a root branch * identifier and having a package version. * * @param VcsDriverInterface $driver The vcs driver * @param PackageInterface $package The package instance * @param string $branch The branch name * * @return PackageInterface|AliasPackage */ protected function includeBranchAlias(VcsDriverInterface $driver, PackageInterface $package, $branch) { if (null !== $this->rootPackageVersion && $branch === $driver->getRootIdentifier()) { $aliasNormalized = $this->normalizeBranchAlias($package); $package = $package instanceof AliasPackage ? $package->getAliasOf() : $package; $package = $this->overrideBranchAliasConfig($package, $aliasNormalized, $branch); $package = $this->addPackageAliases($package, $aliasNormalized); } return $package; }
private function preProcess(VcsDriverInterface $driver, array $data, $identifier) { $data['name'] = $this->packageName ?: $data['name']; if (!isset($data['dist'])) { $data['dist'] = $driver->getDist($identifier); } if (!isset($data['source'])) { $data['source'] = $driver->getSource($identifier); } return $data; }
/** * Include the package in the alias package if the branch is a root branch * identifier and having a package version. * * @param VcsDriverInterface $driver The vcs driver * @param CompletePackageInterface $package The package instance * @param string $branch The branch name * * @return CompletePackageInterface|AliasPackage */ protected function includeBranchAlias(VcsDriverInterface $driver, CompletePackageInterface $package, $branch) { if (null !== $this->rootPackageVersion && $branch === $driver->getRootIdentifier()) { $aliasNormalized = $this->normalizeBranchAlias($package); $package = new AliasPackage($package, $aliasNormalized, $this->rootPackageVersion); } return $package; }
protected function loadVcsVersions(VcsDriverInterface $driver, $package, $identifiers, $type) { $packages = array(); foreach ($identifiers as $ref => $identifier) { $data = array(); $data['name'] = $package; switch ($type) { case 'branch': if ($parsedVersion = $this->validateBranch($ref)) { $data['version'] = $ref; $data['version_normalized'] = $parsedVersion; } if ('dev-' === substr($parsedVersion, 0, 4) || self::VERSION_LIMIT === $parsedVersion) { $data['version'] = 'dev-' . $data['version']; } else { $data['version'] = preg_replace('{(\\.9{7})+}', '.x', $parsedVersion); } break; case 'tag': if ($parsedVersion = $this->validateTag($ref)) { $data['version'] = $ref; $data['version_normalized'] = $parsedVersion; $data['version'] = preg_replace('{[.-]?dev$}i', '', $data['version']); $data['version_normalized'] = preg_replace('{(^dev-|[.-]?dev$)}i', '', $data['version_normalized']); if ($data['version_normalized'] !== $parsedVersion) { if ($this->io->isVerbose()) { $this->io->write('<warning>Skipped tag ' . $ref . ', tag (' . $parsedVersion . ') does not match version (' . $data['version_normalized'] . ')</warning>'); } continue; } } break; default: $parsedVersion = false; } if (!$parsedVersion) { if ($this->io->isVerbose()) { $this->io->write('<warning>Skipped ' . $type . ' ' . $ref . ', invalid name</warning>'); } continue; } if ($this->io->isVerbose()) { $this->io->write('Importing ' . $type . ' ' . $ref . ' (' . $data['version_normalized'] . ')'); } $data['source'] = $driver->getSource($identifier); $data['time'] = $this->getModifiedTimestamp($driver->getUrl() . '/' . $identifier); $data['type'] = $this->type; $packages[] = $this->getComposerMetadata($driver, $data, $identifier); } return $packages; }
/** * Make proper package data * * @param VcsDriverInterface $driver * @param array $data * @param string $identifier * @return array */ protected function preProcess(VcsDriverInterface $driver, array $data, $identifier) { // keep the name of the main identifier for all packages if ($this->packageName != $this->url) { $namespace = preg_replace('/([a-z0-9])([A-Z])/', '$1_$2', $data['namespace']); $namespace = strtolower($namespace); $data['name'] = $this->packageName . '-' . $namespace; } if (!isset($data['dist'])) { $data['dist'] = $driver->getDist($identifier); } if (!isset($data['source'])) { $data['source'] = $driver->getSource($identifier); $data['source']['type'] = $this->repoConfig['type']; } return $data; }