Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/*
3
 *  $Id: BuildPropelGenPEARPackageTask.php 1750 2010-05-09 12:33:47Z francois $
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: 1750 $
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.propelorm.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
		$package->addMaintainer('lead', 'francois', 'Francois Zaninotto', 'fzaninotto@[gmail].com');
141
 
142
		// (wow ... this is a poor design ...)
143
		//
144
		// note that the order of the method calls below is creating
145
		// sub-"release" sections which have specific rules.  This replaces
146
		// the platformexceptions system in the older version of PEAR's package.xml
147
		//
148
		// Programmatically, I feel the need to re-iterate that this API for PEAR_PackageFileManager
149
		// seems really wrong.  Sub-sections should be encapsulated in objects instead of having
150
		// a "flat" API that does not represent the structure being created....
151
 
152
 
153
		// creating a sub-section for 'windows'
154
			$package->addRelease();
155
			$package->setOSInstallCondition('windows');
156
			$package->addInstallAs('pear/pear-propel-gen.bat', 'propel-gen.bat');
157
			$package->addIgnoreToRelease('pear/pear-propel-gen');
158
 
159
		// creating a sub-section for non-windows
160
			$package->addRelease();
161
			$package->addInstallAs('pear/pear-propel-gen', 'propel-gen');
162
			$package->addIgnoreToRelease('pear/pear-propel-gen.bat');
163
 
164
 
165
		// "core" dependencies
166
		$package->setPhpDep('5.2.4');
167
		$package->setPearinstallerDep('1.4.0');
168
 
169
		// "package" dependencies
170
		$package->addPackageDepWithChannel( 'required', 'phing', 'pear.phing.info', '2.3.0');
171
 
172
		$package->addExtensionDep('required', 'pdo');
173
		$package->addExtensionDep('required', 'xml');
174
		$package->addExtensionDep('required', 'xsl');
175
 
176
		// now add the replacements ....
177
		$package->addReplacement('Phing.php', 'pear-config', '@DATA-DIR@', 'data_dir');
178
		$package->addReplacement('pear/pear-propel-gen.bat', 'pear-config', '@PHP-BIN@', 'php_bin');
179
		$package->addReplacement('pear/pear-propel-gen.bat', 'pear-config', '@BIN-DIR@', 'bin_dir');
180
		$package->addReplacement('pear/pear-propel-gen.bat', 'pear-config', '@PEAR-DIR@', 'php_dir');
181
		$package->addReplacement('pear/pear-propel-gen.bat', 'pear-config', '@DATA-DIR@', 'data_dir');
182
 
183
		$package->addReplacement('pear/pear-propel-gen', 'pear-config', '@PHP-BIN@', 'php_bin');
184
		$package->addReplacement('pear/pear-propel-gen', 'pear-config', '@BIN-DIR@', 'bin_dir');
185
		$package->addReplacement('pear/pear-propel-gen', 'pear-config', '@PEAR-DIR@', 'php_dir');
186
		$package->addReplacement('pear/pear-propel-gen', 'pear-config', '@DATA-DIR@', 'data_dir');
187
 
188
		$package->addReplacement('pear/pear-build.xml', 'pear-config', '@PHP-BIN@', 'php_bin');
189
		$package->addReplacement('pear/pear-build.xml', 'pear-config', '@BIN-DIR@', 'bin_dir');
190
		$package->addReplacement('pear/pear-build.xml', 'pear-config', '@PEAR-DIR@', 'php_dir');
191
		$package->addReplacement('pear/pear-build.xml', 'pear-config', '@DATA-DIR@', 'data_dir');
192
 
193
 
194
		// now we run this weird generateContents() method that apparently
195
		// is necessary before we can add replacements ... ?
196
		$package->generateContents();
197
 
198
		$e = $package->writePackageFile();
199
 
200
		if (PEAR::isError($e)) {
201
			throw new BuildException("Unable to write package file.", new Exception($e->getMessage()));
202
		}
203
 
204
	}
205
 
206
	/**
207
	 * Used by the PEAR_PackageFileManager_PhingFileSet lister.
208
	 * @return     array FileSet[]
209
	 */
210
	public function getFileSets() {
211
		return $this->filesets;
212
	}
213
 
214
	// -------------------------------
215
	// Set properties from XML
216
	// -------------------------------
217
 
218
	/**
219
	 * Nested creator, creates a FileSet for this task
220
	 *
221
	 * @return     FileSet The created fileset object
222
	 */
223
	function createFileSet() {
224
		$num = array_push($this->filesets, new FileSet());
225
		return $this->filesets[$num-1];
226
	}
227
 
228
	/**
229
	 * Set the version we are building.
230
	 * @param      string $v
231
	 * @return     void
232
	 */
233
	public function setVersion($v){
234
		$this->version = $v;
235
	}
236
 
237
	/**
238
	 * Set the state we are building.
239
	 * @param      string $v
240
	 * @return     void
241
	 */
242
	public function setState($v) {
243
		$this->state = $v;
244
	}
245
 
246
	/**
247
	 * Sets release notes field.
248
	 * @param      string $v
249
	 * @return     void
250
	 */
251
	public function setNotes($v) {
252
		$this->notes = $v;
253
	}
254
	/**
255
	 * Sets "dir" property from XML.
256
	 * @param      PhingFile $f
257
	 * @return     void
258
	 */
259
	public function setDir(PhingFile $f) {
260
		$this->dir = $f;
261
	}
262
 
263
	/**
264
	 * Sets the file to use for generated package.xml
265
	 */
266
	public function setDestFile(PhingFile $f) {
267
		$this->packageFile = $f;
268
	}
269
 
270
}