| 1 |
lars |
1 |
<?php
|
|
|
2 |
/*
|
|
|
3 |
* $Id: PearPackage2Task.php 210 2007-08-01 22:48:36Z hans $
|
|
|
4 |
*
|
|
|
5 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
6 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
7 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
8 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
9 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
10 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
11 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
12 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
13 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
14 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
15 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
16 |
*
|
|
|
17 |
* This software consists of voluntary contributions made by many individuals
|
|
|
18 |
* and is licensed under the LGPL. For more information please see
|
|
|
19 |
* <http://phing.info>.
|
|
|
20 |
*/
|
|
|
21 |
|
|
|
22 |
require_once 'phing/tasks/ext/PearPackageTask.php';
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
* A task to create a PEAR package.xml version 2.0 file.
|
|
|
26 |
*
|
|
|
27 |
* This class uses the PEAR_PackageFileManager2 class to perform the work.
|
|
|
28 |
*
|
|
|
29 |
* This class is designed to be very flexible -- i.e. account for changes to the package.xml w/o
|
|
|
30 |
* requiring changes to this class. We've accomplished this by having generic <option> and <mapping>
|
|
|
31 |
* nested elements. All options are set using PEAR_PackageFileManager2::setOptions().
|
|
|
32 |
*
|
|
|
33 |
* The <option> tag is used to set a simple option value.
|
|
|
34 |
* <code>
|
|
|
35 |
* <option name="option_name" value="option_value"/>
|
|
|
36 |
* or <option name="option_name">option_value</option>
|
|
|
37 |
* </code>
|
|
|
38 |
*
|
|
|
39 |
* The <mapping> tag represents a complex data type. You can use nested <element> (and nested <element> with
|
|
|
40 |
* <element> tags) to represent the full complexity of the structure. Bear in mind that what you are creating
|
|
|
41 |
* will be mapped to an associative array that will be passed in via PEAR_PackageFileManager2::setOptions().
|
|
|
42 |
* <code>
|
|
|
43 |
* <mapping name="option_name">
|
|
|
44 |
* <element key="key_name" value="key_val"/>
|
|
|
45 |
* <element key="key_name" value="key_val"/>
|
|
|
46 |
* </mapping>
|
|
|
47 |
* </code>
|
|
|
48 |
*
|
|
|
49 |
* Here's an over-simple example of how this could be used:
|
|
|
50 |
* <code>
|
|
|
51 |
* <pearpkg2 name="phing" dir="${build.src.dir}">
|
|
|
52 |
* <fileset dir="src">
|
|
|
53 |
* <include name="**"/>
|
|
|
54 |
* </fileset>
|
|
|
55 |
* <option name="outputdirectory" value="./build"/>
|
|
|
56 |
* <option name="packagefile" value="package2.xml"/>
|
|
|
57 |
* <option name="packagedirectory" value="./${build.dist.dir}"/>
|
|
|
58 |
* <option name="baseinstalldir" value="${pkg.prefix}"/>
|
|
|
59 |
* <option name="channel" value="my.pear-channel.com"/>
|
|
|
60 |
* <option name="summary" value="${pkg.summary}"/>
|
|
|
61 |
* <option name="description" value="${pkg.description}"/>
|
|
|
62 |
* <option name="apiversion" value="${pkg.version}"/>
|
|
|
63 |
* <option name="apistability" value="beta"/>
|
|
|
64 |
* <option name="releaseversion" value="${pkg.version}"/>
|
|
|
65 |
* <option name="releasestability" value="beta"/>
|
|
|
66 |
* <option name="license" value="none"/>
|
|
|
67 |
* <option name="phpdep" value="5.0.0"/>
|
|
|
68 |
* <option name="pearinstallerdep" value="1.4.6"/>
|
|
|
69 |
* <option name="packagetype" value="php"/>
|
|
|
70 |
* <option name="notes" value="${pkg.relnotes}"/>
|
|
|
71 |
* <mapping name="maintainers">
|
|
|
72 |
* <element>
|
|
|
73 |
* <element key="handle" value="hlellelid"/>
|
|
|
74 |
* <element key="name" value="Hans"/>
|
|
|
75 |
* <element key="email" value="hans@xmpl.org"/>
|
|
|
76 |
* <element key="role" value="lead"/>
|
|
|
77 |
* </element>
|
|
|
78 |
* </mapping>
|
|
|
79 |
* </pearpkg2>
|
|
|
80 |
* </code>
|
|
|
81 |
*
|
|
|
82 |
* Look at the build.xml in the Phing base directory (assuming you have the full distro / CVS version of Phing) to
|
|
|
83 |
* see a more complete example of how to call this script.
|
|
|
84 |
*
|
|
|
85 |
* @author Stuart Binge <stuart.binge@complinet.com>
|
|
|
86 |
* @author Hans Lellelid <hans@xmpl.org>
|
|
|
87 |
* @package phing.tasks.ext
|
|
|
88 |
* @version $Revision: 1.9 $
|
|
|
89 |
*/
|
|
|
90 |
class PearPackage2Task extends PearPackageTask {
|
|
|
91 |
|
|
|
92 |
public function init() {
|
|
|
93 |
include_once 'PEAR/PackageFileManager2.php';
|
|
|
94 |
if (!class_exists('PEAR_PackageFileManager2')) {
|
|
|
95 |
throw new BuildException("You must have installed PEAR_PackageFileManager in order to create a PEAR package.xml version 2.0 file.");
|
|
|
96 |
}
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
protected function setVersion2Options()
|
|
|
100 |
{
|
|
|
101 |
$this->pkg->setPackage($this->package);
|
|
|
102 |
$this->pkg->setDate(strftime('%Y-%m-%d'));
|
|
|
103 |
$this->pkg->setTime(strftime('%H:%M:%S'));
|
|
|
104 |
|
|
|
105 |
$newopts = array();
|
|
|
106 |
foreach ($this->options as $opt) {
|
|
|
107 |
switch ($opt->getName()) {
|
|
|
108 |
case 'summary':
|
|
|
109 |
$this->pkg->setSummary($opt->getValue());
|
|
|
110 |
break;
|
|
|
111 |
|
|
|
112 |
case 'description':
|
|
|
113 |
$this->pkg->setDescription($opt->getValue());
|
|
|
114 |
break;
|
|
|
115 |
|
|
|
116 |
case 'uri':
|
|
|
117 |
$this->pkg->setUri($opt->getValue());
|
|
|
118 |
break;
|
|
|
119 |
|
|
|
120 |
case 'license':
|
|
|
121 |
$this->pkg->setLicense($opt->getValue());
|
|
|
122 |
break;
|
|
|
123 |
|
|
|
124 |
case 'channel':
|
|
|
125 |
$this->pkg->setChannel($opt->getValue());
|
|
|
126 |
break;
|
|
|
127 |
|
|
|
128 |
case 'apiversion':
|
|
|
129 |
$this->pkg->setAPIVersion($opt->getValue());
|
|
|
130 |
break;
|
|
|
131 |
|
|
|
132 |
case 'releaseversion':
|
|
|
133 |
$this->pkg->setReleaseVersion($opt->getValue());
|
|
|
134 |
break;
|
|
|
135 |
|
|
|
136 |
case 'releasestability':
|
|
|
137 |
$this->pkg->setReleaseStability($opt->getValue());
|
|
|
138 |
break;
|
|
|
139 |
|
|
|
140 |
case 'apistability':
|
|
|
141 |
$this->pkg->setAPIStability($opt->getValue());
|
|
|
142 |
break;
|
|
|
143 |
|
|
|
144 |
case 'notes':
|
|
|
145 |
$this->pkg->setNotes($opt->getValue());
|
|
|
146 |
break;
|
|
|
147 |
|
|
|
148 |
case 'packagetype':
|
|
|
149 |
$this->pkg->setPackageType($opt->getValue());
|
|
|
150 |
break;
|
|
|
151 |
|
|
|
152 |
case 'phpdep':
|
|
|
153 |
$this->pkg->setPhpDep($opt->getValue());
|
|
|
154 |
break;
|
|
|
155 |
|
|
|
156 |
case 'pearinstallerdep':
|
|
|
157 |
$this->pkg->setPearinstallerDep($opt->getValue());
|
|
|
158 |
break;
|
|
|
159 |
|
|
|
160 |
default:
|
|
|
161 |
$newopts[] = $opt;
|
|
|
162 |
break;
|
|
|
163 |
}
|
|
|
164 |
}
|
|
|
165 |
$this->options = $newopts;
|
|
|
166 |
|
|
|
167 |
$newmaps = array();
|
|
|
168 |
foreach ($this->mappings as $map) {
|
|
|
169 |
switch ($map->getName()) {
|
|
|
170 |
case 'deps':
|
|
|
171 |
$deps = $map->getValue();
|
|
|
172 |
foreach ($deps as $dep) {
|
|
|
173 |
$type = isset($dep['optional']) ? 'optional' : 'required';
|
|
|
174 |
$min = isset($dep['min']) ? $dep['min'] : $dep['version'];
|
|
|
175 |
$max = isset($dep['max']) ? $dep['max'] : $dep['version'];
|
|
|
176 |
$rec = isset($dep['recommended']) ? $dep['recommended'] : $dep['version'];
|
|
|
177 |
$channel = isset($dep['channel']) ? $dep['channel'] : false;
|
|
|
178 |
$uri = isset($dep['uri']) ? $dep['uri'] : false;
|
|
|
179 |
|
|
|
180 |
if (!empty($channel)) {
|
|
|
181 |
$this->pkg->addPackageDepWithChannel(
|
|
|
182 |
$type, $dep['name'], $channel, $min, $max, $rec
|
|
|
183 |
);
|
|
|
184 |
} elseif (!empty($uri)) {
|
|
|
185 |
$this->pkg->addPackageDepWithUri(
|
|
|
186 |
$type, $dep['name'], $uri
|
|
|
187 |
);
|
|
|
188 |
}
|
|
|
189 |
};
|
|
|
190 |
break;
|
|
|
191 |
|
|
|
192 |
case 'extdeps':
|
|
|
193 |
$deps = $map->getValue();
|
|
|
194 |
foreach ($deps as $dep) {
|
|
|
195 |
$type = isset($dep['optional']) ? 'optional' : 'required';
|
|
|
196 |
$min = isset($dep['min']) ? $dep['min'] : $dep['version'];
|
|
|
197 |
$max = isset($dep['max']) ? $dep['max'] : $dep['version'];
|
|
|
198 |
$rec = isset($dep['recommended']) ? $dep['recommended'] : $dep['version'];
|
|
|
199 |
|
|
|
200 |
$this->pkg->addExtensionDep(
|
|
|
201 |
$type, $dep['name'], $min, $max, $rec
|
|
|
202 |
);
|
|
|
203 |
};
|
|
|
204 |
break;
|
|
|
205 |
|
|
|
206 |
case 'maintainers':
|
|
|
207 |
$maintainers = $map->getValue();
|
|
|
208 |
|
|
|
209 |
foreach ($maintainers as $maintainer) {
|
|
|
210 |
if (!isset($maintainer['active'])) {
|
|
|
211 |
$maintainer['active'] = 'yes';
|
|
|
212 |
}
|
|
|
213 |
$this->pkg->addMaintainer(
|
|
|
214 |
$maintainer['role'],
|
|
|
215 |
$maintainer['handle'],
|
|
|
216 |
$maintainer['name'],
|
|
|
217 |
$maintainer['email'],
|
|
|
218 |
$maintainer['active']
|
|
|
219 |
);
|
|
|
220 |
}
|
|
|
221 |
break;
|
|
|
222 |
|
|
|
223 |
case 'replacements':
|
|
|
224 |
$replacements = $map->getValue();
|
|
|
225 |
|
|
|
226 |
foreach($replacements as $replacement) {
|
|
|
227 |
$this->pkg->addReplacement(
|
|
|
228 |
$replacement['path'],
|
|
|
229 |
$replacement['type'],
|
|
|
230 |
$replacement['from'],
|
|
|
231 |
$replacement['to']
|
|
|
232 |
);
|
|
|
233 |
}
|
|
|
234 |
break;
|
|
|
235 |
|
|
|
236 |
default:
|
|
|
237 |
$newmaps[] = $map;
|
|
|
238 |
}
|
|
|
239 |
}
|
|
|
240 |
$this->mappings = $newmaps;
|
|
|
241 |
}
|
|
|
242 |
|
|
|
243 |
/**
|
|
|
244 |
* Main entry point.
|
|
|
245 |
* @return void
|
|
|
246 |
*/
|
|
|
247 |
public function main()
|
|
|
248 |
{
|
|
|
249 |
if ($this->dir === null) {
|
|
|
250 |
throw new BuildException("You must specify the \"dir\" attribute for PEAR package 2 task.");
|
|
|
251 |
}
|
|
|
252 |
|
|
|
253 |
if ($this->package === null) {
|
|
|
254 |
throw new BuildException("You must specify the \"name\" attribute for PEAR package 2 task.");
|
|
|
255 |
}
|
|
|
256 |
|
|
|
257 |
$this->pkg = new PEAR_PackageFileManager2();
|
|
|
258 |
|
|
|
259 |
$this->setVersion2Options();
|
|
|
260 |
$this->setOptions();
|
|
|
261 |
|
|
|
262 |
$this->pkg->addRelease();
|
|
|
263 |
$this->pkg->generateContents();
|
|
|
264 |
$e = $this->pkg->writePackageFile();
|
|
|
265 |
if (PEAR::isError($e)) {
|
|
|
266 |
throw new BuildException("Unable to write package file.", new Exception($e->getMessage()));
|
|
|
267 |
}
|
|
|
268 |
}
|
|
|
269 |
|
|
|
270 |
}
|