From 4020b11ec2e2cb533c282391af8c54127d187321 Mon Sep 17 00:00:00 2001 From: Mike van Riel Date: Wed, 6 Oct 2010 20:48:35 +0200 Subject: [PATCH] Added parameter for setting the desired output format for transformation, separated target param for transformation into a source and target param, added a license file --- DocBlox/Writer/Abstract.php | 12 ++++ DocBlox/Writer/Xslt.php | 6 +- DocBlox/Writer/Xslt/ClassGraph.php | 24 +++++++- LICENSE | 19 +++++++ TODO | 9 +-- bin/transform.php | 90 +++++++++++++++++++----------- config.xml | 3 + 7 files changed, 122 insertions(+), 41 deletions(-) create mode 100644 LICENSE diff --git a/DocBlox/Writer/Abstract.php b/DocBlox/Writer/Abstract.php index 0eb65bf308..8dccae3296 100644 --- a/DocBlox/Writer/Abstract.php +++ b/DocBlox/Writer/Abstract.php @@ -16,6 +16,7 @@ class DocBlox_Writer_Abstract extends DocBlox_Abstract protected $theme = 'default'; protected $theme_path = ''; protected $target = ''; + protected $source = ''; protected $resource_path = ''; public function __construct() @@ -24,6 +25,17 @@ public function __construct() $this->resource_path = $root_path.'/resources'; $this->theme_path = $this->resource_path.'/themes'; $this->target = $root_path.'/output'; + $this->source = $root_path.'/output/structure.xml'; + } + + public function getSource() + { + return $this->source; + } + + public function setSource($source) + { + $this->source = $source; } public function getTarget() diff --git a/DocBlox/Writer/Xslt.php b/DocBlox/Writer/Xslt.php index 4ec9a2d4d9..9b15b71195 100644 --- a/DocBlox/Writer/Xslt.php +++ b/DocBlox/Writer/Xslt.php @@ -160,7 +160,8 @@ function generateFullPath($path) public function execute() { - $target_path = realpath($this->target); + $target_path = realpath($this->getTarget()); + $source_file = realpath($this->getSource()); // copy all generic files to the target folder $this->copyRecursive($this->resource_path.'/js', $target_path.'/js'); @@ -175,7 +176,7 @@ public function execute() // Load the XML source $xml = new DOMDocument(); - $xml->load($target_path.'/structure.xml'); + $xml->load($source_file); // get a list of contained files $files = array(); @@ -194,6 +195,7 @@ public function execute() $this->log('Generating the class diagram'); $class_graph = new DocBlox_Writer_Xslt_ClassGraph(); + $class_graph->setTarget($this->getTarget()); $class_graph->execute($xml); } } diff --git a/DocBlox/Writer/Xslt/ClassGraph.php b/DocBlox/Writer/Xslt/ClassGraph.php index 0a89544054..6592a5c31a 100644 --- a/DocBlox/Writer/Xslt/ClassGraph.php +++ b/DocBlox/Writer/Xslt/ClassGraph.php @@ -20,6 +20,26 @@ class DocBlox_Writer_Xslt_ClassGraph extends DocBlox_Abstract { protected $target = './output'; + /** + * Returns the target location for the SVG. + * + * @return string + */ + public function getTarget() + { + return $this->target; + } + + /** + * Sets the target location for the SVG. + * + * @return string + */ + public function setTarget($target) + { + $this->target = $target; + } + public function execute(DomDocument $xml) { // NOTE: the -V flag sends output using STDERR and STDOUT @@ -102,7 +122,7 @@ public function execute(DomDocument $xml) $graph->renderDotFile($dot_file, $path.'/classes.svg'); } - function buildTreenode($node_list, $parent = 'stdClass') + protected function buildTreenode($node_list, $parent = 'stdClass') { if (!isset($node_list[$parent])) { @@ -118,7 +138,7 @@ function buildTreenode($node_list, $parent = 'stdClass') return $result; } - function buildGraphNode(Image_GraphViz $graph, $nodes, $parent = null) + protected function buildGraphNode(Image_GraphViz $graph, $nodes, $parent = null) { foreach($nodes as $node => $children) { diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000..615e4cf23b --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2010 Mike van Riel + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/TODO b/TODO index 44b12b2412..2855d05773 100644 --- a/TODO +++ b/TODO @@ -1,20 +1,21 @@ 0.6: Add configuration files, clean up and fixes + Add Zend_Config support for projects and default configuration (command-line options override settings) -* Clean up code + Capture STDERR message when graphviz is not installed (ClassGraph.php:26) ++ Get Transformation Writer from Config ++ separate source and target parameter for transform.php ++ Add license (information) ++ add output format parameter to transform.php * Check theming support and improve -* separate source and target parameter for transform.php * description tab of class goes out of bounds if the tags are too big * safari does not show the svg nicely, it places it into a very small scrollbox * add line numbers to markers -* Add license (information) 0.7: Enhance docblock support, statistics support and add support for multiple writers * add inline parsing of annotations in docblock descriptions (see /lib/Zend/Log/Formatter/Firebug.php:40 for an example) * add parsing of docblock annotations and adding specific functionality per annotation * Keep track of number of docblock successes and fails and show at the end of the process * Add statistics (nr of files, classes, methods, with or without docblock. Percentage, lines per method, lines per file, configurable thresholds, etc) -* add output format parameter to transform.php and support for multiple writers +* Add PDF output writer * syntax highlight @example annotation content 0.8: Add custom documents diff --git a/bin/transform.php b/bin/transform.php index 429cf0dcf3..0930910666 100755 --- a/bin/transform.php +++ b/bin/transform.php @@ -16,8 +16,10 @@ // initialize the argument parser $opts = new Zend_Console_Getopt(array( 'help|h' => 'show this help message', - 'target|t-s' => 'path where the structure.xml is located and where to save the generated files (optional, defaults to "output")', - 'theme-s' => 'name of the theme to use (optional, defaults to "default")', + 'source|s-s' => 'path where the structure.xml is located (optional, defaults to "output/structure.xml")', + 'target|t-s' => 'path where to save the generated files (optional, defaults to "output")', + 'output|o-s' => 'output format to use (optional, defaults to "xslt")', + 'theme-s' => 'name of the theme to use (optional, defaults to "default")', 'verbose|v' => 'Outputs any information collected by this application, may slow down the process slightly', )); @@ -29,52 +31,74 @@ { throw new Zend_Console_Getopt_Exception(''); } -} catch (Zend_Console_Getopt_Exception $e) -{ - // if the message actually contains anything, show it. - if ($e->getMessage()) + + // initialize timer + $timer = new sfTimer(); + + if ($opts->getOption('output')) { - echo $e->getMessage() . PHP_EOL . PHP_EOL; + $writer = $opts->getOption('output'); + } else + { + if (!isset(DocBlox_Abstract::config()->transformation->writer)) + { + throw new Exception('Unable to find configuration entry for the transformation writer, please check your configuration file.'); + } + $writer = DocBlox_Abstract::config()->transformation->writer; } + $writer = 'DocBlox_Writer_'.ucfirst($writer); + $writer = new $writer(); - // show help message and exit the application - echo $opts->getUsageMessage(); - exit; -} + // set target option if it was provided by the user + if ($opts->getOption('target')) + { + $path = realpath($opts->getOption('target')); + if (!file_exists($path) && !is_dir($path) && !is_writable($path)) + { + throw new Exception('Given target directory does not exist or is not writable'); + } -// initialize timer -$timer = new sfTimer(); + $writer->setTarget($path); + } -echo 'Starting transformation of files (this could take a while depending upon the size of your project)'.PHP_EOL; + // set source option if it was provided by the user + if ($opts->getOption('source')) + { + $path = realpath($opts->getOption('source')); + if (!file_exists($path) || !is_readable($path)) + { + throw new Exception('Given source does not exist or is not readable'); + } -// TODO: for now we have hardcoded the Xslt writer, this must become a config entry or argument -$writer = new DocBlox_Writer_Xslt(); + $writer->setSource($path); + } -// set target option if it was provided by the user -if ($opts->getOption('t')) -{ - $path = realpath($opts->getOption('t')); - if (!file_exists($path) || !is_readable($path.'/structure.xml')) + // set theme / chrome path if provided + if ($opts->getOption('theme')) { - throw new Exception('Given target or structure.xml does not exist or is not readable'); + $writer->setTheme($opts->getOption('theme')); } - $writer->setTarget($path); -} - -// set theme / chrome path if provided -if ($opts->getOption('theme')) + // enable verbose mode if the flag was set + if ($opts->getOption('verbose')) + { + $writer->setLogLevel(Zend_Log::DEBUG); + } +} catch (Exception $e) { - $writer->setTheme($opts->getOption('theme')); -} + // if the message actually contains anything, show it. + if ($e->getMessage()) + { + echo $e->getMessage() . PHP_EOL . PHP_EOL; + } -// enable verbose mode if the flag was set -if ($opts->getOption('verbose')) -{ - $writer->setLogLevel(Zend_Log::DEBUG); + // show help message and exit the application + echo $opts->getUsageMessage(); + exit; } // start the transformation process +echo 'Starting transformation of files (this could take a while depending upon the size of your project)'.PHP_EOL; $writer->execute(); echo 'Finished transformation in '.round($timer->getElapsedTime(), 2).' seconds'.PHP_EOL; \ No newline at end of file diff --git a/config.xml b/config.xml index 18ce0c3544..0464427b36 100644 --- a/config.xml +++ b/config.xml @@ -17,4 +17,7 @@ TODO FIXME + + xslt + \ No newline at end of file