コード例 #1
1
ファイル: HgDriver.php プロジェクト: composer-fork/composer
 /**
  * {@inheritDoc}
  */
 public function initialize()
 {
     if (Filesystem::isLocalPath($this->url)) {
         $this->repoDir = $this->url;
     } else {
         $cacheDir = $this->config->get('cache-vcs-dir');
         $this->repoDir = $cacheDir . '/' . preg_replace('{[^a-z0-9]}i', '-', $this->url) . '/';
         $fs = new Filesystem();
         $fs->ensureDirectoryExists($cacheDir);
         if (!is_writable(dirname($this->repoDir))) {
             throw new \RuntimeException('Can not clone ' . $this->url . ' to access package information. The "' . $cacheDir . '" directory is not writable by the current user.');
         }
         // update the repo if it is a valid hg repository
         if (is_dir($this->repoDir) && 0 === $this->process->execute('hg summary', $output, $this->repoDir)) {
             if (0 !== $this->process->execute('hg pull', $output, $this->repoDir)) {
                 $this->io->write('<error>Failed to update ' . $this->url . ', package information from this repository may be outdated (' . $this->process->getErrorOutput() . ')</error>');
             }
         } else {
             // clean up directory and do a fresh clone into it
             $fs->removeDirectory($this->repoDir);
             if (0 !== $this->process->execute(sprintf('hg clone --noupdate %s %s', ProcessExecutor::escape($this->url), ProcessExecutor::escape($this->repoDir)), $output, $cacheDir)) {
                 $output = $this->process->getErrorOutput();
                 if (0 !== $this->process->execute('hg --version', $ignoredOutput)) {
                     throw new \RuntimeException('Failed to clone ' . $this->url . ', hg was not found, check that it is installed and in your PATH env.' . "\n\n" . $this->process->getErrorOutput());
                 }
                 throw new \RuntimeException('Failed to clone ' . $this->url . ', could not read packages from it' . "\n\n" . $output);
             }
         }
     }
     $this->getTags();
     $this->getBranches();
 }
コード例 #2
0
 public function testBuildPhar()
 {
     if (defined('HHVM_VERSION')) {
         $this->markTestSkipped('Building the phar does not work on HHVM.');
     }
     $target = dirname(self::$pharPath);
     $fs = new Filesystem();
     $fs->removeDirectory($target);
     $fs->ensureDirectoryExists($target);
     chdir($target);
     $it = new \RecursiveDirectoryIterator(__DIR__ . '/../../../', \RecursiveDirectoryIterator::SKIP_DOTS);
     $ri = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::SELF_FIRST);
     foreach ($ri as $file) {
         $targetPath = $target . DIRECTORY_SEPARATOR . $ri->getSubPathName();
         if ($file->isDir()) {
             $fs->ensureDirectoryExists($targetPath);
         } else {
             copy($file->getPathname(), $targetPath);
         }
     }
     $proc = new Process('php ' . escapeshellarg('./bin/compile'), $target);
     $exitcode = $proc->run();
     if ($exitcode !== 0 || trim($proc->getOutput())) {
         $this->fail($proc->getOutput());
     }
     $this->assertTrue(file_exists(self::$pharPath));
 }
コード例 #3
0
ファイル: ArchiveCommand.php プロジェクト: 4nxiety/pagekit
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $filesystem = new Filesystem();
     $packageName = $this->getPackageFilename($name = $this->argument('name'));
     if (!($targetDir = $this->option('dir'))) {
         $targetDir = $this->container->path();
     }
     $sourcePath = $this->container->get('path.packages') . '/' . $name;
     $filesystem->ensureDirectoryExists($targetDir);
     $target = realpath($targetDir) . '/' . $packageName . '.zip';
     $filesystem->ensureDirectoryExists(dirname($target));
     $exludes = [];
     if (file_exists($composerJsonPath = $sourcePath . '/composer.json')) {
         $jsonFile = new JsonFile($composerJsonPath);
         $jsonData = $jsonFile->read();
         if (!empty($jsonData['archive']['exclude'])) {
             $exludes = $jsonData['archive']['exclude'];
         }
         if (!empty($jsonData['archive']['scripts'])) {
             system($jsonData['archive']['scripts'], $return);
             if ($return !== 0) {
                 throw new \RuntimeException('Can not executes scripts.');
             }
         }
     }
     $tempTarget = sys_get_temp_dir() . '/composer_archive' . uniqid() . '.zip';
     $filesystem->ensureDirectoryExists(dirname($tempTarget));
     $archiver = new PharArchiver();
     $archivePath = $archiver->archive($sourcePath, $tempTarget, 'zip', $exludes);
     rename($archivePath, $target);
     $filesystem->remove($tempTarget);
     return $target;
 }
