| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 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 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
class BuildPhingPEARPackageTask extends MatchingTask { |
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
private $dir; |
|---|
| 36 |
|
|---|
| 37 |
private $version; |
|---|
| 38 |
private $state = 'stable'; |
|---|
| 39 |
private $notes; |
|---|
| 40 |
|
|---|
| 41 |
private $filesets = array(); |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 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'] = 'phing'; |
|---|
| 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 |
|
|---|
| 65 |
$options['phing_project'] = $this->getProject(); |
|---|
| 66 |
$options['phing_filesets'] = $this->filesets; |
|---|
| 67 |
|
|---|
| 68 |
if ($this->packageFile !== null) { |
|---|
| 69 |
|
|---|
| 70 |
$f = new PhingFile($this->packageFile->getAbsolutePath()); |
|---|
| 71 |
$options['packagefile'] = $f->getName(); |
|---|
| 72 |
|
|---|
| 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 |
|
|---|
| 80 |
$options['installexceptions'] = array( 'bin/phing.php' => '/', |
|---|
| 81 |
'bin/pear-phing' => '/', |
|---|
| 82 |
'bin/pear-phing.bat' => '/', |
|---|
| 83 |
); |
|---|
| 84 |
|
|---|
| 85 |
$options['dir_roles'] = array( 'phing_guide' => 'doc', |
|---|
| 86 |
'etc' => 'data', |
|---|
| 87 |
'example' => 'doc'); |
|---|
| 88 |
|
|---|
| 89 |
$options['exceptions'] = array( 'bin/pear-phing.bat' => 'script', |
|---|
| 90 |
'bin/pear-phing' => 'script', |
|---|
| 91 |
'CREDITS' => 'doc', |
|---|
| 92 |
'CHANGELOG' => 'doc', |
|---|
| 93 |
'README' => 'doc', |
|---|
| 94 |
'TODO' => 'doc'); |
|---|
| 95 |
|
|---|
| 96 |
$pkg->setOptions($options); |
|---|
| 97 |
|
|---|
| 98 |
} |
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
* Main entry point. |
|---|
| 102 |
* @return void |
|---|
| 103 |
*/ |
|---|
| 104 |
public function main() { |
|---|
| 105 |
|
|---|
| 106 |
if ($this->dir === null) { |
|---|
| 107 |
throw new BuildException("You must specify the \"dir\" attribute for PEAR package task."); |
|---|
| 108 |
} |
|---|
| 109 |
|
|---|
| 110 |
if ($this->version === null) { |
|---|
| 111 |
throw new BuildException("You must specify the \"version\" attribute for PEAR package task."); |
|---|
| 112 |
} |
|---|
| 113 |
|
|---|
| 114 |
$package = new PEAR_PackageFileManager2(); |
|---|
| 115 |
|
|---|
| 116 |
$this->setOptions($package); |
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
$package->setPackage('phing'); |
|---|
| 120 |
$package->setSummary('PHP5 project build system based on Apache Ant'); |
|---|
| 121 |
$package->setDescription('PHing Is Not GNU make; it\'s a project build system based on Apache Ant. |
|---|
| 122 |
You can do anything with it that you could do with a traditional build system like GNU make, and its use of |
|---|
| 123 |
simple XML build files and extensible PHP "task" classes make it an easy-to-use and highly flexible build framework. |
|---|
| 124 |
Features include file transformations (e.g. token replacement, XSLT transformation, Smarty template transformations, |
|---|
| 125 |
etc.), file system operations, interactive build support, SQL execution, and much more.'); |
|---|
| 126 |
$package->setChannel('pear.phing.info'); |
|---|
| 127 |
$package->setPackageType('php'); |
|---|
| 128 |
|
|---|
| 129 |
$package->setReleaseVersion($this->version); |
|---|
| 130 |
$package->setAPIVersion($this->version); |
|---|
| 131 |
|
|---|
| 132 |
$package->setReleaseStability($this->state); |
|---|
| 133 |
$package->setAPIStability($this->state); |
|---|
| 134 |
|
|---|
| 135 |
$package->setNotes($this->notes); |
|---|
| 136 |
|
|---|
| 137 |
$package->setLicense('LGPL', 'http://www.gnu.org/licenses/lgpl.html'); |
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 |
$package->addMaintainer('lead', 'hans', 'Hans Lellelid', 'hans@xmpl.org'); |
|---|
| 141 |
$package->addMaintainer('lead', 'mrook', 'Michiel Rook', 'michiel.rook@gmail.com'); |
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
// |
|---|
| 147 |
// note that the order of the method calls below is creating |
|---|
| 148 |
// sub-"release" sections which have specific rules. This replaces |
|---|
| 149 |
// the platformexceptions system in the older version of PEAR's package.xml |
|---|
| 150 |
// |
|---|
| 151 |
// Programmatically, I feel the need to re-iterate that this API for PEAR_PackageFileManager |
|---|
| 152 |
// seems really wrong. Sub-sections should be encapsulated in objects instead of having |
|---|
| 153 |
// a "flat" API that does not represent the structure being created.... |
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
// creating a sub-section for 'windows' |
|---|
| 157 |
$package->addRelease(); |
|---|
| 158 |
$package->setOSInstallCondition('windows'); |
|---|
| 159 |
$package->addInstallAs('bin/phing.php', 'phing.php'); |
|---|
| 160 |
$package->addInstallAs('bin/pear-phing.bat', 'phing.bat'); |
|---|
| 161 |
$package->addIgnoreToRelease('bin/pear-phing'); |
|---|
| 162 |
|
|---|
| 163 |
|
|---|
| 164 |
$package->addRelease(); |
|---|
| 165 |
|
|---|
| 166 |
$package->addInstallAs('bin/phing.php', 'phing.php'); |
|---|
| 167 |
$package->addInstallAs('bin/pear-phing', 'phing'); |
|---|
| 168 |
$package->addIgnoreToRelease('bin/pear-phing.bat'); |
|---|
| 169 |
|
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 |
$package->setPhpDep('5.0.0'); |
|---|
| 173 |
$package->setPearinstallerDep('1.4.0'); |
|---|
| 174 |
|
|---|
| 175 |
|
|---|
| 176 |
$package->addPackageDepWithChannel( 'optional', 'VersionControl_SVN', 'pear.php.net', '0.3.0alpha1'); |
|---|
| 177 |
$package->addPackageDepWithChannel( 'optional', 'PHPUnit2', 'pear.php.net', '2.3.0'); |
|---|
| 178 |
$package->addPackageDepWithChannel( 'optional', 'PhpDocumentor', 'pear.php.net', '1.3.0RC3'); |
|---|
| 179 |
$package->addPackageDepWithChannel( 'optional', 'Xdebug', 'pear.php.net', '2.0.0beta2'); |
|---|
| 180 |
$package->addPackageDepWithChannel( 'optional', 'Archive_Tar', 'pear.php.net', '1.3.0'); |
|---|
| 181 |
$package->addPackageDepWithChannel( 'optional', 'PEAR_PackageFileManager', 'pear.php.net', '1.5.2'); |
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 |
$package->addReplacement('Phing.php', 'pear-config', '@DATA-DIR@', 'data_dir'); |
|---|
| 185 |
$package->addReplacement('bin/pear-phing.bat', 'pear-config', '@PHP-BIN@', 'php_bin'); |
|---|
| 186 |
$package->addReplacement('bin/pear-phing.bat', 'pear-config', '@BIN-DIR@', 'bin_dir'); |
|---|
| 187 |
$package->addReplacement('bin/pear-phing.bat', 'pear-config', '@PEAR-DIR@', 'php_dir'); |
|---|
| 188 |
$package->addReplacement('bin/pear-phing', 'pear-config', '@PHP-BIN@', 'php_bin'); |
|---|
| 189 |
$package->addReplacement('bin/pear-phing', 'pear-config', '@BIN-DIR@', 'bin_dir'); |
|---|
| 190 |
$package->addReplacement('bin/pear-phing', 'pear-config', '@PEAR-DIR@', 'php_dir'); |
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
// is necessary before we can add replacements ... ? |
|---|
| 194 |
$package->generateContents(); |
|---|
| 195 |
|
|---|
| 196 |
$e = $package->writePackageFile(); |
|---|
| 197 |
|
|---|
| 198 |
if (PEAR::isError($e)) { |
|---|
| 199 |
throw new BuildException("Unable to write package file.", new Exception($e->getMessage())); |
|---|
| 200 |
} |
|---|
| 201 |
|
|---|
| 202 |
} |
|---|
| 203 |
|
|---|
| 204 |
|
|---|
| 205 |
* Used by the PEAR_PackageFileManager_PhingFileSet lister. |
|---|
| 206 |
* @return array FileSet[] |
|---|
| 207 |
*/ |
|---|
| 208 |
public function getFileSets() { |
|---|
| 209 |
return $this->filesets; |
|---|
| 210 |
} |
|---|
| 211 |
|
|---|
| 212 |
|
|---|
| 213 |
// Set properties from XML |
|---|
| 214 |
// ------------------------------- |
|---|
| 215 |
|
|---|
| 216 |
/** |
|---|
| 217 |
* Nested creator, creates a FileSet for this task |
|---|
| 218 |
* |
|---|
| 219 |
* @return FileSet The created fileset object |
|---|
| 220 |
*/ |
|---|
| 221 |
function createFileSet() { |
|---|
| 222 |
$num = array_push($this->filesets, new FileSet()); |
|---|
| 223 |
return $this->filesets[$num-1]; |
|---|
| 224 |
} |
|---|
| 225 |
|
|---|
| 226 |
|
|---|
| 227 |
* Set the version we are building. |
|---|
| 228 |
* @param string $v |
|---|
| 229 |
* @return void |
|---|
| 230 |
*/ |
|---|
| 231 |
public function setVersion($v){ |
|---|
| 232 |
$this->version = $v; |
|---|
| 233 |
} |
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 |
* Set the state we are building. |
|---|
| 237 |
* @param string $v |
|---|
| 238 |
* @return void |
|---|
| 239 |
*/ |
|---|
| 240 |
public function setState($v) { |
|---|
| 241 |
$this->state = $v; |
|---|
| 242 |
} |
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| 245 |
* Sets release notes field. |
|---|
| 246 |
* @param string $v |
|---|
| 247 |
* @return void |
|---|
| 248 |
*/ |
|---|
| 249 |
public function setNotes($v) { |
|---|
| 250 |
$this->notes = $v; |
|---|
| 251 |
} |
|---|
| 252 |
|
|---|
| 253 |
* Sets "dir" property from XML. |
|---|
| 254 |
* @param PhingFile $f |
|---|
| 255 |
* @return void |
|---|
| 256 |
*/ |
|---|
| 257 |
public function setDir(PhingFile $f) { |
|---|
| 258 |
$this->dir = $f; |
|---|
| 259 |
} |
|---|
| 260 |
|
|---|
| 261 |
|
|---|
| 262 |
* Sets the file to use for generated package.xml |
|---|
| 263 |
*/ |
|---|
| 264 |
public function setDestFile(PhingFile $f) { |
|---|
| 265 |
$this->packageFile = $f; |
|---|
| 266 |
} |
|---|
| 267 |
|
|---|
| 268 |
} |
|---|
| 269 |
|
|---|
| 270 |
|
|---|
| 271 |
|
|---|