Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

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