Esempio n. 1
0
    function __construct(\PEAR2\Pyrus\Package\Dependency\Set $set,
                         \PEAR2\Pyrus\Package $node, PackageTree $parent = null)
    {
        $this->set    = $set;
        $this->node   = $node;
        $this->parent = $parent;
        $this->name   = $node->channel . '/' . $node->name;
        if ($node->isRemote() && $node->isAbstract()) {
            if ($node->getExplicitVersion()) {
                $this->firstVersion = $node->getExplicitVersion();
                if (isset(static::$availableVersionsMap[$this->name])) {
                    $rebuild = true;
                } else {
                    $rebuild = false;
                }

                $this->allVersions = $this->versionsAvailable = array($node->version['release']);
                $this->setAvailableVersionsMap();
                if ($rebuild) {
                    $this->rebuild($this->name);
                }

                self::register($this);
                return;
            }

            if (isset(self::$availableVersionsMap[$this->name])) {
                $this->allVersions = $this->versionsAvailable =
                    self::$availableVersionsMap[$this->name];
            } else {
                while (!($node instanceof \PEAR2\Pyrus\Channel\RemotePackage)) {
                    $node = $node->getInternalPackage();
                }

                foreach ($node->getReleaseList() as $info) {
                    $this->allVersions[] = $info['v'];
                    $this->versionsAvailable[] = $info['v'];
                }

                if (null === $parent) {
                    return $this->findParentVersion();
                }

                $this->setAvailableVersionsMap();
            }
        } else {
            $this->allVersions = $this->versionsAvailable = array($node->version['release']);
            $this->setAvailableVersionsMap();
        }

        self::register($this);
    }
Esempio n. 2
0
    function __get($var)
    {
        if ($var === 'requestedGroup') {
            return $this->requestedGroup();
        }

        return parent::__get($var);
    }
Esempio n. 3
0
 function saveRelease(\PEAR2\Pyrus\Package $new)
 {
     $outfile = $this->get.'/'.$new->name.'-'.$new->version['release'];
     if (!$new->isNewPackage()) {
         // this is a PEAR 1.x package
         $internal = $new->getInternalPackage();
         if ($internal instanceof \PEAR2\Pyrus\Package\Tar || $internal instanceof \PEAR2\Pyrus\Package\Phar) {
             $path = $internal->getTarballPath();
             $fp = fopen($path, 'rb');
             if (fread($fp, 3) == "\x1f\x8b\x08") {
                 // tgz
                 fclose($fp);
                 copy($path, $outfile . '.tgz');
                 $gp = gzopen($path, 'rb');
                 $fp = fopen($outfile . 'tar', 'wb');
                 stream_copy_to_stream($gp, $fp);
                 fclose($gp);
                 fclose($fp);
             } else {
                 // tar
                 copy($path, $outfile . '.tar');
                 $gp = gzopen($outfile . 'tgz', 'wb');
                 rewind($fp);
                 stream_copy_to_stream($fp, $gp);
                 fclose($gp);
                 fclose($fp);
             }
             return;
         }
     }
     $a = new \PEAR2\Pyrus\Package\Creator(array(
                 new \PEAR2\Pyrus\Developer\Creator\Phar($outfile.'.tar', false, Phar::TAR, Phar::NONE,
                                                        array(
                                                              array('tgz', Phar::TAR, Phar::GZ),
                                                              array('zip', Phar::ZIP, Phar::NONE),
                                                             ))),
                 $this->pyruspath,
                 $this->pyruspath,
                 $this->pyruspath);
     return $a->render($new);
 }