コード例 #4
0
ファイル: ArchiveBuilder.php プロジェクト: robertgit/satis
 /**
  * Builds the archives of the repository.
  *
  * @param array $packages List of packages to dump
  */
 public function dump(array $packages)
 {
     $helper = new ArchiveBuilderHelper($this->output, $this->config['archive']);
     $directory = $helper->getDirectory($this->outputDir);
     $this->output->writeln(sprintf("<info>Creating local downloads in '%s'</info>", $directory));
     $format = isset($this->config['archive']['format']) ? $this->config['archive']['format'] : 'zip';
     $endpoint = isset($this->config['archive']['prefix-url']) ? $this->config['archive']['prefix-url'] : $this->config['homepage'];
     $includeArchiveChecksum = isset($this->config['archive']['checksum']) ? (bool) $this->config['archive']['checksum'] : true;
     $composerConfig = Factory::createConfig();
     $factory = new Factory();
     $io = new ConsoleIO($this->input, $this->output, $this->helperSet);
     $io->loadConfiguration($composerConfig);
     /* @var \Composer\Downloader\DownloadManager $downloadManager */
     $downloadManager = $factory->createDownloadManager($io, $composerConfig);
     /* @var \Composer\Package\Archiver\ArchiveManager $archiveManager */
     $archiveManager = $factory->createArchiveManager($composerConfig, $downloadManager);
     $archiveManager->setOverwriteFiles(false);
     shuffle($packages);
     /* @var \Composer\Package\CompletePackage $package */
     foreach ($packages as $package) {
         if ($helper->isSkippable($package)) {
             continue;
         }
         $this->output->writeln(sprintf("<info>Dumping '%s'.</info>", $package->getName()));
         try {
             if ('pear-library' === $package->getType()) {
                 // PEAR packages are archives already
                 $filesystem = new Filesystem();
                 $packageName = $archiveManager->getPackageFilename($package);
                 $path = realpath($directory) . '/' . $packageName . '.' . pathinfo($package->getDistUrl(), PATHINFO_EXTENSION);
                 if (!file_exists($path)) {
                     $downloadDir = sys_get_temp_dir() . '/composer_archiver/' . $packageName;
                     $filesystem->ensureDirectoryExists($downloadDir);
                     $downloadManager->download($package, $downloadDir, false);
                     $filesystem->ensureDirectoryExists($directory);
                     $filesystem->rename($downloadDir . '/' . pathinfo($package->getDistUrl(), PATHINFO_BASENAME), $path);
                     $filesystem->removeDirectory($downloadDir);
                 }
                 // Set archive format to `file` to tell composer to download it as is
                 $archiveFormat = 'file';
             } else {
                 $path = $archiveManager->archive($package, $format, $directory);
                 $archiveFormat = $format;
             }
             $archive = basename($path);
             $distUrl = sprintf('%s/%s/%s', $endpoint, $this->config['archive']['directory'], $archive);
             $package->setDistType($archiveFormat);
             $package->setDistUrl($distUrl);
             if ($includeArchiveChecksum) {
                 $package->setDistSha1Checksum(hash_file('sha1', $path));
             }
             $package->setDistReference($package->getSourceReference());
         } catch (\Exception $exception) {
             if (!$this->skipErrors) {
                 throw $exception;
             }
             $this->output->writeln(sprintf("<error>Skipping Exception '%s'.</error>", $exception->getMessage()));
         }
     }
 }
コード例 #5
0
ファイル: ArchiverTest.php プロジェクト: alancleaver/composer
 public function setUp()
 {
     $this->filesystem = new Filesystem();
     $this->process = new ProcessExecutor();
     $this->testDir = sys_get_temp_dir() . '/composer_archiver_test_' . mt_rand();
     $this->filesystem->ensureDirectoryExists($this->testDir);
 }
コード例 #6
0
ファイル: RunonceManagerTest.php プロジェクト: Jobu/core
 protected function setUp()
 {
     $this->rootDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'composer-test-contao';
     $this->fs = new Filesystem();
     $this->io = $this->getMock('Composer\\IO\\IOInterface');
     $this->fs->ensureDirectoryExists($this->rootDir . '/system');
 }
コード例 #7
0
 private function copyFile($from, $to)
 {
     if (!is_file($from)) {
         throw new \RuntimeException('Invalid PEAR package. package.xml defines file that is not located inside tarball.');
     }
     $this->filesystem->ensureDirectoryExists(dirname($to));
     if (!copy($from, $to)) {
         throw new \RuntimeException(sprintf('Failed to copy %s to %s', $from, $to));
     }
 }
コード例 #8
0
 public function downloadManagerDownload($package, $path)
 {
     $this->filesystem->ensureDirectoryExists($path);
     foreach ($this->typo3Files as $file) {
         $dir = dirname($file);
         if ($dir) {
             $this->filesystem->ensureDirectoryExists($path . '/' . $dir);
         }
         file_put_contents($path . '/' . $file, $file);
     }
 }
コード例 #9
0
    /**
     * @param string $destination
     * @param array $references
     */
    public function generate($destination, array $references)
    {
        $this->filesystem->ensureDirectoryExists(dirname($destination));
        $referencesPhp = var_export($references, true);
        $text = <<<EOF
<?php
namespace ComposerRevisions;

class Revisions
{
    public static \$byName = {$referencesPhp};
}
EOF;
        file_put_contents($destination, $text);
    }
