Subversion Repositories Applications.gtt

Rev

Rev 94 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 94 Rev 187
Line 3... Line 3...
3
 * PEAR_Command_Package (package, package-validate, cvsdiff, cvstag, package-dependencies,
3
 * PEAR_Command_Package (package, package-validate, cvsdiff, cvstag, package-dependencies,
4
 * sign, makerpm, convert commands)
4
 * sign, makerpm, convert commands)
5
 *
5
 *
6
 * PHP versions 4 and 5
6
 * PHP versions 4 and 5
7
 *
7
 *
8
 * LICENSE: This source file is subject to version 3.0 of the PHP license
-
 
9
 * that is available through the world-wide-web at the following URI:
-
 
10
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
-
 
11
 * the PHP License and are unable to obtain it through the web, please
-
 
12
 * send a note to license@php.net so we can mail you a copy immediately.
-
 
13
 *
-
 
14
 * @category   pear
8
 * @category   pear
15
 * @package    PEAR
9
 * @package    PEAR
16
 * @author     Stig Bakken <ssb@php.net>
10
 * @author     Stig Bakken <ssb@php.net>
17
 * @author     Martin Jansen <mj@php.net>
11
 * @author     Martin Jansen <mj@php.net>
18
 * @author     Greg Beaver <cellog@php.net>
12
 * @author     Greg Beaver <cellog@php.net>
19
 * @copyright  1997-2006 The PHP Group
13
 * @copyright  1997-2009 The Authors
20
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
14
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
21
 * @version    CVS: $Id: Package.php,v 1.122 2006/06/07 23:38:14 pajoye Exp $
-
 
22
 * @link       http://pear.php.net/package/PEAR
15
 * @link       http://pear.php.net/package/PEAR
23
 * @since      File available since Release 0.1
16
 * @since      File available since Release 0.1
24
 */
17
 */
Line 25... Line 18...
25
 
18
 
Line 34... Line 27...
34
 * @category   pear
27
 * @category   pear
35
 * @package    PEAR
28
 * @package    PEAR
36
 * @author     Stig Bakken <ssb@php.net>
29
 * @author     Stig Bakken <ssb@php.net>
37
 * @author     Martin Jansen <mj@php.net>
30
 * @author     Martin Jansen <mj@php.net>
38
 * @author     Greg Beaver <cellog@php.net>
31
 * @author     Greg Beaver <cellog@php.net>
39
 * @copyright  1997-2006 The PHP Group
32
 * @copyright  1997-2009 The Authors
40
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
33
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
41
 * @version    Release: 1.5.1
34
 * @version    Release: @package_version@
42
 * @link       http://pear.php.net/package/PEAR
35
 * @link       http://pear.php.net/package/PEAR
43
 * @since      Class available since Release 0.1
36
 * @since      Class available since Release 0.1
44
 */
37
 */
Line 45... Line 38...
45
 
38
 
