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