コード例 #10
0
 public function testExcludeFromClassmap()
 {
     $package = new Package('a', '1.0', '1.0');
     $package->setAutoload(array('psr-0' => array('Main' => 'src/', 'Lala' => array('src/', 'lib/')), 'psr-4' => array('Acme\\Fruit\\' => 'src-fruit/', 'Acme\\Cake\\' => array('src-cake/', 'lib-cake/')), 'classmap' => array('composersrc/'), 'exclude-from-classmap' => array('/composersrc/excludedTests/', '/composersrc/ClassToExclude.php', '/composersrc/*/excluded/excsubpath', '**/excsubpath')));
     $this->repository->expects($this->once())->method('getCanonicalPackages')->will($this->returnValue(array()));
     $this->fs->ensureDirectoryExists($this->workingDir . '/composer');
     $this->fs->ensureDirectoryExists($this->workingDir . '/src/Lala/Test');
     $this->fs->ensureDirectoryExists($this->workingDir . '/lib');
     file_put_contents($this->workingDir . '/src/Lala/ClassMapMain.php', '<?php namespace Lala; class ClassMapMain {}');
     file_put_contents($this->workingDir . '/src/Lala/Test/ClassMapMainTest.php', '<?php namespace Lala\\Test; class ClassMapMainTest {}');
     $this->fs->ensureDirectoryExists($this->workingDir . '/src-fruit');
     $this->fs->ensureDirectoryExists($this->workingDir . '/src-cake');
     $this->fs->ensureDirectoryExists($this->workingDir . '/lib-cake');
     file_put_contents($this->workingDir . '/src-cake/ClassMapBar.php', '<?php namespace Acme\\Cake; class ClassMapBar {}');
     $this->fs->ensureDirectoryExists($this->workingDir . '/composersrc');
     $this->fs->ensureDirectoryExists($this->workingDir . '/composersrc/tests');
     file_put_contents($this->workingDir . '/composersrc/foo.php', '<?php class ClassMapFoo {}');
     // this classes should not be found in the classmap
     $this->fs->ensureDirectoryExists($this->workingDir . '/composersrc/excludedTests');
     file_put_contents($this->workingDir . '/composersrc/excludedTests/bar.php', '<?php class ClassExcludeMapFoo {}');
     file_put_contents($this->workingDir . '/composersrc/ClassToExclude.php', '<?php class ClassClassToExclude {}');
     $this->fs->ensureDirectoryExists($this->workingDir . '/composersrc/long/excluded/excsubpath');
     file_put_contents($this->workingDir . '/composersrc/long/excluded/excsubpath/foo.php', '<?php class ClassExcludeMapFoo2 {}');
     file_put_contents($this->workingDir . '/composersrc/long/excluded/excsubpath/bar.php', '<?php class ClassExcludeMapBar {}');
     $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_1');
     // Assert that autoload_classmap.php was correctly generated.
     $this->assertAutoloadFiles('classmap', $this->vendorDir . '/composer', 'classmap');
 }
コード例 #11
0
 /**
  * Persist the stored configuration.
  *
  * @since 0.1.0
  *
  * @param Event $event Event that was triggered.
  */
 public static function persistConfig(Event $event)
 {
     $filesystem = new Filesystem();
     $path = Paths::getPath('git_composter');
     $filesystem->ensureDirectoryExists($path);
     file_put_contents(Paths::getPath('git_config'), static::getConfig());
 }
コード例 #12
0
 private function copyFile($from, $to, $tasks, $vars)
 {
     if (!is_file($from)) {
         throw new \RuntimeException('Invalid PEAR package. package.xml defines file that is not located inside tarball.');
     }
     $this->filesystem->ensureDirectoryExists(dirname($to));
     if (0 == count($tasks)) {
         $copied = copy($from, $to);
     } else {
         $content = file_get_contents($from);
         $replacements = array();
         foreach ($tasks as $task) {
             $pattern = $task['from'];
             $varName = $task['to'];
             if (isset($vars[$varName])) {
                 if ($varName === 'php_bin' && false === strpos($to, '.bat')) {
                     $replacements[$pattern] = preg_replace('{\\.bat$}', '', $vars[$varName]);
                 } else {
                     $replacements[$pattern] = $vars[$varName];
                 }
             }
         }
         $content = strtr($content, $replacements);
         $copied = file_put_contents($to, $content);
     }
     if (false === $copied) {
         throw new \RuntimeException(sprintf('Failed to copy %s to %s', $from, $to));
     }
 }
コード例 #13
0
ファイル: GitDriver.php プロジェクト: nickelc/composer
 /**
  * {@inheritDoc}
  */
 public function initialize()
 {
     if (static::isLocalUrl($this->url)) {
         $this->repoDir = str_replace('file://', '', $this->url);
     } else {
         $this->repoDir = $this->config->get('cache-vcs-dir') . '/' . preg_replace('{[^a-z0-9.]}i', '-', $this->url) . '/';
         $fs = new Filesystem();
         $fs->ensureDirectoryExists(dirname($this->repoDir));
         if (!is_writable(dirname($this->repoDir))) {
             throw new \RuntimeException('Can not clone ' . $this->url . ' to access package information. The "' . dirname($this->repoDir) . '" directory is not writable by the current user.');
         }
         // update the repo if it is a valid git repository
         if (is_dir($this->repoDir) && 0 === $this->process->execute('git remote', $output, $this->repoDir)) {
             if (0 !== $this->process->execute('git remote update --prune origin', $output, $this->repoDir)) {
                 $this->io->write('<error>Failed to update ' . $this->url . ', package information from this repository may be outdated (' . $this->process->getErrorOutput() . ')</error>');
             }
         } else {
             // clean up directory and do a fresh clone into it
             $fs->removeDirectory($this->repoDir);
             // added in git 1.7.1, prevents prompting the user
             putenv('GIT_ASKPASS=echo');
             $command = sprintf('git clone --mirror %s %s', escapeshellarg($this->url), escapeshellarg($this->repoDir));
             if (0 !== $this->process->execute($command, $output)) {
                 $output = $this->process->getErrorOutput();
                 if (0 !== $this->process->execute('git --version', $ignoredOutput)) {
                     throw new \RuntimeException('Failed to clone ' . $this->url . ', git was not found, check that it is installed and in your PATH env.' . "\n\n" . $this->process->getErrorOutput());
                 }
                 throw new \RuntimeException('Failed to clone ' . $this->url . ', could not read packages from it' . "\n\n" . $output);
             }
         }
     }
     $this->getTags();
     $this->getBranches();
 }
