/**
  * {@inheritdoc}
  */
 public function rollback()
 {
     if ($this->previousMapping) {
         $this->rootPackageFile->addPathMapping($this->previousMapping);
     } else {
         $this->rootPackageFile->removePathMapping($this->mapping->getRepositoryPath());
     }
 }
 /**
  * {@inheritdoc}
  */
 public function rollback()
 {
     if ($this->previousDescriptor) {
         $this->rootPackageFile->addBindingDescriptor($this->previousDescriptor);
     } else {
         $this->rootPackageFile->removeBindingDescriptor($this->bindingDescriptor->getUuid());
     }
 }
 public function rollback()
 {
     if ($this->previousDescriptor) {
         $this->rootPackageFile->addTypeDescriptor($this->previousDescriptor);
     } else {
         $this->rootPackageFile->removeTypeDescriptor($this->typeDescriptor->getName());
     }
 }
Exemplo n.º 4
0
 protected function initEnvironment($homeDir, $rootDir, $mockDispatcher = true)
 {
     if (!$this->baseConfig) {
         $this->baseConfig = new DefaultConfig();
     }
     $this->homeDir = $homeDir;
     $this->rootDir = $rootDir;
     $this->configFile = new ConfigFile($homeDir . '/config.json', $this->baseConfig);
     $this->rootPackageFile = new RootPackageFile('vendor/root', $rootDir . '/puli.json', $this->baseConfig);
     $this->dispatcher = $mockDispatcher ? $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface') : new EventDispatcher();
     $this->repo = $this->getMock('Puli\\Repository\\Api\\EditableRepository');
     $this->discovery = $this->getMock('Puli\\Discovery\\Api\\EditableDiscovery');
     $this->environment = new ProjectEnvironment($this->homeDir, $this->rootDir, $this->rootPackageFile->getConfig(), $this->rootPackageFile, $this->configFile, $this->dispatcher);
 }
 /**
  * {@inheritdoc}
  */
 public function addRootPathMapping(PathMapping $mapping, $flags = 0)
 {
     Assert::integer($flags, 'The argument $flags must be a boolean.');
     $this->assertMappingsLoaded();
     if (!($flags & self::OVERRIDE) && $this->rootPackageFile->hasPathMapping($mapping->getRepositoryPath())) {
         throw DuplicatePathMappingException::forRepositoryPath($mapping->getRepositoryPath(), $this->rootPackage->getName());
     }
     $tx = new Transaction();
     try {
         $syncOp = $this->syncRepositoryPath($mapping->getRepositoryPath());
         $syncOp->takeSnapshot();
         $tx->execute($this->loadPathMapping($mapping, $this->rootPackage));
         if (!($flags & self::IGNORE_FILE_NOT_FOUND)) {
             $this->assertNoLoadErrors($mapping);
         }
         $tx->execute($this->updateConflicts($mapping->listRepositoryPaths()));
         $tx->execute($this->overrideConflictingPackages($mapping));
         $tx->execute($this->updateConflicts());
         $tx->execute($this->addPathMappingToPackageFile($mapping));
         $tx->execute($syncOp);
         $this->saveRootPackageFile();
         $tx->commit();
     } catch (Exception $e) {
         $tx->rollback();
         throw $e;
     }
 }
Exemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function findExtraKeys(Expression $expr)
 {
     $values = array();
     foreach ($this->rootPackageFile->getExtraKeys() as $key => $value) {
         if ($expr->evaluate($key)) {
             $values[$key] = $value;
         }
     }
     return $values;
 }
 /**
  * {@inheritdoc}
  */
 public function migrate($targetVersion)
 {
     $previousVersion = $this->rootPackageFile->getVersion();
     if ($previousVersion === $targetVersion) {
         return;
     }
     $this->rootPackageFile->setVersion($targetVersion);
     try {
         $this->packageFileStorage->saveRootPackageFile($this->rootPackageFile);
     } catch (Exception $e) {
         $this->rootPackageFile->setVersion($previousVersion);
         throw $e;
     }
 }
