source: build/BuildPhingPEARPackageTask.php @ ac2e44fc

Last change on this file since ac2e44fc was ac2e44fc, checked in by Michiel Rook <mrook@…>, 4 years ago

Refs #596 - fix compatibility with PHP_Depend 0.10.0

  • Property mode set to 100644
File size: 11.4 KB
Line 
1<?php
2/*
3 *  $Id$
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
22require_once 'phing/tasks/system/MatchingTask.php';
23include_once 'phing/types/FileSet.php';
24include_once 'phing/tasks/ext/pearpackage/Fileset.php';
25
26/**
27 *
28 * @author   Hans Lellelid <hans@xmpl.org>
29 * @package  phing.tasks.ext
30 * @version  $Revision$
31 */
32class BuildPhingPEARPackageTask extends MatchingTask {
33
34    /** Base directory for reading files. */
35    private $dir;
36
37    private $version;
38    private $state = 'stable';
39    private $notes;
40   
41    private $mode = 'source';
42   
43    private $filesets = array();
44   
45    /** Package file */
46    private $packageFile;
47
48    public function init() {
49        include_once 'PEAR/PackageFileManager2.php';
50        if (!class_exists('PEAR_PackageFileManager2')) {
51            throw new BuildException("You must have installed PEAR_PackageFileManager2 (PEAR_PackageFileManager >= 1.6.0) in order to create a PEAR package.xml file.");
52        }
53    }
54
55    private function setOptions($pkg){
56
57        $options['baseinstalldir'] = 'phing';
58        $options['packagedirectory'] = $this->dir->getAbsolutePath();
59
60        if (empty($this->filesets)) {
61            throw new BuildException("You must use a <fileset> tag to specify the files to include in the package.xml");
62        }
63
64        $options['filelistgenerator'] = 'Fileset';
65
66        // Some PHING-specific options needed by our Fileset reader
67        $options['phing_project'] = $this->getProject();
68        $options['phing_filesets'] = $this->filesets;
69       
70        if ($this->packageFile !== null) {
71            // create one w/ full path
72            $f = new PhingFile($this->packageFile->getAbsolutePath());
73            $options['packagefile'] = $f->getName();
74            // must end in trailing slash
75            $options['outputdirectory'] = $f->getParent() . DIRECTORY_SEPARATOR;
76            $this->log("Creating package file: " . $f->getPath(), Project::MSG_INFO);
77        } else {
78            $this->log("Creating [default] package.xml file in base directory.", Project::MSG_INFO);
79        }
80       
81        if ($this->mode == "docs")
82        {
83            $options['dir_roles'] = array(  'phing_guide' => 'doc',
84                                            'api' => 'doc',
85                                            'example' => 'doc');
86        }
87        else
88        {
89            // add install exceptions
90            $options['installexceptions'] = array(  'bin/phing.php' => '/',
91                                                    'bin/pear-phing' => '/',
92                                                    'bin/pear-phing.bat' => '/',
93                                                    );
94
95            $options['dir_roles'] = array(  'etc' => 'data');
96
97            $options['exceptions'] = array( 'bin/pear-phing.bat' => 'script',
98                                            'bin/pear-phing' => 'script',
99                                            'CREDITS' => 'doc',
100                                            'CHANGELOG' => 'doc',
101                                            'README' => 'doc',
102                                            'UPGRADE' => 'doc',
103                                            'TODO' => 'doc');
104        }
105
106        $pkg->setOptions($options);
107
108    }
109
110    /**
111     * Main entry point.
112     * @return void
113     */
114    public function main() {
115
116        if ($this->dir === null) {
117            throw new BuildException("You must specify the \"dir\" attribute for PEAR package task.");
118        }
119
120        if ($this->version === null) {
121            throw new BuildException("You must specify the \"version\" attribute for PEAR package task.");
122        }
123
124        $package = new PEAR_PackageFileManager2();
125
126        $this->setOptions($package);
127
128        // the hard-coded stuff
129        if ($this->mode == "docs")
130        {
131            $package->setPackage('phingdocs');
132            $package->setSummary('PHP5 project build system based on Apache Ant (documentation)');
133        }
134        else
135        {
136            $package->setPackage('phing');
137            $package->setSummary('PHP5 project build system based on Apache Ant');
138        }
139       
140        $package->setDescription('PHing Is Not GNU make; it\'s a project build system based on Apache Ant.
141You can do anything with it that you could do with a traditional build system like GNU make, and its use of
142simple XML build files and extensible PHP "task" classes make it an easy-to-use and highly flexible build framework.
143Features include file transformations (e.g. token replacement, XSLT transformation, Smarty template transformations,
144etc.), file system operations, interactive build support, SQL execution, and much more.');
145        $package->setChannel('pear.phing.info');
146        $package->setPackageType('php');
147
148        $package->setReleaseVersion($this->version);
149        $package->setAPIVersion($this->version);
150       
151        $package->setReleaseStability($this->state);
152        $package->setAPIStability($this->state);
153       
154        $package->setNotes($this->notes);
155       
156        $package->setLicense('LGPL', 'http://www.gnu.org/licenses/lgpl.html');
157       
158        // Add package maintainers
159        $package->addMaintainer('lead', 'hans', 'Hans Lellelid', 'hans@xmpl.org');
160        $package->addMaintainer('lead', 'mrook', 'Michiel Rook', 'mrook@php.net');
161       
162       
163       
164        // (wow ... this is a poor design ...)
165        //
166        // note that the order of the method calls below is creating
167        // sub-"release" sections which have specific rules.  This replaces
168        // the platformexceptions system in the older version of PEAR's package.xml
169        //
170        // Programmatically, I feel the need to re-iterate that this API for PEAR_PackageFileManager
171        // seems really wrong.  Sub-sections should be encapsulated in objects instead of having
172        // a "flat" API that does not represent the structure being created....
173       
174        if ($this->mode != "docs")
175        {
176            // creating a sub-section for 'windows'
177            $package->addRelease();
178            $package->setOSInstallCondition('windows');
179            $package->addInstallAs('bin/phing.php', 'phing.php');
180            $package->addInstallAs('bin/pear-phing.bat', 'phing.bat');
181            $package->addIgnoreToRelease('bin/pear-phing');
182       
183            // creating a sub-section for non-windows
184            $package->addRelease();
185            $package->addInstallAs('bin/phing.php', 'phing.php');
186            $package->addInstallAs('bin/pear-phing', 'phing');
187            $package->addIgnoreToRelease('bin/pear-phing.bat');
188        }
189       
190
191        // "core" dependencies
192        $package->setPhpDep('5.2.0');
193        $package->setPearinstallerDep('1.8.0');
194       
195        // "package" dependencies
196        if ($this->mode != "docs")
197        {
198            $package->addPackageDepWithChannel( 'optional', 'phingdocs', 'pear.phing.info', $this->version);
199            $package->addPackageDepWithChannel( 'optional', 'VersionControl_SVN', 'pear.php.net', '0.3.4');
200            $package->addPackageDepWithChannel( 'optional', 'VersionControl_Git', 'pear.php.net', '0.4.3');
201            $package->addPackageDepWithChannel( 'optional', 'PHPUnit', 'pear.phpunit.de', '3.4.0');
202            $package->addPackageDepWithChannel( 'optional', 'PhpDocumentor', 'pear.php.net', '1.4.0');
203            $package->addPackageDepWithChannel( 'optional', 'Xdebug', 'pecl.php.net', '2.0.5');
204            $package->addPackageDepWithChannel( 'optional', 'Archive_Tar', 'pear.php.net', '1.3.0');
205            $package->addPackageDepWithChannel( 'optional', 'PEAR_PackageFileManager', 'pear.php.net', '1.5.2');
206            $package->addPackageDepWithChannel( 'optional', 'Services_Amazon_S3', 'pear.php.net', '0.3.1');
207            $package->addPackageDepWithChannel( 'optional', 'HTTP_Request2', 'pear.php.net', '0.5.2');
208            $package->addPackageDepWithChannel( 'optional', 'PHP_Depend', 'pear.pdepend.org', '0.10.0');
209
210            // now add the replacements, chdir() to source directory
211            // to allow addReplacement() to find the specified files
212            $cwd = getcwd();
213            chdir($this->dir->getAbsolutePath());
214           
215            $package->addReplacement('Phing.php', 'pear-config', '@DATA-DIR@', 'data_dir');
216            $package->addReplacement('bin/pear-phing.bat', 'pear-config', '@PHP-BIN@', 'php_bin');
217            $package->addReplacement('bin/pear-phing.bat', 'pear-config', '@BIN-DIR@', 'bin_dir');
218            $package->addReplacement('bin/pear-phing.bat', 'pear-config', '@PEAR-DIR@', 'php_dir');
219            $package->addReplacement('bin/pear-phing', 'pear-config', '@PHP-BIN@', 'php_bin');
220            $package->addReplacement('bin/pear-phing', 'pear-config', '@BIN-DIR@', 'bin_dir');
221            $package->addReplacement('bin/pear-phing', 'pear-config', '@PEAR-DIR@', 'php_dir');
222           
223            chdir($cwd);
224        }
225
226        $package->generateContents();
227       
228        $e = $package->writePackageFile();
229
230        if (PEAR::isError($e)) {
231            throw new BuildException("Unable to write package file.", new Exception($e->getMessage()));
232        }
233
234    }
235
236    /**
237     * Used by the PEAR_PackageFileManager_PhingFileSet lister.
238     * @return array FileSet[]
239     */
240    public function getFileSets() {
241        return $this->filesets;
242    }
243
244    // -------------------------------
245    // Set properties from XML
246    // -------------------------------
247
248    /**
249     * Nested creator, creates a FileSet for this task
250     *
251     * @return FileSet The created fileset object
252     */
253    function createFileSet() {
254        $num = array_push($this->filesets, new FileSet());
255        return $this->filesets[$num-1];
256    }
257
258    /**
259     * Set the version we are building.
260     * @param string $v
261     * @return void
262     */
263    public function setVersion($v){
264        $this->version = $v;
265    }
266
267    /**
268     * Set the state we are building.
269     * @param string $v
270     * @return void
271     */
272    public function setState($v) {
273        $this->state = $v;
274    }
275   
276    /**
277     * Sets release notes field.
278     * @param string $v
279     * @return void
280     */
281    public function setNotes($v) {
282        $this->notes = $v;
283    }
284    /**
285     * Sets "dir" property from XML.
286     * @param PhingFile $f
287     * @return void
288     */
289    public function setDir(PhingFile $f) {
290        $this->dir = $f;
291    }
292
293    /**
294     * Sets the file to use for generated package.xml
295     */
296    public function setDestFile(PhingFile $f) {
297        $this->packageFile = $f;
298    }
299
300    /**
301     * Sets mode property
302     * @param string $v
303     * @return void
304     */
305    public function setMode($v) {
306        $this->mode = $v;
307    }
308}
309
310
Note: See TracBrowser for help on using the repository browser.