コード例 #14
0
ファイル: GetContaoRootTest.php プロジェクト: Jobu/core
 /**
  * Test that a Contao installation can be found within current working directory.
  */
 public function testCoreIsCwd()
 {
     $plugin = $this->clearTest();
     $this->fs->ensureDirectoryExists($this->testRoot . '/system');
     $package = new RootPackage('test/package', '1.0.0.0', '1.0.0');
     $this->assertEquals($this->testRoot, $plugin->getContaoRoot($package));
 }
コード例 #15
0
 public function testUninstall()
 {
     $this->fs->ensureDirectoryExists($this->pluginDir);
     $installer = new GingerInstaller($this->io, $this->composer);
     $repository = new ComposerRepositoryMock();
     $package = new Package('gingerwfms/wf-configurator-backend', '1.0.0', '1.0.0');
     $package->setType('ginger-backend-plugin');
     $package->setExtra(array('plugin-namespace' => 'WfConfiguratorBackend'));
     $repository->addPackage($package);
     $gate = new Gate();
     $mockBus = new CqrsBusMock();
     $pluginNamespace = '';
     $pluginName = '';
     $pluginType = '';
     $pluginVersion = '';
     $mockBus->mapCommand('GingerPluginInstaller\\Cqrs\\UninstallPluginCommand', function (UninstallPluginCommand $command) use(&$pluginNamespace, &$pluginName, &$pluginType, &$pluginVersion) {
         $pluginNamespace = $command->getPluginNamespace();
         $pluginName = $command->getPluginName();
         $pluginType = $command->getPluginType();
         $pluginVersion = $command->getPluginVersion();
     });
     $gate->attach($mockBus);
     $gate->setDefaultBusName($mockBus->getName());
     Bootstrap::getServiceManager()->setAllowOverride(true);
     Bootstrap::getServiceManager()->setService('malocher.cqrs.gate', $gate);
     $installer->uninstall($repository, $package);
     $this->assertSame('WfConfiguratorBackend', $pluginNamespace);
     $this->assertSame('gingerwfms/wf-configurator-backend', $pluginName);
     $this->assertSame('ginger-backend-plugin', $pluginType);
     $this->assertSame('1.0.0', $pluginVersion);
 }
コード例 #16
0
ファイル: GitDriver.php プロジェクト: neon64/composer
 /**
  * {@inheritDoc}
  */
 public function initialize()
 {
     if (Filesystem::isLocalPath($this->url)) {
         $this->url = preg_replace('{[\\/]\\.git/?$}', '', $this->url);
         $this->repoDir = $this->url;
         $cacheUrl = realpath($this->url);
     } else {
         $this->repoDir = $this->config->get('cache-vcs-dir') . '/' . preg_replace('{[^a-z0-9.]}i', '-', $this->url) . '/';
         GitUtil::cleanEnv();
         $fs = new Filesystem();
         $fs->ensureDirectoryExists(dirname($this->repoDir));
         if (!is_writable(dirname($this->repoDir))) {
             throw new \RuntimeException('Can not clone ' . $this->url . ' to access package information. The "' . dirname($this->repoDir) . '" directory is not writable by the current user.');
         }
         if (preg_match('{^ssh://[^@]+@[^:]+:[^0-9]+}', $this->url)) {
             throw new \InvalidArgumentException('The source URL ' . $this->url . ' is invalid, ssh URLs should have a port number after ":".' . "\n" . 'Use ssh://git@example.com:22/path or just git@example.com:path if you do not want to provide a password or custom port.');
         }
         $gitUtil = new GitUtil($this->io, $this->config, $this->process, $fs);
         if (!$gitUtil->syncMirror($this->url, $this->repoDir)) {
             $this->io->writeError('<error>Failed to update ' . $this->url . ', package information from this repository may be outdated</error>');
         }
         $cacheUrl = $this->url;
     }
     $this->getTags();
     $this->getBranches();
     $this->cache = new Cache($this->io, $this->config->get('cache-repo-dir') . '/' . preg_replace('{[^a-z0-9.]}i', '-', $cacheUrl));
 }