Exemplo n.º 8
0
 private function renameNonRootPackage(Package $package, $newName)
 {
     $previousInstallInfo = $package->getInstallInfo();
     $installInfo = new InstallInfo($newName, $previousInstallInfo->getInstallPath());
     $installInfo->setInstallerName($previousInstallInfo->getInstallerName());
     foreach ($previousInstallInfo->getDisabledBindingUuids() as $uuid) {
         $installInfo->addDisabledBindingUuid($uuid);
     }
     $this->rootPackageFile->removeInstallInfo($package->getName());
     $this->rootPackageFile->addInstallInfo($installInfo);
     try {
         $this->packageFileStorage->saveRootPackageFile($this->rootPackageFile);
     } catch (Exception $e) {
         $this->rootPackageFile->removeInstallInfo($newName);
         $this->rootPackageFile->addInstallInfo($previousInstallInfo);
         throw $e;
     }
     $this->packages->remove($package->getName());
     $this->packages->add(new Package($package->getPackageFile(), $package->getInstallPath(), $installInfo, $package->getLoadErrors()));
 }
Exemplo n.º 9
0
 public function testHasInstallInfos()
 {
     $this->assertFalse($this->packageFile->hasInstallInfos());
     $this->packageFile->addInstallInfo(new InstallInfo('vendor/package', '/path/to/package'));
     $this->assertTrue($this->packageFile->hasInstallInfos());
 }
 /**
  * {@inheritdoc}
  */
 public function rollback()
 {
     if ($this->previousMapping) {
         $this->rootPackageFile->addPathMapping($this->previousMapping);
     }
 }
Exemplo n.º 11
0
 private function populateRootConfig(RootPackageFile $packageFile, \stdClass $jsonData)
 {
     if (isset($jsonData->{'override-order'})) {
         $packageFile->setOverrideOrder((array) $jsonData->{'override-order'});
     }
     if (isset($jsonData->plugins)) {
         $packageFile->setPluginClasses($jsonData->plugins);
     }
     if (isset($jsonData->config)) {
         $config = $packageFile->getConfig();
         foreach ($this->objectsToArrays($jsonData->config) as $key => $value) {
             $config->set($key, $value);
         }
     }
     if (isset($jsonData->packages)) {
         foreach ($jsonData->packages as $packageName => $packageData) {
             $installInfo = new InstallInfo($packageName, $packageData->{'install-path'});
             if (isset($packageData->installer)) {
                 $installInfo->setInstallerName($packageData->installer);
             }
             if (isset($packageData->{'enabled-bindings'})) {
                 foreach ($packageData->{'enabled-bindings'} as $uuid) {
                     $installInfo->addEnabledBindingUuid(Uuid::fromString($uuid));
                 }
             }
             if (isset($packageData->{'disabled-bindings'})) {
                 foreach ($packageData->{'disabled-bindings'} as $uuid) {
                     $installInfo->addDisabledBindingUuid(Uuid::fromString($uuid));
                 }
             }
             $packageFile->addInstallInfo($installInfo);
         }
     }
 }
 protected function populateRootManager()
 {
     $this->rootPackageFile->setExtraKey(PackageFileInstallerManager::INSTALLERS_KEY, (object) array('custom-symlink' => (object) array('class' => 'CustomSymlinkInstaller'), 'custom-copy' => (object) array('class' => 'CustomCopyInstaller')));
     $this->packageFile1->setExtraKey(PackageFileInstallerManager::INSTALLERS_KEY, (object) array('rsync' => (object) array('class' => 'RsyncInstaller')));
 }
 /**
  * {@inheritdoc}
  */
 public function rollback()
 {
     if ($this->previousDescriptor) {
         $this->rootPackageFile->addTypeDescriptor($this->previousDescriptor);
     }
 }
