root/branches/1.3/generator/pear/BuildPropelGenPEARPackageTask.php

Revision 985, 8.8 kB (checked in by hans, 10 months ago)

Refs #588 -- Applying Felix's patch for the new JOIN behavior parameter in the doSelectJoin*() methods and build-time option to change the default.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id Rev Date Author HeadURL Revision
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
22 require_once 'phing/tasks/system/MatchingTask.php';
23 include_once 'phing/types/FileSet.php';
24 include_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  */
32 class BuildPropelGenPEARPackageTask 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 $filesets = array();
42
43     /** Package file */
44     private $packageFile;
45
46     public function init() {
47         include_once 'PEAR/PackageFileManager2.php';
48         if (!class_exists('PEAR_PackageFileManager2')) {
49             throw new BuildException("You must have installed PEAR_PackageFileManager2 (PEAR_PackageFileManager >= 1.6.0) in order to create a PEAR package.xml file.");
50         }
51     }
52
53     private function setOptions($pkg){
54
55         $options['baseinstalldir'] = 'propel';
56         $options['packagedirectory'] = $this->dir->getAbsolutePath();
57
58         if (empty($this->filesets)) {
59             throw new BuildException("You must use a <fileset> tag to specify the files to include in the package.xml");
60         }
61
62         $options['filelistgenerator'] = 'Fileset';
63
64         // Some PHING-specific options needed by our Fileset reader
65         $options['phing_project'] = $this->getProject();
66         $options['phing_filesets'] = $this->filesets;
67
68         if ($this->packageFile !== null) {
69             // create one w/ full path
70             $f = new PhingFile($this->packageFile->getAbsolutePath());
71             $options['packagefile'] = $f->getName();
72             // must end in trailing slash
73             $options['outputdirectory'] = $f->getParent() . DIRECTORY_SEPARATOR;
74             $this->log("Creating package file: " . $f->getPath(), Project::MSG_INFO);
75         } else {
76             $this->log("Creating [default] package.xml file in base directory.", Project::MSG_INFO);
77         }
78
79         // add install exceptions
80         $options['installexceptions'] = array(    'pear/pear-propel-gen' => '/',
81                                                 'pear/pear-propel-gen.bat' => '/',
82                                                 'pear/pear-build.xml' => '/',
83                                                 'pear/build.properties' => '/',
84                                                 );
85
86         $options['dir_roles'] = array(    'projects' => 'data',
87                                         'test' => 'test',
88                                         'templates' => 'data',
89                                         'resources' => 'data');
90
91         $options['exceptions'] = array(    'pear/pear-propel-gen.bat' => 'script',
92                                         'pear/pear-propel-gen' => 'script',
93                                         'pear/pear-build.xml' => 'data',
94                                         'build.xml' => 'data',
95                                         'build-propel.xml' => 'data',
96                                     );
97
98         $pkg->setOptions($options);
99
100     }
101
102     /**
103      * Main entry point.
104      * @return     void
105      */
106     public function main() {
107
108         if ($this->dir === null) {
109             throw new BuildException("You must specify the \"dir\" attribute for PEAR package task.");
110         }
111
112         if ($this->version === null) {
113             throw new BuildException("You must specify the \"version\" attribute for PEAR package task.");
114         }
115
116         $package = new PEAR_PackageFileManager2();
117
118         $this->setOptions($package);
119
120         // the hard-coded stuff
121         $package->setPackage('propel_generator');
122         $package->setSummary('Generator component of the Propel PHP object persistence layer');
123         $package->setDescription('Propel is an object persistence layer for PHP5 based on Apache Torque. This package provides the generator engine that builds PHP classes and SQL DDL based on an XML representation of your data model.');
124         $package->setChannel('pear.phpdb.org');
125         $package->setPackageType('php');
126
127         $package->setReleaseVersion($this->version);
128         $package->setAPIVersion($this->version);
129
130         $package->setReleaseStability($this->state);
131         $package->setAPIStability($this->state);
132
133         $package->setNotes($this->notes);
134
135         $package->setLicense('LGPL', 'http://www.gnu.org/licenses/lgpl.html');
136
137         // Add package maintainers
138         $package->addMaintainer('lead', 'hans', 'Hans Lellelid', 'hans@xmpl.org');
139         $package->addMaintainer('lead', 'david', 'David Zuelke', 'dz@bitxtender.com');
140
141
142
143         // (wow ... this is a poor design ...)
144         //
145         // note that the order of the method calls below is creating
146         // sub-"release" sections which have specific rules.  This replaces
147         // the platformexceptions system in the older version of PEAR's package.xml
148         //
149         // Programmatically, I feel the need to re-iterate that this API for PEAR_PackageFileManager
150         // seems really wrong.  Sub-sections should be encapsulated in objects instead of having
151         // a "flat" API that does not represent the structure being created....
152
153
154         // creating a sub-section for 'windows'
155             $package->addRelease();
156             $package->setOSInstallCondition('windows');
157             $package->addInstallAs('pear/pear-propel-gen.bat', 'propel-gen.bat');
158             $package->addIgnoreToRelease('pear/pear-propel-gen');
159
160         // creating a sub-section for non-windows
161             $package->addRelease();
162             $package->addInstallAs('pear/pear-propel-gen', 'propel-gen');
163             $package->addIgnoreToRelease('pear/pear-propel-gen.bat');
164
165
166         // "core" dependencies
167         $package->setPhpDep('5.2.0');
168         $package->setPearinstallerDep('1.4.0');
169
170         // "package" dependencies
171         $package->addPackageDepWithChannel( 'required', 'phing', 'pear.phing.info', '2.3.0');
172         $package->addPackageDepWithChannel( 'optional', 'creole', 'pear.phpdb.org', '1.1.0');
173
174         $package->addExtensionDep('required', 'pdo');
175         $package->addExtensionDep('required', 'xml');
176         $package->addExtensionDep('required', 'xsl');
177
178         // now add the replacements ....
179         $package->addReplacement('Phing.php', 'pear-config', '@DATA-DIR@', 'data_dir');
180         $package->addReplacement('pear/pear-propel-gen.bat', 'pear-config', '@PHP-BIN@', 'php_bin');
181         $package->addReplacement('pear/pear-propel-gen.bat', 'pear-config', '@BIN-DIR@', 'bin_dir');
182         $package->addReplacement('pear/pear-propel-gen.bat', 'pear-config', '@PEAR-DIR@', 'php_dir');
183         $package->addReplacement('pear/pear-propel-gen.bat', 'pear-config', '@DATA-DIR@', 'data_dir');
184
185         $package->addReplacement('pear/pear-propel-gen', 'pear-config', '@PHP-BIN@', 'php_bin');
186         $package->addReplacement('pear/pear-propel-gen', 'pear-config', '@BIN-DIR@', 'bin_dir');
187         $package->addReplacement('pear/pear-propel-gen', 'pear-config', '@PEAR-DIR@', 'php_dir');
188         $package->addReplacement('pear/pear-propel-gen', 'pear-config', '@DATA-DIR@', 'data_dir');
189
190         $package->addReplacement('pear/pear-build.xml', 'pear-config', '@PHP-BIN@', 'php_bin');
191         $package->addReplacement('pear/pear-build.xml', 'pear-config', '@BIN-DIR@', 'bin_dir');
192         $package->addReplacement('pear/pear-build.xml', 'pear-config', '@PEAR-DIR@', 'php_dir');
193         $package->addReplacement('pear/pear-build.xml', 'pear-config', '@DATA-DIR@', 'data_dir');
194
195
196         // now we run this weird generateContents() method that apparently
197         // is necessary before we can add replacements ... ?
198         $package->generateContents();
199
200         $e = $package->writePackageFile();
201
202         if (PEAR::isError($e)) {
203             throw new BuildException("Unable to write package file.", new Exception($e->getMessage()));
204         }
205
206     }
207
208     /**
209      * Used by the PEAR_PackageFileManager_PhingFileSet lister.
210      * @return     array FileSet[]
211      */
212     public function getFileSets() {
213         return $this->filesets;
214     }
215
216     // -------------------------------
217     // Set properties from XML
218     // -------------------------------
219
220     /**
221      * Nested creator, creates a FileSet for this task
222      *
223      * @return     FileSet The created fileset object
224      */
225     function createFileSet() {
226         $num = array_push($this->filesets, new FileSet());
227         return $this->filesets[$num-1];
228     }
229
230     /**
231      * Set the version we are building.
232      * @param      string $v
233      * @return     void
234      */
235     public function setVersion($v){
236         $this->version = $v;
237     }
238
239     /**
240      * Set the state we are building.
241      * @param      string $v
242      * @return     void
243      */
244     public function setState($v) {
245         $this->state = $v;
246     }
247
248     /**
249      * Sets release notes field.
250      * @param      string $v
251      * @return     void
252      */
253     public function setNotes($v) {
254         $this->notes = $v;
255     }
256     /**
257      * Sets "dir" property from XML.
258      * @param      PhingFile $f
259      * @return     void
260      */
261     public function setDir(PhingFile $f) {
262         $this->dir = $f;
263     }
264
265     /**
266      * Sets the file to use for generated package.xml
267      */
268     public function setDestFile(PhingFile $f) {
269         $this->packageFile = $f;
270     }
271
272 }
273
Note: See TracBrowser for help on using the browser.