1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
|
<?php
/**
* $Id: 0d5d03ba0499556fb210b95baeba574de2b869f2 $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
require_once 'phing/Task.php';
/**
* Task to run PhpDocumentor.
*
* @author Hans Lellelid <hans@xmpl.org>
* @author Michiel Rook <mrook@php.net>
* @version $Id: 0d5d03ba0499556fb210b95baeba574de2b869f2 $
* @package phing.tasks.ext.phpdoc
*/
class PhpDocumentorTask extends Task
{
/**
* @var string Title for browser window / package index.
*/
protected $title;
/**
* @var PhingFile The target directory for output files.
*/
protected $destdir;
/**
* @var array FileSet[] Filesets for files to parse.
*/
protected $filesets = array();
/**
* @var array FileSet[] Project documentation (README/INSTALL/CHANGELOG) files.
*/
protected $projDocFilesets = array();
/**
* @var string Package output format.
*/
protected $output;
/**
* @var boolean Whether to generate sourcecode for each file parsed.
*/
protected $linksource = false;
/**
* @var boolean Whether to parse private members.
*/
protected $parsePrivate = false;
/**
* @var boolean Whether to use javadoc descriptions (more primitive).
*/
protected $javadocDesc = false;
/**
* @var PhingFile Base directory for locating template files.
*/
protected $templateBase;
/**
* @var boolean Wheter to suppress output.
*/
protected $quiet = false;
/**
* @var string Comma-separated list of packages to output.
*/
protected $packages;
/**
* @var string Comma-separated list of tags to ignore.
*/
protected $ignoreTags;
/**
* @var string Default package name.
*/
protected $defaultPackageName;
/**
* @var string Default category name.
*/
protected $defaultCategoryName;
/**
* @var PhingFile Directory in which to look for examples.
*/
protected $examplesDir;
/**
* @var PhingFile Directory in which to look for configuration files.
*/
protected $configDir;
/**
* @var boolean Whether to parse as a PEAR repository.
*/
protected $pear = false;
/**
* @var boolean Control whether or not warnings will be shown for
* undocumented elements. Useful for identifying classes and
* methods that haven't yet been documented.
*/
protected $undocumentedelements = false;
/**
* @var string custom tags, will be recognized and put in tags[] instead of
* unknowntags[].
*/
protected $customtags = '';
/**
* @var string files to ignore
*/
protected $ignore = '';
/**
* Set the title for the generated documentation
*/
public function setTitle($title) {
$this->title = $title;
}
/**
* Set the destination directory for the generated documentation
*/
public function setDestdir(PhingFile $destdir) {
$this->destdir = $destdir;
}
/**
* Alias for {@link setDestdir()}.
* @see setDestdir()
*/
public function setTarget(PhingFile $destdir) {
$this->setDestdir($destdir);
}
/**
* Set the output format (e.g. HTML:Smarty:PHP).
* @param string $output
*/
public function setOutput($output) {
$this->output = $output;
}
/**
* Set whether to generate sourcecode for each file parsed
* @param boolean
*/
public function setSourcecode($b) {
$this->setLinksource($b);
}
/**
* Set whether to generate sourcecode for each file parsed
* @param boolean
*/
public function setLinksource($b) {
$this->linksource = $b;
}
/**
* Set whether to suppress output.
* @param boolean $b
*/
public function setQuiet($b) {
$this->quiet = $b;
}
/**
* Should private members/classes be documented
* @param boolean
*/
public function setParseprivate($parseprivate) {
$this->parsePrivate = $parseprivate;
}
/**
* Whether to use javadoc descriptions (more primitive).
* @param boolean
*/
public function setJavadocdesc($javadoc) {
$this->javadocDesc = $javadoc;
}
/**
* Set (comma-separated) list of packages to output.
*
* @param string $packages
*/
public function setPackageoutput($packages) {
$this->packages = $packages;
}
/**
* Set (comma-separated) list of tags to ignore.
*
* @param string $tags
*/
public function setIgnoretags($tags) {
$this->ignoreTags = $tags;
}
/**
* Set a directory to search for examples in.
* @param PhingFile $d
*/
public function setExamplesdir(PhingFile $d) {
$this->examplesDir = $d;
}
/**
* Set a directory to search for configuration files in.
* @param PhingFile $d
*/
public function setConfigdir(PhingFile $d) {
$this->configDir = $d;
}
/**
* Sets the default package name.
* @param string $name
*/
public function setDefaultpackagename($name) {
$this->defaultPackageName = $name;
}
/**
* Sets the default category name.
* @param string $name
*/
public function setDefaultcategoryname($name) {
$this->defaultCategoryName = $name;
}
/**
* Set whether to parse as PEAR repository.
* @param boolean $b
*/
public function setPear($b) {
$this->pear = $b;
}
/**
* Creates a FileSet.
* @return FileSet
*/
public function createFileset() {
$num = array_push($this->filesets, new FileSet());
return $this->filesets[$num-1];
}
/**
* Creates a readme/install/changelog fileset.
* @return FileSet
*/
public function createProjdocfileset() {
$num = array_push($this->projDocFilesets, new FileSet());
return $this->projDocFilesets[$num-1];
}
/**
* Control whether or not warnings will be shown for undocumented elements.
* Useful for identifying classes and methods that haven't yet been
* documented.
* @param boolean $b
*/
public function setUndocumentedelements($b) {
$this->undocumentedelements = $b;
}
/**
* custom tags, will be recognized and put in tags[] instead of
* unknowntags[].
*
* @param string $sCustomtags
*/
public function setCustomtags($sCustomtags) {
$this->customtags = $sCustomtags;
}
/**
* Set base location of all templates for this parse.
*
* @param PhingFile $destdir
*/
public function setTemplateBase(PhingFile $oTemplateBase) {
$this->templateBase = $oTemplateBase;
}
/**
* Set files to ignore
* @param string $sIgnore
*/
public function setIgnore($sIgnore) {
$this->ignore = $sIgnore;
}
/**
* Searches include_path for PhpDocumentor install and adjusts include_path appropriately.
* @throws BuildException - if unable to find PhpDocumentor on include_path
*/
protected function findPhpDocumentorInstall()
{
$found = null;
foreach(Phing::explodeIncludePath() as $path) {
$testpath = $path . DIRECTORY_SEPARATOR . 'PhpDocumentor';
if (file_exists($testpath)) {
$found = $testpath;
break;
}
}
if (!$found) {
throw new BuildException("PhpDocumentor task depends on PhpDocumentor being installed and on include_path.", $this->getLocation());
}
// otherwise, adjust the include_path to path to include the PhpDocumentor directory ...
set_include_path(get_include_path() . PATH_SEPARATOR . $found);
include_once ("phpDocumentor/Setup.inc.php");
if (!class_exists('phpDocumentor_setup')) {
throw new BuildException("Error including PhpDocumentor setup class file.");
}
}
/**
* Main entrypoint of the task
* Loads the necessary environment for running PhpDoc, then runs PhpDoc
*
* @throws BuildException - if the phpdoc classes can't be loaded.
*/
function main()
{
$this->findPhpDocumentorInstall();
include_once 'phing/tasks/ext/phpdoc/PhingPhpDocumentorSetup.php';
$this->validate();
$configdir = $this->configDir ? $this->configDir->getAbsolutePath() : null;
$phpdoc = new PhingPhpDocumentorSetup($configdir, $this);
$this->setPhpDocumentorOptions($phpdoc);
//$phpdoc->readCommandLineSettings();
$phpdoc->setupConverters($this->output);
$phpdoc->createDocs();
}
/**
* Validates that necessary minimum options have been set.
* @throws BuildException if validation doesn't pass
*/
protected function validate()
{
if (!$this->destdir) {
throw new BuildException("You must specify a destdir for phpdoc.", $this->getLocation());
}
if (!$this->output) {
throw new BuildException("You must specify an output format for phpdoc (e.g. HTML:frames:default).", $this->getLocation());
}
if (empty($this->filesets)) {
throw new BuildException("You have not specified any files to include (<fileset>) for phpdoc.", $this->getLocation());
}
}
/**
* Sets the options on the passed-in phpdoc setup object.
* @param PhingPhpDocumentorSetup $phpdoc
*/
protected function setPhpDocumentorOptions(PhingPhpDocumentorSetup $phpdoc)
{
// Title MUST be set first ... (because it re-initializes the internal state of the PhpDocu renderer)
if ($this->title) {
$phpdoc->setTitle($this->title);
}
if ($this->parsePrivate) {
$phpdoc->setParsePrivate();
}
if ($this->javadocDesc) {
$phpdoc->setJavadocDesc();
}
if ($this->quiet) {
$phpdoc->setQuietMode();
}
if ($this->destdir) {
$phpdoc->setTargetDir($this->destdir->getAbsolutePath());
}
if ($this->packages) {
$phpdoc->setPackageOutput($this->packages);
}
if ($this->templateBase) {
$phpdoc->setTemplateBase($this->templateBase->getAbsolutePath());
}
if ($this->linksource) {
$phpdoc->setGenerateSourcecode($this->linksource);
}
if ($this->examplesDir) {
$phpdoc->setExamplesDir($this->examplesDir->getAbsolutePath());
}
if ($this->ignoreTags) {
$phpdoc->setIgnoreTags($this->ignoreTags);
}
if ($this->defaultPackageName) {
$phpdoc->setDefaultPackageName($this->defaultPackageName);
}
if ($this->defaultCategoryName) {
$phpdoc->setDefaultCategoryName($this->defaultCategoryName);
}
if ($this->pear) {
$phpdoc->setPear($this->pear);
}
if ($this->ignore) {
$phpdoc->setIgnore($this->ignore);
}
// append any files in filesets
$filesToParse = array();
foreach($this->filesets as $fs) {
$files = $fs->getDirectoryScanner($this->project)->getIncludedFiles();
foreach($files as $filename) {
$f = new PhingFile($fs->getDir($this->project), $filename);
$filesToParse[] = $f->getAbsolutePath();
}
}
//print_r(implode(",", $filesToParse));
$phpdoc->setFilesToParse(implode(",", $filesToParse));
// append any files in filesets
$ricFiles = array();
foreach($this->projDocFilesets as $fs) {
$files = $fs->getDirectoryScanner($this->project)->getIncludedFiles();
foreach($files as $filename) {
$f = new PhingFile($fs->getDir($this->project), $filename);
$ricFiles[] = $f->getName();
}
}
$phpdoc->setRicFiles($ricFiles);
if ($this->undocumentedelements) {
$phpdoc->setUndocumentedelements($this->undocumentedelements);
}
if ($this->customtags) {
$phpdoc->setCustomtags($this->customtags);
}
}
}
|