Source for file MakePluginPackage.php

Documentation is available at MakePluginPackage.php

  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4.  *  MakePluginPackage.php
  5.  *
  6.  *  please go to http://ethna.jp/ethna-document-dev_guide-pearchannel.html
  7.  *  for more info.
  8.  *
  9.  *  @author     ICHII Takashi <ichii386@schweetheart.jp>
  10.  *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
  11.  *  @package    Ethna
  12.  *  @version    $Id: 6e1bf6ad685b96a1f05251541e41e14b3c1d6b4e $
  13.  */
  14.  
  15. require_once ETHNA_BASE '/class/PearWrapper.php';
  16.  
  17. // {{{ Ethna_Plugin_Handle_MakePluginPackage
  18. /**
  19.  *  make-plugin-package handler.
  20.  *
  21.  *  @author     ICHII Takashi <ichii386@schweetheart.jp>
  22.  *  @access     public
  23.  *  @package    Ethna
  24.  */
  25. {
  26.     // {{{ _parseArgList()
  27.     /**
  28.      * @access private
  29.      */
  30.     function _parseArgList()
  31.     {
  32.         $r $this->_getopt(
  33.             array(
  34.                 'basedir=',
  35.                 'workdir=',
  36.                 'ini-file-path='
  37.             )
  38.         );
  39.         if (Ethna::isError($r)) {
  40.             return $r;
  41.         }
  42.         list($opt_list$arg_list$r;
  43.  
  44.         //  plugin directory path 
  45.         $plugin_dir array_shift($arg_list);
  46.         if (empty($plugin_dir)) {
  47.             return Ethna::raiseError('plugin directory path is not set.''usage');
  48.         }
  49.  
  50.         //  basedir
  51.         if (isset($opt_list['basedir'])) {
  52.             $basedir realpath(end($opt_list['basedir']));
  53.         else {
  54.             $basedir getcwd();
  55.         }
  56.         $plugin_dir "$basedir/${plugin_dir}";
  57.  
  58.         // inifile
  59.         $inifile end($opt_list['ini-file_path']);
  60.         if (empty($inifile)) {
  61.             $inifiles glob("${plugin_dir}/*.ini");
  62.             if (empty($inifiles)) {
  63.                 return Ethna::raiseError(
  64.                     "ERROR: no inifile found on ${plugin_dir}\n"
  65.                   . ' please specify ini file path with [-i|--ini-file-path] option',
  66.                     'usage'
  67.                 );
  68.             }
  69.             if (count($inifile1{
  70.                 return Ethna::raiseError(
  71.                     'more than 2 .ini file found.'
  72.                   . ' please specify [-i|--ini-file-path] option',
  73.                     'usage'
  74.                 );
  75.             }
  76.  
  77.             $inifile array_shift($inifiles);
  78.             $ini parse_ini_file($inifiletrue);
  79.             if (empty($ini)) {
  80.                 return Ethna::raiseError(
  81.                     "invalid ini file: $inifile"
  82.                 );
  83.             }
  84.         }
  85.  
  86.         return array($ini$plugin_dir);
  87.     }
  88.     // }}}
  89.  
  90.  
  91.     // {{{ perform()
  92.     /**
  93.      * @access public
  94.      */
  95.     function perform()
  96.     {
  97.         //    required package check.
  98.         if (!file_exists_ex('PEAR/PackageFileManager2.php')
  99.          || !file_exists_ex('PEAR/PackageFileManager/File.php')) {
  100.             return Ethna::raiseError(
  101.                 "ERROR: PEAR_PackageFileManager2 is not installed! please install it.\n"
  102.               . "usage: pear install -a pear/PackageFileManager2 "
  103.             );
  104.         }
  105.  
  106.         require_once 'PEAR/PackageFileManager2.php';
  107.         require_once 'PEAR/PackageFileManager/File.php';
  108.  
  109.         // 引数の評価
  110.         $args $this->_parseArgList();
  111.         if (Ethna::isError($args)) {
  112.             return $args;
  113.         }
  114.         list($ini$plugin_dir$args;
  115.  
  116.         // 設定用の配列を用意
  117.         $setting array();
  118.  
  119.         // プラグイン名
  120.         $setting['pkgname'$ini['plugin']['name'];
  121.  
  122.         // パッケージの説明
  123.         $setting['channel']     $ini['package']['channel'];
  124.         $setting['summary']     $ini['package']['summary'];
  125.         $setting['description'$ini['package']['description'];
  126.  
  127.         // リリースの説明
  128.         $setting['version']     $ini['release']['version'];
  129.         $setting['state']       $ini['release']['state'];
  130.         $setting['notes']       $ini['release']['notes'];
  131.  
  132.         // メンテナ
  133.         $mnts $ini['maintainers'];
  134.         for ($i 1; ; $i++{
  135.             if (isset($mnts["name$i"]== false
  136.                 || isset($mnts["user$i"]== false
  137.                 || isset($mnts["email$i"]== false{
  138.                 break;
  139.             }
  140.             $setting['maintainers'][array(
  141.                 'user'   => $mnts["user$i"],
  142.                 'name'   => $mnts["name$i"],
  143.                 'email'  => $mnts["email$i"],
  144.                 'role'   => isset($mnts["role$i"]$mnts["role$i"'lead',
  145.                 'active' => isset($mnts["active$i"]$mnts["active$i"== true'yes',
  146.                 );
  147.         }
  148.  
  149.         // ライセンス
  150.         $setting['license']['name'$ini['license']['name'];
  151.         if (isset($ini['license']['uri'])) {
  152.             $setting['license']['uri'$ini['license']['uri'];
  153.         }
  154.  
  155.         // インストールディレクトリ
  156.         $setting['config'array(
  157.             'baseinstalldir' => 'Ethna/extlib/Plugin',
  158.             );
  159.  
  160.         // 任意に $packagexml->doSomething() するための callback
  161.         $setting['callback'array(
  162.             'addPackageDepWithChannel'
  163.                 => array('optional''ethna''pear.ethna.jp''2.6.0'),
  164.             );
  165.  
  166.         // パッケージ作成
  167.         $this->_makePackage($setting$plugin_dir);
  168.     }
  169.     // }}}
  170.  
  171.     // {{{ _makePackage()
  172.     /**
  173.      * @access private
  174.      */
  175.     function _makePackage($setting$workdir)
  176.     {
  177.         // package.xml を作る
  178.         $pkgconfig array(
  179.             'packagedirectory' => $workdir,
  180.             'outputdirectory' => $workdir,
  181.             'ignore' => array('CVS/''.cvsignore''.svn/',
  182.                               'package.xml''*.ini'$setting['pkgname'].'-*.tgz'),
  183.             'filelistgenerator' => 'file',
  184.             'changelogoldtonew' => false,
  185.             );
  186.  
  187.         $packagexml new PEAR_PackageFileManager2();
  188.  
  189.         $pkgconfig array_merge($pkgconfig$setting['config']);
  190.         $packagexml->setOptions($pkgconfig);
  191.  
  192.         $packagexml->setPackage($setting['pkgname']);
  193.         $packagexml->setSummary($setting['summary']);
  194.         $packagexml->setNotes($setting['notes']);
  195.         $packagexml->setDescription($setting['description']);
  196.         $packagexml->setChannel($setting['channel']);
  197.         $packagexml->setAPIVersion($setting['version']);
  198.         $packagexml->setReleaseVersion($setting['version']);
  199.         $packagexml->setReleaseStability($setting['state']);
  200.         $packagexml->setAPIStability($setting['state']);
  201.         $packagexml->setPackageType('php');
  202.         foreach ($setting['maintainers'as $m{
  203.             $packagexml->addMaintainer($m['role']$m['user']$m['name'],
  204.                                        $m['email']$m['active']);
  205.         }
  206.         $packagexml->setLicense($setting['license']['name'],
  207.                                 $setting['license']['uri']);
  208.  
  209.         $packagexml->addRole('css''php');
  210.         $packagexml->addRole('tpl''php');
  211.         $packagexml->addRole('ethna''php');
  212.         $packagexml->addRole('sh''script');
  213.         $packagexml->addRole('bat''script');
  214.  
  215.         $packagexml->setPhpDep('4.3.0');
  216.         $packagexml->setPearinstallerDep('1.3.5');
  217.  
  218.         $packagexml->generateContents();
  219.  
  220.         foreach ($setting['callback'as $method => $params{
  221.             $r call_user_func_array(array($packagexml$method)$params);
  222.         }
  223.  
  224.         $r $packagexml->writePackageFile();
  225.         if (PEAR::isError($r)) {
  226.             return Ethna::raiseError($r->getMessage$r->getCode());
  227.         }
  228.  
  229.         //  finally make package
  230.         PEAR_Command::setFrontendType('CLI');
  231.         $ui PEAR_Command::getFrontendObject();
  232.         $config PEAR_Config::singleton();
  233.         $ui->setConfig($config);
  234.         PEAR::setErrorHandling(PEAR_ERROR_CALLBACKarray($ui'displayFatalError'));
  235.         $cmd PEAR_Command::factory('package'$config);
  236.         if (PEAR::isError($cmd)) {
  237.             return Ethna::raiseError($cmd->getMessage$cmd->getCode());
  238.         }
  239.         $r $cmd->run('package'array()array("$workdir/package.xml"));
  240.         if (PEAR::isError($r)) {
  241.             return Ethna::raiseError($r->getMessage$r->getCode());
  242.         }
  243.     }
  244.     // }}}
  245.  
  246.     // {{{ getUsage()
  247.     /**
  248.      *  @access public
  249.      */
  250.     function getUsage()
  251.     {
  252.         return <<<EOS
  253.     {$this->id} [-b|--basedir=dir] [-i|--ini-file-path=file] [plugin_directory_path] 
  254. EOS;
  255.     }
  256.     // }}}
  257.  
  258.     // {{{ getDescription()
  259.     /**
  260.      *  @access public
  261.      */
  262.     function getDescription()
  263.     {
  264.         return <<<EOS
  265. make plugin package:
  266.     {$this->id} [-b|--basedir=dir] [-i|--ini-file-path=file] [plugin_directory_path] 
  267. EOS;
  268.     }
  269.     // }}}
  270. }
  271. // }}}

Documentation generated on Fri, 11 Nov 2011 03:58:36 +0900 by phpDocumentor 1.4.3