/** * @override \ComponentManager\PackageSource\PackageSource */ public function obtainPackage($tempDirectory, ResolvedComponentVersion $resolvedComponentVersion, Filesystem $filesystem, LoggerInterface $logger) { $version = $resolvedComponentVersion->getVersion(); $sources = $version->getSources(); foreach ($sources as $source) { if ($source instanceof DirectoryComponentSource) { return $source->getDirectory(); } else { $logger->debug('Cannot accept component source; skipping', ['componentSource' => $source]); } } throw new InstallationFailureException('No directory component sources found', InstallationFailureException::CODE_SOURCE_UNAVAILABLE); }
/** * @override \ComponentManager\PackageSource\PackageSource */ public function obtainPackage($tempDirectory, ResolvedComponentVersion $resolvedComponentVersion, Filesystem $filesystem, LoggerInterface $logger) { $componentVersion = $resolvedComponentVersion->getVersion(); $sources = $componentVersion->getSources(); foreach ($sources as $source) { if ($source instanceof GitComponentSource) { $repositoryPath = $this->platform->joinPaths([$tempDirectory, 'repo']); $indexPath = $this->platform->joinPaths([$tempDirectory, 'index']); $repositoryUri = $source->getRepositoryUri(); $finalRef = $resolvedComponentVersion->getFinalVersion(); $ref = $source->getRef(); if ($finalRef !== null) { $logger->info('Installing pinned version', ['ref' => $ref, 'finalRef' => $finalRef]); $installRef = $finalRef; } else { $installRef = $ref; } // These paths must be removed in the event of a failure/retry $paths = [$repositoryPath, $indexPath]; $filesystem->mkdir($paths); $logger->debug('Trying git repository source', ['repositoryPath' => $repositoryPath, 'repositoryUri' => $repositoryUri, 'ref' => $installRef, 'indexPath' => $indexPath]); try { $repository = new GitVersionControl($this->platform->getExecutablePath('git'), $repositoryPath); $repository->init(); $repository->addRemote(new GitRemote('origin', $repositoryUri)); $repository->fetch('origin'); $repository->checkout($installRef); $repository->checkoutIndex($indexPath . $this->platform->getDirectorySeparator()); $resolvedComponentVersion->setFinalVersion($repository->parseRevision($installRef)); return $indexPath; } catch (VersionControlException $e) { $logger->debug('Version control failed; skipping', ['code' => $e->getCode(), 'message' => $e->getMessage()]); $filesystem->remove($paths); } } else { $logger->debug('Cannot accept component source; skipping', ['componentSource' => $source]); } } }
/** * Attempt to build an individual component. * * @param \ComponentManager\ResolvedComponentVersion $resolvedComponentVersion * @param \Psr\Log\LoggerInterface $logger * * @return void * * @throws \ComponentManager\Exception\ComponentProjectException */ protected function tryComponent(ResolvedComponentVersion $resolvedComponentVersion, LoggerInterface $logger) { $component = $resolvedComponentVersion->getComponent(); $typeDirectory = $this->moodle->getPluginTypeDirectory($component->getPluginType()); $targetDirectory = $this->platform->joinPaths([$typeDirectory, $component->getPluginName()]); $componentProjectFilename = $this->platform->joinPaths([$typeDirectory, $component->getPluginName(), ComponentProjectFile::FILENAME]); $logContext = ['component' => $component->getName(), 'componentProjectFilename' => $componentProjectFilename]; if (!$this->filesystem->exists($componentProjectFilename)) { $logger->debug('Component project file not found; skipping build', $logContext); return; } $componentProjectFile = new ComponentProjectFile($componentProjectFilename); try { $buildScript = $componentProjectFile->getScript(ComponentProjectFile::SCRIPT_BUILD); } catch (ComponentProjectException $e) { $logger->info('Component project file doesn\'t contain a build script; skipping build', $logContext); return; } $logger->info('Running build script for component', $logContext); $process = new Process($buildScript, $targetDirectory); $process->setTimeout(3600); $process->run(function ($type, $buffer) use($logger) { $buffer = sprintf('%s: %s', ComponentProjectFile::SCRIPT_BUILD, $buffer); switch ($type) { case Process::ERR: $logger->error($buffer); break; case Process::OUT: $logger->debug($buffer); break; } }); if (!$process->isSuccessful()) { throw new ComponentProjectException($process->getErrorOutput(), ComponentProjectException::CODE_SCRIPT_FAILED); } }
/** * @override \ComponentManager\PackageSource\PackageSource */ public function obtainPackage($tempDirectory, ResolvedComponentVersion $resolvedComponentVersion, Filesystem $filesystem, LoggerInterface $logger) { $component = $resolvedComponentVersion->getComponent(); $version = $resolvedComponentVersion->getVersion(); $sources = $version->getSources(); $finalVersion = $resolvedComponentVersion->getFinalVersion(); if ($finalVersion !== null) { $source = new ZipComponentSource($finalVersion->archiveUri, $finalVersion->md5Checksum); $logger->info('Installing pinned version', ['archiveUri' => $finalVersion->archiveUri, 'md5Checksum' => $finalVersion->md5Checksum]); return $this->trySource($tempDirectory, $logger, $component, $version, $source); } else { foreach ($sources as $source) { if ($source instanceof ZipComponentSource) { $moduleRootDirectory = $this->trySource($tempDirectory, $logger, $component, $version, $source); $resolvedComponentVersion->setFinalVersion((object) ['archiveUri' => $source->getArchiveUri(), 'md5Checksum' => $source->getMd5Checksum()]); return $moduleRootDirectory; } else { $logger->debug('Cannot accept component source; skipping', ['componentSource' => $source]); } } } throw new InstallationFailureException('No zip component sources found', InstallationFailureException::CODE_SOURCE_UNAVAILABLE); }
/** * Add a resolved component version. * * @param \ComponentManager\ResolvedComponentVersion $resolvedComponentVersion * * @return void */ public function addResolvedComponentVersion(ResolvedComponentVersion $resolvedComponentVersion) { $componentName = $resolvedComponentVersion->getComponent()->getName(); $this->resolvedComponentVersions[$componentName] = $resolvedComponentVersion; }