46
class PEAR_Command_Package extends PEAR_Command_Common
39
class PEAR_Command_Package extends PEAR_Command_Common
47
{
-
 
48
    // {{{ properties
-
 
49
 
40
{
50
    var $commands = array(
41
    var $commands = array(
51
        'package' => array(
42
        'package' => array(
52
            'summary' => 'Build Package',
43
            'summary' => 'Build Package',
53
            'function' => 'doPackage',
44
            'function' => 'doPackage',
Line 140... Line 131...
140
command will compare the current code with the last checked-in code.
131
command will compare the current code with the last checked-in code.
141
Using the -r or -R option you may compare the current code with that
132
Using the -r or -R option you may compare the current code with that
142
of a specific release.
133
of a specific release.
143
',
134
',
144
            ),
135
            ),
-
 
136
         'svntag' => array(
-
 
137
             'summary' => 'Set SVN Release Tag',
-
 
138
             'function' => 'doSvnTag',
-
 
139
             'shortcut' => 'sv',
-
 
140
             'options' => array(
-
 
141
                 'quiet' => array(
-
 
142
                     'shortopt' => 'q',
-
 
143
                     'doc' => 'Be quiet',
-
 
144
                     ),
-
 
145
                 'slide' => array(
-
 
146
                     'shortopt' => 'F',
-
 
147
                     'doc' => 'Move (slide) tag if it exists',
-
 
148
                     ),
-
 
149
                 'delete' => array(
-
 
150
                     'shortopt' => 'd',
-
 
151
                     'doc' => 'Remove tag',
-
 
152
                     ),
-
 
153
                 'dry-run' => array(
-
 
154
                     'shortopt' => 'n',
-
 
155
                     'doc' => 'Don\'t do anything, just pretend',
-
 
156
                     ),
-
 
157
                 ),
-
 
158
             'doc' => '<package.xml> [files...]
-
 
159
 Sets a SVN tag on all files in a package.  Use this command after you have
-
 
160
 packaged a distribution tarball with the "package" command to tag what
-
 
161
 revisions of what files were in that release.  If need to fix something
-
 
162
 after running svntag once, but before the tarball is released to the public,
-
 
163
 use the "slide" option to move the release tag.
-
 
164
 
-
 
165
 to include files (such as a second package.xml, or tests not included in the
-
 
166
 release), pass them as additional parameters.
-
 
167
 ',
-
 
168
             ),
145
        'cvstag' => array(
169
        'cvstag' => array(
146
            'summary' => 'Set CVS Release Tag',
170
            'summary' => 'Set CVS Release Tag',
147
            'function' => 'doCvsTag',
171
            'function' => 'doCvsTag',
148
            'shortcut' => 'ct',
172
            'shortcut' => 'ct',
149
            'options' => array(
173
            'options' => array(
Line 182... Line 206...
182
        'package-dependencies' => array(
206
        'package-dependencies' => array(
183
            'summary' => 'Show package dependencies',
207
            'summary' => 'Show package dependencies',
184
            'function' => 'doPackageDependencies',
208
            'function' => 'doPackageDependencies',
185
            'shortcut' => 'pd',
209
            'shortcut' => 'pd',
186
            'options' => array(),
210
            'options' => array(),
187
            'doc' => '
211
            'doc' => '<package-file> or <package.xml> or <install-package-name>
188
List all dependencies the package has.'
212
List all dependencies the package has.
-
 
213
Can take a tgz / tar file, package.xml or a package name of an installed package.'
189
            ),
214
            ),
190
        'sign' => array(
215
        'sign' => array(
191
            'summary' => 'Sign a package distribution file',
216
            'summary' => 'Sign a package distribution file',
192
            'function' => 'doSign',
217
            'function' => 'doSign',
193
            'shortcut' => 'si',
218
            'shortcut' => 'si',
194
            'options' => array(),
219
            'options' => array(
-
 
220
                'verbose' => array(
-
 
221
                    'shortopt' => 'v',
-
 
222
                    'doc' => 'Display GnuPG output',
-
 
223
                    ),
-
 
224
            ),
195
            'doc' => '<package-file>
225
            'doc' => '<package-file>
196
Signs a package distribution (.tar or .tgz) file with GnuPG.',
226
Signs a package distribution (.tar or .tgz) file with GnuPG.',
197
            ),
227
            ),
198
        'makerpm' => array(
228
        'makerpm' => array(
199
            'summary' => 'Builds an RPM spec file from a PEAR package',
229
            'summary' => 'Builds an RPM spec file from a PEAR package',
Line 245... Line 275...
245
            ),
275
            ),
246
        );
276
        );
Line 247... Line 277...
247
 
277
 
Line 248... Line -...
248
    var $output;
-
 
249
 
-
 
250
    // }}}
-
 
251
    // {{{ constructor
278
    var $output;
252
 
279
 
253
    /**
280
    /**
254
     * PEAR_Command_Package constructor.
281
     * PEAR_Command_Package constructor.
255
     *
282
     *
256
     * @access public
283
     * @access public
257
     */
284
     */
258
    function PEAR_Command_Package(&$ui, &$config)
285
    function __construct(&$ui, &$config)
259
    {
286
    {
Line 260... Line -...
260
        parent::PEAR_Command_Common($ui, $config);
-
 
261
    }
-
 
262
 
-
 
263
    // }}}
-
 
264
 
287
        parent::__construct($ui, $config);
265
    // {{{ _displayValidationResults()
288
    }
266
 
289
 
267
    function _displayValidationResults($err, $warn, $strict = false)
290
    function _displayValidationResults($err, $warn, $strict = false)
268
    {
291
    {
269
        foreach ($err as $e) {
292
        foreach ($err as $e) {
270
            $this->output .= "Error: $e\n";
293
            $this->output .= "Error: $e\n";
271
        }
294
        }
272
        foreach ($warn as $w) {
295
        foreach ($warn as $w) {
273
            $this->output .= "Warning: $w\n";
296
            $this->output .= "Warning: $w\n";
274
        }
297
        }
275
        $this->output .= sprintf('Validation: %d error(s), %d warning(s)'."\n",
298
        $this->output .= sprintf('Validation: %d error(s), %d warning(s)'."\n",
276
                                       sizeof($err), sizeof($warn));
299
                                       sizeof($err), sizeof($warn));
277
        if ($strict && sizeof($err) > 0) {
300
        if ($strict && count($err) > 0) {
278
            $this->output .= "Fix these errors and try again.";
301
            $this->output .= "Fix these errors and try again.";
279
            return false;
302
            return false;
Line 280... Line -...
280
        }
-
 
281
        return true;
303
        }
282
    }
304
        return true;
283
 
305
    }
284
    // }}}
306
 
285
    function &getPackager()
307
    function &getPackager()
286
    {
308
    {
287
        if (!class_exists('PEAR_Packager')) {
309
        if (!class_exists('PEAR_Packager')) {
288
            require_once 'PEAR/Packager.php';
310
            require_once 'PEAR/Packager.php';
Line 289... Line 311...
289
        }
311
        }
290
        $a = &new PEAR_Packager;
312
        $a = new PEAR_Packager;
291
        return $a;
313
        return $a;
292
    }
314
    }
293
 
315
 
294
    function &getPackageFile($config, $debug = false, $tmpdir = null)
316
    function &getPackageFile($config, $debug = false)
295
    {
317
    {
296
        if (!class_exists('PEAR_Common')) {
318
        if (!class_exists('PEAR_Common')) {
297
            require_once 'PEAR/Common.php';
319
            require_once 'PEAR/Common.php';
298
        }
320
        }
299
        if (!class_exists('PEAR/PackageFile.php')) {
321
        if (!class_exists('PEAR_PackageFile')) {
300
            require_once 'PEAR/PackageFile.php';
322
            require_once 'PEAR/PackageFile.php';
301
        }
323
        }
302
        $a = &new PEAR_PackageFile($config, $debug, $tmpdir);
324
        $a = new PEAR_PackageFile($config, $debug);
303
        $common = new PEAR_Common;
-
 
Line 304... Line 325...
304
        $common->ui = $this->ui;
325
        $common = new PEAR_Common;
305
        $a->setLogger($common);
326
        $common->ui = $this->ui;
306
        return $a;
327
        $a->setLogger($common);
307
    }
328
        return $a;
308
    // {{{ doPackage()
329
    }
309
 
-
 
310
    function doPackage($command, $options, $params)
330
 
311
    {
331
    function doPackage($command, $options, $params)
312
        $this->output = '';
-
 
313
        $pkginfofile = isset($params[0]) ? $params[0] : 'package.xml';
332
    {
-
 
333
        $this->output = '';
314
        $pkg2 = isset($params[1]) ? $params[1] : null;
334
        $pkginfofile = isset($params[0]) ? $params[0] : 'package.xml';
315
        if (!$pkg2 && !isset($params[0])) {
335
        $pkg2 = isset($params[1]) ? $params[1] : null;
316
            if (file_exists('package2.xml')) {
336
        if (!$pkg2 && !isset($params[0]) && file_exists('package2.xml')) {
317
                $pkg2 = 'package2.xml';
337
            $pkg2 = 'package2.xml';
318
            }
338
        }
319
        }
339
 
-
 
340
        $packager = &$this->getPackager();
320
        $packager = &$this->getPackager();
341
        $compress = empty($options['nocompress']) ? true : false;
321
        $compress = empty($options['nocompress']) ? true : false;
342
        $result   = $packager->package($pkginfofile, $compress, $pkg2);
322
        $result = $packager->package($pkginfofile, $compress, $pkg2);
343
        if (PEAR::isError($result)) {
323
        if (PEAR::isError($result)) {
344
            return $this->raiseError($result);
-
 
345
        }
324
            return $this->raiseError($result);
346
 
325
        }
347
        // Don't want output, only the package file name just created
326
        // Don't want output, only the package file name just created
348
        if (isset($options['showname'])) {
-
 
349
            $this->output = $result;
327
        if (isset($options['showname'])) {
350
        }
328
            $this->output = $result;
351
 
Line 329... Line -...
329
        }
-
 
330
        if ($this->output) {
-
 
331
            $this->ui->outputData($this->output, $command);
-
 
332
        }
352
        if ($this->output) {
333
        return true;
353
            $this->ui->outputData($this->output, $command);
334
    }
354
        }
335
 
355
 
336
    // }}}
356
        return true;
337
    // {{{ doPackageValidate()
357
    }
-
 
358
 
338
 
359
    function doPackageValidate($command, $options, $params)
339
    function doPackageValidate($command, $options, $params)
360
    {
340
    {
361
        $this->output = '';
341
        $this->output = '';
362
        if (count($params) < 1) {
342
        if (sizeof($params) < 1) {
363
            $params[0] = 'package.xml';
343
            $params[0] = "package.xml";
364
        }
344
        }
365
 
345
        $obj = &$this->getPackageFile($this->config, $this->_debug);
366
        $obj = &$this->getPackageFile($this->config, $this->_debug);
346
        $obj->rawReturn();
367
        $obj->rawReturn();
347
        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
368
        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
348
        $info = $obj->fromTgzFile($params[0], PEAR_VALIDATE_NORMAL);
369
        $info = $obj->fromTgzFile($params[0], PEAR_VALIDATE_NORMAL);
349
        if (PEAR::isError($info)) {
370
        if (PEAR::isError($info)) {
350
            $info = $obj->fromPackageFile($params[0], PEAR_VALIDATE_NORMAL);
371
            $info = $obj->fromPackageFile($params[0], PEAR_VALIDATE_NORMAL);
351
        } else {
372
        } else {
-
 
373
            $archive = $info->getArchiveFile();
352
            $archive = $info->getArchiveFile();
374
            $tar = new Archive_Tar($archive);
353
            $tar = &new Archive_Tar($archive);
375
            $tar->extract(dirname($info->getPackageFile()));
354
            $tar->extract(dirname($info->getPackageFile()));
376
            $info->setPackageFile(dirname($info->getPackageFile()) . DIRECTORY_SEPARATOR .
355
            $info->setPackageFile(dirname($info->getPackageFile()) . DIRECTORY_SEPARATOR .
377
                $info->getPackage() . '-' . $info->getVersion() . DIRECTORY_SEPARATOR .
-
 
378
                basename($info->getPackageFile()));
356
                $info->getPackage() . '-' . $info->getVersion() . DIRECTORY_SEPARATOR .
379
        }
357
                basename($info->getPackageFile()));
380
 
358
        }
381
        PEAR::staticPopErrorHandling();
359
        PEAR::staticPopErrorHandling();
382
        if (PEAR::isError($info)) {
360
        if (PEAR::isError($info)) {
383
            return $this->raiseError($info);
361
            return $this->raiseError($info);
384
        }
362
        }
385
 
363
        $valid = false;
386
        $valid = false;
364
        if ($info->getPackagexmlVersion() == '2.0') {
387
        if ($info->getPackagexmlVersion() == '2.0') {
365
            if ($valid = $info->validate(PEAR_VALIDATE_NORMAL)) {
-
 
-
 
388
            if ($valid = $info->validate(PEAR_VALIDATE_NORMAL)) {
366
                $info->flattenFileList();
389
                $info->flattenFileList();
367
                $valid = $info->validate(PEAR_VALIDATE_PACKAGING);
390
                $valid = $info->validate(PEAR_VALIDATE_PACKAGING);
368
            }
391
            }
369
        } else {
392
        } else {
370
            $valid = $info->validate(PEAR_VALIDATE_PACKAGING);
393
            $valid = $info->validate(PEAR_VALIDATE_PACKAGING);
371
        }
394
        }
372
        $err = array();
395
 
373
        $warn = array();
396
        $err = $warn = array();
374
        if (!$valid) {
397
        if ($errors = $info->getValidationWarnings()) {
375
            foreach ($info->getValidationWarnings() as $error) {
398
            foreach ($errors as $error) {
-
 
399
                if ($error['level'] == 'warning') {
376
                if ($error['level'] == 'warning') {
400
                    $warn[] = $error['message'];
377
                    $warn[] = $error['message'];
401
                } else {
378
                } else {
402
                    $err[] = $error['message'];
379
                    $err[] = $error['message'];
403
                }
Line -... Line 404...
-
 
404
            }
-
 
405
        }
-
 
406
 
-
 
407
        $this->_displayValidationResults($err, $warn);
-
 
408
        $this->ui->outputData($this->output, $command);
-
 
409
        return true;
-
 
410
    }
-
 
411
 
-
 
412
    function doSvnTag($command, $options, $params)
-
 
413
    {
-
 
414
        $this->output = '';
-
 
415
        $_cmd = $command;
-
 
416
        if (count($params) < 1) {
-
 
417
            $help = $this->getHelp($command);
-
 
418
            return $this->raiseError("$command: missing parameter: $help[0]");
-
 
419
        }
-
 
420
 
-
 
421
        $packageFile = realpath($params[0]);
-
 
422
        $dir = dirname($packageFile);
-
 
423
        $dir = substr($dir, strrpos($dir, DIRECTORY_SEPARATOR) + 1);
-
 
424
        $obj  = &$this->getPackageFile($this->config, $this->_debug);
-
 
425
        $info = $obj->fromAnyFile($packageFile, PEAR_VALIDATE_NORMAL);
-
 
426
        if (PEAR::isError($info)) {
-
 
427
            return $this->raiseError($info);
-
 
428
        }
-
 
429
 
-
 
430
        $err = $warn = array();
-
 
431
        if (!$info->validate()) {
-
 
432
            foreach ($info->getValidationWarnings() as $error) {
-
 
433
                if ($error['level'] == 'warning') {
-
 
434
                    $warn[] = $error['message'];
-
 
435
                } else {
-
 
436
                    $err[] = $error['message'];
-
 
437
                }
-
 
438
            }
-
 
439
        }
-
 
440
 
-
 
441
        if (!$this->_displayValidationResults($err, $warn, true)) {
-
 
442
            $this->ui->outputData($this->output, $command);
-
 
443
            return $this->raiseError('SVN tag failed');
-
 
444
        }
-
 
445
 
-
 
446
        $version    = $info->getVersion();
-
 
447
        $package    = $info->getName();
-
 
448
        $svntag     = "$package-$version";
-
 
449
 
-
 
450
        if (isset($options['delete'])) {
-
 
451
            return $this->_svnRemoveTag($version, $package, $svntag, $packageFile, $options);
-
 
452
        }
-
 
453
 
-
 
454
        $path = $this->_svnFindPath($packageFile);
-
 
455
 
-
 
456
        // Check if there are any modified files
-
 
457
        $fp = popen('svn st --xml ' . dirname($packageFile), "r");
-
 
458
        $out = '';
-
 
459
        while ($line = fgets($fp, 1024)) {
-
 
460
            $out .= rtrim($line)."\n";
-
 
461
        }
-
 
462
        pclose($fp);
-
 
463
 
-
 
464
        if (!isset($options['quiet']) && strpos($out, 'item="modified"')) {
-
 
465
            $params = array(array(
-
 
466
                'name' => 'modified',
-
 
467
                'type' => 'yesno',
-
 
468
                'default' => 'no',
-
 
469
                'prompt' => 'You have files in your SVN checkout (' . $path['from']  . ') that have been modified but not committed, do you still want to tag ' . $version . '?',
-
 
470
            ));
-
 
471
            $answers = $this->ui->confirmDialog($params);
380
                }
472
 
-
 
473
            if (!in_array($answers['modified'], array('y', 'yes', 'on', '1'))) {
-
 
474
                return true;
-
 
475
            }
-
 
476
        }
-
 
477
 
-
 
478
        if (isset($options['slide'])) {
381
            }
479
            $this->_svnRemoveTag($version, $package, $svntag, $packageFile, $options);
-
 
480
        }
-
 
481
 
-
 
482
        // Check if tag already exists
-
 
483
        $releaseTag = $path['local']['base'] . 'tags' . DIRECTORY_SEPARATOR . $svntag;
-
 
484
        $existsCommand = 'svn ls ' . $path['base'] . 'tags/';
-
 
485
 
-
 
486
        $fp = popen($existsCommand, "r");
-
 
487
        $out = '';
-
 
488
        while ($line = fgets($fp, 1024)) {
-
 
489
            $out .= rtrim($line)."\n";
-
 
490
        }
-
 
491
        pclose($fp);
-
 
492
 
-
 
493
        if (in_array($svntag . DIRECTORY_SEPARATOR, explode("\n", $out))) {
-
 
494
            $this->ui->outputData($this->output, $command);
-
 
495
            return $this->raiseError('SVN tag ' . $svntag . ' for ' . $package . ' already exists.');
-
 
496
        } elseif (file_exists($path['local']['base'] . 'tags') === false) {
-
 
497
            return $this->raiseError('Can not locate the tags directory at ' . $path['local']['base'] . 'tags');
-
 
498
        } elseif (is_writeable($path['local']['base'] . 'tags') === false) {
-
 
499
            return $this->raiseError('Can not write to the tag directory at ' . $path['local']['base'] . 'tags');
-
 
500
        } else {
-
 
501
            $makeCommand = 'svn mkdir ' . $releaseTag;
-
 
502
            $this->output .= "+ $makeCommand\n";
-
 
503
            if (empty($options['dry-run'])) {
-
 
504
                // We need to create the tag dir.
-
 
505
                $fp = popen($makeCommand, "r");
-
 
506
                $out = '';
-
 
507
                while ($line = fgets($fp, 1024)) {
-
 
508
                    $out .= rtrim($line)."\n";
-
 
509
                }
-
 
510
                pclose($fp);
-
 
511
                $this->output .= "$out\n";
-
 
512
            }
-
 
513
        }
-
 
514
 
-
 
515
        $command = 'svn';
-
 
516
        if (isset($options['quiet'])) {
-
 
517
            $command .= ' -q';
-
 
518
        }
-
 
519
 
-
 
520
        $command .= ' copy --parents ';
-
 
521
 
-
 
522
        $dir   = dirname($packageFile);
-
 
523
        $dir   = substr($dir, strrpos($dir, DIRECTORY_SEPARATOR) + 1);
-
 
524
        $files = array_keys($info->getFilelist());
-
 
525
        if (!in_array(basename($packageFile), $files)) {
-
 
526
            $files[] = basename($packageFile);
-
 
527
        }
-
 
528
 
-
 
529
        array_shift($params);
-
 
530
        if (count($params)) {
-
 
531
            // add in additional files to be tagged (package files and such)
-
 
532
            $files = array_merge($files, $params);
-
 
533
        }
-
 
534
 
-
 
535
        $commands = array();
-
 
536
        foreach ($files as $file) {
-
 
537
            if (!file_exists($file)) {
-
 
538
                $file = $dir . DIRECTORY_SEPARATOR . $file;
-
 
539
            }
-
 
540
            $commands[] = $command . ' ' . escapeshellarg($file) . ' ' .
-
 
541
                          escapeshellarg($releaseTag . DIRECTORY_SEPARATOR . $file);
-
 
542
        }
-
 
543
 
-
 
544
        $this->output .= implode("\n", $commands) . "\n";
-
 
545
        if (empty($options['dry-run'])) {
-
 
546
            foreach ($commands as $command) {
-
 
547
                $fp = popen($command, "r");
-
 
548
                while ($line = fgets($fp, 1024)) {
-
 
549
                    $this->output .= rtrim($line)."\n";
-
 
550
                }
-
 
551
                pclose($fp);
-
 
552
            }
-
 
553
        }
-
 
554
 
-
 
555
        $command = 'svn ci -m "Tagging the ' . $version  . ' release" ' . $releaseTag . "\n";
-
 
556
        $this->output .= "+ $command\n";
-
 
557
        if (empty($options['dry-run'])) {
-
 
558
            $fp = popen($command, "r");
-
 
559
            while ($line = fgets($fp, 1024)) {
-
 
560
                $this->output .= rtrim($line)."\n";
-
 
561
            }
-
 
562
            pclose($fp);
-
 
563
        }
-
 
564
 
-
 
565
        $this->ui->outputData($this->output, $_cmd);
-
 
566
        return true;
-
 
567
    }
-
 
568
 
-
 
569
    function _svnFindPath($file)
-
 
570
    {
-
 
571
        $xml = '';
-
 
572
        $command = "svn info --xml $file";
-
 
573
        $fp = popen($command, "r");
-
 
574
        while ($line = fgets($fp, 1024)) {
-
 
575
            $xml .= rtrim($line)."\n";
-
 
576
        }
-
 
577
        pclose($fp);
-
 
578
        $url_tag = strpos($xml, '<url>');
-
 
579
        $url = substr($xml, $url_tag + 5, strpos($xml, '</url>', $url_tag + 5) - ($url_tag + 5));
-
 
580
 
-
 
581
        $path = array();
-
 
582
        $path['from'] = substr($url, 0, strrpos($url, '/'));
-
 
583
        $path['base'] = substr($path['from'], 0, strrpos($path['from'], '/') + 1);
-
 
584
 
-
 
585
        // Figure out the local paths - see http://pear.php.net/bugs/17463
-
 
586
        $pos = strpos($file, DIRECTORY_SEPARATOR . 'trunk' . DIRECTORY_SEPARATOR);
-
 
587
        if ($pos === false) {
-
 
588
            $pos = strpos($file, DIRECTORY_SEPARATOR . 'branches' . DIRECTORY_SEPARATOR);
-
 
589
        }
-
 
590
        $path['local']['base'] = substr($file, 0, $pos + 1);
-
 
591
 
-
 
592
        return $path;
-
 
593
    }
-
 
594
 
-
 
595
    function _svnRemoveTag($version, $package, $tag, $packageFile, $options)
-
 
596
    {
-
 
597
        $command = 'svn';
-
 
598
 
-
 
599
        if (isset($options['quiet'])) {
-
 
600
            $command .= ' -q';
-
 
601
        }
-
 
602
 
-
 
603
        $command .= ' remove';
-
 
604
        $command .= ' -m "Removing tag for the ' . $version  . ' release."';
-
 
605
 
-
 
606
        $path = $this->_svnFindPath($packageFile);
-
 
607
        $command .= ' ' . $path['base'] . 'tags/' . $tag;
-
 
608
 
-
 
609
 
-
 
610
        if ($this->config->get('verbose') > 1) {
-
 
611
            $this->output .= "+ $command\n";
-
 
612
        }
-
 
613
 
-
 
614
        $this->output .= "+ $command\n";
-
 
615
        if (empty($options['dry-run'])) {
-
 
616
            $fp = popen($command, "r");
-
 
617
            while ($line = fgets($fp, 1024)) {
Line 382... Line 618...
382
        }
618
                $this->output .= rtrim($line)."\n";
383
        $this->_displayValidationResults($err, $warn);
619
            }
384
        $this->ui->outputData($this->output, $command);
620
            pclose($fp);
385
        return true;
621
        }
386
    }
622
 
387
 
623
        $this->ui->outputData($this->output, $command);
388
    // }}}
624
        return true;
389
    // {{{ doCvsTag()
625
    }
-
 
626
 
-
 
627
    function doCvsTag($command, $options, $params)
390
 
628
    {
391
    function doCvsTag($command, $options, $params)
629
        $this->output = '';
392
    {
630
        $_cmd = $command;
393
        $this->output = '';
631
        if (count($params) < 1) {
394
        $_cmd = $command;
632
            $help = $this->getHelp($command);
-
 
633
            return $this->raiseError("$command: missing parameter: $help[0]");
395
        if (sizeof($params) < 1) {
634
        }
396
            $help = $this->getHelp($command);
635
 
397
            return $this->raiseError("$command: missing parameter: $help[0]");
636
        $packageFile = realpath($params[0]);
398
        }
637
        $obj  = &$this->getPackageFile($this->config, $this->_debug);
399
        $obj = &$this->getPackageFile($this->config, $this->_debug);
638
        $info = $obj->fromAnyFile($packageFile, PEAR_VALIDATE_NORMAL);
400
        $info = $obj->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
639
        if (PEAR::isError($info)) {
401
        if (PEAR::isError($info)) {
640
            return $this->raiseError($info);
402
            return $this->raiseError($info);
641
        }
403
        }
642
 
404
        $err = $warn = array();
643
        $err = $warn = array();
-
 
644
        if (!$info->validate()) {
405
        if (!$info->validate()) {
645
            foreach ($info->getValidationWarnings() as $error) {
406
            foreach ($info->getValidationWarnings() as $error) {
646
                if ($error['level'] == 'warning') {
407
                if ($error['level'] == 'warning') {
647
                    $warn[] = $error['message'];
408
                    $warn[] = $error['message'];
648
                } else {
-
 
649
                    $err[] = $error['message'];
409
                } else {
650
                }
410
                    $err[] = $error['message'];
651
            }
411
                }
652
        }
412
            }
653
 
413
        }
654
        if (!$this->_displayValidationResults($err, $warn, true)) {
414
        if (!$this->_displayValidationResults($err, $warn, true)) {
655
            $this->ui->outputData($this->output, $command);
415
            $this->ui->outputData($this->output, $command);
656
            return $this->raiseError('CVS tag failed');
416
            return $this->raiseError('CVS tag failed');
657
        }
-
 
658
 
417
        }
659
        $version    = $info->getVersion();
418
        $version = $info->getVersion();
660
        $cvsversion = preg_replace('/[^a-z0-9]/i', '_', $version);
419
        $cvsversion = preg_replace('/[^a-z0-9]/i', '_', $version);
661
        $cvstag     = "RELEASE_$cvsversion";
-
 
662
        $files      = array_keys($info->getFilelist());
420
        $cvstag = "RELEASE_$cvsversion";
663
        $command = 'cvs';
421
        $files = array_keys($info->getFilelist());
664
        if (isset($options['quiet'])) {
422
        $command = "cvs";
665
            $command .= ' -q';
423
        if (isset($options['quiet'])) {
666
        }
-
 
667
 
424
            $command .= ' -q';
668
        if (isset($options['reallyquiet'])) {
425
        }
669
            $command .= ' -Q';
426
        if (isset($options['reallyquiet'])) {
670
        }
-
 
671
 
427
            $command .= ' -Q';
672
        $command .= ' tag';
428
        }
673
        if (isset($options['slide'])) {
429
        $command .= ' tag';
674
            $command .= ' -F';
430
        if (isset($options['slide'])) {
675
        }
431
            $command .= ' -F';
676
 
432
        }
677
        if (isset($options['delete'])) {
-
 
678
            $command .= ' -d';
-
 
679
        }
-
 
680
 
433
        if (isset($options['delete'])) {
681
        $command .= ' ' . $cvstag . ' ' . escapeshellarg($params[0]);
-
 
682
        array_shift($params);
-
 
683
        if (count($params)) {
-
 
684
            // add in additional files to be tagged
434
            $command .= ' -d';
685
            $files = array_merge($files, $params);
435
        }
686
        }
-
 
687
 
436
        $command .= ' ' . $cvstag . ' ' . escapeshellarg($params[0]);
688
        $dir = dirname($packageFile);
437
        array_shift($params);
689
        $dir = substr($dir, strrpos($dir, '/') + 1);
438
        if (count($params)) {
690
        foreach ($files as $file) {
-
 
691
            if (!file_exists($file)) {
439
            // add in additional files to be tagged
692
                $file = $dir . DIRECTORY_SEPARATOR . $file;
440
            $files = array_merge($files, $params);
693
            }
441
        }
694
            $command .= ' ' . escapeshellarg($file);
442
        foreach ($files as $file) {
695
        }
443
            $command .= ' ' . escapeshellarg($file);
696
 
444
        }
697
        if ($this->config->get('verbose') > 1) {
445
        if ($this->config->get('verbose') > 1) {
698
            $this->output .= "+ $command\n";
446
            $this->output .= "+ $command\n";
699
        }
-
 
700
 
447
        }
701
        $this->output .= "+ $command\n";
448
        $this->output .= "+ $command\n";
702
        if (empty($options['dry-run'])) {
449
        if (empty($options['dry-run'])) {
703
            $fp = popen($command, "r");
Line 450... Line -...
450
            $fp = popen($command, "r");
-
 
451
            while ($line = fgets($fp, 1024)) {
-
 
452
                $this->output .= rtrim($line)."\n";
-
 
453
            }
704
            while ($line = fgets($fp, 1024)) {
454
            pclose($fp);
705
                $this->output .= rtrim($line)."\n";
455
        }
706
            }
456
        $this->ui->outputData($this->output, $_cmd);
707
            pclose($fp);
457
        return true;
708
        }
458
    }
709
 
459
 
710
        $this->ui->outputData($this->output, $_cmd);
-
 
711
        return true;
-
 
712
    }
460
    // }}}
713
 
461
    // {{{ doCvsDiff()
714
    function doCvsDiff($command, $options, $params)
462
 
715
    {
463
    function doCvsDiff($command, $options, $params)
716
        $this->output = '';
464
    {
717
        if (sizeof($params) < 1) {
-
 
718
            $help = $this->getHelp($command);
465
        $this->output = '';
719
            return $this->raiseError("$command: missing parameter: $help[0]");
466
        if (sizeof($params) < 1) {
720
        }
467
            $help = $this->getHelp($command);
721
 
468
            return $this->raiseError("$command: missing parameter: $help[0]");
722
        $file = realpath($params[0]);
469
        }
723
        $obj  = &$this->getPackageFile($this->config, $this->_debug);
470
        $obj = &$this->getPackageFile($this->config, $this->_debug);
724
        $info = $obj->fromAnyFile($file, PEAR_VALIDATE_NORMAL);
471
        $info = $obj->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
725
        if (PEAR::isError($info)) {
472
        if (PEAR::isError($info)) {
726
            return $this->raiseError($info);
473
            return $this->raiseError($info);
727
        }
474
        }
728
 
-
 
729
        $err = $warn = array();
475
        $err = $warn = array();
730
        if (!$info->validate()) {
476
        if (!$info->validate()) {
731
            foreach ($info->getValidationWarnings() as $error) {
477
            foreach ($info->getValidationWarnings() as $error) {
732
                if ($error['level'] == 'warning') {
478
                if ($error['level'] == 'warning') {
733
                    $warn[] = $error['message'];
-
 
734
                } else {
479
                    $warn[] = $error['message'];
735
                    $err[] = $error['message'];
480
                } else {
736
                }
481
                    $err[] = $error['message'];
737
            }
482
                }
738
        }
483
            }
739
 
484
        }
740
        if (!$this->_displayValidationResults($err, $warn, true)) {
485
        if (!$this->_displayValidationResults($err, $warn, true)) {
741
            $this->ui->outputData($this->output, $command);
-
 
742
            return $this->raiseError('CVS diff failed');
486
            $this->ui->outputData($this->output, $command);
743
        }
487
            return $this->raiseError('CVS diff failed');
744
 
488
        }
745
        $info1 = $info->getFilelist();
489
        $info1 = $info->getFilelist();
746
        $files = $info1;
-
 
747
        $cmd = "cvs";
490
        $files = $info1;
748
        if (isset($options['quiet'])) {
491
        $cmd = "cvs";
749
            $cmd .= ' -q';
492
        if (isset($options['quiet'])) {
750
            unset($options['quiet']);
493
            $cmd .= ' -q';
751
        }
494
            unset($options['quiet']);
752
 
495
        }
753
        if (isset($options['reallyquiet'])) {
-
 
754
            $cmd .= ' -Q';
496
        if (isset($options['reallyquiet'])) {
755
            unset($options['reallyquiet']);
497
            $cmd .= ' -Q';
756
        }
498
            unset($options['reallyquiet']);
757
 
499
        }
758
        if (isset($options['release'])) {
500
        if (isset($options['release'])) {
759
            $cvsversion = preg_replace('/[^a-z0-9]/i', '_', $options['release']);
-
 
760
            $cvstag = "RELEASE_$cvsversion";
501
            $cvsversion = preg_replace('/[^a-z0-9]/i', '_', $options['release']);
761
            $options['revision'] = $cvstag;
502
            $cvstag = "RELEASE_$cvsversion";
762
            unset($options['release']);
503
            $options['revision'] = $cvstag;
763
        }
504
            unset($options['release']);
764
 
505
        }
765
        $execute = true;
Line 519... Line 779...
519
            $cmd .= $short ? " -$short" : " --$option";
779
            $cmd .= $short ? " -$short" : " --$option";
520
            if ($arg && $optarg) {
780
            if ($arg && $optarg) {
521
                $cmd .= ($short ? '' : '=') . escapeshellarg($optarg);
781
                $cmd .= ($short ? '' : '=') . escapeshellarg($optarg);
522
            }
782
            }
523
        }
783
        }
-
 
784
 
524
        foreach ($files as $file) {
785
        foreach ($files as $file) {
525
            $cmd .= ' ' . escapeshellarg($file['name']);
786
            $cmd .= ' ' . escapeshellarg($file['name']);
526
        }
787
        }
-
 
788
 
527
        if ($this->config->get('verbose') > 1) {
789
        if ($this->config->get('verbose') > 1) {
528
            $this->output .= "+ $cmd\n";
790
            $this->output .= "+ $cmd\n";
529
        }
791
        }
-
 
792
 
530
        if ($execute) {
793
        if ($execute) {
531
            $fp = popen($cmd, "r");
794
            $fp = popen($cmd, "r");
532
            while ($line = fgets($fp, 1024)) {
795
            while ($line = fgets($fp, 1024)) {
533
                $this->output .= rtrim($line)."\n";
796
                $this->output .= rtrim($line)."\n";
534
            }
797
            }
535
            pclose($fp);
798
            pclose($fp);
536
        }
799
        }
-
 
800
 
537
        $this->ui->outputData($this->output, $command);
801
        $this->ui->outputData($this->output, $command);
538
        return true;
802
        return true;
539
    }
803
    }
Line 540... Line -...
540
 
-
 
541
    // }}}
-
 
542
    // {{{ doPackageDependencies()
-
 
543
 
804
 
544
    function doPackageDependencies($command, $options, $params)
805
    function doPackageDependencies($command, $options, $params)
545
    {
806
    {
546
        // $params[0] -> the PEAR package to list its information
807
        // $params[0] -> the PEAR package to list its information
547
        if (sizeof($params) != 1) {
808
        if (count($params) !== 1) {
548
            return $this->raiseError("bad parameter(s), try \"help $command\"");
809
            return $this->raiseError("bad parameter(s), try \"help $command\"");
-
 
810
        }
549
        }
811
 
-
 
812
        $obj = &$this->getPackageFile($this->config, $this->_debug);
550
        $obj = &$this->getPackageFile($this->config, $this->_debug);
813
        if (is_file($params[0]) || strpos($params[0], '.xml') > 0) {
-
 
814
           $info = $obj->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
-
 
815
        } else {
-
 
816
            $reg  = $this->config->getRegistry();
-
 
817
            $info = $obj->fromArray($reg->packageInfo($params[0]));
-
 
818
        }
551
        $info = $obj->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
819
 
552
        if (PEAR::isError($info)) {
820
        if (PEAR::isError($info)) {
553
            return $this->raiseError($info);
821
            return $this->raiseError($info);
-
 
822
        }
554
        }
823
 
555
        $deps = $info->getDeps();
824
        $deps = $info->getDeps();
556
        if (is_array($deps)) {
825
        if (is_array($deps)) {
557
            if ($info->getPackagexmlVersion() == '1.0') {
826
            if ($info->getPackagexmlVersion() == '1.0') {
558
                $data = array(
827
                $data = array(
Line 569... Line 838...
569
                            $req = 'Yes';
838
                            $req = 'Yes';
570
                        }
839
                        }
571
                    } else {
840
                    } else {
572
                        $req = 'Yes';
841
                        $req = 'Yes';
573
                    }
842
                    }
-
 
843
 
574
                    if (isset($this->_deps_rel_trans[$d['rel']])) {
844
                    if (isset($this->_deps_rel_trans[$d['rel']])) {
575
                        $rel = $this->_deps_rel_trans[$d['rel']];
845
                        $rel = $this->_deps_rel_trans[$d['rel']];
576
                    } else {
846
                    } else {
577
                        $rel = $d['rel'];
847
                        $rel = $d['rel'];
578
                    }
848
                    }
Line 608... Line 878...
608
                        'border' => true,
878
                        'border' => true,
609
                        'headline' => array("Required?", "Type", "Name", 'Versioning', 'Group'),
879
                        'headline' => array("Required?", "Type", "Name", 'Versioning', 'Group'),
610
                        );
880
                        );
611
                    foreach ($deps as $type => $subd) {
881
                    foreach ($deps as $type => $subd) {
612
                        $req = ($type == 'required') ? 'Yes' : 'No';
882
                        $req = ($type == 'required') ? 'Yes' : 'No';
613
                        if ($type == 'group') {
883
                        if ($type == 'group' && isset($subd['attribs']['name'])) {
614
                            $group = $subd['attribs']['name'];
884
                            $group = $subd['attribs']['name'];
615
                        } else {
885
                        } else {
616
                            $group = '';
886
                            $group = '';
617
                        }
887
                        }
-
 
888
 
618
                        if (!isset($subd[0])) {
889
                        if (!isset($subd[0])) {
619
                            $subd = array($subd);
890
                            $subd = array($subd);
620
                        }
891
                        }
-
 
892
 
621
                        foreach ($subd as $groupa) {
893
                        foreach ($subd as $groupa) {
622
                            foreach ($groupa as $deptype => $depinfo) {
894
                            foreach ($groupa as $deptype => $depinfo) {
623
                                if ($deptype == 'attribs') {
895
                                if ($deptype == 'attribs') {
624
                                    continue;
896
                                    continue;
625
                                }
897
                                }
-
 
898
 
626
                                if ($deptype == 'pearinstaller') {
899
                                if ($deptype == 'pearinstaller') {
627
                                    $deptype = 'pear Installer';
900
                                    $deptype = 'pear Installer';
628
                                }
901
                                }
-
 
902
 
629
                                if (!isset($depinfo[0])) {
903
                                if (!isset($depinfo[0])) {
630
                                    $depinfo = array($depinfo);
904
                                    $depinfo = array($depinfo);
631
                                }
905
                                }
-
 
906
 
632
                                foreach ($depinfo as $inf) {
907
                                foreach ($depinfo as $inf) {
633
                                    $name = '';
908
                                    $name = '';
634
                                    if (isset($inf['channel'])) {
909
                                    if (isset($inf['channel'])) {
635
                                        $alias = $reg->channelAlias($inf['channel']);
910
                                        $alias = $reg->channelAlias($inf['channel']);
636
                                        if (!$alias) {
911
                                        if (!$alias) {
637
                                            $alias = '(channel?) ' .$inf['channel'];
912
                                            $alias = '(channel?) ' .$inf['channel'];
638
                                        }
913
                                        }
639
                                        $name = $alias . '/';
914
                                        $name = $alias . '/';
-
 
915
 
640
                                    }
916
                                    }
641
                                    if (isset($inf['name'])) {
917
                                    if (isset($inf['name'])) {
642
                                        $name .= $inf['name'];
918
                                        $name .= $inf['name'];
643
                                    } elseif (isset($inf['pattern'])) {
919
                                    } elseif (isset($inf['pattern'])) {
644
                                        $name .= $inf['pattern'];
920
                                        $name .= $inf['pattern'];
645
                                    } else {
921
                                    } else {
646
                                        $name .= '';
922
                                        $name .= '';
647
                                    }
923
                                    }
-
 
924
 
648
                                    if (isset($inf['uri'])) {
925
                                    if (isset($inf['uri'])) {
649
                                        $name .= ' [' . $inf['uri'] .  ']';
926
                                        $name .= ' [' . $inf['uri'] .  ']';
650
                                    }
927
                                    }
-
 
928
 
651
                                    if (isset($inf['conflicts'])) {
929
                                    if (isset($inf['conflicts'])) {
652
                                        $ver = 'conflicts';
930
                                        $ver = 'conflicts';
653
                                    } else {
931
                                    } else {
654
                                        $ver = $d->_getExtraString($inf);
932
                                        $ver = $d->_getExtraString($inf);
655
                                    }
933
                                    }
-
 
934
 
656
                                    $data['data'][] = array($req, ucfirst($deptype), $name,
935
                                    $data['data'][] = array($req, ucfirst($deptype), $name,
657
                                        $ver, $group);
936
                                        $ver, $group);
658
                                }
937
                                }
659
                            }
938
                            }
660
                        }
939
                        }
Line 668... Line 947...
668
 
947
 
669
        // Fallback
948
        // Fallback
670
        $this->ui->outputData("This package does not have any dependencies.", $command);
949
        $this->ui->outputData("This package does not have any dependencies.", $command);
Line 671... Line -...
671
    }
-
 
672
 
-
 
673
    // }}}
-
 
674
    // {{{ doSign()
950
    }
675
 
951
 
676
    function doSign($command, $options, $params)
-
 
677
    {
-
 
678
        require_once 'System.php';
952
    function doSign($command, $options, $params)
679
        require_once 'Archive/Tar.php';
953
    {
680
        // should move most of this code into PEAR_Packager
954
        // should move most of this code into PEAR_Packager
681
        // so it'll be easy to implement "pear package --sign"
955
        // so it'll be easy to implement "pear package --sign"
682
        if (sizeof($params) != 1) {
956
        if (count($params) !== 1) {
-
 
957
            return $this->raiseError("bad parameter(s), try \"help $command\"");
-
 
958
        }
-
 
959
 
-
 
960
        require_once 'System.php';
683
            return $this->raiseError("bad parameter(s), try \"help $command\"");
961
        require_once 'Archive/Tar.php';
684
        }
962
 
685
        if (!file_exists($params[0])) {
963
        if (!file_exists($params[0])) {
-
 
964
            return $this->raiseError("file does not exist: $params[0]");
686
            return $this->raiseError("file does not exist: $params[0]");
965
        }
687
        }
966
 
688
        $obj = $this->getPackageFile($this->config, $this->_debug);
967
        $obj = $this->getPackageFile($this->config, $this->_debug);
689
        $info = $obj->fromTgzFile($params[0], PEAR_VALIDATE_NORMAL);
968
        $info = $obj->fromTgzFile($params[0], PEAR_VALIDATE_NORMAL);
690
        if (PEAR::isError($info)) {
969
        if (PEAR::isError($info)) {
-
 
970
            return $this->raiseError($info);
691
            return $this->raiseError($info);
971
        }
-
 
972
 
692
        }
973
        $tar = new Archive_Tar($params[0]);
693
        $tar = new Archive_Tar($params[0]);
974
 
694
        $tmpdir = System::mktemp('-d pearsign');
975
        $tmpdir = $this->config->get('temp_dir');
695
        if (!$tar->extractList('package2.xml package.sig', $tmpdir)) {
976
        $tmpdir = System::mktemp(' -t "' . $tmpdir . '" -d pearsign');
696
            if (!$tar->extractList('package.xml package.sig', $tmpdir)) {
-
 
697
                return $this->raiseError("failed to extract tar file");
977
        if (!$tar->extractList('package2.xml package.xml package.sig', $tmpdir)) {
-
 
978
            return $this->raiseError("failed to extract tar file");
698
            }
979
        }
699
        }
980
 
700
        if (file_exists("$tmpdir/package.sig")) {
981
        if (file_exists("$tmpdir/package.sig")) {
-
 
982
            return $this->raiseError("package already signed");
701
            return $this->raiseError("package already signed");
983
        }
702
        }
984
 
703
        $packagexml = 'package.xml';
985
        $packagexml = 'package.xml';
704
        if (file_exists("$tmpdir/package2.xml")) {
986
        if (file_exists("$tmpdir/package2.xml")) {
-
 
987
            $packagexml = 'package2.xml';
705
            $packagexml = 'package2.xml';
988
        }
706
        }
989
 
707
        if (file_exists("$tmpdir/package.sig")) {
990
        if (file_exists("$tmpdir/package.sig")) {
-
 
991
            unlink("$tmpdir/package.sig");
-
 
992
        }
-
 
993
 
-
 
994
        if (!file_exists("$tmpdir/$packagexml")) {
-
 
995
            return $this->raiseError("Extracted file $tmpdir/$packagexml not found.");
708
            unlink("$tmpdir/package.sig");
996
        }
709
        }
997
 
710
        $input = $this->ui->userDialog($command,
998
        $input = $this->ui->userDialog($command,
-
 
999
                                       array('GnuPG Passphrase'),
-
 
1000
                                       array('password'));
-
 
1001
        if (!isset($input[0])) {
-
 
1002
            //use empty passphrase
-
 
1003
            $input[0] = '';
-
 
1004
        }
711
                                       array('GnuPG Passphrase'),
1005
 
712
                                       array('password'));
1006
        $devnull = (isset($options['verbose'])) ? '' : ' 2>/dev/null';
713
        $gpg = popen("gpg --batch --passphrase-fd 0 --armor --detach-sign --output $tmpdir/package.sig $tmpdir/$packagexml 2>/dev/null", "w");
1007
        $gpg = popen("gpg --batch --passphrase-fd 0 --armor --detach-sign --output $tmpdir/package.sig $tmpdir/$packagexml" . $devnull, "w");
714
        if (!$gpg) {
1008
        if (!$gpg) {
-
 
1009
            return $this->raiseError("gpg command failed");
715
            return $this->raiseError("gpg command failed");
1010
        }
716
        }
1011
 
717
        fwrite($gpg, "$input[0]\n");
1012
        fwrite($gpg, "$input[0]\n");
718
        if (pclose($gpg) || !file_exists("$tmpdir/package.sig")) {
1013
        if (pclose($gpg) || !file_exists("$tmpdir/package.sig")) {
-
 
1014
            return $this->raiseError("gpg sign failed");
719
            return $this->raiseError("gpg sign failed");
1015
        }
-
 
1016
 
-
 
1017
        if (!$tar->addModify("$tmpdir/package.sig", '', $tmpdir)) {
-
 
1018
            return $this->raiseError('failed adding signature to file');
-
 
1019
        }
720
        }
1020
 
721
        $tar->addModify("$tmpdir/package.sig", '', $tmpdir);
1021
        $this->ui->outputData("Package signed.", $command);
Line 722... Line -...
722
        return true;
-
 
723
    }
-
 
724
 
1022
        return true;
725
    // }}}
1023
    }
726
 
1024
 
727
    /**
1025
    /**
728
     * For unit testing purposes
1026
     * For unit testing purposes
729
     */
1027
     */
730
    function &getInstaller(&$ui)
1028
    function &getInstaller(&$ui)
731
    {
1029
    {
732
        if (!class_exists('PEAR_Installer')) {
1030
        if (!class_exists('PEAR_Installer')) {
733
            require_once 'PEAR/Installer.php';
1031
            require_once 'PEAR/Installer.php';
734
        }
1032
        }
735
        $a = &new PEAR_Installer($ui);
1033
        $a = new PEAR_Installer($ui);
736
        return $a;
1034
        return $a;
737
    }
1035
    }
738
    
1036
 
739
    /**
1037
    /**
740
     * For unit testing purposes
1038
     * For unit testing purposes
Line 745... Line 1043...
745
            if ($fp = @fopen('PEAR/Command/Packaging.php', 'r', true)) {
1043
            if ($fp = @fopen('PEAR/Command/Packaging.php', 'r', true)) {
746
                fclose($fp);
1044
                fclose($fp);
747
                include_once 'PEAR/Command/Packaging.php';
1045
                include_once 'PEAR/Command/Packaging.php';
748
            }
1046
            }
749
        }
1047
        }
750
        
1048
 
751
        if (class_exists('PEAR_Command_Packaging')) {
1049
        if (class_exists('PEAR_Command_Packaging')) {
752
            $a = &new PEAR_Command_Packaging($ui, $config);
1050
            $a = new PEAR_Command_Packaging($ui, $config);
753
        } else {
1051
        } else {
754
            $a = null;
1052
            $a = null;
755
        }
1053
        }
-
 
1054
 
756
        return $a;
1055
        return $a;
757
    }
1056
    }
Line 758... Line -...
758
 
-
 
759
    // {{{ doMakeRPM()
-
 
760
 
1057
 
761
    function doMakeRPM($command, $options, $params)
1058
    function doMakeRPM($command, $options, $params)
Line 762... Line 1059...
762
    {
1059
    {
763
 
1060
 
Line 768... Line 1065...
768
        $packaging_cmd = $this->getCommandPackaging($this->ui, $this->config);
1065
        $packaging_cmd = $this->getCommandPackaging($this->ui, $this->config);
769
        if ($packaging_cmd !== null) {
1066
        if ($packaging_cmd !== null) {
770
            $this->ui->outputData('PEAR_Command_Packaging is installed; using '.
1067
            $this->ui->outputData('PEAR_Command_Packaging is installed; using '.
771
                'newer "make-rpm-spec" command instead');
1068
                'newer "make-rpm-spec" command instead');
772
            return $packaging_cmd->run('make-rpm-spec', $options, $params);
1069
            return $packaging_cmd->run('make-rpm-spec', $options, $params);
773
        } else {
-
 
774
            $this->ui->outputData('WARNING: "pear makerpm" is no longer available; an '.
-
 
775
              'improved version is available via "pear make-rpm-spec", which '.
-
 
776
              'is available by installing PEAR_Command_Packaging');
-
 
777
        }
1070
        }
-
 
1071
 
-
 
1072
        $this->ui->outputData('WARNING: "pear makerpm" is no longer available; an '.
-
 
1073
          'improved version is available via "pear make-rpm-spec", which '.
-
 
1074
          'is available by installing PEAR_Command_Packaging');
778
        return true;
1075
        return true;
779
    }
1076
    }
Line 780... Line 1077...
780
 
1077
 
781
    function doConvert($command, $options, $params)
1078
    function doConvert($command, $options, $params)
782
    {
1079
    {
783
        $packagexml = isset($params[0]) ? $params[0] : 'package.xml';
1080
        $packagexml    = isset($params[0]) ? $params[0] : 'package.xml';
784
        $newpackagexml = isset($params[1]) ? $params[1] : dirname($packagexml) .
1081
        $newpackagexml = isset($params[1]) ? $params[1] : dirname($packagexml) .
785
            DIRECTORY_SEPARATOR . 'package2.xml';
1082
            DIRECTORY_SEPARATOR . 'package2.xml';
786
        $pkg = &$this->getPackageFile($this->config, $this->_debug);
1083
        $pkg = &$this->getPackageFile($this->config, $this->_debug);
787
        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
1084
        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
788
        $pf = $pkg->fromPackageFile($packagexml, PEAR_VALIDATE_NORMAL);
1085
        $pf = $pkg->fromPackageFile($packagexml, PEAR_VALIDATE_NORMAL);
789
        PEAR::staticPopErrorHandling();
1086
        PEAR::staticPopErrorHandling();
790
        if (!PEAR::isError($pf)) {
-
 
791
            if (is_a($pf, 'PEAR_PackageFile_v2')) {
-
 
792
                $this->ui->outputData($packagexml . ' is already a package.xml version 2.0');
-
 
793
                return true;
-
 
794
            }
-
 
795
            $gen = &$pf->getDefaultGenerator();
-
 
796
            $newpf = &$gen->toV2();
-
 
797
            $newpf->setPackagefile($newpackagexml);
-
 
798
            $gen = &$newpf->getDefaultGenerator();
-
 
799
            PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
-
 
800
            $state = (isset($options['flat']) ? PEAR_VALIDATE_PACKAGING : PEAR_VALIDATE_NORMAL);
-
 
801
            $saved = $gen->toPackageFile(dirname($newpackagexml), $state,
-
 
802
                basename($newpackagexml));
-
 
803
            PEAR::staticPopErrorHandling();
-
 
804
            if (PEAR::isError($saved)) {
-
 
805
                if (is_array($saved->getUserInfo())) {
-
 
806
                    foreach ($saved->getUserInfo() as $warning) {
-
 
807
                        $this->ui->outputData($warning['message']);
-
 
808
                    }
-
 
809
                }
-
 
810
                $this->ui->outputData($saved->getMessage());
-
 
811
                return true;
-
 
812
            }
-
 
813
            $this->ui->outputData('Wrote new version 2.0 package.xml to "' . $saved . '"');
-
 
814
            return true;
-
 
815
        } else {
1087
        if (PEAR::isError($pf)) {
816
            if (is_array($pf->getUserInfo())) {
1088
            if (is_array($pf->getUserInfo())) {
817
                foreach ($pf->getUserInfo() as $warning) {
1089
                foreach ($pf->getUserInfo() as $warning) {
818
                    $this->ui->outputData($warning['message']);
1090
                    $this->ui->outputData($warning['message']);
819
                }
1091
                }
820
            }
1092
            }
821
            return $this->raiseError($pf);
1093
            return $this->raiseError($pf);
822
        }
-
 
Line -... Line 1094...
-
 
1094
        }
-
 
1095
 
-
 
1096
        if (is_a($pf, 'PEAR_PackageFile_v2')) {
823
    }
1097
            $this->ui->outputData($packagexml . ' is already a package.xml version 2.0');
-
 
1098
            return true;
-
 
1099
        }
-
 
1100
 
-
 
1101
        $gen   = &$pf->getDefaultGenerator();
-
 
1102
        $newpf = &$gen->toV2();
-
 
1103
        $newpf->setPackagefile($newpackagexml);
-
 
1104
        $gen = &$newpf->getDefaultGenerator();
-
 
1105
        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
-
 
1106
        $state = (isset($options['flat']) ? PEAR_VALIDATE_PACKAGING : PEAR_VALIDATE_NORMAL);
-
 
1107
        $saved = $gen->toPackageFile(dirname($newpackagexml), $state, basename($newpackagexml));
-
 
1108
        PEAR::staticPopErrorHandling();
-
 
1109
        if (PEAR::isError($saved)) {
-
 
1110
            if (is_array($saved->getUserInfo())) {
-
 
1111
                foreach ($saved->getUserInfo() as $warning) {
-
 
1112
                    $this->ui->outputData($warning['message']);
824
 
1113
                }
-
 
1114
            }
-
 
1115
 
-
 
1116
            $this->ui->outputData($saved->getMessage());
Line -... Line 1117...
-
 
1117
            return true;
-
 
1118
        }
-
 
1119
 
825
    // }}}
1120
        $this->ui->outputData('Wrote new version 2.0 package.xml to "' . $saved . '"');