コード例 #17
0
 /**
  * Process symlink, checks given source and destination paths
  */
 public function processSymlink(string $packageSrc, string $relativeSourcePath, string $destinationTheme, string $relativeDestinationPath)
 {
     $sourcePath = sprintf("%s/%s", $packageSrc, $relativeSourcePath);
     $destinationPath = sprintf("%s/%s", $destinationTheme, $relativeDestinationPath);
     if (!file_exists($sourcePath)) {
         $this->io->write(sprintf('<error>The static package does not contain directory: "%s" </error>', $relativeSourcePath));
         return;
     }
     if (file_exists($destinationPath) && !is_link($destinationPath)) {
         $this->io->write(sprintf('<error>Your static path: "%s" is currently not a symlink, please remove first </error>', $destinationPath));
         return;
     }
     //if it's a link, remove it and recreate it
     //assume we are updating the static package
     if (is_link($destinationPath)) {
         unlink($destinationPath);
     } else {
         //file doesn't already exist
         //lets make sure the parent directory does
         $this->filesystem->ensureDirectoryExists(dirname($destinationPath));
     }
     $relativeSourcePath = $this->getRelativePath($destinationPath, $sourcePath);
     if (!@\symlink($relativeSourcePath, $destinationPath)) {
         $this->io->write(sprintf('<error>Failed to symlink %s to %s</error>', $sourcePath, $destinationPath));
     }
 }
コード例 #18
0
ファイル: ArchiveManager.php プロジェクト: VicDeo/poc
 public function archive(PackageInterface $package, $format, $targetDir)
 {
     if (empty($format)) {
         throw new \InvalidArgumentException('Format must be specified');
     }
     $usableArchiver = null;
     foreach ($this->archivers as $archiver) {
         if ($archiver->supports($format, $package->getSourceType())) {
             $usableArchiver = $archiver;
             break;
         }
     }
     if (null === $usableArchiver) {
         throw new \RuntimeException(sprintf('No archiver found to support %s format', $format));
     }
     $filesystem = new Filesystem();
     $packageName = $this->getPackageFilename($package);
     $filesystem->ensureDirectoryExists($targetDir);
     $target = realpath($targetDir) . '/' . $packageName . '.' . $format;
     $filesystem->ensureDirectoryExists(dirname($target));
     if (!$this->overwriteFiles && file_exists($target)) {
         return $target;
     }
     if ($package instanceof RootPackageInterface) {
         $sourcePath = realpath('.');
     } else {
         $sourcePath = sys_get_temp_dir() . '/composer_archive' . uniqid();
         $filesystem->ensureDirectoryExists($sourcePath);
         $this->downloadManager->download($package, $sourcePath);
         if (file_exists($composerJsonPath = $sourcePath . '/composer.json')) {
             $jsonFile = new JsonFile($composerJsonPath);
             $jsonData = $jsonFile->read();
             if (!empty($jsonData['archive']['exclude'])) {
                 $package->setArchiveExcludes($jsonData['archive']['exclude']);
             }
         }
     }
     $tempTarget = sys_get_temp_dir() . '/composer_archive' . uniqid() . '.' . $format;
     $filesystem->ensureDirectoryExists(dirname($tempTarget));
     $archivePath = $usableArchiver->archive($sourcePath, $tempTarget, $format, $package->getArchiveExcludes());
     rename($archivePath, $target);
     if (!$package instanceof RootPackageInterface) {
         $filesystem->removeDirectory($sourcePath);
     }
     $filesystem->remove($tempTarget);
     return $target;
 }
コード例 #19
0
    public function testUpdateDoesntThrowsRuntimeExceptionIfGitCommandFailsAtFirstButIsAbleToRecover()
    {
        $expectedFirstGitUpdateCommand = $this->winCompat("git remote set-url composer '' && git rev-parse --quiet --verify 'ref'^{commit} || (git fetch composer && git fetch --tags composer)");
        $expectedSecondGitUpdateCommand = $this->winCompat("git remote set-url composer 'https://github.com/composer/composer' && git rev-parse --quiet --verify 'ref'^{commit} || (git fetch composer && git fetch --tags composer)");

        $packageMock = $this->getMock('Composer\Package\PackageInterface');
        $packageMock->expects($this->any())
            ->method('getSourceReference')
            ->will($this->returnValue('ref'));
        $packageMock->expects($this->any())
            ->method('getSourceUrls')
            ->will($this->returnValue(array('/foo/bar', 'https://github.com/composer/composer')));
        $processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
        $processExecutor->expects($this->at(0))
            ->method('execute')
            ->with($this->equalTo($this->winCompat("git show-ref --head -d")))
            ->will($this->returnValue(0));
        $processExecutor->expects($this->at(1))
            ->method('execute')
            ->with($this->equalTo($this->winCompat("git status --porcelain --untracked-files=no")))
            ->will($this->returnValue(0));
        $processExecutor->expects($this->at(2))
           ->method('execute')
            ->with($this->equalTo($this->winCompat("git remote -v")))
            ->will($this->returnValue(0));
        $processExecutor->expects($this->at(3))
           ->method('execute')
            ->with($this->equalTo($this->winCompat("git remote -v")))
            ->will($this->returnValue(0));
        $processExecutor->expects($this->at(4))
            ->method('execute')
            ->with($this->equalTo($expectedFirstGitUpdateCommand))
            ->will($this->returnValue(1));
        $processExecutor->expects($this->at(6))
            ->method('execute')
            ->with($this->equalTo($this->winCompat("git --version")))
            ->will($this->returnValue(0));
        $processExecutor->expects($this->at(7))
            ->method('execute')
            ->with($this->equalTo($this->winCompat("git remote -v")))
            ->will($this->returnValue(0));
        $processExecutor->expects($this->at(8))
            ->method('execute')
            ->with($this->equalTo($this->winCompat("git remote -v")))
            ->will($this->returnValue(0));
        $processExecutor->expects($this->at(9))
            ->method('execute')
            ->with($this->equalTo($expectedSecondGitUpdateCommand))
            ->will($this->returnValue(0));
        $processExecutor->expects($this->at(11))
            ->method('execute')
            ->with($this->equalTo($this->winCompat("git checkout 'ref' -- && git reset --hard 'ref' --")), $this->equalTo(null), $this->equalTo($this->winCompat($this->workingDir)))
            ->will($this->returnValue(0));

        $this->fs->ensureDirectoryExists($this->workingDir.'/.git');
        $downloader = $this->getDownloaderMock(null, new Config(), $processExecutor);
        $downloader->update($packageMock, $packageMock, $this->workingDir);
    }