Exemplo n.º 14
0
 /**
  * {@inheritdoc}
  */
 public function removeObsoleteDisabledBindingDescriptors()
 {
     $this->assertPackagesLoaded();
     $removedUuidsByPackage = array();
     try {
         foreach ($this->rootPackageFile->getInstallInfos() as $installInfo) {
             foreach ($installInfo->getDisabledBindingUuids() as $uuid) {
                 if (!$this->bindingDescriptors->contains($uuid)) {
                     $installInfo->removeDisabledBindingUuid($uuid);
                     $removedUuidsByPackage[$installInfo->getPackageName()][] = $uuid;
                 }
             }
         }
         $this->saveRootPackageFile();
     } catch (Exception $e) {
         foreach ($removedUuidsByPackage as $packageName => $removedUuids) {
             $installInfo = $this->rootPackageFile->getInstallInfo($packageName);
             foreach ($removedUuids as $uuid) {
                 $installInfo->addDisabledBindingUuid($uuid);
             }
         }
         throw $e;
     }
 }
Exemplo n.º 15
0
 public function testWriteRootPackageFileSortsPackageBindings()
 {
     $installInfo = new InstallInfo('vendor/package1', '/path/to/package1');
     $installInfo->addEnabledBindingUuid(Uuid::fromString('c54e5668-2b36-43f4-a32c-2d175092b77d'));
     $installInfo->addEnabledBindingUuid(Uuid::fromString('a54e5668-2b36-43f4-a32c-2d175092b77d'));
     $installInfo->addEnabledBindingUuid(Uuid::fromString('b54e5668-2b36-43f4-a32c-2d175092b77d'));
     $installInfo->addDisabledBindingUuid(Uuid::fromString('6d02ee67-d845-4789-a9c1-8301351c6f5a'));
     $installInfo->addDisabledBindingUuid(Uuid::fromString('4d02ee67-d845-4789-a9c1-8301351c6f5a'));
     $installInfo->addDisabledBindingUuid(Uuid::fromString('5d02ee67-d845-4789-a9c1-8301351c6f5a'));
     $packageFile = new RootPackageFile();
     $packageFile->addInstallInfo($installInfo);
     $this->writer->writePackageFile($packageFile, $this->tempFile);
     $this->assertFileExists($this->tempFile);
     $this->assertJsonFileEquals(__DIR__ . '/Fixtures/json/sorted-package-bindings.json', $this->tempFile);
 }
Exemplo n.º 16
0
 /**
  * Creates the context of a Puli project.
  *
  * The home directory is read from the context variable "PULI_HOME".
  * If this variable is not set, the home directory defaults to:
  *
  *  * `$HOME/.puli` on Linux, where `$HOME` is the context variable
  *    "HOME".
  *  * `$APPDATA/Puli` on Windows, where `$APPDATA` is the context
  *    variable "APPDATA".
  *
  * If none of these variables can be found, an exception is thrown.
  *
  * A .htaccess file is put into the home directory to protect it from web
  * access.
  *
  * @param string $rootDir The path to the project.
  *
  * @return ProjectContext The project context.
  */
 private function createProjectContext($rootDir, $env)
 {
     Assert::fileExists($rootDir, 'Could not load Puli context: The root %s does not exist.');
     Assert::directory($rootDir, 'Could not load Puli context: The root %s is a file. Expected a directory.');
     $baseConfig = new DefaultConfig();
     $homeDir = self::parseHomeDirectory();
     if (null !== ($configFile = $this->loadConfigFile($homeDir, $baseConfig))) {
         $baseConfig = $configFile->getConfig();
     }
     // Create a storage without the factory manager
     $packageFileStorage = new PackageFileStorage($this->getStorage(), $this->getPackageFileSerializer());
     $rootDir = Path::canonicalize($rootDir);
     $rootFilePath = $this->rootDir . '/puli.json';
     try {
         $rootPackageFile = $packageFileStorage->loadRootPackageFile($rootFilePath, $baseConfig);
     } catch (FileNotFoundException $e) {
         $rootPackageFile = new RootPackageFile(null, $rootFilePath, $baseConfig);
     }
     $config = new EnvConfig($rootPackageFile->getConfig());
     return new ProjectContext($homeDir, $rootDir, $config, $rootPackageFile, $configFile, $this->dispatcher, $env);
 }
