Esempio n. 1
0
 function _analyzePhpFiles()
 {
     if (!$this->_isValid) {
         return false;
     }
     if (!isset($this->_pf->_packageFile)) {
         $this->_cannotValidateNoPathSet();
         return false;
     }
     $dir_prefix = dirname($this->_pf->_packageFile);
     $common = new PEAR_Common();
     $log = isset($this->_pf->_logger) ? array(&$this->_pf->_logger, 'log') : array(&$common, 'log');
     $info = $this->_pf->getContents();
     $info = $info['dir']['file'];
     if (isset($info['attribs'])) {
         $info = array($info);
     }
     $provides = array();
     foreach ($info as $fa) {
         $fa = $fa['attribs'];
         $file = $fa['name'];
         if (!file_exists($dir_prefix . DIRECTORY_SEPARATOR . $file)) {
             $this->_fileNotFound($dir_prefix . DIRECTORY_SEPARATOR . $file);
             $this->_isValid = 0;
             continue;
         }
         if (in_array($fa['role'], PEAR_Installer_Role::getPhpRoles()) && $dir_prefix) {
             call_user_func_array($log, array(1, "Analyzing {$file}"));
             $srcinfo = $this->analyzeSourceCode($dir_prefix . DIRECTORY_SEPARATOR . $file);
             if ($srcinfo) {
                 $provides = array_merge($provides, $this->_buildProvidesArray($srcinfo));
             }
         }
     }
     $this->_packageName = $pn = $this->_pf->getPackage();
     $pnl = strlen($pn);
     foreach ($provides as $key => $what) {
         if (isset($what['explicit']) || !$what) {
             // skip conformance checks if the provides entry is
             // specified in the package.xml file
             continue;
         }
         extract($what);
         if ($type == 'class') {
             if (!strncasecmp($name, $pn, $pnl)) {
                 continue;
             }
             $this->_stack->push(__FUNCTION__, 'warning', array('file' => $file, 'type' => $type, 'name' => $name, 'package' => $pn), 'in %file%: %type% "%name%" not prefixed with package name "%package%"');
         } elseif ($type == 'function') {
             if (strstr($name, '::') || !strncasecmp($name, $pn, $pnl)) {
                 continue;
             }
             $this->_stack->push(__FUNCTION__, 'warning', array('file' => $file, 'type' => $type, 'name' => $name, 'package' => $pn), 'in %file%: %type% "%name%" not prefixed with package name "%package%"');
         }
     }
     return $this->_isValid;
 }
