Revision | 883 (tree) |
---|---|
Zeit | 2009-06-21 02:06:56 |
Autor | ![]() |
- re-implemented "ethna make-plugin-package" command.
@@ -24,6 +24,71 @@ | ||
24 | 24 | */ |
25 | 25 | class Ethna_Plugin_Handle_MakePluginPackage extends Ethna_Plugin_Handle |
26 | 26 | { |
27 | + // {{{ _parseArgList() | |
28 | + /** | |
29 | + * @access private | |
30 | + */ | |
31 | + function &_parseArgList() | |
32 | + { | |
33 | + $r =& $this->_getopt( | |
34 | + array( | |
35 | + 'basedir=', | |
36 | + 'workdir=', | |
37 | + 'ini-file-path=' | |
38 | + ) | |
39 | + ); | |
40 | + if (Ethna::isError($r)) { | |
41 | + return $r; | |
42 | + } | |
43 | + list($opt_list, $arg_list) = $r; | |
44 | + | |
45 | + // plugin directory path | |
46 | + $plugin_dir = array_shift($arg_list); | |
47 | + if (empty($plugin_dir)) { | |
48 | + return Ethna::raiseError('plugin directory path is not set.', 'usage'); | |
49 | + } | |
50 | + | |
51 | + // basedir | |
52 | + if (isset($opt_list['basedir'])) { | |
53 | + $basedir = realpath(end($opt_list['basedir'])); | |
54 | + } else { | |
55 | + $basedir = getcwd(); | |
56 | + } | |
57 | + $plugin_dir = "$basedir/${plugin_dir}"; | |
58 | + | |
59 | + // inifile | |
60 | + $inifile = end($opt_list['ini-file_path']); | |
61 | + if (empty($inifile)) { | |
62 | + $inifiles = glob("${plugin_dir}/*.ini"); | |
63 | + if (empty($inifiles)) { | |
64 | + return Ethna::raiseError( | |
65 | + "ERROR: no inifile found on ${plugin_dir}\n" | |
66 | + . ' please specify ini file path with [-i|--ini-file-path] option', | |
67 | + 'usage' | |
68 | + ); | |
69 | + } | |
70 | + if (count($inifile) > 1) { | |
71 | + return Ethna::raiseError( | |
72 | + 'more than 2 .ini file found.' | |
73 | + . ' please specify [-i|--ini-file-path] option', | |
74 | + 'usage' | |
75 | + ); | |
76 | + } | |
77 | + | |
78 | + $inifile = array_shift($inifiles); | |
79 | + $ini = parse_ini_file($inifile, true); | |
80 | + if (empty($ini)) { | |
81 | + return Ethna::raiseError( | |
82 | + "invalid ini file: $inifile" | |
83 | + ); | |
84 | + } | |
85 | + } | |
86 | + | |
87 | + return array($ini, $plugin_dir); | |
88 | + } | |
89 | + // }}} | |
90 | + | |
91 | + | |
27 | 92 | // {{{ perform() |
28 | 93 | /** |
29 | 94 | * @access public |
@@ -30,7 +95,15 @@ | ||
30 | 95 | */ |
31 | 96 | function perform() |
32 | 97 | { |
33 | - require_once 'PEAR/PackageFileManager.php'; | |
98 | + // required package check. | |
99 | + if (!file_exists_ex('PEAR/PackageFileManager2.php') | |
100 | + || !file_exists_ex('PEAR/PackageFileManager/File.php')) { | |
101 | + return Ethna::raiseError( | |
102 | + "ERROR: PEAR_PackageFileManager2 is not installed! please install it.\n" | |
103 | + . "usage: pear install -a pear/PackageFileManager2 " | |
104 | + ); | |
105 | + } | |
106 | + | |
34 | 107 | require_once 'PEAR/PackageFileManager2.php'; |
35 | 108 | require_once 'PEAR/PackageFileManager/File.php'; |
36 | 109 |
@@ -39,24 +112,13 @@ | ||
39 | 112 | if (Ethna::isError($args)) { |
40 | 113 | return $args; |
41 | 114 | } |
42 | - list($ini, $skelfile, $workdir) = $args; | |
115 | + list($ini, $plugin_dir) = $args; | |
43 | 116 | |
44 | - // パッケージを作るプラグインの target | |
45 | - $targets = array(); | |
46 | - if ($ini['plugin']['master'] == true) { | |
47 | - $targets[] = 'master'; | |
48 | - } | |
49 | - if ($ini['plugin']['local'] == true) { | |
50 | - $targets[] = 'local'; | |
51 | - } | |
52 | - | |
53 | 117 | // 設定用の配列を用意 |
54 | 118 | $setting = array(); |
55 | 119 | |
56 | - // {{{ master と local で共通の設定 | |
57 | 120 | // プラグイン名 |
58 | - $ptype = $ini['plugin']['type']; | |
59 | - $pname = $ini['plugin']['name']; | |
121 | + $setting['pkgname'] = $ini['plugin']['name']; | |
60 | 122 | |
61 | 123 | // パッケージの説明 |
62 | 124 | $setting['channel'] = $ini['package']['channel']; |
@@ -90,57 +152,22 @@ | ||
90 | 152 | if (isset($ini['license']['uri'])) { |
91 | 153 | $setting['license']['uri'] = $ini['license']['uri']; |
92 | 154 | } |
93 | - // }}} | |
94 | 155 | |
95 | - // まるまるコピー :-p | |
96 | - $setting = array('master' => $setting, 'local' => $setting); | |
97 | - | |
98 | - // {{{ master と local で異なる部分 | |
99 | - // パッケージ名 | |
100 | - $setting['master']['pkgname'] = "Ethna_Plugin_{$ptype}_{$pname}"; | |
101 | - $setting['local'] ['pkgname'] = "App_Plugin_{$ptype}_{$pname}"; | |
102 | - | |
103 | - // プラグインのファイル名 | |
104 | - $setting['master']['filename'] = "Ethna_Plugin_{$ptype}_{$pname}.php"; | |
105 | - $setting['local'] ['filename'] = "skel.plugin.{$ptype}_{$pname}.php"; | |
106 | - | |
107 | - // 入力ファイルの置換マクロ | |
108 | - $setting['master']['macro'] = array( | |
109 | - // package 時に置換 | |
110 | - 'application_id' => 'Ethna', | |
111 | - 'project_id' => 'Ethna', | |
156 | + // インストールディレクトリ | |
157 | + $setting['config'] = array( | |
158 | + 'baseinstalldir' => 'Plugin', | |
112 | 159 | ); |
113 | - $setting['local']['macro'] = array( | |
114 | - // install 時に置換 | |
115 | - ); | |
116 | 160 | |
117 | - // setOptins($config) 時に merge する設定 | |
118 | - $setting['master']['config'] = array( | |
119 | - 'baseinstalldir' => "Ethna/class/Plugin/{$ptype}", | |
120 | - ); | |
121 | - $setting['local']['config'] = array( | |
122 | - 'baseinstalldir' => '.', | |
123 | - ); | |
124 | - | |
125 | 161 | // 任意に $packagexml->doSomething() するための callback |
126 | - $setting['master']['callback'] = array( | |
162 | + $setting['callback'] = array( | |
127 | 163 | 'addPackageDepWithChannel' |
128 | - => array('optional', 'ethna', 'pear.ethna.jp', '2.3.0'), | |
164 | + => array('required', 'ethna', 'pear.ethna.jp', '2.4.0'), | |
129 | 165 | ); |
130 | - $setting['local']['callback'] = array( | |
131 | - // local 用のパッケージを master にインストールさせないための conflict | |
132 | - 'addConflictingPackageDepWithChannel' | |
133 | - => array('pear', 'pear.php.net'), | |
134 | - ); | |
135 | - // }}} | |
136 | 166 | |
137 | - | |
138 | 167 | // パッケージ作成 |
139 | 168 | $this->pear =& new Ethna_PearWrapper(); |
140 | - $this->pear->init('master'); | |
141 | - foreach ($targets as $target) { | |
142 | - $this->_makePackage($skelfile, $setting[$target], "$workdir/$target"); | |
143 | - } | |
169 | + $this->pear->init('local'); | |
170 | + $this->_makePackage($setting, $plugin_dir); | |
144 | 171 | } |
145 | 172 | // }}} |
146 | 173 |
@@ -148,42 +175,14 @@ | ||
148 | 175 | /** |
149 | 176 | * @access private |
150 | 177 | */ |
151 | - function &_makePackage($skelfile, $setting, $workdir) | |
178 | + function &_makePackage($setting, $workdir) | |
152 | 179 | { |
153 | - if (Ethna_Util::mkdir($workdir, 0755) === false) { | |
154 | - return Ethna::raiseError("failed making working dir: $workdir."); | |
155 | - } | |
156 | - | |
157 | - // プラグインの元ファイルを作成 | |
158 | - $rfp = fopen($skelfile, "r"); | |
159 | - if ($rfp == false) { | |
160 | - return Ethna::raiseError("failed open skelton file: $skelfile."); | |
161 | - } | |
162 | - $outputfile = $setting['filename']; | |
163 | - $wfp = fopen("$workdir/$outputfile", "w"); | |
164 | - if ($rfp == false) { | |
165 | - fclose($rfp); | |
166 | - return Ethna::raiseError("failed creating working file: $outputfile."); | |
167 | - } | |
168 | - for (;;) { | |
169 | - $s = fread($rfp, 4096); | |
170 | - if (strlen($s) == 0) { | |
171 | - break; | |
172 | - } | |
173 | - foreach ($setting['macro'] as $k => $v) { | |
174 | - $s = preg_replace("/{\\\$$k}/", $v, $s); | |
175 | - } | |
176 | - fwrite($wfp, $s); | |
177 | - } | |
178 | - fclose($wfp); | |
179 | - fclose($rfp); | |
180 | - | |
181 | 180 | // package.xml を作る |
182 | 181 | $pkgconfig = array( |
183 | 182 | 'packagedirectory' => $workdir, |
184 | 183 | 'outputdirectory' => $workdir, |
185 | 184 | 'ignore' => array('CVS/', '.cvsignore', '.svn/', |
186 | - 'package.xml', 'package.ini', $setting['pkgname'].'-*.tgz'), | |
185 | + 'package.xml', '*.ini', $setting['pkgname'].'-*.tgz'), | |
187 | 186 | 'filelistgenerator' => 'file', |
188 | 187 | 'changelogoldtonew' => false, |
189 | 188 | ); |
@@ -216,7 +215,7 @@ | ||
216 | 215 | $packagexml->addRole('sh', 'script'); |
217 | 216 | $packagexml->addRole('bat', 'script'); |
218 | 217 | |
219 | - $packagexml->setPhpDep('4.1.0'); | |
218 | + $packagexml->setPhpDep('4.3.0'); | |
220 | 219 | $packagexml->setPearinstallerDep('1.3.5'); |
221 | 220 | |
222 | 221 | $packagexml->generateContents(); |
@@ -230,54 +229,32 @@ | ||
230 | 229 | return Ethna::raiseError($r->getMessage, $r->getCode()); |
231 | 230 | } |
232 | 231 | |
233 | - // package を作る | |
234 | - $r = $this->pear->_run('package', array(), array("$workdir/package.xml")); | |
232 | + // finally make package | |
233 | + PEAR_Command::setFrontendType('CLI'); | |
234 | + $ui =& PEAR_Command::getFrontendObject(); | |
235 | + $config =& PEAR_Config::singleton(); | |
236 | + $ui->setConfig($config); | |
237 | + PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array(&$ui, 'displayFatalError')); | |
238 | + $cmd =& PEAR_Command::factory('package', $config); | |
239 | + if (PEAR::isError($cmd)) { | |
240 | + return Ethna::raiseError($cmd->getMessage, $cmd->getCode()); | |
241 | + } | |
242 | + $r = $cmd->run('package', array(), array("$workdir/package.xml")); | |
235 | 243 | if (PEAR::isError($r)) { |
236 | 244 | return Ethna::raiseError($r->getMessage, $r->getCode()); |
237 | 245 | } |
238 | - | |
239 | - if (Ethna_Util::purgeDir($workdir) === false) { | |
240 | - return Ethna::raiseError("failed cleaning up working dir: $workdir."); | |
241 | - } | |
242 | 246 | } |
243 | 247 | // }}} |
244 | 248 | |
245 | - // {{{ _parseArgList() | |
249 | + // {{{ getUsage() | |
246 | 250 | /** |
247 | - * @access private | |
251 | + * @access public | |
248 | 252 | */ |
249 | - function &_parseArgList() | |
253 | + function getUsage() | |
250 | 254 | { |
251 | - $r =& $this->_getopt(array('inifile=', 'skelfile=', 'workdir=')); | |
252 | - if (Ethna::isError($r)) { | |
253 | - return $r; | |
254 | - } | |
255 | - list($opt_list, $arg_list) = $r; | |
256 | - | |
257 | - // inifile | |
258 | - if (isset($opt_list['inifile']) | |
259 | - && is_readable(end($opt_list['inifile']))) { | |
260 | - $ini = parse_ini_file(end($opt_list['inifile']), true); | |
261 | - } else { | |
262 | - return Ethna::raiseError('give a valid inifile.'); | |
263 | - } | |
264 | - | |
265 | - // skelfile | |
266 | - if (isset($opt_list['skelfile']) | |
267 | - && is_readable(end($opt_list['skelfile']))) { | |
268 | - $skelfile = end($opt_list['skelfile']); | |
269 | - } else { | |
270 | - return Ethna::raiseError('give a valid filename of plugin skelton file.'); | |
271 | - } | |
272 | - | |
273 | - // workdir | |
274 | - if (isset($opt_list['workdir'])) { | |
275 | - $workdir = end($opt_list['workdir']); | |
276 | - } else { | |
277 | - $workdir = getcwd(); | |
278 | - } | |
279 | - | |
280 | - return array($ini, $skelfile, $workdir); | |
255 | + return <<<EOS | |
256 | + {$this->id} [-b|--basedir=dir] [-i|--ini-file-path=file] [plugin_directory_path] | |
257 | +EOS; | |
281 | 258 | } |
282 | 259 | // }}} |
283 | 260 |
@@ -289,8 +266,7 @@ | ||
289 | 266 | { |
290 | 267 | return <<<EOS |
291 | 268 | make plugin package: |
292 | - {$this->id} [-i|--inifile=file] [-s|--skelfile=file] [-w|--workdir=dir] | |
293 | - | |
269 | + {$this->id} [-b|--basedir=dir] [-i|--ini-file-path=file] [plugin_directory_path] | |
294 | 270 | EOS; |
295 | 271 | } |
296 | 272 | // }}} |