Exemplo n.º 17
0
 private function addRootConfig(array &$jsonData, RootPackageFile $packageFile)
 {
     $overrideOrder = $packageFile->getOverrideOrder();
     $installInfos = $packageFile->getInstallInfos();
     // Pass false to exclude base configuration values
     $configValues = $packageFile->getConfig()->toRawArray(false);
     if (count($overrideOrder) > 0) {
         $jsonData['override-order'] = $overrideOrder;
     }
     if (count($configValues) > 0) {
         $jsonData['config'] = (object) $configValues;
     }
     if (array() !== $packageFile->getPluginClasses(false)) {
         $jsonData['plugins'] = $packageFile->getPluginClasses();
         sort($jsonData['plugins']);
     }
     if (count($installInfos) > 0) {
         $packagesData = array();
         foreach ($installInfos as $installInfo) {
             $installData = new stdClass();
             $installData->{'install-path'} = $installInfo->getInstallPath();
             if (InstallInfo::DEFAULT_INSTALLER_NAME !== $installInfo->getInstallerName()) {
                 $installData->installer = $installInfo->getInstallerName();
             }
             if ($installInfo->hasEnabledBindingUuids()) {
                 $installData->{'enabled-bindings'} = array();
                 foreach ($installInfo->getEnabledBindingUuids() as $uuid) {
                     $installData->{'enabled-bindings'}[] = $uuid->toString();
                 }
                 sort($installData->{'enabled-bindings'});
             }
             if ($installInfo->hasDisabledBindingUuids()) {
                 $installData->{'disabled-bindings'} = array();
                 foreach ($installInfo->getDisabledBindingUuids() as $uuid) {
                     $installData->{'disabled-bindings'}[] = $uuid->toString();
                 }
                 sort($installData->{'disabled-bindings'});
             }
             $packagesData[$installInfo->getPackageName()] = $installData;
         }
         ksort($packagesData);
         $jsonData['packages'] = (object) $packagesData;
     }
 }
Exemplo n.º 18
0
    public function testSerializeRootPackageFileSortsPackageBindings()
    {
        $installInfo = new InstallInfo('vendor/package1', '/path/to/package1');
        $installInfo->addDisabledBindingUuid(Uuid::fromString('6d02ee67-d845-4789-a9c1-8301351c6f5a'));
        $installInfo->addDisabledBindingUuid(Uuid::fromString('4d02ee67-d845-4789-a9c1-8301351c6f5a'));
        $installInfo->addDisabledBindingUuid(Uuid::fromString('5d02ee67-d845-4789-a9c1-8301351c6f5a'));
        $packageFile = new RootPackageFile();
        $packageFile->addInstallInfo($installInfo);
        $json = <<<JSON
{
    "version": "1.0",
    "packages": {
        "vendor/package1": {
            "install-path": "/path/to/package1",
            "disabled-bindings": [
                "4d02ee67-d845-4789-a9c1-8301351c6f5a",
                "5d02ee67-d845-4789-a9c1-8301351c6f5a",
                "6d02ee67-d845-4789-a9c1-8301351c6f5a"
            ]
        }
    }
}

JSON;
        $this->assertJsonEquals($json, $this->serializer->serializeRootPackageFile($packageFile));
    }
 protected function populateRootManager()
 {
     $this->rootPackageFile->setExtraKey(AssetPlugin::INSTALLERS_KEY, (object) array('symlink' => (object) array('class' => 'SymlinkInstaller'), 'copy' => (object) array('class' => 'CopyInstaller')));
     $this->packageFile1->setExtraKey(AssetPlugin::INSTALLERS_KEY, (object) array('rsync' => (object) array('class' => 'RsyncInstaller')));
 }