コード例 #20
0
 protected function setUp()
 {
     $fs = new Filesystem();
     $this->target = sys_get_temp_dir() . '/composer-foo';
     foreach ($this->getFixtureFiles() as $filename) {
         $path = $this->target . '/' . $filename;
         $fs->ensureDirectoryExists(dirname($path));
         @file_put_contents($path, '');
     }
 }
コード例 #21
0
 /**
  * Ensures that all required directories exist when installing the application.
  *
  * @param Event $event
  */
 public static function ensureDirectoriesExist(Event $event)
 {
     $options = $event->getComposer()->getPackage()->getExtra();
     $directories = [$options['symfony-var-dir']];
     foreach ($directories as $eachDirectory) {
         $event->getIO()->write(sprintf('Ensuring the <comment>%s</comment> directory exists.', $eachDirectory));
         $fs = new Filesystem();
         $fs->ensureDirectoryExists($eachDirectory);
     }
 }
コード例 #22
0
ファイル: GitDriver.php プロジェクト: symstriker/composer
 /**
  * {@inheritDoc}
  */
 public function initialize()
 {
     if (static::isLocalUrl($this->url)) {
         $this->repoDir = str_replace('file://', '', $this->url);
     } else {
         $this->repoDir = $this->config->get('cache-vcs-dir') . '/' . preg_replace('{[^a-z0-9.]}i', '-', $this->url) . '/';
         $util = new GitUtil();
         $util->cleanEnv();
         $fs = new Filesystem();
         $fs->ensureDirectoryExists(dirname($this->repoDir));
         if (!is_writable(dirname($this->repoDir))) {
             throw new \RuntimeException('Can not clone ' . $this->url . ' to access package information. The "' . dirname($this->repoDir) . '" directory is not writable by the current user.');
         }
         if (preg_match('{^ssh://[^@]+@[^:]+:[^0-9]+}', $this->url)) {
             throw new \InvalidArgumentException('The source URL ' . $this->url . ' is invalid, ssh URLs should have a port number after ":".' . "\n" . 'Use ssh://git@example.com:22/path or just git@example.com:path if you do not want to provide a password or custom port.');
         }
         // update the repo if it is a valid git repository
         if (is_dir($this->repoDir) && 0 === $this->process->execute('git remote', $output, $this->repoDir)) {
             if (0 !== $this->process->execute('git remote update --prune origin', $output, $this->repoDir)) {
                 $this->io->write('<error>Failed to update ' . $this->url . ', package information from this repository may be outdated (' . $this->process->getErrorOutput() . ')</error>');
             }
         } else {
             // clean up directory and do a fresh clone into it
             $fs->removeDirectory($this->repoDir);
             $command = sprintf('git clone --mirror %s %s', escapeshellarg($this->url), escapeshellarg($this->repoDir));
             if (0 !== $this->process->execute($command, $output)) {
                 $output = $this->process->getErrorOutput();
                 if (0 !== $this->process->execute('git --version', $ignoredOutput)) {
                     throw new \RuntimeException('Failed to clone ' . $this->url . ', git was not found, check that it is installed and in your PATH env.' . "\n\n" . $this->process->getErrorOutput());
                 }
                 if ($this->io->isInteractive() && preg_match('{(https?://)([^/]+)(.*)$}i', $this->url, $match) && strpos($output, 'fatal: Authentication failed') !== false) {
                     if ($this->io->hasAuthentication($match[2])) {
                         $auth = $this->io->getAuthentication($match[2]);
                     } else {
                         $this->io->write($this->url . ' requires Authentication');
                         $auth = array('username' => $this->io->ask('Username: '******'password' => $this->io->askAndHideAnswer('Password: '******'username']) . ':' . rawurlencode($auth['password']) . '@' . $match[2] . $match[3];
                     $command = sprintf('git clone --mirror %s %s', escapeshellarg($url), escapeshellarg($this->repoDir));
                     if (0 === $this->process->execute($command, $output)) {
                         $this->io->setAuthentication($match[2], $auth['username'], $auth['password']);
                     } else {
                         $output = $this->process->getErrorOutput();
                         throw new \RuntimeException('Failed to clone ' . $this->url . ', could not read packages from it' . "\n\n" . $output);
                     }
                 } else {
                     throw new \RuntimeException('Failed to clone ' . $this->url . ', could not read packages from it' . "\n\n" . $output);
                 }
             }
         }
     }
     $this->getTags();
     $this->getBranches();
     $this->cache = new Cache($this->io, $this->config->get('cache-repo-dir') . '/' . preg_replace('{[^a-z0-9.]}i', '-', $this->url));
 }
コード例 #23
0
 public function testBuildPhar()
 {
     $fs = new Filesystem();
     $fs->removeDirectory(dirname(self::$pharPath));
     $fs->ensureDirectoryExists(dirname(self::$pharPath));
     chdir(dirname(self::$pharPath));
     $proc = new Process('php ' . escapeshellarg(__DIR__ . '/../../../bin/compile'));
     $exitcode = $proc->run();
     $this->assertSame(0, $exitcode);
     $this->assertTrue(file_exists(self::$pharPath));
 }
コード例 #24
0
 protected function setUp()
 {
     $fs = new Filesystem();
     $this->fs = $fs;
     $this->sources = $fs->normalizePath(realpath(sys_get_temp_dir()) . '/composer_archiver_test' . uniqid(mt_rand(), true));
     $fileTree = array('A/prefixA.foo', 'A/prefixB.foo', 'A/prefixC.foo', 'A/prefixD.foo', 'A/prefixE.foo', 'A/prefixF.foo', 'B/sub/prefixA.foo', 'B/sub/prefixB.foo', 'B/sub/prefixC.foo', 'B/sub/prefixD.foo', 'B/sub/prefixE.foo', 'B/sub/prefixF.foo', 'toplevelA.foo', 'toplevelB.foo', 'prefixA.foo', 'prefixB.foo', 'prefixC.foo', 'prefixD.foo', 'prefixE.foo', 'prefixF.foo');
     foreach ($fileTree as $relativePath) {
         $path = $this->sources . '/' . $relativePath;
         $fs->ensureDirectoryExists(dirname($path));
         file_put_contents($path, '');
     }
 }
コード例 #25
0
 /**
  * Complete the setup task.
  *
  * @since 0.1.0
  *
  * @return void
  */
 public function complete()
 {
     $filesystem = new Filesystem();
     $templatesFolder = $this->getConfigKey('Folders', 'templates');
     $finder = new Finder();
     foreach ($finder->files()->in($templatesFolder) as $file) {
         $from = $file->getPathname();
         $to = $this->getTargetPath($from);
         $filesystem->ensureDirectoryExists(dirname($to));
         $filesystem->copyThenRemove($from, $to);
     }
 }
コード例 #26
0
 protected function setUp()
 {
     $fs = new Filesystem();
     $this->fs = $fs;
     $this->sources = $fs->normalizePath($this->getUniqueTmpDirectory());
     $fileTree = array('A/prefixA.foo', 'A/prefixB.foo', 'A/prefixC.foo', 'A/prefixD.foo', 'A/prefixE.foo', 'A/prefixF.foo', 'B/sub/prefixA.foo', 'B/sub/prefixB.foo', 'B/sub/prefixC.foo', 'B/sub/prefixD.foo', 'B/sub/prefixE.foo', 'B/sub/prefixF.foo', 'C/prefixA.foo', 'C/prefixB.foo', 'C/prefixC.foo', 'C/prefixD.foo', 'C/prefixE.foo', 'C/prefixF.foo', 'D/prefixA', 'D/prefixB', 'D/prefixC', 'D/prefixD', 'D/prefixE', 'D/prefixF', 'E/subtestA.foo', 'F/subtestA.foo', 'G/subtestA.foo', 'H/subtestA.foo', 'I/J/subtestA.foo', 'K/dirJ/subtestA.foo', 'toplevelA.foo', 'toplevelB.foo', 'prefixA.foo', 'prefixB.foo', 'prefixC.foo', 'prefixD.foo', 'prefixE.foo', 'prefixF.foo', 'parameters.yml', 'parameters.yml.dist', '!important!.txt', '!important_too!.txt', '#weirdfile');
     foreach ($fileTree as $relativePath) {
         $path = $this->sources . '/' . $relativePath;
         $fs->ensureDirectoryExists(dirname($path));
         file_put_contents($path, '');
     }
 }
コード例 #27
0
 protected function setUp()
 {
     $fs = new Filesystem();
     $this->fs = $fs;
     $this->sources = $fs->normalizePath(realpath(sys_get_temp_dir()) . '/composer_archiver_test' . uniqid(mt_rand(), true));
     $fileTree = array('A/prefixA.foo', 'A/prefixB.foo', 'A/prefixC.foo', 'A/prefixD.foo', 'A/prefixE.foo', 'A/prefixF.foo', 'B/sub/prefixA.foo', 'B/sub/prefixB.foo', 'B/sub/prefixC.foo', 'B/sub/prefixD.foo', 'B/sub/prefixE.foo', 'B/sub/prefixF.foo', 'C/prefixA.foo', 'C/prefixB.foo', 'C/prefixC.foo', 'C/prefixD.foo', 'C/prefixE.foo', 'C/prefixF.foo', 'D/prefixA', 'D/prefixB', 'D/prefixC', 'D/prefixD', 'D/prefixE', 'D/prefixF', 'E/subtestA.foo', 'F/subtestA.foo', 'G/subtestA.foo', 'H/subtestA.foo', 'I/J/subtestA.foo', 'K/dirJ/subtestA.foo', 'toplevelA.foo', 'toplevelB.foo', 'prefixA.foo', 'prefixB.foo', 'prefixC.foo', 'prefixD.foo', 'prefixE.foo', 'prefixF.foo', 'parameters.yml', 'parameters.yml.dist', '!important!.txt', '!important_too!.txt');
     foreach ($fileTree as $relativePath) {
         $path = $this->sources . '/' . $relativePath;
         $fs->ensureDirectoryExists(dirname($path));
         file_put_contents($path, '');
     }
 }
コード例 #28
0
    protected function setUp()
    {
        $fs = new Filesystem();
        $source = __DIR__.'/../Fixtures/foo';
        $this->target = $target = sys_get_temp_dir() . '/composer-foo';

        $it = new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS);
        $ri = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::SELF_FIRST);
        $fs->ensureDirectoryExists($target);

        /* @var \SplFileInfo $file */
        foreach ($ri as $file) {
            /* @var \RecursiveDirectoryIterator $ri */
            $targetPath = $target . DIRECTORY_SEPARATOR . $ri->getSubPathName();
            if ($file->isDir()) {
                $fs->ensureDirectoryExists($targetPath);
            } else {
                copy($file->getPathname(), $targetPath);
            }
        }
    }
