Thomas Bruederli
2016-04-17 cde7a9eb74b6fd6315885c30c0763e0ee5332499
commit | author | age
8e7859 1 #!/usr/bin/env php
TB 2 <?php
3 /*
4  +-----------------------------------------------------------------------+
5  | bin/package2composer.sh                                               |
6  |                                                                       |
7  | This file is part of the Roundcube Webmail client                     |
8  | Copyright (C) 2013, The Roundcube Dev Team                            |
9  |                                                                       |
10  | Licensed under the GNU General Public License version 3 or            |
11  | any later version with exceptions for skins & plugins.                |
12  | See the README file for a full license statement.                     |
13  |                                                                       |
14  | PURPOSE:                                                              |
15  |  Convert a plugin's package.xml file into a composer.json description |
16  |                                                                       |
17  +-----------------------------------------------------------------------+
18  | Author: Thomas Bruederli <thomas@roundcube.net>                       |
19  +-----------------------------------------------------------------------+
20 */
21
22 ini_set('error_reporting', E_ALL & ~E_NOTICE);
23
24 list(, $filename, $vendor) = $_SERVER['argv'];
25
26 if (!$filename || !is_readable($filename)) {
27     die("Invalid input file name!\nUsage: " . $_SERVER['argv'][0] . " XMLFILE VENDOR\n");
28 }
29
30 if (!$vendor) {
31     $vendor = 'anonymous';
32 }
33
34 $package = new SimpleXMLElement(file_get_contents($filename));
35
36 $data = array(
37     'name' => $vendor . '/' . strval($package->name),
38     'type' => 'roundcube-plugin',
40b45c 39     'description' => trim(strval($package->description), '- ') ? trim(strval($package->description)) : trim(strval($package->summary)),
8e7859 40     'homepage' => strval($package->uri),
TB 41     'license' => 'GPLv3+',
139031 42     'version' => strval($package->version->release),
8e7859 43     'authors' => array(),
TB 44     'repositories' => array(
45         array('type' => 'composer', 'url' => 'http://plugins.roundcube.net'),
46     ),
47     'require' => array(
48         'php' => '>=5.3.0',
49         'roundcube/plugin-installer' => '>=0.1.3',
50     ),
51 );
52
53 if ($package->license) {
54     $data['license'] = strval($package->license);
55 }
56
57 if ($package->lead) {
012a65 58     foreach ($package->lead as $lead) {
139031 59         if (strval($lead->active) == 'no') {
TB 60             continue;
61         }
012a65 62         $data['authors'][] = array(
TB 63             'name' => strval($lead->name),
64             'email' => strval($lead->email),
65             'role' => 'Lead',
66         );
67     }
8e7859 68 }
TB 69
70 if ($devs = $package->developer) {
012a65 71     foreach ($package->developer as $dev) {
8e7859 72         $data['authors'][] = array(
TB 73             'name' => strval($dev->name),
74             'email' => strval($dev->email),
75             'role' => 'Developer',
76         );
77     }
78 }
79
a149d5 80 if ($package->dependencies->required->extension) {
TB 81     foreach ($package->dependencies->required->extension as $ext) {
82         $data['require']['ext-' . strval($ext->name)] = '*';
83     }
84 }
85
8e7859 86 // remove empty values
TB 87 $data = array_filter($data);
88
89 // use the JSON encoder from the Composer package
90 if (is_file('composer.phar')) {
91     include 'phar://composer.phar/src/Composer/Json/JsonFile.php';
92     echo \Composer\Json\JsonFile::encode($data);
93 }
94 // PHP 5.4's json_encode() does the job, too
95 else if (defined('JSON_PRETTY_PRINT')) {
96     $flags = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT & JSON_UNESCAPED_SLASHES : 0;
97     echo json_encode($data, $flags);
98 }
99 else {
100     fputs(STDERR,
101 "FAILED! composer.phar not found in current directory.
102
103 Please download it from http://getcomposer.org/download/ or with
104   curl -s http://getcomposer.org/installer | php
105 ");
106 }
107
108 echo "\n";
109