Esempio n. 2
0
 /**
  * Package up both a package.xml and package2.xml for the same release
  * @param PEAR_Packager
  * @param PEAR_PackageFile_v1
  * @param bool generate a .tgz or a .tar
  * @param string|null temporary directory to package in
  */
 function toTgz2(&$packager, &$pf1, $compress = true, $where = null)
 {
     require_once 'Archive/Tar.php';
     if (!$this->_packagefile->isEquivalent($pf1)) {
         return PEAR::raiseError('PEAR_Packagefile_v2::toTgz: "' . basename($pf1->getPackageFile()) . '" is not equivalent to "' . basename($this->_packagefile->getPackageFile()) . '"');
     }
     if ($where === null) {
         if (!($where = System::mktemp(array('-d')))) {
             return PEAR::raiseError('PEAR_Packagefile_v2::toTgz: mktemp failed');
         }
     } elseif (!@System::mkDir(array('-p', $where))) {
         return PEAR::raiseError('PEAR_Packagefile_v2::toTgz: "' . $where . '" could' . ' not be created');
     }
     if (file_exists($where . DIRECTORY_SEPARATOR . 'package.xml') && !is_file($where . DIRECTORY_SEPARATOR . 'package.xml')) {
         return PEAR::raiseError('PEAR_Packagefile_v2::toTgz: unable to save package.xml as' . ' "' . $where . DIRECTORY_SEPARATOR . 'package.xml"');
     }
     if (!$this->_packagefile->validate(PEAR_VALIDATE_PACKAGING)) {
         return PEAR::raiseError('PEAR_Packagefile_v2::toTgz: invalid package.xml');
     }
     $ext = $compress ? '.tgz' : '.tar';
     $pkgver = $this->_packagefile->getPackage() . '-' . $this->_packagefile->getVersion();
     $dest_package = getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext;
     if (file_exists(getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext) && !is_file(getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext)) {
         return PEAR::raiseError('PEAR_Packagefile_v2::toTgz: cannot create tgz file "' . getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext . '"');
     }
     if ($pkgfile = $this->_packagefile->getPackageFile()) {
         $pkgdir = dirname(realpath($pkgfile));
         $pkgfile = basename($pkgfile);
     } else {
         return PEAR::raiseError('PEAR_Packagefile_v2::toTgz: package file object must ' . 'be created from a real file');
     }
     // {{{ Create the package file list
     $filelist = array();
     $i = 0;
     $this->_packagefile->flattenFilelist();
     $contents = $this->_packagefile->getContents();
     if (isset($contents['bundledpackage'])) {
         // bundles of packages
         $contents = $contents['bundledpackage'];
         if (!isset($contents[0])) {
             $contents = array($contents);
         }
         $packageDir = $where;
         foreach ($contents as $i => $package) {
             $fname = $package;
             $file = $pkgdir . DIRECTORY_SEPARATOR . $fname;
             if (!file_exists($file)) {
                 return $packager->raiseError("File does not exist: {$fname}");
             }
             $tfile = $packageDir . DIRECTORY_SEPARATOR . $fname;
             System::mkdir(array('-p', dirname($tfile)));
             copy($file, $tfile);
             $filelist[$i++] = $tfile;
             $packager->log(2, "Adding package {$fname}");
         }
     } else {
         // normal packages
         $contents = $contents['dir']['file'];
         if (!isset($contents[0])) {
             $contents = array($contents);
         }
         $packageDir = $where;
         foreach ($contents as $i => $file) {
             $fname = $file['attribs']['name'];
             $atts = $file['attribs'];
             $orig = $file;
             $file = $pkgdir . DIRECTORY_SEPARATOR . $fname;
             if (!file_exists($file)) {
                 return $packager->raiseError("File does not exist: {$fname}");
             } else {
                 $tfile = $packageDir . DIRECTORY_SEPARATOR . $fname;
                 unset($orig['attribs']);
                 if (count($orig)) {
                     // file with tasks
                     // run any package-time tasks
                     if (function_exists('file_get_contents')) {
                         $contents = file_get_contents($file);
                     } else {
                         $fp = fopen($file, "r");
                         $contents = @fread($fp, filesize($file));
                         fclose($fp);
                     }
                     foreach ($orig as $tag => $raw) {
                         $tag = str_replace($this->_packagefile->getTasksNs() . ':', '', $tag);
                         $task = "PEAR_Task_{$tag}";
                         $task =& new $task($this->_packagefile->_config, $this->_packagefile->_logger, PEAR_TASK_PACKAGE);
                         $task->init($raw, $atts, null);
                         $res = $task->startSession($this->_packagefile, $contents, $tfile);
                         if (!$res) {
                             continue;
                             // skip this task
                         }
                         if (PEAR::isError($res)) {
                             return $res;
                         }
                         $contents = $res;
                         // save changes
                         System::mkdir(array('-p', dirname($tfile)));
                         $wp = fopen($tfile, "wb");
                         fwrite($wp, $contents);
                         fclose($wp);
                     }
                 }
                 if (!file_exists($tfile)) {
                     System::mkdir(array('-p', dirname($tfile)));
                     copy($file, $tfile);
                 }
                 $filelist[$i++] = $tfile;
                 $this->_packagefile->setFileAttribute($fname, 'md5sum', md5_file($tfile), $i - 1);
                 $packager->log(2, "Adding file {$fname}");
             }
         }
     }
     // }}}
     if ($pf1 !== null) {
         $name = 'package2.xml';
     } else {
         $name = 'package.xml';
     }
     $packagexml = $this->toPackageFile($where, PEAR_VALIDATE_PACKAGING, $name);
     if ($packagexml) {
         $tar =& new Archive_Tar($dest_package, $compress);
         $tar->setErrorHandling(PEAR_ERROR_RETURN);
         // XXX Don't print errors
         // ----- Creates with the package.xml file
         $ok = $tar->createModify(array($packagexml), '', $where);
         if (PEAR::isError($ok)) {
             return $packager->raiseError($ok);
         } elseif (!$ok) {
             return $packager->raiseError('PEAR_Packagefile_v2::toTgz(): adding ' . $name . ' failed');
         }
         // ----- Add the content of the package
         if (!$tar->addModify($filelist, $pkgver, $where)) {
             return $packager->raiseError('PEAR_Packagefile_v2::toTgz(): tarball creation failed');
         }
         // add the package.xml version 1.0
         if ($pf1 !== null) {
             $pfgen =& $pf1->getDefaultGenerator();
             $packagexml1 = $pfgen->toPackageFile($where, PEAR_VALIDATE_PACKAGING, 'package.xml', true);
             if (!$tar->addModify(array($packagexml1), '', $where)) {
                 return $packager->raiseError('PEAR_Packagefile_v2::toTgz(): adding package.xml failed');
             }
         }
         return $dest_package;
     }
 }