Menu

[r12]: / trunk / PhpCheckstyle / run.php  Maximize  Restore  History

Download this file

149 lines (126 with data), 4.2 kB

  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
<?php
/*
* $Id: run.php 27242 2005-07-21 01:21:42Z hkodungallur $
*
* Copyright(c) 2004-2005, SpikeSource Inc. All Rights Reserved.
* Licensed under the Open Source License version 2.1
* (See http://www.spikesource.com/license.html)
*/
/**
* CLI file to run the PHPCheckstyle
*/
function usage() {
echo "Usage: ".$_SERVER['argv'][0]." <options>\n";
echo "\n";
echo " Options: \n";
echo " --src Root of the source directory tree or a file.\n";
echo " --exclude [Optional] A directory or file that needs to be excluded.\n";
echo " --format [Optional] Output format (html/text/console). Defaults to 'html'.\n";
echo " --outdir [Optional] Report Directory. Defaults to './style-report'.\n";
echo " --config [Optional] The name of the config file'.\n";
echo " --debug [Optional] Add some debug logs (warning, very verbose)'.\n";
echo " --linecount [Optional] Generate a report on the number of lines of code (JavaNCSS format)'.\n";
echo " --help Display this usage information.\n";
exit;
}
// default values
$options['src'] = false;
$options['exclude'] = array();
$options['format'] = "html";
$options['outdir'] = "./style-report";
$options['config'] = "default.cfg.xml";
$options['debug'] = false;
$xmlOutFile = "style-report.xml";
$txtOutFile = "style-report.txt";
$lineCountFile = "ncss.xml";
// loop through user input
for ($i = 1; $i < $_SERVER["argc"]; $i++) {
switch ($_SERVER["argv"][$i]) {
case "--src":
$i++;
$options['src'] = $_SERVER['argv'][$i];
break;
case "--outdir":
$i++;
$options['outdir'] = $_SERVER['argv'][$i];
break;
case "--exclude":
$i++;
$options['exclude'][] = $_SERVER['argv'][$i];
break;
case "--format":
$i++;
$options['format'] = $_SERVER['argv'][$i];
break;
case "--config":
$i++;
$options['config'] = $_SERVER['argv'][$i];
break;
case "--debug":
$options['debug'] = true;
break;
case "--linecount":
$options['linecount'] = true;
break;
case "--help":
usage();
break;
default:
usage();
break;
}
}
define("PHPCHECKSTYLE_HOME_DIR", dirname(__FILE__));
require_once PHPCHECKSTYLE_HOME_DIR."/src/PHPCheckstyle.php";
require_once PHPCHECKSTYLE_HOME_DIR."/src/util/Utility.php";
global $util;
define("CONFIG_FILE", $options['config']);
define("DEBUG", $options['debug']);
$outDir = $options['outdir'];
// if output directory does not exist, create it
if (!file_exists($outDir)) {
$util->makeDirRecursive($outDir);
}
// check for valid format and set the output file name
// right now the output file name is not configurable, only
// the output directory is configurable (from command line)
if ($options['format'] == "html") {
$outputFile = $outDir."/".$xmlOutFile;
} elseif ($options['format'] == "text") {
$outputFile = $outDir."/".$txtOutFile;
} elseif ($options['format'] == "console") {
$outputFile = "";
} else {
echo "\nUnknown format.\n\n";
usage();
}
// check that source directory is specified and is valid
if ($options['src'] == false) {
echo "\nPlease specify a source directory/file using --src option.\n\n";
usage();
}
if (!empty($options['linecount'])) {
$lineCountFile = $outDir."/".$lineCountFile;
}
$style = new PHPCheckstyle($options['format'], $outputFile, $lineCountFile);
$style->processFiles($options['src'], $options['exclude']);
// if output format is html, run the xml file through xsl to generate
// the html file
if ($options['format'] == "html") {
$xslFile = PHPCHECKSTYLE_HOME_DIR."/html/xsl/phpcheckstyle.xsl";
$htmlFile = $outDir."/index.html";
$xsl = new XSLTProcessor();
$docXsl = new DOMDocument();
$docXsl->load($xslFile);
$xsl->importStyleSheet($docXsl);
$hfh = fopen($htmlFile, "w");
$docOutput = new DOMDocument();
$docOutput->load($outputFile);
fwrite($hfh, $xsl->transformToXML($docOutput));
fclose($hfh);
$outputFile = $htmlFile;
// copy the css and images
$util->copyr(PHPCHECKSTYLE_HOME_DIR."/html/css", $outDir."/css");
$util->copyr(PHPCHECKSTYLE_HOME_DIR."/html/images", $outDir."/images");
}
echo "Reporting Completed. Please check the results in the file ".$outputFile."\n\n";
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.