コード例 #29
0
ファイル: FossilDriver.php プロジェクト: neon64/composer
 /**
  * {@inheritDoc}
  */
 public function initialize()
 {
     if (Filesystem::isLocalPath($this->url)) {
         $this->checkoutDir = $this->url;
     } else {
         $this->repoFile = $this->config->get('cache-repo-dir') . '/' . preg_replace('{[^a-z0-9]}i', '-', $this->url) . '.fossil';
         $this->checkoutDir = $this->config->get('cache-vcs-dir') . '/' . preg_replace('{[^a-z0-9]}i', '-', $this->url) . '/';
         $fs = new Filesystem();
         $fs->ensureDirectoryExists($this->checkoutDir);
         if (!is_writable(dirname($this->checkoutDir))) {
             throw new \RuntimeException('Can not clone ' . $this->url . ' to access package information. The "' . $this->checkoutDir . '" directory is not writable by the current user.');
         }
         // Ensure we are allowed to use this URL by config
         $this->config->prohibitUrlByConfig($this->url, $this->io);
         // update the repo if it is a valid fossil repository
         if (is_file($this->repoFile) && is_dir($this->checkoutDir) && 0 === $this->process->execute('fossil info', $output, $this->checkoutDir)) {
             if (0 !== $this->process->execute('fossil pull', $output, $this->checkoutDir)) {
                 $this->io->writeError('<error>Failed to update ' . $this->url . ', package information from this repository may be outdated (' . $this->process->getErrorOutput() . ')</error>');
             }
         } else {
             // clean up directory and do a fresh clone into it
             $fs->removeDirectory($this->checkoutDir);
             $fs->remove($this->repoFile);
             $fs->ensureDirectoryExists($this->checkoutDir);
             if (0 !== $this->process->execute(sprintf('fossil clone %s %s', ProcessExecutor::escape($this->url), ProcessExecutor::escape($this->repoFile)), $output)) {
                 $output = $this->process->getErrorOutput();
                 if (0 !== $this->process->execute('fossil version', $ignoredOutput)) {
                     throw new \RuntimeException('Failed to clone ' . $this->url . ', fossil was not found, check that it is installed and in your PATH env.' . "\n\n" . $this->process->getErrorOutput());
                 }
                 throw new \RuntimeException('Failed to clone ' . $this->url . ' to repository ' . $this->repoFile . "\n\n" . $output);
             }
             if (0 !== $this->process->execute(sprintf('fossil open %s', ProcessExecutor::escape($this->repoFile)), $output, $this->checkoutDir)) {
                 $output = $this->process->getErrorOutput();
                 throw new \RuntimeException('Failed to open repository ' . $this->repoFile . ' in ' . $this->checkoutDir . "\n\n" . $output);
             }
         }
     }
     $this->getTags();
     $this->getBranches();
 }
コード例 #30
0
 /**
  * @static
  *
  * @param \Composer\Script\CommandEvent $event
  */
 public static function checkAndInstall($event)
 {
     $appDir = getcwd() . '/app';
     $resourcesPath = $appDir . '/Resources';
     if (is_dir($resourcesPath)) {
         $filesystem = new Filesystem();
         $jackrabbitDir = $resourcesPath . '/java/jackrabbit';
         $filesystem->ensureDirectoryExists($jackrabbitDir);
         if (!self::check($jackrabbitDir) && false !== ($file = self::download($event->getIO(), $jackrabbitDir))) {
             self::install($file, $appDir);
         }
     }
 }