Esempio n. 4
0
 /**
  * Render packages from the creators passed into the constructor.
  *
  * This will take any package source and an array mapping internal
  * path => file name and create new packages in the formats requested.
  *
  * All files in package.xml will have the string @PACKAGE_VERSION@
  * automatically replaced with the current package's version
  * @param \PEAR2\Pyrus\Package $package
  * @param array $extrafiles
  */
 function render(\PEAR2\Pyrus\Package $package, array $extrafiles = array())
 {
     foreach ($this->_creators as $creator) {
         $creator->init();
     }
     $this->prepend = $prepend = $package->name . '-' . $package->version['release'];
     if ($package->isNewPackage()) {
         $packagexml = $prepend . '/.xmlregistry/packages/' . str_replace('/', '!', $package->channel) . '/' . $package->name . '/' . $package->version['release'] . '-info.xml';
     } else {
         if ($package->isOldAndCrustyCompatible()) {
             $packagexml = 'package2.xml';
             $old = file_get_contents('package.xml');
         } else {
             $packagexml = 'package.xml';
         }
     }
     if (self::VERSION === '@' . 'PACKAGE_VERSION@') {
         // we're running straight from SVN, so pretend to be 2.0.0
         $package->packagerversion = '2.0.0';
     } else {
         $package->packagerversion = self::VERSION;
     }
     // get packaging package.xml
     $packageingstr = (string) new \PEAR2\Pyrus\XMLWriter($package->toArray(true));
     foreach ($this->_creators as $creator) {
         $creator->addFile($packagexml, $packageingstr);
     }
     if ($package->isOldAndCrustyCompatible()) {
         foreach ($this->_creators as $creator) {
             $creator->addFile('package.xml', $old);
         }
     }
     if ($package->getInternalPackage() instanceof Xml) {
         // check for package_compatible.xml
         if ($package->isNewPackage() && file_exists($package->getFilePath('package_compatible.xml'))) {
             foreach ($this->_creators as $creator) {
                 $creator->addFile('package.xml', file_get_contents($package->getFilePath('package_compatible.xml')));
             }
         }
     }
     $packagingloc = \PEAR2\Pyrus\Config::current()->temp_dir . DIRECTORY_SEPARATOR . 'pyrpackage';
     if (file_exists($packagingloc)) {
         \PEAR2\Pyrus\Filesystem::rmrf($packagingloc, false, false);
     }
     mkdir($packagingloc, 0777, true);
     // $packageat is the relative path within the archive
     // $info is an array of format:
     // array('attribs' => array('name' => ...)[, 'tasks:blah' ...])
     $alreadyPackaged = array();
     $globalreplace = array('attribs' => array('from' => '@' . 'PACKAGE_VERSION@', 'to' => 'version', 'type' => 'package-info'));
     foreach ($package->packagingcontents as $packageat => $info) {
         $role = \PEAR2\Pyrus\Installer\Role::factory($package->getPackageType(), $info['attribs']['role']);
         try {
             $role->packageTimeValidate($package, $info);
         } catch (\Exception $e) {
             throw new Creator\Exception('Invalid file ' . $packageat . ': ' . $e->getMessage(), $e);
         }
         $packageat = str_replace('\\', '/', $packageat);
         $packageat = str_replace('//', '/', $packageat);
         if ($packageat[0] === '/' || strlen($packageat) > 2 && ($packageat[1] === ':' && $packageat[2] == '/')) {
             throw new Creator\Exception('Invalid path, cannot save a root path ' . $packageat);
         }
         if (preg_match('@^\\.\\.?/|/\\.\\.?\\z|/\\.\\./@', $packageat)) {
             throw new Creator\Exception('Invalid path, cannot use directory ' . 'reference . or .. ' . $packageat);
         }
         $alreadyPackaged[$packageat] = true;
         $packageat = $prepend . '/' . $packageat;
         $contents = $package->getFileContents($info['attribs']['name'], true);
         if (!file_exists(dirname($packagingloc . DIRECTORY_SEPARATOR . $packageat))) {
             mkdir(dirname($packagingloc . DIRECTORY_SEPARATOR . $packageat), 0777, true);
         }
         $fp = fopen($packagingloc . DIRECTORY_SEPARATOR . $packageat, 'wb+');
         ftruncate($fp, 0);
         stream_copy_to_stream($contents, $fp);
         fclose($contents);
         rewind($fp);
         if ($package->isNewPackage() && $info['attribs']['role'] == 'php') {
             if (isset($info['tasks:replace'])) {
                 if (isset($info['tasks:replace'][0])) {
                     $info['tasks:replace'][] = $globalreplace;
                 } else {
                     $info['tasks:replace'] = array($info['tasks:replace'], $globalreplace);
                 }
             } else {
                 $info['tasks:replace'] = $globalreplace;
             }
         }
         if (isset(\PEAR2\Pyrus\Config::current()->registry->package[$package->channel . '/' . $package->name])) {
             $version = \PEAR2\Pyrus\Config::current()->registry->info($package->name, $package->channel, 'version');
         } else {
             $version = null;
         }
         foreach (new Creator\TaskIterator($info, $package, \PEAR2\Pyrus\Task\Common::PACKAGE, $version) as $task) {
             // do pre-processing of file contents
             try {
                 $task->startSession($fp, $packageat);
             } catch (\Exception $e) {
                 // TODO: handle exceptions
             }
         }
         fclose($fp);
     }
     foreach ($this->_creators as $creator) {
         $creator->addDir($packagingloc);
     }
     if ($package->isNewPackage()) {
         $this->addPEAR2Stuff($alreadyPackaged);
     }
     $this->addExtraFiles($extrafiles);
     foreach ($this->_creators as $creator) {
         $creator->close();
     }
     \PEAR2\Pyrus\Filesystem::rmrf($packagingloc, false, false);
 }