CC-2166: Packaging Improvements. Moved the Zend app into airtime_mvc. It is now installed to /var/www/airtime. Storage is now set to /srv/airtime/stor. Utils are now installed to /usr/lib/airtime/utils/. Added install/airtime-dircheck.php as a simple test to see if everything is install/uninstalled correctly.
This commit is contained in:
parent
514777e8d2
commit
b11cbd8159
4546 changed files with 138 additions and 51 deletions
480
airtime_mvc/library/phing/tasks/ext/CapsuleTask.php
Normal file
480
airtime_mvc/library/phing/tasks/ext/CapsuleTask.php
Normal file
|
@ -0,0 +1,480 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* $Id: CapsuleTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
include_once 'phing/Task.php';
|
||||
include_once 'phing/BuildException.php';
|
||||
include_once 'phing/lib/Capsule.php';
|
||||
include_once 'phing/util/StringHelper.php';
|
||||
|
||||
/**
|
||||
* A phing task for generating output by using Capsule.
|
||||
*
|
||||
* This is based on the interface to TexenTask from Apache's Velocity engine.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Id: CapsuleTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext
|
||||
*/
|
||||
class CapsuleTask extends Task {
|
||||
|
||||
/**
|
||||
* Capsule "template" engine.
|
||||
* @var Capsule
|
||||
*/
|
||||
protected $context;
|
||||
|
||||
/**
|
||||
* Any vars assigned via the build file.
|
||||
* @var array AssignedVar[]
|
||||
*/
|
||||
protected $assignedVars = array();
|
||||
|
||||
/**
|
||||
* This is the control template that governs the output.
|
||||
* It may or may not invoke the services of worker
|
||||
* templates.
|
||||
* @var string
|
||||
*/
|
||||
protected $controlTemplate;
|
||||
|
||||
/**
|
||||
* This is where Velocity will look for templates
|
||||
* using the file template loader.
|
||||
* @var string
|
||||
*/
|
||||
protected $templatePath;
|
||||
|
||||
/**
|
||||
* This is where texen will place all the output
|
||||
* that is a product of the generation process.
|
||||
* @var string
|
||||
*/
|
||||
protected $outputDirectory;
|
||||
|
||||
/**
|
||||
* This is the file where the generated text
|
||||
* will be placed.
|
||||
* @var string
|
||||
*/
|
||||
protected $outputFile;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* These are properties that are fed into the
|
||||
* initial context from a properties file. This
|
||||
* is simply a convenient way to set some values
|
||||
* that you wish to make available in the context.
|
||||
* </p>
|
||||
* <p>
|
||||
* These values are not critical, like the template path
|
||||
* or output path, but allow a convenient way to
|
||||
* set a value that may be specific to a particular
|
||||
* generation task.
|
||||
* </p>
|
||||
* <p>
|
||||
* For example, if you are generating scripts to allow
|
||||
* user to automatically create a database, then
|
||||
* you might want the <code>$databaseName</code>
|
||||
* to be placed
|
||||
* in the initial context so that it is available
|
||||
* in a script that might look something like the
|
||||
* following:
|
||||
* <code><pre>
|
||||
* #!bin/sh
|
||||
*
|
||||
* echo y | mysqladmin create $databaseName
|
||||
* </pre></code>
|
||||
* The value of <code>$databaseName</code> isn't critical to
|
||||
* output, and you obviously don't want to change
|
||||
* the ant task to simply take a database name.
|
||||
* So initial context values can be set with
|
||||
* properties file.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $contextProperties;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// The following getters & setters are used by phing to set properties
|
||||
// specified in the XML for the capsule task.
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* [REQUIRED] Set the control template for the
|
||||
* generating process.
|
||||
* @param string $controlTemplate
|
||||
* @return void
|
||||
*/
|
||||
public function setControlTemplate ($controlTemplate) {
|
||||
$this->controlTemplate = $controlTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the control template for the
|
||||
* generating process.
|
||||
* @return string
|
||||
*/
|
||||
public function getControlTemplate() {
|
||||
return $this->controlTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* [REQUIRED] Set the path where Velocity will look
|
||||
* for templates using the file template
|
||||
* loader.
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function setTemplatePath($templatePath) {
|
||||
$resolvedPath = "";
|
||||
$tok = strtok($templatePath, ",");
|
||||
while ( $tok ) {
|
||||
// resolve relative path from basedir and leave
|
||||
// absolute path untouched.
|
||||
$fullPath = $this->project->resolveFile($tok);
|
||||
$cpath = $fullPath->getCanonicalPath();
|
||||
if ($cpath === false) {
|
||||
$this->log("Template directory does not exist: " . $fullPath->getAbsolutePath());
|
||||
} else {
|
||||
$resolvedPath .= $cpath;
|
||||
}
|
||||
$tok = strtok(",");
|
||||
if ( $tok ) {
|
||||
$resolvedPath .= ",";
|
||||
}
|
||||
}
|
||||
$this->templatePath = $resolvedPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path where Velocity will look
|
||||
* for templates using the file template
|
||||
* loader.
|
||||
* @return string
|
||||
*/
|
||||
public function getTemplatePath() {
|
||||
return $this->templatePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* [REQUIRED] Set the output directory. It will be
|
||||
* created if it doesn't exist.
|
||||
* @param PhingFile $outputDirectory
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function setOutputDirectory(PhingFile $outputDirectory) {
|
||||
try {
|
||||
if (!$outputDirectory->exists()) {
|
||||
$this->log("Output directory does not exist, creating: " . $outputDirectory->getPath(),Project::MSG_VERBOSE);
|
||||
if (!$outputDirectory->mkdirs()) {
|
||||
throw new IOException("Unable to create Ouptut directory: " . $outputDirectory->getAbsolutePath());
|
||||
}
|
||||
}
|
||||
$this->outputDirectory = $outputDirectory->getCanonicalPath();
|
||||
} catch (IOException $ioe) {
|
||||
throw new BuildException($ioe);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the output directory.
|
||||
* @return string
|
||||
*/
|
||||
public function getOutputDirectory() {
|
||||
return $this->outputDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
* [REQUIRED] Set the output file for the
|
||||
* generation process.
|
||||
* @param string $outputFile (TODO: change this to File)
|
||||
* @return void
|
||||
*/
|
||||
public function setOutputFile($outputFile) {
|
||||
$this->outputFile = $outputFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the output file for the
|
||||
* generation process.
|
||||
* @return string
|
||||
*/
|
||||
public function getOutputFile() {
|
||||
return $this->outputFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the context properties that will be
|
||||
* fed into the initial context be the
|
||||
* generating process starts.
|
||||
* @param string $file
|
||||
* @return void
|
||||
*/
|
||||
public function setContextProperties($file) {
|
||||
$sources = explode(",", $file);
|
||||
$this->contextProperties = new Properties();
|
||||
|
||||
// Always try to get the context properties resource
|
||||
// from a file first. Templates may be taken from a JAR
|
||||
// file but the context properties resource may be a
|
||||
// resource in the filesystem. If this fails than attempt
|
||||
// to get the context properties resource from the
|
||||
// classpath.
|
||||
for ($i=0, $sourcesLength=count($sources); $i < $sourcesLength; $i++) {
|
||||
$source = new Properties();
|
||||
|
||||
try {
|
||||
|
||||
// resolve relative path from basedir and leave
|
||||
// absolute path untouched.
|
||||
$fullPath = $this->project->resolveFile($sources[$i]);
|
||||
$this->log("Using contextProperties file: " . $fullPath->toString());
|
||||
$source->load($fullPath);
|
||||
|
||||
} catch (Exception $e) {
|
||||
|
||||
throw new BuildException("Context properties file " . $sources[$i] .
|
||||
" could not be found in the file system!");
|
||||
|
||||
}
|
||||
|
||||
$keys = $source->keys();
|
||||
|
||||
foreach ($keys as $key) {
|
||||
$name = $key;
|
||||
$value = $this->project->replaceProperties($source->getProperty($name));
|
||||
$this->contextProperties->setProperty($name, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the context properties that will be
|
||||
* fed into the initial context be the
|
||||
* generating process starts.
|
||||
* @return Properties
|
||||
*/
|
||||
public function getContextProperties() {
|
||||
return $this->contextProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an "AssignedVar" class.
|
||||
*/
|
||||
public function createAssign() {
|
||||
$a = new AssignedVar();
|
||||
$this->assignedVars[] = $a;
|
||||
return $a;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// End of XML setters & getters
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Creates a Smarty object.
|
||||
*
|
||||
* @return Smarty initialized (cleared) Smarty context.
|
||||
* @throws Exception the execute method will catch
|
||||
* and rethrow as a <code>BuildException</code>
|
||||
*/
|
||||
public function initControlContext() {
|
||||
$this->context->clear();
|
||||
foreach($this->assignedVars as $var) {
|
||||
$this->context->put($var->getName(), $var->getValue());
|
||||
}
|
||||
return $this->context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the input script with Velocity
|
||||
*
|
||||
* @throws BuildException
|
||||
* BuildExceptions are thrown when required attributes are missing.
|
||||
* Exceptions thrown by Velocity are rethrown as BuildExceptions.
|
||||
*/
|
||||
public function main() {
|
||||
|
||||
// Make sure the template path is set.
|
||||
if (empty($this->templatePath)) {
|
||||
throw new BuildException("The template path needs to be defined!");
|
||||
}
|
||||
|
||||
// Make sure the control template is set.
|
||||
if ($this->controlTemplate === null) {
|
||||
throw new BuildException("The control template needs to be defined!");
|
||||
}
|
||||
|
||||
// Make sure the output directory is set.
|
||||
if ($this->outputDirectory === null) {
|
||||
throw new BuildException("The output directory needs to be defined!");
|
||||
}
|
||||
|
||||
// Make sure there is an output file.
|
||||
if ($this->outputFile === null) {
|
||||
throw new BuildException("The output file needs to be defined!");
|
||||
}
|
||||
|
||||
// Setup Smarty runtime.
|
||||
|
||||
// Smarty uses one object to store properties and to store
|
||||
// the context for the template (unlike Velocity). We setup this object, calling it
|
||||
// $this->context, and then initControlContext simply zeros out
|
||||
// any assigned variables.
|
||||
$this->context = new Capsule();
|
||||
|
||||
if ($this->templatePath !== null) {
|
||||
$this->log("Using templatePath: " . $this->templatePath);
|
||||
$this->context->setTemplatePath($this->templatePath);
|
||||
}
|
||||
|
||||
// Make sure the output directory exists, if it doesn't
|
||||
// then create it.
|
||||
$outputDir = new PhingFile($this->outputDirectory);
|
||||
if (!$outputDir->exists()) {
|
||||
$this->log("Output directory does not exist, creating: " . $outputDir->getAbsolutePath());
|
||||
$outputDir->mkdirs();
|
||||
}
|
||||
|
||||
$this->context->setOutputDirectory($outputDir->getAbsolutePath());
|
||||
|
||||
$path = $this->outputDirectory . DIRECTORY_SEPARATOR . $this->outputFile;
|
||||
$this->log("Generating to file " . $path);
|
||||
|
||||
//$writer = new FileWriter($path);
|
||||
|
||||
// The generator and the output path should
|
||||
// be placed in the init context here and
|
||||
// not in the generator class itself.
|
||||
$c = $this->initControlContext();
|
||||
|
||||
// Set any variables that need to always
|
||||
// be loaded
|
||||
$this->populateInitialContext($c);
|
||||
|
||||
// Feed all the options into the initial
|
||||
// control context so they are available
|
||||
// in the control/worker templates.
|
||||
if ($this->contextProperties !== null) {
|
||||
|
||||
foreach($this->contextProperties->keys() as $property) {
|
||||
|
||||
$value = $this->contextProperties->getProperty($property);
|
||||
|
||||
// Special exception (from Texen)
|
||||
// for properties ending in file.contents:
|
||||
// in that case we dump the contents of the file
|
||||
// as the "value" for the Property.
|
||||
if (preg_match('/file\.contents$/', $property)) {
|
||||
// pull in contents of file specified
|
||||
|
||||
$property = substr($property, 0, strpos($property, "file.contents") - 1);
|
||||
|
||||
// reset value, and then
|
||||
// read in teh contents of the file into that var
|
||||
$value = "";
|
||||
$f = new PhingFile($project->resolveFile($value)->getCanonicalPath());
|
||||
if ($f->exists()) {
|
||||
$fr = new FileReader($f);
|
||||
$fr->readInto($value);
|
||||
}
|
||||
|
||||
} // if ends with file.contents
|
||||
|
||||
if (StringHelper::isBoolean($value)) {
|
||||
$value = StringHelper::booleanValue($value);
|
||||
}
|
||||
|
||||
$c->put($property, $value);
|
||||
|
||||
} // foreach property
|
||||
|
||||
} // if contextProperties !== null
|
||||
|
||||
try {
|
||||
$this->log("Parsing control template: " . $this->controlTemplate);
|
||||
$c->parse($this->controlTemplate, $path);
|
||||
} catch (Exception $ioe) {
|
||||
throw new BuildException("Cannot write parsed template: ". $ioe->getMessage());
|
||||
}
|
||||
|
||||
$this->cleanup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Place useful objects into the initial context.
|
||||
*
|
||||
*
|
||||
* @param Capsule $context The context to populate, as retrieved from
|
||||
* {@link #initControlContext()}.
|
||||
* @return void
|
||||
* @throws Exception Error while populating context. The {@link
|
||||
* #main()} method will catch and rethrow as a
|
||||
* <code>BuildException</code>.
|
||||
*/
|
||||
protected function populateInitialContext(Capsule $context) {
|
||||
$this->context->put("now", strftime("%c", time()));
|
||||
$this->context->put("task", $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* A hook method called at the end of {@link #execute()} which can
|
||||
* be overridden to perform any necessary cleanup activities (such
|
||||
* as the release of database connections, etc.). By default,
|
||||
* does nothing.
|
||||
* @return void
|
||||
* @throws Exception Problem cleaning up.
|
||||
*/
|
||||
protected function cleanup() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* An "inner" class for holding assigned var values.
|
||||
* May be need to expand beyond name/value in the future.
|
||||
*
|
||||
* @package phing.tasks.ext
|
||||
*/
|
||||
class AssignedVar {
|
||||
|
||||
private $name;
|
||||
private $value;
|
||||
|
||||
function setName($v) {
|
||||
$this->name = $v;
|
||||
}
|
||||
|
||||
function setValue($v) {
|
||||
$this->value = $v;
|
||||
}
|
||||
|
||||
function getName() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
function getValue() {
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
}
|
143
airtime_mvc/library/phing/tasks/ext/ExportPropertiesTask.php
Normal file
143
airtime_mvc/library/phing/tasks/ext/ExportPropertiesTask.php
Normal file
|
@ -0,0 +1,143 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* $Id: ExportPropertiesTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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";
|
||||
|
||||
/**
|
||||
* Saves currently defined properties into a specified file
|
||||
*
|
||||
* @author Andrei Serdeliuc
|
||||
* @extends Task
|
||||
* @version $Id: ExportPropertiesTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext
|
||||
*/
|
||||
class ExportPropertiesTask extends Task
|
||||
{
|
||||
/**
|
||||
* Array of project properties
|
||||
*
|
||||
* (default value: null)
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
private $_properties = null;
|
||||
|
||||
/**
|
||||
* Target file for saved properties
|
||||
*
|
||||
* (default value: null)
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
private $_targetFile = null;
|
||||
|
||||
/**
|
||||
* Exclude properties starting with these prefixes
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
private $_disallowedPropertyPrefixes = array(
|
||||
'host.',
|
||||
'phing.',
|
||||
'os.',
|
||||
'php.',
|
||||
'line.',
|
||||
'env.',
|
||||
'user.'
|
||||
);
|
||||
|
||||
/**
|
||||
* setter for _targetFile
|
||||
*
|
||||
* @access public
|
||||
* @param string $file
|
||||
* @return bool
|
||||
*/
|
||||
public function setTargetFile($file)
|
||||
{
|
||||
if(!is_dir(dirname($file))) {
|
||||
throw new BuildException("Parent directory of target file doesn't exist");
|
||||
}
|
||||
|
||||
if(!is_writable(dirname($file)) && (file_exists($file) && !is_writable($file))) {
|
||||
throw new BuildException("Target file isn't writable");
|
||||
}
|
||||
|
||||
$this->_targetFile = $file;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* setter for _disallowedPropertyPrefixes
|
||||
*
|
||||
* @access public
|
||||
* @param string $file
|
||||
* @return bool
|
||||
*/
|
||||
public function setDisallowedPropertyPrefixes($prefixes)
|
||||
{
|
||||
$this->_disallowedPropertyPrefixes = explode(",", $prefixes);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function main()
|
||||
{
|
||||
// Sets the currently declared properties
|
||||
$this->_properties = $this->getProject()->getProperties();
|
||||
|
||||
if(is_array($this->_properties) && !empty($this->_properties) && null !== $this->_targetFile) {
|
||||
$propertiesString = '';
|
||||
foreach($this->_properties as $propertyName => $propertyValue) {
|
||||
if(!$this->isDisallowedPropery($propertyName)) {
|
||||
$propertiesString .= $propertyName . "=" . $propertyValue . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
if(!file_put_contents($this->_targetFile, $propertiesString)) {
|
||||
throw new BuildException('Failed writing to ' . $this->_targetFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a property name is disallowed
|
||||
*
|
||||
* @access protected
|
||||
* @param string $propertyName
|
||||
* @return bool
|
||||
*/
|
||||
protected function isDisallowedPropery($propertyName)
|
||||
{
|
||||
foreach($this->_disallowedPropertyPrefixes as $property) {
|
||||
if(substr($propertyName, 0, strlen($property)) == $property) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
183
airtime_mvc/library/phing/tasks/ext/ExtractBaseTask.php
Normal file
183
airtime_mvc/library/phing/tasks/ext/ExtractBaseTask.php
Normal file
|
@ -0,0 +1,183 @@
|
|||
<?php
|
||||
/*
|
||||
*
|
||||
* 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/tasks/system/MatchingTask.php';
|
||||
|
||||
/**
|
||||
* Base class for extracting tasks such as Unzip and Untar.
|
||||
*
|
||||
* @author Joakim Bodin <joakim.bodin+phing@gmail.com>
|
||||
* @version $Id: ExtractBaseTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext
|
||||
* @since 2.2.0
|
||||
*/
|
||||
abstract class ExtractBaseTask extends MatchingTask {
|
||||
/**
|
||||
* @var PhingFile $file
|
||||
*/
|
||||
protected $file;
|
||||
/**
|
||||
* @var PhingFile $todir
|
||||
*/
|
||||
protected $todir;
|
||||
protected $removepath;
|
||||
protected $filesets = array(); // all fileset objects assigned to this task
|
||||
|
||||
/**
|
||||
* Add a new fileset.
|
||||
* @return FileSet
|
||||
*/
|
||||
public function createFileSet() {
|
||||
$this->fileset = new FileSet();
|
||||
$this->filesets[] = $this->fileset;
|
||||
return $this->fileset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of the zip file to extract.
|
||||
* @param PhingFile $file zip file to extract
|
||||
*/
|
||||
public function setFile(PhingFile $file) {
|
||||
$this->file = $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the base directory to look in for things to zip.
|
||||
* @param PhingFile $baseDir
|
||||
*/
|
||||
public function setToDir(PhingFile $todir) {
|
||||
$this->todir = $todir;
|
||||
}
|
||||
|
||||
public function setRemovePath($removepath)
|
||||
{
|
||||
$this->removepath = $removepath;
|
||||
}
|
||||
|
||||
/**
|
||||
* do the work
|
||||
* @throws BuildException
|
||||
*/
|
||||
public function main() {
|
||||
|
||||
$this->validateAttributes();
|
||||
|
||||
$filesToExtract = array();
|
||||
if ($this->file !== null) {
|
||||
if(!$this->isDestinationUpToDate($this->file)) {
|
||||
$filesToExtract[] = $this->file;
|
||||
} else {
|
||||
$this->log('Nothing to do: ' . $this->todir->getAbsolutePath() . ' is up to date for ' . $this->file->getCanonicalPath(), Project::MSG_INFO);
|
||||
}
|
||||
}
|
||||
|
||||
foreach($this->filesets as $compressedArchiveFileset) {
|
||||
$compressedArchiveDirScanner = $compressedArchiveFileset->getDirectoryScanner($this->project);
|
||||
$compressedArchiveFiles = $compressedArchiveDirScanner->getIncludedFiles();
|
||||
$compressedArchiveDir = $compressedArchiveFileset->getDir($this->project);
|
||||
|
||||
foreach ($compressedArchiveFiles as $compressedArchiveFilePath) {
|
||||
$compressedArchiveFile = new PhingFile($compressedArchiveDir, $compressedArchiveFilePath);
|
||||
if($compressedArchiveFile->isDirectory())
|
||||
{
|
||||
throw new BuildException($compressedArchiveFile->getAbsolutePath() . ' compressed archive cannot be a directory.');
|
||||
}
|
||||
|
||||
if(!$this->isDestinationUpToDate($compressedArchiveFile)) {
|
||||
$filesToExtract[] = $compressedArchiveFile;
|
||||
} else {
|
||||
$this->log('Nothing to do: ' . $this->todir->getAbsolutePath() . ' is up to date for ' . $compressedArchiveFile->getCanonicalPath(), Project::MSG_INFO);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($filesToExtract as $compressedArchiveFile) {
|
||||
$this->extractArchive($compressedArchiveFile);
|
||||
}
|
||||
}
|
||||
|
||||
abstract protected function extractArchive(PhingFile $compressedArchiveFile);
|
||||
|
||||
/**
|
||||
* @param array $files array of filenames
|
||||
* @param PhingFile $dir
|
||||
* @return boolean
|
||||
*/
|
||||
protected function isDestinationUpToDate(PhingFile $compressedArchiveFile) {
|
||||
if (!$compressedArchiveFile->exists()) {
|
||||
throw new BuildException("Could not find file " . $compressedArchiveFile->__toString() . " to extract.");
|
||||
}
|
||||
|
||||
$compressedArchiveContent = $this->listArchiveContent($compressedArchiveFile);
|
||||
if(is_array($compressedArchiveContent)) {
|
||||
|
||||
$fileSystem = FileSystem::getFileSystem();
|
||||
foreach ($compressedArchiveContent as $compressArchivePathInfo) {
|
||||
$compressArchiveFilename = $compressArchivePathInfo['filename'];
|
||||
if(!empty($this->removepath) && strlen($compressArchiveFilename) >= strlen($this->removepath))
|
||||
{
|
||||
$compressArchiveFilename = preg_replace('/^' . $this->removepath . '/','', $compressArchiveFilename);
|
||||
}
|
||||
$compressArchivePath = new PhingFile($this->todir, $compressArchiveFilename);
|
||||
|
||||
if(!$compressArchivePath->exists() ||
|
||||
$fileSystem->compareMTimes($compressedArchiveFile->getCanonicalPath(), $compressArchivePath->getCanonicalPath()) == 1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
abstract protected function listArchiveContent(PhingFile $compressedArchiveFile);
|
||||
|
||||
/**
|
||||
* Validates attributes coming in from XML
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
* @throws BuildException
|
||||
*/
|
||||
protected function validateAttributes() {
|
||||
|
||||
if ($this->file === null && count($this->filesets) === 0) {
|
||||
throw new BuildException("Specify at least one source compressed archive - a file or a fileset.");
|
||||
}
|
||||
|
||||
if ($this->todir === null) {
|
||||
throw new BuildException("todir must be set.");
|
||||
}
|
||||
|
||||
if ($this->todir !== null && $this->todir->exists() && !$this->todir->isDirectory()) {
|
||||
throw new BuildException("todir must be a directory.");
|
||||
}
|
||||
|
||||
if ($this->file !== null && $this->file->exists() && $this->file->isDirectory()) {
|
||||
throw new BuildException("Compressed archive file cannot be a directory.");
|
||||
}
|
||||
|
||||
if ($this->file !== null && !$this->file->exists()) {
|
||||
throw new BuildException("Could not find compressed archive file " . $this->file->__toString() . " to extract.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
147
airtime_mvc/library/phing/tasks/ext/FileHashTask.php
Normal file
147
airtime_mvc/library/phing/tasks/ext/FileHashTask.php
Normal file
|
@ -0,0 +1,147 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: FileHashTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
|
||||
/**
|
||||
* fileHash
|
||||
*
|
||||
* Calculate either MD5 or SHA hash value of a specified file and retun the
|
||||
* value in a property
|
||||
*
|
||||
* @author Johan Persson <johan162@gmail.com>
|
||||
* @version $Id: FileHashTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext
|
||||
*/
|
||||
class FileHashTask extends Task
|
||||
{
|
||||
/**
|
||||
* Property for File
|
||||
* @var PhingFile file
|
||||
*/
|
||||
private $file;
|
||||
|
||||
/**
|
||||
* Property to be set
|
||||
* @var string $property
|
||||
*/
|
||||
private $propertyName = "filehashvalue";
|
||||
|
||||
/**
|
||||
* Specify which hash algorithm to use.
|
||||
* 0 = MD5
|
||||
* 1 = SHA1
|
||||
*
|
||||
* @var integer $hashtype
|
||||
*/
|
||||
private $hashtype=0;
|
||||
|
||||
|
||||
/**
|
||||
* Specify if MD5 or SHA1 hash should be used
|
||||
* @param integer $type 0=MD5, 1=SHA1
|
||||
*/
|
||||
public function setHashtype($type)
|
||||
{
|
||||
$this->hashtype = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Which file for calculate the has value of
|
||||
* @param PhingFile $file
|
||||
*/
|
||||
public function setFile($file)
|
||||
{
|
||||
$this->file = $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of the property to use to return the has value
|
||||
* @param $property
|
||||
* @return
|
||||
*/
|
||||
public function setPropertyName($property)
|
||||
{
|
||||
$this->propertyName = $property;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main-Method for the Task
|
||||
*
|
||||
* @return void
|
||||
* @throws BuildException
|
||||
*/
|
||||
public function main()
|
||||
{
|
||||
$this->checkFile();
|
||||
$this->checkPropertyName();
|
||||
|
||||
// read file
|
||||
if( (int)$this->hashtype === 0 ) {
|
||||
$this->log("Calculating MD5 hash from: ".$this->file);
|
||||
$hashValue = md5_file($this->file,false);
|
||||
}
|
||||
elseif( (int)$this->hashtype === 1 ) {
|
||||
$this->log("Calculating SHA1 hash from: ".$this->file);
|
||||
$hashValue = sha1_file($this->file,false);
|
||||
}
|
||||
else {
|
||||
throw new BuildException(
|
||||
sprintf('[FileHash] Unknown hashtype specified %d. Must be either 0 (=MD5) or 1 (=SHA1).',$this->hashtype));
|
||||
|
||||
}
|
||||
|
||||
// publish hash value
|
||||
$this->project->setProperty($this->propertyName, $hashValue);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* checks file attribute
|
||||
* @return void
|
||||
* @throws BuildException
|
||||
*/
|
||||
private function checkFile()
|
||||
{
|
||||
// check File
|
||||
if ($this->file === null ||
|
||||
strlen($this->file) == 0) {
|
||||
throw new BuildException('[FileHash] You must specify an input file.', $this->file);
|
||||
}
|
||||
|
||||
if( ! is_readable($this->file) ) {
|
||||
throw new BuildException(sprintf('[FileHash] Input file does not exist or is not readable: %s',$this->file));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* checks property attribute
|
||||
* @return void
|
||||
* @throws BuildException
|
||||
*/
|
||||
private function checkPropertyName()
|
||||
{
|
||||
if (is_null($this->propertyName) ||
|
||||
strlen($this->propertyName) === 0) {
|
||||
throw new BuildException('Property name for publishing hashvalue is not set');
|
||||
}
|
||||
}
|
||||
}
|
120
airtime_mvc/library/phing/tasks/ext/FileSizeTask.php
Normal file
120
airtime_mvc/library/phing/tasks/ext/FileSizeTask.php
Normal file
|
@ -0,0 +1,120 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: FileSizeTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
|
||||
/**
|
||||
* fileHash
|
||||
*
|
||||
* Calculate either MD5 or SHA hash value of a specified file and retun the
|
||||
* value in a property
|
||||
*
|
||||
* @author Johan Persson <johan162@gmail.com>
|
||||
* @version $Id: FileSizeTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext
|
||||
*/
|
||||
class FileSizeTask extends Task
|
||||
{
|
||||
/**
|
||||
* Property for File
|
||||
* @var PhingFile file
|
||||
*/
|
||||
private $file;
|
||||
|
||||
/**
|
||||
* Property where the file size will be stored
|
||||
* @var string $property
|
||||
*/
|
||||
private $propertyName = "filesize";
|
||||
|
||||
/**
|
||||
* Which file for calculate the has value of
|
||||
* @param PhingFile $file
|
||||
*/
|
||||
public function setFile($file)
|
||||
{
|
||||
$this->file = $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of the property to use to return the has value
|
||||
* @param $property
|
||||
* @return
|
||||
*/
|
||||
public function setPropertyName($property)
|
||||
{
|
||||
$this->propertyName = $property;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main-Method for the Task
|
||||
*
|
||||
* @return void
|
||||
* @throws BuildException
|
||||
*/
|
||||
public function main()
|
||||
{
|
||||
$this->checkFile();
|
||||
$this->checkPropertyName();
|
||||
|
||||
$size = filesize($this->file);
|
||||
|
||||
if( $size === false ) {
|
||||
throw new BuildException(sprintf('[FileSize] Cannot determine size of file: %s',$this->file));
|
||||
|
||||
}
|
||||
|
||||
// publish hash value
|
||||
$this->project->setProperty($this->propertyName, $size);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* checks file attribute
|
||||
* @return void
|
||||
* @throws BuildException
|
||||
*/
|
||||
private function checkFile()
|
||||
{
|
||||
// check File
|
||||
if ($this->file === null ||
|
||||
strlen($this->file) == 0) {
|
||||
throw new BuildException('[FileSize] You must specify an input file.', $this->file);
|
||||
}
|
||||
|
||||
if( ! is_readable($this->file) ) {
|
||||
throw new BuildException(sprintf('[FileSize] Input file does not exist or is not readable: %s',$this->file));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* checks property attribute
|
||||
* @return void
|
||||
* @throws BuildException
|
||||
*/
|
||||
private function checkPropertyName()
|
||||
{
|
||||
if (is_null($this->propertyName) ||
|
||||
strlen($this->propertyName) === 0) {
|
||||
throw new BuildException('[FileSize] Property name for publishing file size is not set');
|
||||
}
|
||||
}
|
||||
}
|
216
airtime_mvc/library/phing/tasks/ext/FtpDeployTask.php
Normal file
216
airtime_mvc/library/phing/tasks/ext/FtpDeployTask.php
Normal file
|
@ -0,0 +1,216 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: FtpDeployTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
|
||||
/**
|
||||
* FtpDeployTask
|
||||
*
|
||||
* Deploys a set of files to a remote FTP server.
|
||||
*
|
||||
*
|
||||
* Example usage:
|
||||
* <ftpdeploy host="host" port="21" username="user" password="password" dir="public_html" mode="ascii" clearfirst="true">
|
||||
* <fileset dir=".">
|
||||
* <include name="**"/>
|
||||
* <exclude name="phing"/>
|
||||
* <exclude name="build.xml"/>
|
||||
* <exclude name="images/**.png"/>
|
||||
* <exclude name="images/**.gif"/>
|
||||
* <exclude name="images/**.jpg"/>
|
||||
* </fileset>
|
||||
* </ftpdeploy>
|
||||
*
|
||||
* @author Jorrit Schippers <jorrit at ncode dot nl>
|
||||
* @version $Id: FtpDeployTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @since 2.3.1
|
||||
* @package phing.tasks.ext
|
||||
*/
|
||||
class FtpDeployTask extends Task
|
||||
{
|
||||
private $host = null;
|
||||
private $port = 21;
|
||||
private $username = null;
|
||||
private $password = null;
|
||||
private $dir = null;
|
||||
private $filesets;
|
||||
private $completeDirMap;
|
||||
private $mode = FTP_BINARY;
|
||||
private $clearFirst = false;
|
||||
private $passive = false;
|
||||
|
||||
public function __construct() {
|
||||
$this->filesets = array();
|
||||
$this->completeDirMap = array();
|
||||
}
|
||||
|
||||
public function setHost($host) {
|
||||
$this->host = $host;
|
||||
}
|
||||
|
||||
public function setPort($port) {
|
||||
$this->port = (int) $port;
|
||||
}
|
||||
|
||||
public function setUsername($username) {
|
||||
$this->username = $username;
|
||||
}
|
||||
|
||||
public function setPassword($password) {
|
||||
$this->password = $password;
|
||||
}
|
||||
|
||||
public function setDir($dir) {
|
||||
$this->dir = $dir;
|
||||
}
|
||||
|
||||
public function setMode($mode) {
|
||||
switch(strtolower($mode)) {
|
||||
case 'ascii':
|
||||
$this->mode = FTP_ASCII;
|
||||
break;
|
||||
case 'binary':
|
||||
case 'bin':
|
||||
$this->mode = FTP_BINARY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function setPassive($passive)
|
||||
{
|
||||
$this->passive = (bool) $passive;
|
||||
}
|
||||
|
||||
public function setClearFirst($clearFirst) {
|
||||
$this->clearFirst = (bool) $clearFirst;
|
||||
}
|
||||
|
||||
function createFileSet() {
|
||||
$num = array_push($this->filesets, new FileSet());
|
||||
return $this->filesets[$num-1];
|
||||
}
|
||||
|
||||
/**
|
||||
* The init method: check if Net_FTP is available
|
||||
*/
|
||||
public function init() {
|
||||
require_once 'PEAR.php';
|
||||
|
||||
$paths = explode(PATH_SEPARATOR, get_include_path());
|
||||
foreach($paths as $path) {
|
||||
if(file_exists($path.DIRECTORY_SEPARATOR.'Net'.DIRECTORY_SEPARATOR.'FTP.php')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
throw new BuildException('The FTP Deploy task requires the Net_FTP PEAR package.');
|
||||
}
|
||||
|
||||
/**
|
||||
* The main entry point method.
|
||||
*/
|
||||
public function main() {
|
||||
$project = $this->getProject();
|
||||
|
||||
require_once 'Net/FTP.php';
|
||||
$ftp = new Net_FTP($this->host, $this->port);
|
||||
$ret = $ftp->connect();
|
||||
if(@PEAR::isError($ret)) {
|
||||
throw new BuildException('Could not connect to FTP server '.$this->host.' on port '.$this->port.': '.$ret->getMessage());
|
||||
} else {
|
||||
$this->log('Connected to FTP server ' . $this->host . ' on port ' . $this->port, Project::MSG_VERBOSE);
|
||||
}
|
||||
|
||||
$ret = $ftp->login($this->username, $this->password);
|
||||
if(@PEAR::isError($ret)) {
|
||||
throw new BuildException('Could not login to FTP server '.$this->host.' on port '.$this->port.' with username '.$this->username.': '.$ret->getMessage());
|
||||
} else {
|
||||
$this->log('Logged in to FTP server with username ' . $this->username, Project::MSG_VERBOSE);
|
||||
}
|
||||
|
||||
if ($this->passive) {
|
||||
$this->log('Setting passive mode', Project::MSG_INFO);
|
||||
$ret = $ftp->setPassive();
|
||||
if(@PEAR::isError($ret)) {
|
||||
$ftp->disconnect();
|
||||
throw new BuildException('Could not set PASSIVE mode: '.$ret->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// append '/' to the end if necessary
|
||||
$dir = substr($this->dir, -1) == '/' ? $this->dir : $this->dir.'/';
|
||||
|
||||
if($this->clearFirst) {
|
||||
// TODO change to a loop through all files and directories within current directory
|
||||
$this->log('Clearing directory '.$dir, Project::MSG_INFO);
|
||||
$ftp->rm($dir, true);
|
||||
}
|
||||
|
||||
// Create directory just in case
|
||||
$ret = $ftp->mkdir($dir, true);
|
||||
if(@PEAR::isError($ret)) {
|
||||
$ftp->disconnect();
|
||||
throw new BuildException('Could not create directory '.$dir.': '.$ret->getMessage());
|
||||
}
|
||||
|
||||
$ret = $ftp->cd($dir);
|
||||
if(@PEAR::isError($ret)) {
|
||||
$ftp->disconnect();
|
||||
throw new BuildException('Could not change to directory '.$dir.': '.$ret->getMessage());
|
||||
} else {
|
||||
$this->log('Changed directory ' . $dir, Project::MSG_VERBOSE);
|
||||
}
|
||||
|
||||
$fs = FileSystem::getFileSystem();
|
||||
$convert = $fs->getSeparator() == '\\';
|
||||
|
||||
foreach($this->filesets as $fs) {
|
||||
$ds = $fs->getDirectoryScanner($project);
|
||||
$fromDir = $fs->getDir($project);
|
||||
$srcFiles = $ds->getIncludedFiles();
|
||||
$srcDirs = $ds->getIncludedDirectories();
|
||||
foreach($srcDirs as $dirname) {
|
||||
if($convert)
|
||||
$dirname = str_replace('\\', '/', $dirname);
|
||||
$this->log('Will create directory '.$dirname, Project::MSG_VERBOSE);
|
||||
$ret = $ftp->mkdir($dirname, true);
|
||||
if(@PEAR::isError($ret)) {
|
||||
$ftp->disconnect();
|
||||
throw new BuildException('Could not create directory '.$dirname.': '.$ret->getMessage());
|
||||
}
|
||||
}
|
||||
foreach($srcFiles as $filename) {
|
||||
$file = new PhingFile($fromDir->getAbsolutePath(), $filename);
|
||||
if($convert)
|
||||
$filename = str_replace('\\', '/', $filename);
|
||||
$this->log('Will copy '.$file->getCanonicalPath().' to '.$filename, Project::MSG_VERBOSE);
|
||||
$ret = $ftp->put($file->getCanonicalPath(), $filename, true, $this->mode);
|
||||
if(@PEAR::isError($ret)) {
|
||||
$ftp->disconnect();
|
||||
throw new BuildException('Could not deploy file '.$filename.': '.$ret->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$ftp->disconnect();
|
||||
$this->log('Disconnected from FTP server', Project::MSG_VERBOSE);
|
||||
}
|
||||
}
|
||||
?>
|
286
airtime_mvc/library/phing/tasks/ext/HttpRequestTask.php
Normal file
286
airtime_mvc/library/phing/tasks/ext/HttpRequestTask.php
Normal file
|
@ -0,0 +1,286 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: HttpRequestTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
|
||||
/**
|
||||
* A HTTP request task.
|
||||
* Making an HTTP request and try to match the response against an provided
|
||||
* regular expression.
|
||||
*
|
||||
* @package phing.tasks.ext
|
||||
* @author Benjamin Schultz <bschultz@proqrent.de>
|
||||
* @version $Id: HttpRequestTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @since 2.4.1
|
||||
*/
|
||||
class HttpRequestTask extends Task
|
||||
{
|
||||
/**
|
||||
* Holds the request URL
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_url = null;
|
||||
|
||||
/**
|
||||
* Holds the regular expression that should match the response
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_responseRegex = '';
|
||||
|
||||
/**
|
||||
* Whether to enable detailed logging
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_verbose = false;
|
||||
|
||||
/**
|
||||
* Holds additional header data
|
||||
*
|
||||
* @var array<Parameter>
|
||||
*/
|
||||
protected $_headers = array();
|
||||
|
||||
/**
|
||||
* Holds additional config data for HTTP_Request2
|
||||
*
|
||||
* @var array<Parameter>
|
||||
*/
|
||||
protected $_configData = array();
|
||||
|
||||
/**
|
||||
* Holds the authentication user name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_authUser = null;
|
||||
|
||||
/**
|
||||
* Holds the authentication password
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_authPassword = '';
|
||||
|
||||
/**
|
||||
* Holds the authentication scheme
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_authScheme;
|
||||
|
||||
/**
|
||||
* Holds the events that will be logged
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $_observerEvents = array(
|
||||
'connect',
|
||||
'sentHeaders',
|
||||
'sentBodyPart',
|
||||
'receivedHeaders',
|
||||
'receivedBody',
|
||||
'disconnect',
|
||||
);
|
||||
|
||||
/**
|
||||
* Sets the request URL
|
||||
*
|
||||
* @param string $url
|
||||
*/
|
||||
public function setUrl($url)
|
||||
{
|
||||
$this->_url = $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the response regex
|
||||
*
|
||||
* @param string $regex
|
||||
*/
|
||||
public function setResponseRegex($regex)
|
||||
{
|
||||
$this->_responseRegex = $regex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the authentication user name
|
||||
*
|
||||
* @param string $user
|
||||
*/
|
||||
public function setAuthUser($user)
|
||||
{
|
||||
$this->_authUser = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the authentication password
|
||||
*
|
||||
* @param string $password
|
||||
*/
|
||||
public function setAuthPassword($password)
|
||||
{
|
||||
$this->_authPassword = $password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the authentication scheme
|
||||
*
|
||||
* @param string $scheme
|
||||
*/
|
||||
public function setAuthScheme($scheme)
|
||||
{
|
||||
$this->_authScheme = $scheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to enable detailed logging
|
||||
*
|
||||
* @param boolean $verbose
|
||||
*/
|
||||
public function setVerbose($verbose)
|
||||
{
|
||||
$this->_verbose = StringHelper::booleanValue($verbose);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a list of observer events that will be logged
|
||||
* if verbose output is enabled.
|
||||
*
|
||||
* @param string $observerEvents List of observer events
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setObserverEvents($observerEvents)
|
||||
{
|
||||
$this->_observerEvents = array();
|
||||
|
||||
$token = ' ,;';
|
||||
$ext = strtok($observerEvents, $token);
|
||||
|
||||
while ($ext !== false) {
|
||||
$this->_observerEvents[] = $ext;
|
||||
$ext = strtok($token);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an additional header for this task
|
||||
*
|
||||
* @return Parameter The created header
|
||||
*/
|
||||
public function createHeader()
|
||||
{
|
||||
$num = array_push($this->_headers, new Parameter());
|
||||
return $this->_headers[$num-1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a config parameter for this task
|
||||
*
|
||||
* @return Parameter The created parameter
|
||||
*/
|
||||
public function createConfig()
|
||||
{
|
||||
$num = array_push($this->_configData, new Parameter());
|
||||
return $this->_configData[$num-1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the necessary environment for running this task.
|
||||
*
|
||||
* @throws BuildException
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
@include_once 'HTTP/Request2.php';
|
||||
|
||||
if (! class_exists('HTTP_Request2')) {
|
||||
throw new BuildException(
|
||||
'HttpRequestTask depends on HTTP_Request2 being installed '
|
||||
. 'and on include_path.',
|
||||
$this->getLocation()
|
||||
);
|
||||
}
|
||||
|
||||
$this->_authScheme = HTTP_Request2::AUTH_BASIC;
|
||||
|
||||
// Other dependencies that should only be loaded
|
||||
// when class is actually used
|
||||
require_once 'HTTP/Request2/Observer/Log.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the http request
|
||||
*/
|
||||
public function main()
|
||||
{
|
||||
if (!isset($this->_url)) {
|
||||
throw new BuildException("Missing attribute 'url' set");
|
||||
}
|
||||
|
||||
$request = new HTTP_Request2($this->_url);
|
||||
|
||||
// set the authentication data
|
||||
if (!empty($this->_authUser)) {
|
||||
$request->setAuth(
|
||||
$this->_authUser,
|
||||
$this->_authPassword,
|
||||
$this->_authScheme
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($this->_configData as $config) {
|
||||
$request->setConfig($config->getName(), $config->getValue());
|
||||
}
|
||||
|
||||
foreach ($this->_headers as $header) {
|
||||
$request->setHeader($header->getName(), $header->getValue());
|
||||
}
|
||||
|
||||
if ($this->_verbose) {
|
||||
$observer = new HTTP_Request2_Observer_Log();
|
||||
|
||||
// set the events we want to log
|
||||
$observer->events = $this->_observerEvents;
|
||||
|
||||
$request->attach($observer);
|
||||
}
|
||||
|
||||
$response = $request->send();
|
||||
|
||||
if ($this->_responseRegex !== '') {
|
||||
$matches = array();
|
||||
preg_match($this->_responseRegex, $response->getBody(), $matches);
|
||||
|
||||
if (count($matches) === 0) {
|
||||
throw new BuildException(
|
||||
'The received response body did not match the '
|
||||
. 'given regular expression'
|
||||
);
|
||||
} else {
|
||||
$this->log('The response body matched the provided regex.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
242
airtime_mvc/library/phing/tasks/ext/JslLintTask.php
Normal file
242
airtime_mvc/library/phing/tasks/ext/JslLintTask.php
Normal file
|
@ -0,0 +1,242 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: JslLintTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
require_once 'phing/util/DataStore.php';
|
||||
|
||||
/**
|
||||
* A Javascript lint task. Checks syntax of Javascript files.
|
||||
* Javascript lint (http://www.javascriptlint.com) must be in the system path.
|
||||
* This class is based on Knut Urdalen's PhpLintTask.
|
||||
*
|
||||
* @author Stefan Priebsch <stefan.priebsch@e-novative.de>
|
||||
* @version $Id: JslLintTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext
|
||||
*/
|
||||
class JslLintTask extends Task
|
||||
{
|
||||
protected $file; // the source file (from xml attribute)
|
||||
protected $filesets = array(); // all fileset objects assigned to this task
|
||||
|
||||
protected $showWarnings = true;
|
||||
protected $haltOnFailure = false;
|
||||
protected $hasErrors = false;
|
||||
private $badFiles = array();
|
||||
|
||||
private $cache = null;
|
||||
private $conf = null;
|
||||
|
||||
private $executable = "jsl";
|
||||
|
||||
/**
|
||||
* Sets the flag if warnings should be shown
|
||||
* @param boolean $show
|
||||
*/
|
||||
public function setShowWarnings($show) {
|
||||
$this->showWarnings = StringHelper::booleanValue($show);
|
||||
}
|
||||
|
||||
/**
|
||||
* The haltonfailure property
|
||||
* @param boolean $aValue
|
||||
*/
|
||||
public function setHaltOnFailure($aValue) {
|
||||
$this->haltOnFailure = $aValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* File to be performed syntax check on
|
||||
* @param PhingFile $file
|
||||
*/
|
||||
public function setFile(PhingFile $file) {
|
||||
$this->file = $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to store last-modified times in cache
|
||||
*
|
||||
* @param PhingFile $file
|
||||
*/
|
||||
public function setCacheFile(PhingFile $file)
|
||||
{
|
||||
$this->cache = new DataStore($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* jsl config file
|
||||
*
|
||||
* @param PhingFile $file
|
||||
*/
|
||||
public function setConfFile(PhingFile $file)
|
||||
{
|
||||
$this->conf = $file;
|
||||
}
|
||||
|
||||
public function setExecutable($path){
|
||||
$this->executable = $path;
|
||||
}
|
||||
|
||||
public function getExecutable(){
|
||||
return $this->executable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Nested creator, creates a FileSet for this task
|
||||
*
|
||||
* @return FileSet The created fileset object
|
||||
*/
|
||||
function createFileSet() {
|
||||
$num = array_push($this->filesets, new FileSet());
|
||||
return $this->filesets[$num-1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute lint check against PhingFile or a FileSet
|
||||
*/
|
||||
public function main() {
|
||||
if(!isset($this->file) and count($this->filesets) == 0) {
|
||||
throw new BuildException("Missing either a nested fileset or attribute 'file' set");
|
||||
}
|
||||
|
||||
exec($this->executable, $output);
|
||||
if (!preg_match('/JavaScript\sLint/', implode('', $output))) throw new BuildException('Javascript Lint not found');
|
||||
|
||||
if($this->file instanceof PhingFile) {
|
||||
$this->lint($this->file->getPath());
|
||||
} else { // process filesets
|
||||
$project = $this->getProject();
|
||||
foreach($this->filesets as $fs) {
|
||||
$ds = $fs->getDirectoryScanner($project);
|
||||
$files = $ds->getIncludedFiles();
|
||||
$dir = $fs->getDir($this->project)->getPath();
|
||||
foreach($files as $file) {
|
||||
$this->lint($dir.DIRECTORY_SEPARATOR.$file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->haltOnFailure && $this->hasErrors) throw new BuildException('Syntax error(s) in JS files:' .implode(', ',$this->badFiles));
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the actual syntax check
|
||||
*
|
||||
* @param string $file
|
||||
* @return void
|
||||
*/
|
||||
protected function lint($file)
|
||||
{
|
||||
$command = $this->executable . ' -output-format ' . escapeshellarg('file:__FILE__;line:__LINE__;message:__ERROR__') . ' ';
|
||||
|
||||
if (isset($this->conf)) {
|
||||
$command .= '-conf ' . $this->conf->getPath() . ' ';
|
||||
}
|
||||
|
||||
$command .= '-process ';
|
||||
|
||||
if(file_exists($file))
|
||||
{
|
||||
if(is_readable($file))
|
||||
{
|
||||
if ($this->cache)
|
||||
{
|
||||
$lastmtime = $this->cache->get($file);
|
||||
|
||||
if ($lastmtime >= filemtime($file))
|
||||
{
|
||||
$this->log("Not linting '" . $file . "' due to cache", Project::MSG_DEBUG);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$messages = array();
|
||||
exec($command.'"'.$file.'"', $messages);
|
||||
|
||||
$summary = $messages[sizeof($messages) - 1];
|
||||
|
||||
preg_match('/(\d+)\serror/', $summary, $matches);
|
||||
$errorCount = $matches[1];
|
||||
|
||||
preg_match('/(\d+)\swarning/', $summary, $matches);
|
||||
$warningCount = $matches[1];
|
||||
|
||||
$errors = array();
|
||||
$warnings = array();
|
||||
if ($errorCount > 0 || $warningCount > 0) {
|
||||
$last = false;
|
||||
foreach ($messages as $message) {
|
||||
$matches = array();
|
||||
if (preg_match('/^(\.*)\^$/', $message)) {
|
||||
$column = strlen($message);
|
||||
if ($last == 'error') {
|
||||
$errors[count($errors) - 1]['column'] = $column;
|
||||
} else if ($last == 'warning') {
|
||||
$warnings[count($warnings) - 1]['column'] = $column;
|
||||
}
|
||||
$last = false;
|
||||
}
|
||||
if (!preg_match('/^file:(.+);line:(\d+);message:(.+)$/', $message, $matches)) continue;
|
||||
$msg = $matches[3];
|
||||
$data = array('filename' => $matches[1], 'line' => $matches[2], 'message' => $msg);
|
||||
if (preg_match('/^.*error:.+$/i', $msg)) {
|
||||
$errors[] = $data;
|
||||
$last = 'error';
|
||||
} else if (preg_match('/^.*warning:.+$/i', $msg)) {
|
||||
$warnings[] = $data;
|
||||
$last = 'warning';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($this->showWarnings && $warningCount > 0)
|
||||
{
|
||||
$this->log($file . ': ' . $warningCount . ' warnings detected', Project::MSG_WARN);
|
||||
foreach ($warnings as $warning) {
|
||||
$this->log('- line ' . $warning['line'] . (isset($warning['column']) ? ' column ' . $warning['column'] : '') . ': ' . $warning['message'], Project::MSG_WARN);
|
||||
}
|
||||
}
|
||||
|
||||
if($errorCount > 0)
|
||||
{
|
||||
$this->log($file . ': ' . $errorCount . ' errors detected', Project::MSG_ERR);
|
||||
foreach ($errors as $error) {
|
||||
$this->log('- line ' . $error['line'] . (isset($error['column']) ? ' column ' . $error['column'] : '') . ': ' . $error['message'], Project::MSG_ERR);
|
||||
}
|
||||
$this->badFiles[] = $file;
|
||||
$this->hasErrors = true;
|
||||
} else if (!$this->showWarnings || $warningCount == 0) {
|
||||
$this->log($file . ': No syntax errors detected', Project::MSG_INFO);
|
||||
}
|
||||
|
||||
if ($this->cache)
|
||||
{
|
||||
$this->cache->put($file, filemtime($file));
|
||||
}
|
||||
} else {
|
||||
throw new BuildException('Permission denied: '.$file);
|
||||
}
|
||||
} else {
|
||||
throw new BuildException('File not found: '.$file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
77
airtime_mvc/library/phing/tasks/ext/MailTask.php
Normal file
77
airtime_mvc/library/phing/tasks/ext/MailTask.php
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: MailTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
include_once 'phing/Task.php';
|
||||
|
||||
/**
|
||||
* Send a message by mail()
|
||||
*
|
||||
* <mail to="user@example.org" subject="build complete">The build process is a success...</mail>
|
||||
*
|
||||
* @author Francois Harvey at SecuriWeb (http://www.securiweb.net)
|
||||
* @version $Id: MailTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext
|
||||
*/
|
||||
class MailTask extends Task {
|
||||
|
||||
protected $recipient;
|
||||
|
||||
protected $subject;
|
||||
|
||||
protected $msg;
|
||||
|
||||
function main() {
|
||||
$this->log('Sending mail to ' . $this->recipient );
|
||||
mail($this->recipient, $this->subject, $this->msg);
|
||||
}
|
||||
|
||||
/** setter for message */
|
||||
function setMsg($msg) {
|
||||
$this->setMessage($msg);
|
||||
}
|
||||
|
||||
/** alias setter */
|
||||
function setMessage($msg) {
|
||||
$this->msg = (string) $msg;
|
||||
}
|
||||
|
||||
/** setter for subject **/
|
||||
function setSubject($subject) {
|
||||
$this->subject = (string) $subject;
|
||||
}
|
||||
|
||||
/** setter for recipient **/
|
||||
function setRecipient($recipient) {
|
||||
$this->recipient = (string) $recipient;
|
||||
}
|
||||
|
||||
/** alias for recipient **/
|
||||
function setTo($recipient) {
|
||||
$this->recipient = (string) $recipient;
|
||||
}
|
||||
|
||||
/** Supporting the <mail>Message</mail> syntax. */
|
||||
function addText($msg)
|
||||
{
|
||||
$this->msg = (string) $msg;
|
||||
}
|
||||
}
|
||||
|
343
airtime_mvc/library/phing/tasks/ext/ManifestTask.php
Normal file
343
airtime_mvc/library/phing/tasks/ext/ManifestTask.php
Normal file
|
@ -0,0 +1,343 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: ManifestTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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";
|
||||
require_once 'phing/system/io/PhingFile.php';
|
||||
|
||||
/**
|
||||
* ManifestTask
|
||||
*
|
||||
* Generates a simple Manifest file with optional checksums.
|
||||
*
|
||||
*
|
||||
* Manifest schema:
|
||||
* ...
|
||||
* path/to/file CHECKSUM [CHECKSUM2] [CHECKSUM3]
|
||||
* path/to/secondfile CHECKSUM [CHECKSUM2] [CHECKSUM3]
|
||||
* ...
|
||||
*
|
||||
* Example usage:
|
||||
* <manifest checksum="crc32" file="${dir_build}/Manifest">
|
||||
* <fileset refid="files_build" />
|
||||
* </manifest>
|
||||
*
|
||||
* <manifest checksum="md5,adler32,sha256" file="${dir_build}/Manifest">
|
||||
* <fileset refid="files_build" />
|
||||
* </manifest>
|
||||
*
|
||||
*
|
||||
*
|
||||
* @author David Persson <davidpersson at qeweurope dot org>
|
||||
* @package phing.tasks.ext
|
||||
* @version $Id: ManifestTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @since 2.3.1
|
||||
*/
|
||||
class ManifestTask extends Task
|
||||
{
|
||||
var $taskname = 'manifest';
|
||||
|
||||
/**
|
||||
* Action
|
||||
*
|
||||
* "w" for reading in files from fileSet
|
||||
* and writing manifest
|
||||
*
|
||||
* or
|
||||
*
|
||||
* "r" for reading in files from fileSet
|
||||
* and checking against manifest
|
||||
*
|
||||
* @var string "r" or "w"
|
||||
*/
|
||||
private $action = 'w';
|
||||
|
||||
/**
|
||||
* The target file passed in the buildfile.
|
||||
*/
|
||||
private $destFile = null;
|
||||
|
||||
/**
|
||||
* Holds filesets
|
||||
*
|
||||
* @var array An Array of objects
|
||||
*/
|
||||
private $filesets = array();
|
||||
|
||||
/**
|
||||
* Enable/Disable checksuming or/and select algorithm
|
||||
* true defaults to md5
|
||||
* false disables checksuming
|
||||
* string "md5,sha256,..." enables generation of multiple checksums
|
||||
* string "sha256" generates sha256 checksum only
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
private $checksum = false;
|
||||
|
||||
/**
|
||||
* A string used in hashing method
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $salt = '';
|
||||
|
||||
/**
|
||||
* Holds some data collected during runtime
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $meta = array('totalFileCount' => 0,'totalFileSize' => 0);
|
||||
|
||||
|
||||
/**
|
||||
* The setter for the attribute "file"
|
||||
* This is where the manifest will be written to/read from
|
||||
*
|
||||
* @param string Path to readable file
|
||||
* @return void
|
||||
*/
|
||||
public function setFile(PhingFile $file)
|
||||
{
|
||||
$this->file = $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* The setter for the attribute "checksum"
|
||||
*
|
||||
* @param mixed $mixed
|
||||
* @return void
|
||||
*/
|
||||
public function setChecksum($mixed)
|
||||
{
|
||||
if(is_string($mixed)) {
|
||||
$data = array(strtolower($mixed));
|
||||
|
||||
if(strpos($data[0],',')) {
|
||||
$data = explode(',',$mixed);
|
||||
}
|
||||
|
||||
$this->checksum = $data;
|
||||
|
||||
} elseif($mixed === true) {
|
||||
$this->checksum = array('md5');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The setter for the optional attribute "salt"
|
||||
*
|
||||
* @param string $string
|
||||
* @return void
|
||||
*/
|
||||
public function setSalt($string)
|
||||
{
|
||||
$this->salt = $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Nested creator, creates a FileSet for this task
|
||||
*
|
||||
* @access public
|
||||
* @return object The created fileset object
|
||||
*/
|
||||
public function createFileSet()
|
||||
{
|
||||
$num = array_push($this->filesets, new FileSet());
|
||||
return $this->filesets[$num-1];
|
||||
}
|
||||
|
||||
/**
|
||||
* The init method: Do init steps.
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
// nothing to do here
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegate the work
|
||||
*/
|
||||
public function main()
|
||||
{
|
||||
$this->validateAttributes();
|
||||
|
||||
if($this->action == 'w') {
|
||||
$this->write();
|
||||
|
||||
} elseif($this->action == 'r') {
|
||||
$this->read();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates Manifest file
|
||||
* Writes to $this->file
|
||||
*
|
||||
* @throws BuildException
|
||||
*/
|
||||
private function write()
|
||||
{
|
||||
$project = $this->getProject();
|
||||
|
||||
if(!touch($this->file->getPath())) {
|
||||
throw new BuildException("Unable to write to ".$this->file->getPath().".");
|
||||
}
|
||||
|
||||
$this->log("Writing to " . $this->file->__toString(), Project::MSG_INFO);
|
||||
|
||||
if(is_array($this->checksum)) {
|
||||
$this->log("Using " . implode(', ',$this->checksum)." for checksuming.", Project::MSG_INFO);
|
||||
}
|
||||
|
||||
foreach($this->filesets as $fs) {
|
||||
|
||||
$dir = $fs->getDir($this->project)->getPath();
|
||||
|
||||
$ds = $fs->getDirectoryScanner($project);
|
||||
$fromDir = $fs->getDir($project);
|
||||
$srcFiles = $ds->getIncludedFiles();
|
||||
$srcDirs = $ds->getIncludedDirectories();
|
||||
|
||||
foreach($ds->getIncludedFiles() as $file_path) {
|
||||
$line = $file_path;
|
||||
if($this->checksum) {
|
||||
foreach($this->checksum as $algo) {
|
||||
if(!$hash = $this->hashFile($dir.'/'.$file_path,$algo)) {
|
||||
throw new BuildException("Hashing $dir/$file_path with $algo failed!");
|
||||
}
|
||||
|
||||
$line .= "\t".$hash;
|
||||
}
|
||||
}
|
||||
$line .= "\n";
|
||||
$manifest[] = $line;
|
||||
$this->log("Adding file ".$file_path,Project::MSG_VERBOSE);
|
||||
$this->meta['totalFileCount'] ++;
|
||||
$this->meta['totalFileSize'] += filesize($dir.'/'.$file_path);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
file_put_contents($this->file,$manifest);
|
||||
|
||||
$this->log("Done. Total files: ".$this->meta['totalFileCount'].". Total file size: ".$this->meta['totalFileSize']." bytes.", Project::MSG_INFO);
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo implement
|
||||
*/
|
||||
private function read()
|
||||
{
|
||||
throw new BuildException("Checking against manifest not yet supported.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper method for hash generation
|
||||
* Automatically selects extension
|
||||
* Falls back to built-in functions
|
||||
*
|
||||
* @link http://www.php.net/mhash
|
||||
* @link http://www.php.net/hash
|
||||
*
|
||||
* @param string $msg The string that should be hashed
|
||||
* @param string $algo Algorithm
|
||||
* @return mixed String on success, false if $algo is not available
|
||||
*/
|
||||
private function hash($msg,$algo)
|
||||
{
|
||||
if(extension_loaded('hash')) {
|
||||
$algo = strtolower($algo);
|
||||
|
||||
if(in_array($algo,hash_algos())) {
|
||||
return hash($algo,$this->salt.$msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(extension_loaded('mhash')) {
|
||||
$algo = strtoupper($algo);
|
||||
|
||||
if(defined('MHASH_'.$algo)) {
|
||||
return mhash('MHASH_'.$algo,$this->salt.$msg);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
switch(strtolower($algo)) {
|
||||
case 'md5':
|
||||
return md5($this->salt.$msg);
|
||||
case 'crc32':
|
||||
return abs(crc32($this->salt.$msg));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hash a files contents
|
||||
* plus it's size an modification time
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $algo
|
||||
* @return mixed String on success, false if $algo is not available
|
||||
*/
|
||||
private function hashFile($file,$algo)
|
||||
{
|
||||
if(!file_exists($file)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$msg = file_get_contents($file).filesize($file).filemtime($file);
|
||||
|
||||
return $this->hash($msg,$algo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates attributes coming in from XML
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
* @throws BuildException
|
||||
*/
|
||||
protected function validateAttributes()
|
||||
{
|
||||
if($this->action != 'r' && $this->action != 'w') {
|
||||
throw new BuildException("'action' attribute has non valid value. Use 'r' or 'w'");
|
||||
}
|
||||
|
||||
if(empty($this->salt)) {
|
||||
$this->log("No salt provided. Specify one with the 'salt' attribute.", Project::MSG_WARN);
|
||||
}
|
||||
|
||||
if (is_null($this->file) && count($this->filesets) === 0) {
|
||||
throw new BuildException("Specify at least sources and destination - a file or a fileset.");
|
||||
}
|
||||
|
||||
if (!is_null($this->file) && $this->file->exists() && $this->file->isDirectory()) {
|
||||
throw new BuildException("Destination file cannot be a directory.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
65
airtime_mvc/library/phing/tasks/ext/PackageAsPathTask.php
Normal file
65
airtime_mvc/library/phing/tasks/ext/PackageAsPathTask.php
Normal file
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* $Id: PackageAsPathTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
|
||||
/**
|
||||
* Convert dot-notation packages to relative paths.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Id: PackageAsPathTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext
|
||||
*/
|
||||
class PackageAsPathTask extends Task {
|
||||
|
||||
/** The package to convert. */
|
||||
protected $pckg;
|
||||
|
||||
/** The value to store the conversion in. */
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Executes the package to patch converstion and stores it
|
||||
* in the user property <code>value</code>.
|
||||
*/
|
||||
public function main()
|
||||
{
|
||||
$this->project->setUserProperty($this->name, strtr($this->pckg, '.', '/'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $pckg the package to convert
|
||||
*/
|
||||
public function setPackage($pckg)
|
||||
{
|
||||
$this->pckg = $pckg;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name the Ant variable to store the path in
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
}
|
279
airtime_mvc/library/phing/tasks/ext/PatchTask.php
Normal file
279
airtime_mvc/library/phing/tasks/ext/PatchTask.php
Normal file
|
@ -0,0 +1,279 @@
|
|||
<?php
|
||||
/**
|
||||
* Patches a file by applying a 'diff' file to it
|
||||
*
|
||||
* Requires "patch" to be on the execution path.
|
||||
*
|
||||
* Based on Apache Ant PatchTask:
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @author Mikhail Krasilnikov <mk@3wstyle>
|
||||
* @version 0.01
|
||||
* @package phing.tasks.ext
|
||||
*/
|
||||
require_once 'phing/Task.php';
|
||||
|
||||
/**
|
||||
* Patches a file by applying a 'diff' file to it
|
||||
*
|
||||
* Requires "patch" to be on the execution path.
|
||||
*
|
||||
* @package phing.tasks.ext
|
||||
*/
|
||||
class PatchTask extends Task
|
||||
{
|
||||
/**
|
||||
* Base command to be executed
|
||||
* @var string
|
||||
*/
|
||||
const CMD = 'patch --batch ';
|
||||
|
||||
/**
|
||||
* File to be patched
|
||||
* @var string
|
||||
*/
|
||||
private $originalFile;
|
||||
|
||||
/**
|
||||
* Patch file
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $patchFile;
|
||||
|
||||
/**
|
||||
* Value for a "-p" option
|
||||
* @var int
|
||||
*/
|
||||
private $strip;
|
||||
|
||||
/**
|
||||
* Command line arguments for patch binary
|
||||
* @var array
|
||||
*/
|
||||
private $cmdArgs = array();
|
||||
|
||||
/**
|
||||
* Halt on error return value from patch invocation.
|
||||
* @var bool
|
||||
*/
|
||||
private $haltOnFailure = false;
|
||||
|
||||
/**
|
||||
* The file containing the diff output
|
||||
*
|
||||
* Required.
|
||||
*
|
||||
* @param string $file File containing the diff output
|
||||
* @return void
|
||||
* @throws BuildException if $file not exists
|
||||
*/
|
||||
public function setPatchFile($file)
|
||||
{
|
||||
if (!is_file($file))
|
||||
throw new BuildException(sprintf('Patchfile %s doesn\'t exist', $file));
|
||||
|
||||
$this->patchFile = $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* The file to patch
|
||||
*
|
||||
* Optional if it can be inferred from the diff file.
|
||||
*
|
||||
* @param string $file File to patch
|
||||
* @return void
|
||||
*/
|
||||
public function setOriginalFile($file)
|
||||
{
|
||||
$this->originalFile = $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* The name of a file to send the output to, instead of patching
|
||||
* the file(s) in place
|
||||
*
|
||||
* Optional.
|
||||
*
|
||||
* @param string $file File to send the output to
|
||||
* @return void
|
||||
*/
|
||||
public function setDestFile($file)
|
||||
{
|
||||
if ($file !== null)
|
||||
$this->cmdArgs []= "--output=$file";
|
||||
}
|
||||
|
||||
/**
|
||||
* Flag to create backups
|
||||
*
|
||||
* Optional, default - false
|
||||
*
|
||||
* @param bool $backups If true create backups
|
||||
* @return void
|
||||
*/
|
||||
public function setBackups($backups)
|
||||
{
|
||||
if ($backups)
|
||||
$this->cmdArgs []= '--backup';
|
||||
}
|
||||
|
||||
/**
|
||||
* Flag to ignore whitespace differences;
|
||||
*
|
||||
* Default - false
|
||||
*
|
||||
* @param bool $ignore If true ignore whitespace differences
|
||||
* @return void
|
||||
*/
|
||||
public function setIgnoreWhiteSpace($ignore)
|
||||
{
|
||||
if ($ignore)
|
||||
$this->cmdArgs []= '--ignore-whitespace';
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip the smallest prefix containing <i>num</i> leading slashes
|
||||
* from filenames.
|
||||
*
|
||||
* patch's <i>--strip</i> option.
|
||||
*
|
||||
* @param int $num number of lines to strip
|
||||
* @return void
|
||||
* @throws BuildException if num is < 0, or other errors
|
||||
*/
|
||||
public function setStrip($num)
|
||||
{
|
||||
if ($num < 0)
|
||||
throw new BuildException('strip has to be >= 0');
|
||||
|
||||
$this->strip = $num;
|
||||
}
|
||||
|
||||
/**
|
||||
* Work silently unless an error occurs
|
||||
*
|
||||
* Optional, default - false
|
||||
* @param bool $flag If true suppress set the -s option on the patch command
|
||||
* @return void
|
||||
*/
|
||||
public function setQuiet($flag)
|
||||
{
|
||||
if ($flag)
|
||||
$this->cmdArgs []= '--silent';
|
||||
}
|
||||
|
||||
/**
|
||||
* Assume patch was created with old and new files swapped
|
||||
*
|
||||
* Optional, default - false
|
||||
*
|
||||
* @param bool $flag If true set the -R option on the patch command
|
||||
* @return void
|
||||
*/
|
||||
public function setReverse($flag)
|
||||
{
|
||||
if ($flag)
|
||||
$this->cmdArgs []= '--reverse';
|
||||
}
|
||||
|
||||
/**
|
||||
* The directory to run the patch command in
|
||||
*
|
||||
* Defaults to the project's base directory.
|
||||
*
|
||||
* @param string $directory Directory to run the patch command in
|
||||
* @return void
|
||||
*/
|
||||
public function setDir($directory)
|
||||
{
|
||||
$this->cmdArgs []= "--directory=$directory";
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignore patches that seem to be reversed or already applied
|
||||
*
|
||||
* @param bool $flag If true set the -N (--forward) option
|
||||
* @return void
|
||||
*/
|
||||
public function setForward($flag)
|
||||
{
|
||||
if ($flag)
|
||||
$this->cmdArgs []= "--forward";
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maximum fuzz factor
|
||||
*
|
||||
* Defaults to 0
|
||||
*
|
||||
* @param string $value Value of a fuzz factor
|
||||
* @return void
|
||||
*/
|
||||
public function setFuzz($value)
|
||||
{
|
||||
$this->cmdArgs []= "--fuzz=$value";
|
||||
}
|
||||
|
||||
/**
|
||||
* If true, stop the build process if the patch command
|
||||
* exits with an error status.
|
||||
*
|
||||
* The default is "false"
|
||||
*
|
||||
* @param bool $value "true" if it should halt, otherwise "false"
|
||||
* @return void
|
||||
*/
|
||||
public function setHaltOnFailure($value)
|
||||
{
|
||||
$this->haltOnFailure = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main task method
|
||||
*
|
||||
* @return void
|
||||
* @throws BuildException when it all goes a bit pear shaped
|
||||
*/
|
||||
public function main()
|
||||
{
|
||||
if ($this->patchFile == null)
|
||||
throw new BuildException('patchfile argument is required');
|
||||
|
||||
// Define patch file
|
||||
$this->cmdArgs []= '-i ' . $this->patchFile;
|
||||
// Define strip factor
|
||||
if ($this->strip != null)
|
||||
$this->cmdArgs []= '--strip=' . $this->strip;
|
||||
// Define original file if specified
|
||||
if ($this->originalFile != null)
|
||||
$this->cmdArgs []= $this->originalFile;
|
||||
|
||||
$cmd = self::CMD . implode(' ', $this->cmdArgs);
|
||||
|
||||
$this->log('Applying patch: ' . $this->patchFile);
|
||||
|
||||
exec($cmd, $output, $exitCode);
|
||||
|
||||
foreach ($output as $line)
|
||||
$this->log($line, Project::MSG_VERBOSE);
|
||||
|
||||
if ($exitCode != 0 && $this->haltOnFailure)
|
||||
throw new BuildException( "Task exited with code $exitCode" );
|
||||
|
||||
}
|
||||
}
|
270
airtime_mvc/library/phing/tasks/ext/PearPackage2Task.php
Normal file
270
airtime_mvc/library/phing/tasks/ext/PearPackage2Task.php
Normal file
|
@ -0,0 +1,270 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: PearPackage2Task.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/tasks/ext/PearPackageTask.php';
|
||||
|
||||
/**
|
||||
* A task to create a PEAR package.xml version 2.0 file.
|
||||
*
|
||||
* This class uses the PEAR_PackageFileManager2 class to perform the work.
|
||||
*
|
||||
* This class is designed to be very flexible -- i.e. account for changes to the package.xml w/o
|
||||
* requiring changes to this class. We've accomplished this by having generic <option> and <mapping>
|
||||
* nested elements. All options are set using PEAR_PackageFileManager2::setOptions().
|
||||
*
|
||||
* The <option> tag is used to set a simple option value.
|
||||
* <code>
|
||||
* <option name="option_name" value="option_value"/>
|
||||
* or <option name="option_name">option_value</option>
|
||||
* </code>
|
||||
*
|
||||
* The <mapping> tag represents a complex data type. You can use nested <element> (and nested <element> with
|
||||
* <element> tags) to represent the full complexity of the structure. Bear in mind that what you are creating
|
||||
* will be mapped to an associative array that will be passed in via PEAR_PackageFileManager2::setOptions().
|
||||
* <code>
|
||||
* <mapping name="option_name">
|
||||
* <element key="key_name" value="key_val"/>
|
||||
* <element key="key_name" value="key_val"/>
|
||||
* </mapping>
|
||||
* </code>
|
||||
*
|
||||
* Here's an over-simple example of how this could be used:
|
||||
* <code>
|
||||
* <pearpkg2 name="phing" dir="${build.src.dir}">
|
||||
* <fileset dir="src">
|
||||
* <include name="**"/>
|
||||
* </fileset>
|
||||
* <option name="outputdirectory" value="./build"/>
|
||||
* <option name="packagefile" value="package2.xml"/>
|
||||
* <option name="packagedirectory" value="./${build.dist.dir}"/>
|
||||
* <option name="baseinstalldir" value="${pkg.prefix}"/>
|
||||
* <option name="channel" value="my.pear-channel.com"/>
|
||||
* <option name="summary" value="${pkg.summary}"/>
|
||||
* <option name="description" value="${pkg.description}"/>
|
||||
* <option name="apiversion" value="${pkg.version}"/>
|
||||
* <option name="apistability" value="beta"/>
|
||||
* <option name="releaseversion" value="${pkg.version}"/>
|
||||
* <option name="releasestability" value="beta"/>
|
||||
* <option name="license" value="none"/>
|
||||
* <option name="phpdep" value="5.0.0"/>
|
||||
* <option name="pearinstallerdep" value="1.4.6"/>
|
||||
* <option name="packagetype" value="php"/>
|
||||
* <option name="notes" value="${pkg.relnotes}"/>
|
||||
* <mapping name="maintainers">
|
||||
* <element>
|
||||
* <element key="handle" value="hlellelid"/>
|
||||
* <element key="name" value="Hans"/>
|
||||
* <element key="email" value="hans@xmpl.org"/>
|
||||
* <element key="role" value="lead"/>
|
||||
* </element>
|
||||
* </mapping>
|
||||
* </pearpkg2>
|
||||
* </code>
|
||||
*
|
||||
* Look at the build.xml in the Phing base directory (assuming you have the full distro / CVS version of Phing) to
|
||||
* see a more complete example of how to call this script.
|
||||
*
|
||||
* @author Stuart Binge <stuart.binge@complinet.com>
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @package phing.tasks.ext
|
||||
* @version $Id: PearPackage2Task.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*/
|
||||
class PearPackage2Task extends PearPackageTask {
|
||||
|
||||
public function init() {
|
||||
include_once 'PEAR/PackageFileManager2.php';
|
||||
if (!class_exists('PEAR_PackageFileManager2')) {
|
||||
throw new BuildException("You must have installed PEAR_PackageFileManager in order to create a PEAR package.xml version 2.0 file.");
|
||||
}
|
||||
}
|
||||
|
||||
protected function setVersion2Options()
|
||||
{
|
||||
$this->pkg->setPackage($this->package);
|
||||
$this->pkg->setDate(strftime('%Y-%m-%d'));
|
||||
$this->pkg->setTime(strftime('%H:%M:%S'));
|
||||
|
||||
$newopts = array();
|
||||
foreach ($this->options as $opt) {
|
||||
switch ($opt->getName()) {
|
||||
case 'summary':
|
||||
$this->pkg->setSummary($opt->getValue());
|
||||
break;
|
||||
|
||||
case 'description':
|
||||
$this->pkg->setDescription($opt->getValue());
|
||||
break;
|
||||
|
||||
case 'uri':
|
||||
$this->pkg->setUri($opt->getValue());
|
||||
break;
|
||||
|
||||
case 'license':
|
||||
$this->pkg->setLicense($opt->getValue());
|
||||
break;
|
||||
|
||||
case 'channel':
|
||||
$this->pkg->setChannel($opt->getValue());
|
||||
break;
|
||||
|
||||
case 'apiversion':
|
||||
$this->pkg->setAPIVersion($opt->getValue());
|
||||
break;
|
||||
|
||||
case 'releaseversion':
|
||||
$this->pkg->setReleaseVersion($opt->getValue());
|
||||
break;
|
||||
|
||||
case 'releasestability':
|
||||
$this->pkg->setReleaseStability($opt->getValue());
|
||||
break;
|
||||
|
||||
case 'apistability':
|
||||
$this->pkg->setAPIStability($opt->getValue());
|
||||
break;
|
||||
|
||||
case 'notes':
|
||||
$this->pkg->setNotes($opt->getValue());
|
||||
break;
|
||||
|
||||
case 'packagetype':
|
||||
$this->pkg->setPackageType($opt->getValue());
|
||||
break;
|
||||
|
||||
case 'phpdep':
|
||||
$this->pkg->setPhpDep($opt->getValue());
|
||||
break;
|
||||
|
||||
case 'pearinstallerdep':
|
||||
$this->pkg->setPearinstallerDep($opt->getValue());
|
||||
break;
|
||||
|
||||
default:
|
||||
$newopts[] = $opt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->options = $newopts;
|
||||
|
||||
$newmaps = array();
|
||||
foreach ($this->mappings as $map) {
|
||||
switch ($map->getName()) {
|
||||
case 'deps':
|
||||
$deps = $map->getValue();
|
||||
foreach ($deps as $dep) {
|
||||
$type = isset($dep['optional']) ? 'optional' : 'required';
|
||||
$min = isset($dep['min']) ? $dep['min'] : $dep['version'];
|
||||
$max = isset($dep['max']) ? $dep['max'] : $dep['version'];
|
||||
$rec = isset($dep['recommended']) ? $dep['recommended'] : $dep['version'];
|
||||
$channel = isset($dep['channel']) ? $dep['channel'] : false;
|
||||
$uri = isset($dep['uri']) ? $dep['uri'] : false;
|
||||
|
||||
if (!empty($channel)) {
|
||||
$this->pkg->addPackageDepWithChannel(
|
||||
$type, $dep['name'], $channel, $min, $max, $rec
|
||||
);
|
||||
} elseif (!empty($uri)) {
|
||||
$this->pkg->addPackageDepWithUri(
|
||||
$type, $dep['name'], $uri
|
||||
);
|
||||
}
|
||||
};
|
||||
break;
|
||||
|
||||
case 'extdeps':
|
||||
$deps = $map->getValue();
|
||||
foreach ($deps as $dep) {
|
||||
$type = isset($dep['optional']) ? 'optional' : 'required';
|
||||
$min = isset($dep['min']) ? $dep['min'] : $dep['version'];
|
||||
$max = isset($dep['max']) ? $dep['max'] : $dep['version'];
|
||||
$rec = isset($dep['recommended']) ? $dep['recommended'] : $dep['version'];
|
||||
|
||||
$this->pkg->addExtensionDep(
|
||||
$type, $dep['name'], $min, $max, $rec
|
||||
);
|
||||
};
|
||||
break;
|
||||
|
||||
case 'maintainers':
|
||||
$maintainers = $map->getValue();
|
||||
|
||||
foreach ($maintainers as $maintainer) {
|
||||
if (!isset($maintainer['active'])) {
|
||||
$maintainer['active'] = 'yes';
|
||||
}
|
||||
$this->pkg->addMaintainer(
|
||||
$maintainer['role'],
|
||||
$maintainer['handle'],
|
||||
$maintainer['name'],
|
||||
$maintainer['email'],
|
||||
$maintainer['active']
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'replacements':
|
||||
$replacements = $map->getValue();
|
||||
|
||||
foreach($replacements as $replacement) {
|
||||
$this->pkg->addReplacement(
|
||||
$replacement['path'],
|
||||
$replacement['type'],
|
||||
$replacement['from'],
|
||||
$replacement['to']
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$newmaps[] = $map;
|
||||
}
|
||||
}
|
||||
$this->mappings = $newmaps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main entry point.
|
||||
* @return void
|
||||
*/
|
||||
public function main()
|
||||
{
|
||||
if ($this->dir === null) {
|
||||
throw new BuildException("You must specify the \"dir\" attribute for PEAR package 2 task.");
|
||||
}
|
||||
|
||||
if ($this->package === null) {
|
||||
throw new BuildException("You must specify the \"name\" attribute for PEAR package 2 task.");
|
||||
}
|
||||
|
||||
$this->pkg = new PEAR_PackageFileManager2();
|
||||
|
||||
$this->setVersion2Options();
|
||||
$this->setOptions();
|
||||
|
||||
$this->pkg->addRelease();
|
||||
$this->pkg->generateContents();
|
||||
$e = $this->pkg->writePackageFile();
|
||||
if (PEAR::isError($e)) {
|
||||
throw new BuildException("Unable to write package file.", new Exception($e->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
427
airtime_mvc/library/phing/tasks/ext/PearPackageTask.php
Normal file
427
airtime_mvc/library/phing/tasks/ext/PearPackageTask.php
Normal file
|
@ -0,0 +1,427 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: PearPackageTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/tasks/system/MatchingTask.php';
|
||||
include_once 'phing/types/FileSet.php';
|
||||
|
||||
/**
|
||||
* A task to create PEAR package.xml file.
|
||||
*
|
||||
* This class uses the PEAR_PackageFileMaintainer class to perform the work.
|
||||
*
|
||||
* This class is designed to be very flexible -- i.e. account for changes to the package.xml w/o
|
||||
* requiring changes to this class. We've accomplished this by having generic <option> and <mapping>
|
||||
* nested elements. All options are set using PEAR_PackageFileMaintainer::setOptions().
|
||||
*
|
||||
* The <option> tag is used to set a simple option value.
|
||||
* <code>
|
||||
* <option name="option_name" value="option_value"/>
|
||||
* or <option name="option_name">option_value</option>
|
||||
* </code>
|
||||
*
|
||||
* The <mapping> tag represents a complex data type. You can use nested <element> (and nested <element> with
|
||||
* <element> tags) to represent the full complexity of the structure. Bear in mind that what you are creating
|
||||
* will be mapped to an associative array that will be passed in via PEAR_PackageFileMaintainer::setOptions().
|
||||
* <code>
|
||||
* <mapping name="option_name">
|
||||
* <element key="key_name" value="key_val"/>
|
||||
* <element key="key_name" value="key_val"/>
|
||||
* </mapping>
|
||||
* </code>
|
||||
*
|
||||
* Here's an over-simple example of how this could be used:
|
||||
* <code>
|
||||
* <pearpkg name="phing" dir="${build.src.dir}" destFile="${build.base.dir}/package.xml">
|
||||
* <fileset>
|
||||
* <include name="**"/>
|
||||
* </fileset>
|
||||
* <option name="notes">Sample release notes here.</option>
|
||||
* <option name="description">Package description</option>
|
||||
* <option name="summary">Short description</option>
|
||||
* <option name="version" value="2.0.0b1"/>
|
||||
* <option name="state" value="beta"/>
|
||||
* <mapping name="maintainers">
|
||||
* <element>
|
||||
* <element key="handle" value="hlellelid"/>
|
||||
* <element key="name" value="Hans"/>
|
||||
* <element key="email" value="hans@xmpl.org"/>
|
||||
* <element key="role" value="lead"/>
|
||||
* </element>
|
||||
* </mapping>
|
||||
* </pearpkg>
|
||||
* </code>
|
||||
*
|
||||
* Look at the build.xml in the Phing base directory (assuming you have the full distro / CVS version of Phing) to
|
||||
* see a more complete example of how to call this script.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @package phing.tasks.ext
|
||||
* @version $Id: PearPackageTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*/
|
||||
class PearPackageTask extends MatchingTask {
|
||||
|
||||
/** */
|
||||
protected $package;
|
||||
|
||||
/** Base directory for reading files. */
|
||||
protected $dir;
|
||||
|
||||
/** Package file */
|
||||
private $packageFile;
|
||||
|
||||
/** @var array FileSet[] */
|
||||
private $filesets = array();
|
||||
|
||||
/** @var PEAR_PackageFileManager */
|
||||
protected $pkg;
|
||||
|
||||
private $preparedOptions = array();
|
||||
|
||||
/** @var array PearPkgOption[] */
|
||||
protected $options = array();
|
||||
|
||||
/** Nested <mapping> (complex options) types. */
|
||||
protected $mappings = array();
|
||||
|
||||
public function init() {
|
||||
include_once 'PEAR/PackageFileManager.php';
|
||||
if (!class_exists('PEAR_PackageFileManager')) {
|
||||
throw new BuildException("You must have installed PEAR_PackageFileManager in order to create a PEAR package.xml file.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets PEAR package.xml options, based on class properties.
|
||||
* @return void
|
||||
*/
|
||||
protected function setOptions() {
|
||||
|
||||
// 1) first prepare/populate options
|
||||
$this->populateOptions();
|
||||
|
||||
// 2) make any final adjustments (this could move into populateOptions() also)
|
||||
|
||||
// default PEAR basedir would be the name of the package (e.g."phing")
|
||||
if (!isset($this->preparedOptions['baseinstalldir'])) {
|
||||
$this->preparedOptions['baseinstalldir'] = $this->package;
|
||||
}
|
||||
|
||||
// unless filelistgenerator has been overridden, we use Phing FileSet generator
|
||||
if (!isset($this->preparedOptions['filelistgenerator'])) {
|
||||
if (empty($this->filesets)) {
|
||||
throw new BuildException("You must use a <fileset> tag to specify the files to include in the package.xml");
|
||||
}
|
||||
$this->preparedOptions['filelistgenerator'] = 'Fileset';
|
||||
$this->preparedOptions['usergeneratordir'] = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'pearpackage';
|
||||
// Some PHING-specific options needed by our Fileset reader
|
||||
$this->preparedOptions['phing_project'] = $this->project;
|
||||
$this->preparedOptions['phing_filesets'] = $this->filesets;
|
||||
} elseif ($this->preparedOptions['filelistgeneragor'] != 'Fileset' && !empty($this->filesets)) {
|
||||
throw new BuildException("You cannot use <fileset> element if you have specified the \"filelistgenerator\" option.");
|
||||
}
|
||||
|
||||
// 3) Set the options
|
||||
|
||||
// No need for excessive validation here, since the PEAR class will do its own
|
||||
// validation & return errors
|
||||
$e = $this->pkg->setOptions($this->preparedOptions);
|
||||
|
||||
if (PEAR::isError($e)) {
|
||||
throw new BuildException("Unable to set options.", new Exception($e->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixes the boolean in optional dependencies
|
||||
*/
|
||||
private function fixDeps($deps)
|
||||
{
|
||||
foreach (array_keys($deps) as $dep)
|
||||
{
|
||||
if (isset($deps[$dep]['optional']) && $deps[$dep]['optional'])
|
||||
{
|
||||
$deps[$dep]['optional'] = "yes";
|
||||
}
|
||||
}
|
||||
|
||||
return $deps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the options that are set via attributes and the nested tags to the options array.
|
||||
*/
|
||||
private function populateOptions() {
|
||||
|
||||
// These values could be overridden if explicitly defined using nested tags
|
||||
$this->preparedOptions['package'] = $this->package;
|
||||
$this->preparedOptions['packagedirectory'] = $this->dir->getAbsolutePath();
|
||||
|
||||
if ($this->packageFile !== null) {
|
||||
// create one w/ full path
|
||||
$f = new PhingFile($this->packageFile->getAbsolutePath());
|
||||
$this->preparedOptions['packagefile'] = $f->getName();
|
||||
// must end in trailing slash
|
||||
$this->preparedOptions['outputdirectory'] = $f->getParent() . DIRECTORY_SEPARATOR;
|
||||
$this->log("Creating package file: " . $f->__toString(), Project::MSG_INFO);
|
||||
} else {
|
||||
$this->log("Creating [default] package.xml file in base directory.", Project::MSG_INFO);
|
||||
}
|
||||
|
||||
// converts option objects and mapping objects into
|
||||
// key => value options that can be passed to PEAR_PackageFileManager
|
||||
|
||||
foreach($this->options as $opt) {
|
||||
$this->preparedOptions[ $opt->getName() ] = $opt->getValue(); //no arrays yet. preg_split('/\s*,\s*/', $opt->getValue());
|
||||
}
|
||||
|
||||
foreach($this->mappings as $map) {
|
||||
$value = $map->getValue(); // getValue returns complex value
|
||||
|
||||
if ($map->getName() == 'deps')
|
||||
{
|
||||
$value = $this->fixDeps($value);
|
||||
}
|
||||
|
||||
$this->preparedOptions[ $map->getName() ] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Main entry point.
|
||||
* @return void
|
||||
*/
|
||||
public function main() {
|
||||
|
||||
if ($this->dir === null) {
|
||||
throw new BuildException("You must specify the \"dir\" attribute for PEAR package task.");
|
||||
}
|
||||
|
||||
if ($this->package === null) {
|
||||
throw new BuildException("You must specify the \"name\" attribute for PEAR package task.");
|
||||
}
|
||||
|
||||
$this->pkg = new PEAR_PackageFileManager();
|
||||
|
||||
$this->setOptions();
|
||||
|
||||
$e = $this->pkg->writePackageFile();
|
||||
if (PEAR::isError($e)) {
|
||||
throw new BuildException("Unable to write package file.", new Exception($e->getMessage()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by the PEAR_PackageFileManager_PhingFileSet lister.
|
||||
* @return array FileSet[]
|
||||
*/
|
||||
public function getFileSets() {
|
||||
return $this->filesets;
|
||||
}
|
||||
|
||||
// -------------------------------
|
||||
// Set properties from XML
|
||||
// -------------------------------
|
||||
|
||||
/**
|
||||
* Nested creator, creates a FileSet for this task
|
||||
*
|
||||
* @return FileSet The created fileset object
|
||||
*/
|
||||
function createFileSet() {
|
||||
$num = array_push($this->filesets, new FileSet());
|
||||
return $this->filesets[$num-1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set "package" property from XML.
|
||||
* @see setName()
|
||||
* @param string $v
|
||||
* @return void
|
||||
*/
|
||||
public function setPackage($v) {
|
||||
$this->package = $v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets "dir" property from XML.
|
||||
* @param PhingFile $f
|
||||
* @return void
|
||||
*/
|
||||
public function setDir(PhingFile $f) {
|
||||
$this->dir = $f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets "name" property from XML.
|
||||
* @param string $v
|
||||
* @return void
|
||||
*/
|
||||
public function setName($v) {
|
||||
$this->package = $v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the file to use for generated package.xml
|
||||
*/
|
||||
public function setDestFile(PhingFile $f) {
|
||||
$this->packageFile = $f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles nested generic <option> elements.
|
||||
*/
|
||||
function createOption() {
|
||||
$o = new PearPkgOption();
|
||||
$this->options[] = $o;
|
||||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles nested generic <option> elements.
|
||||
*/
|
||||
function createMapping() {
|
||||
$o = new PearPkgMapping();
|
||||
$this->mappings[] = $o;
|
||||
return $o;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generic option class is used for non-complex options.
|
||||
*
|
||||
* @package phing.tasks.ext
|
||||
*/
|
||||
class PearPkgOption {
|
||||
|
||||
private $name;
|
||||
private $value;
|
||||
|
||||
public function setName($v) { $this->name = $v; }
|
||||
public function getName() { return $this->name; }
|
||||
|
||||
public function setValue($v) { $this->value = $v; }
|
||||
public function getValue() { return $this->value; }
|
||||
public function addText($txt) { $this->value = trim($txt); }
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles complex options <mapping> elements which are hashes (assoc arrays).
|
||||
*
|
||||
* @package phing.tasks.ext
|
||||
*/
|
||||
class PearPkgMapping {
|
||||
|
||||
private $name;
|
||||
private $elements = array();
|
||||
|
||||
public function setName($v) {
|
||||
$this->name = $v;
|
||||
}
|
||||
|
||||
public function getName() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function createElement() {
|
||||
$e = new PearPkgMappingElement();
|
||||
$this->elements[] = $e;
|
||||
return $e;
|
||||
}
|
||||
|
||||
public function getElements() {
|
||||
return $this->elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the PHP hash or array of hashes (etc.) that this mapping represents.
|
||||
* @return array
|
||||
*/
|
||||
public function getValue() {
|
||||
$value = array();
|
||||
foreach($this->getElements() as $el) {
|
||||
if ($el->getKey() !== null) {
|
||||
$value[ $el->getKey() ] = $el->getValue();
|
||||
} else {
|
||||
$value[] = $el->getValue();
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sub-element of <mapping>.
|
||||
*
|
||||
* @package phing.tasks.ext
|
||||
*/
|
||||
class PearPkgMappingElement {
|
||||
|
||||
private $key;
|
||||
private $value;
|
||||
private $elements = array();
|
||||
|
||||
public function setKey($v) {
|
||||
$this->key = $v;
|
||||
}
|
||||
|
||||
public function getKey() {
|
||||
return $this->key;
|
||||
}
|
||||
|
||||
public function setValue($v) {
|
||||
$this->value = $v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns either the simple value or
|
||||
* the calculated value (array) of nested elements.
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValue() {
|
||||
if (!empty($this->elements)) {
|
||||
$value = array();
|
||||
foreach($this->elements as $el) {
|
||||
if ($el->getKey() !== null) {
|
||||
$value[ $el->getKey() ] = $el->getValue();
|
||||
} else {
|
||||
$value[] = $el->getValue();
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
} else {
|
||||
return $this->value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles nested <element> tags.
|
||||
*/
|
||||
public function createElement() {
|
||||
$e = new PearPkgMappingElement();
|
||||
$this->elements[] = $e;
|
||||
return $e;
|
||||
}
|
||||
|
||||
}
|
600
airtime_mvc/library/phing/tasks/ext/PhpCodeSnifferTask.php
Normal file
600
airtime_mvc/library/phing/tasks/ext/PhpCodeSnifferTask.php
Normal file
|
@ -0,0 +1,600 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: PhpCodeSnifferTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
|
||||
/**
|
||||
* A PHP code sniffer task. Checking the style of one or more PHP source files.
|
||||
*
|
||||
* @author Dirk Thomas <dirk.thomas@4wdmedia.de>
|
||||
* @version $Id: PhpCodeSnifferTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext
|
||||
*/
|
||||
class PhpCodeSnifferTask extends Task {
|
||||
|
||||
protected $file; // the source file (from xml attribute)
|
||||
protected $filesets = array(); // all fileset objects assigned to this task
|
||||
|
||||
// parameters for php code sniffer
|
||||
protected $standard = 'Generic';
|
||||
protected $sniffs = array();
|
||||
protected $showWarnings = true;
|
||||
protected $showSources = false;
|
||||
protected $reportWidth = 80;
|
||||
protected $verbosity = 0;
|
||||
protected $tabWidth = 0;
|
||||
protected $allowedFileExtensions = array('php');
|
||||
protected $ignorePatterns = false;
|
||||
protected $noSubdirectories = false;
|
||||
protected $configData = array();
|
||||
|
||||
// parameters to customize output
|
||||
protected $showSniffs = false;
|
||||
protected $format = 'default';
|
||||
protected $formatters = array();
|
||||
|
||||
/**
|
||||
* Holds the type of the doc generator
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $docGenerator = '';
|
||||
|
||||
/**
|
||||
* Holds the outfile for the documentation
|
||||
*
|
||||
* @var PhingFile
|
||||
*/
|
||||
protected $docFile = null;
|
||||
|
||||
private $haltonerror = false;
|
||||
private $haltonwarning = false;
|
||||
|
||||
/**
|
||||
* Load the necessary environment for running PHP_CodeSniffer.
|
||||
*
|
||||
* @throws BuildException
|
||||
* @return void
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
/**
|
||||
* Determine PHP_CodeSniffer version number
|
||||
*/
|
||||
preg_match('/\d\.\d\.\d/', shell_exec('phpcs --version'), $version);
|
||||
|
||||
if (version_compare($version[0], '1.2.2') < 0) {
|
||||
throw new BuildException(
|
||||
'PhpCodeSnifferTask requires PHP_CodeSniffer version >= 1.2.2',
|
||||
$this->getLocation()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* File to be performed syntax check on
|
||||
* @param PhingFile $file
|
||||
*/
|
||||
public function setFile(PhingFile $file) {
|
||||
$this->file = $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Nested creator, creates a FileSet for this task
|
||||
*
|
||||
* @return FileSet The created fileset object
|
||||
*/
|
||||
function createFileSet() {
|
||||
$num = array_push($this->filesets, new FileSet());
|
||||
return $this->filesets[$num-1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the coding standard to test for
|
||||
*
|
||||
* @param string $standard The coding standard
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setStandard($standard)
|
||||
{
|
||||
if (!class_exists('PHP_CodeSniffer')) {
|
||||
include_once 'PHP/CodeSniffer.php';
|
||||
}
|
||||
|
||||
if (PHP_CodeSniffer::isInstalledStandard($standard) === false) {
|
||||
// They didn't select a valid coding standard, so help them
|
||||
// out by letting them know which standards are installed.
|
||||
$installedStandards = PHP_CodeSniffer::getInstalledStandards();
|
||||
$numStandards = count($installedStandards);
|
||||
$errMsg = '';
|
||||
|
||||
if ($numStandards === 0) {
|
||||
$errMsg = 'No coding standards are installed.';
|
||||
} else {
|
||||
$lastStandard = array_pop($installedStandards);
|
||||
|
||||
if ($numStandards === 1) {
|
||||
$errMsg = 'The only coding standard installed is ' . $lastStandard;
|
||||
} else {
|
||||
$standardList = implode(', ', $installedStandards);
|
||||
$standardList .= ' and ' . $lastStandard;
|
||||
$errMsg = 'The installed coding standards are ' . $standardList;
|
||||
}
|
||||
}
|
||||
|
||||
throw new BuildException(
|
||||
'ERROR: the "' . $standard . '" coding standard is not installed. ' . $errMsg,
|
||||
$this->getLocation()
|
||||
);
|
||||
}
|
||||
|
||||
$this->standard = $standard;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sniffs which the standard should be restricted to
|
||||
* @param string $sniffs
|
||||
*/
|
||||
public function setSniffs($sniffs)
|
||||
{
|
||||
$token = ' ,;';
|
||||
$sniff = strtok($sniffs, $token);
|
||||
while ($sniff !== false) {
|
||||
$this->sniffs[] = $sniff;
|
||||
$sniff = strtok($token);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type of the doc generator
|
||||
*
|
||||
* @param string $generator HTML or Text
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDocGenerator($generator)
|
||||
{
|
||||
$this->docGenerator = $generator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the outfile for the documentation
|
||||
*
|
||||
* @param PhingFile $file The outfile for the doc
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDocFile(PhingFile $file)
|
||||
{
|
||||
$this->docFile = $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the flag if warnings should be shown
|
||||
* @param boolean $show
|
||||
*/
|
||||
public function setShowWarnings($show)
|
||||
{
|
||||
$this->showWarnings = StringHelper::booleanValue($show);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the flag if sources should be shown
|
||||
*
|
||||
* @param boolean $show Whether to show sources or not
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setShowSources($show)
|
||||
{
|
||||
$this->showSources = StringHelper::booleanValue($show);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the width of the report
|
||||
*
|
||||
* @param int $width How wide the screen reports should be.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setReportWidth($width)
|
||||
{
|
||||
$this->reportWidth = (int) $width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the verbosity level
|
||||
* @param int $level
|
||||
*/
|
||||
public function setVerbosity($level)
|
||||
{
|
||||
$this->verbosity = (int)$level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the tab width to replace tabs with spaces
|
||||
* @param int $width
|
||||
*/
|
||||
public function setTabWidth($width)
|
||||
{
|
||||
$this->tabWidth = (int)$width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the allowed file extensions when using directories instead of specific files
|
||||
* @param array $extensions
|
||||
*/
|
||||
public function setAllowedFileExtensions($extensions)
|
||||
{
|
||||
$this->allowedFileExtensions = array();
|
||||
$token = ' ,;';
|
||||
$ext = strtok($extensions, $token);
|
||||
while ($ext !== false) {
|
||||
$this->allowedFileExtensions[] = $ext;
|
||||
$ext = strtok($token);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the ignore patterns to skip files when using directories instead of specific files
|
||||
* @param array $extensions
|
||||
*/
|
||||
public function setIgnorePatterns($patterns)
|
||||
{
|
||||
$this->ignorePatterns = array();
|
||||
$token = ' ,;';
|
||||
$pattern = strtok($patterns, $token);
|
||||
while ($pattern !== false) {
|
||||
$this->ignorePatterns[] = $pattern;
|
||||
$pattern = strtok($token);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the flag if subdirectories should be skipped
|
||||
* @param boolean $subdirectories
|
||||
*/
|
||||
public function setNoSubdirectories($subdirectories)
|
||||
{
|
||||
$this->noSubdirectories = StringHelper::booleanValue($subdirectories);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a config parameter for this task
|
||||
*
|
||||
* @return Parameter The created parameter
|
||||
*/
|
||||
public function createConfig() {
|
||||
$num = array_push($this->configData, new Parameter());
|
||||
return $this->configData[$num-1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the flag if the used sniffs should be listed
|
||||
* @param boolean $show
|
||||
*/
|
||||
public function setShowSniffs($show)
|
||||
{
|
||||
$this->showSniffs = StringHelper::booleanValue($show);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the output format
|
||||
* @param string $format
|
||||
*/
|
||||
public function setFormat($format)
|
||||
{
|
||||
$this->format = $format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create object for nested formatter element.
|
||||
* @return CodeSniffer_FormatterElement
|
||||
*/
|
||||
public function createFormatter () {
|
||||
$num = array_push($this->formatters,
|
||||
new PhpCodeSnifferTask_FormatterElement());
|
||||
return $this->formatters[$num-1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the haltonerror flag
|
||||
* @param boolean $value
|
||||
*/
|
||||
function setHaltonerror($value)
|
||||
{
|
||||
$this->haltonerror = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the haltonwarning flag
|
||||
* @param boolean $value
|
||||
*/
|
||||
function setHaltonwarning($value)
|
||||
{
|
||||
$this->haltonwarning = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes PHP code sniffer against PhingFile or a FileSet
|
||||
*/
|
||||
public function main() {
|
||||
if (!class_exists('PHP_CodeSniffer')) {
|
||||
include_once 'PHP/CodeSniffer.php';
|
||||
}
|
||||
|
||||
if(!isset($this->file) and count($this->filesets) == 0) {
|
||||
throw new BuildException("Missing either a nested fileset or attribute 'file' set");
|
||||
}
|
||||
|
||||
if (count($this->formatters) == 0) {
|
||||
// turn legacy format attribute into formatter
|
||||
$fmt = new PhpCodeSnifferTask_FormatterElement();
|
||||
$fmt->setType($this->format);
|
||||
$fmt->setUseFile(false);
|
||||
$this->formatters[] = $fmt;
|
||||
}
|
||||
|
||||
if (!isset($this->file))
|
||||
{
|
||||
$fileList = array();
|
||||
$project = $this->getProject();
|
||||
foreach ($this->filesets as $fs) {
|
||||
$ds = $fs->getDirectoryScanner($project);
|
||||
$files = $ds->getIncludedFiles();
|
||||
$dir = $fs->getDir($this->project)->getAbsolutePath();
|
||||
foreach ($files as $file) {
|
||||
$fileList[] = $dir.DIRECTORY_SEPARATOR.$file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$codeSniffer = new PHP_CodeSniffer($this->verbosity, $this->tabWidth);
|
||||
$codeSniffer->setAllowedFileExtensions($this->allowedFileExtensions);
|
||||
if (is_array($this->ignorePatterns)) $codeSniffer->setIgnorePatterns($this->ignorePatterns);
|
||||
foreach ($this->configData as $configData) {
|
||||
$codeSniffer->setConfigData($configData->getName(), $configData->getValue(), true);
|
||||
}
|
||||
|
||||
if ($this->file instanceof PhingFile) {
|
||||
$codeSniffer->process($this->file->getPath(), $this->standard, $this->sniffs, $this->noSubdirectories);
|
||||
|
||||
} else {
|
||||
$codeSniffer->process($fileList, $this->standard, $this->sniffs, $this->noSubdirectories);
|
||||
}
|
||||
|
||||
$report = $this->printErrorReport($codeSniffer);
|
||||
|
||||
// generate the documentation
|
||||
if ($this->docGenerator !== '' && $this->docFile !== null) {
|
||||
ob_start();
|
||||
|
||||
$codeSniffer->generateDocs($this->standard, $this->sniffs, $this->docGenerator);
|
||||
|
||||
$output = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
// write to file
|
||||
$outputFile = $this->docFile->getPath();
|
||||
$check = file_put_contents($outputFile, $output);
|
||||
|
||||
if (is_bool($check) && !$check) {
|
||||
throw new BuildException('Error writing doc to ' . $outputFile);
|
||||
}
|
||||
} elseif ($this->docGenerator !== '' && $this->docFile === null) {
|
||||
$codeSniffer->generateDocs($this->standard, $this->sniffs, $this->docGenerator);
|
||||
}
|
||||
|
||||
if ($this->haltonerror && $report['totals']['errors'] > 0)
|
||||
{
|
||||
throw new BuildException('phpcodesniffer detected ' . $report['totals']['errors']. ' error' . ($report['totals']['errors'] > 1 ? 's' : ''));
|
||||
}
|
||||
|
||||
if ($this->haltonwarning && $report['totals']['warnings'] > 0)
|
||||
{
|
||||
throw new BuildException('phpcodesniffer detected ' . $report['totals']['warnings'] . ' warning' . ($report['totals']['warnings'] > 1 ? 's' : ''));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the error report.
|
||||
*
|
||||
* @param PHP_CodeSniffer $phpcs The PHP_CodeSniffer object containing
|
||||
* the errors.
|
||||
*
|
||||
* @return int The number of error and warning messages shown.
|
||||
*/
|
||||
protected function printErrorReport($phpcs)
|
||||
{
|
||||
if ($this->showSniffs) {
|
||||
$sniffs = $phpcs->getSniffs();
|
||||
$sniffStr = '';
|
||||
foreach ($sniffs as $sniff) {
|
||||
$sniffStr .= '- ' . $sniff.PHP_EOL;
|
||||
}
|
||||
$this->log('The list of used sniffs (#' . count($sniffs) . '): ' . PHP_EOL . $sniffStr, Project::MSG_INFO);
|
||||
}
|
||||
|
||||
$filesViolations = $phpcs->getFilesErrors();
|
||||
$reporting = new PHP_CodeSniffer_Reporting();
|
||||
$report = $reporting->prepare($filesViolations, $this->showWarnings);
|
||||
|
||||
// process output
|
||||
foreach ($this->formatters as $fe) {
|
||||
switch ($fe->getType()) {
|
||||
case 'default':
|
||||
// default format goes to logs, no buffering
|
||||
$this->outputCustomFormat($report);
|
||||
$fe->setUseFile(false);
|
||||
break;
|
||||
|
||||
default:
|
||||
$reportFile = '';
|
||||
|
||||
if ($fe->getUseFile()) {
|
||||
$reportFile = $fe->getOutfile()->getPath();
|
||||
ob_start();
|
||||
}
|
||||
|
||||
$reporting->printReport(
|
||||
$fe->getType(),
|
||||
$filesViolations,
|
||||
$this->showWarnings,
|
||||
$this->showSources,
|
||||
$reportFile,
|
||||
$this->reportWidth
|
||||
);
|
||||
|
||||
// reporting class uses ob_end_flush(), but we don't want
|
||||
// an output if we use a file
|
||||
if ($fe->getUseFile()) {
|
||||
ob_end_clean();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $report;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the results with a custom format
|
||||
*
|
||||
* @param array $report Packaged list of all errors in each file
|
||||
*/
|
||||
protected function outputCustomFormat($report) {
|
||||
$files = $report['files'];
|
||||
foreach ($files as $file => $attributes) {
|
||||
$errors = $attributes['errors'];
|
||||
$warnings = $attributes['warnings'];
|
||||
$messages = $attributes['messages'];
|
||||
if ($errors > 0) {
|
||||
$this->log($file . ': ' . $errors . ' error' . ($errors > 1 ? 's' : '') . ' detected', Project::MSG_ERR);
|
||||
$this->outputCustomFormatMessages($messages, 'ERROR');
|
||||
} else {
|
||||
$this->log($file . ': No syntax errors detected', Project::MSG_VERBOSE);
|
||||
}
|
||||
if ($warnings > 0) {
|
||||
$this->log($file . ': ' . $warnings . ' warning' . ($warnings > 1 ? 's' : '') . ' detected', Project::MSG_WARN);
|
||||
$this->outputCustomFormatMessages($messages, 'WARNING');
|
||||
}
|
||||
}
|
||||
|
||||
$totalErrors = $report['totals']['errors'];
|
||||
$totalWarnings = $report['totals']['warnings'];
|
||||
$this->log(count($files) . ' files where checked', Project::MSG_INFO);
|
||||
if ($totalErrors > 0) {
|
||||
$this->log($totalErrors . ' error' . ($totalErrors > 1 ? 's' : '') . ' detected', Project::MSG_ERR);
|
||||
} else {
|
||||
$this->log('No syntax errors detected', Project::MSG_INFO);
|
||||
}
|
||||
if ($totalWarnings > 0) {
|
||||
$this->log($totalWarnings . ' warning' . ($totalWarnings > 1 ? 's' : '') . ' detected', Project::MSG_INFO);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the messages of a specific type for one file
|
||||
* @param array $messages
|
||||
* @param string $type
|
||||
*/
|
||||
protected function outputCustomFormatMessages($messages, $type) {
|
||||
foreach ($messages as $line => $messagesPerLine) {
|
||||
foreach ($messagesPerLine as $column => $messagesPerColumn) {
|
||||
foreach ($messagesPerColumn as $message) {
|
||||
$msgType = $message['type'];
|
||||
if ($type == $msgType) {
|
||||
$logLevel = Project::MSG_INFO;
|
||||
if ($msgType == 'ERROR') {
|
||||
$logLevel = Project::MSG_ERR;
|
||||
} else if ($msgType == 'WARNING') {
|
||||
$logLevel = Project::MSG_WARN;
|
||||
}
|
||||
$text = $message['message'];
|
||||
$string = $msgType . ' in line ' . $line . ' column ' . $column . ': ' . $text;
|
||||
$this->log($string, $logLevel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} //end phpCodeSnifferTask
|
||||
|
||||
class PhpCodeSnifferTask_FormatterElement extends DataType {
|
||||
|
||||
/**
|
||||
* Type of output to generate
|
||||
* @var string
|
||||
*/
|
||||
protected $type = "";
|
||||
|
||||
/**
|
||||
* Output to file?
|
||||
* @var bool
|
||||
*/
|
||||
protected $useFile = true;
|
||||
|
||||
/**
|
||||
* Output file.
|
||||
* @var string
|
||||
*/
|
||||
protected $outfile = "";
|
||||
|
||||
/**
|
||||
* Validate config.
|
||||
*/
|
||||
public function parsingComplete () {
|
||||
if(empty($this->type)) {
|
||||
throw new BuildException("Format missing required 'type' attribute.");
|
||||
}
|
||||
if ($useFile && empty($this->outfile)) {
|
||||
throw new BuildException("Format requires 'outfile' attribute when 'useFile' is true.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function setType ($type) {
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
public function getType () {
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function setUseFile ($useFile) {
|
||||
$this->useFile = $useFile;
|
||||
}
|
||||
|
||||
public function getUseFile () {
|
||||
return $this->useFile;
|
||||
}
|
||||
|
||||
public function setOutfile (PhingFile $outfile) {
|
||||
$this->outfile = $outfile;
|
||||
}
|
||||
|
||||
public function getOutfile () {
|
||||
return $this->outfile;
|
||||
}
|
||||
|
||||
} //end FormatterElement
|
255
airtime_mvc/library/phing/tasks/ext/PhpLintTask.php
Normal file
255
airtime_mvc/library/phing/tasks/ext/PhpLintTask.php
Normal file
|
@ -0,0 +1,255 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: PhpLintTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
require_once 'phing/util/DataStore.php';
|
||||
require_once 'phing/system/io/FileWriter.php';
|
||||
|
||||
/**
|
||||
* A PHP lint task. Checking syntax of one or more PHP source file.
|
||||
*
|
||||
* @author Knut Urdalen <knut.urdalen@telio.no>
|
||||
* @author Stefan Priebsch <stefan.priebsch@e-novative.de>
|
||||
* @version $Id: PhpLintTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext
|
||||
*/
|
||||
class PhpLintTask extends Task {
|
||||
|
||||
protected $file; // the source file (from xml attribute)
|
||||
protected $filesets = array(); // all fileset objects assigned to this task
|
||||
|
||||
protected $errorProperty;
|
||||
protected $haltOnFailure = false;
|
||||
protected $hasErrors = false;
|
||||
protected $badFiles = array();
|
||||
protected $interpreter = ''; // php interpreter to use for linting
|
||||
|
||||
protected $logLevel = Project::MSG_INFO;
|
||||
|
||||
protected $cache = null;
|
||||
|
||||
protected $tofile = null;
|
||||
|
||||
protected $deprecatedAsError = false;
|
||||
|
||||
/**
|
||||
* Initialize the interpreter with the Phing property
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->setInterpreter(Phing::getProperty('php.interpreter'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Override default php interpreter
|
||||
* @todo Do some sort of checking if the path is correct but would
|
||||
* require traversing the systems executeable path too
|
||||
* @param string $sPhp
|
||||
*/
|
||||
public function setInterpreter($sPhp) {
|
||||
$this->Interpreter = $sPhp;
|
||||
}
|
||||
|
||||
/**
|
||||
* The haltonfailure property
|
||||
* @param boolean $aValue
|
||||
*/
|
||||
public function setHaltOnFailure($aValue) {
|
||||
$this->haltOnFailure = $aValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* File to be performed syntax check on
|
||||
* @param PhingFile $file
|
||||
*/
|
||||
public function setFile(PhingFile $file) {
|
||||
$this->file = $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an property name in which to put any errors.
|
||||
* @param string $propname
|
||||
*/
|
||||
public function setErrorproperty($propname)
|
||||
{
|
||||
$this->errorProperty = $propname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to store last-modified times in cache
|
||||
*
|
||||
* @param PhingFile $file
|
||||
*/
|
||||
public function setCacheFile(PhingFile $file)
|
||||
{
|
||||
$this->cache = new DataStore($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to store last-modified times in cache
|
||||
*
|
||||
* @param PhingFile $file
|
||||
*/
|
||||
public function setToFile(PhingFile $tofile)
|
||||
{
|
||||
$this->tofile = $tofile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Nested creator, creates a FileSet for this task
|
||||
*
|
||||
* @return FileSet The created fileset object
|
||||
*/
|
||||
function createFileSet() {
|
||||
$num = array_push($this->filesets, new FileSet());
|
||||
return $this->filesets[$num-1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set level of log messages generated (default = info)
|
||||
* @param string $level
|
||||
*/
|
||||
public function setLevel($level)
|
||||
{
|
||||
switch ($level)
|
||||
{
|
||||
case "error": $this->logLevel = Project::MSG_ERR; break;
|
||||
case "warning": $this->logLevel = Project::MSG_WARN; break;
|
||||
case "info": $this->logLevel = Project::MSG_INFO; break;
|
||||
case "verbose": $this->logLevel = Project::MSG_VERBOSE; break;
|
||||
case "debug": $this->logLevel = Project::MSG_DEBUG; break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to treat deprecated warnings (introduced in PHP 5.3) as errors
|
||||
* @param boolean $deprecatedAsError
|
||||
*/
|
||||
public function setDeprecatedAsError($deprecatedAsError)
|
||||
{
|
||||
$this->deprecatedAsError = $deprecatedAsError;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute lint check against PhingFile or a FileSet
|
||||
*/
|
||||
public function main() {
|
||||
if(!isset($this->file) and count($this->filesets) == 0) {
|
||||
throw new BuildException("Missing either a nested fileset or attribute 'file' set");
|
||||
}
|
||||
|
||||
if($this->file instanceof PhingFile) {
|
||||
$this->lint($this->file->getPath());
|
||||
} else { // process filesets
|
||||
$project = $this->getProject();
|
||||
foreach($this->filesets as $fs) {
|
||||
$ds = $fs->getDirectoryScanner($project);
|
||||
$files = $ds->getIncludedFiles();
|
||||
$dir = $fs->getDir($this->project)->getPath();
|
||||
foreach($files as $file) {
|
||||
$this->lint($dir.DIRECTORY_SEPARATOR.$file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// write list of 'bad files' to file (if specified)
|
||||
if ($this->tofile) {
|
||||
$writer = new FileWriter($this->tofile);
|
||||
|
||||
foreach ($this->badFiles as $file => $msg) {
|
||||
$writer->write($file . "=" . $msg . PHP_EOL);
|
||||
}
|
||||
|
||||
$writer->close();
|
||||
}
|
||||
|
||||
if ($this->haltOnFailure && $this->hasErrors) throw new BuildException('Syntax error(s) in PHP files: '.implode(', ',$this->badFiles));
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the actual syntax check
|
||||
*
|
||||
* @param string $file
|
||||
* @return void
|
||||
*/
|
||||
protected function lint($file) {
|
||||
$command = $this->Interpreter == ''
|
||||
? 'php'
|
||||
: $this->Interpreter;
|
||||
$command .= ' -l ';
|
||||
if(file_exists($file)) {
|
||||
if(is_readable($file)) {
|
||||
if ($this->cache)
|
||||
{
|
||||
$lastmtime = $this->cache->get($file);
|
||||
|
||||
if ($lastmtime >= filemtime($file))
|
||||
{
|
||||
$this->log("Not linting '" . $file . "' due to cache", Project::MSG_DEBUG);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$messages = array();
|
||||
exec($command.'"'.$file.'" 2>&1', $messages);
|
||||
if(!preg_match('/^No syntax errors detected/', $messages[0])) {
|
||||
if (count($messages) < 2 ) {
|
||||
$this->log("Could not parse file", Project::MSG_ERR);
|
||||
} else {
|
||||
for ($i = 0; $i < count($messages) - 1; $i++) {
|
||||
$message = $messages[$i];
|
||||
if (trim($message) == '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!preg_match('/^(.*)Deprecated:/', $message) || $this->deprecatedAsError) {
|
||||
$this->log($message, $this->logLevel);
|
||||
|
||||
if ($this->errorProperty) {
|
||||
$this->project->setProperty($this->errorProperty, $message);
|
||||
}
|
||||
|
||||
if (!isset($this->badFiles[$file])) {
|
||||
$this->badFiles[$file] = $message;
|
||||
}
|
||||
|
||||
$this->hasErrors = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->log($file.': No syntax errors detected', $this->logLevel);
|
||||
}
|
||||
|
||||
if ($this->cache)
|
||||
{
|
||||
$this->cache->put($file, filemtime($file));
|
||||
}
|
||||
} else {
|
||||
throw new BuildException('Permission denied: '.$file);
|
||||
}
|
||||
} else {
|
||||
throw new BuildException('File not found: '.$file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
204
airtime_mvc/library/phing/tasks/ext/ReplaceRegexpTask.php
Normal file
204
airtime_mvc/library/phing/tasks/ext/ReplaceRegexpTask.php
Normal file
|
@ -0,0 +1,204 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: ReplaceRegexpTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
|
||||
/**
|
||||
* ReplaceRegExp is a directory based task for replacing the occurrence of a given regular expression with a substitution
|
||||
* pattern in a selected file or set of files.
|
||||
*
|
||||
* <code>
|
||||
* <replaceregexp file="${src}/build.properties"
|
||||
* match="OldProperty=(.*)"
|
||||
* replace="NewProperty=\1"
|
||||
* byline="true"/>
|
||||
* </code>
|
||||
*
|
||||
* @author Jonathan Bond-Caron <jbondc@openmv.com>
|
||||
* @version $Id: ReplaceRegexpTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.system
|
||||
* @see <http://ant.apache.org/manual/OptionalTasks/replaceregexp.html>
|
||||
*/
|
||||
class ReplaceRegexpTask extends Task {
|
||||
|
||||
/** Single file to process. */
|
||||
private $file;
|
||||
|
||||
/** Any filesets that should be processed. */
|
||||
private $filesets = array();
|
||||
|
||||
/**
|
||||
* Regular expression
|
||||
*
|
||||
* @var RegularExpression
|
||||
*/
|
||||
private $_regexp;
|
||||
|
||||
/**
|
||||
* File to apply regexp on
|
||||
*
|
||||
* @param string $path
|
||||
*/
|
||||
function setFile(PhingFile $path)
|
||||
{
|
||||
$this->file = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the regexp match pattern
|
||||
*
|
||||
* @param string $regexp
|
||||
*/
|
||||
function setMatch( $regexp )
|
||||
{
|
||||
$this->_regexp->setPattern( $regexp );
|
||||
}
|
||||
|
||||
/**
|
||||
* @see setMatch()
|
||||
*/
|
||||
function setPattern( $regexp )
|
||||
{
|
||||
$this->setMatch( $regexp );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the replacement string
|
||||
*
|
||||
* @param string $string
|
||||
*/
|
||||
function setReplace( $string )
|
||||
{
|
||||
$this->_regexp->setReplace( $string );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the regexp flags
|
||||
*
|
||||
* @param string $flags
|
||||
*/
|
||||
function setFlags( $flags )
|
||||
{
|
||||
// TODO... $this->_regexp->setFlags( $flags );
|
||||
}
|
||||
|
||||
/**
|
||||
* Match only per line
|
||||
*
|
||||
* @param bool $yesNo
|
||||
*/
|
||||
function setByline( $yesNo )
|
||||
{
|
||||
// TODO... $this->_regexp->
|
||||
}
|
||||
|
||||
/** Nested creator, adds a set of files (nested fileset attribute). */
|
||||
function createFileSet()
|
||||
{
|
||||
$num = array_push($this->filesets, new FileSet());
|
||||
return $this->filesets[$num-1];
|
||||
}
|
||||
|
||||
function init()
|
||||
{
|
||||
$this->_regexp = new RegularExpression;
|
||||
}
|
||||
|
||||
function main()
|
||||
{
|
||||
if ($this->file === null && empty($this->filesets)) {
|
||||
throw new BuildException("You must specify a file or fileset(s) for the <ReplaceRegexp> task.");
|
||||
}
|
||||
|
||||
// compile a list of all files to modify, both file attrib and fileset elements
|
||||
// can be used.
|
||||
$files = array();
|
||||
|
||||
if ($this->file !== null) {
|
||||
$files[] = $this->file;
|
||||
}
|
||||
|
||||
if (!empty($this->filesets)) {
|
||||
$filenames = array();
|
||||
foreach($this->filesets as $fs) {
|
||||
try {
|
||||
$ds = $fs->getDirectoryScanner($this->project);
|
||||
$filenames = $ds->getIncludedFiles(); // get included filenames
|
||||
$dir = $fs->getDir($this->project);
|
||||
foreach ($filenames as $fname) {
|
||||
$files[] = new PhingFile($dir, $fname);
|
||||
}
|
||||
} catch (BuildException $be) {
|
||||
$this->log($be->getMessage(), Project::MSG_WARN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->log("Applying Regexp processing to " . count($files) . " files.");
|
||||
|
||||
// These "slots" allow filters to retrieve information about the currently-being-process files
|
||||
$slot = $this->getRegisterSlot("currentFile");
|
||||
$basenameSlot = $this->getRegisterSlot("currentFile.basename");
|
||||
|
||||
$filter = new FilterChain($this->project);
|
||||
|
||||
$r = new ReplaceRegexp;
|
||||
$r->setRegexps(array($this->_regexp));
|
||||
|
||||
$filter->addReplaceRegexp($r);
|
||||
$filters = array($filter);
|
||||
|
||||
foreach($files as $file) {
|
||||
// set the register slots
|
||||
|
||||
$slot->setValue($file->getPath());
|
||||
$basenameSlot->setValue($file->getName());
|
||||
|
||||
// 1) read contents of file, pulling through any filters
|
||||
$in = null;
|
||||
try {
|
||||
$contents = "";
|
||||
$in = FileUtils::getChainedReader(new FileReader($file), $filters, $this->project);
|
||||
while(-1 !== ($buffer = $in->read())) {
|
||||
$contents .= $buffer;
|
||||
}
|
||||
$in->close();
|
||||
} catch (Exception $e) {
|
||||
if ($in) $in->close();
|
||||
$this->log("Erorr reading file: " . $e->getMessage(), Project::MSG_WARN);
|
||||
}
|
||||
|
||||
try {
|
||||
// now create a FileWriter w/ the same file, and write to the file
|
||||
$out = new FileWriter($file);
|
||||
$out->write($contents);
|
||||
$out->close();
|
||||
$this->log("Applying regexp processing to " . $file->getPath(), Project::MSG_VERBOSE);
|
||||
} catch (Exception $e) {
|
||||
if ($out) $out->close();
|
||||
$this->log("Error writing file back: " . $e->getMessage(), Project::MSG_WARN);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
354
airtime_mvc/library/phing/tasks/ext/ScpTask.php
Normal file
354
airtime_mvc/library/phing/tasks/ext/ScpTask.php
Normal file
|
@ -0,0 +1,354 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: ScpTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
|
||||
/**
|
||||
* Copy files to and from a remote host using scp.
|
||||
*
|
||||
* @author Michiel Rook <mrook@php.net>
|
||||
* @author Johan Van den Brande <johan@vandenbrande.com>
|
||||
* @version $Id: ScpTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext
|
||||
*/
|
||||
|
||||
class ScpTask extends Task
|
||||
{
|
||||
protected $file = "";
|
||||
protected $filesets = array(); // all fileset objects assigned to this task
|
||||
protected $todir = "";
|
||||
protected $mode = null;
|
||||
|
||||
protected $host = "";
|
||||
protected $port = 22;
|
||||
protected $username = "";
|
||||
protected $password = "";
|
||||
protected $autocreate = true;
|
||||
protected $fetch = false;
|
||||
protected $localEndpoint = "";
|
||||
protected $remoteEndpoint = "";
|
||||
|
||||
protected $pubkeyfile = '';
|
||||
protected $privkeyfile = '';
|
||||
protected $privkeyfilepassphrase = '';
|
||||
|
||||
protected $connection = null;
|
||||
protected $sftp = null;
|
||||
|
||||
protected $count = 0;
|
||||
|
||||
/**
|
||||
* Sets the remote host
|
||||
*/
|
||||
public function setHost($h)
|
||||
{
|
||||
$this->host = $h;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the remote host
|
||||
*/
|
||||
public function getHost()
|
||||
{
|
||||
return $this->host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the remote host port
|
||||
*/
|
||||
public function setPort($p)
|
||||
{
|
||||
$this->port = $p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the remote host port
|
||||
*/
|
||||
public function getPort()
|
||||
{
|
||||
return $this->port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the mode value
|
||||
*/
|
||||
public function setMode($value)
|
||||
{
|
||||
$this->mode = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the mode value
|
||||
*/
|
||||
public function getMode()
|
||||
{
|
||||
return $this->mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the username of the user to scp
|
||||
*/
|
||||
public function setUsername($username)
|
||||
{
|
||||
$this->username = $username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the username
|
||||
*/
|
||||
public function getUsername()
|
||||
{
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the password of the user to scp
|
||||
*/
|
||||
public function setPassword($password)
|
||||
{
|
||||
$this->password = $password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the password
|
||||
*/
|
||||
public function getPassword()
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the public key file of the user to scp
|
||||
*/
|
||||
public function setPubkeyfile($pubkeyfile)
|
||||
{
|
||||
$this->pubkeyfile = $pubkeyfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the pubkeyfile
|
||||
*/
|
||||
public function getPubkeyfile()
|
||||
{
|
||||
return $this->pubkeyfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the private key file of the user to scp
|
||||
*/
|
||||
public function setPrivkeyfile($privkeyfile)
|
||||
{
|
||||
$this->privkeyfile = $privkeyfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the private keyfile
|
||||
*/
|
||||
public function getPrivkeyfile()
|
||||
{
|
||||
return $this->privkeyfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the private key file passphrase of the user to scp
|
||||
*/
|
||||
public function setPrivkeyfilepassphrase($privkeyfilepassphrase)
|
||||
{
|
||||
$this->privkeyfilepassphrase = $privkeyfilepassphrase;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the private keyfile passphrase
|
||||
*/
|
||||
public function getPrivkeyfilepassphrase($privkeyfilepassphrase)
|
||||
{
|
||||
return $this->privkeyfilepassphrase;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to autocreate remote directories
|
||||
*/
|
||||
public function setAutocreate($autocreate)
|
||||
{
|
||||
$this->autocreate = (bool) $autocreate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether to autocreate remote directories
|
||||
*/
|
||||
public function getAutocreate()
|
||||
{
|
||||
return $this->autocreate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set destination directory
|
||||
*/
|
||||
public function setTodir($todir)
|
||||
{
|
||||
$this->todir = $todir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the destination directory
|
||||
*/
|
||||
public function getTodir()
|
||||
{
|
||||
return $this->todir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets local filename
|
||||
*/
|
||||
public function setFile($file)
|
||||
{
|
||||
$this->file = $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns local filename
|
||||
*/
|
||||
public function getFile()
|
||||
{
|
||||
return $this->file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to send (default) or fetch files
|
||||
*/
|
||||
public function setFetch($fetch)
|
||||
{
|
||||
$this->fetch = (bool) $fetch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether to send (default) or fetch files
|
||||
*/
|
||||
public function getFetch()
|
||||
{
|
||||
return $this->fetch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Nested creator, creates a FileSet for this task
|
||||
*
|
||||
* @return FileSet The created fileset object
|
||||
*/
|
||||
public function createFileSet() {
|
||||
$num = array_push($this->filesets, new FileSet());
|
||||
return $this->filesets[$num-1];
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
if (!function_exists('ssh2_connect')) {
|
||||
throw new BuildException("To use ScpTask, you need to install the SSH extension.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function main()
|
||||
{
|
||||
if ($this->file == "" && empty($this->filesets)) {
|
||||
throw new BuildException("Missing either a nested fileset or attribute 'file'");
|
||||
}
|
||||
|
||||
if ($this->host == "" || $this->username == "") {
|
||||
throw new BuildException("Attribute 'hostname' and 'username' must be set");
|
||||
}
|
||||
|
||||
$this->connection = ssh2_connect($this->host, $this->port);
|
||||
if (is_null($this->connection)) {
|
||||
throw new BuildException("Could not establish connection to " . $this->host . ":" . $this->port . "!");
|
||||
}
|
||||
|
||||
$could_auth = null;
|
||||
if ( $this->pubkeyfile ) {
|
||||
$could_auth = ssh2_auth_pubkey_file($this->connection, $this->username, $this->pubkeyfile, $this->privkeyfile, $this->privkeyfilepassphrase);
|
||||
} else {
|
||||
$could_auth = ssh2_auth_password($this->connection, $this->username, $this->password);
|
||||
}
|
||||
if (!$could_auth) {
|
||||
throw new BuildException("Could not authenticate connection!");
|
||||
}
|
||||
|
||||
// prepare sftp resource
|
||||
if ($this->autocreate) {
|
||||
$this->sftp = ssh2_sftp($this->connection);
|
||||
}
|
||||
|
||||
if ($this->file != "") {
|
||||
$this->copyFile($this->file, basename($this->file));
|
||||
} else {
|
||||
if ($this->fetch) {
|
||||
throw new BuildException("Unable to use filesets to retrieve files from remote server");
|
||||
}
|
||||
|
||||
foreach($this->filesets as $fs) {
|
||||
$ds = $fs->getDirectoryScanner($this->project);
|
||||
$files = $ds->getIncludedFiles();
|
||||
$dir = $fs->getDir($this->project)->getPath();
|
||||
foreach($files as $file) {
|
||||
$path = $dir.DIRECTORY_SEPARATOR.$file;
|
||||
$this->copyFile($path, $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->log("Copied " . $this->counter . " file(s) " . ($this->fetch ? "from" : "to") . " '" . $this->host . "'");
|
||||
}
|
||||
|
||||
protected function copyFile($local, $remote)
|
||||
{
|
||||
$path = rtrim($this->todir, "/") . "/";
|
||||
|
||||
if ($this->fetch) {
|
||||
$localEndpoint = $path . $remote;
|
||||
$remoteEndpoint = $local;
|
||||
|
||||
$ret = @ssh2_scp_recv($this->connection, $remoteEndpoint, $localEndpoint);
|
||||
|
||||
if ($ret === false) {
|
||||
throw new BuildException("Could not fetch remote file '" . $remoteEndpoint . "'");
|
||||
}
|
||||
} else {
|
||||
$localEndpoint = $local;
|
||||
$remoteEndpoint = $path . $remote;
|
||||
|
||||
if ($this->autocreate) {
|
||||
ssh2_sftp_mkdir($this->sftp, dirname($remoteEndpoint), (is_null($this->mode) ? 0777 : $this->mode), true);
|
||||
}
|
||||
|
||||
if (!is_null($this->mode)) {
|
||||
$ret = @ssh2_scp_send($this->connection, $localEndpoint, $remoteEndpoint, $this->mode);
|
||||
} else {
|
||||
$ret = @ssh2_scp_send($this->connection, $localEndpoint, $remoteEndpoint);
|
||||
}
|
||||
|
||||
if ($ret === false) {
|
||||
throw new BuildException("Could not create remote file '" . $remoteEndpoint . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->counter++;
|
||||
}
|
||||
}
|
||||
?>
|
610
airtime_mvc/library/phing/tasks/ext/SmartyTask.php
Normal file
610
airtime_mvc/library/phing/tasks/ext/SmartyTask.php
Normal file
|
@ -0,0 +1,610 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* $Id: SmartyTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
include_once 'phing/BuildException.php';
|
||||
include_once 'phing/util/StringHelper.php';
|
||||
|
||||
/**
|
||||
* A phing task for generating output by using Smarty.
|
||||
*
|
||||
* This is based on the TexenTask from Apache's Velocity engine. This class
|
||||
* was originally proted in order to provide a template compiling system for
|
||||
* Torque.
|
||||
*
|
||||
* TODO:
|
||||
* - Add Path / useClasspath support?
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org> (SmartyTask)
|
||||
* @author Jason van Zyl <jvanzyl@apache.org> (TexenTask)
|
||||
* @author Robert Burrell Donkin <robertdonkin@mac.com>
|
||||
* @version $Id: SmartyTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext
|
||||
*/
|
||||
class SmartyTask extends Task {
|
||||
|
||||
/**
|
||||
* Smarty template engine.
|
||||
* @var Smarty
|
||||
*/
|
||||
protected $context;
|
||||
|
||||
/**
|
||||
* Variables that are assigned to the context on parse/compile.
|
||||
* @var array
|
||||
*/
|
||||
protected $properties = array();
|
||||
|
||||
/**
|
||||
* This is the control template that governs the output.
|
||||
* It may or may not invoke the services of worker
|
||||
* templates.
|
||||
* @var string
|
||||
*/
|
||||
protected $controlTemplate;
|
||||
|
||||
/**
|
||||
* This is where Velocity will look for templates
|
||||
* using the file template loader.
|
||||
* @var string
|
||||
*/
|
||||
protected $templatePath;
|
||||
|
||||
/**
|
||||
* This is where texen will place all the output
|
||||
* that is a product of the generation process.
|
||||
* @var string
|
||||
*/
|
||||
protected $outputDirectory;
|
||||
|
||||
/**
|
||||
* This is the file where the generated text
|
||||
* will be placed.
|
||||
* @var string
|
||||
*/
|
||||
protected $outputFile;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* These are properties that are fed into the
|
||||
* initial context from a properties file. This
|
||||
* is simply a convenient way to set some values
|
||||
* that you wish to make available in the context.
|
||||
* </p>
|
||||
* <p>
|
||||
* These values are not critical, like the template path
|
||||
* or output path, but allow a convenient way to
|
||||
* set a value that may be specific to a particular
|
||||
* generation task.
|
||||
* </p>
|
||||
* <p>
|
||||
* For example, if you are generating scripts to allow
|
||||
* user to automatically create a database, then
|
||||
* you might want the <code>$databaseName</code>
|
||||
* to be placed
|
||||
* in the initial context so that it is available
|
||||
* in a script that might look something like the
|
||||
* following:
|
||||
* <code><pre>
|
||||
* #!bin/sh
|
||||
*
|
||||
* echo y | mysqladmin create $databaseName
|
||||
* </pre></code>
|
||||
* The value of <code>$databaseName</code> isn't critical to
|
||||
* output, and you obviously don't want to change
|
||||
* the ant task to simply take a database name.
|
||||
* So initial context values can be set with
|
||||
* properties file.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $contextProperties;
|
||||
|
||||
/**
|
||||
* Smarty compiles templates before parsing / replacing tokens in them.
|
||||
* By default it will try ./templates_c, but you may wish to override this.
|
||||
* @var string
|
||||
*/
|
||||
protected $compilePath;
|
||||
|
||||
/**
|
||||
* Whether to force Smarty to recompile templates.
|
||||
* Smarty does check file modification time, but you can set this
|
||||
* to be *sure* that the template will be compiled (of course it will
|
||||
* be slower if you do).
|
||||
* @var boolean
|
||||
*/
|
||||
protected $forceCompile = false;
|
||||
|
||||
/**
|
||||
* Smarty can use config files.
|
||||
* This tells Smarty where to look for the config files.
|
||||
* @var string
|
||||
*/
|
||||
protected $configPath;
|
||||
|
||||
/**
|
||||
* Customize the left delimiter for Smarty tags.
|
||||
* @var string
|
||||
*/
|
||||
protected $leftDelimiter;
|
||||
|
||||
/**
|
||||
* Customize the right delimiter for Smarty tags.
|
||||
* @var string
|
||||
*/
|
||||
protected $rightDelimiter;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// The following getters & setters are used by phing to set properties
|
||||
// specified in the XML for the smarty task.
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
public function init() {
|
||||
include_once 'Smarty.class.php';
|
||||
if (!class_exists('Smarty')) {
|
||||
throw new BuildException("To use SmartyTask, you must have the path to Smarty.class.php on your include_path or your \$PHP_CLASSPATH environment variable.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [REQUIRED] Set the control template for the
|
||||
* generating process.
|
||||
* @param string $controlTemplate
|
||||
* @return void
|
||||
*/
|
||||
public function setControlTemplate ($controlTemplate) {
|
||||
$this->controlTemplate = $controlTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the control template for the
|
||||
* generating process.
|
||||
* @return string
|
||||
*/
|
||||
public function getControlTemplate() {
|
||||
return $this->controlTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* [REQUIRED] Set the path where Velocity will look
|
||||
* for templates using the file template
|
||||
* loader.
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function setTemplatePath($templatePath) {
|
||||
$resolvedPath = "";
|
||||
$tok = strtok($templatePath, ",");
|
||||
while ( $tok ) {
|
||||
// resolve relative path from basedir and leave
|
||||
// absolute path untouched.
|
||||
$fullPath = $this->project->resolveFile($tok);
|
||||
$cpath = $fullPath->getCanonicalPath();
|
||||
if ($cpath === false) {
|
||||
$this->log("Template directory does not exist: " . $fullPath->getAbsolutePath());
|
||||
} else {
|
||||
$resolvedPath .= $cpath;
|
||||
}
|
||||
$tok = strtok(",");
|
||||
if ( $tok ) {
|
||||
$resolvedPath .= ",";
|
||||
}
|
||||
}
|
||||
$this->templatePath = $resolvedPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path where Velocity will look
|
||||
* for templates using the file template
|
||||
* loader.
|
||||
* @return string
|
||||
*/
|
||||
public function getTemplatePath() {
|
||||
return $this->templatePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* [REQUIRED] Set the output directory. It will be
|
||||
* created if it doesn't exist.
|
||||
* @param PhingFile $outputDirectory
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function setOutputDirectory(PhingFile $outputDirectory) {
|
||||
try {
|
||||
if (!$outputDirectory->exists()) {
|
||||
$this->log("Output directory does not exist, creating: " . $outputDirectory->getPath(),Project::MSG_VERBOSE);
|
||||
if (!$outputDirectory->mkdirs()) {
|
||||
throw new IOException("Unable to create Ouptut directory: " . $outputDirectory->getAbsolutePath());
|
||||
}
|
||||
}
|
||||
$this->outputDirectory = $outputDirectory->getCanonicalPath();
|
||||
} catch (IOException $ioe) {
|
||||
throw new BuildException($ioe->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the output directory.
|
||||
* @return string
|
||||
*/
|
||||
public function getOutputDirectory() {
|
||||
return $this->outputDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
* [REQUIRED] Set the output file for the
|
||||
* generation process.
|
||||
* @return void
|
||||
*/
|
||||
public function setOutputFile($outputFile) {
|
||||
$this->outputFile = $outputFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the output file for the
|
||||
* generation process.
|
||||
* @return string
|
||||
*/
|
||||
public function getOutputFile() {
|
||||
return $this->outputFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the path Smarty uses as a "cache" for compiled templates.
|
||||
* @param string $compilePath
|
||||
*/
|
||||
public function setCompilePath($compilePath) {
|
||||
$this->compilePath = $compilePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path Smarty uses for compiling templates.
|
||||
* @return string
|
||||
*/
|
||||
public function getCompilePath() {
|
||||
return $this->compilePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether Smarty should always recompile tempaltes.
|
||||
* @param boolean $force
|
||||
* @return void
|
||||
*/
|
||||
public function setForceCompile($force) {
|
||||
$this->forceCompile = (boolean) $force;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether Smarty should always recompile template.
|
||||
* @return boolean
|
||||
*/
|
||||
public function getForceCompile() {
|
||||
return $this->forceCompile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set where Smarty looks for config files.
|
||||
* @param string $configPath
|
||||
* @return void
|
||||
*/
|
||||
public function setConfigPath($configPath) {
|
||||
$this->configPath = $configPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path that Smarty uses for looking for config files.
|
||||
* @return string
|
||||
*/
|
||||
public function getConfigPath() {
|
||||
return $this->configPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Smarty template left delimiter.
|
||||
* @param string $delim
|
||||
* @return void
|
||||
*/
|
||||
public function setLeftDelimiter($delim) {
|
||||
$this->leftDelimiter = $delim;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Smarty template right delimiter
|
||||
* @return string
|
||||
*/
|
||||
public function getLeftDelimiter() {
|
||||
return $this->leftDelimiter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Smarty template right delimiter.
|
||||
* @param string $delim
|
||||
* @return void
|
||||
*/
|
||||
public function setRightDelimiter($delim) {
|
||||
$this->rightDelimiter = $delim;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Smarty template right delimiter
|
||||
* @return string
|
||||
*/
|
||||
public function getRightDelimiter() {
|
||||
return $this->rightDelimiter;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the context properties that will be
|
||||
* fed into the initial context be the
|
||||
* generating process starts.
|
||||
* @param string $file
|
||||
* @return void
|
||||
*/
|
||||
public function setContextProperties($file) {
|
||||
|
||||
$sources = explode(",", $file);
|
||||
$this->contextProperties = new Properties();
|
||||
|
||||
// Always try to get the context properties resource
|
||||
// from a file first. Templates may be taken from a JAR
|
||||
// file but the context properties resource may be a
|
||||
// resource in the filesystem. If this fails than attempt
|
||||
// to get the context properties resource from the
|
||||
// classpath.
|
||||
for ($i=0, $sourcesLength=count($sources); $i < $sourcesLength; $i++) {
|
||||
$source = new Properties();
|
||||
|
||||
try {
|
||||
|
||||
// resolve relative path from basedir and leave
|
||||
// absolute path untouched.
|
||||
$fullPath = $this->project->resolveFile($sources[$i]);
|
||||
$this->log("Using contextProperties file: " . $fullPath->__toString());
|
||||
$source->load($fullPath);
|
||||
|
||||
} catch (Exception $e) {
|
||||
|
||||
throw new BuildException("Context properties file " . $sources[$i] .
|
||||
" could not be found in the file system!");
|
||||
|
||||
}
|
||||
|
||||
$keys = $source->keys();
|
||||
|
||||
foreach ($keys as $key) {
|
||||
$name = $key;
|
||||
$value = $this->project->replaceProperties($source->getProperty($name));
|
||||
$this->contextProperties->setProperty($name, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the context properties that will be
|
||||
* fed into the initial context be the
|
||||
* generating process starts.
|
||||
* @return Properties
|
||||
*/
|
||||
public function getContextProperties() {
|
||||
return $this->contextProperties;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// End of XML setters & getters
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Creates a Smarty object.
|
||||
*
|
||||
* @return Smarty initialized (cleared) Smarty context.
|
||||
* @throws Exception the execute method will catch
|
||||
* and rethrow as a <code>BuildException</code>
|
||||
*/
|
||||
public function initControlContext() {
|
||||
$this->context->clear_all_assign();
|
||||
return $this->context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the input script with Velocity
|
||||
*
|
||||
* @throws BuildException
|
||||
* BuildExceptions are thrown when required attributes are missing.
|
||||
* Exceptions thrown by Velocity are rethrown as BuildExceptions.
|
||||
*/
|
||||
public function main() {
|
||||
|
||||
// Make sure the template path is set.
|
||||
if (empty($this->templatePath)) {
|
||||
throw new BuildException("The template path needs to be defined!");
|
||||
}
|
||||
|
||||
// Make sure the control template is set.
|
||||
if ($this->controlTemplate === null) {
|
||||
throw new BuildException("The control template needs to be defined!");
|
||||
}
|
||||
|
||||
// Make sure the output directory is set.
|
||||
if ($this->outputDirectory === null) {
|
||||
throw new BuildException("The output directory needs to be defined!");
|
||||
}
|
||||
|
||||
// Make sure there is an output file.
|
||||
if ($this->outputFile === null) {
|
||||
throw new BuildException("The output file needs to be defined!");
|
||||
}
|
||||
|
||||
// Setup Smarty runtime.
|
||||
|
||||
// Smarty uses one object to store properties and to store
|
||||
// the context for the template (unlike Velocity). We setup this object, calling it
|
||||
// $this->context, and then initControlContext simply zeros out
|
||||
// any assigned variables.
|
||||
$this->context = new Smarty();
|
||||
|
||||
if ($this->compilePath !== null) {
|
||||
$this->log("Using compilePath: " . $this->compilePath);
|
||||
$this->context->compile_dir = $this->compilePath;
|
||||
}
|
||||
|
||||
if ($this->configPath !== null) {
|
||||
$this->log("Using configPath: " . $this->configPath);
|
||||
$this->context->config_dir = $this->configPath;
|
||||
}
|
||||
|
||||
if ($this->forceCompile !== null) {
|
||||
$this->context->force_compile = $this->forceCompile;
|
||||
}
|
||||
|
||||
if ($this->leftDelimiter !== null) {
|
||||
$this->context->left_delimiter = $this->leftDelimiter;
|
||||
}
|
||||
|
||||
if ($this->rightDelimiter !== null) {
|
||||
$this->context->right_delimiter = $this->rightDelimiter;
|
||||
}
|
||||
|
||||
if ($this->templatePath !== null) {
|
||||
$this->log("Using templatePath: " . $this->templatePath);
|
||||
$this->context->template_dir = $this->templatePath;
|
||||
}
|
||||
|
||||
$smartyCompilePath = new PhingFile($this->context->compile_dir);
|
||||
if (!$smartyCompilePath->exists()) {
|
||||
$this->log("Compile directory does not exist, creating: " . $smartyCompilePath->getPath(), Project::MSG_VERBOSE);
|
||||
if (!$smartyCompilePath->mkdirs()) {
|
||||
throw new BuildException("Smarty needs a place to compile templates; specify a 'compilePath' or create ".$this->context->compile_dir);
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure the output directory exists, if it doesn't
|
||||
// then create it.
|
||||
$file = new PhingFile($this->outputDirectory);
|
||||
if (!$file->exists()) {
|
||||
$this->log("Output directory does not exist, creating: " . $file->getAbsolutePath());
|
||||
$file->mkdirs();
|
||||
}
|
||||
|
||||
$path = $this->outputDirectory . DIRECTORY_SEPARATOR . $this->outputFile;
|
||||
$this->log("Generating to file " . $path);
|
||||
|
||||
$writer = new FileWriter($path);
|
||||
|
||||
// The generator and the output path should
|
||||
// be placed in the init context here and
|
||||
// not in the generator class itself.
|
||||
$c = $this->initControlContext();
|
||||
|
||||
// Set any variables that need to always
|
||||
// be loaded
|
||||
$this->populateInitialContext($c);
|
||||
|
||||
// Feed all the options into the initial
|
||||
// control context so they are available
|
||||
// in the control/worker templates.
|
||||
if ($this->contextProperties !== null) {
|
||||
|
||||
foreach($this->contextProperties->keys() as $property) {
|
||||
|
||||
$value = $this->contextProperties->getProperty($property);
|
||||
|
||||
// Special exception (from Texen)
|
||||
// for properties ending in file.contents:
|
||||
// in that case we dump the contents of the file
|
||||
// as the "value" for the Property.
|
||||
if (StringHelper::endsWith("file.contents", $property)) {
|
||||
// pull in contents of file specified
|
||||
|
||||
$property = substr($property, 0, strpos($property, "file.contents") - 1);
|
||||
|
||||
// reset value, and then
|
||||
// read in teh contents of the file into that var
|
||||
$value = "";
|
||||
$f = new PhingFile($project->resolveFile($value)->getCanonicalPath());
|
||||
if ($f->exists()) {
|
||||
try {
|
||||
$fr = new FileReader($f);
|
||||
$fr->readInto($value);
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
} // if ends with file.contents
|
||||
|
||||
if (StringHelper::isBoolean($value)) {
|
||||
$value = StringHelper::booleanValue($value);
|
||||
}
|
||||
|
||||
$c->assign($property, $value);
|
||||
|
||||
} // foreach property
|
||||
|
||||
} // if contextProperties !== null
|
||||
|
||||
try {
|
||||
//$c->display($this->controlTemplate);
|
||||
$writer->write($c->fetch($this->controlTemplate));
|
||||
$writer->close();
|
||||
} catch (IOException $ioe) {
|
||||
$writer->close();
|
||||
throw new BuildException("Cannot write parsed template.");
|
||||
}
|
||||
|
||||
$this->cleanup();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Place useful objects into the initial context.</p>
|
||||
*
|
||||
* <p>TexenTask places <code>Date().toString()</code> into the
|
||||
* context as <code>$now</code>. Subclasses who want to vary the
|
||||
* objects in the context should override this method.</p>
|
||||
*
|
||||
* <p><code>$generator</code> is not put into the context in this
|
||||
* method.</p>
|
||||
*
|
||||
* @param context The context to populate, as retrieved from
|
||||
* {@link #initControlContext()}.
|
||||
* @return void
|
||||
* @throws Exception Error while populating context. The {@link
|
||||
* #execute()} method will catch and rethrow as a
|
||||
* <code>BuildException</code>.
|
||||
*/
|
||||
protected function populateInitialContext(Smarty $context) {
|
||||
}
|
||||
|
||||
/**
|
||||
* A hook method called at the end of {@link #execute()} which can
|
||||
* be overridden to perform any necessary cleanup activities (such
|
||||
* as the release of database connections, etc.). By default,
|
||||
* does nothing.
|
||||
* @return void
|
||||
* @throws Exception Problem cleaning up.
|
||||
*/
|
||||
protected function cleanup() {
|
||||
}
|
||||
}
|
178
airtime_mvc/library/phing/tasks/ext/SshTask.php
Normal file
178
airtime_mvc/library/phing/tasks/ext/SshTask.php
Normal file
|
@ -0,0 +1,178 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: SshTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
|
||||
/**
|
||||
* Execute commands on a remote host using ssh.
|
||||
*
|
||||
* @author Johan Van den Brande <johan@vandenbrande.com>
|
||||
* @version $Id: SshTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext
|
||||
*/
|
||||
|
||||
class SshTask extends Task {
|
||||
|
||||
private $host = "";
|
||||
private $port = 22;
|
||||
private $username = "";
|
||||
private $password = "";
|
||||
private $command = "";
|
||||
private $pubkeyfile = '';
|
||||
private $privkeyfile = '';
|
||||
private $privkeyfilepassphrase = '';
|
||||
|
||||
public function setHost($host)
|
||||
{
|
||||
$this->host = $host;
|
||||
}
|
||||
|
||||
public function getHost()
|
||||
{
|
||||
return $this->host;
|
||||
}
|
||||
|
||||
public function setPort($port)
|
||||
{
|
||||
$this->port = $port;
|
||||
}
|
||||
|
||||
public function getPort()
|
||||
{
|
||||
return $this->port;
|
||||
}
|
||||
|
||||
public function setUsername($username)
|
||||
{
|
||||
$this->username = $username;
|
||||
}
|
||||
|
||||
public function getUsername()
|
||||
{
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
public function setPassword($password)
|
||||
{
|
||||
$this->password = $password;
|
||||
}
|
||||
|
||||
public function getPassword()
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the public key file of the user to scp
|
||||
*/
|
||||
public function setPubkeyfile($pubkeyfile)
|
||||
{
|
||||
$this->pubkeyfile = $pubkeyfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the pubkeyfile
|
||||
*/
|
||||
public function getPubkeyfile()
|
||||
{
|
||||
return $this->pubkeyfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the private key file of the user to scp
|
||||
*/
|
||||
public function setPrivkeyfile($privkeyfile)
|
||||
{
|
||||
$this->privkeyfile = $privkeyfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the private keyfile
|
||||
*/
|
||||
public function getPrivkeyfile()
|
||||
{
|
||||
return $this->privkeyfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the private key file passphrase of the user to scp
|
||||
*/
|
||||
public function setPrivkeyfilepassphrase($privkeyfilepassphrase)
|
||||
{
|
||||
$this->privkeyfilepassphrase = $privkeyfilepassphrase;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the private keyfile passphrase
|
||||
*/
|
||||
public function getPrivkeyfilepassphrase($privkeyfilepassphrase)
|
||||
{
|
||||
return $this->privkeyfilepassphrase;
|
||||
}
|
||||
|
||||
public function setCommand($command)
|
||||
{
|
||||
$this->command = $command;
|
||||
}
|
||||
|
||||
public function getCommand()
|
||||
{
|
||||
return $this->command;
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
if (!function_exists('ssh2_connect')) {
|
||||
throw new BuildException("To use SshTask, you need to install the SSH extension.");
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
public function main()
|
||||
{
|
||||
$this->connection = ssh2_connect($this->host, $this->port);
|
||||
if (is_null($this->connection)) {
|
||||
throw new BuildException("Could not establish connection to " . $this->host . ":" . $this->port . "!");
|
||||
}
|
||||
|
||||
$could_auth = null;
|
||||
if ( $this->pubkeyfile ) {
|
||||
$could_auth = ssh2_auth_pubkey_file($this->connection, $this->username, $this->pubkeyfile, $this->privkeyfile, $this->privkeyfilepassphrase);
|
||||
} else {
|
||||
$could_auth = ssh2_auth_password($this->connection, $this->username, $this->password);
|
||||
}
|
||||
if (!$could_auth) {
|
||||
throw new BuildException("Could not authenticate connection!");
|
||||
}
|
||||
|
||||
$stream = ssh2_exec($this->connection, $this->command);
|
||||
if (!$stream) {
|
||||
throw new BuildException("Could not execute command!");
|
||||
}
|
||||
|
||||
stream_set_blocking( $stream, true );
|
||||
while( $buf = fread($stream,4096) ){
|
||||
print($buf);
|
||||
}
|
||||
fclose($stream);
|
||||
}
|
||||
}
|
||||
?>
|
444
airtime_mvc/library/phing/tasks/ext/TarTask.php
Normal file
444
airtime_mvc/library/phing/tasks/ext/TarTask.php
Normal file
|
@ -0,0 +1,444 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: TarTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/tasks/system/MatchingTask.php';
|
||||
include_once 'phing/util/SourceFileScanner.php';
|
||||
include_once 'phing/mappers/MergeMapper.php';
|
||||
include_once 'phing/util/StringHelper.php';
|
||||
|
||||
/**
|
||||
* Creates a tar archive using PEAR Archive_Tar.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org> (Phing)
|
||||
* @author Stefano Mazzocchi <stefano@apache.org> (Ant)
|
||||
* @author Stefan Bodewig <stefan.bodewig@epost.de> (Ant)
|
||||
* @author Magesh Umasankar
|
||||
* @version $Id: TarTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext
|
||||
*/
|
||||
class TarTask extends MatchingTask {
|
||||
|
||||
const TAR_NAMELEN = 100;
|
||||
|
||||
const WARN = "warn";
|
||||
const FAIL = "fail";
|
||||
const OMIT = "omit";
|
||||
|
||||
private $tarFile;
|
||||
private $baseDir;
|
||||
private $includeEmpty = true; // Whether to include empty dirs in the TAR
|
||||
|
||||
private $longFileMode = "warn";
|
||||
|
||||
private $filesets = array();
|
||||
private $fileSetFiles = array();
|
||||
|
||||
/**
|
||||
* Indicates whether the user has been warned about long files already.
|
||||
*/
|
||||
private $longWarningGiven = false;
|
||||
|
||||
/**
|
||||
* Compression mode. Available options "gzip", "bzip2", "none" (null).
|
||||
*/
|
||||
private $compression = null;
|
||||
|
||||
/**
|
||||
* File path prefix in the tar archive
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $prefix = null;
|
||||
|
||||
/**
|
||||
* Ensures that PEAR lib exists.
|
||||
*/
|
||||
public function init() {
|
||||
include_once 'Archive/Tar.php';
|
||||
if (!class_exists('Archive_Tar')) {
|
||||
throw new BuildException("You must have installed the PEAR Archive_Tar class in order to use TarTask.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new fileset
|
||||
* @return FileSet
|
||||
*/
|
||||
public function createTarFileSet() {
|
||||
$this->fileset = new TarFileSet();
|
||||
$this->filesets[] = $this->fileset;
|
||||
return $this->fileset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new fileset. Alias to createTarFileSet() for backwards compatibility.
|
||||
* @return FileSet
|
||||
* @see createTarFileSet()
|
||||
*/
|
||||
public function createFileSet() {
|
||||
$this->fileset = new TarFileSet();
|
||||
$this->filesets[] = $this->fileset;
|
||||
return $this->fileset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set is the name/location of where to create the tar file.
|
||||
* @param PhingFile $destFile The output of the tar
|
||||
*/
|
||||
public function setDestFile(PhingFile $destFile) {
|
||||
$this->tarFile = $destFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the base directory to look in for things to tar.
|
||||
* @param PhingFile $baseDir
|
||||
*/
|
||||
public function setBasedir(PhingFile $baseDir) {
|
||||
$this->baseDir = $baseDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the include empty dirs flag.
|
||||
* @param boolean Flag if empty dirs should be tarred too
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function setIncludeEmptyDirs($bool) {
|
||||
$this->includeEmpty = (boolean) $bool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set how to handle long files, those with a path>100 chars.
|
||||
* Optional, default=warn.
|
||||
* <p>
|
||||
* Allowable values are
|
||||
* <ul>
|
||||
* <li> truncate - paths are truncated to the maximum length
|
||||
* <li> fail - paths greater than the maximim cause a build exception
|
||||
* <li> warn - paths greater than the maximum cause a warning and GNU is used
|
||||
* <li> gnu - GNU extensions are used for any paths greater than the maximum.
|
||||
* <li> omit - paths greater than the maximum are omitted from the archive
|
||||
* </ul>
|
||||
*/
|
||||
public function setLongfile($mode) {
|
||||
$this->longFileMode = $mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set compression method.
|
||||
* Allowable values are
|
||||
* <ul>
|
||||
* <li> none - no compression
|
||||
* <li> gzip - Gzip compression
|
||||
* <li> bzip2 - Bzip2 compression
|
||||
* </ul>
|
||||
*/
|
||||
public function setCompression($mode) {
|
||||
switch($mode) {
|
||||
case "gzip":
|
||||
$this->compression = "gz";
|
||||
break;
|
||||
case "bzip2":
|
||||
$this->compression = "bz2";
|
||||
break;
|
||||
case "none":
|
||||
$this->compression = null;
|
||||
break;
|
||||
default:
|
||||
$this->log("Ignoring unknown compression mode: ".$mode, Project::MSG_WARN);
|
||||
$this->compression = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the file path prefix for file in the tar file.
|
||||
*
|
||||
* @param string $prefix Prefix
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setPrefix($prefix) {
|
||||
$this->prefix = $prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* do the work
|
||||
* @throws BuildException
|
||||
*/
|
||||
public function main() {
|
||||
|
||||
if ($this->tarFile === null) {
|
||||
throw new BuildException("tarfile attribute must be set!", $this->getLocation());
|
||||
}
|
||||
|
||||
if ($this->tarFile->exists() && $this->tarFile->isDirectory()) {
|
||||
throw new BuildException("tarfile is a directory!", $this->getLocation());
|
||||
}
|
||||
|
||||
if ($this->tarFile->exists() && !$this->tarFile->canWrite()) {
|
||||
throw new BuildException("Can not write to the specified tarfile!", $this->getLocation());
|
||||
}
|
||||
|
||||
// shouldn't need to clone, since the entries in filesets
|
||||
// themselves won't be modified -- only elements will be added
|
||||
$savedFileSets = $this->filesets;
|
||||
|
||||
try {
|
||||
if ($this->baseDir !== null) {
|
||||
if (!$this->baseDir->exists()) {
|
||||
throw new BuildException("basedir does not exist!", $this->getLocation());
|
||||
}
|
||||
if (empty($this->filesets)) { // if there weren't any explicit filesets specivied, then
|
||||
// create a default, all-inclusive fileset using the specified basedir.
|
||||
$mainFileSet = new TarFileSet($this->fileset);
|
||||
$mainFileSet->setDir($this->baseDir);
|
||||
$this->filesets[] = $mainFileSet;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($this->filesets)) {
|
||||
throw new BuildException("You must supply either a basedir "
|
||||
. "attribute or some nested filesets.",
|
||||
$this->getLocation());
|
||||
}
|
||||
|
||||
// check if tar is out of date with respect to each fileset
|
||||
if($this->tarFile->exists()) {
|
||||
$upToDate = true;
|
||||
foreach($this->filesets as $fs) {
|
||||
$files = $fs->getFiles($this->project, $this->includeEmpty);
|
||||
if (!$this->archiveIsUpToDate($files, $fs->getDir($this->project))) {
|
||||
$upToDate = false;
|
||||
}
|
||||
for ($i=0, $fcount=count($files); $i < $fcount; $i++) {
|
||||
if ($this->tarFile->equals(new PhingFile($fs->getDir($this->project), $files[$i]))) {
|
||||
throw new BuildException("A tar file cannot include itself", $this->getLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($upToDate) {
|
||||
$this->log("Nothing to do: " . $this->tarFile->__toString() . " is up to date.", Project::MSG_INFO);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$this->log("Building tar: " . $this->tarFile->__toString(), Project::MSG_INFO);
|
||||
|
||||
$tar = new Archive_Tar($this->tarFile->getAbsolutePath(), $this->compression);
|
||||
|
||||
// print errors
|
||||
$tar->setErrorHandling(PEAR_ERROR_PRINT);
|
||||
|
||||
foreach($this->filesets as $fs) {
|
||||
$files = $fs->getFiles($this->project, $this->includeEmpty);
|
||||
if (count($files) > 1 && strlen($fs->getFullpath()) > 0) {
|
||||
throw new BuildException("fullpath attribute may only "
|
||||
. "be specified for "
|
||||
. "filesets that specify a "
|
||||
. "single file.");
|
||||
}
|
||||
$fsBasedir = $fs->getDir($this->project);
|
||||
$filesToTar = array();
|
||||
for ($i=0, $fcount=count($files); $i < $fcount; $i++) {
|
||||
$f = new PhingFile($fsBasedir, $files[$i]);
|
||||
$filesToTar[] = $f->getAbsolutePath();
|
||||
$this->log("Adding file " . $f->getPath() . " to archive.", Project::MSG_VERBOSE);
|
||||
}
|
||||
$tar->addModify($filesToTar, $this->prefix, $fsBasedir->getAbsolutePath());
|
||||
}
|
||||
|
||||
|
||||
} catch (IOException $ioe) {
|
||||
$msg = "Problem creating TAR: " . $ioe->getMessage();
|
||||
$this->filesets = $savedFileSets;
|
||||
throw new BuildException($msg, $ioe, $this->getLocation());
|
||||
}
|
||||
|
||||
$this->filesets = $savedFileSets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $files array of filenames
|
||||
* @param PhingFile $dir
|
||||
* @return boolean
|
||||
*/
|
||||
protected function archiveIsUpToDate($files, $dir) {
|
||||
$sfs = new SourceFileScanner($this);
|
||||
$mm = new MergeMapper();
|
||||
$mm->setTo($this->tarFile->getAbsolutePath());
|
||||
return count($sfs->restrict($files, $dir, null, $mm)) == 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This is a FileSet with the option to specify permissions.
|
||||
*
|
||||
* Permissions are currently not implemented by PEAR Archive_Tar,
|
||||
* but hopefully they will be in the future.
|
||||
*
|
||||
*/
|
||||
class TarFileSet extends FileSet {
|
||||
|
||||
private $files = null;
|
||||
|
||||
private $mode = 0100644;
|
||||
|
||||
private $userName = "";
|
||||
private $groupName = "";
|
||||
private $prefix = "";
|
||||
private $fullpath = "";
|
||||
private $preserveLeadingSlashes = false;
|
||||
|
||||
/**
|
||||
* Get a list of files and directories specified in the fileset.
|
||||
* @return array a list of file and directory names, relative to
|
||||
* the baseDir for the project.
|
||||
*/
|
||||
public function getFiles(Project $p, $includeEmpty = true) {
|
||||
|
||||
if ($this->files === null) {
|
||||
|
||||
$ds = $this->getDirectoryScanner($p);
|
||||
$this->files = $ds->getIncludedFiles();
|
||||
|
||||
if ($includeEmpty) {
|
||||
|
||||
// first any empty directories that will not be implicitly added by any of the files
|
||||
$implicitDirs = array();
|
||||
foreach($this->files as $file) {
|
||||
$implicitDirs[] = dirname($file);
|
||||
}
|
||||
|
||||
$incDirs = $ds->getIncludedDirectories();
|
||||
|
||||
// we'll need to add to that list of implicit dirs any directories
|
||||
// that contain other *directories* (and not files), since otherwise
|
||||
// we get duplicate directories in the resulting tar
|
||||
foreach($incDirs as $dir) {
|
||||
foreach($incDirs as $dircheck) {
|
||||
if (!empty($dir) && $dir == dirname($dircheck)) {
|
||||
$implicitDirs[] = $dir;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$implicitDirs = array_unique($implicitDirs);
|
||||
|
||||
// Now add any empty dirs (dirs not covered by the implicit dirs)
|
||||
// to the files array.
|
||||
|
||||
foreach($incDirs as $dir) { // we cannot simply use array_diff() since we want to disregard empty/. dirs
|
||||
if ($dir != "" && $dir != "." && !in_array($dir, $implicitDirs)) {
|
||||
// it's an empty dir, so we'll add it.
|
||||
$this->files[] = $dir;
|
||||
}
|
||||
}
|
||||
} // if $includeEmpty
|
||||
|
||||
} // if ($this->files===null)
|
||||
|
||||
return $this->files;
|
||||
}
|
||||
|
||||
/**
|
||||
* A 3 digit octal string, specify the user, group and
|
||||
* other modes in the standard Unix fashion;
|
||||
* optional, default=0644
|
||||
* @param string $octalString
|
||||
*/
|
||||
public function setMode($octalString) {
|
||||
$octal = (int) $octalString;
|
||||
$this->mode = 0100000 | $octal;
|
||||
}
|
||||
|
||||
public function getMode() {
|
||||
return $this->mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* The username for the tar entry
|
||||
* This is not the same as the UID, which is
|
||||
* not currently set by the task.
|
||||
*/
|
||||
public function setUserName($userName) {
|
||||
$this->userName = $userName;
|
||||
}
|
||||
|
||||
public function getUserName() {
|
||||
return $this->userName;
|
||||
}
|
||||
|
||||
/**
|
||||
* The groupname for the tar entry; optional, default=""
|
||||
* This is not the same as the GID, which is
|
||||
* not currently set by the task.
|
||||
*/
|
||||
public function setGroup($groupName) {
|
||||
$this->groupName = $groupName;
|
||||
}
|
||||
|
||||
public function getGroup() {
|
||||
return $this->groupName;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the prefix attribute is set, all files in the fileset
|
||||
* are prefixed with that path in the archive.
|
||||
* optional.
|
||||
*/
|
||||
public function setPrefix($prefix) {
|
||||
$this->prefix = $prefix;
|
||||
}
|
||||
|
||||
public function getPrefix() {
|
||||
return $this->prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the fullpath attribute is set, the file in the fileset
|
||||
* is written with that path in the archive. The prefix attribute,
|
||||
* if specified, is ignored. It is an error to have more than one file specified in
|
||||
* such a fileset.
|
||||
*/
|
||||
public function setFullpath($fullpath) {
|
||||
$this->fullpath = $fullpath;
|
||||
}
|
||||
|
||||
public function getFullpath() {
|
||||
return $this->fullpath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flag to indicates whether leading `/'s should
|
||||
* be preserved in the file names.
|
||||
* Optional, default is <code>false</code>.
|
||||
* @return void
|
||||
*/
|
||||
public function setPreserveLeadingSlashes($b) {
|
||||
$this->preserveLeadingSlashes = (boolean) $b;
|
||||
}
|
||||
|
||||
public function getPreserveLeadingSlashes() {
|
||||
return $this->preserveLeadingSlashes;
|
||||
}
|
||||
}
|
89
airtime_mvc/library/phing/tasks/ext/UntarTask.php
Normal file
89
airtime_mvc/library/phing/tasks/ext/UntarTask.php
Normal file
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
/*
|
||||
*
|
||||
* 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/tasks/ext/ExtractBaseTask.php';
|
||||
|
||||
/**
|
||||
* Extracts one or several tar archives using PEAR Archive_Tar
|
||||
*
|
||||
* @author Joakim Bodin <joakim.bodin+phing@gmail.com>
|
||||
* @version $Id: UntarTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext
|
||||
* @since 2.2.0
|
||||
*/
|
||||
class UntarTask extends ExtractBaseTask {
|
||||
|
||||
/**
|
||||
* Ensures that PEAR lib exists.
|
||||
*/
|
||||
public function init() {
|
||||
include_once 'Archive/Tar.php';
|
||||
if (!class_exists('Archive_Tar')) {
|
||||
throw new BuildException("You must have installed the PEAR Archive_Tar class in order to use UntarTask.");
|
||||
}
|
||||
}
|
||||
|
||||
protected function extractArchive(PhingFile $tarfile)
|
||||
{
|
||||
$this->log("Extracting tar file: " . $tarfile->__toString() . ' to ' . $this->todir->__toString(), Project::MSG_INFO);
|
||||
|
||||
try {
|
||||
$tar = $this->initTar($tarfile);
|
||||
if(!$tar->extractModify($this->todir->getAbsolutePath(), $this->removepath)) {
|
||||
throw new BuildException('Failed to extract tar file: ' . $tarfile->getAbsolutePath());
|
||||
}
|
||||
} catch (IOException $ioe) {
|
||||
$msg = "Could not extract tar file: " . $ioe->getMessage();
|
||||
throw new BuildException($msg, $ioe, $this->getLocation());
|
||||
}
|
||||
}
|
||||
|
||||
protected function listArchiveContent(PhingFile $tarfile)
|
||||
{
|
||||
$tar = $this->initTar($tarfile);
|
||||
return $tar->listContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Init a Archive_Tar class with correct compression for the given file.
|
||||
*
|
||||
* @param PhingFile $tarfile
|
||||
* @return Archive_Tar the tar class instance
|
||||
*/
|
||||
private function initTar(PhingFile $tarfile)
|
||||
{
|
||||
$compression = null;
|
||||
$tarfileName = $tarfile->getName();
|
||||
$mode = strtolower(substr($tarfileName, strrpos($tarfileName, '.')));
|
||||
|
||||
$compressions = array(
|
||||
'gz' => array('.gz', '.tgz',),
|
||||
'bz2' => array('.bz2',),
|
||||
);
|
||||
foreach ($compressions as $algo => $ext) {
|
||||
if (array_search($mode, $ext) !== false) {
|
||||
$compression = $algo;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return new Archive_Tar($tarfile->getAbsolutePath(), $compression);
|
||||
}
|
||||
}
|
77
airtime_mvc/library/phing/tasks/ext/UnzipTask.php
Normal file
77
airtime_mvc/library/phing/tasks/ext/UnzipTask.php
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
/*
|
||||
*
|
||||
* 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/tasks/ext/ExtractBaseTask.php';
|
||||
require_once 'phing/system/io/FileSystem.php';
|
||||
|
||||
/**
|
||||
* Extracts one or several zip archives using ZipArchive class.
|
||||
*
|
||||
* @author Joakim Bodin <joakim.bodin+phing@gmail.com>
|
||||
* @author George Miroshnikov <laggy.luke@gmail.com>
|
||||
* @version $Id: UnzipTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext
|
||||
*/
|
||||
class UnzipTask extends ExtractBaseTask
|
||||
{
|
||||
/**
|
||||
* Extract archive content into $this->todir directory
|
||||
* @param PhingFile Zip file to extract
|
||||
* @return boolean
|
||||
*/
|
||||
protected function extractArchive(PhingFile $zipfile)
|
||||
{
|
||||
$this->log("Extracting zip: " . $zipfile->__toString() . ' to ' . $this->todir->__toString(), Project::MSG_INFO);
|
||||
|
||||
$zip = new ZipArchive();
|
||||
|
||||
$result = $zip->open($zipfile->getAbsolutePath());
|
||||
if (!$result) {
|
||||
$this->log("Unable to open zipfile " . $zipfile->__toString(), Project::MSG_ERR);
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = $zip->extractTo($this->todir->getAbsolutePath());
|
||||
if (!$result) {
|
||||
$this->log("Unable to extract zipfile " . $zipfile->__toString(), Project::MSG_ERR);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* List archive content
|
||||
* @param PhingFile Zip file to list content
|
||||
* @return array List of files inside $zipfile
|
||||
*/
|
||||
protected function listArchiveContent(PhingFile $zipfile)
|
||||
{
|
||||
$zip = new ZipArchive();
|
||||
$zip->open($zipfile->getAbsolutePath());
|
||||
|
||||
$content = array();
|
||||
for ($i = 0; $i < $zip->numFiles; $i++) {
|
||||
$content[] = $zip->getNameIndex($i);
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
|
217
airtime_mvc/library/phing/tasks/ext/VersionTask.php
Normal file
217
airtime_mvc/library/phing/tasks/ext/VersionTask.php
Normal file
|
@ -0,0 +1,217 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: VersionTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
|
||||
/**
|
||||
* VersionTask
|
||||
*
|
||||
* Increments a three-part version number from a given file
|
||||
* and writes it back to the file.
|
||||
* Incrementing is based on given releasetype, which can be one
|
||||
* of Major, Minor and Bugfix.
|
||||
* Resulting version number is also published under supplied property.
|
||||
*
|
||||
* @author Mike Wittje <mw@mike.wittje.de>
|
||||
* @version $Id: VersionTask.php 905 2010-10-05 16:28:03Z mrook $ $Rev $Revision: 905 $ $Date: 2010-10-05 18:28:03 +0200 (Tue, 05 Oct 2010) $ $Author: mrook $
|
||||
* @package phing.tasks.ext
|
||||
*/
|
||||
class VersionTask extends Task
|
||||
{
|
||||
/**
|
||||
* Property for Releasetype
|
||||
* @var string $releasetype
|
||||
*/
|
||||
private $releasetype;
|
||||
|
||||
/**
|
||||
* Property for File
|
||||
* @var PhingFile file
|
||||
*/
|
||||
private $file;
|
||||
|
||||
/**
|
||||
* Property to be set
|
||||
* @var string $property
|
||||
*/
|
||||
private $property;
|
||||
|
||||
/* Allowed Releastypes */
|
||||
const RELEASETYPE_MAJOR = 'MAJOR';
|
||||
const RELEASETYPE_MINOR = 'MINOR';
|
||||
const RELEASETYPE_BUGFIX = 'BUGFIX';
|
||||
|
||||
/**
|
||||
* Set Property for Releasetype (Minor, Major, Bugfix)
|
||||
* @param string $releasetype
|
||||
*/
|
||||
public function setReleasetype($releasetype)
|
||||
{
|
||||
$this->releasetype = strtoupper($releasetype);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Property for File containing versioninformation
|
||||
* @param PhingFile $file
|
||||
*/
|
||||
public function setFile($file)
|
||||
{
|
||||
$this->file = $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set
|
||||
* @param $property
|
||||
* @return
|
||||
*/
|
||||
public function setProperty($property)
|
||||
{
|
||||
$this->property = $property;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main-Method for the Task
|
||||
*
|
||||
* @return void
|
||||
* @throws BuildException
|
||||
*/
|
||||
public function main()
|
||||
{
|
||||
// check supplied attributes
|
||||
$this->checkReleasetype();
|
||||
$this->checkFile();
|
||||
$this->checkProperty();
|
||||
|
||||
// read file
|
||||
$filecontent = file_get_contents($this->file);
|
||||
|
||||
// get new version
|
||||
$newVersion = $this->getVersion($filecontent);
|
||||
|
||||
// write new Version to file
|
||||
file_put_contents($this->file, $newVersion);
|
||||
|
||||
// publish new version number as property
|
||||
$this->project->setProperty($this->property, $newVersion);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new version number corresponding to Release type
|
||||
*
|
||||
* @param string $filecontent
|
||||
* @return string
|
||||
*/
|
||||
private function getVersion($filecontent)
|
||||
{
|
||||
// init
|
||||
$newVersion = '';
|
||||
|
||||
// Extract version
|
||||
list($major, $minor, $bugfix) = explode(".", $filecontent);
|
||||
|
||||
// Return new version number
|
||||
switch ($this->releasetype) {
|
||||
case self::RELEASETYPE_MAJOR:
|
||||
$newVersion = sprintf("%d.%d.%d", ++$major,
|
||||
0,
|
||||
0);
|
||||
break;
|
||||
|
||||
case self::RELEASETYPE_MINOR:
|
||||
$newVersion = sprintf("%d.%d.%d", $major,
|
||||
++$minor,
|
||||
0);
|
||||
break;
|
||||
|
||||
case self::RELEASETYPE_BUGFIX:
|
||||
$newVersion = sprintf("%d.%d.%d", $major,
|
||||
$minor,
|
||||
++$bugfix);
|
||||
break;
|
||||
}
|
||||
|
||||
return $newVersion;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* checks releasetype attribute
|
||||
* @return void
|
||||
* @throws BuildException
|
||||
*/
|
||||
private function checkReleasetype()
|
||||
{
|
||||
// check Releasetype
|
||||
if (is_null($this->releasetype)) {
|
||||
throw new BuildException('releasetype attribute is required', $this->location);
|
||||
}
|
||||
// known releasetypes
|
||||
$releaseTypes = array(
|
||||
self::RELEASETYPE_MAJOR,
|
||||
self::RELEASETYPE_MINOR,
|
||||
self::RELEASETYPE_BUGFIX
|
||||
);
|
||||
|
||||
if (!in_array($this->releasetype, $releaseTypes)) {
|
||||
throw new BuildException(sprintf('Unknown Releasetype %s..Must be one of Major, Minor or Bugfix',
|
||||
$this->releasetype), $this->location);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* checks file attribute
|
||||
* @return void
|
||||
* @throws BuildException
|
||||
*/
|
||||
private function checkFile()
|
||||
{
|
||||
// check File
|
||||
if ($this->file === null ||
|
||||
strlen($this->file) == 0) {
|
||||
throw new BuildException('You must specify a file containing the version number', $this->location);
|
||||
}
|
||||
|
||||
$content = file_get_contents($this->file);
|
||||
if (strlen($content) == 0) {
|
||||
throw new BuildException(sprintf('Supplied file %s is empty', $this->file), $this->location);
|
||||
}
|
||||
|
||||
// check for three-part number
|
||||
$split = explode('.', $content);
|
||||
if (count($split) !== 3) {
|
||||
throw new BuildException('Unknown version number format', $this->location);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* checks property attribute
|
||||
* @return void
|
||||
* @throws BuildException
|
||||
*/
|
||||
private function checkProperty()
|
||||
{
|
||||
if (is_null($this->property) ||
|
||||
strlen($this->property) === 0) {
|
||||
throw new BuildException('Property for publishing version number is not set', $this->location);
|
||||
}
|
||||
}
|
||||
}
|
136
airtime_mvc/library/phing/tasks/ext/XmlLintTask.php
Normal file
136
airtime_mvc/library/phing/tasks/ext/XmlLintTask.php
Normal file
|
@ -0,0 +1,136 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: XmlLintTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
|
||||
/**
|
||||
* A XML lint task. Checking syntax of one or more XML files against an XML Schema using the DOM extension.
|
||||
*
|
||||
* @author Knut Urdalen <knut.urdalen@telio.no>
|
||||
* @version $Id: XmlLintTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext
|
||||
*/
|
||||
class XmlLintTask extends Task {
|
||||
|
||||
protected $file; // the source file (from xml attribute)
|
||||
protected $schema; // the schema file (from xml attribute)
|
||||
protected $filesets = array(); // all fileset objects assigned to this task
|
||||
|
||||
/**
|
||||
* File to be performed syntax check on
|
||||
*
|
||||
* @param PhingFile $file
|
||||
*/
|
||||
public function setFile(PhingFile $file) {
|
||||
$this->file = $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* XML Schema Description file to validate against
|
||||
*
|
||||
* @param PhingFile $schema
|
||||
*/
|
||||
public function setSchema(PhingFile $schema) {
|
||||
$this->schema = $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Nested creator, creates a FileSet for this task
|
||||
*
|
||||
* @return FileSet The created fileset object
|
||||
*/
|
||||
function createFileSet() {
|
||||
$num = array_push($this->filesets, new FileSet());
|
||||
return $this->filesets[$num-1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute lint check against PhingFile or a FileSet
|
||||
*/
|
||||
public function main() {
|
||||
if(!isset($this->schema)) {
|
||||
throw new BuildException("Missing attribute 'schema'");
|
||||
}
|
||||
$schema = $this->schema->getPath();
|
||||
if(!file_exists($schema)) {
|
||||
throw new BuildException("File not found: ".$schema);
|
||||
}
|
||||
if(!isset($this->file) and count($this->filesets) == 0) {
|
||||
throw new BuildException("Missing either a nested fileset or attribute 'file' set");
|
||||
}
|
||||
|
||||
set_error_handler(array($this, 'errorHandler'));
|
||||
if($this->file instanceof PhingFile) {
|
||||
$this->lint($this->file->getPath());
|
||||
} else { // process filesets
|
||||
$project = $this->getProject();
|
||||
foreach($this->filesets as $fs) {
|
||||
$ds = $fs->getDirectoryScanner($project);
|
||||
$files = $ds->getIncludedFiles();
|
||||
$dir = $fs->getDir($this->project)->getPath();
|
||||
foreach($files as $file) {
|
||||
$this->lint($dir.DIRECTORY_SEPARATOR.$file);
|
||||
}
|
||||
}
|
||||
}
|
||||
restore_error_handler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs validation
|
||||
*
|
||||
* @param string $file
|
||||
* @return void
|
||||
*/
|
||||
protected function lint($file) {
|
||||
if(file_exists($file)) {
|
||||
if(is_readable($file)) {
|
||||
$dom = new DOMDocument();
|
||||
$dom->load($file);
|
||||
if($dom->schemaValidate($this->schema->getPath())) {
|
||||
$this->log($file.' validated', Project::MSG_INFO);
|
||||
} else {
|
||||
$this->log($file.' fails to validate (See messages above)', Project::MSG_ERR);
|
||||
}
|
||||
} else {
|
||||
throw new BuildException('Permission denied: '.$file);
|
||||
}
|
||||
} else {
|
||||
throw new BuildException('File not found: '.$file);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Local error handler to catch validation errors and log them through Phing
|
||||
*
|
||||
* @param int $level
|
||||
* @param string $message
|
||||
* @param string $file
|
||||
* @param int $line
|
||||
*/
|
||||
public function errorHandler($level, $message, $file, $line, $context) {
|
||||
$matches = array();
|
||||
preg_match('/^.*\(\): (.*)$/', $message, $matches);
|
||||
$this->log($matches[1], Project::MSG_ERR);
|
||||
}
|
||||
|
||||
}
|
||||
|
247
airtime_mvc/library/phing/tasks/ext/XmlPropertyTask.php
Normal file
247
airtime_mvc/library/phing/tasks/ext/XmlPropertyTask.php
Normal file
|
@ -0,0 +1,247 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* $Id: XmlPropertyTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
include_once 'phing/tasks/system/PropertyTask.php';
|
||||
|
||||
/**
|
||||
* Task for setting properties from an XML file in buildfiles.
|
||||
*
|
||||
* @author Jonathan Bond-Caron <jbondc@openmv.com>
|
||||
* @version $Revision: 905 $
|
||||
* @package phing.tasks.ext
|
||||
* @since 2.4.0
|
||||
* @see http://ant.apache.org/manual/CoreTasks/xmlproperty.html
|
||||
*/
|
||||
class XmlPropertyTask extends PropertyTask {
|
||||
|
||||
private $_keepRoot = true;
|
||||
private $_collapseAttr = false;
|
||||
private $_delimiter = ',';
|
||||
|
||||
/** Set a file to use as the source for properties. */
|
||||
function setFile($file) {
|
||||
if (is_string($file)) {
|
||||
$file = new PhingFile($file);
|
||||
}
|
||||
$this->file = $file;
|
||||
}
|
||||
|
||||
/** Get the PhingFile that is being used as property source. */
|
||||
function getFile() {
|
||||
return $this->file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefix to apply to properties loaded using <code>file</code>.
|
||||
* A "." is appended to the prefix if not specified.
|
||||
* @param string $prefix prefix string
|
||||
* @return void
|
||||
* @since 2.0
|
||||
*/
|
||||
function setPrefix($prefix) {
|
||||
$this->prefix = $prefix;
|
||||
if (!StringHelper::endsWith(".", $prefix)) {
|
||||
$this->prefix .= ".";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @since 2.0
|
||||
*/
|
||||
function getPrefix() {
|
||||
return $this->prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep the xml root tag as the first value in the property name
|
||||
*
|
||||
* @param bool $yesNo
|
||||
*/
|
||||
function setKeepRoot($yesNo) {
|
||||
$this->_keepRoot = (bool)$yesNo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
function getKeepRoot() {
|
||||
return $this->_keepRoot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Treat attributes as nested elements.
|
||||
*
|
||||
* @param bool $yesNo
|
||||
*/
|
||||
function setCollapseAttributes($yesNo) {
|
||||
$this->_collapseAttr = (bool)$yesNo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
function getCollapseAttributes() {
|
||||
return $this->_collapseAttr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delimiter for splitting multiple values.
|
||||
*
|
||||
* @param string $d
|
||||
*/
|
||||
function setDelimiter($d) {
|
||||
$this->_delimiter = $d;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function getDelimiter() {
|
||||
return $this->_delimiter;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the property in the project to the value.
|
||||
* if the task was give a file or env attribute
|
||||
* here is where it is loaded
|
||||
*/
|
||||
function main() {
|
||||
|
||||
if ($this->file === null ) {
|
||||
throw new BuildException("You must specify file to load properties from", $this->getLocation());
|
||||
}
|
||||
|
||||
$this->loadFile($this->file);
|
||||
}
|
||||
|
||||
/**
|
||||
* load properties from an XML file.
|
||||
* @param PhingFile $file
|
||||
*/
|
||||
protected function loadFile(PhingFile $file) {
|
||||
$props = new Properties();
|
||||
$this->log("Loading ". $file->getAbsolutePath(), Project::MSG_INFO);
|
||||
try { // try to load file
|
||||
if ($file->exists()) {
|
||||
|
||||
$this->addProperties($this->_getProperties($file));
|
||||
|
||||
} else {
|
||||
$this->log("Unable to find property file: ". $file->getAbsolutePath() ."... skipped", Project::MSG_WARN);
|
||||
}
|
||||
} catch (IOException $ioe) {
|
||||
throw new BuildException("Could not load properties from file.", $ioe);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an XML file and returns properties
|
||||
*
|
||||
* @param string $filePath
|
||||
*
|
||||
* @return Properties
|
||||
*/
|
||||
protected function _getProperties($filePath) {
|
||||
|
||||
// load() already made sure that file is readable
|
||||
// but we'll double check that when reading the file into
|
||||
// an array
|
||||
|
||||
if (($lines = @file($filePath)) === false) {
|
||||
throw new IOException("Unable to parse contents of $filePath");
|
||||
}
|
||||
|
||||
$prop = new Properties;
|
||||
|
||||
$xml = simplexml_load_file($filePath);
|
||||
|
||||
if($xml === false)
|
||||
throw new IOException("Unable to parse XML file $filePath");
|
||||
|
||||
$path = array();
|
||||
|
||||
if($this->_keepRoot) {
|
||||
$path[] = dom_import_simplexml($xml)->tagName;
|
||||
}
|
||||
|
||||
$this->_addNode($xml, $path, $prop);
|
||||
|
||||
return $prop;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an XML node
|
||||
*
|
||||
* @param SimpleXMLElement $node
|
||||
* @param array $path Path to this node
|
||||
* @param Properties $prop Properties will be added as they are found (by reference here)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _addNode($node, $path, $prop) {
|
||||
|
||||
foreach($node as $tag => $value) {
|
||||
|
||||
$prefix = implode('.', $path);
|
||||
|
||||
|
||||
// Check for attributes
|
||||
foreach($value->attributes() as $attribute => $val) {
|
||||
|
||||
if($this->_collapseAttr)
|
||||
$prop->setProperty($prefix . ".$attribute", (string)$val);
|
||||
else
|
||||
$prop->setProperty($prefix . "($attribute)", (string)$val);
|
||||
}
|
||||
|
||||
//echo "\r\nCHILDREN ". count($value->children()). is_array($value);
|
||||
// Add tag
|
||||
if(count($value->children())) {
|
||||
|
||||
//echo "\r\nOBJECT $prefix.$tag ";
|
||||
|
||||
$path[] = $tag;
|
||||
$this->_addNode($value, $path, $prop);
|
||||
|
||||
} else {
|
||||
//echo "\r\nADD $prefix.$tag";
|
||||
|
||||
$val = (string)$value;
|
||||
|
||||
/* Check for * and ** on 'exclude' and 'include' tag / ant seems to do this? could use FileSet here
|
||||
if($tag == 'exclude') {
|
||||
}*/
|
||||
|
||||
// When property already exists, i.e. multiple xml tag
|
||||
// <project>
|
||||
// <exclude>file/a.php</exclude>
|
||||
// <exclude>file/a.php</exclude>
|
||||
// </project>
|
||||
//
|
||||
// Would be come project.exclude = file/a.php,file/a.php
|
||||
$p = empty($prefix) ? $tag : $prefix . ".$tag";
|
||||
$prop->append($p, (string)$val, $this->_delimiter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
207
airtime_mvc/library/phing/tasks/ext/ZendCodeAnalyzerTask.php
Normal file
207
airtime_mvc/library/phing/tasks/ext/ZendCodeAnalyzerTask.php
Normal file
|
@ -0,0 +1,207 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: ZendCodeAnalyzerTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
|
||||
/**
|
||||
* ZendCodeAnalyzerTask analyze PHP source code using the ZendCodeAnalyzer included in Zend Studio 5.1
|
||||
*
|
||||
* Available warnings:
|
||||
* <b>zend-error</b> - %s(line %d): %s
|
||||
* <b>oneline-comment</b> - One-line comment ends with tag.
|
||||
* <b>bool-assign</b> - Assignment seen where boolean expression is expected. Did you mean '==' instead of '='?
|
||||
* <b>bool-print</b> - Print statement used when boolean expression is expected.
|
||||
* <b>bool-array</b> - Array used when boolean expression is expected.
|
||||
* <b>bool-object</b> - Object used when boolean expression is expected.
|
||||
* <b>call-time-ref</b> - Call-time reference is deprecated. Define function as accepting parameter by reference instead.
|
||||
* <b>if-if-else</b> - In if-if-else construction else relates to the closest if. Use braces to make the code clearer.
|
||||
* <b>define-params</b> - define() requires two or three parameters.
|
||||
* <b>define-const</b> - First parameter for define() should be string. Maybe you forgot quotes?
|
||||
* <b>break-var</b> - Break/continue with variable is dangerous - break level can be out of scope.
|
||||
* <b>break-depth</b> - Break/continue with depth more than current nesting level.
|
||||
* <b>var-once</b> - Variable '%s' encountered only once. May be a typo?
|
||||
* <b>var-arg-unused</b> - Function argument '%s' is never used.
|
||||
* <b>var-global-unused</b> - Global variable '%s' is defined but never used.
|
||||
* <b>var-use-before-def</b> - Variable '%s' is used before it was assigned.
|
||||
* <b>var-use-before-def-global</b> - Global variable '%s' is used without being assigned. You are probably relying on register_globals feature of PHP. Note that this feature is off by default.
|
||||
* <b>var-no-global</b> - PHP global variable '%s' is used as local. Maybe you wanted to define '%s' as global?
|
||||
* <b>var-value-unused</b> - Value assigned to variable '%s' is never used
|
||||
* <b>var-ref-notmodified</b> - Function parameter '%s' is passed by reference but never modified. Consider passing by value.
|
||||
* <b>return-empty-val</b> - Function '%s' has both empty return and return with value.
|
||||
* <b>return-empty-used</b> - Function '%s' has empty return but return value is used.
|
||||
* <b>return-noref</b> - Function '%s' returns reference but the value is not assigned by reference. Maybe you meant '=&' instead of '='?
|
||||
* <b>return-end-used</b> - Control reaches the end of function '%s'(file %s, line %d) but return value is used.
|
||||
* <b>sprintf-miss-args</b> - Missing arguments for sprintf: format reqires %d arguments but %d are supplied.
|
||||
* <b>sprintf-extra-args</b> - Extra arguments for sprintf: format reqires %d arguments but %d are supplied.
|
||||
* <b>unreach-code</b> - Unreachable code in function '%s'.
|
||||
* <b>include-var</b> - include/require with user-accessible variable can be dangerous. Consider using constant instead.
|
||||
* <b>non-object</b> - Variable '%s' used as object, but has different type.
|
||||
* <b>bad-escape</b> - Bad escape sequence: \%c, did you mean \\%c?
|
||||
* <b>empty-cond</b> - Condition without a body
|
||||
* <b>expr-unused</b> - Expression result is never used
|
||||
*
|
||||
* @author Knut Urdalen <knut.urdalen@gmail.com>
|
||||
* @version $Id: ZendCodeAnalyzerTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext
|
||||
*/
|
||||
class ZendCodeAnalyzerTask extends Task
|
||||
{
|
||||
protected $analyzerPath = ""; // Path to ZendCodeAnalyzer binary
|
||||
protected $file = ""; // the source file (from xml attribute)
|
||||
protected $filesets = array(); // all fileset objects assigned to this task
|
||||
protected $counter = 0;
|
||||
protected $disable = array();
|
||||
protected $enable = array();
|
||||
|
||||
private $haltonwarning = false;
|
||||
|
||||
/**
|
||||
* File to be analyzed
|
||||
*
|
||||
* @param PhingFile $file
|
||||
*/
|
||||
public function setFile(PhingFile $file) {
|
||||
$this->file = $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Path to ZendCodeAnalyzer binary
|
||||
*
|
||||
* @param string $analyzerPath
|
||||
*/
|
||||
public function setAnalyzerPath($analyzerPath) {
|
||||
$this->analyzerPath = $analyzerPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable warning levels. Seperate warning levels with ','
|
||||
*
|
||||
* @param string $disable
|
||||
*/
|
||||
public function setDisable($disable) {
|
||||
$this->disable = explode(",", $disable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable warning levels. Seperate warning levels with ','
|
||||
*
|
||||
* @param string $enable
|
||||
*/
|
||||
public function setEnable($enable) {
|
||||
$this->enable = explode(",", $enable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the haltonwarning flag
|
||||
* @param boolean $value
|
||||
*/
|
||||
function setHaltonwarning($value)
|
||||
{
|
||||
$this->haltonwarning = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Nested creator, creates a FileSet for this task
|
||||
*
|
||||
* @return FileSet The created fileset object
|
||||
*/
|
||||
function createFileSet() {
|
||||
$num = array_push($this->filesets, new FileSet());
|
||||
return $this->filesets[$num-1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyze against PhingFile or a FileSet
|
||||
*/
|
||||
public function main() {
|
||||
if(!isset($this->analyzerPath)) {
|
||||
throw new BuildException("Missing attribute 'analyzerPath'");
|
||||
}
|
||||
|
||||
if(!isset($this->file) and count($this->filesets) == 0) {
|
||||
throw new BuildException("Missing either a nested fileset or attribute 'file' set");
|
||||
}
|
||||
|
||||
if($this->file instanceof PhingFile) {
|
||||
$this->analyze($this->file->getPath());
|
||||
} else { // process filesets
|
||||
$project = $this->getProject();
|
||||
|
||||
foreach($this->filesets as $fs) {
|
||||
$ds = $fs->getDirectoryScanner($project);
|
||||
$files = $ds->getIncludedFiles();
|
||||
$dir = $fs->getDir($this->project)->getPath();
|
||||
|
||||
foreach($files as $file) {
|
||||
$this->analyze($dir.DIRECTORY_SEPARATOR.$file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->log("Number of findings: ".$this->counter, Project::MSG_INFO);
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyze file
|
||||
*
|
||||
* @param string $file
|
||||
* @return void
|
||||
*/
|
||||
protected function analyze($file) {
|
||||
if(file_exists($file)) {
|
||||
if(is_readable($file)) {
|
||||
// Construct shell command
|
||||
$cmd = $this->analyzerPath." ";
|
||||
|
||||
foreach($this->enable as $enable) { // Enable warning levels
|
||||
$cmd .= " --enable $enable ";
|
||||
}
|
||||
|
||||
foreach($this->disable as $disable) { // Disable warning levels
|
||||
$cmd .= " --disable $disable ";
|
||||
}
|
||||
|
||||
$cmd .= "$file 2>&1";
|
||||
|
||||
// Execute command
|
||||
$result = shell_exec($cmd);
|
||||
$result = explode("\n", $result);
|
||||
|
||||
for($i=2, $size=count($result); $i<($size-1); $i++) {
|
||||
$this->counter++;
|
||||
$this->log($result[$i], Project::MSG_WARN);
|
||||
}
|
||||
|
||||
$total = count($result) - 3;
|
||||
|
||||
if ($total > 0 && $this->haltonwarning) {
|
||||
throw new BuildException('zendcodeanalyzer detected ' . $total . ' warning' . ($total > 1 ? 's' : '') . ' in ' . $file);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BuildException('Permission denied: '.$file);
|
||||
}
|
||||
} else {
|
||||
throw new BuildException('File not found: '.$file);
|
||||
}
|
||||
}
|
||||
}
|
300
airtime_mvc/library/phing/tasks/ext/ZipTask.php
Normal file
300
airtime_mvc/library/phing/tasks/ext/ZipTask.php
Normal file
|
@ -0,0 +1,300 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: ZipTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/tasks/system/MatchingTask.php';
|
||||
include_once 'phing/util/SourceFileScanner.php';
|
||||
include_once 'phing/mappers/MergeMapper.php';
|
||||
include_once 'phing/util/StringHelper.php';
|
||||
|
||||
/**
|
||||
* Creates a zip archive using PHP ZipArchive extension/
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: ZipTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class ZipTask extends MatchingTask {
|
||||
|
||||
/**
|
||||
* @var PhingFile
|
||||
*/
|
||||
private $zipFile;
|
||||
|
||||
/**
|
||||
* @var PhingFile
|
||||
*/
|
||||
private $baseDir;
|
||||
|
||||
/**
|
||||
* Whether to include empty dirs in the archive.
|
||||
*/
|
||||
private $includeEmpty = true;
|
||||
|
||||
private $filesets = array();
|
||||
private $fileSetFiles = array();
|
||||
|
||||
/**
|
||||
* File path prefix in zip archive
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $prefix = null;
|
||||
|
||||
/**
|
||||
* Add a new fileset.
|
||||
* @return FileSet
|
||||
*/
|
||||
public function createFileSet() {
|
||||
$this->fileset = new ZipFileSet();
|
||||
$this->filesets[] = $this->fileset;
|
||||
return $this->fileset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set is the name/location of where to create the zip file.
|
||||
* @param PhingFile $destFile The output of the zip
|
||||
*/
|
||||
public function setDestFile(PhingFile $destFile) {
|
||||
$this->zipFile = $destFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the base directory to look in for things to zip.
|
||||
* @param PhingFile $baseDir
|
||||
*/
|
||||
public function setBasedir(PhingFile $baseDir) {
|
||||
$this->baseDir = $baseDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the file path prefix for file in the zip file.
|
||||
*
|
||||
* @param string $prefix Prefix
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setPrefix($prefix) {
|
||||
$this->prefix = $prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the include empty dirs flag.
|
||||
* @param boolean Flag if empty dirs should be tarred too
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function setIncludeEmptyDirs($bool) {
|
||||
$this->includeEmpty = (boolean) $bool;
|
||||
}
|
||||
|
||||
/**
|
||||
* do the work
|
||||
* @throws BuildException
|
||||
*/
|
||||
public function main() {
|
||||
|
||||
if ($this->zipFile === null) {
|
||||
throw new BuildException("zipfile attribute must be set!", $this->getLocation());
|
||||
}
|
||||
|
||||
if ($this->zipFile->exists() && $this->zipFile->isDirectory()) {
|
||||
throw new BuildException("zipfile is a directory!", $this->getLocation());
|
||||
}
|
||||
|
||||
if ($this->zipFile->exists() && !$this->zipFile->canWrite()) {
|
||||
throw new BuildException("Can not write to the specified zipfile!", $this->getLocation());
|
||||
}
|
||||
|
||||
// shouldn't need to clone, since the entries in filesets
|
||||
// themselves won't be modified -- only elements will be added
|
||||
$savedFileSets = $this->filesets;
|
||||
|
||||
try {
|
||||
if ($this->baseDir !== null) {
|
||||
if (!$this->baseDir->exists()) {
|
||||
throw new BuildException("basedir does not exist!", $this->getLocation());
|
||||
}
|
||||
|
||||
if (empty($this->filesets))
|
||||
{
|
||||
// add the main fileset to the list of filesets to process.
|
||||
$mainFileSet = new ZipFileSet($this->fileset);
|
||||
$mainFileSet->setDir($this->baseDir);
|
||||
$this->filesets[] = $mainFileSet;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($this->filesets)) {
|
||||
throw new BuildException("You must supply either a basedir "
|
||||
. "attribute or some nested filesets.",
|
||||
$this->getLocation());
|
||||
}
|
||||
|
||||
// check if zip is out of date with respect to each
|
||||
// fileset
|
||||
$upToDate = true;
|
||||
foreach($this->filesets as $fs) {
|
||||
$files = $fs->getFiles($this->project, $this->includeEmpty);
|
||||
if (!$this->archiveIsUpToDate($files, $fs->getDir($this->project))) {
|
||||
$upToDate = false;
|
||||
}
|
||||
for ($i=0, $fcount=count($files); $i < $fcount; $i++) {
|
||||
if ($this->zipFile->equals(new PhingFile($fs->getDir($this->project), $files[$i]))) {
|
||||
throw new BuildException("A zip file cannot include itself", $this->getLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($upToDate) {
|
||||
$this->log("Nothing to do: " . $this->zipFile->__toString() . " is up to date.", Project::MSG_INFO);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->log("Building zip: " . $this->zipFile->__toString(), Project::MSG_INFO);
|
||||
|
||||
$zip = new ZipArchive();
|
||||
$res = $zip->open($this->zipFile->getAbsolutePath(), ZIPARCHIVE::CREATE);
|
||||
|
||||
if ($res !== true)
|
||||
{
|
||||
throw new Exception("ZipArchive::open() failed with code " . $res);
|
||||
}
|
||||
|
||||
foreach($this->filesets as $fs) {
|
||||
$fsBasedir = (null != $this->baseDir) ? $this->baseDir :
|
||||
$fs->getDir($this->project);
|
||||
|
||||
$files = $fs->getFiles($this->project, $this->includeEmpty);
|
||||
|
||||
$filesToZip = array();
|
||||
for ($i=0, $fcount=count($files); $i < $fcount; $i++) {
|
||||
$f = new PhingFile($fsBasedir, $files[$i]);
|
||||
|
||||
$pathInZip = $this->prefix
|
||||
. $f->getPathWithoutBase($fsBasedir);
|
||||
|
||||
$pathInZip = str_replace('\\', '/', $pathInZip);
|
||||
|
||||
if ($f->isDirectory()) {
|
||||
if ($pathInZip != '.') {
|
||||
$zip->addEmptyDir($pathInZip);
|
||||
}
|
||||
} else {
|
||||
$zip->addFile($f->getPath(), $pathInZip);
|
||||
}
|
||||
$this->log("Adding " . $f->getPath() . " as " . $pathInZip . " to archive.", Project::MSG_VERBOSE);
|
||||
}
|
||||
}
|
||||
|
||||
$zip->close();
|
||||
} catch (IOException $ioe) {
|
||||
$msg = "Problem creating ZIP: " . $ioe->getMessage();
|
||||
$this->filesets = $savedFileSets;
|
||||
throw new BuildException($msg, $ioe, $this->getLocation());
|
||||
}
|
||||
|
||||
$this->filesets = $savedFileSets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $files array of filenames
|
||||
* @param PhingFile $dir
|
||||
* @return boolean
|
||||
*/
|
||||
protected function archiveIsUpToDate($files, $dir) {
|
||||
$sfs = new SourceFileScanner($this);
|
||||
$mm = new MergeMapper();
|
||||
$mm->setTo($this->zipFile->getAbsolutePath());
|
||||
return count($sfs->restrict($files, $dir, null, $mm)) == 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This is a FileSet with the to specify permissions.
|
||||
*
|
||||
* Permissions are currently not implemented by PEAR Archive_Tar,
|
||||
* but hopefully they will be in the future.
|
||||
*
|
||||
*/
|
||||
class ZipFileSet extends FileSet {
|
||||
|
||||
private $files = null;
|
||||
|
||||
/**
|
||||
* Get a list of files and directories specified in the fileset.
|
||||
* @return array a list of file and directory names, relative to
|
||||
* the baseDir for the project.
|
||||
*/
|
||||
public function getFiles(Project $p, $includeEmpty = true) {
|
||||
|
||||
if ($this->files === null) {
|
||||
|
||||
$ds = $this->getDirectoryScanner($p);
|
||||
$this->files = $ds->getIncludedFiles();
|
||||
|
||||
// build a list of directories implicitly added by any of the files
|
||||
$implicitDirs = array();
|
||||
foreach($this->files as $file) {
|
||||
$implicitDirs[] = dirname($file);
|
||||
}
|
||||
|
||||
$incDirs = $ds->getIncludedDirectories();
|
||||
|
||||
// we'll need to add to that list of implicit dirs any directories
|
||||
// that contain other *directories* (and not files), since otherwise
|
||||
// we get duplicate directories in the resulting tar
|
||||
foreach($incDirs as $dir) {
|
||||
foreach($incDirs as $dircheck) {
|
||||
if (!empty($dir) && $dir == dirname($dircheck)) {
|
||||
$implicitDirs[] = $dir;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$implicitDirs = array_unique($implicitDirs);
|
||||
|
||||
$emptyDirectories = array();
|
||||
|
||||
if ($includeEmpty) {
|
||||
// Now add any empty dirs (dirs not covered by the implicit dirs)
|
||||
// to the files array.
|
||||
|
||||
foreach($incDirs as $dir) { // we cannot simply use array_diff() since we want to disregard empty/. dirs
|
||||
if ($dir != "" && $dir != "." && !in_array($dir, $implicitDirs)) {
|
||||
// it's an empty dir, so we'll add it.
|
||||
$emptyDirectories[] = $dir;
|
||||
}
|
||||
}
|
||||
} // if $includeEmpty
|
||||
|
||||
$this->files = array_merge($implicitDirs, $emptyDirectories, $this->files);
|
||||
sort($this->files);
|
||||
} // if ($this->files===null)
|
||||
|
||||
return $this->files;
|
||||
}
|
||||
|
||||
}
|
124
airtime_mvc/library/phing/tasks/ext/coverage/CoverageMerger.php
Normal file
124
airtime_mvc/library/phing/tasks/ext/coverage/CoverageMerger.php
Normal file
|
@ -0,0 +1,124 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: CoverageMerger.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/system/util/Properties.php';
|
||||
|
||||
/**
|
||||
* Saves coverage output of the test to a specified database
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: CoverageMerger.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.coverage
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class CoverageMerger
|
||||
{
|
||||
private static function mergeCodeCoverage($left, $right)
|
||||
{
|
||||
$coverageMerged = array();
|
||||
|
||||
reset($left);
|
||||
reset($right);
|
||||
|
||||
while (current($left) && current($right)) {
|
||||
$linenr_left = key($left);
|
||||
$linenr_right = key($right);
|
||||
|
||||
if ($linenr_left < $linenr_right) {
|
||||
$coverageMerged[$linenr_left] = current($left);
|
||||
next($left);
|
||||
} elseif ($linenr_right < $linenr_left) {
|
||||
$coverageMerged[$linenr_right] = current($right);
|
||||
next($right);
|
||||
} else {
|
||||
if ((current($left) < 0) || (current($right) < 0)) {
|
||||
$coverageMerged[$linenr_right] = current($right);
|
||||
} else {
|
||||
$coverageMerged[$linenr_right] = current($left) + current($right);
|
||||
}
|
||||
|
||||
next($left);
|
||||
next($right);
|
||||
}
|
||||
}
|
||||
|
||||
while (current($left)) {
|
||||
$coverageMerged[key($left)] = current($left);
|
||||
next($left);
|
||||
}
|
||||
|
||||
while (current($right)) {
|
||||
$coverageMerged[key($right)] = current($right);
|
||||
next($right);
|
||||
}
|
||||
|
||||
return $coverageMerged;
|
||||
}
|
||||
|
||||
static function merge($project, $codeCoverageInformation)
|
||||
{
|
||||
$coverageDatabase = $project->getProperty('coverage.database');
|
||||
|
||||
if (!$coverageDatabase) {
|
||||
throw new BuildException("Property coverage.database is not set - please include coverage-setup in your build file");
|
||||
}
|
||||
|
||||
$database = new PhingFile($coverageDatabase);
|
||||
|
||||
$props = new Properties();
|
||||
$props->load($database);
|
||||
|
||||
$coverageTotal = $codeCoverageInformation;
|
||||
|
||||
foreach ($coverageTotal as $filename => $data) {
|
||||
$lines = array();
|
||||
$filename = strtolower($filename);
|
||||
|
||||
if ($props->getProperty($filename) != null) {
|
||||
foreach ($data as $_line => $_data) {
|
||||
if (is_array($_data)) {
|
||||
$count = count($_data);
|
||||
} else if ($_data == -1) {
|
||||
// not executed
|
||||
$count = -1;
|
||||
} else if ($_data == -2) {
|
||||
// dead code
|
||||
$count = -2;
|
||||
}
|
||||
|
||||
$lines[$_line] = $count;
|
||||
}
|
||||
|
||||
ksort($lines);
|
||||
|
||||
$file = unserialize($props->getProperty($filename));
|
||||
$left = $file['coverage'];
|
||||
|
||||
$coverageMerged = CoverageMerger::mergeCodeCoverage($left, $lines);
|
||||
|
||||
$file['coverage'] = $coverageMerged;
|
||||
$props->setProperty($filename, serialize($file));
|
||||
}
|
||||
}
|
||||
|
||||
$props->store($database);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: CoverageMergerTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
require_once 'phing/system/io/PhingFile.php';
|
||||
require_once 'phing/system/io/Writer.php';
|
||||
require_once 'phing/system/util/Properties.php';
|
||||
require_once 'phing/tasks/ext/coverage/CoverageMerger.php';
|
||||
|
||||
/**
|
||||
* Merges code coverage snippets into a code coverage database
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: CoverageMergerTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.coverage
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class CoverageMergerTask extends Task
|
||||
{
|
||||
/** the list of filesets containing the .php filename rules */
|
||||
private $filesets = array();
|
||||
|
||||
/**
|
||||
* Add a new fileset containing the .php files to process
|
||||
*
|
||||
* @param FileSet the new fileset containing .php files
|
||||
*/
|
||||
function addFileSet(FileSet $fileset)
|
||||
{
|
||||
$this->filesets[] = $fileset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate over all filesets and return all the filenames.
|
||||
*
|
||||
* @return array an array of filenames
|
||||
*/
|
||||
private function getFilenames()
|
||||
{
|
||||
$files = array();
|
||||
|
||||
foreach ($this->filesets as $fileset)
|
||||
{
|
||||
$ds = $fileset->getDirectoryScanner($this->project);
|
||||
$ds->scan();
|
||||
|
||||
$includedFiles = $ds->getIncludedFiles();
|
||||
|
||||
foreach ($includedFiles as $file)
|
||||
{
|
||||
$fs = new PhingFile(basename($ds->getBaseDir()), $file);
|
||||
|
||||
$files[] = $fs->getAbsolutePath();
|
||||
}
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
function main()
|
||||
{
|
||||
$files = $this->getFilenames();
|
||||
|
||||
$this->log("Merging " . count($files) . " coverage files");
|
||||
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$coverageInformation = unserialize(file_get_contents($file));
|
||||
|
||||
CoverageMerger::merge($this->project, array($coverageInformation));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,556 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: CoverageReportTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
require_once 'phing/system/io/PhingFile.php';
|
||||
require_once 'phing/system/io/Writer.php';
|
||||
require_once 'phing/system/util/Properties.php';
|
||||
require_once 'phing/tasks/ext/phpunit/PHPUnitUtil.php';
|
||||
require_once 'phing/tasks/ext/coverage/CoverageReportTransformer.php';
|
||||
|
||||
/**
|
||||
* Transforms information in a code coverage database to XML
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: CoverageReportTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.coverage
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class CoverageReportTask extends Task
|
||||
{
|
||||
private $outfile = "coverage.xml";
|
||||
|
||||
private $transformers = array();
|
||||
|
||||
/** the classpath to use (optional) */
|
||||
private $classpath = NULL;
|
||||
|
||||
/** the path to the GeSHi library (optional) */
|
||||
private $geshipath = "";
|
||||
|
||||
/** the path to the GeSHi language files (optional) */
|
||||
private $geshilanguagespath = "";
|
||||
|
||||
function setClasspath(Path $classpath)
|
||||
{
|
||||
if ($this->classpath === null)
|
||||
{
|
||||
$this->classpath = $classpath;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->classpath->append($classpath);
|
||||
}
|
||||
}
|
||||
|
||||
function createClasspath()
|
||||
{
|
||||
$this->classpath = new Path();
|
||||
return $this->classpath;
|
||||
}
|
||||
|
||||
function setGeshiPath($path)
|
||||
{
|
||||
$this->geshipath = $path;
|
||||
}
|
||||
|
||||
function setGeshiLanguagesPath($path)
|
||||
{
|
||||
$this->geshilanguagespath = $path;
|
||||
}
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->doc = new DOMDocument();
|
||||
$this->doc->encoding = 'UTF-8';
|
||||
$this->doc->formatOutput = true;
|
||||
$this->doc->appendChild($this->doc->createElement('snapshot'));
|
||||
}
|
||||
|
||||
function setOutfile($outfile)
|
||||
{
|
||||
$this->outfile = $outfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a report based on the XML created by this task
|
||||
*/
|
||||
function createReport()
|
||||
{
|
||||
$transformer = new CoverageReportTransformer($this);
|
||||
$this->transformers[] = $transformer;
|
||||
return $transformer;
|
||||
}
|
||||
|
||||
protected function getPackageElement($packageName)
|
||||
{
|
||||
$packages = $this->doc->documentElement->getElementsByTagName('package');
|
||||
|
||||
foreach ($packages as $package)
|
||||
{
|
||||
if ($package->getAttribute('name') == $packageName)
|
||||
{
|
||||
return $package;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
protected function addClassToPackage($classname, $element)
|
||||
{
|
||||
$packageName = PHPUnitUtil::getPackageName($classname);
|
||||
|
||||
$package = $this->getPackageElement($packageName);
|
||||
|
||||
if ($package === NULL)
|
||||
{
|
||||
$package = $this->doc->createElement('package');
|
||||
$package->setAttribute('name', $packageName);
|
||||
$this->doc->documentElement->appendChild($package);
|
||||
}
|
||||
|
||||
$package->appendChild($element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a subpackage to their package
|
||||
*
|
||||
* @param string $packageName The name of the package
|
||||
* @param string $subpackageName The name of the subpackage
|
||||
*
|
||||
* @author Benjamin Schultz <bschultz@proqrent.de>
|
||||
* @return void
|
||||
*/
|
||||
protected function addSubpackageToPackage($packageName, $subpackageName)
|
||||
{
|
||||
$package = $this->getPackageElement($packageName);
|
||||
$subpackage = $this->getSubpackageElement($subpackageName);
|
||||
|
||||
if ($package === null) {
|
||||
$package = $this->doc->createElement('package');
|
||||
$package->setAttribute('name', $packageName);
|
||||
$this->doc->documentElement->appendChild($package);
|
||||
}
|
||||
|
||||
if ($subpackage === null) {
|
||||
$subpackage = $this->doc->createElement('subpackage');
|
||||
$subpackage->setAttribute('name', $subpackageName);
|
||||
}
|
||||
|
||||
$package->appendChild($subpackage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the subpackage element
|
||||
*
|
||||
* @param string $subpackageName The name of the subpackage
|
||||
*
|
||||
* @author Benjamin Schultz <bschultz@proqrent.de>
|
||||
* @return DOMNode|null null when no DOMNode with the given name exists
|
||||
*/
|
||||
protected function getSubpackageElement($subpackageName)
|
||||
{
|
||||
$subpackages = $this->doc->documentElement->getElementsByTagName('subpackage');
|
||||
|
||||
foreach ($subpackages as $subpackage) {
|
||||
if ($subpackage->getAttribute('name') == $subpackageName) {
|
||||
return $subpackage;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a class to their subpackage
|
||||
*
|
||||
* @param string $classname The name of the class
|
||||
* @param DOMNode $element The dom node to append to the subpackage element
|
||||
*
|
||||
* @author Benjamin Schultz <bschultz@proqrent.de>
|
||||
* @return void
|
||||
*/
|
||||
protected function addClassToSubpackage($classname, $element)
|
||||
{
|
||||
$subpackageName = PHPUnitUtil::getSubpackageName($classname);
|
||||
|
||||
$subpackage = $this->getSubpackageElement($subpackageName);
|
||||
|
||||
if ($subpackage === null) {
|
||||
$subpackage = $this->doc->createElement('subpackage');
|
||||
$subpackage->setAttribute('name', $subpackageName);
|
||||
$this->doc->documentElement->appendChild($subpackage);
|
||||
}
|
||||
|
||||
$subpackage->appendChild($element);
|
||||
}
|
||||
|
||||
protected function stripDiv($source)
|
||||
{
|
||||
$openpos = strpos($source, "<div");
|
||||
$closepos = strpos($source, ">", $openpos);
|
||||
|
||||
$line = substr($source, $closepos + 1);
|
||||
|
||||
$tagclosepos = strpos($line, "</div>");
|
||||
|
||||
$line = substr($line, 0, $tagclosepos);
|
||||
|
||||
return $line;
|
||||
}
|
||||
|
||||
protected function highlightSourceFile($filename)
|
||||
{
|
||||
if ($this->geshipath)
|
||||
{
|
||||
require_once $this->geshipath . '/geshi.php';
|
||||
|
||||
$source = file_get_contents($filename);
|
||||
|
||||
$geshi = new GeSHi($source, 'php', $this->geshilanguagespath);
|
||||
|
||||
$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
|
||||
|
||||
$geshi->enable_strict_mode(true);
|
||||
|
||||
$geshi->enable_classes(true);
|
||||
|
||||
$geshi->set_url_for_keyword_group(3, '');
|
||||
|
||||
$html = $geshi->parse_code();
|
||||
|
||||
$lines = split("<li>|</li>", $html);
|
||||
|
||||
// skip first and last line
|
||||
array_pop($lines);
|
||||
array_shift($lines);
|
||||
|
||||
$lines = array_filter($lines);
|
||||
|
||||
$lines = array_map(array($this, 'stripDiv'), $lines);
|
||||
|
||||
return $lines;
|
||||
}
|
||||
else
|
||||
{
|
||||
$lines = file($filename);
|
||||
|
||||
for ($i = 0; $i < count($lines); $i++)
|
||||
{
|
||||
$line = $lines[$i];
|
||||
|
||||
$line = rtrim($line);
|
||||
|
||||
if (function_exists('mb_convert_encoding'))
|
||||
{
|
||||
$lines[$i] = mb_convert_encoding($line, 'UTF-8');
|
||||
}
|
||||
else
|
||||
{
|
||||
$lines[$i] = utf8_encode($line);
|
||||
}
|
||||
}
|
||||
|
||||
return $lines;
|
||||
}
|
||||
}
|
||||
|
||||
protected function transformSourceFile($filename, $coverageInformation, $classStartLine = 1)
|
||||
{
|
||||
$sourceElement = $this->doc->createElement('sourcefile');
|
||||
$sourceElement->setAttribute('name', basename($filename));
|
||||
|
||||
/**
|
||||
* Add original/full filename to document
|
||||
*/
|
||||
$sourceElement->setAttribute('sourcefile', $filename);
|
||||
|
||||
$filelines = $this->highlightSourceFile($filename);
|
||||
|
||||
$linenr = 1;
|
||||
|
||||
foreach ($filelines as $line)
|
||||
{
|
||||
$lineElement = $this->doc->createElement('sourceline');
|
||||
$lineElement->setAttribute('coveredcount', (isset($coverageInformation[$linenr]) ? $coverageInformation[$linenr] : '0'));
|
||||
|
||||
if ($linenr == $classStartLine)
|
||||
{
|
||||
$lineElement->setAttribute('startclass', 1);
|
||||
}
|
||||
|
||||
$textnode = $this->doc->createTextNode($line);
|
||||
$lineElement->appendChild($textnode);
|
||||
|
||||
$sourceElement->appendChild($lineElement);
|
||||
|
||||
$linenr++;
|
||||
}
|
||||
|
||||
return $sourceElement;
|
||||
}
|
||||
|
||||
protected function filterCovered($var)
|
||||
{
|
||||
return ($var >= 0 || $var == -2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the coverage information
|
||||
*
|
||||
* @param string $filename The filename
|
||||
* @param array $coverageInformation Array with covergae information
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @author Benjamin Schultz <bschultz@proqrent.de>
|
||||
* @return void
|
||||
*/
|
||||
protected function transformCoverageInformation($filename, $coverageInformation)
|
||||
{
|
||||
$classes = PHPUnitUtil::getDefinedClasses($filename, $this->classpath);
|
||||
|
||||
if (is_array($classes))
|
||||
{
|
||||
foreach ($classes as $classname)
|
||||
{
|
||||
$reflection = new ReflectionClass($classname);
|
||||
|
||||
$methods = $reflection->getMethods();
|
||||
|
||||
$classElement = $this->doc->createElement('class');
|
||||
$classElement->setAttribute('name', $reflection->getName());
|
||||
|
||||
$packageName = PHPUnitUtil::getPackageName($reflection->getName());
|
||||
$subpackageName = PHPUnitUtil::getSubpackageName($reflection->getName());
|
||||
|
||||
if ($subpackageName !== null) {
|
||||
$this->addSubpackageToPackage($packageName, $subpackageName);
|
||||
$this->addClassToSubpackage($reflection->getName(), $classElement);
|
||||
} else {
|
||||
$this->addClassToPackage($reflection->getName(), $classElement);
|
||||
}
|
||||
|
||||
$classStartLine = $reflection->getStartLine();
|
||||
|
||||
$methodscovered = 0;
|
||||
$methodcount = 0;
|
||||
|
||||
// Strange PHP5 reflection bug, classes without parent class or implemented interfaces seem to start one line off
|
||||
if ($reflection->getParentClass() == NULL && count($reflection->getInterfaces()) == 0)
|
||||
{
|
||||
unset($coverageInformation[$classStartLine + 1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
unset($coverageInformation[$classStartLine]);
|
||||
}
|
||||
|
||||
reset($coverageInformation);
|
||||
|
||||
foreach ($methods as $method)
|
||||
{
|
||||
// PHP5 reflection considers methods of a parent class to be part of a subclass, we don't
|
||||
if ($method->getDeclaringClass()->getName() != $reflection->getName())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// small fix for XDEBUG_CC_UNUSED
|
||||
if (isset($coverageInformation[$method->getStartLine()]))
|
||||
{
|
||||
unset($coverageInformation[$method->getStartLine()]);
|
||||
}
|
||||
|
||||
if (isset($coverageInformation[$method->getEndLine()]))
|
||||
{
|
||||
unset($coverageInformation[$method->getEndLine()]);
|
||||
}
|
||||
|
||||
if ($method->isAbstract())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$linenr = key($coverageInformation);
|
||||
|
||||
while ($linenr !== null && $linenr < $method->getStartLine())
|
||||
{
|
||||
next($coverageInformation);
|
||||
$linenr = key($coverageInformation);
|
||||
}
|
||||
|
||||
$methodCoveredCount = 0;
|
||||
$methodTotalCount = 0;
|
||||
|
||||
$methodHasCoveredLine = false;
|
||||
|
||||
while ($linenr !== null && $linenr <= $method->getEndLine()) {
|
||||
$methodTotalCount++;
|
||||
$methodHasCoveredLine = true;
|
||||
|
||||
// set covered when CODE is other than -1 (not executed)
|
||||
if ($coverageInformation[$linenr] > 0 || $coverageInformation[$linenr] == -2) {
|
||||
$methodCoveredCount++;
|
||||
}
|
||||
|
||||
next($coverageInformation);
|
||||
$linenr = key($coverageInformation);
|
||||
}
|
||||
|
||||
if (($methodTotalCount == $methodCoveredCount) && $methodHasCoveredLine) {
|
||||
$methodscovered++;
|
||||
}
|
||||
|
||||
$methodcount++;
|
||||
}
|
||||
|
||||
$statementcount = count($coverageInformation);
|
||||
$statementscovered = count(array_filter($coverageInformation, array($this, 'filterCovered')));
|
||||
|
||||
$classElement->appendChild($this->transformSourceFile($filename, $coverageInformation, $classStartLine));
|
||||
|
||||
$classElement->setAttribute('methodcount', $methodcount);
|
||||
$classElement->setAttribute('methodscovered', $methodscovered);
|
||||
$classElement->setAttribute('statementcount', $statementcount);
|
||||
$classElement->setAttribute('statementscovered', $statementscovered);
|
||||
$classElement->setAttribute('totalcount', $methodcount + $statementcount);
|
||||
$classElement->setAttribute('totalcovered', $methodscovered + $statementscovered);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function calculateStatistics()
|
||||
{
|
||||
$packages = $this->doc->documentElement->getElementsByTagName('package');
|
||||
|
||||
$totalmethodcount = 0;
|
||||
$totalmethodscovered = 0;
|
||||
|
||||
$totalstatementcount = 0;
|
||||
$totalstatementscovered = 0;
|
||||
|
||||
foreach ($packages as $package) {
|
||||
$methodcount = 0;
|
||||
$methodscovered = 0;
|
||||
|
||||
$statementcount = 0;
|
||||
$statementscovered = 0;
|
||||
|
||||
$subpackages = $package->getElementsByTagName('subpackage');
|
||||
|
||||
foreach ($subpackages as $subpackage) {
|
||||
$subpackageMethodCount = 0;
|
||||
$subpackageMethodsCovered = 0;
|
||||
|
||||
$subpackageStatementCount = 0;
|
||||
$subpackageStatementsCovered = 0;
|
||||
|
||||
$subpackageClasses = $subpackage->getElementsByTagName('class');
|
||||
|
||||
foreach ($subpackageClasses as $subpackageClass) {
|
||||
$subpackageMethodCount += $subpackageClass->getAttribute('methodcount');
|
||||
$subpackageMethodsCovered += $subpackageClass->getAttribute('methodscovered');
|
||||
|
||||
$subpackageStatementCount += $subpackageClass->getAttribute('statementcount');
|
||||
$subpackageStatementsCovered += $subpackageClass->getAttribute('statementscovered');
|
||||
}
|
||||
|
||||
$subpackage->setAttribute('methodcount', $subpackageMethodCount);
|
||||
$subpackage->setAttribute('methodscovered', $subpackageMethodsCovered);
|
||||
|
||||
$subpackage->setAttribute('statementcount', $subpackageStatementCount);
|
||||
$subpackage->setAttribute('statementscovered', $subpackageStatementsCovered);
|
||||
|
||||
$subpackage->setAttribute('totalcount', $subpackageMethodCount + $subpackageStatementCount);
|
||||
$subpackage->setAttribute('totalcovered', $subpackageMethodsCovered + $subpackageStatementsCovered);
|
||||
}
|
||||
|
||||
$classes = $package->getElementsByTagName('class');
|
||||
|
||||
foreach ($classes as $class) {
|
||||
$methodcount += $class->getAttribute('methodcount');
|
||||
$methodscovered += $class->getAttribute('methodscovered');
|
||||
|
||||
$statementcount += $class->getAttribute('statementcount');
|
||||
$statementscovered += $class->getAttribute('statementscovered');
|
||||
}
|
||||
|
||||
$package->setAttribute('methodcount', $methodcount);
|
||||
$package->setAttribute('methodscovered', $methodscovered);
|
||||
|
||||
$package->setAttribute('statementcount', $statementcount);
|
||||
$package->setAttribute('statementscovered', $statementscovered);
|
||||
|
||||
$package->setAttribute('totalcount', $methodcount + $statementcount);
|
||||
$package->setAttribute('totalcovered', $methodscovered + $statementscovered);
|
||||
|
||||
$totalmethodcount += $methodcount;
|
||||
$totalmethodscovered += $methodscovered;
|
||||
|
||||
$totalstatementcount += $statementcount;
|
||||
$totalstatementscovered += $statementscovered;
|
||||
}
|
||||
|
||||
$this->doc->documentElement->setAttribute('methodcount', $totalmethodcount);
|
||||
$this->doc->documentElement->setAttribute('methodscovered', $totalmethodscovered);
|
||||
|
||||
$this->doc->documentElement->setAttribute('statementcount', $totalstatementcount);
|
||||
$this->doc->documentElement->setAttribute('statementscovered', $totalstatementscovered);
|
||||
|
||||
$this->doc->documentElement->setAttribute('totalcount', $totalmethodcount + $totalstatementcount);
|
||||
$this->doc->documentElement->setAttribute('totalcovered', $totalmethodscovered + $totalstatementscovered);
|
||||
}
|
||||
|
||||
function main()
|
||||
{
|
||||
$coverageDatabase = $this->project->getProperty('coverage.database');
|
||||
|
||||
if (!$coverageDatabase)
|
||||
{
|
||||
throw new BuildException("Property coverage.database is not set - please include coverage-setup in your build file");
|
||||
}
|
||||
|
||||
$database = new PhingFile($coverageDatabase);
|
||||
|
||||
$this->log("Transforming coverage report");
|
||||
|
||||
$props = new Properties();
|
||||
$props->load($database);
|
||||
|
||||
foreach ($props->keys() as $filename)
|
||||
{
|
||||
$file = unserialize($props->getProperty($filename));
|
||||
|
||||
$this->transformCoverageInformation($file['fullname'], $file['coverage']);
|
||||
}
|
||||
|
||||
$this->calculateStatistics();
|
||||
|
||||
$this->doc->save($this->outfile);
|
||||
|
||||
foreach ($this->transformers as $transformer)
|
||||
{
|
||||
$transformer->setXmlDocument($this->doc);
|
||||
$transformer->transform();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: CoverageReportTransformer.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
require_once 'phing/system/io/PhingFile.php';
|
||||
require_once 'phing/system/io/FileWriter.php';
|
||||
require_once 'phing/util/ExtendedFileStream.php';
|
||||
|
||||
/**
|
||||
* Transform a Phing/Xdebug code coverage xml report.
|
||||
* The default transformation generates an html report in framed style.
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: CoverageReportTransformer.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.coverage
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class CoverageReportTransformer
|
||||
{
|
||||
private $task = NULL;
|
||||
private $styleDir = "";
|
||||
private $toDir = "";
|
||||
private $document = NULL;
|
||||
|
||||
function __construct(Task $task)
|
||||
{
|
||||
$this->task = $task;
|
||||
}
|
||||
|
||||
function setStyleDir($styleDir)
|
||||
{
|
||||
$this->styleDir = $styleDir;
|
||||
}
|
||||
|
||||
function setToDir($toDir)
|
||||
{
|
||||
$this->toDir = $toDir;
|
||||
}
|
||||
|
||||
function setXmlDocument($document)
|
||||
{
|
||||
$this->document = $document;
|
||||
}
|
||||
|
||||
function transform()
|
||||
{
|
||||
$dir = new PhingFile($this->toDir);
|
||||
|
||||
if (!$dir->exists())
|
||||
{
|
||||
throw new BuildException("Directory '" . $this->toDir . "' does not exist");
|
||||
}
|
||||
|
||||
$xslfile = $this->getStyleSheet();
|
||||
|
||||
$xsl = new DOMDocument();
|
||||
$xsl->load($xslfile->getAbsolutePath());
|
||||
|
||||
$proc = new XSLTProcessor();
|
||||
$proc->importStyleSheet($xsl);
|
||||
|
||||
ExtendedFileStream::registerStream();
|
||||
|
||||
// no output for the framed report
|
||||
// it's all done by extension...
|
||||
$proc->setParameter('', 'output.dir', $dir->toString());
|
||||
$proc->transformToXML($this->document);
|
||||
|
||||
ExtendedFileStream::unregisterStream();
|
||||
}
|
||||
|
||||
private function getStyleSheet()
|
||||
{
|
||||
$xslname = "coverage-frames.xsl";
|
||||
|
||||
if ($this->styleDir)
|
||||
{
|
||||
$file = new PhingFile($this->styleDir, $xslname);
|
||||
}
|
||||
else
|
||||
{
|
||||
$path = Phing::getResourcePath("phing/etc/$xslname");
|
||||
|
||||
if ($path === NULL)
|
||||
{
|
||||
$path = Phing::getResourcePath("etc/$xslname");
|
||||
|
||||
if ($path === NULL)
|
||||
{
|
||||
throw new BuildException("Could not find $xslname in resource path");
|
||||
}
|
||||
}
|
||||
|
||||
$file = new PhingFile($path);
|
||||
}
|
||||
|
||||
if (!$file->exists())
|
||||
{
|
||||
throw new BuildException("Could not find file " . $file->getPath());
|
||||
}
|
||||
|
||||
return $file;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,139 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: CoverageSetupTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
require_once 'phing/system/io/PhingFile.php';
|
||||
require_once 'phing/system/io/Writer.php';
|
||||
require_once 'phing/system/util/Properties.php';
|
||||
require_once 'phing/tasks/ext/coverage/CoverageMerger.php';
|
||||
|
||||
/**
|
||||
* Initializes a code coverage database
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: CoverageSetupTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.coverage
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class CoverageSetupTask extends Task
|
||||
{
|
||||
/** the list of filesets containing the .php filename rules */
|
||||
private $filesets = array();
|
||||
|
||||
/** the filename of the coverage database */
|
||||
private $database = "coverage.db";
|
||||
|
||||
/** the classpath to use (optional) */
|
||||
private $classpath = NULL;
|
||||
|
||||
/**
|
||||
* Add a new fileset containing the .php files to process
|
||||
*
|
||||
* @param FileSet the new fileset containing .php files
|
||||
*/
|
||||
function addFileSet(FileSet $fileset)
|
||||
{
|
||||
$this->filesets[] = $fileset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the filename of the coverage database to use
|
||||
*
|
||||
* @param string the filename of the database
|
||||
*/
|
||||
function setDatabase($database)
|
||||
{
|
||||
$this->database = $database;
|
||||
}
|
||||
|
||||
function setClasspath(Path $classpath)
|
||||
{
|
||||
if ($this->classpath === null)
|
||||
{
|
||||
$this->classpath = $classpath;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->classpath->append($classpath);
|
||||
}
|
||||
}
|
||||
|
||||
function createClasspath()
|
||||
{
|
||||
$this->classpath = new Path();
|
||||
return $this->classpath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate over all filesets and return the filename of all files.
|
||||
*
|
||||
* @return array an array of (basedir, filenames) pairs
|
||||
*/
|
||||
private function getFilenames()
|
||||
{
|
||||
$files = array();
|
||||
|
||||
foreach ($this->filesets as $fileset)
|
||||
{
|
||||
$ds = $fileset->getDirectoryScanner($this->project);
|
||||
$ds->scan();
|
||||
|
||||
$includedFiles = $ds->getIncludedFiles();
|
||||
|
||||
foreach ($includedFiles as $file)
|
||||
{
|
||||
$fs = new PhingFile(realpath($ds->getBaseDir()), $file);
|
||||
|
||||
$files[] = array('key' => strtolower($fs->getAbsolutePath()), 'fullname' => $fs->getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
function init()
|
||||
{
|
||||
}
|
||||
|
||||
function main()
|
||||
{
|
||||
$files = $this->getFilenames();
|
||||
|
||||
$this->log("Setting up coverage database for " . count($files) . " files");
|
||||
|
||||
$props = new Properties();
|
||||
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$fullname = $file['fullname'];
|
||||
$filename = $file['key'];
|
||||
|
||||
$props->setProperty($filename, serialize(array('fullname' => $fullname, 'coverage' => array())));
|
||||
}
|
||||
|
||||
$dbfile = new PhingFile($this->database);
|
||||
|
||||
$props->store($dbfile);
|
||||
|
||||
$this->project->setProperty('coverage.database', $dbfile->getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,414 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: CoverageThresholdTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
require_once 'phing/system/io/PhingFile.php';
|
||||
require_once 'phing/system/util/Properties.php';
|
||||
|
||||
/**
|
||||
* Stops the build if any of the specified coverage threshold was not reached
|
||||
*
|
||||
* @author Benjamin Schultz <bschultz@proqrent.de>
|
||||
* @version $Id: CoverageThresholdTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.coverage
|
||||
* @since 2.4.1
|
||||
*/
|
||||
class CoverageThresholdTask extends Task
|
||||
{
|
||||
/**
|
||||
* Holds an optional classpath
|
||||
*
|
||||
* @var Path
|
||||
*/
|
||||
private $_classpath = null;
|
||||
|
||||
/**
|
||||
* Holds an optional database file
|
||||
*
|
||||
* @var PhingFile
|
||||
*/
|
||||
private $_database = null;
|
||||
|
||||
/**
|
||||
* Holds the coverage threshold for the entire project
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $_perProject = 25;
|
||||
|
||||
/**
|
||||
* Holds the coverage threshold for any class
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $_perClass = 25;
|
||||
|
||||
/**
|
||||
* Holds the coverage threshold for any method
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $_perMethod = 25;
|
||||
|
||||
/**
|
||||
* Holds the minimum found coverage value for a class
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $_minClassCoverageFound = null;
|
||||
|
||||
/**
|
||||
* Holds the minimum found coverage value for a method
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $_minMethodCoverageFound = null;
|
||||
|
||||
/**
|
||||
* Number of statements in the entire project
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $_projectStatementCount = 0;
|
||||
|
||||
/**
|
||||
* Number of covered statements in the entire project
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $_projectStatementsCovered = 0;
|
||||
|
||||
/**
|
||||
* Whether to enable detailed logging
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $_verbose = false;
|
||||
|
||||
/**
|
||||
* Sets an optional classpath
|
||||
*
|
||||
* @param Path $classpath The classpath
|
||||
*/
|
||||
public function setClasspath(Path $classpath)
|
||||
{
|
||||
if ($this->_classpath === null) {
|
||||
$this->_classpath = $classpath;
|
||||
} else {
|
||||
$this->_classpath->append($classpath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the optional coverage database to use
|
||||
*
|
||||
* @param PhingFile The database file
|
||||
*/
|
||||
public function setDatabase(PhingFile $database)
|
||||
{
|
||||
$this->_database = $database;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create classpath object
|
||||
*
|
||||
* @return Path
|
||||
*/
|
||||
public function createClasspath()
|
||||
{
|
||||
$this->classpath = new Path();
|
||||
return $this->classpath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the coverage threshold for entire project
|
||||
*
|
||||
* @param integer $threshold Coverage threshold for entire project
|
||||
*/
|
||||
public function setPerProject($threshold)
|
||||
{
|
||||
$this->_perProject = $threshold;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the coverage threshold for any class
|
||||
*
|
||||
* @param integer $threshold Coverage threshold for any class
|
||||
*/
|
||||
public function setPerClass($threshold)
|
||||
{
|
||||
$this->_perClass = $threshold;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the coverage threshold for any method
|
||||
*
|
||||
* @param integer $threshold Coverage threshold for any method
|
||||
*/
|
||||
public function setPerMethod($threshold)
|
||||
{
|
||||
$this->_perMethod = $threshold;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to enable detailed logging or not
|
||||
*
|
||||
* @param boolean $verbose
|
||||
*/
|
||||
public function setVerbose($verbose)
|
||||
{
|
||||
$this->_verbose = StringHelper::booleanValue($verbose);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter covered statements
|
||||
*
|
||||
* @param integer $var Coverage CODE/count
|
||||
* @return boolean
|
||||
*/
|
||||
protected function filterCovered($var)
|
||||
{
|
||||
return ($var >= 0 || $var === -2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the coverage threshold
|
||||
*
|
||||
* @param string $filename The filename to analyse
|
||||
* @param array $coverageInformation Array with coverage information
|
||||
*/
|
||||
protected function calculateCoverageThreshold($filename, $coverageInformation)
|
||||
{
|
||||
$classes = PHPUnitUtil::getDefinedClasses($filename, $this->_classpath);
|
||||
|
||||
if (is_array($classes)) {
|
||||
foreach ($classes as $className) {
|
||||
$reflection = new ReflectionClass($className);
|
||||
$classStartLine = $reflection->getStartLine();
|
||||
|
||||
// Strange PHP5 reflection bug, classes without parent class
|
||||
// or implemented interfaces seem to start one line off
|
||||
if ($reflection->getParentClass() === null
|
||||
&& count($reflection->getInterfaces()) === 0
|
||||
) {
|
||||
unset($coverageInformation[$classStartLine + 1]);
|
||||
} else {
|
||||
unset($coverageInformation[$classStartLine]);
|
||||
}
|
||||
|
||||
reset($coverageInformation);
|
||||
|
||||
$methods = $reflection->getMethods();
|
||||
|
||||
foreach ($methods as $method) {
|
||||
// PHP5 reflection considers methods of a parent class
|
||||
// to be part of a subclass, we don't
|
||||
if ($method->getDeclaringClass()->getName() != $reflection->getName()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$methodStartLine = $method->getStartLine();
|
||||
$methodEndLine = $method->getEndLine();
|
||||
|
||||
// small fix for XDEBUG_CC_UNUSED
|
||||
if (isset($coverageInformation[$methodStartLine])) {
|
||||
unset($coverageInformation[$methodStartLine]);
|
||||
}
|
||||
|
||||
if (isset($coverageInformation[$methodEndLine])) {
|
||||
unset($coverageInformation[$methodEndLine]);
|
||||
}
|
||||
|
||||
if ($method->isAbstract()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$lineNr = key($coverageInformation);
|
||||
|
||||
while ($lineNr !== null && $lineNr < $methodStartLine) {
|
||||
next($coverageInformation);
|
||||
$lineNr = key($coverageInformation);
|
||||
}
|
||||
|
||||
$methodStatementsCovered = 0;
|
||||
$methodStatementCount = 0;
|
||||
|
||||
while ($lineNr !== null && $lineNr <= $methodEndLine) {
|
||||
$methodStatementCount++;
|
||||
|
||||
$lineCoverageInfo = $coverageInformation[$lineNr];
|
||||
// set covered when CODE is other than -1 (not executed)
|
||||
if ($lineCoverageInfo > 0 || $lineCoverageInfo === -2) {
|
||||
$methodStatementsCovered++;
|
||||
}
|
||||
|
||||
next($coverageInformation);
|
||||
$lineNr = key($coverageInformation);
|
||||
}
|
||||
|
||||
if ($methodStatementCount > 0) {
|
||||
$methodCoverage = ( $methodStatementsCovered
|
||||
/ $methodStatementCount) * 100;
|
||||
} else {
|
||||
$methodCoverage = 0;
|
||||
}
|
||||
|
||||
if ($methodCoverage < $this->_perMethod
|
||||
&& !$method->isAbstract()
|
||||
) {
|
||||
throw new BuildException(
|
||||
'The coverage (' . $methodCoverage . '%) '
|
||||
. 'for method "' . $method->getName() . '" is lower'
|
||||
. ' than the specified threshold ('
|
||||
. $this->_perMethod . '%), see file: "'
|
||||
. $filename . '"'
|
||||
);
|
||||
} elseif ($methodCoverage < $this->_perMethod
|
||||
&& $method->isAbstract()
|
||||
) {
|
||||
if ($this->_verbose === true) {
|
||||
$this->log(
|
||||
'Skipped coverage threshold for abstract method "'
|
||||
. $method->getName() . '"'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// store the minimum coverage value for logging (see #466)
|
||||
if ($this->_minMethodCoverageFound !== null) {
|
||||
if ($this->_minMethodCoverageFound > $methodCoverage) {
|
||||
$this->_minMethodCoverageFound = $methodCoverage;
|
||||
}
|
||||
} else {
|
||||
$this->_minMethodCoverageFound = $methodCoverage;
|
||||
}
|
||||
}
|
||||
|
||||
$classStatementCount = count($coverageInformation);
|
||||
$classStatementsCovered = count(
|
||||
array_filter(
|
||||
$coverageInformation,
|
||||
array($this, 'filterCovered')
|
||||
)
|
||||
);
|
||||
|
||||
if ($classStatementCount > 0) {
|
||||
$classCoverage = ( $classStatementsCovered
|
||||
/ $classStatementCount) * 100;
|
||||
} else {
|
||||
$classCoverage = 0;
|
||||
}
|
||||
|
||||
if ($classCoverage < $this->_perClass
|
||||
&& !$reflection->isAbstract()
|
||||
) {
|
||||
throw new BuildException(
|
||||
'The coverage (' . $classCoverage . '%) for class "'
|
||||
. $reflection->getName() . '" is lower than the '
|
||||
. 'specified threshold (' . $this->_perClass . '%), '
|
||||
. 'see file: "' . $filename . '"'
|
||||
);
|
||||
} elseif ($classCoverage < $this->_perClass
|
||||
&& $reflection->isAbstract()
|
||||
) {
|
||||
if ($this->_verbose === true) {
|
||||
$this->log(
|
||||
'Skipped coverage threshold for abstract class "'
|
||||
. $reflection->getName() . '"'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// store the minimum coverage value for logging (see #466)
|
||||
if ($this->_minClassCoverageFound !== null) {
|
||||
if ($this->_minClassCoverageFound > $classCoverage) {
|
||||
$this->_minClassCoverageFound = $classCoverage;
|
||||
}
|
||||
} else {
|
||||
$this->_minClassCoverageFound = $classCoverage;
|
||||
}
|
||||
|
||||
$this->_projectStatementCount += $classStatementCount;
|
||||
$this->_projectStatementsCovered += $classStatementsCovered;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function main()
|
||||
{
|
||||
if ($this->_database === null) {
|
||||
$coverageDatabase = $this->project
|
||||
->getProperty('coverage.database');
|
||||
|
||||
if (! $coverageDatabase) {
|
||||
throw new BuildException(
|
||||
'Either include coverage-setup in your build file or set '
|
||||
. 'the "database" attribute'
|
||||
);
|
||||
}
|
||||
|
||||
$database = new PhingFile($coverageDatabase);
|
||||
} else {
|
||||
$database = $this->_database;
|
||||
}
|
||||
|
||||
$this->log(
|
||||
'Calculating coverage threshold: min. '
|
||||
. $this->_perProject . '% per project, '
|
||||
. $this->_perClass . '% per class and '
|
||||
. $this->_perMethod . '% per method is required'
|
||||
);
|
||||
|
||||
$props = new Properties();
|
||||
$props->load($database);
|
||||
|
||||
foreach ($props->keys() as $filename) {
|
||||
$file = unserialize($props->getProperty($filename));
|
||||
|
||||
$this->calculateCoverageThreshold(
|
||||
$file['fullname'],
|
||||
$file['coverage']
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->_projectStatementCount > 0) {
|
||||
$coverage = ( $this->_projectStatementsCovered
|
||||
/ $this->_projectStatementCount) * 100;
|
||||
} else {
|
||||
$coverage = 0;
|
||||
}
|
||||
|
||||
if ($coverage < $this->_perProject) {
|
||||
throw new BuildException(
|
||||
'The coverage (' . $coverage . '%) for the entire project '
|
||||
. 'is lower than the specified threshold ('
|
||||
. $this->_perProject . '%)'
|
||||
);
|
||||
}
|
||||
|
||||
$this->log(
|
||||
'Passed coverage threshold. Minimum found coverage values are: '
|
||||
. round($coverage, 2) . '% per project, '
|
||||
. round($this->_minClassCoverageFound, 2) . '% per class and '
|
||||
. round($this->_minMethodCoverageFound, 2) . '% per method'
|
||||
);
|
||||
}
|
||||
}
|
592
airtime_mvc/library/phing/tasks/ext/creole/CreoleSQLExecTask.php
Normal file
592
airtime_mvc/library/phing/tasks/ext/creole/CreoleSQLExecTask.php
Normal file
|
@ -0,0 +1,592 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: CreoleSQLExecTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/tasks/ext/creole/CreoleTask.php';
|
||||
include_once 'phing/system/io/StringReader.php';
|
||||
|
||||
/**
|
||||
* Executes a series of SQL statements on a database using Creole.
|
||||
*
|
||||
* <p>Statements can
|
||||
* either be read in from a text file using the <i>src</i> attribute or from
|
||||
* between the enclosing SQL tags.</p>
|
||||
*
|
||||
* <p>Multiple statements can be provided, separated by semicolons (or the
|
||||
* defined <i>delimiter</i>). Individual lines within the statements can be
|
||||
* commented using either --, // or REM at the start of the line.</p>
|
||||
*
|
||||
* <p>The <i>autocommit</i> attribute specifies whether auto-commit should be
|
||||
* turned on or off whilst executing the statements. If auto-commit is turned
|
||||
* on each statement will be executed and committed. If it is turned off the
|
||||
* statements will all be executed as one transaction.</p>
|
||||
*
|
||||
* <p>The <i>onerror</i> attribute specifies how to proceed when an error occurs
|
||||
* during the execution of one of the statements.
|
||||
* The possible values are: <b>continue</b> execution, only show the error;
|
||||
* <b>stop</b> execution and commit transaction;
|
||||
* and <b>abort</b> execution and transaction and fail task.</p>
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org> (Phing)
|
||||
* @author Jeff Martin <jeff@custommonkey.org> (Ant)
|
||||
* @author Michael McCallum <gholam@xtra.co.nz> (Ant)
|
||||
* @author Tim Stephenson <tim.stephenson@sybase.com> (Ant)
|
||||
* @package phing.tasks.ext.creole
|
||||
* @version $Revision: 905 $
|
||||
*/
|
||||
class CreoleSQLExecTask extends CreoleTask {
|
||||
|
||||
private $goodSql = 0;
|
||||
private $totalSql = 0;
|
||||
|
||||
const DELIM_ROW = "row";
|
||||
const DELIM_NORMAL = "normal";
|
||||
|
||||
/**
|
||||
* Database connection
|
||||
*/
|
||||
private $conn = null;
|
||||
|
||||
/**
|
||||
* files to load
|
||||
*/
|
||||
private $filesets = array();
|
||||
|
||||
/**
|
||||
* all filterchains objects assigned to this task
|
||||
*/
|
||||
private $filterChains = array();
|
||||
|
||||
/**
|
||||
* SQL statement
|
||||
*/
|
||||
private $statement = null;
|
||||
|
||||
/**
|
||||
* SQL input file
|
||||
*/
|
||||
private $srcFile = null;
|
||||
|
||||
/**
|
||||
* SQL input command
|
||||
*/
|
||||
private $sqlCommand = "";
|
||||
|
||||
/**
|
||||
* SQL transactions to perform
|
||||
*/
|
||||
private $transactions = array();
|
||||
|
||||
/**
|
||||
* SQL Statement delimiter
|
||||
*/
|
||||
private $delimiter = ";";
|
||||
|
||||
/**
|
||||
* The delimiter type indicating whether the delimiter will
|
||||
* only be recognized on a line by itself
|
||||
*/
|
||||
private $delimiterType = "normal"; // can't use constant just defined
|
||||
|
||||
/**
|
||||
* Print SQL results.
|
||||
*/
|
||||
private $print = false;
|
||||
|
||||
/**
|
||||
* Print header columns.
|
||||
*/
|
||||
private $showheaders = true;
|
||||
|
||||
/**
|
||||
* Results Output file.
|
||||
*/
|
||||
private $output = null;
|
||||
|
||||
|
||||
/**
|
||||
* Action to perform if an error is found
|
||||
**/
|
||||
private $onError = "abort";
|
||||
|
||||
/**
|
||||
* Encoding to use when reading SQL statements from a file
|
||||
*/
|
||||
private $encoding = null;
|
||||
|
||||
/**
|
||||
* Append to an existing file or overwrite it?
|
||||
*/
|
||||
private $append = false;
|
||||
|
||||
/**
|
||||
* Set the name of the SQL file to be run.
|
||||
* Required unless statements are enclosed in the build file
|
||||
*/
|
||||
public function setSrc(PhingFile $srcFile) {
|
||||
$this->srcFile = $srcFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an inline SQL command to execute.
|
||||
* NB: Properties are not expanded in this text.
|
||||
*/
|
||||
public function addText($sql) {
|
||||
$this->sqlCommand .= $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a set of files (nested fileset attribute).
|
||||
*/
|
||||
public function addFileset(FileSet $set) {
|
||||
$this->filesets[] = $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a filterchain
|
||||
*
|
||||
* @access public
|
||||
* @return object The created filterchain object
|
||||
*/
|
||||
function createFilterChain() {
|
||||
$num = array_push($this->filterChains, new FilterChain($this->project));
|
||||
return $this->filterChains[$num-1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a SQL transaction to execute
|
||||
*/
|
||||
public function createTransaction() {
|
||||
$t = new SQLExecTransaction($this);
|
||||
$this->transactions[] = $t;
|
||||
return $t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the file encoding to use on the SQL files read in
|
||||
*
|
||||
* @param encoding the encoding to use on the files
|
||||
*/
|
||||
public function setEncoding($encoding) {
|
||||
$this->encoding = $encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the statement delimiter.
|
||||
*
|
||||
* <p>For example, set this to "go" and delimitertype to "ROW" for
|
||||
* Sybase ASE or MS SQL Server.</p>
|
||||
*
|
||||
* @param delimiter
|
||||
*/
|
||||
public function setDelimiter($delimiter)
|
||||
{
|
||||
$this->delimiter = $delimiter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Delimiter type for this sql task. The delimiter type takes two
|
||||
* values - normal and row. Normal means that any occurence of the delimiter
|
||||
* terminate the SQL command whereas with row, only a line containing just
|
||||
* the delimiter is recognized as the end of the command.
|
||||
*
|
||||
* @param string $delimiterType
|
||||
*/
|
||||
public function setDelimiterType($delimiterType)
|
||||
{
|
||||
$this->delimiterType = $delimiterType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the print flag.
|
||||
*
|
||||
* @param boolean $print
|
||||
*/
|
||||
public function setPrint($print)
|
||||
{
|
||||
$this->print = (boolean) $print;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print headers for result sets from the
|
||||
* statements; optional, default true.
|
||||
* @param boolean $showheaders
|
||||
*/
|
||||
public function setShowheaders($showheaders) {
|
||||
$this->showheaders = (boolean) $showheaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the output file;
|
||||
* optional, defaults to the console.
|
||||
* @param PhingFile $output
|
||||
*/
|
||||
public function setOutput(PhingFile $output) {
|
||||
$this->output = $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* whether output should be appended to or overwrite
|
||||
* an existing file. Defaults to false.
|
||||
* @param $append
|
||||
*/
|
||||
public function setAppend($append) {
|
||||
$this->append = (boolean) $append;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action to perform when statement fails: continue, stop, or abort
|
||||
* optional; default "abort"
|
||||
*/
|
||||
public function setOnerror($action) {
|
||||
$this->onError = $action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the sql file and then execute it
|
||||
* @throws BuildException
|
||||
*/
|
||||
public function main() {
|
||||
|
||||
$savedTransaction = array();
|
||||
for($i=0,$size=count($this->transactions); $i < $size; $i++) {
|
||||
$savedTransaction[] = clone $this->transactions[$i];
|
||||
}
|
||||
|
||||
$savedSqlCommand = $this->sqlCommand;
|
||||
|
||||
$this->sqlCommand = trim($this->sqlCommand);
|
||||
|
||||
try {
|
||||
if ($this->srcFile === null && $this->sqlCommand === ""
|
||||
&& empty($this->filesets)) {
|
||||
if (count($this->transactions) === 0) {
|
||||
throw new BuildException("Source file or fileset, "
|
||||
. "transactions or sql statement "
|
||||
. "must be set!", $this->location);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->srcFile !== null && !$this->srcFile->exists()) {
|
||||
throw new BuildException("Source file does not exist!", $this->location);
|
||||
}
|
||||
|
||||
// deal with the filesets
|
||||
for ($i = 0,$size=count($this->filesets); $i < $size; $i++) {
|
||||
$fs = $this->filesets[$i];
|
||||
$ds = $fs->getDirectoryScanner($this->project);
|
||||
$srcDir = $fs->getDir($this->project);
|
||||
|
||||
$srcFiles = $ds->getIncludedFiles();
|
||||
|
||||
// Make a transaction for each file
|
||||
for ($j=0, $size=count($srcFiles); $j < $size; $j++) {
|
||||
$t = $this->createTransaction();
|
||||
$t->setSrc(new PhingFile($srcDir, $srcFiles[$j]));
|
||||
}
|
||||
}
|
||||
|
||||
// Make a transaction group for the outer command
|
||||
$t = $this->createTransaction();
|
||||
if ($this->srcFile) $t->setSrc($this->srcFile);
|
||||
$t->addText($this->sqlCommand);
|
||||
$this->conn = $this->getConnection();
|
||||
|
||||
try {
|
||||
|
||||
$this->statement = $this->conn->createStatement();
|
||||
|
||||
$out = null;
|
||||
|
||||
try {
|
||||
|
||||
if ($this->output !== null) {
|
||||
$this->log("Opening output file " . $this->output, Project::MSG_VERBOSE);
|
||||
$out = new BufferedWriter(new FileWriter($this->output->getAbsolutePath(), $this->append));
|
||||
}
|
||||
|
||||
// Process all transactions
|
||||
for ($i=0,$size=count($this->transactions); $i < $size; $i++) {
|
||||
$this->transactions[$i]->runTransaction($out);
|
||||
if (!$this->isAutocommit()) {
|
||||
$this->log("Commiting transaction", Project::MSG_VERBOSE);
|
||||
$this->conn->commit();
|
||||
}
|
||||
}
|
||||
if ($out) $out->close();
|
||||
} catch (Exception $e) {
|
||||
if ($out) $out->close();
|
||||
throw $e;
|
||||
}
|
||||
} catch (IOException $e) {
|
||||
if (!$this->isAutocommit() && $this->conn !== null && $this->onError == "abort") {
|
||||
try {
|
||||
$this->conn->rollback();
|
||||
} catch (SQLException $ex) {}
|
||||
}
|
||||
throw new BuildException($e->getMessage(), $this->location);
|
||||
} catch (SQLException $e){
|
||||
if (!$this->isAutocommit() && $this->conn !== null && $this->onError == "abort") {
|
||||
try {
|
||||
$this->conn->rollback();
|
||||
} catch (SQLException $ex) {}
|
||||
}
|
||||
throw new BuildException($e->getMessage(), $this->location);
|
||||
}
|
||||
|
||||
$this->log($this->goodSql . " of " . $this->totalSql .
|
||||
" SQL statements executed successfully");
|
||||
} catch (Exception $e) {
|
||||
$this->transactions = $savedTransaction;
|
||||
$this->sqlCommand = $savedSqlCommand;
|
||||
throw $e;
|
||||
}
|
||||
// finally {
|
||||
$this->transactions = $savedTransaction;
|
||||
$this->sqlCommand = $savedSqlCommand;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* read in lines and execute them
|
||||
* @throws SQLException, IOException
|
||||
*/
|
||||
public function runStatements(Reader $reader, $out = null) {
|
||||
$sql = "";
|
||||
$line = "";
|
||||
|
||||
$buffer = '';
|
||||
|
||||
if ((is_array($this->filterChains)) && (!empty($this->filterChains))) {
|
||||
$in = FileUtils::getChainedReader(new BufferedReader($reader), $this->filterChains, $this->getProject());
|
||||
while(-1 !== ($read = $in->read())) { // -1 indicates EOF
|
||||
$buffer .= $read;
|
||||
}
|
||||
$lines = explode("\n", $buffer);
|
||||
} else {
|
||||
$in = new BufferedReader($reader);
|
||||
|
||||
while (($line = $in->readLine()) !== null) {
|
||||
$lines[] = $line;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
foreach ($lines as $line) {
|
||||
$line = trim($line);
|
||||
$line = ProjectConfigurator::replaceProperties($this->project, $line,
|
||||
$this->project->getProperties());
|
||||
|
||||
if (StringHelper::startsWith("//", $line) ||
|
||||
StringHelper::startsWith("--", $line) ||
|
||||
StringHelper::startsWith("#", $line)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strlen($line) > 4
|
||||
&& strtoupper(substr($line,0, 4)) == "REM ") {
|
||||
continue;
|
||||
}
|
||||
|
||||
$sql .= " " . $line;
|
||||
$sql = trim($sql);
|
||||
|
||||
// SQL defines "--" as a comment to EOL
|
||||
// and in Oracle it may contain a hint
|
||||
// so we cannot just remove it, instead we must end it
|
||||
if (strpos($line, "--") !== false) {
|
||||
$sql .= "\n";
|
||||
}
|
||||
|
||||
if ($this->delimiterType == self::DELIM_NORMAL
|
||||
&& StringHelper::endsWith($this->delimiter, $sql)
|
||||
|| $this->delimiterType == self::DELIM_ROW
|
||||
&& $line == $this->delimiter) {
|
||||
$this->log("SQL: " . $sql, Project::MSG_VERBOSE);
|
||||
$this->execSQL(StringHelper::substring($sql, 0, strlen($sql) - strlen($this->delimiter)), $out);
|
||||
$sql = "";
|
||||
}
|
||||
}
|
||||
|
||||
// Catch any statements not followed by ;
|
||||
if ($sql !== "") {
|
||||
$this->execSQL($sql, $out);
|
||||
}
|
||||
} catch (SQLException $e) {
|
||||
throw new BuildException("Error running statements", $e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Exec the sql statement.
|
||||
* @throws SQLException
|
||||
*/
|
||||
protected function execSQL($sql, $out = null) {
|
||||
// Check and ignore empty statements
|
||||
if (trim($sql) == "") {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->totalSql++;
|
||||
if (!$this->statement->execute($sql)) {
|
||||
$this->log($this->statement->getUpdateCount() . " rows affected", Project::MSG_VERBOSE);
|
||||
} else {
|
||||
if ($this->print) {
|
||||
$this->printResults($out);
|
||||
}
|
||||
}
|
||||
|
||||
$this->goodSql++;
|
||||
|
||||
} catch (SQLException $e) {
|
||||
$this->log("Failed to execute: " . $sql, Project::MSG_ERR);
|
||||
if ($this->onError != "continue") {
|
||||
throw new BuildException("Failed to execute SQL", $e);
|
||||
}
|
||||
$this->log($e->getMessage(), Project::MSG_ERR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* print any results in the statement.
|
||||
* @throw SQLException
|
||||
*/
|
||||
protected function printResults($out = null) {
|
||||
|
||||
$rs = null;
|
||||
do {
|
||||
$rs = $this->statement->getResultSet();
|
||||
|
||||
if ($rs !== null) {
|
||||
|
||||
$this->log("Processing new result set.", Project::MSG_VERBOSE);
|
||||
|
||||
$line = "";
|
||||
|
||||
$colsprinted = false;
|
||||
|
||||
while ($rs->next()) {
|
||||
$fields = $rs->getRow();
|
||||
|
||||
if (!$colsprinted && $this->showheaders) {
|
||||
$first = true;
|
||||
foreach($fields as $fieldName => $ignore) {
|
||||
if ($first) $first = false; else $line .= ",";
|
||||
$line .= $fieldName;
|
||||
}
|
||||
if ($out !== null) {
|
||||
$out->write($line);
|
||||
$out->newLine();
|
||||
} else {
|
||||
print($line.PHP_EOL);
|
||||
}
|
||||
$line = "";
|
||||
$colsprinted = true;
|
||||
} // if show headers
|
||||
|
||||
$first = true;
|
||||
foreach($fields as $columnValue) {
|
||||
|
||||
if ($columnValue != null) {
|
||||
$columnValue = trim($columnValue);
|
||||
}
|
||||
|
||||
if ($first) {
|
||||
$first = false;
|
||||
} else {
|
||||
$line .= ",";
|
||||
}
|
||||
$line .= $columnValue;
|
||||
}
|
||||
|
||||
if ($out !== null) {
|
||||
$out->write($line);
|
||||
$out->newLine();
|
||||
} else {
|
||||
print($line . PHP_EOL);
|
||||
}
|
||||
$line = "";
|
||||
|
||||
} // while rs->next()
|
||||
}
|
||||
} while ($this->statement->getMoreResults());
|
||||
print(PHP_EOL);
|
||||
if ($out !== null) $out->newLine();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* "Inner" class that contains the definition of a new transaction element.
|
||||
* Transactions allow several files or blocks of statements
|
||||
* to be executed using the same JDBC connection and commit
|
||||
* operation in between.
|
||||
*
|
||||
* @package phing.tasks.ext.creole
|
||||
*/
|
||||
class SQLExecTransaction {
|
||||
|
||||
private $tSrcFile = null;
|
||||
private $tSqlCommand = "";
|
||||
private $parent;
|
||||
|
||||
function __construct($parent)
|
||||
{
|
||||
// Parent is required so that we can log things ...
|
||||
$this->parent = $parent;
|
||||
}
|
||||
|
||||
public function setSrc(PhingFile $src)
|
||||
{
|
||||
$this->tSrcFile = $src;
|
||||
}
|
||||
|
||||
public function addText($sql)
|
||||
{
|
||||
$this->tSqlCommand .= $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IOException, SQLException
|
||||
*/
|
||||
public function runTransaction($out = null)
|
||||
{
|
||||
if (!empty($this->tSqlCommand)) {
|
||||
$this->parent->log("Executing commands", Project::MSG_INFO);
|
||||
$this->parent->runStatements(new StringReader($this->tSqlCommand), $out);
|
||||
}
|
||||
|
||||
if ($this->tSrcFile !== null) {
|
||||
$this->parent->log("Executing file: " . $this->tSrcFile->getAbsolutePath(),
|
||||
Project::MSG_INFO);
|
||||
|
||||
$reader = new FileReader($this->tSrcFile);
|
||||
|
||||
$this->parent->runStatements($reader, $out);
|
||||
$reader->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
242
airtime_mvc/library/phing/tasks/ext/creole/CreoleTask.php
Normal file
242
airtime_mvc/library/phing/tasks/ext/creole/CreoleTask.php
Normal file
|
@ -0,0 +1,242 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* $Id: CreoleTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
include_once 'phing/types/Reference.php';
|
||||
|
||||
/**
|
||||
* Handles Creole configuration needed by SQL type tasks.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org> (Phing)
|
||||
* @author Nick Chalko <nick@chalko.com> (Ant)
|
||||
* @author Jeff Martin <jeff@custommonkey.org> (Ant)
|
||||
* @author Michael McCallum <gholam@xtra.co.nz> (Ant)
|
||||
* @author Tim Stephenson <tim.stephenson@sybase.com> (Ant)
|
||||
* @version $Revision: 905 $
|
||||
* @package phing.tasks.system
|
||||
*/
|
||||
abstract class CreoleTask extends Task {
|
||||
|
||||
/**
|
||||
* Used for caching loaders / driver. This is to avoid
|
||||
* getting an OutOfMemoryError when calling this task
|
||||
* multiple times in a row.
|
||||
*
|
||||
* NOT IMPLEMENTED YET
|
||||
*/
|
||||
private static $loaderMap = array();
|
||||
|
||||
private $caching = true;
|
||||
|
||||
/**
|
||||
* Autocommit flag. Default value is false
|
||||
*/
|
||||
private $autocommit = false;
|
||||
|
||||
/**
|
||||
* [optional] Classpath to Creole driver to use.
|
||||
* @param string
|
||||
*/
|
||||
private $driver;
|
||||
|
||||
/**
|
||||
* DB url.
|
||||
*/
|
||||
private $url;
|
||||
|
||||
/**
|
||||
* User name.
|
||||
*/
|
||||
private $userId;
|
||||
|
||||
/**
|
||||
* Password
|
||||
*/
|
||||
private $password;
|
||||
|
||||
/**
|
||||
* RDBMS Product needed for this SQL.
|
||||
**/
|
||||
private $rdbms;
|
||||
|
||||
/**
|
||||
* Initialize CreoleTask.
|
||||
* This method includes any necessary Creole libraries and triggers
|
||||
* appropriate error if they cannot be found. This is not done in header
|
||||
* because we may want this class to be loaded w/o triggering an error.
|
||||
*/
|
||||
function init() {
|
||||
include_once 'creole/Creole.php';
|
||||
if (!class_exists('Creole')) {
|
||||
throw new Exception("Creole task depends on Creole classes being on include_path. (i.e. include of 'creole/Creole.php' failed.)");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Caching loaders / driver. This is to avoid
|
||||
* getting an OutOfMemoryError when calling this task
|
||||
* multiple times in a row; default: true
|
||||
* @param $enable
|
||||
*/
|
||||
public function setCaching($enable) {
|
||||
$this->caching = $enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the database connection URL; required.
|
||||
* @param url The url to set
|
||||
*/
|
||||
public function setUrl($url) {
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Creole driver to be used.
|
||||
*
|
||||
* @param string $driver driver class name
|
||||
*/
|
||||
public function setDriver($driver)
|
||||
{
|
||||
$this->driver = $driver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the password; required.
|
||||
* @param password The password to set
|
||||
*/
|
||||
public function setPassword($password) {
|
||||
$this->password = $password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Auto commit flag for database connection;
|
||||
* optional, default false.
|
||||
* @param autocommit The autocommit to set
|
||||
*/
|
||||
public function setAutocommit($autocommit) {
|
||||
$this->autocommit = $autocommit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the version string, execute task only if
|
||||
* rdbms version match; optional.
|
||||
* @param version The version to set
|
||||
*/
|
||||
public function setVersion($version) {
|
||||
$this->version = $version;
|
||||
}
|
||||
|
||||
protected function getLoaderMap() {
|
||||
return self::$loaderMap;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new Connection as using the driver, url, userid and password specified.
|
||||
* The calling method is responsible for closing the connection.
|
||||
* @return Connection the newly created connection.
|
||||
* @throws BuildException if the UserId/Password/Url is not set or there is no suitable driver or the driver fails to load.
|
||||
*/
|
||||
protected function getConnection() {
|
||||
|
||||
if ($this->url === null) {
|
||||
throw new BuildException("Url attribute must be set!", $this->location);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$this->log("Connecting to " . $this->getUrl(), Project::MSG_VERBOSE);
|
||||
$info = new Properties();
|
||||
|
||||
$dsn = Creole::parseDSN($this->url);
|
||||
|
||||
if (!isset($dsn["username"]) && $this->userId === null) {
|
||||
throw new BuildException("Username must be in URL or userid attribute must be set.", $this->location);
|
||||
}
|
||||
|
||||
if ($this->userId) {
|
||||
$dsn["username"] = $this->getUserId();
|
||||
}
|
||||
|
||||
if ($this->password) {
|
||||
$dsn["password"] = $this->getPassword();
|
||||
}
|
||||
|
||||
if ($this->driver) {
|
||||
Creole::registerDriver($dsn['phptype'], $this->driver);
|
||||
}
|
||||
|
||||
$conn = Creole::getConnection($dsn);
|
||||
$conn->setAutoCommit($this->autocommit);
|
||||
return $conn;
|
||||
|
||||
} catch (SQLException $e) {
|
||||
throw new BuildException($e->getMessage(), $this->location);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function isCaching($value) {
|
||||
$this->caching = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the autocommit.
|
||||
* @return Returns a boolean
|
||||
*/
|
||||
public function isAutocommit() {
|
||||
return $this->autocommit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the url.
|
||||
* @return Returns a String
|
||||
*/
|
||||
public function getUrl() {
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the userId.
|
||||
* @return Returns a String
|
||||
*/
|
||||
public function getUserId() {
|
||||
return $this->userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user name for the connection; required.
|
||||
* @param userId The userId to set
|
||||
*/
|
||||
public function setUserid($userId) {
|
||||
$this->userId = $userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the password.
|
||||
* @return Returns a String
|
||||
*/
|
||||
public function getPassword() {
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
}
|
196
airtime_mvc/library/phing/tasks/ext/dbdeploy/DbDeployTask.php
Normal file
196
airtime_mvc/library/phing/tasks/ext/dbdeploy/DbDeployTask.php
Normal file
|
@ -0,0 +1,196 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: DbDeployTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
require_once 'phing/tasks/ext/dbdeploy/DbmsSyntaxFactory.php';
|
||||
|
||||
|
||||
/**
|
||||
* Generate SQL script for db using dbdeploy schema version table and delta scripts
|
||||
*
|
||||
* <dbdeploy url="mysql:host=localhost;dbname=test" userid="dbdeploy" password="dbdeploy" dir="db" outputfile="">
|
||||
*
|
||||
* @author Luke Crouch at SourceForge (http://sourceforge.net)
|
||||
* @version $Revision: 905 $
|
||||
* @package phing.tasks.ext.dbdeploy
|
||||
*/
|
||||
|
||||
class DbDeployTask extends Task {
|
||||
|
||||
public static $TABLE_NAME = 'changelog';
|
||||
|
||||
protected $url;
|
||||
protected $userid;
|
||||
protected $password;
|
||||
protected $dir;
|
||||
protected $outputFile = 'dbdeploy_deploy.sql';
|
||||
protected $undoOutputFile = 'dbdeploy_undo.sql';
|
||||
protected $deltaSet = 'Main';
|
||||
protected $lastChangeToApply = 999;
|
||||
protected $dbmsSyntax = null;
|
||||
|
||||
function main() {
|
||||
try{
|
||||
// get correct DbmsSyntax object
|
||||
$dbms = substr($this->url, 0, strpos($this->url, ':'));
|
||||
$dbmsSyntaxFactory = new DbmsSyntaxFactory($dbms);
|
||||
$this->dbmsSyntax = $dbmsSyntaxFactory->getDbmsSyntax();
|
||||
|
||||
// open file handles for output
|
||||
$outputFileHandle = fopen($this->outputFile, "w+");
|
||||
$undoOutputFileHandle = fopen($this->undoOutputFile, "w+");
|
||||
|
||||
// figure out which revisions are in the db already
|
||||
$this->appliedChangeNumbers = $this->getAppliedChangeNumbers();
|
||||
$this->log('Current db revision: ' . $this->getLastChangeAppliedInDb());
|
||||
|
||||
// generate sql file needed to take db to "lastChangeToApply" version
|
||||
$doSql = $this->doDeploy();
|
||||
$undoSql = $this->undoDeploy();
|
||||
|
||||
// write the do and undo SQL to their respective files
|
||||
fwrite($outputFileHandle, $doSql);
|
||||
fwrite($undoOutputFileHandle, $undoSql);
|
||||
|
||||
} catch (Exception $e){
|
||||
throw new BuildException($e);
|
||||
}
|
||||
}
|
||||
|
||||
function getAppliedChangeNumbers(){
|
||||
if(count($this->appliedChangeNumbers) == 0){
|
||||
$this->log('Getting applied changed numbers from DB: ' . $this->url );
|
||||
$appliedChangeNumbers = array();
|
||||
$dbh = new PDO($this->url, $this->userid, $this->password);
|
||||
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$sql = "SELECT * FROM " . DbDeployTask::$TABLE_NAME . " WHERE delta_set = '$this->deltaSet' ORDER BY change_number";
|
||||
foreach($dbh->query($sql) as $change){
|
||||
$appliedChangeNumbers[] = $change['change_number'];
|
||||
}
|
||||
$this->appliedChangeNumbers = $appliedChangeNumbers;
|
||||
}
|
||||
return $this->appliedChangeNumbers;
|
||||
}
|
||||
|
||||
function getLastChangeAppliedInDb(){
|
||||
return (count($this->appliedChangeNumbers) > 0) ? max($this->appliedChangeNumbers) : 0;
|
||||
}
|
||||
|
||||
function doDeploy(){
|
||||
$sqlToPerformDeploy = '';
|
||||
$lastChangeAppliedInDb = $this->getLastChangeAppliedInDb();
|
||||
$files = $this->getDeltasFilesArray();
|
||||
ksort($files);
|
||||
foreach($files as $fileChangeNumber=>$fileName){
|
||||
if($fileChangeNumber > $lastChangeAppliedInDb && $fileChangeNumber <= $this->lastChangeToApply){
|
||||
$sqlToPerformDeploy .= '-- Fragment begins: ' . $fileChangeNumber . ' --' . "\n";
|
||||
$sqlToPerformDeploy .= 'INSERT INTO ' . DbDeployTask::$TABLE_NAME . ' (change_number, delta_set, start_dt, applied_by, description)'.
|
||||
' VALUES ('. $fileChangeNumber .', \''. $this->deltaSet .'\', '. $this->dbmsSyntax->generateTimestamp() .', \'dbdeploy\', \''. $fileName .'\');' . "\n";
|
||||
$fullFileName = $this->dir . '/' . $fileName;
|
||||
$fh = fopen($fullFileName, 'r');
|
||||
$contents = fread($fh, filesize($fullFileName));
|
||||
// allow construct with and without space added
|
||||
$deploySQLFromFileSplit = strpos($contents, '-- //@UNDO');
|
||||
if ($deploySQLFromFileSplit === false)
|
||||
$deploySQLFromFileSplit = strpos($contents, '--//@UNDO');
|
||||
$deploySQLFromFile = substr($contents,0,$deploySQLFromFileSplit);
|
||||
$sqlToPerformDeploy .= $deploySQLFromFile;
|
||||
$sqlToPerformDeploy .= 'UPDATE ' . DbDeployTask::$TABLE_NAME . ' SET complete_dt = ' . $this->dbmsSyntax->generateTimestamp() . ' WHERE change_number = ' . $fileChangeNumber . ' AND delta_set = \'' . $this->deltaSet . '\';' . "\n";
|
||||
$sqlToPerformDeploy .= '-- Fragment ends: ' . $fileChangeNumber . ' --' . "\n";
|
||||
}
|
||||
}
|
||||
return $sqlToPerformDeploy;
|
||||
}
|
||||
|
||||
function undoDeploy(){
|
||||
$sqlToPerformUndo = '';
|
||||
$lastChangeAppliedInDb = $this->getLastChangeAppliedInDb();
|
||||
$files = $this->getDeltasFilesArray();
|
||||
krsort($files);
|
||||
foreach($files as $fileChangeNumber=>$fileName){
|
||||
if($fileChangeNumber > $lastChangeAppliedInDb && $fileChangeNumber <= $this->lastChangeToApply){
|
||||
$fullFileName = $this->dir . '/' . $fileName;
|
||||
$fh = fopen($fullFileName, 'r');
|
||||
$contents = fread($fh, filesize($fullFileName));
|
||||
$undoSQLFromFile = substr($contents,strpos($contents, '-- //@UNDO')+10);
|
||||
$sqlToPerformUndo .= $undoSQLFromFile;
|
||||
$sqlToPerformUndo .= 'DELETE FROM ' . DbDeployTask::$TABLE_NAME . ' WHERE change_number = ' . $fileChangeNumber . ' AND delta_set = \'' . $this->deltaSet . '\';' . "\n";
|
||||
$sqlToPerformUndo .= '-- Fragment ends: ' . $fileChangeNumber . ' --' . "\n";
|
||||
}
|
||||
}
|
||||
return $sqlToPerformUndo;
|
||||
}
|
||||
|
||||
function getDeltasFilesArray(){
|
||||
$baseDir = realpath($this->dir);
|
||||
$dh = opendir($baseDir);
|
||||
$fileChangeNumberPrefix = '';
|
||||
while(($file = readdir($dh)) !== false){
|
||||
if(preg_match('[\d+]', $file, $fileChangeNumberPrefix)){
|
||||
$files[intval($fileChangeNumberPrefix[0])] = $file;
|
||||
}
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
|
||||
function setUrl($url){
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
function setUserId($userid){
|
||||
$this->userid = $userid;
|
||||
}
|
||||
|
||||
function setPassword($password){
|
||||
$this->password = $password;
|
||||
}
|
||||
|
||||
function setDir($dir){
|
||||
$this->dir = $dir;
|
||||
}
|
||||
|
||||
function setOutputFile($outputFile){
|
||||
$this->outputFile = $outputFile;
|
||||
}
|
||||
|
||||
function setUndoOutputFile($undoOutputFile){
|
||||
$this->undoOutputFile = $undoOutputFile;
|
||||
}
|
||||
|
||||
function setLastChangeToApply($lastChangeToApply){
|
||||
$this->lastChangeToApply = $lastChangeToApply;
|
||||
}
|
||||
|
||||
function setDeltaSet($deltaSet){
|
||||
$this->deltaSet = $deltaSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new fileset.
|
||||
* @return FileSet
|
||||
*/
|
||||
public function createFileSet() {
|
||||
$this->fileset = new FileSet();
|
||||
$this->filesets[] = $this->fileset;
|
||||
return $this->fileset;
|
||||
}
|
||||
}
|
||||
|
34
airtime_mvc/library/phing/tasks/ext/dbdeploy/DbmsSyntax.php
Normal file
34
airtime_mvc/library/phing/tasks/ext/dbdeploy/DbmsSyntax.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: DbmsSyntax.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Utility class for generating necessary server-specific SQL commands
|
||||
*
|
||||
* @author Luke Crouch at SourceForge (http://sourceforge.net)
|
||||
* @version $Revision: 905 $
|
||||
* @package phing.tasks.ext.dbdeploy
|
||||
*/
|
||||
|
||||
abstract class DbmsSyntax
|
||||
{
|
||||
public abstract function generateTimestamp();
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: DbmsSyntaxFactory.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
require_once 'phing/tasks/ext/dbdeploy/DbmsSyntax.php';
|
||||
|
||||
/**
|
||||
* Factory for generating dbms-specific syntax-generating objects
|
||||
*
|
||||
* @author Luke Crouch at SourceForge (http://sourceforge.net)
|
||||
* @version $Revision: 905 $
|
||||
* @package phing.tasks.ext.dbdeploy
|
||||
*/
|
||||
|
||||
class DbmsSyntaxFactory
|
||||
{
|
||||
private $dbms;
|
||||
|
||||
public function __construct($dbms)
|
||||
{
|
||||
$this->dbms = $dbms;
|
||||
}
|
||||
|
||||
public function getDbmsSyntax()
|
||||
{
|
||||
switch ($this->dbms){
|
||||
case('sqlite') :
|
||||
require_once 'phing/tasks/ext/dbdeploy/DbmsSyntaxSQLite.php';
|
||||
return new DbmsSyntaxSQLite();
|
||||
case('mysql'):
|
||||
require_once 'phing/tasks/ext/dbdeploy/DbmsSyntaxMysql.php';
|
||||
return new DbmsSyntaxMysql();
|
||||
case('mssql'):
|
||||
require_once 'phing/tasks/ext/dbdeploy/DbmsSyntaxMsSql.php';
|
||||
return new DbmsSyntaxMsSql();
|
||||
default:
|
||||
throw new Exception($this->dbms . ' is not supported by dbdeploy task.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: DbmsSyntaxMsSql.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Utility class for generating necessary server-specific SQL commands
|
||||
*
|
||||
* @author Luke Crouch at SourceForge (http://sourceforge.net)
|
||||
* @version $Revision: 905 $
|
||||
* @package phing.tasks.ext.dbdeploy
|
||||
*/
|
||||
|
||||
class DbmsSyntaxMsSql extends DbmsSyntax
|
||||
{
|
||||
public function generateTimestamp()
|
||||
{
|
||||
return "DATEDIFF(s, '19700101', GETDATE())";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: DbmsSyntaxMysql.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Utility class for generating necessary server-specific SQL commands
|
||||
*
|
||||
* @author Luke Crouch at SourceForge (http://sourceforge.net)
|
||||
* @version $Revision: 905 $
|
||||
* @package phing.tasks.ext.dbdeploy
|
||||
*/
|
||||
|
||||
class DbmsSyntaxMysql extends DbmsSyntax
|
||||
{
|
||||
public function generateTimestamp()
|
||||
{
|
||||
return "NOW()";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: DbmsSyntaxSQLite.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Utility class for generating necessary server-specific SQL commands
|
||||
*
|
||||
* @author Luke Crouch at SourceForge (http://sourceforge.net)
|
||||
* @version $Revision: 905 $
|
||||
* @package phing.tasks.ext.dbdeploy
|
||||
*/
|
||||
|
||||
class DbmsSyntaxSQLite extends DbmsSyntax
|
||||
{
|
||||
public function generateTimestamp()
|
||||
{
|
||||
return "strftime('%s','now')";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: IoncubeComment.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Wrapper for comments for ionCube tasks
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: IoncubeComment.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.ioncube
|
||||
* @since 2.2.0
|
||||
*/
|
||||
class IoncubeComment
|
||||
{
|
||||
private $value = "";
|
||||
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function addText($txt)
|
||||
{
|
||||
$this->value = trim($txt);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,535 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: IoncubeEncoderTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
require_once 'phing/tasks/ext/ioncube/IoncubeComment.php';
|
||||
|
||||
/**
|
||||
* Invokes the ionCube Encoder (PHP4 or PHP5)
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @author Andrew Eddie <andrew.eddie@jamboworks.com>
|
||||
* @version $Id: IoncubeEncoderTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.ioncube
|
||||
* @since 2.2.0
|
||||
*/
|
||||
class IoncubeEncoderTask extends Task
|
||||
{
|
||||
private $ionSwitches = array();
|
||||
|
||||
private $ionOptions = array();
|
||||
|
||||
private $ionOptionsXS = array();
|
||||
|
||||
private $comments = array();
|
||||
|
||||
private $encoderName = 'ioncube_encoder';
|
||||
|
||||
private $fromDir = '';
|
||||
|
||||
private $ioncubePath = '/usr/local/ioncube';
|
||||
|
||||
private $phpVersion = '5';
|
||||
|
||||
private $targetOption = '';
|
||||
|
||||
private $toDir = '';
|
||||
|
||||
/**
|
||||
* Adds a comment to be used in encoded files
|
||||
*/
|
||||
function addComment(IoncubeComment $comment)
|
||||
{
|
||||
$this->comments[] = $comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the allowed server
|
||||
*/
|
||||
function setAllowedServer($value)
|
||||
{
|
||||
$this->ionOptionsXS['allowed-server'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the allowed server setting
|
||||
*/
|
||||
function getAllowedServer()
|
||||
{
|
||||
return $this->ionOptionsXS['allowed-server'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the binary option
|
||||
*/
|
||||
function setBinary($value)
|
||||
{
|
||||
$this->ionSwitches['binary'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the binary option
|
||||
*/
|
||||
function getBinary()
|
||||
{
|
||||
return $this->ionSwitches['binary'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets files or folders to copy (separated by space)
|
||||
*/
|
||||
function setCopy($value)
|
||||
{
|
||||
$this->ionOptionsXS['copy'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the copy setting
|
||||
*/
|
||||
function getCopy()
|
||||
{
|
||||
return $this->ionOptionsXS['copy'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets additional file patterns, files or directories to encode,
|
||||
* or to reverse the effect of copy (separated by space)
|
||||
*/
|
||||
function setEncode($value)
|
||||
{
|
||||
$this->ionOptionsXS['encode'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the encode setting
|
||||
*/
|
||||
function getEncode()
|
||||
{
|
||||
return $this->ionOptionsXS['encode'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets regexps of additional files to encrypt (separated by space)
|
||||
*/
|
||||
function setEncrypt($value)
|
||||
{
|
||||
$this->ionOptionsXS['encrypt'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns regexps of additional files to encrypt (separated by space)
|
||||
*/
|
||||
function getEncrypt()
|
||||
{
|
||||
return $this->ionOptionsXS['encrypt'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a period after which the files expire
|
||||
*/
|
||||
function setExpirein($value)
|
||||
{
|
||||
$this->ionOptions['expire-in'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expireIn setting
|
||||
*/
|
||||
function getExpirein()
|
||||
{
|
||||
return $this->ionOptions['expire-in'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a YYYY-MM-DD date to expire the files
|
||||
*/
|
||||
function setExpireon($value)
|
||||
{
|
||||
$this->ionOptions['expire-on'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expireOn setting
|
||||
*/
|
||||
function getExpireon()
|
||||
{
|
||||
return $this->ionOptions['expire-on'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the source directory
|
||||
*/
|
||||
function setFromDir($value)
|
||||
{
|
||||
$this->fromDir = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the source directory
|
||||
*/
|
||||
function getFromDir()
|
||||
{
|
||||
return $this->fromDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set files and directories to ignore entirely and exclude from the target directory
|
||||
* (separated by space).
|
||||
*/
|
||||
function setIgnore($value)
|
||||
{
|
||||
$this->ionOptionsXS['ignore'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ignore setting
|
||||
*/
|
||||
function getIgnore()
|
||||
{
|
||||
return $this->ionOptionsXS['ignore'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the path to the ionCube encoder
|
||||
*/
|
||||
function setIoncubePath($value)
|
||||
{
|
||||
$this->ioncubePath = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path to the ionCube encoder
|
||||
*/
|
||||
function getIoncubePath()
|
||||
{
|
||||
return $this->ioncubePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set files and directories not to be ignored (separated by space).
|
||||
*/
|
||||
function setKeep($value)
|
||||
{
|
||||
$this->ionOptionsXS['keep'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ignore setting
|
||||
*/
|
||||
function getKeep()
|
||||
{
|
||||
return $this->ionOptionsXS['keep'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the path to the license file to use
|
||||
*/
|
||||
function setLicensePath($value)
|
||||
{
|
||||
$this->ionOptions['with-license'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path to the license file to use
|
||||
*/
|
||||
function getLicensePath()
|
||||
{
|
||||
return $this->ionOptions['with-license'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the no-doc-comments option
|
||||
*/
|
||||
function setNoDocComments($value)
|
||||
{
|
||||
$this->ionSwitches['no-doc-comment'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the no-doc-comments option
|
||||
*/
|
||||
function getNoDocComments()
|
||||
{
|
||||
return $this->ionSwitches['no-doc-comment'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the obfuscate option
|
||||
*/
|
||||
function setObfuscate($value)
|
||||
{
|
||||
$this->ionOptionsXS['obfuscate'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the optimize option
|
||||
*/
|
||||
function getObfuscate()
|
||||
{
|
||||
return $this->ionOptionsXS['obfuscate'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the obfuscation key (required if using the obfuscate option)
|
||||
*/
|
||||
function setObfuscationKey($value)
|
||||
{
|
||||
$this->ionOptions['obfuscation-key'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the optimize option
|
||||
*/
|
||||
function getObfuscationKey()
|
||||
{
|
||||
return $this->ionOptions['obfuscation-key'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the optimize option
|
||||
*/
|
||||
function setOptimize($value)
|
||||
{
|
||||
$this->ionOptions['optimize'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the optimize option
|
||||
*/
|
||||
function getOptimize()
|
||||
{
|
||||
return $this->ionOptions['optimize'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the passphrase to use when encoding files
|
||||
*/
|
||||
function setPassPhrase($value)
|
||||
{
|
||||
$this->ionOptions['passphrase'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the passphrase to use when encoding files
|
||||
*/
|
||||
function getPassPhrase()
|
||||
{
|
||||
return $this->ionOptions['passphrase'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the version of PHP to use (defaults to 5)
|
||||
*/
|
||||
function setPhpVersion($value)
|
||||
{
|
||||
$this->phpVersion = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the version of PHP to use (defaults to 5)
|
||||
*/
|
||||
function getPhpVersion()
|
||||
{
|
||||
return $this->phpVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the target directory
|
||||
*/
|
||||
function setToDir($value)
|
||||
{
|
||||
$this->toDir = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the target directory
|
||||
*/
|
||||
function getToDir()
|
||||
{
|
||||
return $this->toDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the without-runtime-loader-support option
|
||||
*/
|
||||
function setWithoutRuntimeLoaderSupport($value)
|
||||
{
|
||||
$this->ionSwitches['without-runtime-loader-support'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the without-runtime-loader-support option
|
||||
*/
|
||||
function getWithoutRuntimeLoaderSupport()
|
||||
{
|
||||
return $this->ionSwitches['without-runtime-loader-support'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the no-short-open-tags option
|
||||
*/
|
||||
function setNoShortOpenTags($value)
|
||||
{
|
||||
$this->ionSwitches['no-short-open-tags'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the no-short-open-tags option
|
||||
*/
|
||||
function getNoShortOpenTags()
|
||||
{
|
||||
return $this->ionSwitches['no-short-open-tags'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the option to use when encoding target directory already exists (defaults to none)
|
||||
*/
|
||||
function setTargetOption($targetOption)
|
||||
{
|
||||
$this->targetOption = $targetOption;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns he option to use when encoding target directory already exists (defaults to none)
|
||||
*/
|
||||
function getTargetOption()
|
||||
{
|
||||
return $this->targetOption;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the callback-file option
|
||||
*/
|
||||
function setCallbackFile($value)
|
||||
{
|
||||
$this->ionOptions['callback-file'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the callback-file option
|
||||
*/
|
||||
function getCallbackFile()
|
||||
{
|
||||
return $this->ionOptions['callback-file'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the obfuscation-exclusions-file option
|
||||
*/
|
||||
function setObfuscationExclusionFile($value)
|
||||
{
|
||||
$this->ionOptions['obfuscation-exclusion-file'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the obfuscation-exclusions-file option
|
||||
*/
|
||||
function getObfuscationExclusionFile()
|
||||
{
|
||||
return $this->ionOptions['obfuscation-exclusion-file'];
|
||||
}
|
||||
|
||||
/**
|
||||
* The main entry point
|
||||
*
|
||||
* @throws BuildException
|
||||
*/
|
||||
function main()
|
||||
{
|
||||
$arguments = $this->constructArguments();
|
||||
|
||||
$encoder = new PhingFile($this->ioncubePath, $this->encoderName . ($this->phpVersion == 5 ? '5' : ''));
|
||||
|
||||
$this->log("Running ionCube Encoder...");
|
||||
|
||||
exec($encoder->__toString() . ' ' . $arguments . " 2>&1", $output, $return);
|
||||
|
||||
if ($return != 0)
|
||||
{
|
||||
throw new BuildException("Could not execute ionCube Encoder: " . implode(' ', $output));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an argument string for the ionCube encoder
|
||||
*/
|
||||
private function constructArguments()
|
||||
{
|
||||
$arguments = '';
|
||||
|
||||
foreach ($this->ionSwitches as $name => $value)
|
||||
{
|
||||
if ($value)
|
||||
{
|
||||
$arguments.= "--$name ";
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->ionOptions as $name => $value)
|
||||
{
|
||||
$arguments.= "--$name '$value' ";
|
||||
}
|
||||
|
||||
foreach ($this->ionOptionsXS as $name => $value)
|
||||
{
|
||||
foreach (explode(' ', $value) as $arg)
|
||||
{
|
||||
$arguments.= "--$name '$arg' ";
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->comments as $comment)
|
||||
{
|
||||
$arguments.= "--add-comment '" . $comment->getValue() . "' ";
|
||||
}
|
||||
|
||||
if (!empty($this->targetOption))
|
||||
{
|
||||
switch ($this->targetOption)
|
||||
{
|
||||
case "replace":
|
||||
case "merge":
|
||||
case "update":
|
||||
case "rename":
|
||||
{
|
||||
$arguments.= "--" . $this->targetOption . "-target ";
|
||||
} break;
|
||||
|
||||
default:
|
||||
{
|
||||
throw new BuildException("Unknown target option '" . $this->targetOption . "'");
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->fromDir != '')
|
||||
{
|
||||
$arguments .= $this->fromDir . ' ';
|
||||
}
|
||||
|
||||
if ($this->toDir != '')
|
||||
{
|
||||
$arguments .= "-o " . $this->toDir . ' ';
|
||||
}
|
||||
|
||||
return $arguments;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,208 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: IoncubeLicenseTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
require_once 'phing/tasks/ext/ioncube/IoncubeComment.php';
|
||||
|
||||
/**
|
||||
* Invokes the ionCube "make_license" program
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: IoncubeLicenseTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.ioncube
|
||||
* @since 2.2.0
|
||||
*/
|
||||
class IoncubeLicenseTask extends Task
|
||||
{
|
||||
private $ioncubePath = "/usr/local/ioncube";
|
||||
|
||||
private $licensePath = "";
|
||||
private $passPhrase = "";
|
||||
private $allowedServer = "";
|
||||
private $expireOn = "";
|
||||
private $expireIn = "";
|
||||
private $comments = array();
|
||||
|
||||
/**
|
||||
* Sets the path to the ionCube encoder
|
||||
*/
|
||||
function setIoncubePath($ioncubePath)
|
||||
{
|
||||
$this->ioncubePath = $ioncubePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path to the ionCube encoder
|
||||
*/
|
||||
function getIoncubePath()
|
||||
{
|
||||
return $this->ioncubePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the path to the license file to use
|
||||
*/
|
||||
function setLicensePath($licensePath)
|
||||
{
|
||||
$this->licensePath = $licensePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path to the license file to use
|
||||
*/
|
||||
function getLicensePath()
|
||||
{
|
||||
return $this->licensePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the passphrase to use when encoding files
|
||||
*/
|
||||
function setPassPhrase($passPhrase)
|
||||
{
|
||||
$this->passPhrase = $passPhrase;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the passphrase to use when encoding files
|
||||
*/
|
||||
function getPassPhrase()
|
||||
{
|
||||
return $this->passPhrase;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a comment to be used in encoded files
|
||||
*/
|
||||
function addComment(IoncubeComment $comment)
|
||||
{
|
||||
$this->comments[] = $comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the --allowed-server option to use when generating the license
|
||||
*/
|
||||
function setAllowedServer($allowedServer)
|
||||
{
|
||||
$this->allowedServer = $allowedServer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the --allowed-server option
|
||||
*/
|
||||
function getAllowedServer()
|
||||
{
|
||||
return $this->allowedServer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the --expire-on option to use when generating the license
|
||||
*/
|
||||
function setExpireOn($expireOn)
|
||||
{
|
||||
$this->expireOn = $expireOn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the --expire-on option
|
||||
*/
|
||||
function getExpireOn()
|
||||
{
|
||||
return $this->expireOn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the --expire-in option to use when generating the license
|
||||
*/
|
||||
function setExpireIn($expireIn)
|
||||
{
|
||||
$this->expireIn = $expireIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the --expire-in option
|
||||
*/
|
||||
function getExpireIn()
|
||||
{
|
||||
return $this->expireIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* The main entry point
|
||||
*
|
||||
* @throws BuildException
|
||||
*/
|
||||
function main()
|
||||
{
|
||||
$arguments = $this->constructArguments();
|
||||
|
||||
$makelicense = new PhingFile($this->ioncubePath, 'make_license');
|
||||
|
||||
$this->log("Running ionCube make_license...");
|
||||
|
||||
exec($makelicense->__toString() . " " . $arguments . " 2>&1", $output, $return);
|
||||
|
||||
if ($return != 0)
|
||||
{
|
||||
throw new BuildException("Could not execute ionCube make_license: " . implode(' ', $output));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an argument string for the ionCube make_license
|
||||
*/
|
||||
private function constructArguments()
|
||||
{
|
||||
$arguments = "";
|
||||
|
||||
if (!empty($this->passPhrase))
|
||||
{
|
||||
$arguments.= "--passphrase '" . $this->passPhrase . "' ";
|
||||
}
|
||||
|
||||
foreach ($this->comments as $comment)
|
||||
{
|
||||
$arguments.= "--header-line '" . $comment->getValue() . "' ";
|
||||
}
|
||||
|
||||
if (!empty($this->licensePath))
|
||||
{
|
||||
$arguments.= "--o '" . $this->licensePath . "' ";
|
||||
}
|
||||
|
||||
if (!empty($this->allowedServer))
|
||||
{
|
||||
$arguments.= "--allowed-server {" . $this->allowedServer . "} ";
|
||||
}
|
||||
|
||||
if (!empty($this->expireOn))
|
||||
{
|
||||
$arguments.= "--expire-on " . $this->expireOn . " ";
|
||||
}
|
||||
|
||||
if (!empty($this->expireIn))
|
||||
{
|
||||
$arguments.= "--expire-in " . $this->expireIn . " ";
|
||||
}
|
||||
|
||||
return $arguments;
|
||||
}
|
||||
}
|
291
airtime_mvc/library/phing/tasks/ext/jsmin/JsMin.php
Normal file
291
airtime_mvc/library/phing/tasks/ext/jsmin/JsMin.php
Normal file
|
@ -0,0 +1,291 @@
|
|||
<?php
|
||||
/**
|
||||
* jsmin.php - PHP implementation of Douglas Crockford's JSMin.
|
||||
*
|
||||
* This is pretty much a direct port of jsmin.c to PHP with just a few
|
||||
* PHP-specific performance tweaks. Also, whereas jsmin.c reads from stdin and
|
||||
* outputs to stdout, this library accepts a string as input and returns another
|
||||
* string as output.
|
||||
*
|
||||
* PHP 5 or higher is required.
|
||||
*
|
||||
* Permission is hereby granted to use this version of the library under the
|
||||
* same terms as jsmin.c, which has the following license:
|
||||
*
|
||||
* --
|
||||
* Copyright (c) 2002 Douglas Crockford (www.crockford.com)
|
||||
*
|
||||
* 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 shall be used for Good, not Evil.
|
||||
*
|
||||
* 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.
|
||||
* --
|
||||
*
|
||||
* @package JSMin
|
||||
* @author Ryan Grove <ryan@wonko.com>
|
||||
* @copyright 2002 Douglas Crockford <douglas@crockford.com> (jsmin.c)
|
||||
* @copyright 2008 Ryan Grove <ryan@wonko.com> (PHP port)
|
||||
* @license http://opensource.org/licenses/mit-license.php MIT License
|
||||
* @version 1.1.1 (2008-03-02)
|
||||
* @link http://code.google.com/p/jsmin-php/
|
||||
*/
|
||||
|
||||
class JSMin {
|
||||
const ORD_LF = 10;
|
||||
const ORD_SPACE = 32;
|
||||
|
||||
protected $a = '';
|
||||
protected $b = '';
|
||||
protected $input = '';
|
||||
protected $inputIndex = 0;
|
||||
protected $inputLength = 0;
|
||||
protected $lookAhead = null;
|
||||
protected $output = '';
|
||||
|
||||
// -- Public Static Methods --------------------------------------------------
|
||||
|
||||
public static function minify($js) {
|
||||
$jsmin = new JSMin($js);
|
||||
return $jsmin->min();
|
||||
}
|
||||
|
||||
// -- Public Instance Methods ------------------------------------------------
|
||||
|
||||
public function __construct($input) {
|
||||
$this->input = str_replace("\r\n", "\n", $input);
|
||||
$this->inputLength = strlen($this->input);
|
||||
}
|
||||
|
||||
// -- Protected Instance Methods ---------------------------------------------
|
||||
|
||||
protected function action($d) {
|
||||
switch($d) {
|
||||
case 1:
|
||||
$this->output .= $this->a;
|
||||
|
||||
case 2:
|
||||
$this->a = $this->b;
|
||||
|
||||
if ($this->a === "'" || $this->a === '"') {
|
||||
for (;;) {
|
||||
$this->output .= $this->a;
|
||||
$this->a = $this->get();
|
||||
|
||||
if ($this->a === $this->b) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (ord($this->a) <= self::ORD_LF) {
|
||||
throw new JSMinException('Unterminated string literal.');
|
||||
}
|
||||
|
||||
if ($this->a === '\\') {
|
||||
$this->output .= $this->a;
|
||||
$this->a = $this->get();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
case 3:
|
||||
$this->b = $this->next();
|
||||
|
||||
if ($this->b === '/' && (
|
||||
$this->a === '(' || $this->a === ',' || $this->a === '=' ||
|
||||
$this->a === ':' || $this->a === '[' || $this->a === '!' ||
|
||||
$this->a === '&' || $this->a === '|' || $this->a === '?')) {
|
||||
|
||||
$this->output .= $this->a . $this->b;
|
||||
|
||||
for (;;) {
|
||||
$this->a = $this->get();
|
||||
|
||||
if ($this->a === '/') {
|
||||
break;
|
||||
} elseif ($this->a === '\\') {
|
||||
$this->output .= $this->a;
|
||||
$this->a = $this->get();
|
||||
} elseif (ord($this->a) <= self::ORD_LF) {
|
||||
throw new JSMinException('Unterminated regular expression '.
|
||||
'literal.');
|
||||
}
|
||||
|
||||
$this->output .= $this->a;
|
||||
}
|
||||
|
||||
$this->b = $this->next();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function get() {
|
||||
$c = $this->lookAhead;
|
||||
$this->lookAhead = null;
|
||||
|
||||
if ($c === null) {
|
||||
if ($this->inputIndex < $this->inputLength) {
|
||||
$c = $this->input[$this->inputIndex];
|
||||
$this->inputIndex += 1;
|
||||
} else {
|
||||
$c = null;
|
||||
}
|
||||
}
|
||||
|
||||
if ($c === "\r") {
|
||||
return "\n";
|
||||
}
|
||||
|
||||
if ($c === null || $c === "\n" || ord($c) >= self::ORD_SPACE) {
|
||||
return $c;
|
||||
}
|
||||
|
||||
return ' ';
|
||||
}
|
||||
|
||||
protected function isAlphaNum($c) {
|
||||
return ord($c) > 126 || $c === '\\' || preg_match('/^[\w\$]$/', $c) === 1;
|
||||
}
|
||||
|
||||
protected function min() {
|
||||
$this->a = "\n";
|
||||
$this->action(3);
|
||||
|
||||
while ($this->a !== null) {
|
||||
switch ($this->a) {
|
||||
case ' ':
|
||||
if ($this->isAlphaNum($this->b)) {
|
||||
$this->action(1);
|
||||
} else {
|
||||
$this->action(2);
|
||||
}
|
||||
break;
|
||||
|
||||
case "\n":
|
||||
switch ($this->b) {
|
||||
case '{':
|
||||
case '[':
|
||||
case '(':
|
||||
case '+':
|
||||
case '-':
|
||||
$this->action(1);
|
||||
break;
|
||||
|
||||
case ' ':
|
||||
$this->action(3);
|
||||
break;
|
||||
|
||||
default:
|
||||
if ($this->isAlphaNum($this->b)) {
|
||||
$this->action(1);
|
||||
}
|
||||
else {
|
||||
$this->action(2);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
switch ($this->b) {
|
||||
case ' ':
|
||||
if ($this->isAlphaNum($this->a)) {
|
||||
$this->action(1);
|
||||
break;
|
||||
}
|
||||
|
||||
$this->action(3);
|
||||
break;
|
||||
|
||||
case "\n":
|
||||
switch ($this->a) {
|
||||
case '}':
|
||||
case ']':
|
||||
case ')':
|
||||
case '+':
|
||||
case '-':
|
||||
case '"':
|
||||
case "'":
|
||||
$this->action(1);
|
||||
break;
|
||||
|
||||
default:
|
||||
if ($this->isAlphaNum($this->a)) {
|
||||
$this->action(1);
|
||||
}
|
||||
else {
|
||||
$this->action(3);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->action(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->output;
|
||||
}
|
||||
|
||||
protected function next() {
|
||||
$c = $this->get();
|
||||
|
||||
if ($c === '/') {
|
||||
switch($this->peek()) {
|
||||
case '/':
|
||||
for (;;) {
|
||||
$c = $this->get();
|
||||
|
||||
if (ord($c) <= self::ORD_LF) {
|
||||
return $c;
|
||||
}
|
||||
}
|
||||
|
||||
case '*':
|
||||
$this->get();
|
||||
|
||||
for (;;) {
|
||||
switch($this->get()) {
|
||||
case '*':
|
||||
if ($this->peek() === '/') {
|
||||
$this->get();
|
||||
return ' ';
|
||||
}
|
||||
break;
|
||||
|
||||
case null:
|
||||
throw new JSMinException('Unterminated comment.');
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
return $c;
|
||||
}
|
||||
}
|
||||
|
||||
return $c;
|
||||
}
|
||||
|
||||
protected function peek() {
|
||||
$this->lookAhead = $this->get();
|
||||
return $this->lookAhead;
|
||||
}
|
||||
}
|
||||
|
||||
// -- Exceptions ---------------------------------------------------------------
|
||||
class JSMinException extends Exception {}
|
||||
?>
|
128
airtime_mvc/library/phing/tasks/ext/jsmin/JsMinTask.php
Normal file
128
airtime_mvc/library/phing/tasks/ext/jsmin/JsMinTask.php
Normal file
|
@ -0,0 +1,128 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: JsMinTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
require_once 'phing/tasks/ext/jsmin/JsMin.php';
|
||||
|
||||
/**
|
||||
* Task to minify javascript files.
|
||||
*
|
||||
* Requires JSMin which can be found at http://code.google.com/p/jsmin-php/ but
|
||||
* is bundled with Phing so no additional install of JsMin is required.
|
||||
*
|
||||
* @author Frank Kleine <mikey@stubbles.net>
|
||||
* @version $Id: JsMinTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext
|
||||
* @since 2.3.0
|
||||
*/
|
||||
class JsMinTask extends Task
|
||||
{
|
||||
/**
|
||||
* the source files
|
||||
*
|
||||
* @var FileSet
|
||||
*/
|
||||
protected $filesets = array();
|
||||
/**
|
||||
* Whether the build should fail, if
|
||||
* errors occured
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $failonerror = false;
|
||||
/**
|
||||
* directory to put minified javascript files into
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $targetDir;
|
||||
|
||||
/**
|
||||
* Nested creator, adds a set of files (nested fileset attribute).
|
||||
*/
|
||||
public function createFileSet()
|
||||
{
|
||||
$num = array_push($this->filesets, new FileSet());
|
||||
return $this->filesets[$num - 1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the build should fail, if an error occured.
|
||||
*
|
||||
* @param boolean $value
|
||||
*/
|
||||
public function setFailonerror($value)
|
||||
{
|
||||
$this->failonerror = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the directory where minified javascript files should be put inot
|
||||
*
|
||||
* @param string $targetDir
|
||||
*/
|
||||
public function setTargetDir($targetDir)
|
||||
{
|
||||
$this->targetDir = $targetDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* The init method: Do init steps.
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The main entry point method.
|
||||
*/
|
||||
public function main()
|
||||
{
|
||||
foreach ($this->filesets as $fs) {
|
||||
try {
|
||||
$files = $fs->getDirectoryScanner($this->project)->getIncludedFiles();
|
||||
$fullPath = realpath($fs->getDir($this->project));
|
||||
foreach ($files as $file) {
|
||||
$this->log('Minifying file ' . $file);
|
||||
try {
|
||||
$target = $this->targetDir . '/' . str_replace($fullPath, '', str_replace('.js', '-min.js', $file));
|
||||
if (file_exists(dirname($target)) === false) {
|
||||
mkdir(dirname($target), 0700, true);
|
||||
}
|
||||
|
||||
file_put_contents($target, JSMin::minify(file_get_contents($fullPath . '/' . $file)));
|
||||
} catch (JSMinException $jsme) {
|
||||
$this->log("Could not minify file $file: " . $jsme->getMessage(), Project::MSG_ERR);
|
||||
}
|
||||
}
|
||||
} catch (BuildException $be) {
|
||||
// directory doesn't exist or is not readable
|
||||
if ($this->failonerror) {
|
||||
throw $be;
|
||||
} else {
|
||||
$this->log($be->getMessage(), $this->quiet ? Project::MSG_VERBOSE : Project::MSG_WARN);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: PhpDependAnalyzerElement.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/system/io/PhingFile.php';
|
||||
|
||||
/**
|
||||
* Analyzer element for the PhpDependTask
|
||||
*
|
||||
* @package phing.tasks.ext.pdepend
|
||||
* @author Benjamin Schultz <bschultz@proqrent.de>
|
||||
* @version $Id: PhpDependAnalyzerElement.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @since 2.4.1
|
||||
*/
|
||||
class PhpDependAnalyzerElement
|
||||
{
|
||||
/**
|
||||
* The type of the analyzer
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_type = '';
|
||||
|
||||
/**
|
||||
* The value(s) for the analyzer option
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_value = array();
|
||||
|
||||
/**
|
||||
* Sets the analyzer type
|
||||
*
|
||||
* @param string $type Type of the analyzer
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setType($type)
|
||||
{
|
||||
$this->_type = $type;
|
||||
|
||||
switch ($this->_type) {
|
||||
case 'coderank-mode':
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new BuildException(
|
||||
"Analyzer '" . $this->_type . "' not implemented"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the analyzer type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value for the analyzer
|
||||
*
|
||||
* @param string $value Value for the analyzer
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->_value = array();
|
||||
|
||||
$token = ' ,;';
|
||||
$values = strtok($value, $token);
|
||||
|
||||
while ($values !== false) {
|
||||
$this->_value[] = $values;
|
||||
$values = strtok($token);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the analyzer value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->_value;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: PhpDependLoggerElement.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/system/io/PhingFile.php';
|
||||
|
||||
/**
|
||||
* Logger element for the PhpDependTask.
|
||||
*
|
||||
* @package phing.tasks.ext.pdepend
|
||||
* @author Benjamin Schultz <bschultz@proqrent.de>
|
||||
* @version $Id: PhpDependLoggerElement.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @since 2.4.1
|
||||
*/
|
||||
class PhpDependLoggerElement
|
||||
{
|
||||
/**
|
||||
* The type of the logger.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_type = '';
|
||||
|
||||
/**
|
||||
* Output file for logger.
|
||||
*
|
||||
* @var PhingFile
|
||||
*/
|
||||
protected $_outfile = null;
|
||||
|
||||
/**
|
||||
* Sets the logger type.
|
||||
*
|
||||
* @param string $type Type of the logger
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setType($type)
|
||||
{
|
||||
$this->_type = $type;
|
||||
|
||||
switch ($this->_type) {
|
||||
case 'jdepend-chart':
|
||||
case 'jdepend-xml':
|
||||
case 'overview-pyramid':
|
||||
case 'phpunit-xml':
|
||||
case 'summary-xml':
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new BuildException(
|
||||
"Logger '" . $this->_type . "' not implemented"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the logger type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the output file for the logger results.
|
||||
*
|
||||
* @param PhingFile $outfile The output file
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setOutfile(PhingFile $outfile)
|
||||
{
|
||||
$this->_outfile = $outfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the output file.
|
||||
*
|
||||
* @return PhingFile
|
||||
*/
|
||||
public function getOutfile()
|
||||
{
|
||||
return $this->_outfile;
|
||||
}
|
||||
}
|
530
airtime_mvc/library/phing/tasks/ext/pdepend/PhpDependTask.php
Normal file
530
airtime_mvc/library/phing/tasks/ext/pdepend/PhpDependTask.php
Normal file
|
@ -0,0 +1,530 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: PhpDependTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
|
||||
/**
|
||||
* Runs the PHP_Depend software analyzer and metric tool.
|
||||
* Performs static code analysis on a given source base.
|
||||
*
|
||||
* @package phing.tasks.ext.pdepend
|
||||
* @author Benjamin Schultz <bschultz@proqrent.de>
|
||||
* @version $Id: PhpDependTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @since 2.4.1
|
||||
*/
|
||||
class PhpDependTask extends Task
|
||||
{
|
||||
/**
|
||||
* A php source code filename or directory
|
||||
*
|
||||
* @var PhingFile
|
||||
*/
|
||||
protected $_file = null;
|
||||
|
||||
/**
|
||||
* All fileset objects assigned to this task
|
||||
*
|
||||
* @var array<FileSet>
|
||||
*/
|
||||
protected $_filesets = array();
|
||||
|
||||
/**
|
||||
* List of allowed file extensions. Default file extensions are <b>php</b>
|
||||
* and <p>php5</b>.
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $_allowedFileExtensions = array('php', 'php5');
|
||||
|
||||
/**
|
||||
* List of exclude directories. Default exclude dirs are <b>.git</b>,
|
||||
* <b>.svn</b> and <b>CVS</b>.
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $_excludeDirectories = array('.git', '.svn', 'CVS');
|
||||
|
||||
/**
|
||||
* List of exclude packages
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $_excludePackages = array();
|
||||
|
||||
/**
|
||||
* Should the parse ignore doc comment annotations?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_withoutAnnotations = false;
|
||||
|
||||
/**
|
||||
* Should PHP_Depend treat <b>+global</b> as a regular project package?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_supportBadDocumentation = false;
|
||||
|
||||
/**
|
||||
* Flag for enable/disable debugging
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_debug = false;
|
||||
|
||||
/**
|
||||
* PHP_Depend configuration file
|
||||
*
|
||||
* @var PhingFile
|
||||
*/
|
||||
protected $_configFile = null;
|
||||
|
||||
/**
|
||||
* Logger elements
|
||||
*
|
||||
* @var array<PhpDependLoggerElement>
|
||||
*/
|
||||
protected $_loggers = array();
|
||||
|
||||
/**
|
||||
* Analyzer elements
|
||||
*
|
||||
* @var array<PhpDependAnalyzerElement>
|
||||
*/
|
||||
protected $_analyzers = array();
|
||||
|
||||
/**
|
||||
* Holds the PHP_Depend runner instance
|
||||
*
|
||||
* @var PHP_Depend_TextUI_Runner
|
||||
*/
|
||||
protected $_runner = null;
|
||||
|
||||
/**
|
||||
* Holds the optimization
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_optimization = '';
|
||||
|
||||
/**
|
||||
* Holds the available optimizations
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
private $_optimizations = array();
|
||||
|
||||
/**
|
||||
* Flag that determines whether to halt on error
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_haltonerror = false;
|
||||
|
||||
/**
|
||||
* Load the necessary environment for running PHP_Depend
|
||||
*
|
||||
* @return void
|
||||
* @throws BuildException
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
/**
|
||||
* Determine PHP_Depend installation
|
||||
*/
|
||||
@include_once 'PHP/Depend/TextUI/Runner.php';
|
||||
|
||||
if (! class_exists('PHP_Depend_TextUI_Runner')) {
|
||||
throw new BuildException(
|
||||
'PhpDependTask depends on PHP_Depend being installed '
|
||||
. 'and on include_path',
|
||||
$this->getLocation()
|
||||
);
|
||||
}
|
||||
|
||||
$this->_optimizations[] = PHP_Depend_TextUI_Runner::OPTIMZATION_BEST;
|
||||
$this->_optimizations[] = PHP_Depend_TextUI_Runner::OPTIMZATION_NONE;
|
||||
|
||||
/**
|
||||
* Other dependencies that should only be loaded
|
||||
* when class is actually used
|
||||
*/
|
||||
require_once 'phing/tasks/ext/pdepend/PhpDependLoggerElement.php';
|
||||
require_once 'phing/tasks/ext/pdepend/PhpDependAnalyzerElement.php';
|
||||
require_once 'PHP/Depend/TextUI/ResultPrinter.php';
|
||||
require_once 'PHP/Depend/Util/Configuration.php';
|
||||
require_once 'PHP/Depend/Util/ConfigurationInstance.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the input source file or directory
|
||||
*
|
||||
* @param PhingFile $file The input source file or directory
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setFile(PhingFile $file)
|
||||
{
|
||||
$this->_file = $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Nested creator, adds a set of files (nested fileset attribute)
|
||||
*
|
||||
* @return FileSet The created fileset object
|
||||
*/
|
||||
public function createFileSet()
|
||||
{
|
||||
$num = array_push($this->_filesets, new FileSet());
|
||||
return $this->_filesets[$num-1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a list of filename extensions for valid php source code files
|
||||
*
|
||||
* @param string $fileExtensions List of valid file extensions
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setAllowedFileExtensions($fileExtensions)
|
||||
{
|
||||
$this->_allowedFileExtensions = array();
|
||||
|
||||
$token = ' ,;';
|
||||
$ext = strtok($fileExtensions, $token);
|
||||
|
||||
while ($ext !== false) {
|
||||
$this->_allowedFileExtensions[] = $ext;
|
||||
$ext = strtok($token);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a list of exclude directories
|
||||
*
|
||||
* @param string $excludeDirectories List of exclude directories
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setExcludeDirectories($excludeDirectories)
|
||||
{
|
||||
$this->_excludeDirectories = array();
|
||||
|
||||
$token = ' ,;';
|
||||
$pattern = strtok($excludeDirectories, $token);
|
||||
|
||||
while ($pattern !== false) {
|
||||
$this->_excludeDirectories[] = $pattern;
|
||||
$pattern = strtok($token);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a list of exclude packages
|
||||
*
|
||||
* @param string $excludePackages Exclude packages
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setExcludePackages($excludePackages)
|
||||
{
|
||||
$this->_excludePackages = array();
|
||||
|
||||
$token = ' ,;';
|
||||
$pattern = strtok($excludePackages, $token);
|
||||
|
||||
while ($pattern !== false) {
|
||||
$this->_excludePackages[] = $pattern;
|
||||
$pattern = strtok($token);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the parser ignore doc comment annotations?
|
||||
*
|
||||
* @param boolean $withoutAnnotations
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setWithoutAnnotations($withoutAnnotations)
|
||||
{
|
||||
$this->_withoutAnnotations = StringHelper::booleanValue(
|
||||
$withoutAnnotations
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Should PHP_Depend support projects with a bad documentation. If this
|
||||
* option is set to <b>true</b>, PHP_Depend will treat the default package
|
||||
* <b>+global</b> as a regular project package.
|
||||
*
|
||||
* @param boolean $supportBadDocumentation
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setSupportBadDocumentation($supportBadDocumentation)
|
||||
{
|
||||
$this->_supportBadDocumentation = StringHelper::booleanValue(
|
||||
$supportBadDocumentation
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set debugging On/Off
|
||||
*
|
||||
* @param boolean $debug
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDebug($debug)
|
||||
{
|
||||
$this->_debug = StringHelper::booleanValue($debug);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set halt on error
|
||||
*
|
||||
* @param boolean $haltonerror
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setHaltonerror($haltonerror)
|
||||
{
|
||||
$this->_haltonerror = StringHelper::booleanValue($haltonerror);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the configuration file
|
||||
*
|
||||
* @param PhingFile $configFile The configuration file
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setConfigFile(PhingFile $configFile)
|
||||
{
|
||||
$this->_configFile = $configFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create object for nested logger element
|
||||
*
|
||||
* @return PhpDependLoggerElement
|
||||
*/
|
||||
public function createLogger()
|
||||
{
|
||||
$num = array_push($this->_loggers, new PhpDependLoggerElement());
|
||||
return $this->_loggers[$num-1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create object for nested analyzer element
|
||||
*
|
||||
* @return PhpDependAnalyzerElement
|
||||
*/
|
||||
public function createAnalyzer()
|
||||
{
|
||||
$num = array_push($this->_analyzers, new PhpDependAnalyzerElement());
|
||||
return $this->_analyzers[$num-1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes PHP_Depend_TextUI_Runner against PhingFile or a FileSet
|
||||
*
|
||||
* @return void
|
||||
* @throws BuildException
|
||||
*/
|
||||
public function main()
|
||||
{
|
||||
if (!isset($this->_file) and count($this->_filesets) == 0) {
|
||||
throw new BuildException(
|
||||
"Missing either a nested fileset or attribute 'file' set"
|
||||
);
|
||||
}
|
||||
|
||||
if (count($this->_loggers) == 0) {
|
||||
throw new BuildException("Missing nested 'logger' element");
|
||||
}
|
||||
|
||||
$this->validateLoggers();
|
||||
$this->validateAnalyzers();
|
||||
|
||||
$filesToParse = array();
|
||||
|
||||
if ($this->_file instanceof PhingFile) {
|
||||
$filesToParse[] = $this->_file->__toString();
|
||||
} else {
|
||||
// append any files in filesets
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->_runner = new PHP_Depend_TextUI_Runner();
|
||||
$this->_runner->addProcessListener(new PHP_Depend_TextUI_ResultPrinter());
|
||||
|
||||
$this->_runner->setSourceArguments($filesToParse);
|
||||
|
||||
foreach ($this->_loggers as $logger) {
|
||||
// Register logger
|
||||
$this->_runner->addLogger(
|
||||
$logger->getType(),
|
||||
$logger->getOutfile()->__toString()
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($this->_analyzers as $analyzer) {
|
||||
// Register additional analyzer
|
||||
$this->_runner->addOption(
|
||||
$analyzer->getType(),
|
||||
$analyzer->getValue()
|
||||
);
|
||||
}
|
||||
|
||||
// Disable annotation parsing
|
||||
if ($this->_withoutAnnotations) {
|
||||
$this->_runner->setWithoutAnnotations();
|
||||
}
|
||||
|
||||
// Enable bad documentation support
|
||||
if ($this->_supportBadDocumentation) {
|
||||
$this->_runner->setSupportBadDocumentation();
|
||||
}
|
||||
|
||||
// Check for suffix
|
||||
if (count($this->_allowedFileExtensions) > 0) {
|
||||
$this->_runner->setFileExtensions($this->_allowedFileExtensions);
|
||||
}
|
||||
|
||||
// Check for ignore directories
|
||||
if (count($this->_excludeDirectories) > 0) {
|
||||
$this->_runner->setExcludeDirectories($this->_excludeDirectories);
|
||||
}
|
||||
|
||||
// Check for exclude packages
|
||||
if (count($this->_excludePackages) > 0) {
|
||||
$this->_runner->setExcludePackages($this->_excludePackages);
|
||||
}
|
||||
|
||||
// Check optimization strategy
|
||||
if ($this->_optimization !== '') {
|
||||
if (in_array($this->_optimization, $this->_optimizations)) {
|
||||
// Set optimization strategy
|
||||
$this->_runner->setOptimization($this->_optimization);
|
||||
} else {
|
||||
throw new BuildException(
|
||||
'Invalid optimization "' . $this->_optimization . '" given.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Check for configuration option
|
||||
if ($this->_configFile instanceof PhingFile) {
|
||||
if (file_exists($this->_configFile->__toString()) === false) {
|
||||
throw new BuildException(
|
||||
'The configuration file "'
|
||||
. $this->_configFile->__toString() . '" doesn\'t exist.'
|
||||
);
|
||||
}
|
||||
|
||||
// Load configuration file
|
||||
$config = new PHP_Depend_Util_Configuration(
|
||||
$this->_configFile->__toString(),
|
||||
null,
|
||||
true
|
||||
);
|
||||
|
||||
// Store in config registry
|
||||
PHP_Depend_Util_ConfigurationInstance::set($config);
|
||||
}
|
||||
|
||||
if ($this->_debug) {
|
||||
require_once 'PHP/Depend/Util/Log.php';
|
||||
// Enable debug logging
|
||||
PHP_Depend_Util_Log::setSeverity(PHP_Depend_Util_Log::DEBUG);
|
||||
}
|
||||
|
||||
$this->_runner->run();
|
||||
|
||||
if ($this->_runner->hasParseErrors() === true) {
|
||||
$this->log('Following errors occurred:');
|
||||
|
||||
foreach ($this->_runner->getParseErrors() as $error) {
|
||||
$this->log($error);
|
||||
}
|
||||
|
||||
if ($this->_haltonerror === true) {
|
||||
throw new BuildException('Errors occurred during parse process');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the available loggers
|
||||
*
|
||||
* @return void
|
||||
* @throws BuildException
|
||||
*/
|
||||
protected function validateLoggers()
|
||||
{
|
||||
foreach ($this->_loggers as $logger) {
|
||||
if ($logger->getType() === '') {
|
||||
throw new BuildException(
|
||||
"Logger missing required 'type' attribute"
|
||||
);
|
||||
}
|
||||
|
||||
if ($logger->getOutfile() === null) {
|
||||
throw new BuildException(
|
||||
"Logger requires 'outfile' attribute"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the available analyzers
|
||||
*
|
||||
* @return void
|
||||
* @throws BuildException
|
||||
*/
|
||||
protected function validateAnalyzers()
|
||||
{
|
||||
foreach ($this->_analyzers as $analyzer) {
|
||||
if ($analyzer->getType() === '') {
|
||||
throw new BuildException(
|
||||
"Analyzer missing required 'type' attribute"
|
||||
);
|
||||
}
|
||||
|
||||
if (count($analyzer->getValue()) === 0) {
|
||||
throw new BuildException(
|
||||
"Analyzer missing required 'value' attribute"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: PDOResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/system/io/PhingFile.php';
|
||||
|
||||
/**
|
||||
* Abstract
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @package phing.tasks.ext.pdo
|
||||
* @since 2.3.0
|
||||
*/
|
||||
abstract class PDOResultFormatter
|
||||
{
|
||||
/**
|
||||
* Output writer.
|
||||
*
|
||||
* @var Writer
|
||||
*/
|
||||
protected $out;
|
||||
|
||||
/**
|
||||
* Sets the output writer.
|
||||
*
|
||||
* @param Writer $out
|
||||
*/
|
||||
public function setOutput(Writer $out) {
|
||||
$this->out = $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the output writer.
|
||||
*
|
||||
* @return Writer
|
||||
*/
|
||||
public function getOutput() {
|
||||
return $this->out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the preferred output filename for this formatter.
|
||||
* @return string
|
||||
*/
|
||||
abstract public function getPreferredOutfile();
|
||||
|
||||
/**
|
||||
* Perform any initialization.
|
||||
*/
|
||||
public function initialize() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a specific row from PDO result set.
|
||||
*
|
||||
* @param array $row Row of PDO result set.
|
||||
*/
|
||||
abstract public function processRow($row);
|
||||
|
||||
/**
|
||||
* Perform any final tasks and Close the writer.
|
||||
*/
|
||||
public function close() {
|
||||
$this->out->close();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,312 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: PDOSQLExecFormatterElement.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/system/io/PhingFile.php';
|
||||
require_once 'phing/tasks/ext/pdo/PlainPDOResultFormatter.php';
|
||||
require_once 'phing/tasks/ext/pdo/XMLPDOResultFormatter.php';
|
||||
|
||||
/**
|
||||
* A class to represent the nested <formatter> element for PDO SQL results.
|
||||
*
|
||||
* This class is inspired by the similarly-named class in the PHPUnit tasks.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @package phing.tasks.ext.pdo
|
||||
* @since 2.3.0
|
||||
*/
|
||||
class PDOSQLExecFormatterElement
|
||||
{
|
||||
/**
|
||||
* @var PDOResultFormatter
|
||||
*/
|
||||
private $formatter;
|
||||
|
||||
/**
|
||||
* The type of the formatter (used for built-in formatter classes).
|
||||
* @var string
|
||||
*/
|
||||
private $type = "";
|
||||
|
||||
/**
|
||||
* Whether to use file (or write output to phing log).
|
||||
* @var boolean
|
||||
*/
|
||||
private $useFile = true;
|
||||
|
||||
/**
|
||||
* Output file for formatter.
|
||||
* @var PhingFile
|
||||
*/
|
||||
private $outfile;
|
||||
|
||||
/**
|
||||
* Print header columns.
|
||||
* @var boolean
|
||||
*/
|
||||
private $showheaders = true;
|
||||
|
||||
/**
|
||||
* Whether to format XML output.
|
||||
* @var boolean
|
||||
*/
|
||||
private $formatoutput = true;
|
||||
|
||||
/**
|
||||
* Encoding for XML output.
|
||||
* @var string
|
||||
*/
|
||||
private $encoding;
|
||||
|
||||
/**
|
||||
* Column delimiter.
|
||||
* Defaults to ','
|
||||
* @var string
|
||||
*/
|
||||
private $coldelimiter = ",";
|
||||
|
||||
/**
|
||||
* Row delimiter.
|
||||
* Defaults to PHP_EOL.
|
||||
* @var string
|
||||
*/
|
||||
private $rowdelimiter = PHP_EOL;
|
||||
|
||||
/**
|
||||
* Append to an existing file or overwrite it?
|
||||
* @var boolean
|
||||
*/
|
||||
private $append = false;
|
||||
|
||||
/**
|
||||
* Parameters for a custom formatter.
|
||||
* @var array Parameter[]
|
||||
*/
|
||||
private $formatterParams = array();
|
||||
|
||||
/**
|
||||
* @var PDOSQLExecTask
|
||||
*/
|
||||
private $parentTask;
|
||||
|
||||
/**
|
||||
* Construct a new PDOSQLExecFormatterElement with parent task.
|
||||
* @param PDOSQLExecTask $parentTask
|
||||
*/
|
||||
public function __construct(PDOSQLExecTask $parentTask)
|
||||
{
|
||||
$this->parentTask = $parentTask;
|
||||
}
|
||||
|
||||
/**
|
||||
* Supports nested <param> element (for custom formatter classes).
|
||||
* @return Parameter
|
||||
*/
|
||||
public function createParam() {
|
||||
$num = array_push($this->parameters, new Parameter());
|
||||
return $this->parameters[$num-1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a configured output writer.
|
||||
* @return Writer
|
||||
*/
|
||||
private function getOutputWriter()
|
||||
{
|
||||
if ($this->useFile) {
|
||||
$of = $this->getOutfile();
|
||||
if (!$of) {
|
||||
$of = new PhingFile($this->formatter->getPreferredOutfile());
|
||||
}
|
||||
return new FileWriter($of, $this->append);
|
||||
} else {
|
||||
return $this->getDefaultOutput();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures wrapped formatter class with any attributes on this element.
|
||||
*/
|
||||
public function prepare() {
|
||||
|
||||
if (!$this->formatter) {
|
||||
throw new BuildException("No formatter specified (use type or classname attribute)", $this->getLocation());
|
||||
}
|
||||
|
||||
$out = $this->getOutputWriter();
|
||||
|
||||
print "Setting output writer to: " . get_class($out) . "\n";
|
||||
$this->formatter->setOutput($out);
|
||||
|
||||
if ($this->formatter instanceof PlainPDOResultFormatter) {
|
||||
// set any options that apply to the plain formatter
|
||||
$this->formatter->setShowheaders($this->showheaders);
|
||||
$this->formatter->setRowdelim($this->rowdelimiter);
|
||||
$this->formatter->setColdelim($this->coldelimiter);
|
||||
} elseif ($this->formatter instanceof XMLPDOResultFormatter) {
|
||||
// set any options that apply to the xml formatter
|
||||
$this->formatter->setEncoding($this->encoding);
|
||||
$this->formatter->setFormatOutput($this->formatoutput);
|
||||
}
|
||||
|
||||
foreach($this->formatterParams as $param) {
|
||||
$param = new Parameter();
|
||||
$method = 'set' . $param->getName();
|
||||
if (!method_exists($this->formatter, $param->getName())) {
|
||||
throw new BuildException("Formatter " . get_class($this->formatter) . " does not have a $method method.", $this->getLocation());
|
||||
}
|
||||
call_user_func(array($this->formatter, $method), $param->getValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the formatter type.
|
||||
* @param string $type
|
||||
*/
|
||||
function setType($type) {
|
||||
$this->type = $type;
|
||||
if ($this->type == "xml") {
|
||||
$this->formatter = new XMLPDOResultFormatter();
|
||||
} elseif ($this->type == "plain") {
|
||||
$this->formatter = new PlainPDOResultFormatter();
|
||||
} else {
|
||||
throw new BuildException("Formatter '" . $this->type . "' not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set classname for a custom formatter (must extend PDOResultFormatter).
|
||||
* @param string $className
|
||||
*/
|
||||
function setClassName($className) {
|
||||
$classNameNoDot = Phing::import($className);
|
||||
$this->formatter = new $classNameNoDot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether to write formatter results to file.
|
||||
* @param boolean $useFile
|
||||
*/
|
||||
function setUseFile($useFile) {
|
||||
$this->useFile = (boolean) $useFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether to write formatter results to file.
|
||||
* @return boolean
|
||||
*/
|
||||
function getUseFile() {
|
||||
return $this->useFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the output file for the formatter results.
|
||||
* @param PhingFile $outFile
|
||||
*/
|
||||
function setOutfile(PhingFile $outfile) {
|
||||
$this->outfile = $outfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the output file.
|
||||
* @return PhingFile
|
||||
*/
|
||||
function getOutfile() {
|
||||
return $this->outfile;
|
||||
/*
|
||||
} else {
|
||||
return new PhingFile($this->formatter->getPreferredOutfile());
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
* whether output should be appended to or overwrite
|
||||
* an existing file. Defaults to false.
|
||||
* @param boolean $append
|
||||
*/
|
||||
public function setAppend($append) {
|
||||
$this->append = (boolean) $append;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether output should be appended to file.
|
||||
* @return boolean
|
||||
*/
|
||||
public function getAppend() {
|
||||
return $this->append;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print headers for result sets from the
|
||||
* statements; optional, default true.
|
||||
* @param boolean $showheaders
|
||||
*/
|
||||
public function setShowheaders($showheaders) {
|
||||
$this->showheaders = (boolean) $showheaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the column delimiter.
|
||||
* @param string $v
|
||||
*/
|
||||
public function setColdelim($v) {
|
||||
$this->coldelimiter = $v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the row delimiter.
|
||||
* @param string $v
|
||||
*/
|
||||
public function setRowdelim($v) {
|
||||
$this->rowdelimiter = $v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the DOM document encoding.
|
||||
* @param string $v
|
||||
*/
|
||||
public function setEncoding($v) {
|
||||
$this->encoding = $v;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $v
|
||||
*/
|
||||
public function setFormatOutput($v) {
|
||||
$this->formatOutput = (boolean) $v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a default output writer for this task.
|
||||
* @return Writer
|
||||
*/
|
||||
private function getDefaultOutput()
|
||||
{
|
||||
return new LogWriter($this->parentTask);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the formatter that has been configured based on this element.
|
||||
* @return PDOResultFormatter
|
||||
*/
|
||||
function getFormatter() {
|
||||
return $this->formatter;
|
||||
}
|
||||
}
|
646
airtime_mvc/library/phing/tasks/ext/pdo/PDOSQLExecTask.php
Normal file
646
airtime_mvc/library/phing/tasks/ext/pdo/PDOSQLExecTask.php
Normal file
|
@ -0,0 +1,646 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: PDOSQLExecTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/tasks/ext/pdo/PDOTask.php';
|
||||
include_once 'phing/system/io/StringReader.php';
|
||||
include_once 'phing/tasks/ext/pdo/PDOSQLExecFormatterElement.php';
|
||||
|
||||
/**
|
||||
* Executes a series of SQL statements on a database using PDO.
|
||||
*
|
||||
* <p>Statements can
|
||||
* either be read in from a text file using the <i>src</i> attribute or from
|
||||
* between the enclosing SQL tags.</p>
|
||||
*
|
||||
* <p>Multiple statements can be provided, separated by semicolons (or the
|
||||
* defined <i>delimiter</i>). Individual lines within the statements can be
|
||||
* commented using either --, // or REM at the start of the line.</p>
|
||||
*
|
||||
* <p>The <i>autocommit</i> attribute specifies whether auto-commit should be
|
||||
* turned on or off whilst executing the statements. If auto-commit is turned
|
||||
* on each statement will be executed and committed. If it is turned off the
|
||||
* statements will all be executed as one transaction.</p>
|
||||
*
|
||||
* <p>The <i>onerror</i> attribute specifies how to proceed when an error occurs
|
||||
* during the execution of one of the statements.
|
||||
* The possible values are: <b>continue</b> execution, only show the error;
|
||||
* <b>stop</b> execution and commit transaction;
|
||||
* and <b>abort</b> execution and transaction and fail task.</p>
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org> (Phing)
|
||||
* @author Jeff Martin <jeff@custommonkey.org> (Ant)
|
||||
* @author Michael McCallum <gholam@xtra.co.nz> (Ant)
|
||||
* @author Tim Stephenson <tim.stephenson@sybase.com> (Ant)
|
||||
* @package phing.tasks.ext.pdo
|
||||
* @version $Revision: 905 $
|
||||
*/
|
||||
class PDOSQLExecTask extends PDOTask {
|
||||
|
||||
/**
|
||||
* Count of how many statements were executed successfully.
|
||||
* @var int
|
||||
*/
|
||||
private $goodSql = 0;
|
||||
|
||||
/**
|
||||
* Count of total number of SQL statements.
|
||||
* @var int
|
||||
*/
|
||||
private $totalSql = 0;
|
||||
|
||||
const DELIM_ROW = "row";
|
||||
const DELIM_NORMAL = "normal";
|
||||
|
||||
/**
|
||||
* Database connection
|
||||
* @var PDO
|
||||
*/
|
||||
private $conn = null;
|
||||
|
||||
/**
|
||||
* Files to load
|
||||
* @var array FileSet[]
|
||||
*/
|
||||
private $filesets = array();
|
||||
|
||||
/**
|
||||
* Files to load
|
||||
* @var array FileList[]
|
||||
*/
|
||||
private $filelists = array();
|
||||
|
||||
/**
|
||||
* Formatter elements.
|
||||
* @var array PDOSQLExecFormatterElement[]
|
||||
*/
|
||||
private $formatters = array();
|
||||
|
||||
/**
|
||||
* SQL statement
|
||||
* @var PDOStatement
|
||||
*/
|
||||
private $statement;
|
||||
|
||||
/**
|
||||
* SQL input file
|
||||
* @var PhingFile
|
||||
*/
|
||||
private $srcFile;
|
||||
|
||||
/**
|
||||
* SQL input command
|
||||
* @var string
|
||||
*/
|
||||
private $sqlCommand = "";
|
||||
|
||||
/**
|
||||
* SQL transactions to perform
|
||||
*/
|
||||
private $transactions = array();
|
||||
|
||||
/**
|
||||
* SQL Statement delimiter (for parsing files)
|
||||
* @var string
|
||||
*/
|
||||
private $delimiter = ";";
|
||||
|
||||
/**
|
||||
* The delimiter type indicating whether the delimiter will
|
||||
* only be recognized on a line by itself
|
||||
*/
|
||||
private $delimiterType = "normal"; // can't use constant just defined
|
||||
|
||||
/**
|
||||
* Action to perform if an error is found
|
||||
**/
|
||||
private $onError = "abort";
|
||||
|
||||
/**
|
||||
* Encoding to use when reading SQL statements from a file
|
||||
*/
|
||||
private $encoding = null;
|
||||
|
||||
/**
|
||||
* Fetch mode for PDO select queries.
|
||||
* @var int
|
||||
*/
|
||||
private $fetchMode;
|
||||
|
||||
/**
|
||||
* Set the name of the SQL file to be run.
|
||||
* Required unless statements are enclosed in the build file
|
||||
*/
|
||||
public function setSrc(PhingFile $srcFile) {
|
||||
$this->srcFile = $srcFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an inline SQL command to execute.
|
||||
* NB: Properties are not expanded in this text.
|
||||
*/
|
||||
public function addText($sql) {
|
||||
$this->sqlCommand .= $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a set of files (nested fileset attribute).
|
||||
*/
|
||||
public function addFileset(FileSet $set) {
|
||||
$this->filesets[] = $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a set of files (nested filelist attribute).
|
||||
*/
|
||||
public function addFilelist(FileList $list) {
|
||||
$this->filelists[] = $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new PDOSQLExecFormatterElement for <formatter> element.
|
||||
* @return PDOSQLExecFormatterElement
|
||||
*/
|
||||
public function createFormatter()
|
||||
{
|
||||
$fe = new PDOSQLExecFormatterElement($this);
|
||||
$this->formatters[] = $fe;
|
||||
return $fe;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a SQL transaction to execute
|
||||
*/
|
||||
public function createTransaction() {
|
||||
$t = new PDOSQLExecTransaction($this);
|
||||
$this->transactions[] = $t;
|
||||
return $t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the file encoding to use on the SQL files read in
|
||||
*
|
||||
* @param encoding the encoding to use on the files
|
||||
*/
|
||||
public function setEncoding($encoding) {
|
||||
$this->encoding = $encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the statement delimiter.
|
||||
*
|
||||
* <p>For example, set this to "go" and delimitertype to "ROW" for
|
||||
* Sybase ASE or MS SQL Server.</p>
|
||||
*
|
||||
* @param delimiter
|
||||
*/
|
||||
public function setDelimiter($delimiter)
|
||||
{
|
||||
$this->delimiter = $delimiter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Delimiter type for this sql task. The delimiter type takes two
|
||||
* values - normal and row. Normal means that any occurence of the delimiter
|
||||
* terminate the SQL command whereas with row, only a line containing just
|
||||
* the delimiter is recognized as the end of the command.
|
||||
*
|
||||
* @param string $delimiterType
|
||||
*/
|
||||
public function setDelimiterType($delimiterType)
|
||||
{
|
||||
$this->delimiterType = $delimiterType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Action to perform when statement fails: continue, stop, or abort
|
||||
* optional; default "abort"
|
||||
*/
|
||||
public function setOnerror($action) {
|
||||
$this->onError = $action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the fetch mode to use for the PDO resultset.
|
||||
* @param mixed $mode The PDO fetchmode integer or constant name.
|
||||
*/
|
||||
public function setFetchmode($mode) {
|
||||
if (is_numeric($mode)) {
|
||||
$this->fetchMode = (int) $mode;
|
||||
} else {
|
||||
if (defined($mode)) {
|
||||
$this->fetchMode = constant($mode);
|
||||
} else {
|
||||
throw new BuildException("Invalid PDO fetch mode specified: " . $mode, $this->getLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a default output writer for this task.
|
||||
* @return Writer
|
||||
*/
|
||||
private function getDefaultOutput()
|
||||
{
|
||||
return new LogWriter($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the sql file and then execute it
|
||||
* @throws BuildException
|
||||
*/
|
||||
public function main() {
|
||||
|
||||
// Set a default fetchmode if none was specified
|
||||
// (We're doing that here to prevent errors loading the class is PDO is not available.)
|
||||
if ($this->fetchMode === null) {
|
||||
$this->fetchMode = PDO::FETCH_BOTH;
|
||||
}
|
||||
|
||||
// Initialize the formatters here. This ensures that any parameters passed to the formatter
|
||||
// element get passed along to the actual formatter object
|
||||
foreach($this->formatters as $fe) {
|
||||
$fe->prepare();
|
||||
}
|
||||
|
||||
$savedTransaction = array();
|
||||
for($i=0,$size=count($this->transactions); $i < $size; $i++) {
|
||||
$savedTransaction[] = clone $this->transactions[$i];
|
||||
}
|
||||
|
||||
$savedSqlCommand = $this->sqlCommand;
|
||||
|
||||
$this->sqlCommand = trim($this->sqlCommand);
|
||||
|
||||
try {
|
||||
if ($this->srcFile === null && $this->sqlCommand === ""
|
||||
&& empty($this->filesets) && empty($this->filelists)
|
||||
&& count($this->transactions) === 0) {
|
||||
throw new BuildException("Source file or fileset/filelist, "
|
||||
. "transactions or sql statement "
|
||||
. "must be set!", $this->location);
|
||||
}
|
||||
|
||||
if ($this->srcFile !== null && !$this->srcFile->exists()) {
|
||||
throw new BuildException("Source file does not exist!", $this->location);
|
||||
}
|
||||
|
||||
// deal with the filesets
|
||||
foreach($this->filesets as $fs) {
|
||||
$ds = $fs->getDirectoryScanner($this->project);
|
||||
$srcDir = $fs->getDir($this->project);
|
||||
$srcFiles = $ds->getIncludedFiles();
|
||||
// Make a transaction for each file
|
||||
foreach($srcFiles as $srcFile) {
|
||||
$t = $this->createTransaction();
|
||||
$t->setSrc(new PhingFile($srcDir, $srcFile));
|
||||
}
|
||||
}
|
||||
|
||||
// process filelists
|
||||
foreach($this->filelists as $fl) {
|
||||
$srcDir = $fl->getDir($this->project);
|
||||
$srcFiles = $fl->getFiles($this->project);
|
||||
// Make a transaction for each file
|
||||
foreach($srcFiles as $srcFile) {
|
||||
$t = $this->createTransaction();
|
||||
$t->setSrc(new PhingFile($srcDir, $srcFile));
|
||||
}
|
||||
}
|
||||
|
||||
// Make a transaction group for the outer command
|
||||
$t = $this->createTransaction();
|
||||
if ($this->srcFile) $t->setSrc($this->srcFile);
|
||||
$t->addText($this->sqlCommand);
|
||||
$this->conn = $this->getConnection();
|
||||
|
||||
try {
|
||||
|
||||
$this->statement = null;
|
||||
|
||||
// Initialize the formatters.
|
||||
$this->initFormatters();
|
||||
|
||||
try {
|
||||
|
||||
// Process all transactions
|
||||
for ($i=0,$size=count($this->transactions); $i < $size; $i++) {
|
||||
if (!$this->isAutocommit()) {
|
||||
$this->log("Beginning transaction", Project::MSG_VERBOSE);
|
||||
$this->conn->beginTransaction();
|
||||
}
|
||||
$this->transactions[$i]->runTransaction();
|
||||
if (!$this->isAutocommit()) {
|
||||
$this->log("Commiting transaction", Project::MSG_VERBOSE);
|
||||
$this->conn->commit();
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
} catch (IOException $e) {
|
||||
if (!$this->isAutocommit() && $this->conn !== null && $this->onError == "abort") {
|
||||
try {
|
||||
$this->conn->rollback();
|
||||
} catch (PDOException $ex) {}
|
||||
}
|
||||
throw new BuildException($e->getMessage(), $this->location);
|
||||
} catch (PDOException $e){
|
||||
if (!$this->isAutocommit() && $this->conn !== null && $this->onError == "abort") {
|
||||
try {
|
||||
$this->conn->rollback();
|
||||
} catch (PDOException $ex) {}
|
||||
}
|
||||
throw new BuildException($e->getMessage(), $this->location);
|
||||
}
|
||||
|
||||
// Close the formatters.
|
||||
$this->closeFormatters();
|
||||
|
||||
$this->log($this->goodSql . " of " . $this->totalSql .
|
||||
" SQL statements executed successfully");
|
||||
|
||||
} catch (Exception $e) {
|
||||
$this->transactions = $savedTransaction;
|
||||
$this->sqlCommand = $savedSqlCommand;
|
||||
throw $e;
|
||||
}
|
||||
// finally {
|
||||
$this->transactions = $savedTransaction;
|
||||
$this->sqlCommand = $savedSqlCommand;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* read in lines and execute them
|
||||
* @throws PDOException, IOException
|
||||
*/
|
||||
public function runStatements(Reader $reader) {
|
||||
$sql = "";
|
||||
$line = "";
|
||||
$sqlBacklog = "";
|
||||
$hasQuery = false;
|
||||
|
||||
$in = new BufferedReader($reader);
|
||||
|
||||
try {
|
||||
while (($line = $in->readLine()) !== null) {
|
||||
$line = trim($line);
|
||||
$line = ProjectConfigurator::replaceProperties($this->project, $line,
|
||||
$this->project->getProperties());
|
||||
|
||||
if (($line != $this->delimiter) && (
|
||||
StringHelper::startsWith("//", $line) ||
|
||||
StringHelper::startsWith("--", $line) ||
|
||||
StringHelper::startsWith("#", $line))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strlen($line) > 4
|
||||
&& strtoupper(substr($line,0, 4)) == "REM ") {
|
||||
continue;
|
||||
}
|
||||
|
||||
// MySQL supports defining new delimiters
|
||||
if (preg_match('/DELIMITER [\'"]?([^\'" $]+)[\'"]?/i', $line, $matches)) {
|
||||
$this->setDelimiter($matches[1]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($sqlBacklog !== "") {
|
||||
$sql = $sqlBacklog;
|
||||
$sqlBacklog = "";
|
||||
}
|
||||
|
||||
$sql .= " " . $line . "\n";
|
||||
|
||||
// SQL defines "--" as a comment to EOL
|
||||
// and in Oracle it may contain a hint
|
||||
// so we cannot just remove it, instead we must end it
|
||||
if (strpos($line, "--") !== false) {
|
||||
$sql .= "\n";
|
||||
}
|
||||
|
||||
// DELIM_ROW doesn't need this (as far as i can tell)
|
||||
if ($this->delimiterType == self::DELIM_NORMAL) {
|
||||
|
||||
$reg = "#((?:\"(?:\\\\.|[^\"])*\"?)+|'(?:\\\\.|[^'])*'?|" . preg_quote($this->delimiter) . ")#";
|
||||
|
||||
$sqlParts = preg_split($reg, $sql, 0, PREG_SPLIT_DELIM_CAPTURE);
|
||||
$sqlBacklog = "";
|
||||
foreach ($sqlParts as $sqlPart) {
|
||||
// we always want to append, even if it's a delim (which will be stripped off later)
|
||||
$sqlBacklog .= $sqlPart;
|
||||
|
||||
// we found a single (not enclosed by ' or ") delimiter, so we can use all stuff before the delim as the actual query
|
||||
if ($sqlPart === $this->delimiter) {
|
||||
$sql = $sqlBacklog;
|
||||
$sqlBacklog = "";
|
||||
$hasQuery = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($hasQuery || ($this->delimiterType == self::DELIM_ROW && $line == $this->delimiter)) {
|
||||
// this assumes there is always a delimter on the end of the SQL statement.
|
||||
$sql = StringHelper::substring($sql, 0, strlen($sql) - 1 - strlen($this->delimiter));
|
||||
$this->log("SQL: " . $sql, Project::MSG_VERBOSE);
|
||||
$this->execSQL($sql);
|
||||
$sql = "";
|
||||
$hasQuery = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Catch any statements not followed by ;
|
||||
if ($sql !== "") {
|
||||
$this->execSQL($sql);
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the passed-in SQL statement is a SELECT statement.
|
||||
* This does a pretty simple match, checking to see if statement starts with
|
||||
* 'select' (but not 'select into').
|
||||
*
|
||||
* @param string $sql
|
||||
* @return boolean Whether specified SQL looks like a SELECT query.
|
||||
*/
|
||||
protected function isSelectSql($sql)
|
||||
{
|
||||
$sql = trim($sql);
|
||||
return (stripos($sql, 'select') === 0 && stripos($sql, 'select into ') !== 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exec the sql statement.
|
||||
* @throws PDOException
|
||||
*/
|
||||
protected function execSQL($sql) {
|
||||
|
||||
// Check and ignore empty statements
|
||||
if (trim($sql) == "") {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->totalSql++;
|
||||
|
||||
$this->statement = $this->conn->prepare($sql);
|
||||
$this->statement->execute();
|
||||
$this->log($this->statement->rowCount() . " rows affected", Project::MSG_VERBOSE);
|
||||
|
||||
// only call processResults() for statements that return actual data (such as 'select')
|
||||
if ($this->statement->columnCount() > 0)
|
||||
{
|
||||
$this->processResults();
|
||||
}
|
||||
|
||||
$this->statement->closeCursor();
|
||||
$this->statement = null;
|
||||
|
||||
$this->goodSql++;
|
||||
|
||||
} catch (PDOException $e) {
|
||||
$this->log("Failed to execute: " . $sql, Project::MSG_ERR);
|
||||
if ($this->onError != "continue") {
|
||||
throw new BuildException("Failed to execute SQL", $e);
|
||||
}
|
||||
$this->log($e->getMessage(), Project::MSG_ERR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns configured PDOResultFormatter objects (which were created from PDOSQLExecFormatterElement objects).
|
||||
* @return array PDOResultFormatter[]
|
||||
*/
|
||||
protected function getConfiguredFormatters()
|
||||
{
|
||||
$formatters = array();
|
||||
foreach ($this->formatters as $fe) {
|
||||
$formatters[] = $fe->getFormatter();
|
||||
}
|
||||
return $formatters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the formatters.
|
||||
*/
|
||||
protected function initFormatters() {
|
||||
$formatters = $this->getConfiguredFormatters();
|
||||
foreach ($formatters as $formatter) {
|
||||
$formatter->initialize();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Run cleanup and close formatters.
|
||||
*/
|
||||
protected function closeFormatters() {
|
||||
$formatters = $this->getConfiguredFormatters();
|
||||
foreach ($formatters as $formatter) {
|
||||
$formatter->close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Passes results from query to any formatters.
|
||||
* @throw PDOException
|
||||
*/
|
||||
protected function processResults() {
|
||||
|
||||
try {
|
||||
|
||||
$this->log("Processing new result set.", Project::MSG_VERBOSE);
|
||||
|
||||
$formatters = $this->getConfiguredFormatters();
|
||||
|
||||
while ($row = $this->statement->fetch($this->fetchMode)) {
|
||||
foreach ($formatters as $formatter) {
|
||||
$formatter->processRow($row);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception $x) {
|
||||
$this->log("Error processing reults: " . $x->getMessage(), Project::MSG_ERR);
|
||||
foreach ($formatters as $formatter) {
|
||||
$formatter->close();
|
||||
}
|
||||
throw $x;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* "Inner" class that contains the definition of a new transaction element.
|
||||
* Transactions allow several files or blocks of statements
|
||||
* to be executed using the same JDBC connection and commit
|
||||
* operation in between.
|
||||
*
|
||||
* @package phing.tasks.ext.pdo
|
||||
*/
|
||||
class PDOSQLExecTransaction {
|
||||
|
||||
private $tSrcFile = null;
|
||||
private $tSqlCommand = "";
|
||||
private $parent;
|
||||
|
||||
function __construct($parent)
|
||||
{
|
||||
// Parent is required so that we can log things ...
|
||||
$this->parent = $parent;
|
||||
}
|
||||
|
||||
public function setSrc(PhingFile $src)
|
||||
{
|
||||
$this->tSrcFile = $src;
|
||||
}
|
||||
|
||||
public function addText($sql)
|
||||
{
|
||||
$this->tSqlCommand .= $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IOException, PDOException
|
||||
*/
|
||||
public function runTransaction()
|
||||
{
|
||||
if (!empty($this->tSqlCommand)) {
|
||||
$this->parent->log("Executing commands", Project::MSG_INFO);
|
||||
$this->parent->runStatements(new StringReader($this->tSqlCommand));
|
||||
}
|
||||
|
||||
if ($this->tSrcFile !== null) {
|
||||
$this->parent->log("Executing file: " . $this->tSrcFile->getAbsolutePath(),
|
||||
Project::MSG_INFO);
|
||||
$reader = new FileReader($this->tSrcFile);
|
||||
$this->parent->runStatements($reader);
|
||||
$reader->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
217
airtime_mvc/library/phing/tasks/ext/pdo/PDOTask.php
Normal file
217
airtime_mvc/library/phing/tasks/ext/pdo/PDOTask.php
Normal file
|
@ -0,0 +1,217 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* $Id: PDOTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
include_once 'phing/types/Reference.php';
|
||||
|
||||
/**
|
||||
* Handles PDO configuration needed by SQL type tasks.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org> (Phing)
|
||||
* @author Nick Chalko <nick@chalko.com> (Ant)
|
||||
* @author Jeff Martin <jeff@custommonkey.org> (Ant)
|
||||
* @author Michael McCallum <gholam@xtra.co.nz> (Ant)
|
||||
* @author Tim Stephenson <tim.stephenson@sybase.com> (Ant)
|
||||
* @version $Revision: 905 $
|
||||
* @package phing.tasks.system
|
||||
*/
|
||||
abstract class PDOTask extends Task {
|
||||
|
||||
private $caching = true;
|
||||
|
||||
/**
|
||||
* Autocommit flag. Default value is false
|
||||
*/
|
||||
private $autocommit = false;
|
||||
|
||||
/**
|
||||
* DB url.
|
||||
*/
|
||||
private $url;
|
||||
|
||||
/**
|
||||
* User name.
|
||||
*/
|
||||
private $userId;
|
||||
|
||||
/**
|
||||
* Password
|
||||
*/
|
||||
private $password;
|
||||
|
||||
/**
|
||||
* RDBMS Product needed for this SQL.
|
||||
**/
|
||||
private $rdbms;
|
||||
|
||||
/**
|
||||
* Initialize CreoleTask.
|
||||
* This method includes any necessary Creole libraries and triggers
|
||||
* appropriate error if they cannot be found. This is not done in header
|
||||
* because we may want this class to be loaded w/o triggering an error.
|
||||
*/
|
||||
function init() {
|
||||
if (!class_exists('PDO')) {
|
||||
throw new Exception("PDOTask depends on PDO feature being included in PHP.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Caching loaders / driver. This is to avoid
|
||||
* getting an OutOfMemoryError when calling this task
|
||||
* multiple times in a row; default: true
|
||||
* @param $enable
|
||||
*/
|
||||
public function setCaching($enable) {
|
||||
$this->caching = $enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the database connection URL; required.
|
||||
* @param url The url to set
|
||||
*/
|
||||
public function setUrl($url) {
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the password; required.
|
||||
* @param password The password to set
|
||||
*/
|
||||
public function setPassword($password) {
|
||||
$this->password = $password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Auto commit flag for database connection;
|
||||
* optional, default false.
|
||||
* @param autocommit The autocommit to set
|
||||
*/
|
||||
public function setAutocommit($autocommit) {
|
||||
$this->autocommit = $autocommit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the version string, execute task only if
|
||||
* rdbms version match; optional.
|
||||
* @param version The version to set
|
||||
*/
|
||||
public function setVersion($version) {
|
||||
$this->version = $version;
|
||||
}
|
||||
|
||||
protected function getLoaderMap() {
|
||||
return self::$loaderMap;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new Connection as using the driver, url, userid and password specified.
|
||||
* The calling method is responsible for closing the connection.
|
||||
* @return Connection the newly created connection.
|
||||
* @throws BuildException if the UserId/Password/Url is not set or there is no suitable driver or the driver fails to load.
|
||||
*/
|
||||
protected function getConnection() {
|
||||
|
||||
if ($this->url === null) {
|
||||
throw new BuildException("Url attribute must be set!", $this->location);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$this->log("Connecting to " . $this->getUrl(), Project::MSG_VERBOSE);
|
||||
|
||||
$user = null;
|
||||
$pass = null;
|
||||
|
||||
if ($this->userId) {
|
||||
$user = $this->getUserId();
|
||||
}
|
||||
|
||||
if ($this->password) {
|
||||
$pass = $this->getPassword();
|
||||
}
|
||||
|
||||
$conn = new PDO($this->getUrl(), $user, $pass);
|
||||
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
if ($this->autocommit) {
|
||||
try {
|
||||
$conn->setAttribute(PDO::ATTR_AUTOCOMMIT, $this->autocommit);
|
||||
} catch (PDOException $pe) {
|
||||
$this->log("Unable to enable auto-commit for this database: " . $pe->getMessage(), Project::MSG_WARN);
|
||||
}
|
||||
}
|
||||
|
||||
return $conn;
|
||||
|
||||
} catch (SQLException $e) {
|
||||
throw new BuildException($e->getMessage(), $this->location);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function isCaching($value) {
|
||||
$this->caching = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the autocommit.
|
||||
* @return Returns a boolean
|
||||
*/
|
||||
public function isAutocommit() {
|
||||
return $this->autocommit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the url.
|
||||
* @return Returns a String
|
||||
*/
|
||||
public function getUrl() {
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the userId.
|
||||
* @return Returns a String
|
||||
*/
|
||||
public function getUserId() {
|
||||
return $this->userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user name for the connection; required.
|
||||
* @param userId The userId to set
|
||||
*/
|
||||
public function setUserid($userId) {
|
||||
$this->userId = $userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the password.
|
||||
* @return Returns a String
|
||||
*/
|
||||
public function getPassword() {
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: PlainPDOResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/system/io/PhingFile.php';
|
||||
require_once 'phing/tasks/ext/pdo/PDOResultFormatter.php';
|
||||
|
||||
/**
|
||||
* Plain text formatter for PDO results.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @package phing.tasks.ext.pdo
|
||||
* @since 2.3.0
|
||||
*/
|
||||
class PlainPDOResultFormatter extends PDOResultFormatter
|
||||
{
|
||||
/**
|
||||
* Have column headers been printed?
|
||||
* @var boolean
|
||||
*/
|
||||
private $colsprinted = false;
|
||||
|
||||
/**
|
||||
* Whether to show headers.
|
||||
* @var boolean
|
||||
*/
|
||||
private $showheaders = true;
|
||||
|
||||
/**
|
||||
* Column delimiter.
|
||||
* Defaults to ','
|
||||
* @var string
|
||||
*/
|
||||
private $coldelimiter = ",";
|
||||
|
||||
/**
|
||||
* Row delimiter.
|
||||
* Defaults to PHP_EOL.
|
||||
* @var string
|
||||
*/
|
||||
private $rowdelimiter = PHP_EOL;
|
||||
|
||||
/**
|
||||
* Set the showheaders attribute.
|
||||
* @param boolean $v
|
||||
*/
|
||||
public function setShowheaders($v) {
|
||||
$this->showheaders = StringHelper::booleanValue($v);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the column delimiter.
|
||||
* @param string $v
|
||||
*/
|
||||
public function setColdelim($v) {
|
||||
$this->coldelimiter = $v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the row delimiter.
|
||||
* @param string $v
|
||||
*/
|
||||
public function setRowdelim($v) {
|
||||
$this->rowdelimiter = $v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a specific row from PDO result set.
|
||||
*
|
||||
* @param array $row Row of PDO result set.
|
||||
*/
|
||||
public function processRow($row) {
|
||||
|
||||
if (!$this->colsprinted && $this->showheaders) {
|
||||
$first = true;
|
||||
foreach($row as $fieldName => $ignore) {
|
||||
if ($first) $first = false; else $line .= ",";
|
||||
$line .= $fieldName;
|
||||
}
|
||||
|
||||
$this->out->write($line);
|
||||
$this->out->write(PHP_EOL);
|
||||
|
||||
$line = "";
|
||||
$colsprinted = true;
|
||||
} // if show headers
|
||||
|
||||
$first = true;
|
||||
foreach($row as $columnValue) {
|
||||
|
||||
if ($columnValue != null) {
|
||||
$columnValue = trim($columnValue);
|
||||
}
|
||||
|
||||
if ($first) {
|
||||
$first = false;
|
||||
} else {
|
||||
$line .= $this->coldelimiter;
|
||||
}
|
||||
$line .= $columnValue;
|
||||
}
|
||||
|
||||
$this->out->write($line);
|
||||
$this->out->write($this->rowdelimiter);
|
||||
|
||||
}
|
||||
|
||||
public function getPreferredOutfile()
|
||||
{
|
||||
return new PhingFile('results.txt');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,141 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: XMLPDOResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/system/io/PhingFile.php';
|
||||
require_once 'phing/tasks/ext/pdo/PDOResultFormatter.php';
|
||||
|
||||
/**
|
||||
* XML formatter for PDO results.
|
||||
*
|
||||
* This class reprsents the output of a query using a simple XML schema.
|
||||
*
|
||||
* <results>
|
||||
* <row>
|
||||
* <col name="id">value</col>
|
||||
* <col name="name">value2</col>
|
||||
* </row>
|
||||
* <row>
|
||||
* <col name="id">value</col>
|
||||
* <col name="name">value2</col>
|
||||
* </row>
|
||||
* </results>
|
||||
*
|
||||
* The actual names of the colums will depend on the fetchmode that was used
|
||||
* with PDO.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @package phing.tasks.ext.pdo
|
||||
* @since 2.3.0
|
||||
*/
|
||||
class XMLPDOResultFormatter extends PDOResultFormatter {
|
||||
|
||||
/**
|
||||
* The XML document being created.
|
||||
* @var DOMDocument
|
||||
*/
|
||||
private $doc;
|
||||
|
||||
/**
|
||||
* @var DOMElement
|
||||
*/
|
||||
private $rootNode;
|
||||
|
||||
/**
|
||||
* XML document encoding
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $encoding;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
private $formatOutput = true;
|
||||
|
||||
/**
|
||||
* Set the DOM document encoding.
|
||||
* @param string $v
|
||||
*/
|
||||
public function setEncoding($v) {
|
||||
$this->encoding = $v;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $v
|
||||
*/
|
||||
public function setFormatOutput($v) {
|
||||
$this->formatOutput = (boolean) $v;
|
||||
}
|
||||
|
||||
public function initialize() {
|
||||
$this->doc = new DOMDocument("1.0", $this->encoding);
|
||||
$this->rootNode = $this->doc->createElement('results');
|
||||
$this->doc->appendChild($this->rootNode);
|
||||
$this->doc->formatOutput = $this->formatOutput;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a specific row from PDO result set.
|
||||
*
|
||||
* @param array $row Row of PDO result set.
|
||||
*/
|
||||
public function processRow($row) {
|
||||
|
||||
$rowNode = $this->doc->createElement('row');
|
||||
$this->rootNode->appendChild($rowNode);
|
||||
|
||||
foreach($row as $columnName => $columnValue) {
|
||||
|
||||
$colNode = $this->doc->createElement('column');
|
||||
$colNode->setAttribute('name', $columnName);
|
||||
|
||||
if ($columnValue != null) {
|
||||
$columnValue = trim($columnValue);
|
||||
$colNode->nodeValue = $columnValue;
|
||||
}
|
||||
$rowNode->appendChild($colNode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a preferred filename for an output file.
|
||||
*
|
||||
* If no filename is specified, this is where the results will be placed
|
||||
* (unless usefile=false).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPreferredOutfile()
|
||||
{
|
||||
return new PhingFile('results.xml');
|
||||
}
|
||||
|
||||
/**
|
||||
* Write XML to file and free the DOM objects.
|
||||
*/
|
||||
public function close() {
|
||||
$this->out->write($this->doc->saveXML());
|
||||
$this->rootNode = null;
|
||||
$this->doc = null;
|
||||
parent::close();
|
||||
}
|
||||
}
|
228
airtime_mvc/library/phing/tasks/ext/pearpackage/Fileset.php
Normal file
228
airtime_mvc/library/phing/tasks/ext/pearpackage/Fileset.php
Normal file
|
@ -0,0 +1,228 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: Fileset.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
include_once 'phing/system/io/PhingFile.php';
|
||||
|
||||
/**
|
||||
* Builds list of files for PEAR_PackageFileManager using a Phing FileSet.
|
||||
*
|
||||
* Some code here is taken from PEAR_PackageFileManager_File -- getting results from flat
|
||||
* array into the assoc array expected from getFileList().
|
||||
*
|
||||
* @author Greg Beaver
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @package phing.tasks.ext.pearpackage
|
||||
* @version $Revision: 905 $
|
||||
*/
|
||||
class PEAR_PackageFileManager_Fileset {
|
||||
|
||||
/**
|
||||
* Curent Phing Project.
|
||||
* @var Project
|
||||
*/
|
||||
private $project;
|
||||
|
||||
/**
|
||||
* FileSets to use.
|
||||
* @var array FileSet[]
|
||||
*/
|
||||
private $filesets = array();
|
||||
|
||||
/**
|
||||
* Set up the FileSet filelist generator
|
||||
*
|
||||
* 'project' and 'filesets' are the only options that this class uses.
|
||||
*
|
||||
* @param PEAR_PackageFileManager
|
||||
* @param array
|
||||
*/
|
||||
function __construct($options)
|
||||
{
|
||||
if (!is_array($options)) {
|
||||
$options = $options->getOptions();
|
||||
}
|
||||
|
||||
$this->project = $options['phing_project'];
|
||||
$this->filesets = $options['phing_filesets'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the <filelist></filelist> section
|
||||
* of the package file.
|
||||
*
|
||||
* This function performs the backend generation of the array
|
||||
* containing all files in this package
|
||||
* @return array structure of all files to include
|
||||
*/
|
||||
function getFileList() {
|
||||
|
||||
$allfiles = array();
|
||||
|
||||
foreach($this->filesets as $fs) {
|
||||
$ds = $fs->getDirectoryScanner($this->project);
|
||||
|
||||
$files = $ds->getIncludedFiles();
|
||||
|
||||
// We need to store these files keyed by the basedir from DirectoryScanner
|
||||
// so that we can resolve the fullpath of the file later.
|
||||
if (isset($allfiles[$ds->getBasedir()]))
|
||||
{
|
||||
$allfiles[$ds->getBasedir()] = array_merge($allfiles[$ds->getBasedir()], $files);
|
||||
}
|
||||
else
|
||||
{
|
||||
$allfiles[$ds->getBasedir()] = $files;
|
||||
}
|
||||
}
|
||||
|
||||
$struc = array();
|
||||
|
||||
foreach($allfiles as $basedir => $files) {
|
||||
|
||||
foreach($files as $file) {
|
||||
|
||||
// paths are relative to $basedir above
|
||||
$path = strtr(dirname($file), DIRECTORY_SEPARATOR, '/');
|
||||
|
||||
if (!$path || $path == '.') {
|
||||
$path = '/'; // for array index
|
||||
}
|
||||
|
||||
$parts = explode('.', basename($file));
|
||||
$ext = array_pop($parts);
|
||||
if (strlen($ext) == strlen($file)) {
|
||||
$ext = '';
|
||||
}
|
||||
|
||||
$f = new PhingFile($basedir, $file);
|
||||
|
||||
$struc[$path][] = array('file' => basename($file),
|
||||
'ext' => $ext,
|
||||
'path' => (($path == '/') ? basename($file) : $path . '/' . basename($file)),
|
||||
'fullpath' => $f->getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
uksort($struc,'strnatcasecmp');
|
||||
foreach($struc as $key => $ind) {
|
||||
usort($ind, array($this, 'sortfiles'));
|
||||
$struc[$key] = $ind;
|
||||
}
|
||||
|
||||
$tempstruc = $struc;
|
||||
$struc = array('/' => $tempstruc['/']);
|
||||
$bv = 0;
|
||||
foreach($tempstruc as $key => $ind) {
|
||||
$save = $key;
|
||||
if ($key != '/') {
|
||||
$struc['/'] = $this->setupDirs($struc['/'], explode('/', $key), $tempstruc[$key]);
|
||||
}
|
||||
}
|
||||
uksort($struc['/'], array($this, 'mystrucsort'));
|
||||
|
||||
return $struc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively move contents of $struc into associative array
|
||||
*
|
||||
* The contents of $struc have many indexes like 'dir/subdir/subdir2'.
|
||||
* This function converts them to
|
||||
* array('dir' => array('subdir' => array('subdir2')))
|
||||
* @param array struc is array('dir' => array of files in dir,
|
||||
* 'dir/subdir' => array of files in dir/subdir,...)
|
||||
* @param array array form of 'dir/subdir/subdir2' array('dir','subdir','subdir2')
|
||||
* @return array same as struc but with array('dir' =>
|
||||
* array(file1,file2,'subdir' => array(file1,...)))
|
||||
*/
|
||||
private function setupDirs($struc, $dir, $contents) {
|
||||
|
||||
if (!count($dir)) {
|
||||
foreach($contents as $dir => $files) {
|
||||
if (is_string($dir)) {
|
||||
if (strpos($dir, '/')) {
|
||||
$test = true;
|
||||
$a = $contents[$dir];
|
||||
unset($contents[$dir]);
|
||||
$b = explode('/', $dir);
|
||||
$c = array_shift($b);
|
||||
if (isset($contents[$c])) {
|
||||
$contents[$c] = $this->setDir($contents[$c], $this->setupDirs(array(), $b, $a));
|
||||
} else {
|
||||
$contents[$c] = $this->setupDirs(array(), $b, $a);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $contents;
|
||||
}
|
||||
$me = array_shift($dir);
|
||||
if (!isset($struc[$me])) {
|
||||
$struc[$me] = array();
|
||||
}
|
||||
$struc[$me] = $this->setupDirs($struc[$me], $dir, $contents);
|
||||
return $struc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively add all the subdirectories of $contents to $dir without erasing anything in
|
||||
* $dir
|
||||
* @param array
|
||||
* @param array
|
||||
* @return array processed $dir
|
||||
*/
|
||||
function setDir($dir, $contents)
|
||||
{
|
||||
while(list($one,$two) = each($contents)) {
|
||||
if (isset($dir[$one])) {
|
||||
$dir[$one] = $this->setDir($dir[$one], $contents[$one]);
|
||||
} else {
|
||||
$dir[$one] = $two;
|
||||
}
|
||||
}
|
||||
return $dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorting functions for the file list
|
||||
* @param string
|
||||
* @param string
|
||||
* @access private
|
||||
*/
|
||||
function sortfiles($a, $b)
|
||||
{
|
||||
return strnatcasecmp($a['file'],$b['file']);
|
||||
}
|
||||
|
||||
function mystrucsort($a, $b)
|
||||
{
|
||||
if (is_numeric($a) && is_string($b)) return 1;
|
||||
if (is_numeric($b) && is_string($a)) return -1;
|
||||
if (is_numeric($a) && is_numeric($b))
|
||||
{
|
||||
if ($a > $b) return 1;
|
||||
if ($a < $b) return -1;
|
||||
if ($a == $b) return 0;
|
||||
}
|
||||
return strnatcasecmp($a,$b);
|
||||
}
|
||||
}
|
||||
|
56
airtime_mvc/library/phing/tasks/ext/phar/IterableFileSet.php
Normal file
56
airtime_mvc/library/phing/tasks/ext/phar/IterableFileSet.php
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: IterableFileSet.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* FileSet adapter to SPL's Iterator.
|
||||
*
|
||||
* @package phing.tasks.ext.phar
|
||||
* @author Alexey Shockov <alexey@shockov.com>
|
||||
* @since 2.4.0
|
||||
* @internal
|
||||
*/
|
||||
class IterableFileSet
|
||||
extends FileSet
|
||||
implements IteratorAggregate
|
||||
{
|
||||
/**
|
||||
* @return Iterator
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return new ArrayIterator($this->getFiles());
|
||||
}
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getFiles()
|
||||
{
|
||||
$directoryScanner = $this->getDirectoryScanner($this->getProject());
|
||||
$files = $directoryScanner->getIncludedFiles();
|
||||
|
||||
$baseDirectory = $directoryScanner->getBasedir();
|
||||
foreach ($files as $index => $file) {
|
||||
$files[$index] = realpath($baseDirectory.'/'.$file);
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
||||
}
|
55
airtime_mvc/library/phing/tasks/ext/phar/PharMetadata.php
Normal file
55
airtime_mvc/library/phing/tasks/ext/phar/PharMetadata.php
Normal file
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: PharMetadata.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/tasks/ext/phar/PharMetadataElement.php';
|
||||
|
||||
/**
|
||||
* @package phing.tasks.ext.phar
|
||||
* @author Alexey Shockov <alexey@shockov.com>
|
||||
* @since 2.4.0
|
||||
*/
|
||||
class PharMetadata
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $elements = array();
|
||||
/**
|
||||
* @return PharMetadataElement
|
||||
*/
|
||||
public function createElement()
|
||||
{
|
||||
return ($this->elements[] = new PharMetadataElement());
|
||||
}
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
$metadata = array();
|
||||
|
||||
foreach ($this->elements as $element) {
|
||||
$metadata[$element->getName()] = $element->toArray();
|
||||
}
|
||||
|
||||
return $metadata;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: PharMetadataElement.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/tasks/ext/phar/PharMetadata.php';
|
||||
|
||||
/**
|
||||
* @package phing.tasks.ext.phar
|
||||
* @author Alexey Shockov <alexey@shockov.com>
|
||||
* @since 2.4.0
|
||||
*/
|
||||
class PharMetadataElement
|
||||
extends PharMetadata
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $value;
|
||||
/**
|
||||
* @param string $value
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
/**
|
||||
* @param string $name
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
/**
|
||||
* Return array of
|
||||
*
|
||||
* @return string|array
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
/*
|
||||
* Elements first!
|
||||
*/
|
||||
return (empty($this->elements) ? $this->value : $this->elements);
|
||||
}
|
||||
/**
|
||||
* @return string|array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return (empty($this->elements) ? $this->value : parent::toArray());
|
||||
}
|
||||
}
|
302
airtime_mvc/library/phing/tasks/ext/phar/PharPackageTask.php
Normal file
302
airtime_mvc/library/phing/tasks/ext/phar/PharPackageTask.php
Normal file
|
@ -0,0 +1,302 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: PharPackageTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/tasks/system/MatchingTask.php';
|
||||
require_once 'phing/tasks/ext/phar/IterableFileSet.php';
|
||||
require_once 'phing/tasks/ext/phar/PharMetadata.php';
|
||||
|
||||
/**
|
||||
* Package task for {@link http://ru.php.net/manual/en/book.phar.php Phar technology}.
|
||||
*
|
||||
* @package phing.tasks.ext
|
||||
* @author Alexey Shockov <alexey@shockov.com>
|
||||
* @since 2.4.0
|
||||
*/
|
||||
class PharPackageTask
|
||||
extends MatchingTask
|
||||
{
|
||||
/**
|
||||
* @var PhingFile
|
||||
*/
|
||||
private $destinationFile;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $compression = Phar::NONE;
|
||||
/**
|
||||
* Base directory, from where local package paths will be calculated.
|
||||
*
|
||||
* @var PhingFile
|
||||
*/
|
||||
private $baseDirectory;
|
||||
/**
|
||||
* @var PhingFile
|
||||
*/
|
||||
private $cliStubFile;
|
||||
/**
|
||||
* @var PhingFile
|
||||
*/
|
||||
private $webStubFile;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $stubPath;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $signatureAlgorithm = Phar::SHA1;
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $filesets = array();
|
||||
/**
|
||||
* @var PharMetadata
|
||||
*/
|
||||
private $metadata = null;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $alias;
|
||||
/**
|
||||
* @return PharMetadata
|
||||
*/
|
||||
public function createMetadata()
|
||||
{
|
||||
return ($this->metadata = new PharMetadata());
|
||||
}
|
||||
/**
|
||||
* @return FileSet
|
||||
*/
|
||||
public function createFileSet()
|
||||
{
|
||||
$this->fileset = new IterableFileSet();
|
||||
$this->filesets[] = $this->fileset;
|
||||
return $this->fileset;
|
||||
}
|
||||
/**
|
||||
* @param string $algorithm
|
||||
*/
|
||||
public function setSignature($algorithm)
|
||||
{
|
||||
/*
|
||||
* If we don't support passed algprithm, leave old one.
|
||||
*/
|
||||
switch ($algorithm) {
|
||||
case 'md5':
|
||||
$this->signatureAlgorithm = Phar::MD5;
|
||||
break;
|
||||
case 'sha1':
|
||||
$this->signatureAlgorithm = Phar::SHA1;
|
||||
break;
|
||||
case 'sha256':
|
||||
$this->signatureAlgorithm = Phar::SHA256;
|
||||
break;
|
||||
case 'sha512':
|
||||
$this->signatureAlgorithm = Phar::SHA512;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param string $compression
|
||||
*/
|
||||
public function setCompression($compression)
|
||||
{
|
||||
/*
|
||||
* If we don't support passed compression, leave old one.
|
||||
*/
|
||||
switch ($compression) {
|
||||
case 'gzip':
|
||||
$this->compression = Phar::GZ;
|
||||
break;
|
||||
case 'bzip2':
|
||||
$this->compression = Phar::BZ2;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param PhingFile $destinationFile
|
||||
*/
|
||||
public function setDestFile(PhingFile $destinationFile)
|
||||
{
|
||||
$this->destinationFile = $destinationFile;
|
||||
}
|
||||
/**
|
||||
* @param PhingFile $baseDirectory
|
||||
*/
|
||||
public function setBaseDir(PhingFile $baseDirectory)
|
||||
{
|
||||
$this->baseDirectory = $baseDirectory;
|
||||
}
|
||||
/**
|
||||
* @param PhingFile $stubFile
|
||||
*/
|
||||
public function setCliStub(PhingFile $stubFile)
|
||||
{
|
||||
$this->cliStubFile = $stubFile;
|
||||
}
|
||||
/**
|
||||
* @param PhingFile $stubFile
|
||||
*/
|
||||
public function setWebStub(PhingFile $stubFile)
|
||||
{
|
||||
$this->webStubFile = $stubFile;
|
||||
}
|
||||
/**
|
||||
* @param string $stubPath
|
||||
*/
|
||||
public function setStub($stubPath)
|
||||
{
|
||||
$this->stubPath = $stubPath;
|
||||
}
|
||||
/**
|
||||
* @param $alias
|
||||
*/
|
||||
public function setAlias($alias)
|
||||
{
|
||||
$this->alias = $alias;
|
||||
}
|
||||
/**
|
||||
* @throws BuildException
|
||||
*/
|
||||
public function main()
|
||||
{
|
||||
$this->checkPreconditions();
|
||||
|
||||
try {
|
||||
$this->log(
|
||||
'Building package: '.$this->destinationFile->__toString(),
|
||||
Project::MSG_INFO
|
||||
);
|
||||
|
||||
/*
|
||||
* Delete old package, if exists.
|
||||
*/
|
||||
if ($this->destinationFile->exists()) {
|
||||
/*
|
||||
* TODO Check operation for errors...
|
||||
*/
|
||||
$this->destinationFile->delete();
|
||||
}
|
||||
|
||||
$phar = $this->buildPhar();
|
||||
$phar->startBuffering();
|
||||
|
||||
$baseDirectory = realpath($this->baseDirectory->getPath());
|
||||
|
||||
foreach ($this->filesets as $fileset) {
|
||||
foreach ($fileset as $realFileName) {
|
||||
/*
|
||||
* Calculate local file name.
|
||||
*/
|
||||
$localFileName = $realFileName;
|
||||
if (0 === strpos($realFileName, $baseDirectory)) {
|
||||
$localFileName = substr(
|
||||
$realFileName,
|
||||
strlen($baseDirectory)
|
||||
);
|
||||
}
|
||||
|
||||
$this->log(
|
||||
'Adding '.$realFileName.' as '.$localFileName.' to package',
|
||||
Project::MSG_VERBOSE
|
||||
);
|
||||
|
||||
$phar->addFile($realFileName, $localFileName);
|
||||
}
|
||||
}
|
||||
|
||||
$phar->stopBuffering();
|
||||
|
||||
/*
|
||||
* File compression, if needed.
|
||||
*/
|
||||
if (Phar::NONE != $this->compression) {
|
||||
$phar->compressFiles($this->compression);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
throw new BuildException(
|
||||
'Problem creating package: '.$e->getMessage(),
|
||||
$e,
|
||||
$this->getLocation()
|
||||
);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @throws BuildException
|
||||
*/
|
||||
private function checkPreconditions()
|
||||
{
|
||||
if (is_null($this->destinationFile)) {
|
||||
throw new BuildException("destfile attribute must be set!", $this->getLocation());
|
||||
}
|
||||
|
||||
if ($this->destinationFile->exists() && $this->destinationFile->isDirectory()) {
|
||||
throw new BuildException("destfile is a directory!", $this->getLocation());
|
||||
}
|
||||
|
||||
if (!$this->destinationFile->canWrite()) {
|
||||
throw new BuildException("Can not write to the specified destfile!", $this->getLocation());
|
||||
}
|
||||
if (!is_null($this->baseDirectory)) {
|
||||
if (!$this->baseDirectory->exists()) {
|
||||
throw new BuildException("basedir does not exist!", $this->getLocation());
|
||||
}
|
||||
}
|
||||
|
||||
if (is_null($this->metadata)) {
|
||||
throw new BuildException("metadata element must be set", $this->getLocation());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Build and configure Phar object.
|
||||
*
|
||||
* @return Phar
|
||||
*/
|
||||
private function buildPhar()
|
||||
{
|
||||
$phar = new Phar($this->destinationFile);
|
||||
|
||||
$phar->setSignatureAlgorithm($this->signatureAlgorithm);
|
||||
|
||||
if (isset($this->stubPath)) {
|
||||
$phar->setStub(file_get_contents($this->stubPath));
|
||||
} else {
|
||||
$phar->setDefaultStub(
|
||||
$this->cliStubFile,
|
||||
$this->webStubFile
|
||||
);
|
||||
}
|
||||
|
||||
if ($metadata = $this->metadata->toArray()) {
|
||||
$phar->setMetadata($metadata);
|
||||
}
|
||||
|
||||
if(!empty($this->alias)){
|
||||
$phar->setAlias($this->alias);
|
||||
}
|
||||
|
||||
return $phar;
|
||||
}
|
||||
}
|
248
airtime_mvc/library/phing/tasks/ext/phk/PhkPackageTask.php
Normal file
248
airtime_mvc/library/phing/tasks/ext/phk/PhkPackageTask.php
Normal file
|
@ -0,0 +1,248 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: PhkPackageTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
require_once 'phing/tasks/ext/phk/PhkPackageWebAccess.php';
|
||||
|
||||
/**
|
||||
* See {@link http://phk.tekwire.net/} for more information about PHK.
|
||||
*
|
||||
* @author Alexey Shockov <alexey@shockov.com>
|
||||
* @package phing.tasks.ext.phk
|
||||
*/
|
||||
class PhkPackageTask extends Task
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $outputFile;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $inputDirectory;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $phkCreatorPath;
|
||||
/**
|
||||
* @var PhkPackageWebAccess
|
||||
*/
|
||||
private $webAccess;
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $modifiers = array();
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $options = array();
|
||||
/**
|
||||
* @return PhkPackageWebAccess
|
||||
*/
|
||||
public function createWebAccess()
|
||||
{
|
||||
return ($this->webAccess = new PhkPackageWebAccess());
|
||||
}
|
||||
/**
|
||||
* @param string $crcCheck
|
||||
*/
|
||||
public function setCrcCheck($crcCheck)
|
||||
{
|
||||
$this->options['crc_check'] = ('true' == $crcCheck ? true : false);
|
||||
}
|
||||
/**
|
||||
* @param string $webRunScript
|
||||
*/
|
||||
public function setWebRunScript($webRunScript)
|
||||
{
|
||||
$this->options['web_run_script'] = $webRunScript;
|
||||
}
|
||||
/**
|
||||
* @param string $cliRunScript
|
||||
*/
|
||||
public function setCliRunScript($cliRunScript)
|
||||
{
|
||||
$this->options['cli_run_script'] = $cliRunScript;
|
||||
}
|
||||
/**
|
||||
* @param string $libRunScript
|
||||
*/
|
||||
public function setLibRunScript($libRunScript)
|
||||
{
|
||||
$this->options['lib_run_script'] = $libRunScript;
|
||||
}
|
||||
/**
|
||||
* @param string $name
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->options['name'] = $name;
|
||||
}
|
||||
/**
|
||||
* @param string $webMainRedirect
|
||||
*/
|
||||
public function setWebMainRedirect($webMainRedirect)
|
||||
{
|
||||
$this->options['web_main_redirect'] = ('true' == $webMainRedirect ? true : false);
|
||||
}
|
||||
/**
|
||||
* @param string $pluginClass
|
||||
*/
|
||||
public function setPluginClass($pluginClass)
|
||||
{
|
||||
$this->options['plugin_class'] = $pluginClass;
|
||||
}
|
||||
/**
|
||||
* @param string $version
|
||||
*/
|
||||
public function setVersion($version)
|
||||
{
|
||||
$this->options['version'] = $version;
|
||||
}
|
||||
/**
|
||||
* @param string $summary
|
||||
*/
|
||||
public function setSummary($summary)
|
||||
{
|
||||
$this->options['summary'] = $summary;
|
||||
}
|
||||
/**
|
||||
* @param string $inputDirectory
|
||||
*/
|
||||
public function setInputDirectory($inputDirectory)
|
||||
{
|
||||
$this->inputDirectory = $inputDirectory;
|
||||
}
|
||||
/**
|
||||
* @param string $outputFile
|
||||
*/
|
||||
public function setOutputFile($outputFile)
|
||||
{
|
||||
$this->outputFile = $outputFile;
|
||||
}
|
||||
/**
|
||||
* May be none, gzip or bzip2.
|
||||
*
|
||||
* @param string $compress
|
||||
*/
|
||||
public function setCompress($compress)
|
||||
{
|
||||
$this->modifiers['compress'] = $compress;
|
||||
}
|
||||
/**
|
||||
* True or false.
|
||||
*
|
||||
* @param srting $strip
|
||||
*/
|
||||
public function setStrip($strip)
|
||||
{
|
||||
$this->modifiers['strip'] = $strip;
|
||||
}
|
||||
/**
|
||||
* Path to PHK_Creator.phk file.
|
||||
*
|
||||
* @param srting $path
|
||||
*/
|
||||
public function setPhkCreatorPath($path)
|
||||
{
|
||||
$this->phkCreatorPath = $path;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
|
||||
}
|
||||
/**
|
||||
* Main method...
|
||||
*/
|
||||
public function main()
|
||||
{
|
||||
/*
|
||||
* Check for empty first - speed ;)
|
||||
*/
|
||||
if (!is_file($this->phkCreatorPath)) {
|
||||
throw new BuildException('You must specify the "phkcreatorpath" attribute for PHK task.');
|
||||
}
|
||||
if (empty($this->inputDirectory)) {
|
||||
throw new BuildException('You must specify the "inputdirectory" attribute for PHK task.');
|
||||
}
|
||||
if (empty($this->outputFile)) {
|
||||
throw new BuildException('You must specify the "outputfile" attribute for PHK task.');
|
||||
}
|
||||
|
||||
require_once $this->phkCreatorPath;
|
||||
|
||||
$mountPoint = PHK_Mgr::mount($this->outputFile, PHK::F_CREATOR);
|
||||
$phkManager = PHK_Mgr::instance($mountPoint);
|
||||
|
||||
/*
|
||||
* Add files.
|
||||
*/
|
||||
$phkManager->ftree()->merge_file_tree('/', $this->inputDirectory, $this->modifiers);
|
||||
|
||||
/*
|
||||
* Add web_access to options, if present.
|
||||
*/
|
||||
if (!is_null($this->webAccess)) {
|
||||
$webAccessPaths = $this->webAccess->getPaths();
|
||||
if (!empty($webAccessPaths)) {
|
||||
$this->options['web_access'] = $webAccessPaths;
|
||||
}
|
||||
}
|
||||
|
||||
$phkManager->set_options($this->options);
|
||||
|
||||
/*
|
||||
* Intercept output (in PHP we can't intercept stream).
|
||||
*/
|
||||
ob_start();
|
||||
/*
|
||||
* Create file...
|
||||
*/
|
||||
$phkManager->dump();
|
||||
/*
|
||||
* Print with Phing log...
|
||||
*/
|
||||
$output = trim(ob_get_clean());
|
||||
$output = split("\n", $output);
|
||||
foreach ($output as $line) {
|
||||
/*
|
||||
* Delete all '--- *' lines. Bluh!
|
||||
*/
|
||||
/*
|
||||
* TODO Change preg_math to more faster alternative.
|
||||
*/
|
||||
if (preg_match('/^---/', $line)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->log($line);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set rights for generated file... Don't use umask() - see
|
||||
* notes in official documentation for this function.
|
||||
*/
|
||||
chmod($this->outputFile, 0644);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: PhkPackageWebAccess.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/tasks/ext/phk/PhkPackageWebAccessPath.php';
|
||||
|
||||
/**
|
||||
* @author Alexey Shockov <alexey@shockov.com>
|
||||
* @package phing.tasks.ext.phk
|
||||
*/
|
||||
class PhkPackageWebAccess
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $paths = array();
|
||||
/**
|
||||
* @return PhkPackageWebAccessPath
|
||||
*/
|
||||
public function createPath()
|
||||
{
|
||||
return ($this->paths[] = new PhkPackageWebAccessPath());
|
||||
}
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getPaths()
|
||||
{
|
||||
/*
|
||||
* Get real paths...
|
||||
*/
|
||||
$paths = array();
|
||||
|
||||
foreach ($this->paths as $path) {
|
||||
$paths[] = $path->getPath();
|
||||
}
|
||||
|
||||
return $paths;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: PhkPackageWebAccessPath.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author Alexey Shockov <alexey@shockov.com>
|
||||
* @package phing.tasks.ext.phk
|
||||
*/
|
||||
class PhkPackageWebAccessPath
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $path;
|
||||
/**
|
||||
* @param string $path
|
||||
*/
|
||||
public function addText($path)
|
||||
{
|
||||
$this->path = trim($path);
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPath()
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,177 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: PHPCPDFormatterElement.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/system/io/PhingFile.php';
|
||||
|
||||
/**
|
||||
* A wrapper for the implementations of PHPCPDResultFormatter.
|
||||
*
|
||||
* @package phing.tasks.ext.phpcpd
|
||||
* @author Benjamin Schultz <bschultz@proqrent.de>
|
||||
* @version $Id: PHPCPDFormatterElement.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*/
|
||||
class PHPCPDFormatterElement
|
||||
{
|
||||
/**
|
||||
* The report result formatter.
|
||||
*
|
||||
* @var PHPCPDResultFormatter
|
||||
*/
|
||||
protected $_formatter = null;
|
||||
|
||||
/**
|
||||
* The type of the formatter.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_type = '';
|
||||
|
||||
/**
|
||||
* Whether to use file (or write output to phing log).
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_useFile = true;
|
||||
|
||||
/**
|
||||
* Output file for formatter.
|
||||
*
|
||||
* @var PhingFile
|
||||
*/
|
||||
protected $_outfile = null;
|
||||
|
||||
/**
|
||||
* The parent task
|
||||
*
|
||||
* @var PHPCPDTask
|
||||
*/
|
||||
private $_parentTask;
|
||||
|
||||
/**
|
||||
* Construct a new PHPCPDFormatterElement with parent task.
|
||||
* @param PHPCPDTask $parentTask
|
||||
*/
|
||||
public function __construct(PHPCPDTask $parentTask)
|
||||
{
|
||||
$this->_parentTask = $parentTask;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the formatter type.
|
||||
*
|
||||
* @param string $type Type of the formatter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setType($type)
|
||||
{
|
||||
$this->_type = $type;
|
||||
|
||||
switch ($this->_type) {
|
||||
case 'pmd':
|
||||
if ($this->_useFile === false) {
|
||||
throw new BuildException(
|
||||
"Formatter '" . $this->_type
|
||||
. "' can only print the result to an file"
|
||||
);
|
||||
}
|
||||
|
||||
include_once 'phing/tasks/ext/phpcpd/formatter/PMDPHPCPDResultFormatter.php';
|
||||
$this->_formatter = new PMDPHPCPDResultFormatter();
|
||||
break;
|
||||
|
||||
case 'default':
|
||||
include_once 'phing/tasks/ext/phpcpd/formatter/DefaultPHPCPDResultFormatter.php';
|
||||
$this->_formatter = new DefaultPHPCPDResultFormatter();
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new BuildException(
|
||||
"Formatter '" . $this->_type . "' not implemented"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the formatter type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether to write formatter results to file or not.
|
||||
*
|
||||
* @param boolean $useFile True or false.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUseFile($useFile)
|
||||
{
|
||||
$this->_useFile = StringHelper::booleanValue($useFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether to write formatter results to file or not.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getUseFile()
|
||||
{
|
||||
return $this->_useFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the output file for the formatter results.
|
||||
*
|
||||
* @param PhingFile $outfile The output file
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setOutfile(PhingFile $outfile)
|
||||
{
|
||||
$this->_outfile = $outfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the output file.
|
||||
*
|
||||
* @return PhingFile
|
||||
*/
|
||||
public function getOutfile()
|
||||
{
|
||||
return $this->_outfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the report formatter.
|
||||
*
|
||||
* @throws BuildException When the specified renderer does not exist.
|
||||
* @return PHPCPDResultFormatter
|
||||
*/
|
||||
public function getFormatter()
|
||||
{
|
||||
return $this->_formatter;
|
||||
}
|
||||
}
|
323
airtime_mvc/library/phing/tasks/ext/phpcpd/PHPCPDTask.php
Normal file
323
airtime_mvc/library/phing/tasks/ext/phpcpd/PHPCPDTask.php
Normal file
|
@ -0,0 +1,323 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: PHPCPDTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
|
||||
/**
|
||||
* Runs PHP Copy & Paste Detector. Checking PHP files for duplicated code.
|
||||
* Refactored original PhpCpdTask provided by
|
||||
* Timo Haberkern <timo.haberkern@fantastic-bits.de>
|
||||
*
|
||||
* @package phing.tasks.ext.phpcpd
|
||||
* @author Benjamin Schultz <bschultz@proqrent.de>
|
||||
* @version $Id: PHPCPDTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*/
|
||||
class PHPCPDTask extends Task
|
||||
{
|
||||
/**
|
||||
* A php source code filename or directory
|
||||
*
|
||||
* @var PhingFile
|
||||
*/
|
||||
protected $_file = null;
|
||||
|
||||
/**
|
||||
* All fileset objects assigned to this task
|
||||
*
|
||||
* @var array<FileSet>
|
||||
*/
|
||||
protected $_filesets = array();
|
||||
|
||||
/**
|
||||
* Minimum number of identical lines.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $_minLines = 5;
|
||||
|
||||
/**
|
||||
* Minimum number of identical tokens.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $_minTokens = 70;
|
||||
|
||||
/**
|
||||
* List of valid file extensions for analyzed files.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_allowedFileExtensions = array('php');
|
||||
|
||||
/**
|
||||
* List of exclude directory patterns.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_ignorePatterns = array('.git', '.svn', 'CVS', '.bzr', '.hg');
|
||||
|
||||
/**
|
||||
* The format for the report
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_format = 'default';
|
||||
|
||||
/**
|
||||
* Formatter elements.
|
||||
*
|
||||
* @var array<PHPCPDFormatterElement>
|
||||
*/
|
||||
protected $_formatters = array();
|
||||
|
||||
/**
|
||||
* Load the necessary environment for running PHPCPD.
|
||||
*
|
||||
* @throws BuildException - if the phpcpd classes can't be loaded.
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
/**
|
||||
* Determine PHPCPD installation
|
||||
*/
|
||||
@include_once 'PHPCPD/TextUI/Command.php';
|
||||
|
||||
if (! class_exists('PHPCPD_TextUI_Command')) {
|
||||
throw new BuildException(
|
||||
'PHPCPDTask depends on PHPCPD being installed '
|
||||
. 'and on include_path.',
|
||||
$this->getLocation()
|
||||
);
|
||||
}
|
||||
|
||||
// Other dependencies that should only be loaded
|
||||
// when class is actually used
|
||||
require_once 'phing/tasks/ext/phpcpd/PHPCPDFormatterElement.php';
|
||||
require_once 'PHPCPD/Detector.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the input source file or directory.
|
||||
*
|
||||
* @param PhingFile $file The input source file or directory.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setFile(PhingFile $file)
|
||||
{
|
||||
$this->_file = $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Nested creator, adds a set of files (nested fileset attribute).
|
||||
*
|
||||
* @return FileSet The created fileset object
|
||||
*/
|
||||
public function createFileSet()
|
||||
{
|
||||
$num = array_push($this->_filesets, new FileSet());
|
||||
return $this->_filesets[$num-1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the minimum rule priority.
|
||||
*
|
||||
* @param integer $minimumPriority Minimum rule priority.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setMinimumPriority($minimumPriority)
|
||||
{
|
||||
$this->_minimumPriority = $minimumPriority;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the minimum number of identical lines (default: 5).
|
||||
*
|
||||
* @param integer $minLines Minimum number of identical lines
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setMinLines($minLines)
|
||||
{
|
||||
$this->_minLines = $minLines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the minimum number of identical tokens (default: 70).
|
||||
*
|
||||
* @param integer $minTokens Minimum number of identical tokens
|
||||
*/
|
||||
public function setMinTokens($minTokens)
|
||||
{
|
||||
$this->_minTokens = $minTokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a list of filename extensions for valid php source code files.
|
||||
*
|
||||
* @param string $fileExtensions List of valid file extensions.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setAllowedFileExtensions($fileExtensions)
|
||||
{
|
||||
$this->_allowedFileExtensions = array();
|
||||
|
||||
$token = ' ,;';
|
||||
$ext = strtok($fileExtensions, $token);
|
||||
|
||||
while ($ext !== false) {
|
||||
$this->_allowedFileExtensions[] = $ext;
|
||||
$ext = strtok($token);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a list of ignore patterns that is used to exclude directories from
|
||||
* the source analysis.
|
||||
*
|
||||
* @param string $ignorePatterns List of ignore patterns.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setIgnorePatterns($ignorePatterns)
|
||||
{
|
||||
$this->_ignorePatterns = array();
|
||||
|
||||
$token = ' ,;';
|
||||
$pattern = strtok($ignorePatterns, $token);
|
||||
|
||||
while ($pattern !== false) {
|
||||
$this->_ignorePatterns[] = $pattern;
|
||||
$pattern = strtok($token);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the output format
|
||||
*
|
||||
* @param string $format Format of the report
|
||||
*/
|
||||
public function setFormat($format)
|
||||
{
|
||||
$this->_format = $format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create object for nested formatter element.
|
||||
*
|
||||
* @return PHPCPDFormatterElement
|
||||
*/
|
||||
public function createFormatter()
|
||||
{
|
||||
$num = array_push(
|
||||
$this->_formatters,
|
||||
new PHPCPDFormatterElement($this)
|
||||
);
|
||||
return $this->_formatters[$num-1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes PHPCPD against PhingFile or a FileSet
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function main()
|
||||
{
|
||||
if (!isset($this->_file) and count($this->_filesets) == 0) {
|
||||
throw new BuildException(
|
||||
"Missing either a nested fileset or attribute 'file' set"
|
||||
);
|
||||
}
|
||||
|
||||
if (count($this->_formatters) == 0) {
|
||||
// turn legacy format attribute into formatter
|
||||
$fmt = new PHPCPDFormatterElement($this);
|
||||
$fmt->setType($this->format);
|
||||
$fmt->setUseFile(false);
|
||||
$this->_formatters[] = $fmt;
|
||||
}
|
||||
|
||||
$this->validateFormatters();
|
||||
|
||||
$filesToParse = array();
|
||||
|
||||
if ($this->_file instanceof PhingFile) {
|
||||
$filesToParse[] = $this->_file->getPath();
|
||||
} else {
|
||||
// append any files in filesets
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->log('Processing files...');
|
||||
|
||||
$detector = new PHPCPD_Detector();
|
||||
$clones = $detector->copyPasteDetection(
|
||||
$filesToParse,
|
||||
$this->_minLines,
|
||||
$this->_minTokens
|
||||
);
|
||||
|
||||
$this->log('Finished copy/paste detection');
|
||||
|
||||
foreach ($this->_formatters as $fe) {
|
||||
$formatter = $fe->getFormatter();
|
||||
$formatter->processClones(
|
||||
$clones,
|
||||
$fe->getOutfile(),
|
||||
$this->project
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the available formatters
|
||||
*
|
||||
* @throws BuildException
|
||||
* @return void
|
||||
*/
|
||||
protected function validateFormatters()
|
||||
{
|
||||
foreach ($this->_formatters as $fe) {
|
||||
if ($fe->getType() == '') {
|
||||
throw new BuildException(
|
||||
"Formatter missing required 'type' attribute."
|
||||
);
|
||||
}
|
||||
|
||||
if ($fe->getUsefile() && $fe->getOutfile() === null) {
|
||||
throw new BuildException(
|
||||
"Formatter requires 'outfile' attribute "
|
||||
. "when 'useFile' is true."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: DefaultPHPCPDResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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 'PHPCPD/TextUI/ResultPrinter.php';
|
||||
require_once 'phing/tasks/ext/phpcpd/formatter/PHPCPDResultFormatter.php';
|
||||
|
||||
/**
|
||||
* Prints plain text output of phpcpd run
|
||||
*
|
||||
* @package phing.tasks.ext.phpcpd.formatter
|
||||
* @author Benjamin Schultz <bschultz@proqrent.de>
|
||||
* @version $Id: DefaultPHPCPDResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*/
|
||||
class DefaultPHPCPDResultFormatter extends PHPCPDResultFormatter
|
||||
{
|
||||
|
||||
/**
|
||||
* Processes a list of clones.
|
||||
*
|
||||
* @param PHPCPD_CloneMap $clones
|
||||
*/
|
||||
public function processClones(PHPCPD_CloneMap $clones, PhingFile $outfile, Project $project)
|
||||
{
|
||||
$logger = new PHPCPD_TextUI_ResultPrinter();
|
||||
// default format goes to logs, no buffering
|
||||
ob_start();
|
||||
$logger->printResult($clones, $project->getBaseDir());
|
||||
$output = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
if (!$this->usefile) {
|
||||
echo $output;
|
||||
} else {
|
||||
$outputFile = $outfile->getPath();
|
||||
file_put_contents($outputFile, $output);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: PHPCPDResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This abstract class describes classes that format the results of a PHPCPD run.
|
||||
*
|
||||
* @package phing.tasks.ext.phpcpd.formatter
|
||||
* @author Benjamin Schultz <bschultz@proqrent.de>
|
||||
* @version $Id: PHPCPDResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*/
|
||||
abstract class PHPCPDResultFormatter
|
||||
{
|
||||
/**
|
||||
* Processes a list of clones.
|
||||
*
|
||||
* @param PHPCPD_CloneMap $clones
|
||||
*/
|
||||
abstract public function processClones(PHPCPD_CloneMap $clones, PhingFile $outfile, Project $project);
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: PMDPHPCPDResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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 'PHPCPD/Log/XML/PMD.php';
|
||||
require_once 'phing/tasks/ext/phpcpd/formatter/PHPCPDResultFormatter.php';
|
||||
|
||||
/**
|
||||
* Prints PMD-XML output of phpcpd run
|
||||
*
|
||||
* @package phing.tasks.ext.phpcpd.formatter
|
||||
* @author Benjamin Schultz <bschultz@proqrent.de>
|
||||
* @version $Id: PMDPHPCPDResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*/
|
||||
class PMDPHPCPDResultFormatter extends PHPCPDResultFormatter
|
||||
{
|
||||
/**
|
||||
* Processes a list of clones.
|
||||
*
|
||||
* @param PHPCPD_CloneMap $clones
|
||||
*/
|
||||
public function processClones(PHPCPD_CloneMap $clones, PhingFile $outfile, Project $project)
|
||||
{
|
||||
$logger = new PHPCPD_Log_XML_PMD($outfile);
|
||||
$logger->processClones($clones);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,220 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: PhingPhpDocumentorSetup.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Phing subclass of the phpDocumentor_setup class provided with PhpDocumentor to work around limitations in PhpDocumentor API.
|
||||
*
|
||||
* This class is necessary because phpDocumentor_setup does not expose a complete API for setting configuration options. Because
|
||||
* this class must directly modify some "private" GLOBAL(!) configuration variables, it is liable to break if the PhpDocumentor
|
||||
* internal implementation changes. Obviously this is far from ideal, but there's also no solution given the inflexibility of the
|
||||
* PhpDocumentor design.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>@author hans
|
||||
* @version $Id: PhingPhpDocumentorSetup.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.phpdoc
|
||||
*/
|
||||
class PhingPhpDocumentorSetup extends phpDocumentor_setup {
|
||||
|
||||
/**
|
||||
* Constructs a new PhingPhpDocumentorSetup.
|
||||
*
|
||||
* @param string $configDir Directory in which to look for configuration files.
|
||||
*/
|
||||
public function __construct($configdir = null) {
|
||||
global $_phpDocumentor_cvsphpfile_exts, $_phpDocumentor_setting, $_phpDocumentor_phpfile_exts;
|
||||
|
||||
$this->setup = new Io();
|
||||
$this->render = new phpDocumentor_IntermediateParser("Default Title");
|
||||
|
||||
$GLOBALS['_phpDocumentor_install_dir'] = $configdir;
|
||||
$this->parseIni();
|
||||
|
||||
// These redundant-looking lines seem to actually make a difference.
|
||||
// See: http://phing.info/trac/ticket/150
|
||||
$_phpDocumentor_phpfile_exts = $GLOBALS['_phpDocumentor_phpfile_exts'];
|
||||
$_phpDocumentor_cvsphpfile_exts = $GLOBALS['_phpDocumentor_cvsphpfile_exts'];
|
||||
|
||||
if (tokenizer_ext) {
|
||||
$this->parse = new phpDocumentorTParser();
|
||||
} else {
|
||||
$this->parse = new Parser();
|
||||
}
|
||||
|
||||
$this->setMemoryLimit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether to generate sourcecode for each file parsed.
|
||||
*
|
||||
* This method exists as a hack because there is no API exposed for this in PhpDocumentor.
|
||||
* Note that because we are setting a "private" GLOBAL(!!) config var with this value, this
|
||||
* is subject to break if PhpDocumentor internals changes.
|
||||
*
|
||||
* @param bool $b
|
||||
*/
|
||||
public function setGenerateSourcecode($b) {
|
||||
global $_phpDocumentor_setting;
|
||||
$_phpDocumentor_setting['sourcecode'] = (boolean) $b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an array of README/INSTALL/CHANGELOG file paths.
|
||||
*
|
||||
* This method exists as a hack because there is no API exposed for this in PhpDocumentor.
|
||||
* Note that because we are setting a "private" GLOBAL(!!) config var with this value, this
|
||||
* is subject to break if PhpDocumentor internals changes.
|
||||
*
|
||||
* @param array $files Absolute paths to files.
|
||||
*/
|
||||
public function setRicFiles($files) {
|
||||
global $_phpDocumentor_RIC_files;
|
||||
$_phpDocumentor_RIC_files = $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set comma-separated list of tags to ignore.
|
||||
*
|
||||
* This method exists as a hack because there is no API exposed for this in PhpDocumentor.
|
||||
* Note that because we are setting a "private" GLOBAL(!!) config var with this value, this
|
||||
* is subject to break if PhpDocumentor internals changes.
|
||||
*
|
||||
* @param string $tags
|
||||
*/
|
||||
public function setIgnoreTags($tags) {
|
||||
global $_phpDocumentor_setting;
|
||||
$ignoretags = explode(',', $tags);
|
||||
$ignoretags = array_map('trim', $ignoretags);
|
||||
$tags = array();
|
||||
foreach($ignoretags as $tag) {
|
||||
if (!in_array($tag,array('@global', '@access', '@package', '@ignore', '@name', '@param', '@return', '@staticvar', '@var')))
|
||||
$tags[] = $tag;
|
||||
}
|
||||
$_phpDocumentor_setting['ignoretags'] = $tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether to parse dirs as PEAR repos.
|
||||
*
|
||||
* This method exists as a hack because there is no API exposed for this in PhpDocumentor.
|
||||
* Note that because we are setting a "private" GLOBAL(!!) config var with this value, this
|
||||
* is subject to break if PhpDocumentor internals changes.
|
||||
*
|
||||
* @param bool $b
|
||||
*/
|
||||
public function setPear($b) {
|
||||
global $_phpDocumentor_setting;
|
||||
$_phpDocumentor_setting['pear'] = (boolean) $b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set fullpath to directory to look in for examples.
|
||||
*
|
||||
* This method exists as a hack because there is no API exposed for this in PhpDocumentor.
|
||||
* Note that because we are setting a "private" GLOBAL(!!) config var with this value, this
|
||||
* is subject to break if PhpDocumentor internals changes.
|
||||
*
|
||||
* @param string $dir
|
||||
*/
|
||||
public function setExamplesDir($dir) {
|
||||
global $_phpDocumentor_setting;
|
||||
$_phpDocumentor_setting['examplesdir'] = $dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default package name.
|
||||
*
|
||||
* This method exists as a hack because there is no API exposed for this in PhpDocumentor.
|
||||
* Note that because we are setting a "private" GLOBAL(!!) config var with this value, this
|
||||
* is subject to break if PhpDocumentor internals changes.
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
public function setDefaultPackageName($name) {
|
||||
$GLOBALS['phpDocumentor_DefaultPackageName'] = trim($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default category name.
|
||||
*
|
||||
* This method exists as a hack because there is no API exposed for this in PhpDocumentor.
|
||||
* Note that because we are setting a "private" GLOBAL(!!) config var with this value, this
|
||||
* is subject to break if PhpDocumentor internals changes.
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
public function setDefaultCategoryName($name) {
|
||||
$GLOBALS['phpDocumentor_DefaultCategoryName'] = trim($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables quiet mode.
|
||||
*
|
||||
* This method exists as a hack because the API exposed for this method in PhpDocumentor
|
||||
* doesn't work correctly.
|
||||
*
|
||||
* Note that because we are setting a "private" GLOBAL(!!) config var with this value, this
|
||||
* is subject to break if PhpDocumentor internals changes.
|
||||
*
|
||||
*/
|
||||
public function setQuietMode() {
|
||||
global $_phpDocumentor_setting;
|
||||
$_phpDocumentor_setting['quiet'] = true;
|
||||
parent::setQuietMode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Control whether or not warnings will be shown for undocumented elements.
|
||||
* Useful for identifying classes and methods that haven't yet been
|
||||
* documented.
|
||||
*
|
||||
* @param bool $bEnable
|
||||
*/
|
||||
public function setUndocumentedelements($bEnable) {
|
||||
$this->render->setUndocumentedElementWarningsMode($bEnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* custom tags, will be recognized and put in tags[] instead of
|
||||
* unknowntags[]
|
||||
*
|
||||
* This method exists as a hack because the API exposed for this method in
|
||||
* PhpDocumentor doesn't work correctly.
|
||||
*
|
||||
* Note that because we are setting a "private" GLOBAL(!!) config var with
|
||||
* this value, this is subject to break if PhpDocumentor internals changes.
|
||||
*
|
||||
* @param string $sCustomtags
|
||||
*/
|
||||
public function setCustomtags($sCustomtags) {
|
||||
global $_phpDocumentor_setting;
|
||||
$_phpDocumentor_setting['customtags'] = $sCustomtags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Files to ignore
|
||||
*
|
||||
* @param string $sIgnore
|
||||
*/
|
||||
public function setIgnore($sIgnore) {
|
||||
global $_phpDocumentor_setting;
|
||||
$_phpDocumentor_setting['ignore'] = $sIgnore;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,265 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* $Id: PhpDocumentorExternalTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/tasks/ext/phpdoc/PhpDocumentorTask.php';
|
||||
|
||||
/**
|
||||
* Task to run phpDocumentor with an external process
|
||||
*
|
||||
* This classes uses the commandline phpdoc script to build documentation.
|
||||
* Use this task instead of the PhpDocumentorTask when you've a clash with the
|
||||
* Smarty libraries.
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @author Markus Fischer <markus@fischer.name>
|
||||
* @version $Id: PhpDocumentorExternalTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.phpdoc
|
||||
*/
|
||||
class PhpDocumentorExternalTask extends PhpDocumentorTask
|
||||
{
|
||||
/**
|
||||
* The path to the executable for phpDocumentor
|
||||
*/
|
||||
protected $programPath = 'phpdoc';
|
||||
|
||||
protected $sourcepath = NULL;
|
||||
|
||||
/**
|
||||
* @var bool ignore symlinks to other files or directories
|
||||
*/
|
||||
protected $ignoresymlinks = false;
|
||||
|
||||
/**
|
||||
* Sets the path to the phpDocumentor executable
|
||||
*/
|
||||
public function setProgramPath($programPath)
|
||||
{
|
||||
$this->programPath = $programPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path to the phpDocumentor executable
|
||||
*/
|
||||
public function getProgramPath()
|
||||
{
|
||||
return $this->programPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the source path. A directory or a comma separate list of directories.
|
||||
*/
|
||||
public function setSourcepath($sourcepath)
|
||||
{
|
||||
$this->sourcepath = $sourcepath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignore symlinks to other files or directories.
|
||||
*
|
||||
* @param bool $bSet
|
||||
*/
|
||||
public function setIgnoresymlinks($bSet) {
|
||||
$this->ignoresymlinks = $bSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main entrypoint of the task
|
||||
*/
|
||||
public function main()
|
||||
{
|
||||
$this->validate();
|
||||
$arguments = join(' ', $this->constructArguments());
|
||||
|
||||
$this->log("Running phpDocumentor...");
|
||||
|
||||
exec($this->programPath . " " . $arguments, $output, $return);
|
||||
|
||||
if ($return != 0)
|
||||
{
|
||||
throw new BuildException("Could not execute phpDocumentor: " . implode(' ', $output));
|
||||
}
|
||||
|
||||
foreach($output as $line)
|
||||
{
|
||||
if(strpos($line, 'ERROR') !== false)
|
||||
{
|
||||
$this->log($line, Project::MSG_ERR);
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->log($line, Project::MSG_VERBOSE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an argument string for phpDocumentor
|
||||
* @return array
|
||||
*/
|
||||
protected function constructArguments()
|
||||
{
|
||||
$aArgs = array();
|
||||
if ($this->title)
|
||||
{
|
||||
$aArgs[] = '--title "' . $this->title . '"';
|
||||
}
|
||||
|
||||
if ($this->destdir)
|
||||
{
|
||||
$aArgs[] = '--target "' . $this->destdir->getAbsolutePath() . '"';
|
||||
}
|
||||
|
||||
if ($this->sourcepath)
|
||||
{
|
||||
$aArgs[] = '--directory "' . $this->sourcepath . '"';
|
||||
}
|
||||
|
||||
if ($this->output)
|
||||
{
|
||||
$aArgs[] = '--output ' . $this->output;
|
||||
}
|
||||
|
||||
if ($this->linksource)
|
||||
{
|
||||
$aArgs[] = '--sourcecode on';
|
||||
}
|
||||
|
||||
if ($this->parseprivate)
|
||||
{
|
||||
$aArgs[] = '--parseprivate on';
|
||||
}
|
||||
|
||||
if ($this->ignore)
|
||||
{
|
||||
$aArgs[] = '--ignore ' . $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();
|
||||
}
|
||||
}
|
||||
if (count($filesToParse) > 0) {
|
||||
$aArgs[] = '--filename "' . join(',', $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->getAbsolutePath();
|
||||
}
|
||||
}
|
||||
if (count($ricFiles) > 0) {
|
||||
$aArgs[] = '--readmeinstallchangelog "' .
|
||||
join(',', $ricFiles) . '"';
|
||||
}
|
||||
|
||||
if ($this->javadocDesc) {
|
||||
$aArgs[] = '--javadocdesc on';
|
||||
}
|
||||
|
||||
if ($this->quiet) {
|
||||
$aArgs[] = '--quiet on';
|
||||
}
|
||||
|
||||
if ($this->packages) {
|
||||
$aArgs[] = '--packageoutput "' . $this->packages . '"';
|
||||
}
|
||||
|
||||
if ($this->ignoreTags) {
|
||||
$aArgs[] = '--ignore-tags "' . $this->ignoreTags . '"';
|
||||
}
|
||||
|
||||
if ($this->defaultCategoryName) {
|
||||
$aArgs[] = '--defaultcategoryname "' . $this->defaultCategoryName .
|
||||
'"';
|
||||
}
|
||||
|
||||
if ($this->examplesDir) {
|
||||
$aArgs[] = '--examplesdir "' . $this->examplesDir->getAbsolutePath()
|
||||
. '"';
|
||||
}
|
||||
|
||||
if ($this->templateBase) {
|
||||
$aArgs[] = '--templatebase "' . $this->templateBase->getAbsolutePath()
|
||||
. '"';
|
||||
}
|
||||
|
||||
if ($this->pear) {
|
||||
$aArgs[] = '--pear on';
|
||||
}
|
||||
|
||||
if ($this->undocumentedelements) {
|
||||
$aArgs[] = '--undocumentedelements on';
|
||||
}
|
||||
|
||||
if ($this->customtags) {
|
||||
$aArgs[] = '--customtags "' . $this->customtags . '"';
|
||||
}
|
||||
|
||||
if ($this->ignoresymlinks) {
|
||||
$aArgs[] = '--ignoresymlinks on';
|
||||
}
|
||||
|
||||
return $aArgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override PhpDocumentorTask::init() because they're specific to the phpdoc
|
||||
* API which we don't use.
|
||||
*/
|
||||
public function init() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates that necessary minimum options have been set. Based on
|
||||
* PhpDocumentorTask::validate().
|
||||
*/
|
||||
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) && !$this->sourcepath) {
|
||||
throw new BuildException("You have not specified any files to " .
|
||||
"include (<fileset> or sourcepath attribute) for phpdoc.",
|
||||
$this->getLocation());
|
||||
}
|
||||
if ($this->configdir) {
|
||||
$this->log('Ignoring unsupported configdir-Attribute',
|
||||
Project::MSG_VERBOSE);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
485
airtime_mvc/library/phing/tasks/ext/phpdoc/PhpDocumentorTask.php
Normal file
485
airtime_mvc/library/phing/tasks/ext/phpdoc/PhpDocumentorTask.php
Normal file
|
@ -0,0 +1,485 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* $Id: PhpDocumentorTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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 <michiel.rook@gmail.com>
|
||||
* @version $Id: PhpDocumentorTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @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(explode(PATH_SEPARATOR, get_include_path()) 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.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the necessary environment for running PhpDoc.
|
||||
*
|
||||
* @throws BuildException - if the phpdoc classes can't be loaded.
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$this->findPhpDocumentorInstall();
|
||||
include_once 'phing/tasks/ext/phpdoc/PhingPhpDocumentorSetup.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Main entrypoint of the task
|
||||
*/
|
||||
function main()
|
||||
{
|
||||
$this->validate();
|
||||
$configdir = $this->configDir ? $this->configDir->getAbsolutePath() : null;
|
||||
$phpdoc = new PhingPhpDocumentorSetup($configdir);
|
||||
$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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,180 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: PHPMDFormatterElement.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/system/io/PhingFile.php';
|
||||
require_once 'PHP/PMD/Writer/Stream.php';
|
||||
|
||||
/**
|
||||
* A wrapper for the implementations of PHPMDResultFormatter.
|
||||
*
|
||||
* @package phing.tasks.ext.phpmd
|
||||
* @author Benjamin Schultz <bschultz@proqrent.de>
|
||||
* @version $Id: PHPMDFormatterElement.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @since 2.4.1
|
||||
*/
|
||||
class PHPMDFormatterElement
|
||||
{
|
||||
/**
|
||||
* @var PHPMDResultFormatter
|
||||
*/
|
||||
protected $formatter = null;
|
||||
|
||||
/**
|
||||
* The type of the formatter.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $type = "";
|
||||
|
||||
/**
|
||||
* Whether to use file (or write output to phing log).
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $useFile = true;
|
||||
|
||||
/**
|
||||
* Output file for formatter.
|
||||
*
|
||||
* @var PhingFile
|
||||
*/
|
||||
protected $outfile = null;
|
||||
|
||||
/**
|
||||
* Sets the formatter type.
|
||||
*
|
||||
* @param string $type Type of the formatter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setType($type)
|
||||
{
|
||||
$this->type = $type;
|
||||
|
||||
switch ($this->type) {
|
||||
case 'xml':
|
||||
include_once 'PHP/PMD/Renderer/XMLRenderer.php';
|
||||
break;
|
||||
|
||||
case 'html':
|
||||
include_once 'PHP/PMD/Renderer/HTMLRenderer.php';
|
||||
break;
|
||||
|
||||
case 'text':
|
||||
include_once 'PHP/PMD/Renderer/TextRenderer.php';
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new BuildException("Formatter '" . $this->type . "' not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the formatter type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether to write formatter results to file or not.
|
||||
*
|
||||
* @param boolean $useFile True or false.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUseFile($useFile)
|
||||
{
|
||||
$this->useFile = (boolean) $useFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether to write formatter results to file or not.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getUseFile()
|
||||
{
|
||||
return $this->useFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the output file for the formatter results.
|
||||
*
|
||||
* @param PhingFile $outfile The output file
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setOutfile(PhingFile $outfile)
|
||||
{
|
||||
$this->outfile = $outfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the output file.
|
||||
*
|
||||
* @return PhingFile
|
||||
*/
|
||||
public function getOutfile()
|
||||
{
|
||||
return $this->outfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a report renderer instance based on the formatter type.
|
||||
*
|
||||
* @return PHP_PMD_AbstractRenderer
|
||||
* @throws BuildException When the specified renderer does not exist.
|
||||
*/
|
||||
public function getRenderer()
|
||||
{
|
||||
switch ($this->type) {
|
||||
case 'xml':
|
||||
$renderer = new PHP_PMD_Renderer_XMLRenderer();
|
||||
break;
|
||||
|
||||
case 'html':
|
||||
$renderer = new PHP_PMD_Renderer_HTMLRenderer();
|
||||
break;
|
||||
|
||||
case 'text':
|
||||
$renderer = new PHP_PMD_Renderer_TextRenderer();
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new BuildException("PHP_MD renderer '" . $this->type . "' not implemented");
|
||||
}
|
||||
|
||||
// Create a report stream
|
||||
if ($this->getUseFile() === false || $this->getOutfile() === null) {
|
||||
$stream = STDOUT;
|
||||
} else {
|
||||
$stream = fopen($this->getOutfile()->getAbsoluteFile(), 'wb');
|
||||
}
|
||||
|
||||
$renderer->setWriter(new PHP_PMD_Writer_Stream($stream));
|
||||
|
||||
return $renderer;
|
||||
}
|
||||
}
|
297
airtime_mvc/library/phing/tasks/ext/phpmd/PHPMDTask.php
Normal file
297
airtime_mvc/library/phing/tasks/ext/phpmd/PHPMDTask.php
Normal file
|
@ -0,0 +1,297 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: PHPMDTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
|
||||
/**
|
||||
* Runs PHP Mess Detector. Checking PHP files for several potential problems
|
||||
* based on rulesets.
|
||||
*
|
||||
* @package phing.tasks.ext.phpmd
|
||||
* @author Benjamin Schultz <bschultz@proqrent.de>
|
||||
* @version $Id: PHPMDTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @since 2.4.1
|
||||
*/
|
||||
class PHPMDTask extends Task
|
||||
{
|
||||
/**
|
||||
* A php source code filename or directory
|
||||
*
|
||||
* @var PhingFile
|
||||
*/
|
||||
protected $file = null;
|
||||
|
||||
/**
|
||||
* All fileset objects assigned to this task
|
||||
*
|
||||
* @var array<FileSet>
|
||||
*/
|
||||
protected $filesets = array();
|
||||
|
||||
/**
|
||||
* The rule-set filenames or identifier.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $rulesets = 'codesize,unusedcode';
|
||||
|
||||
/**
|
||||
* The minimum priority for rules to load.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $minimumPriority = 5;
|
||||
|
||||
/**
|
||||
* List of valid file extensions for analyzed files.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $allowedFileExtensions = array('php');
|
||||
|
||||
/**
|
||||
* List of exclude directory patterns.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $ignorePatterns = array('.git', '.svn', 'CVS', '.bzr', '.hg');
|
||||
|
||||
/**
|
||||
* The format for the report
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $format = 'text';
|
||||
|
||||
/**
|
||||
* Formatter elements.
|
||||
*
|
||||
* @var array<PHPMDFormatterElement>
|
||||
*/
|
||||
protected $formatters = array();
|
||||
|
||||
/**
|
||||
* Load the necessary environment for running PHPMD.
|
||||
*
|
||||
* @throws BuildException - if the phpmd classes can't be loaded.
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
/**
|
||||
* Determine PHPMD version number
|
||||
*/
|
||||
@include_once 'PHP/PMD.php';
|
||||
|
||||
if (! class_exists('PHP_PMD')) {
|
||||
throw new BuildException(
|
||||
'PHPMDTask depends on PHPMD being installed and on include_path.',
|
||||
$this->getLocation()
|
||||
);
|
||||
}
|
||||
|
||||
/*$version = PHP_PMD::VERSION;
|
||||
|
||||
if (version_compare($version, '0.2.1') < 0) {
|
||||
throw new BuildException(
|
||||
"PHPMDTask requires PHPMD version >= 0.2.1",
|
||||
$this->getLocation()
|
||||
);
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Other dependencies that should only be loaded when class is actually used.
|
||||
*/
|
||||
require_once 'phing/tasks/ext/phpmd/PHPMDFormatterElement.php';
|
||||
require_once 'PHP/PMD/AbstractRule.php';
|
||||
|
||||
$this->minimumPriority = PHP_PMD_AbstractRule::LOWEST_PRIORITY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the input source file or directory.
|
||||
*
|
||||
* @param PhingFile $file The input source file or directory.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setFile(PhingFile $file)
|
||||
{
|
||||
$this->file = $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Nested creator, adds a set of files (nested fileset attribute).
|
||||
*
|
||||
* @return FileSet The created fileset object
|
||||
*/
|
||||
public function createFileSet()
|
||||
{
|
||||
$num = array_push($this->filesets, new FileSet());
|
||||
return $this->filesets[$num-1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the minimum rule priority.
|
||||
*
|
||||
* @param integer $minimumPriority Minimum rule priority.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setMinimumPriority($minimumPriority)
|
||||
{
|
||||
$this->minimumPriority = $minimumPriority;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the rule-sets.
|
||||
*
|
||||
* @param string $ruleSetFileNames Comma-separated string of rule-set filenames
|
||||
* or identifier.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setRulesets($ruleSetFileNames)
|
||||
{
|
||||
$this->rulesets = $ruleSetFileNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a list of filename extensions for valid php source code files.
|
||||
*
|
||||
* @param string $fileExtensions List of valid file extensions without leading dot.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setAllowedFileExtensions($fileExtensions)
|
||||
{
|
||||
$this->allowedFileExtensions = array();
|
||||
|
||||
$token = ' ,;';
|
||||
$ext = strtok($fileExtensions, $token);
|
||||
|
||||
while ($ext !== false) {
|
||||
$this->allowedFileExtensions[] = $ext;
|
||||
$ext = strtok($token);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a list of ignore patterns that is used to exclude directories from
|
||||
* the source analysis.
|
||||
*
|
||||
* @param string $ignorePatterns List of ignore patterns.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setIgnorePatterns($ignorePatterns)
|
||||
{
|
||||
$this->ignorePatterns = array();
|
||||
|
||||
$token = ' ,;';
|
||||
$pattern = strtok($ignorePatterns, $token);
|
||||
|
||||
while ($pattern !== false) {
|
||||
$this->ignorePatterns[] = $pattern;
|
||||
$pattern = strtok($token);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create object for nested formatter element.
|
||||
*
|
||||
* @return PHPMDFormatterElement
|
||||
*/
|
||||
public function createFormatter()
|
||||
{
|
||||
$num = array_push($this->formatters, new PHPMDFormatterElement($this));
|
||||
return $this->formatters[$num-1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes PHPMD against PhingFile or a FileSet
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function main()
|
||||
{
|
||||
if (!isset($this->file) and count($this->filesets) == 0) {
|
||||
throw new BuildException("Missing either a nested fileset or attribute 'file' set");
|
||||
}
|
||||
|
||||
if (count($this->formatters) == 0) {
|
||||
// turn legacy format attribute into formatter
|
||||
$fmt = new PHPMDFormatterElement();
|
||||
$fmt->setType($this->format);
|
||||
$fmt->setUseFile(false);
|
||||
$this->formatters[] = $fmt;
|
||||
}
|
||||
|
||||
$reportRenderers = array();
|
||||
|
||||
foreach ($this->formatters as $fe) {
|
||||
if ($fe->getType() == '') {
|
||||
throw new BuildException("Formatter missing required 'type' attribute.");
|
||||
}
|
||||
if ($fe->getUsefile() && $fe->getOutfile() === null) {
|
||||
throw new BuildException("Formatter requires 'outfile' attribute when 'useFile' is true.");
|
||||
}
|
||||
|
||||
$reportRenderers[] = $fe->getRenderer();
|
||||
}
|
||||
|
||||
// Create a rule set factory
|
||||
$ruleSetFactory = new PHP_PMD_RuleSetFactory();
|
||||
$ruleSetFactory->setMinimumPriority($this->minimumPriority);
|
||||
|
||||
$phpmd = new PHP_PMD();
|
||||
|
||||
$phpmd->setFileExtensions($this->allowedFileExtensions);
|
||||
$phpmd->setIgnorePattern($this->ignorePatterns);
|
||||
|
||||
$filesToParse = array();
|
||||
|
||||
if ($this->file instanceof PhingFile) {
|
||||
$filesToParse[] = $this->file->getPath();
|
||||
} else {
|
||||
// append any files in filesets
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$inputPath = implode(',', $filesToParse);
|
||||
|
||||
$this->log('Processing files...');
|
||||
|
||||
$phpmd->processFiles(
|
||||
$inputPath,
|
||||
$this->rulesets,
|
||||
$reportRenderers,
|
||||
$ruleSetFactory
|
||||
);
|
||||
|
||||
$this->log('Finished processing files');
|
||||
}
|
||||
}
|
207
airtime_mvc/library/phing/tasks/ext/phpunit/BatchTest.php
Normal file
207
airtime_mvc/library/phing/tasks/ext/phpunit/BatchTest.php
Normal file
|
@ -0,0 +1,207 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: BatchTest.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/types/FileSet.php';
|
||||
|
||||
/**
|
||||
* Scans a list of files given by the fileset attribute, extracts valid test cases
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: BatchTest.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.phpunit
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class BatchTest
|
||||
{
|
||||
/** the list of filesets containing the testcase filename rules */
|
||||
private $filesets = array();
|
||||
|
||||
/** the reference to the project */
|
||||
private $project = NULL;
|
||||
|
||||
/** the classpath to use with Phing::__import() calls */
|
||||
private $classpath = NULL;
|
||||
|
||||
/** names of classes to exclude */
|
||||
private $excludeClasses = array();
|
||||
|
||||
/** name of the batchtest/suite */
|
||||
protected $name = "Phing Batchtest";
|
||||
|
||||
/**
|
||||
* Create a new batchtest instance
|
||||
*
|
||||
* @param Project the project it depends on.
|
||||
*/
|
||||
public function __construct(Project $project)
|
||||
{
|
||||
$this->project = $project;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the batchtest/suite
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the classes to exclude
|
||||
*/
|
||||
public function setExclude($exclude)
|
||||
{
|
||||
$this->excludeClasses = explode(" ", $exclude);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the classpath
|
||||
*/
|
||||
public function setClasspath(Path $classpath)
|
||||
{
|
||||
if ($this->classpath === null)
|
||||
{
|
||||
$this->classpath = $classpath;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->classpath->append($classpath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Path object
|
||||
*/
|
||||
public function createClasspath()
|
||||
{
|
||||
$this->classpath = new Path();
|
||||
return $this->classpath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the classpath
|
||||
*/
|
||||
public function getClasspath()
|
||||
{
|
||||
return $this->classpath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new fileset containing the XML results to aggregate
|
||||
*
|
||||
* @param FileSet the new fileset containing XML results.
|
||||
*/
|
||||
public function addFileSet(FileSet $fileset)
|
||||
{
|
||||
$this->filesets[] = $fileset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate over all filesets and return the filename of all files.
|
||||
*
|
||||
* @return array an array of filenames
|
||||
*/
|
||||
private function getFilenames()
|
||||
{
|
||||
$filenames = array();
|
||||
|
||||
foreach ($this->filesets as $fileset)
|
||||
{
|
||||
$ds = $fileset->getDirectoryScanner($this->project);
|
||||
$ds->scan();
|
||||
|
||||
$files = $ds->getIncludedFiles();
|
||||
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$filenames[] = $ds->getBaseDir() . "/" . $file;
|
||||
}
|
||||
}
|
||||
|
||||
return $filenames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks wheter $input is a PHPUnit Test
|
||||
*/
|
||||
private function isTestCase($input)
|
||||
{
|
||||
return is_subclass_of($input, 'PHPUnit_Framework_TestCase') || is_subclass_of($input, 'PHPUnit_Framework_TestSuite');
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters an array of classes, removes all classes that are not test cases or test suites,
|
||||
* or classes that are declared abstract
|
||||
*/
|
||||
private function filterTests($input)
|
||||
{
|
||||
$reflect = new ReflectionClass($input);
|
||||
|
||||
return $this->isTestCase($input) && (!$reflect->isAbstract());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of test cases and test suites that are declared
|
||||
* by the files included by the filesets
|
||||
*
|
||||
* @return array an array of tests.
|
||||
*/
|
||||
protected function elements()
|
||||
{
|
||||
$filenames = $this->getFilenames();
|
||||
|
||||
$declaredClasses = array();
|
||||
|
||||
foreach ($filenames as $filename)
|
||||
{
|
||||
$definedClasses = PHPUnitUtil::getDefinedClasses($filename, $this->classpath);
|
||||
|
||||
foreach($definedClasses as $definedClass) {
|
||||
$this->project->log("(PHPUnit) Adding $definedClass (from $filename) to tests.", Project::MSG_DEBUG);
|
||||
}
|
||||
|
||||
$declaredClasses = array_merge($declaredClasses, $definedClasses);
|
||||
}
|
||||
|
||||
$elements = array_filter($declaredClasses, array($this, "filterTests"));
|
||||
|
||||
return $elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a testsuite containing all the tests in this batch
|
||||
*
|
||||
* @return PHPUnit_Framework_TestSuite
|
||||
*/
|
||||
public function getTestSuite()
|
||||
{
|
||||
$suite = new PHPUnit_Framework_TestSuite($this->name);
|
||||
|
||||
foreach ($this->elements() as $test)
|
||||
{
|
||||
$testClass = new ReflectionClass($test);
|
||||
|
||||
$suite->addTestSuite($testClass);
|
||||
}
|
||||
|
||||
return $suite;
|
||||
}
|
||||
}
|
178
airtime_mvc/library/phing/tasks/ext/phpunit/FormatterElement.php
Normal file
178
airtime_mvc/library/phing/tasks/ext/phpunit/FormatterElement.php
Normal file
|
@ -0,0 +1,178 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: FormatterElement.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/system/io/PhingFile.php';
|
||||
|
||||
/**
|
||||
* A wrapper for the implementations of PHPUnit2ResultFormatter.
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: FormatterElement.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.phpunit
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class FormatterElement
|
||||
{
|
||||
protected $formatter = NULL;
|
||||
|
||||
protected $type = "";
|
||||
|
||||
protected $useFile = true;
|
||||
|
||||
protected $toDir = ".";
|
||||
|
||||
protected $outfile = "";
|
||||
|
||||
protected $parent = NULL;
|
||||
|
||||
/**
|
||||
* Sets parent task
|
||||
* @param Task $parent Calling Task
|
||||
*/
|
||||
public function setParent($parent)
|
||||
{
|
||||
$this->parent = $parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a specific formatter type
|
||||
* @param string $type
|
||||
*/
|
||||
public function setType($type)
|
||||
{
|
||||
$this->type = $type;
|
||||
|
||||
if ($this->type == "summary")
|
||||
{
|
||||
require_once 'phing/tasks/ext/phpunit/formatter/SummaryPHPUnitResultFormatter.php';
|
||||
$this->formatter = new SummaryPHPUnitResultFormatter($this->parent);
|
||||
}
|
||||
else
|
||||
if ($this->type == "clover")
|
||||
{
|
||||
require_once 'phing/tasks/ext/phpunit/formatter/CloverPHPUnitResultFormatter.php';
|
||||
$this->formatter = new CloverPHPUnitResultFormatter($this->parent);
|
||||
}
|
||||
else
|
||||
if ($this->type == "xml")
|
||||
{
|
||||
require_once 'phing/tasks/ext/phpunit/formatter/XMLPHPUnitResultFormatter.php';
|
||||
$this->formatter = new XMLPHPUnitResultFormatter($this->parent);
|
||||
}
|
||||
else
|
||||
if ($this->type == "plain")
|
||||
{
|
||||
require_once 'phing/tasks/ext/phpunit/formatter/PlainPHPUnitResultFormatter.php';
|
||||
$this->formatter = new PlainPHPUnitResultFormatter($this->parent);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BuildException("Formatter '" . $this->type . "' not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a specific formatter class
|
||||
*/
|
||||
public function setClassName($className)
|
||||
{
|
||||
$classNameNoDot = Phing::import($className);
|
||||
|
||||
$this->formatter = new $classNameNoDot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to store formatting results in a file
|
||||
*/
|
||||
public function setUseFile($useFile)
|
||||
{
|
||||
$this->useFile = $useFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether to store formatting results in a file
|
||||
*/
|
||||
public function getUseFile()
|
||||
{
|
||||
return $this->useFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets output directory
|
||||
* @param string $toDir
|
||||
*/
|
||||
public function setToDir($toDir)
|
||||
{
|
||||
$this->toDir = $toDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns output directory
|
||||
* @return string
|
||||
*/
|
||||
public function getToDir()
|
||||
{
|
||||
return $this->toDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets output filename
|
||||
* @param string $outfile
|
||||
*/
|
||||
public function setOutfile($outfile)
|
||||
{
|
||||
$this->outfile = $outfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns output filename
|
||||
* @return string
|
||||
*/
|
||||
public function getOutfile()
|
||||
{
|
||||
if ($this->outfile)
|
||||
{
|
||||
return $this->outfile;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->formatter->getPreferredOutfile() . $this->getExtension();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns extension
|
||||
* @return string
|
||||
*/
|
||||
public function getExtension()
|
||||
{
|
||||
return $this->formatter->getExtension();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns formatter object
|
||||
* @return PHPUnitResultFormatter
|
||||
*/
|
||||
public function getFormatter()
|
||||
{
|
||||
return $this->formatter;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,213 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: PHPUnitReportTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
require_once 'phing/system/io/PhingFile.php';
|
||||
require_once 'phing/system/io/FileWriter.php';
|
||||
require_once 'phing/util/ExtendedFileStream.php';
|
||||
|
||||
/**
|
||||
* Transform a PHPUnit xml report using XSLT.
|
||||
* This transformation generates an html report in either framed or non-framed
|
||||
* style. The non-framed style is convenient to have a concise report via mail,
|
||||
* the framed report is much more convenient if you want to browse into
|
||||
* different packages or testcases since it is a Javadoc like report.
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: PHPUnitReportTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.phpunit
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class PHPUnitReportTask extends Task
|
||||
{
|
||||
private $format = "noframes";
|
||||
private $styleDir = "";
|
||||
private $toDir = "";
|
||||
|
||||
/** the directory where the results XML can be found */
|
||||
private $inFile = "testsuites.xml";
|
||||
|
||||
/**
|
||||
* Set the filename of the XML results file to use.
|
||||
*/
|
||||
public function setInFile($inFile)
|
||||
{
|
||||
$this->inFile = $inFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the format of the generated report. Must be noframes or frames.
|
||||
*/
|
||||
public function setFormat($format)
|
||||
{
|
||||
$this->format = $format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the directory where the stylesheets are located.
|
||||
*/
|
||||
public function setStyleDir($styleDir)
|
||||
{
|
||||
$this->styleDir = $styleDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the directory where the files resulting from the
|
||||
* transformation should be written to.
|
||||
*/
|
||||
public function setToDir($toDir)
|
||||
{
|
||||
$this->toDir = $toDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path to the XSL stylesheet
|
||||
*/
|
||||
protected function getStyleSheet()
|
||||
{
|
||||
$xslname = "phpunit-" . $this->format . ".xsl";
|
||||
|
||||
if ($this->styleDir)
|
||||
{
|
||||
$file = new PhingFile($this->styleDir, $xslname);
|
||||
}
|
||||
else
|
||||
{
|
||||
$path = Phing::getResourcePath("phing/etc/$xslname");
|
||||
|
||||
if ($path === NULL)
|
||||
{
|
||||
$path = Phing::getResourcePath("etc/$xslname");
|
||||
|
||||
if ($path === NULL)
|
||||
{
|
||||
throw new BuildException("Could not find $xslname in resource path");
|
||||
}
|
||||
}
|
||||
|
||||
$file = new PhingFile($path);
|
||||
}
|
||||
|
||||
if (!$file->exists())
|
||||
{
|
||||
throw new BuildException("Could not find file " . $file->getPath());
|
||||
}
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the DOM document
|
||||
*/
|
||||
protected function transform(DOMDocument $document)
|
||||
{
|
||||
$dir = new PhingFile($this->toDir);
|
||||
|
||||
if (!$dir->exists())
|
||||
{
|
||||
throw new BuildException("Directory '" . $this->toDir . "' does not exist");
|
||||
}
|
||||
|
||||
$xslfile = $this->getStyleSheet();
|
||||
|
||||
$xsl = new DOMDocument();
|
||||
$xsl->load($xslfile->getAbsolutePath());
|
||||
|
||||
$proc = new XSLTProcessor();
|
||||
$proc->importStyleSheet($xsl);
|
||||
|
||||
if ($this->format == "noframes")
|
||||
{
|
||||
$writer = new FileWriter(new PhingFile($this->toDir, "phpunit-noframes.html"));
|
||||
$writer->write($proc->transformToXML($document));
|
||||
$writer->close();
|
||||
}
|
||||
else
|
||||
{
|
||||
ExtendedFileStream::registerStream();
|
||||
|
||||
// no output for the framed report
|
||||
// it's all done by extension...
|
||||
$dir = new PhingFile($this->toDir);
|
||||
$proc->setParameter('', 'output.dir', $dir->toString());
|
||||
$proc->transformToXML($document);
|
||||
|
||||
ExtendedFileStream::unregisterStream();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixes DOM document tree:
|
||||
* - adds package="default" to 'testsuite' elements without
|
||||
* package attribute
|
||||
* - removes outer 'testsuite' container(s)
|
||||
*/
|
||||
protected function fixDocument(DOMDocument $document)
|
||||
{
|
||||
$rootElement = $document->firstChild;
|
||||
|
||||
$xp = new DOMXPath($document);
|
||||
|
||||
$nodes = $xp->query("/testsuites/testsuite");
|
||||
|
||||
foreach ($nodes as $node)
|
||||
{
|
||||
$children = $xp->query("./testsuite", $node);
|
||||
|
||||
foreach ($children as $child)
|
||||
{
|
||||
if (!$child->hasAttribute('package'))
|
||||
{
|
||||
$child->setAttribute('package', 'default');
|
||||
}
|
||||
|
||||
$rootElement->appendChild($child);
|
||||
}
|
||||
|
||||
$rootElement->removeChild($node);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the task
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
if (!class_exists('XSLTProcessor')) {
|
||||
throw new BuildException("PHPUnitReportTask requires the XSL extension");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The main entry point
|
||||
*
|
||||
* @throws BuildException
|
||||
*/
|
||||
public function main()
|
||||
{
|
||||
$testSuitesDoc = new DOMDocument();
|
||||
$testSuitesDoc->load($this->inFile);
|
||||
|
||||
$this->fixDocument($testSuitesDoc);
|
||||
|
||||
$this->transform($testSuitesDoc);
|
||||
}
|
||||
}
|
365
airtime_mvc/library/phing/tasks/ext/phpunit/PHPUnitTask.php
Normal file
365
airtime_mvc/library/phing/tasks/ext/phpunit/PHPUnitTask.php
Normal file
|
@ -0,0 +1,365 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: PHPUnitTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
require_once 'phing/system/io/PhingFile.php';
|
||||
require_once 'phing/system/io/Writer.php';
|
||||
require_once 'phing/util/LogWriter.php';
|
||||
|
||||
/**
|
||||
* Runs PHPUnit tests.
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: PHPUnitTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.phpunit
|
||||
* @see BatchTest
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class PHPUnitTask extends Task
|
||||
{
|
||||
private $batchtests = array();
|
||||
private $formatters = array();
|
||||
private $bootstrap = "";
|
||||
private $haltonerror = false;
|
||||
private $haltonfailure = false;
|
||||
private $haltonincomplete = false;
|
||||
private $haltonskipped = false;
|
||||
private $errorproperty;
|
||||
private $failureproperty;
|
||||
private $incompleteproperty;
|
||||
private $skippedproperty;
|
||||
private $printsummary = false;
|
||||
private $testfailed = false;
|
||||
private $testfailuremessage = "";
|
||||
private $codecoverage = false;
|
||||
private $groups = array();
|
||||
private $excludeGroups = array();
|
||||
private $usecustomerrorhandler = true;
|
||||
|
||||
/**
|
||||
* Initialize Task.
|
||||
* This method includes any necessary PHPUnit2 libraries and triggers
|
||||
* appropriate error if they cannot be found. This is not done in header
|
||||
* because we may want this class to be loaded w/o triggering an error.
|
||||
*/
|
||||
public function init() {
|
||||
if (version_compare(PHP_VERSION, '5.0.3') < 0)
|
||||
{
|
||||
throw new BuildException("PHPUnitTask requires PHP version >= 5.0.3", $this->getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine PHPUnit version number
|
||||
*/
|
||||
@include_once 'PHPUnit/Runner/Version.php';
|
||||
|
||||
$version = PHPUnit_Runner_Version::id();
|
||||
|
||||
if (version_compare($version, '3.2.0') < 0)
|
||||
{
|
||||
throw new BuildException("PHPUnitTask requires PHPUnit version >= 3.2.0", $this->getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Other dependencies that should only be loaded when class is actually used.
|
||||
*/
|
||||
require_once 'phing/tasks/ext/phpunit/PHPUnitTestRunner.php';
|
||||
require_once 'phing/tasks/ext/phpunit/BatchTest.php';
|
||||
require_once 'phing/tasks/ext/phpunit/FormatterElement.php';
|
||||
|
||||
/**
|
||||
* Add some defaults to the PHPUnit filter
|
||||
*/
|
||||
$pwd = dirname(__FILE__);
|
||||
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
require_once 'PHPUnit/Util/Filter.php';
|
||||
|
||||
// point PHPUnit_MAIN_METHOD define to non-existing method
|
||||
if (!defined('PHPUnit_MAIN_METHOD'))
|
||||
{
|
||||
define('PHPUnit_MAIN_METHOD', 'PHPUnitTask::undefined');
|
||||
}
|
||||
|
||||
$path = realpath($pwd . '/../../../');
|
||||
if (version_compare($version, '3.5.0') >= 0) {
|
||||
PHP_CodeCoverage_Filter::getInstance()->addDirectoryToBlacklist($path);
|
||||
} else {
|
||||
PHPUnit_Util_Filter::addDirectoryToFilter($path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of a bootstrap file that is run before
|
||||
* executing the tests
|
||||
*
|
||||
* @param string $bootstrap the name of the bootstrap file
|
||||
*/
|
||||
public function setBootstrap($bootstrap)
|
||||
{
|
||||
$this->bootstrap = $bootstrap;
|
||||
}
|
||||
|
||||
public function setErrorproperty($value)
|
||||
{
|
||||
$this->errorproperty = $value;
|
||||
}
|
||||
|
||||
public function setFailureproperty($value)
|
||||
{
|
||||
$this->failureproperty = $value;
|
||||
}
|
||||
|
||||
public function setIncompleteproperty($value)
|
||||
{
|
||||
$this->incompleteproperty = $value;
|
||||
}
|
||||
|
||||
public function setSkippedproperty($value)
|
||||
{
|
||||
$this->skippedproperty = $value;
|
||||
}
|
||||
|
||||
public function setHaltonerror($value)
|
||||
{
|
||||
$this->haltonerror = $value;
|
||||
}
|
||||
|
||||
public function setHaltonfailure($value)
|
||||
{
|
||||
$this->haltonfailure = $value;
|
||||
}
|
||||
|
||||
public function getHaltonfailure()
|
||||
{
|
||||
return $this->haltonfailure;
|
||||
}
|
||||
|
||||
public function setHaltonincomplete($value)
|
||||
{
|
||||
$this->haltonincomplete = $value;
|
||||
}
|
||||
|
||||
public function getHaltonincomplete()
|
||||
{
|
||||
return $this->haltonincomplete;
|
||||
}
|
||||
|
||||
public function setHaltonskipped($value)
|
||||
{
|
||||
$this->haltonskipped = $value;
|
||||
}
|
||||
|
||||
public function getHaltonskipped()
|
||||
{
|
||||
return $this->haltonskipped;
|
||||
}
|
||||
|
||||
public function setPrintsummary($printsummary)
|
||||
{
|
||||
$this->printsummary = $printsummary;
|
||||
}
|
||||
|
||||
public function setCodecoverage($codecoverage)
|
||||
{
|
||||
$this->codecoverage = $codecoverage;
|
||||
}
|
||||
|
||||
public function setUseCustomErrorHandler($usecustomerrorhandler)
|
||||
{
|
||||
$this->usecustomerrorhandler = $usecustomerrorhandler;
|
||||
}
|
||||
|
||||
public function setGroups($groups)
|
||||
{
|
||||
$token = ' ,;';
|
||||
$this->groups = array();
|
||||
$tok = strtok($groups, $token);
|
||||
while ($tok !== false) {
|
||||
$this->groups[] = $tok;
|
||||
$tok = strtok($token);
|
||||
}
|
||||
}
|
||||
|
||||
public function setExcludeGroups($excludeGroups)
|
||||
{
|
||||
$token = ' ,;';
|
||||
$this->excludeGroups = array();
|
||||
$tok = strtok($excludeGroups, $token);
|
||||
while ($tok !== false) {
|
||||
$this->excludeGroups[] = $tok;
|
||||
$tok = strtok($token);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new formatter to all tests of this task.
|
||||
*
|
||||
* @param FormatterElement formatter element
|
||||
*/
|
||||
public function addFormatter(FormatterElement $fe)
|
||||
{
|
||||
$fe->setParent($this);
|
||||
$this->formatters[] = $fe;
|
||||
}
|
||||
|
||||
/**
|
||||
* The main entry point
|
||||
*
|
||||
* @throws BuildException
|
||||
*/
|
||||
public function main()
|
||||
{
|
||||
if ($this->codecoverage && !extension_loaded('xdebug'))
|
||||
{
|
||||
throw new Exception("PHPUnitTask depends on Xdebug being installed to gather code coverage information.");
|
||||
}
|
||||
|
||||
if ($this->printsummary)
|
||||
{
|
||||
$fe = new FormatterElement();
|
||||
$fe->setParent($this);
|
||||
$fe->setType("summary");
|
||||
$fe->setUseFile(false);
|
||||
$this->formatters[] = $fe;
|
||||
}
|
||||
|
||||
if ($this->bootstrap)
|
||||
{
|
||||
require_once $this->bootstrap;
|
||||
}
|
||||
|
||||
foreach ($this->formatters as $fe)
|
||||
{
|
||||
$formatter = $fe->getFormatter();
|
||||
|
||||
if ($fe->getUseFile())
|
||||
{
|
||||
$destFile = new PhingFile($fe->getToDir(), $fe->getOutfile());
|
||||
|
||||
$writer = new FileWriter($destFile->getAbsolutePath());
|
||||
|
||||
$formatter->setOutput($writer);
|
||||
}
|
||||
else
|
||||
{
|
||||
$formatter->setOutput($this->getDefaultOutput());
|
||||
}
|
||||
|
||||
$formatter->startTestRun();
|
||||
}
|
||||
|
||||
foreach ($this->batchtests as $batchtest)
|
||||
{
|
||||
$this->execute($batchtest->getTestSuite());
|
||||
}
|
||||
|
||||
foreach ($this->formatters as $fe)
|
||||
{
|
||||
$formatter = $fe->getFormatter();
|
||||
$formatter->endTestRun();
|
||||
}
|
||||
|
||||
if ($this->testfailed)
|
||||
{
|
||||
throw new BuildException($this->testfailuremessage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws BuildException
|
||||
*/
|
||||
protected function execute($suite)
|
||||
{
|
||||
$runner = new PHPUnitTestRunner($this->project, $this->groups, $this->excludeGroups);
|
||||
|
||||
$runner->setCodecoverage($this->codecoverage);
|
||||
$runner->setUseCustomErrorHandler($this->usecustomerrorhandler);
|
||||
|
||||
foreach ($this->formatters as $fe)
|
||||
{
|
||||
$formatter = $fe->getFormatter();
|
||||
|
||||
$runner->addFormatter($formatter);
|
||||
}
|
||||
|
||||
$runner->run($suite);
|
||||
|
||||
$retcode = $runner->getRetCode();
|
||||
|
||||
if ($retcode == PHPUnitTestRunner::ERRORS) {
|
||||
if ($this->errorproperty) {
|
||||
$this->project->setNewProperty($this->errorproperty, true);
|
||||
}
|
||||
if ($this->haltonerror) {
|
||||
$this->testfailed = true;
|
||||
$this->testfailuremessage = $runner->getLastFailureMessage();
|
||||
}
|
||||
} elseif ($retcode == PHPUnitTestRunner::FAILURES) {
|
||||
if ($this->failureproperty) {
|
||||
$this->project->setNewProperty($this->failureproperty, true);
|
||||
}
|
||||
|
||||
if ($this->haltonfailure) {
|
||||
$this->testfailed = true;
|
||||
$this->testfailuremessage = $runner->getLastFailureMessage();
|
||||
}
|
||||
} elseif ($retcode == PHPUnitTestRunner::INCOMPLETES) {
|
||||
if ($this->incompleteproperty) {
|
||||
$this->project->setNewProperty($this->incompleteproperty, true);
|
||||
}
|
||||
|
||||
if ($this->haltonincomplete) {
|
||||
$this->testfailed = true;
|
||||
$this->testfailuremessage = $runner->getLastFailureMessage();
|
||||
}
|
||||
} elseif ($retcode == PHPUnitTestRunner::SKIPPED) {
|
||||
if ($this->skippedproperty) {
|
||||
$this->project->setNewProperty($this->skippedproperty, true);
|
||||
}
|
||||
|
||||
if ($this->haltonskipped) {
|
||||
$this->testfailed = true;
|
||||
$this->testfailuremessage = $runner->getLastFailureMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function getDefaultOutput()
|
||||
{
|
||||
return new LogWriter($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a set of tests based on pattern matching.
|
||||
*
|
||||
* @return BatchTest a new instance of a batch test.
|
||||
*/
|
||||
public function createBatchTest()
|
||||
{
|
||||
$batchtest = new BatchTest($this->getProject());
|
||||
|
||||
$this->batchtests[] = $batchtest;
|
||||
|
||||
return $batchtest;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,302 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: PHPUnitTestRunner.php 906 2010-10-05 18:01:43Z mrook $
|
||||
*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
// phpunit 3.5 ships with autoloader
|
||||
// @todo - find out sane model for Phing and PHPUnit autoloaders/hooks co-existense
|
||||
if (version_compare(PHPUnit_Runner_Version::id(), '3.5.0') >=0) {
|
||||
require_once 'PHPUnit/Autoload.php';
|
||||
}
|
||||
require_once 'PHPUnit/Util/ErrorHandler.php';
|
||||
require_once 'PHPUnit/Util/Filter.php';
|
||||
require_once 'phing/tasks/ext/coverage/CoverageMerger.php';
|
||||
require_once 'phing/system/util/Timer.php';
|
||||
|
||||
/**
|
||||
* Simple Testrunner for PHPUnit that runs all tests of a testsuite.
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: PHPUnitTestRunner.php 906 2010-10-05 18:01:43Z mrook $
|
||||
* @package phing.tasks.ext.phpunit
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class PHPUnitTestRunner extends PHPUnit_Runner_BaseTestRunner implements PHPUnit_Framework_TestListener
|
||||
{
|
||||
const SUCCESS = 0;
|
||||
const FAILURES = 1;
|
||||
const ERRORS = 2;
|
||||
const INCOMPLETES = 3;
|
||||
const SKIPPED = 4;
|
||||
|
||||
private $retCode = 0;
|
||||
private $lastFailureMessage = "";
|
||||
private $formatters = array();
|
||||
|
||||
private $codecoverage = false;
|
||||
|
||||
private $project = NULL;
|
||||
|
||||
private $groups = array();
|
||||
private $excludeGroups = array();
|
||||
|
||||
private $useCustomErrorHandler = true;
|
||||
|
||||
public function __construct(Project $project, $groups = array(), $excludeGroups = array())
|
||||
{
|
||||
$this->project = $project;
|
||||
$this->groups = $groups;
|
||||
$this->excludeGroups = $excludeGroups;
|
||||
$this->retCode = self::SUCCESS;
|
||||
}
|
||||
|
||||
public function setCodecoverage($codecoverage)
|
||||
{
|
||||
$this->codecoverage = $codecoverage;
|
||||
}
|
||||
|
||||
public function setUseCustomErrorHandler($useCustomErrorHandler)
|
||||
{
|
||||
$this->useCustomErrorHandler = $useCustomErrorHandler;
|
||||
}
|
||||
|
||||
public function addFormatter($formatter)
|
||||
{
|
||||
$this->formatters[] = $formatter;
|
||||
}
|
||||
|
||||
public static function handleError($level, $message, $file, $line)
|
||||
{
|
||||
$isFiltered = false;
|
||||
if (version_compare(PHPUnit_Runner_Version::id(), '3.5.0') >=0) {
|
||||
$isFiltered = PHP_CodeCoverage::getInstance()->filter()->isFiltered(
|
||||
$file, array(), true
|
||||
);
|
||||
} else {
|
||||
$isFiltered = PHPUnit_Util_Filter::isFiltered($file, true, true);
|
||||
}
|
||||
if (!$isFiltered) {
|
||||
return PHPUnit_Util_ErrorHandler::handleError($level, $message, $file, $line);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a test
|
||||
*/
|
||||
public function run(PHPUnit_Framework_TestSuite $suite)
|
||||
{
|
||||
$res = new PHPUnit_Framework_TestResult();
|
||||
|
||||
if ($this->codecoverage)
|
||||
{
|
||||
$res->collectCodeCoverageInformation(TRUE);
|
||||
}
|
||||
|
||||
$res->addListener($this);
|
||||
|
||||
foreach ($this->formatters as $formatter)
|
||||
{
|
||||
$res->addListener($formatter);
|
||||
}
|
||||
|
||||
/* Set PHPUnit error handler */
|
||||
if ($this->useCustomErrorHandler)
|
||||
{
|
||||
$oldErrorHandler = set_error_handler(array('PHPUnitTestRunner', 'handleError'), E_ALL | E_STRICT);
|
||||
}
|
||||
|
||||
$suite->run($res, false, $this->groups, $this->excludeGroups);
|
||||
|
||||
foreach ($this->formatters as $formatter)
|
||||
{
|
||||
$formatter->processResult($res);
|
||||
}
|
||||
|
||||
/* Restore Phing error handler */
|
||||
if ($this->useCustomErrorHandler)
|
||||
{
|
||||
restore_error_handler();
|
||||
}
|
||||
|
||||
if ($this->codecoverage)
|
||||
{
|
||||
$coverage = $res->getCodeCoverage();
|
||||
|
||||
$summary = $coverage->getSummary();
|
||||
|
||||
CoverageMerger::merge($this->project, $summary);
|
||||
}
|
||||
|
||||
if ($res->errorCount() != 0)
|
||||
{
|
||||
$this->retCode = self::ERRORS;
|
||||
}
|
||||
else if ($res->failureCount() != 0)
|
||||
{
|
||||
$this->retCode = self::FAILURES;
|
||||
}
|
||||
else if ($res->notImplementedCount() != 0)
|
||||
{
|
||||
$this->retCode = self::INCOMPLETES;
|
||||
}
|
||||
else if ($res->skippedCount() != 0)
|
||||
{
|
||||
$this->retCode = self::SKIPPED;
|
||||
}
|
||||
}
|
||||
|
||||
public function getRetCode()
|
||||
{
|
||||
return $this->retCode;
|
||||
}
|
||||
|
||||
public function getLastFailureMessage()
|
||||
{
|
||||
return $this->lastFailureMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* An error occurred.
|
||||
*
|
||||
* @param PHPUnit_Framework_Test $test
|
||||
* @param Exception $e
|
||||
* @param float $time
|
||||
*/
|
||||
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
|
||||
{
|
||||
$this->lastFailureMessage = "Test ERROR (" . $test->getName() . "): " . $e->getMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* A failure occurred.
|
||||
*
|
||||
* @param PHPUnit_Framework_Test $test
|
||||
* @param PHPUnit_Framework_AssertionFailedError $e
|
||||
* @param float $time
|
||||
*/
|
||||
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
|
||||
{
|
||||
$this->lastFailureMessage = "Test FAILURE (" . $test->getName() . "): " . $e->getMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Incomplete test.
|
||||
*
|
||||
* @param PHPUnit_Framework_Test $test
|
||||
* @param Exception $e
|
||||
* @param float $time
|
||||
*/
|
||||
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
|
||||
{
|
||||
$this->lastFailureMessage = "Test INCOMPLETE (" . $test->getName() . "): " . $e->getMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Skipped test.
|
||||
*
|
||||
* @param PHPUnit_Framework_Test $test
|
||||
* @param Exception $e
|
||||
* @param float $time
|
||||
* @since Method available since Release 3.0.0
|
||||
*/
|
||||
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
|
||||
{
|
||||
$this->lastFailureMessage = "Test SKIPPED (" . $test->getName() . "): " . $e->getMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* A test started.
|
||||
*
|
||||
* @param string $testName
|
||||
*/
|
||||
public function testStarted($testName)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* A test ended.
|
||||
*
|
||||
* @param string $testName
|
||||
*/
|
||||
public function testEnded($testName)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* A test failed.
|
||||
*
|
||||
* @param integer $status
|
||||
* @param PHPUnit_Framework_Test $test
|
||||
* @param PHPUnit_Framework_AssertionFailedError $e
|
||||
*/
|
||||
public function testFailed($status, PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to define how to handle a failed loading of
|
||||
* a test suite.
|
||||
*
|
||||
* @param string $message
|
||||
*/
|
||||
protected function runFailed($message)
|
||||
{
|
||||
throw new BuildException($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* A test suite started.
|
||||
*
|
||||
* @param PHPUnit_Framework_TestSuite $suite
|
||||
* @since Method available since Release 2.2.0
|
||||
*/
|
||||
public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* A test suite ended.
|
||||
*
|
||||
* @param PHPUnit_Framework_TestSuite $suite
|
||||
* @since Method available since Release 2.2.0
|
||||
*/
|
||||
public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* A test started.
|
||||
*
|
||||
* @param PHPUnit_Framework_Test $test
|
||||
*/
|
||||
public function startTest(PHPUnit_Framework_Test $test)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* A test ended.
|
||||
*
|
||||
* @param PHPUnit_Framework_Test $test
|
||||
* @param float $time
|
||||
*/
|
||||
public function endTest(PHPUnit_Framework_Test $test, $time)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
141
airtime_mvc/library/phing/tasks/ext/phpunit/PHPUnitUtil.php
Normal file
141
airtime_mvc/library/phing/tasks/ext/phpunit/PHPUnitUtil.php
Normal file
|
@ -0,0 +1,141 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: PHPUnitUtil.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Various utility functions
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: PHPUnitUtil.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.phpunit
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class PHPUnitUtil
|
||||
{
|
||||
protected static $definedClasses = array();
|
||||
|
||||
/**
|
||||
* Returns the package of a class as defined in the docblock of the class using @package
|
||||
*
|
||||
* @param string the name of the class
|
||||
* @return string the name of the package
|
||||
*/
|
||||
static function getPackageName($classname)
|
||||
{
|
||||
$reflect = new ReflectionClass($classname);
|
||||
|
||||
if (preg_match('/@package[\s]+([\.\w]+)/', $reflect->getDocComment(), $matches))
|
||||
{
|
||||
return $matches[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
return "default";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the subpackage of a class as defined in the docblock of the class
|
||||
* using @subpackage
|
||||
*
|
||||
* @param string $classname the name of the class
|
||||
*
|
||||
* @author Benjamin Schultz <bschultz@proqrent.de>
|
||||
* @return string|null the name of the subpackage
|
||||
*/
|
||||
public static function getSubpackageName($classname)
|
||||
{
|
||||
$reflect = new ReflectionClass($classname);
|
||||
|
||||
if (preg_match('/@subpackage[\s]+([\.\w]+)/', $reflect->getDocComment(), $matches)) {
|
||||
return $matches[1];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Derives the classname from a filename.
|
||||
* Assumes that there is only one class defined in that particular file, and that
|
||||
* the naming follows the dot-path (Java) notation scheme.
|
||||
*
|
||||
* @param string the filename
|
||||
* @return string the name fo the class
|
||||
*/
|
||||
public static function getClassFromFileName($filename)
|
||||
{
|
||||
$filename = basename($filename);
|
||||
|
||||
$rpos = strrpos($filename, '.');
|
||||
|
||||
if ($rpos != -1)
|
||||
{
|
||||
$filename = substr($filename, 0, $rpos);
|
||||
}
|
||||
|
||||
return $filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string the filename
|
||||
* @param Path optional classpath
|
||||
* @return array list of classes defined in the file
|
||||
*/
|
||||
public static function getDefinedClasses($filename, $classpath = NULL)
|
||||
{
|
||||
$filename = realpath($filename);
|
||||
|
||||
if (!file_exists($filename))
|
||||
{
|
||||
throw new Exception("File '" . $filename . "' does not exist");
|
||||
}
|
||||
|
||||
if (isset(self::$definedClasses[$filename]))
|
||||
{
|
||||
return self::$definedClasses[$filename];
|
||||
}
|
||||
|
||||
Phing::__import($filename, $classpath);
|
||||
|
||||
$declaredClasses = get_declared_classes();
|
||||
|
||||
foreach ($declaredClasses as $classname)
|
||||
{
|
||||
$reflect = new ReflectionClass($classname);
|
||||
|
||||
self::$definedClasses[$reflect->getFilename()][] = $classname;
|
||||
|
||||
if (is_array(self::$definedClasses[$reflect->getFilename()]))
|
||||
{
|
||||
self::$definedClasses[$reflect->getFilename()] = array_unique(self::$definedClasses[$reflect->getFilename()]);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset(self::$definedClasses[$filename]))
|
||||
{
|
||||
return self::$definedClasses[$filename];
|
||||
}
|
||||
else
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: CloverPHPUnitResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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 'PHPUnit/Util/Log/JUnit.php';
|
||||
require_once 'PHPUnit/Util/Log/CodeCoverage/XML/Clover.php';
|
||||
require_once 'phing/tasks/ext/phpunit/formatter/PHPUnitResultFormatter.php';
|
||||
|
||||
/**
|
||||
* Prints Clover XML output of the test
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: CloverPHPUnitResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.formatter
|
||||
* @since 2.4.0
|
||||
*/
|
||||
class CloverPHPUnitResultFormatter extends PHPUnitResultFormatter
|
||||
{
|
||||
/**
|
||||
* @var PHPUnit_Util_Log_CodeCoverage_XML_Clover
|
||||
*/
|
||||
private $clover = NULL;
|
||||
|
||||
/**
|
||||
* @var PHPUnit_Framework_TestResult
|
||||
*/
|
||||
private $result = NULL;
|
||||
|
||||
public function __construct(PHPUnitTask $parentTask)
|
||||
{
|
||||
parent::__construct($parentTask);
|
||||
|
||||
$this->clover = new PHPUnit_Util_Log_CodeCoverage_XML_Clover(null);
|
||||
}
|
||||
|
||||
public function getExtension()
|
||||
{
|
||||
return ".xml";
|
||||
}
|
||||
|
||||
public function getPreferredOutfile()
|
||||
{
|
||||
return "clover-coverage";
|
||||
}
|
||||
|
||||
public function processResult(PHPUnit_Framework_TestResult $result)
|
||||
{
|
||||
$this->result = $result;
|
||||
}
|
||||
|
||||
public function endTestRun()
|
||||
{
|
||||
ob_start();
|
||||
$this->clover->process($this->result);
|
||||
$contents = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
if ($this->out)
|
||||
{
|
||||
$this->out->write($contents);
|
||||
$this->out->close();
|
||||
}
|
||||
|
||||
parent::endTestRun();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,203 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: PHPUnitResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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 'PHPUnit/Framework/TestListener.php';
|
||||
|
||||
require_once 'phing/system/io/Writer.php';
|
||||
|
||||
/**
|
||||
* This abstract class describes classes that format the results of a PHPUnit testrun.
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: PHPUnitResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.phpunit.formatter
|
||||
* @since 2.1.0
|
||||
*/
|
||||
abstract class PHPUnitResultFormatter implements PHPUnit_Framework_TestListener
|
||||
{
|
||||
protected $out = NULL;
|
||||
|
||||
protected $project = NULL;
|
||||
|
||||
private $timers = false;
|
||||
|
||||
private $runCounts = false;
|
||||
|
||||
private $failureCounts = false;
|
||||
|
||||
private $errorCounts = false;
|
||||
|
||||
private $incompleteCounts = false;
|
||||
|
||||
private $skipCounts = false;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param PHPUnitTask $parentTask Calling Task
|
||||
*/
|
||||
public function __construct(PHPUnitTask $parentTask)
|
||||
{
|
||||
$this->project = $parentTask->getProject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the writer the formatter is supposed to write its results to.
|
||||
*/
|
||||
public function setOutput(Writer $out)
|
||||
{
|
||||
$this->out = $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the extension used for this formatter
|
||||
*
|
||||
* @return string the extension
|
||||
*/
|
||||
public function getExtension()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
public function getPreferredOutfile()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
public function processResult(PHPUnit_Framework_TestResult $result)
|
||||
{
|
||||
}
|
||||
|
||||
public function startTestRun()
|
||||
{
|
||||
$this->timers = array($this->getMicrotime());
|
||||
$this->runCounts = array(0);
|
||||
$this->failureCounts = array(0);
|
||||
$this->errorCounts = array(0);
|
||||
$this->incompleteCounts = array(0);
|
||||
$this->skipCounts = array(0);
|
||||
}
|
||||
|
||||
public function endTestRun()
|
||||
{
|
||||
}
|
||||
|
||||
public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
|
||||
{
|
||||
$this->timers[] = $this->getMicrotime();
|
||||
$this->runCounts[] = 0;
|
||||
$this->failureCounts[] = 0;
|
||||
$this->errorCounts[] = 0;
|
||||
$this->incompleteCounts[] = 0;
|
||||
$this->skipCounts[] = 0;
|
||||
}
|
||||
|
||||
public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
|
||||
{
|
||||
$lastRunCount = array_pop($this->runCounts);
|
||||
$this->runCounts[count($this->runCounts) - 1] += $lastRunCount;
|
||||
|
||||
$lastFailureCount = array_pop($this->failureCounts);
|
||||
$this->failureCounts[count($this->failureCounts) - 1] += $lastFailureCount;
|
||||
|
||||
$lastErrorCount = array_pop($this->errorCounts);
|
||||
$this->errorCounts[count($this->errorCounts) - 1] += $lastErrorCount;
|
||||
|
||||
$lastIncompleteCount = array_pop($this->incompleteCounts);
|
||||
$this->incompleteCounts[count($this->incompleteCounts) - 1] += $lastIncompleteCount;
|
||||
|
||||
$lastSkipCount = array_pop($this->skipCounts);
|
||||
$this->skipCounts[count($this->skipCounts) - 1] += $lastSkipCount;
|
||||
|
||||
array_pop($this->timers);
|
||||
}
|
||||
|
||||
public function startTest(PHPUnit_Framework_Test $test)
|
||||
{
|
||||
$this->runCounts[count($this->runCounts) - 1]++;
|
||||
}
|
||||
|
||||
public function endTest(PHPUnit_Framework_Test $test, $time)
|
||||
{
|
||||
}
|
||||
|
||||
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
|
||||
{
|
||||
$this->errorCounts[count($this->errorCounts) - 1]++;
|
||||
}
|
||||
|
||||
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
|
||||
{
|
||||
$this->failureCounts[count($this->failureCounts) - 1]++;
|
||||
}
|
||||
|
||||
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
|
||||
{
|
||||
$this->incompleteCounts[count($this->incompleteCounts) - 1]++;
|
||||
}
|
||||
|
||||
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
|
||||
{
|
||||
$this->skipCounts[count($this->skipCounts) - 1]++;
|
||||
}
|
||||
|
||||
public function getRunCount()
|
||||
{
|
||||
return end($this->runCounts);
|
||||
}
|
||||
|
||||
public function getFailureCount()
|
||||
{
|
||||
return end($this->failureCounts);
|
||||
}
|
||||
|
||||
public function getErrorCount()
|
||||
{
|
||||
return end($this->errorCounts);
|
||||
}
|
||||
|
||||
public function getIncompleteCount()
|
||||
{
|
||||
return end($this->incompleteCounts);
|
||||
}
|
||||
|
||||
public function getSkippedCount()
|
||||
{
|
||||
return end($this->skipCounts);
|
||||
}
|
||||
|
||||
public function getElapsedTime()
|
||||
{
|
||||
if (end($this->timers))
|
||||
{
|
||||
return $this->getMicrotime() - end($this->timers);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private function getMicrotime() {
|
||||
list($usec, $sec) = explode(' ', microtime());
|
||||
return (float)$usec + (float)$sec;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,131 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: PlainPHPUnitResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/tasks/ext/phpunit/formatter/PHPUnitResultFormatter.php';
|
||||
|
||||
/**
|
||||
* Prints plain text output of the test to a specified Writer.
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: PlainPHPUnitResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.phpunit.formatter
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class PlainPHPUnitResultFormatter extends PHPUnitResultFormatter
|
||||
{
|
||||
private $inner = "";
|
||||
|
||||
public function getExtension()
|
||||
{
|
||||
return ".txt";
|
||||
}
|
||||
|
||||
public function getPreferredOutfile()
|
||||
{
|
||||
return "testresults";
|
||||
}
|
||||
|
||||
public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
|
||||
{
|
||||
parent::startTestSuite($suite);
|
||||
|
||||
$this->inner = "";
|
||||
}
|
||||
|
||||
public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
|
||||
{
|
||||
foreach ($suite->tests() as $test)
|
||||
{
|
||||
if ($test instanceof PHPUnit_Framework_TestSuite)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$sb = "Testsuite: " . $suite->getName() . "\n";
|
||||
$sb.= "Tests run: " . $this->getRunCount();
|
||||
$sb.= ", Failures: " . $this->getFailureCount();
|
||||
$sb.= ", Errors: " . $this->getErrorCount();
|
||||
$sb.= ", Incomplete: " . $this->getIncompleteCount();
|
||||
$sb.= ", Skipped: " . $this->getSkippedCount();
|
||||
$sb.= ", Time elapsed: " . sprintf('%0.5f', $this->getElapsedTime()) . " s\n";
|
||||
|
||||
if ($this->out != NULL)
|
||||
{
|
||||
$this->out->write($sb);
|
||||
$this->out->write($this->inner);
|
||||
}
|
||||
|
||||
parent::endTestSuite($suite);
|
||||
}
|
||||
|
||||
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
|
||||
{
|
||||
parent::addError($test, $e, $time);
|
||||
|
||||
$this->formatError("ERROR", $test, $e);
|
||||
}
|
||||
|
||||
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
|
||||
{
|
||||
parent::addFailure($test, $e, $time);
|
||||
$this->formatError("FAILED", $test, $e);
|
||||
}
|
||||
|
||||
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
|
||||
{
|
||||
parent::addIncompleteTest($test, $e, $time);
|
||||
|
||||
$this->formatError("INCOMPLETE", $test);
|
||||
}
|
||||
|
||||
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
|
||||
{
|
||||
parent::addSkippedTest($test, $e, $time);
|
||||
$this->formatError("SKIPPED", $test);
|
||||
}
|
||||
|
||||
private function formatError($type, PHPUnit_Framework_Test $test, Exception $e = null)
|
||||
{
|
||||
if ($test != null)
|
||||
{
|
||||
$this->endTest($test, time());
|
||||
}
|
||||
|
||||
$this->inner.= $test->getName() . " " . $type . "\n";
|
||||
|
||||
if ($e !== null) {
|
||||
$this->inner.= $e->getMessage() . "\n";
|
||||
$this->inner.= PHPUnit_Util_Filter::getFilteredStackTrace($e, false) . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
public function endTestRun()
|
||||
{
|
||||
parent::endTestRun();
|
||||
|
||||
if ($this->out != NULL)
|
||||
{
|
||||
$this->out->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: SummaryPHPUnitResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/tasks/ext/phpunit/formatter/PHPUnitResultFormatter.php';
|
||||
|
||||
/**
|
||||
* Prints short summary output of the test to Phing's logging system.
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: SummaryPHPUnitResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.formatter
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class SummaryPHPUnitResultFormatter extends PHPUnitResultFormatter
|
||||
{
|
||||
public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
|
||||
{
|
||||
parent::endTestSuite($suite);
|
||||
}
|
||||
|
||||
public function endTestRun()
|
||||
{
|
||||
parent::endTestRun();
|
||||
|
||||
$sb = "Tests run: " . $this->getRunCount();
|
||||
$sb.= ", Failures: " . $this->getFailureCount();
|
||||
$sb.= ", Errors: " . $this->getErrorCount();
|
||||
$sb.= ", Incomplete: " . $this->getIncompleteCount();
|
||||
$sb.= ", Skipped: " . $this->getSkippedCount();
|
||||
$sb.= ", Time elapsed: " . sprintf('%0.5f', $this->getElapsedTime()) . " s\n";
|
||||
|
||||
if ($this->out != NULL)
|
||||
{
|
||||
$this->out->write($sb);
|
||||
$this->out->close();
|
||||
}
|
||||
}
|
||||
|
||||
public function getExtension()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,120 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: XMLPHPUnitResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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 'PHPUnit/Util/Log/JUnit.php';
|
||||
|
||||
require_once 'phing/tasks/ext/phpunit/formatter/PHPUnitResultFormatter.php';
|
||||
|
||||
/**
|
||||
* Prints XML output of the test to a specified Writer
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: XMLPHPUnitResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.formatter
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class XMLPHPUnitResultFormatter extends PHPUnitResultFormatter
|
||||
{
|
||||
/**
|
||||
* @var PHPUnit_Util_Log_JUnit
|
||||
*/
|
||||
private $logger = NULL;
|
||||
|
||||
public function __construct(PHPUnitTask $parentTask)
|
||||
{
|
||||
parent::__construct($parentTask);
|
||||
|
||||
$logIncompleteSkipped = $parentTask->getHaltonincomplete() || $parentTask->getHaltonskipped();
|
||||
|
||||
$this->logger = new PHPUnit_Util_Log_JUnit(null, $logIncompleteSkipped);
|
||||
$this->logger->setWriteDocument(false);
|
||||
}
|
||||
|
||||
public function getExtension()
|
||||
{
|
||||
return ".xml";
|
||||
}
|
||||
|
||||
public function getPreferredOutfile()
|
||||
{
|
||||
return "testsuites";
|
||||
}
|
||||
|
||||
public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
|
||||
{
|
||||
parent::startTestSuite($suite);
|
||||
|
||||
$this->logger->startTestSuite($suite);
|
||||
}
|
||||
|
||||
public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
|
||||
{
|
||||
parent::endTestSuite($suite);
|
||||
|
||||
$this->logger->endTestSuite($suite);
|
||||
}
|
||||
|
||||
public function startTest(PHPUnit_Framework_Test $test)
|
||||
{
|
||||
parent::startTest($test);
|
||||
|
||||
$this->logger->startTest($test);
|
||||
}
|
||||
|
||||
public function endTest(PHPUnit_Framework_Test $test, $time)
|
||||
{
|
||||
parent::endTest($test, $time);
|
||||
|
||||
$this->logger->endTest($test, $time);
|
||||
}
|
||||
|
||||
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
|
||||
{
|
||||
parent::addError($test, $e, $time);
|
||||
|
||||
$this->logger->addError($test, $e, $time);
|
||||
}
|
||||
|
||||
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
|
||||
{
|
||||
parent::addFailure($test, $e, $time);
|
||||
|
||||
$this->logger->addFailure($test, $e, $time);
|
||||
}
|
||||
|
||||
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
|
||||
{
|
||||
parent::addIncompleteTest($test, $e, $time);
|
||||
|
||||
$this->logger->addIncompleteTest($test, $e, $time);
|
||||
}
|
||||
|
||||
public function endTestRun()
|
||||
{
|
||||
parent::endTestRun();
|
||||
|
||||
if ($this->out)
|
||||
{
|
||||
$this->out->write($this->logger->getXML());
|
||||
$this->out->close();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: SimpleTestCountResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/tasks/ext/simpletest/SimpleTestResultFormatter.php';
|
||||
|
||||
/**
|
||||
* Dummy result formatter used to count SimpleTest results
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: SimpleTestCountResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.simpletest
|
||||
* @since 2.2.0
|
||||
*/
|
||||
class SimpleTestCountResultFormatter extends SimpleTestResultFormatter
|
||||
{
|
||||
const SUCCESS = 0;
|
||||
const FAILURES = 1;
|
||||
const ERRORS = 2;
|
||||
|
||||
function getRetCode()
|
||||
{
|
||||
if ($this->getExceptionCount() != 0)
|
||||
{
|
||||
return self::ERRORS;
|
||||
}
|
||||
else if ($this->getFailCount() != 0)
|
||||
{
|
||||
return self::FAILURES;
|
||||
}
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: SimpleTestDebugResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/tasks/ext/simpletest/SimpleTestResultFormatter.php';
|
||||
|
||||
/**
|
||||
* Prints plain text output of the test to a specified Writer.
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: SimpleTestDebugResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.simpletest
|
||||
* @since 2.2.0
|
||||
*/
|
||||
class SimpleTestDebugResultFormatter extends SimpleTestResultFormatter
|
||||
{
|
||||
protected $current_case = "";
|
||||
protected $current_test = "";
|
||||
private $failingTests = array();
|
||||
|
||||
function printFailingTests() {
|
||||
foreach ($this->failingTests as $test) {
|
||||
$this->out->write($test . "\n");
|
||||
}
|
||||
}
|
||||
|
||||
function paintCaseStart($test_name)
|
||||
{
|
||||
parent::paintCaseStart($test_name);
|
||||
$this->paint( "Testsuite: $test_name\n");
|
||||
$this->current_case = $test_name;
|
||||
}
|
||||
|
||||
function paintMethodStart($test_name)
|
||||
{
|
||||
parent::paintMethodStart($test_name);
|
||||
$this->current_test = $test_name;
|
||||
//$msg = "{$this->current_case} :: $test_name\n";
|
||||
$msg = " TestCase: $test_name";
|
||||
$this->paint($msg);
|
||||
}
|
||||
|
||||
function paint($msg) {
|
||||
if ($this->out == null ) {
|
||||
print $msg;
|
||||
} else {
|
||||
$this->out->write($msg);
|
||||
}
|
||||
}
|
||||
|
||||
function paintMethodEnd($test_name) {
|
||||
parent::paintMethodEnd($test_name);
|
||||
$this->paint("\n");
|
||||
}
|
||||
|
||||
function paintCaseEnd($test_name)
|
||||
{
|
||||
parent::paintCaseEnd($test_name);
|
||||
$this->current_case = "";
|
||||
/* Only count suites where more than one test was run */
|
||||
|
||||
if ($this->getRunCount() && false)
|
||||
{
|
||||
$sb = "";
|
||||
$sb.= "Tests run: " . $this->getRunCount();
|
||||
$sb.= ", Failures: " . $this->getFailureCount();
|
||||
$sb.= ", Errors: " . $this->getErrorCount();
|
||||
$sb.= ", Time elapsed: " . $this->getElapsedTime();
|
||||
$sb.= " sec\n";
|
||||
$this->paint($sb);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function paintError($message)
|
||||
{
|
||||
parent::paintError($message);
|
||||
$this->formatError("ERROR", $message);
|
||||
$this->failingTests[] = $this->current_case . "->" . $this->current_test;
|
||||
}
|
||||
|
||||
function paintFail($message)
|
||||
{
|
||||
parent::paintFail($message);
|
||||
$this->formatError("FAILED", $message);
|
||||
$this->failingTests[] = $this->current_case . "->" . $this->current_test;
|
||||
}
|
||||
function paintException($message)
|
||||
{
|
||||
parent::paintException($message);
|
||||
$this->failingTests[] = $this->current_case . "->" . $this->current_test;
|
||||
$this->formatError("Exception", $message);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function formatError($type, $message)
|
||||
{
|
||||
$this->paint("ERROR: $type: $message");
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: SimpleTestFormatterElement.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/tasks/ext/phpunit/FormatterElement.php';
|
||||
|
||||
/**
|
||||
* Child class of "FormatterElement", overrides setType to provide other
|
||||
* formatter classes for SimpleTest
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: SimpleTestFormatterElement.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.simpletest
|
||||
* @since 2.2.0
|
||||
*/
|
||||
class SimpleTestFormatterElement extends FormatterElement
|
||||
{
|
||||
function setType($type)
|
||||
{
|
||||
$this->type = $type;
|
||||
|
||||
if ($this->type == "xml")
|
||||
{
|
||||
require_once 'phing/tasks/ext/simpletest/SimpleTestXmlResultFormatter.php';
|
||||
$destFile = new PhingFile($this->toDir, 'testsuites.xml');
|
||||
$this->formatter = new SimpleTestXmlResultFormatter();
|
||||
}
|
||||
else
|
||||
if ($this->type == "plain")
|
||||
{
|
||||
require_once 'phing/tasks/ext/simpletest/SimpleTestPlainResultFormatter.php';
|
||||
$this->formatter = new SimpleTestPlainResultFormatter();
|
||||
}
|
||||
else
|
||||
if ($this->type == "summary")
|
||||
{
|
||||
require_once 'phing/tasks/ext/simpletest/SimpleTestSummaryResultFormatter.php';
|
||||
$this->formatter = new SimpleTestSummaryResultFormatter();
|
||||
}
|
||||
else
|
||||
if ($this->type == "debug")
|
||||
{
|
||||
require_once 'phing/tasks/ext/simpletest/SimpleTestDebugResultFormatter.php';
|
||||
$this->formatter = new SimpleTestDebugResultFormatter();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BuildException("Formatter '" . $this->type . "' not implemented");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: SimpleTestPlainResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/tasks/ext/simpletest/SimpleTestResultFormatter.php';
|
||||
|
||||
/**
|
||||
* Prints plain text output of the test to a specified Writer.
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: SimpleTestPlainResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.simpletest
|
||||
* @since 2.2.0
|
||||
*/
|
||||
class SimpleTestPlainResultFormatter extends SimpleTestResultFormatter
|
||||
{
|
||||
private $inner = "";
|
||||
|
||||
function getExtension()
|
||||
{
|
||||
return ".txt";
|
||||
}
|
||||
|
||||
function getPreferredOutfile()
|
||||
{
|
||||
return "testresults";
|
||||
}
|
||||
|
||||
function paintCaseStart($test_name)
|
||||
{
|
||||
parent::paintCaseStart($test_name);
|
||||
|
||||
$this->inner = "";
|
||||
}
|
||||
|
||||
function paintCaseEnd($test_name)
|
||||
{
|
||||
parent::paintCaseEnd($test_name);
|
||||
|
||||
$sb = "";
|
||||
/* Only count suites where more than one test was run */
|
||||
if ($this->getRunCount())
|
||||
{
|
||||
$sb.= "Testsuite: $test_name\n";
|
||||
$sb.= "Tests run: " . $this->getRunCount();
|
||||
$sb.= ", Failures: " . $this->getFailureCount();
|
||||
$sb.= ", Errors: " . $this->getErrorCount();
|
||||
$sb.= ", Time elapsed: " . $this->getElapsedTime();
|
||||
$sb.= " sec\n";
|
||||
|
||||
if ($this->out != NULL)
|
||||
{
|
||||
$this->out->write($sb);
|
||||
$this->out->write($this->inner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function paintError($message)
|
||||
{
|
||||
parent::paintError($message);
|
||||
|
||||
$this->formatError("ERROR", $message);
|
||||
}
|
||||
|
||||
function paintFail($message)
|
||||
{
|
||||
parent::paintFail($message);
|
||||
|
||||
$this->formatError("FAILED", $message);
|
||||
}
|
||||
|
||||
private function formatError($type, $message)
|
||||
{
|
||||
$this->inner.= $this->getTestName() . " " . $type . "\n";
|
||||
$this->inner.= $message . "\n";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,161 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: SimpleTestResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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 'simpletest/scorer.php';
|
||||
|
||||
require_once 'phing/system/io/Writer.php';
|
||||
|
||||
/**
|
||||
* This abstract class describes classes that format the results of a SimpleTest testrun.
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: SimpleTestResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.simpletest
|
||||
* @since 2.2.0
|
||||
*/
|
||||
abstract class SimpleTestResultFormatter extends SimpleReporter
|
||||
{
|
||||
protected $out = NULL;
|
||||
|
||||
protected $project = NULL;
|
||||
|
||||
private $timer = NULL;
|
||||
|
||||
private $runCount = 0;
|
||||
|
||||
private $failureCount = 0;
|
||||
|
||||
private $errorCount = 0;
|
||||
|
||||
private $currentTest = "";
|
||||
|
||||
/**
|
||||
* Sets the writer the formatter is supposed to write its results to.
|
||||
*/
|
||||
function setOutput(Writer $out)
|
||||
{
|
||||
$this->out = $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the extension used for this formatter
|
||||
*
|
||||
* @return string the extension
|
||||
*/
|
||||
function getExtension()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the project
|
||||
*
|
||||
* @param Project the project
|
||||
*/
|
||||
function setProject(Project $project)
|
||||
{
|
||||
$this->project = $project;
|
||||
}
|
||||
|
||||
function getPreferredOutfile()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
function paintMethodStart($test_name)
|
||||
{
|
||||
parent::paintMethodStart($test_name);
|
||||
|
||||
$this->currentTest = $test_name;
|
||||
}
|
||||
|
||||
function paintMethodEnd($test_name)
|
||||
{
|
||||
parent::paintMethodEnd($test_name);
|
||||
|
||||
$this->runCount++;
|
||||
}
|
||||
|
||||
function paintCaseStart($test_name)
|
||||
{
|
||||
parent::paintCaseStart($test_name);
|
||||
|
||||
$this->runCount = 0;
|
||||
$this->failureCount = 0;
|
||||
$this->errorCount = 0;
|
||||
|
||||
$this->timer = new Timer();
|
||||
$this->timer->start();
|
||||
}
|
||||
|
||||
function paintCaseEnd($test_name)
|
||||
{
|
||||
parent::paintCaseEnd($test_name);
|
||||
|
||||
$this->timer->stop();
|
||||
}
|
||||
|
||||
function paintError($message)
|
||||
{
|
||||
parent::paintError($message);
|
||||
|
||||
$this->errorCount++;
|
||||
}
|
||||
|
||||
function paintFail($message)
|
||||
{
|
||||
parent::paintFail($message);
|
||||
|
||||
$this->failureCount++;
|
||||
}
|
||||
|
||||
function getRunCount()
|
||||
{
|
||||
return $this->runCount;
|
||||
}
|
||||
|
||||
function getFailureCount()
|
||||
{
|
||||
return $this->failureCount;
|
||||
}
|
||||
|
||||
function getErrorCount()
|
||||
{
|
||||
return $this->errorCount;
|
||||
}
|
||||
|
||||
function getTestName()
|
||||
{
|
||||
return $this->currentTest;
|
||||
}
|
||||
|
||||
function getElapsedTime()
|
||||
{
|
||||
if ($this->timer)
|
||||
{
|
||||
return $this->timer->getElapsedTime();
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: SimpleTestSummaryResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/tasks/ext/simpletest/SimpleTestResultFormatter.php';
|
||||
|
||||
/**
|
||||
* Prints short summary output of the test to Phing's logging system.
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: SimpleTestSummaryResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.simpletest
|
||||
* @since 2.2.0
|
||||
*/
|
||||
class SimpleTestSummaryResultFormatter extends SimpleTestResultFormatter
|
||||
{
|
||||
function paintCaseEnd($test_name)
|
||||
{
|
||||
parent::paintCaseEnd($test_name);
|
||||
|
||||
/* Only count suites where more than one test was run */
|
||||
if ($this->getRunCount())
|
||||
{
|
||||
$sb.= "Tests run: " . $this->getRunCount();
|
||||
$sb.= ", Failures: " . $this->getFailureCount();
|
||||
$sb.= ", Errors: " . $this->getErrorCount();
|
||||
$sb.= ", Time elapsed: " . $this->getElapsedTime();
|
||||
$sb.= " sec\n";
|
||||
|
||||
if ($this->out != NULL)
|
||||
{
|
||||
$this->out->write($sb);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,264 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: SimpleTestTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
require_once 'phing/system/io/PhingFile.php';
|
||||
require_once 'phing/system/io/Writer.php';
|
||||
require_once 'phing/util/LogWriter.php';
|
||||
|
||||
/**
|
||||
* Runs SimpleTest tests.
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: SimpleTestTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.simpletest
|
||||
* @since 2.2.0
|
||||
*/
|
||||
class SimpleTestTask extends Task
|
||||
{
|
||||
private $formatters = array();
|
||||
private $haltonerror = false;
|
||||
private $haltonfailure = false;
|
||||
private $failureproperty;
|
||||
private $errorproperty;
|
||||
private $printsummary = false;
|
||||
private $testfailed = false;
|
||||
private $debug = false;
|
||||
|
||||
/**
|
||||
* Initialize Task.
|
||||
* This method includes any necessary SimpleTest libraries and triggers
|
||||
* appropriate error if they cannot be found. This is not done in header
|
||||
* because we may want this class to be loaded w/o triggering an error.
|
||||
*/
|
||||
function init() {
|
||||
@include_once 'simpletest/scorer.php';
|
||||
|
||||
if (!class_exists('SimpleReporter')) {
|
||||
throw new BuildException("SimpleTestTask depends on SimpleTest package being installed.", $this->getLocation());
|
||||
}
|
||||
|
||||
require_once 'simpletest/reporter.php';
|
||||
require_once 'simpletest/xml.php';
|
||||
require_once 'simpletest/test_case.php';
|
||||
require_once 'phing/tasks/ext/simpletest/SimpleTestCountResultFormatter.php';
|
||||
require_once 'phing/tasks/ext/simpletest/SimpleTestDebugResultFormatter.php';
|
||||
require_once 'phing/tasks/ext/simpletest/SimpleTestFormatterElement.php';
|
||||
}
|
||||
|
||||
function setFailureproperty($value)
|
||||
{
|
||||
$this->failureproperty = $value;
|
||||
}
|
||||
|
||||
function setErrorproperty($value)
|
||||
{
|
||||
$this->errorproperty = $value;
|
||||
}
|
||||
|
||||
function setHaltonerror($value)
|
||||
{
|
||||
$this->haltonerror = $value;
|
||||
}
|
||||
|
||||
function setHaltonfailure($value)
|
||||
{
|
||||
$this->haltonfailure = $value;
|
||||
}
|
||||
|
||||
function setPrintsummary($printsummary)
|
||||
{
|
||||
$this->printsummary = $printsummary;
|
||||
}
|
||||
|
||||
public function setDebug($debug)
|
||||
{
|
||||
$this->debug = $debug;
|
||||
}
|
||||
|
||||
public function getDebug()
|
||||
{
|
||||
return $this->debug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new formatter to all tests of this task.
|
||||
*
|
||||
* @param SimpleTestFormatterElement formatter element
|
||||
*/
|
||||
function addFormatter(SimpleTestFormatterElement $fe)
|
||||
{
|
||||
$this->formatters[] = $fe;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new fileset containing the XML results to aggregate
|
||||
*
|
||||
* @param FileSet the new fileset containing XML results.
|
||||
*/
|
||||
function addFileSet(FileSet $fileset)
|
||||
{
|
||||
$this->filesets[] = $fileset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate over all filesets and return the filename of all files
|
||||
* that end with .php.
|
||||
*
|
||||
* @return array an array of filenames
|
||||
*/
|
||||
private function getFilenames()
|
||||
{
|
||||
$filenames = array();
|
||||
|
||||
foreach ($this->filesets as $fileset)
|
||||
{
|
||||
$ds = $fileset->getDirectoryScanner($this->project);
|
||||
$ds->scan();
|
||||
|
||||
$files = $ds->getIncludedFiles();
|
||||
|
||||
foreach ($files as $file)
|
||||
{
|
||||
if (strstr($file, ".php"))
|
||||
{
|
||||
$filenames[] = $ds->getBaseDir() . "/" . $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $filenames;
|
||||
}
|
||||
|
||||
/**
|
||||
* The main entry point
|
||||
*
|
||||
* @throws BuildException
|
||||
*/
|
||||
function main()
|
||||
{
|
||||
$group = new GroupTest();
|
||||
|
||||
$filenames = $this->getFilenames();
|
||||
|
||||
foreach ($filenames as $testfile)
|
||||
{
|
||||
$group->addTestFile($testfile);
|
||||
}
|
||||
|
||||
if ($this->debug)
|
||||
{
|
||||
$fe = new SimpleTestFormatterElement();
|
||||
$fe->setType('debug');
|
||||
$fe->setUseFile(false);
|
||||
$this->formatters[] = $fe;
|
||||
}
|
||||
|
||||
if ($this->printsummary)
|
||||
{
|
||||
$fe = new SimpleTestFormatterElement();
|
||||
$fe->setType('summary');
|
||||
$fe->setUseFile(false);
|
||||
$this->formatters[] = $fe;
|
||||
}
|
||||
|
||||
foreach ($this->formatters as $fe)
|
||||
{
|
||||
$formatter = $fe->getFormatter();
|
||||
$formatter->setProject($this->getProject());
|
||||
|
||||
if ($fe->getUseFile())
|
||||
{
|
||||
$destFile = new PhingFile($fe->getToDir(), $fe->getOutfile());
|
||||
|
||||
$writer = new FileWriter($destFile->getAbsolutePath());
|
||||
|
||||
$formatter->setOutput($writer);
|
||||
}
|
||||
else
|
||||
{
|
||||
$formatter->setOutput($this->getDefaultOutput());
|
||||
}
|
||||
}
|
||||
|
||||
$this->execute($group);
|
||||
|
||||
if ($this->testfailed && $this->formatters[0]->getFormatter() instanceof SimpleTestDebugResultFormatter )
|
||||
{
|
||||
$this->getDefaultOutput()->write("Failed tests: ");
|
||||
$this->formatters[0]->getFormatter()->printFailingTests();
|
||||
}
|
||||
|
||||
if ($this->testfailed)
|
||||
{
|
||||
throw new BuildException("One or more tests failed");
|
||||
}
|
||||
}
|
||||
|
||||
private function execute($suite)
|
||||
{
|
||||
$counter = new SimpleTestCountResultFormatter();
|
||||
$reporter = new MultipleReporter();
|
||||
$reporter->attachReporter($counter);
|
||||
|
||||
foreach ($this->formatters as $fe)
|
||||
{
|
||||
// SimpleTest 1.0.1 workaround
|
||||
$formatterList[] = $fe->getFormatter();
|
||||
|
||||
$reporter->attachReporter(end($formatterList));
|
||||
}
|
||||
|
||||
$suite->run($reporter);
|
||||
|
||||
$retcode = $counter->getRetCode();
|
||||
|
||||
if ($retcode == SimpleTestCountResultFormatter::ERRORS)
|
||||
{
|
||||
if ($this->errorproperty)
|
||||
{
|
||||
$this->project->setNewProperty($this->errorproperty, true);
|
||||
}
|
||||
|
||||
if ($this->haltonerror)
|
||||
{
|
||||
$this->testfailed = true;
|
||||
}
|
||||
}
|
||||
elseif ($retcode == SimpleTestCountResultFormatter::FAILURES)
|
||||
{
|
||||
if ($this->failureproperty)
|
||||
{
|
||||
$this->project->setNewProperty($this->failureproperty, true);
|
||||
}
|
||||
|
||||
if ($this->haltonfailure)
|
||||
{
|
||||
$this->testfailed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getDefaultOutput()
|
||||
{
|
||||
return new LogWriter($this);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,178 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: SimpleTestXmlResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/tasks/ext/simpletest/SimpleTestResultFormatter.php';
|
||||
require_once 'simpletest/xml.php';
|
||||
|
||||
/**
|
||||
* Prints plain text output of the test to a specified Writer.
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: SimpleTestXmlResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.simpletest
|
||||
* @since 2.2.0
|
||||
*/
|
||||
class SimpleTestXmlResultFormatter extends SimpleTestResultFormatter
|
||||
{
|
||||
/**
|
||||
* @var XmlReporter
|
||||
*/
|
||||
private $logger = NULL;
|
||||
|
||||
private $xmlData = "";
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->logger = new XmlReporter();
|
||||
}
|
||||
|
||||
function getExtension()
|
||||
{
|
||||
return ".xml";
|
||||
}
|
||||
|
||||
function getPreferredOutfile()
|
||||
{
|
||||
return "testsuites";
|
||||
}
|
||||
|
||||
private function captureStart()
|
||||
{
|
||||
ob_start();
|
||||
}
|
||||
|
||||
private function captureStop()
|
||||
{
|
||||
$this->xmlData .= ob_get_contents();
|
||||
ob_end_clean();
|
||||
}
|
||||
|
||||
function paintGroupStart($test_name, $size)
|
||||
{
|
||||
parent::paintGroupStart($test_name, $size);
|
||||
|
||||
$this->captureStart();
|
||||
$this->logger->paintGroupStart($test_name, $size);
|
||||
$this->captureStop();
|
||||
}
|
||||
|
||||
function paintGroupEnd($test_name)
|
||||
{
|
||||
parent::paintGroupEnd($test_name, $size);
|
||||
|
||||
$this->captureStart();
|
||||
$this->logger->paintGroupEnd($test_name);
|
||||
$this->captureStop();
|
||||
|
||||
if (count($this->_test_stack) == 0)
|
||||
{
|
||||
if ($this->out)
|
||||
{
|
||||
$this->out->write($this->xmlData);
|
||||
$this->out->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function paintCaseStart($test_name)
|
||||
{
|
||||
$this->captureStart();
|
||||
$this->logger->paintCaseStart($test_name);
|
||||
$this->captureStop();
|
||||
}
|
||||
|
||||
function paintCaseEnd($test_name)
|
||||
{
|
||||
$this->captureStart();
|
||||
$this->logger->paintCaseEnd($test_name);
|
||||
$this->captureStop();
|
||||
}
|
||||
|
||||
function paintMethodStart($test_name)
|
||||
{
|
||||
$this->captureStart();
|
||||
$this->logger->paintMethodStart($test_name);
|
||||
$this->captureStop();
|
||||
}
|
||||
|
||||
function paintMethodEnd($test_name)
|
||||
{
|
||||
$this->captureStart();
|
||||
$this->logger->paintMethodEnd($test_name);
|
||||
$this->captureStop();
|
||||
}
|
||||
|
||||
function paintPass($message)
|
||||
{
|
||||
$this->captureStart();
|
||||
$this->logger->paintPass($message);
|
||||
$this->captureStop();
|
||||
}
|
||||
|
||||
function paintError($message)
|
||||
{
|
||||
$this->captureStart();
|
||||
$this->logger->paintError($message);
|
||||
$this->captureStop();
|
||||
}
|
||||
|
||||
function paintFail($message)
|
||||
{
|
||||
$this->captureStart();
|
||||
$this->logger->paintFail($message);
|
||||
$this->captureStop();
|
||||
}
|
||||
|
||||
function paintException($exception)
|
||||
{
|
||||
$this->captureStart();
|
||||
$this->logger->paintException($exception);
|
||||
$this->captureStop();
|
||||
}
|
||||
|
||||
function paintSkip($message)
|
||||
{
|
||||
$this->captureStart();
|
||||
$this->logger->paintSkip($message);
|
||||
$this->captureStop();
|
||||
}
|
||||
|
||||
function paintMessage($message)
|
||||
{
|
||||
$this->captureStart();
|
||||
$this->logger->paintMessage($message);
|
||||
$this->captureStop();
|
||||
}
|
||||
|
||||
function paintFormattedMessage($message)
|
||||
{
|
||||
$this->captureStart();
|
||||
$this->logger->paintFormattedMessage($message);
|
||||
$this->captureStop();
|
||||
}
|
||||
|
||||
function paintSignal($type, $payload)
|
||||
{
|
||||
$this->captureStart();
|
||||
$this->logger->paintSignal($type, $payload);
|
||||
$this->captureStop();
|
||||
}
|
||||
}
|
323
airtime_mvc/library/phing/tasks/ext/svn/SvnBaseTask.php
Normal file
323
airtime_mvc/library/phing/tasks/ext/svn/SvnBaseTask.php
Normal file
|
@ -0,0 +1,323 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: SvnBaseTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
include_once 'phing/Task.php';
|
||||
|
||||
/**
|
||||
* Base class for Subversion tasks
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @author Andrew Eddie <andrew.eddie@jamboworks.com>
|
||||
* @version $Id: SvnBaseTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.svn
|
||||
* @see VersionControl_SVN
|
||||
* @since 2.2.0
|
||||
*/
|
||||
abstract class SvnBaseTask extends Task
|
||||
{
|
||||
private $workingCopy = "";
|
||||
|
||||
private $repositoryUrl = "";
|
||||
|
||||
private $svnPath = "/usr/bin/svn";
|
||||
|
||||
private $svn = NULL;
|
||||
|
||||
private $mode = "";
|
||||
|
||||
private $svnArgs = array();
|
||||
|
||||
private $svnSwitches = array();
|
||||
|
||||
private $toDir = "";
|
||||
|
||||
/**
|
||||
* Initialize Task.
|
||||
* This method includes any necessary SVN libraries and triggers
|
||||
* appropriate error if they cannot be found. This is not done in header
|
||||
* because we may want this class to be loaded w/o triggering an error.
|
||||
*/
|
||||
function init() {
|
||||
include_once 'VersionControl/SVN.php';
|
||||
if (!class_exists('VersionControl_SVN')) {
|
||||
throw new Exception("The SVN tasks depend on PEAR VersionControl_SVN package being installed.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the path to the workingcopy
|
||||
*/
|
||||
function setWorkingCopy($workingCopy)
|
||||
{
|
||||
$this->workingCopy = $workingCopy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path to the workingcopy
|
||||
*/
|
||||
function getWorkingCopy()
|
||||
{
|
||||
return $this->workingCopy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the path/URI to the repository
|
||||
*/
|
||||
function setRepositoryUrl($repositoryUrl)
|
||||
{
|
||||
$this->repositoryUrl = $repositoryUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path/URI to the repository
|
||||
*/
|
||||
function getRepositoryUrl()
|
||||
{
|
||||
return $this->repositoryUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the path to the SVN executable
|
||||
*/
|
||||
function setSvnPath($svnPath)
|
||||
{
|
||||
$this->svnPath = $svnPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path to the SVN executable
|
||||
*/
|
||||
function getSvnPath()
|
||||
{
|
||||
return $this->svnPath;
|
||||
}
|
||||
|
||||
//
|
||||
// Args
|
||||
//
|
||||
|
||||
/**
|
||||
* Sets the path to export/checkout to
|
||||
*/
|
||||
function setToDir($toDir)
|
||||
{
|
||||
$this->toDir = $toDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path to export/checkout to
|
||||
*/
|
||||
function getToDir()
|
||||
{
|
||||
return $this->toDir;
|
||||
}
|
||||
|
||||
//
|
||||
// Switches
|
||||
//
|
||||
|
||||
/**
|
||||
* Sets the force switch
|
||||
*/
|
||||
function setForce($value)
|
||||
{
|
||||
$this->svnSwitches['force'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the force switch
|
||||
*/
|
||||
function getForce()
|
||||
{
|
||||
return isset( $this->svnSwitches['force'] ) ? $this->svnSwitches['force'] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the username of the user to export
|
||||
*/
|
||||
function setUsername($value)
|
||||
{
|
||||
$this->svnSwitches['username'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the username
|
||||
*/
|
||||
function getUsername()
|
||||
{
|
||||
return isset( $this->svnSwitches['username'] ) ? $this->svnSwitches['username'] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the password of the user to export
|
||||
*/
|
||||
function setPassword($value)
|
||||
{
|
||||
$this->svnSwitches['password'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the password
|
||||
*/
|
||||
function getPassword()
|
||||
{
|
||||
return isset( $this->svnSwitches['password'] ) ? $this->svnSwitches['password'] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the no-auth-cache switch
|
||||
*/
|
||||
function setNoCache($value)
|
||||
{
|
||||
$this->svnSwitches['no-auth-cache'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the no-auth-cache switch
|
||||
*/
|
||||
function getNoCache()
|
||||
{
|
||||
return isset( $this->svnSwitches['no-auth-cache'] ) ? $this->svnSwitches['no-auth-cache'] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the non-recursive switch
|
||||
*/
|
||||
function setRecursive($value)
|
||||
{
|
||||
$this->svnSwitches['non-recursive'] = is_bool($value) ? !$value : TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the non-recursive switch
|
||||
*/
|
||||
function getRecursive()
|
||||
{
|
||||
return isset( $this->svnSwitches['non-recursive'] ) ? $this->svnSwitches['non-recursive'] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the ignore-externals switch
|
||||
*/
|
||||
function setIgnoreExternals($value)
|
||||
{
|
||||
$this->svnSwitches['ignore-externals'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ignore-externals switch
|
||||
*/
|
||||
function getIgnoreExternals()
|
||||
{
|
||||
return isset( $this->svnSwitches['ignore-externals'] ) ? $this->svnSwitches['ignore-externals'] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a VersionControl_SVN class based on $mode
|
||||
*
|
||||
* @param string The SVN mode to use (info, export, checkout, ...)
|
||||
* @throws BuildException
|
||||
*/
|
||||
protected function setup($mode)
|
||||
{
|
||||
$this->mode = $mode;
|
||||
|
||||
// Set up runtime options. Will be passed to all
|
||||
// subclasses.
|
||||
$options = array('fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_ASSOC, 'svn_path' => escapeshellarg($this->getSvnPath()));
|
||||
|
||||
// Pass array of subcommands we need to factory
|
||||
$this->svn = VersionControl_SVN::factory($mode, $options);
|
||||
|
||||
$this->svn->use_escapeshellcmd = false;
|
||||
|
||||
if (!empty($this->repositoryUrl))
|
||||
{
|
||||
$this->svnArgs = array($this->repositoryUrl);
|
||||
}
|
||||
else
|
||||
if (!empty($this->workingCopy))
|
||||
{
|
||||
if (is_dir($this->workingCopy))
|
||||
{
|
||||
if (in_array(".svn", scandir($this->workingCopy)))
|
||||
{
|
||||
$this->svnArgs = array(escapeshellarg($this->workingCopy));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BuildException("'".$this->workingCopy."' doesn't seem to be a working copy");
|
||||
}
|
||||
}
|
||||
else
|
||||
if ($mode=='info' )
|
||||
{
|
||||
if (is_file($this->workingCopy))
|
||||
{
|
||||
$this->svnArgs = array(escapeshellarg($this->workingCopy));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BuildException("'".$this->workingCopy."' is not a directory nor a file");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BuildException("'".$this->workingCopy."' is not a directory");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the constructed VersionControl_SVN instance
|
||||
*
|
||||
* @param array Additional arguments to pass to SVN.
|
||||
* @param array Switches to pass to SVN.
|
||||
* @return string Output generated by SVN.
|
||||
*/
|
||||
protected function run($args = array(), $switches = array())
|
||||
{
|
||||
$svnstack = PEAR_ErrorStack::singleton('VersionControl_SVN');
|
||||
|
||||
$tempArgs = $this->svnArgs;
|
||||
|
||||
$tempArgs = array_merge($tempArgs, $args);
|
||||
|
||||
$tempSwitches = $this->svnSwitches;
|
||||
|
||||
$tempSwitches = array_merge($tempSwitches, $switches);
|
||||
|
||||
if ($output = $this->svn->run($tempArgs, $tempSwitches))
|
||||
{
|
||||
return $output;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (count($errs = $svnstack->getErrors()))
|
||||
{
|
||||
$err = current($errs);
|
||||
|
||||
throw new BuildException("Failed to run the 'svn " . $this->mode . "' command: " . $err['params']['errstr']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
67
airtime_mvc/library/phing/tasks/ext/svn/SvnCheckoutTask.php
Normal file
67
airtime_mvc/library/phing/tasks/ext/svn/SvnCheckoutTask.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: SvnCheckoutTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
require_once 'phing/tasks/ext/svn/SvnBaseTask.php';
|
||||
|
||||
/**
|
||||
* Checks out a repository to a local directory
|
||||
*
|
||||
* @author Andrew Eddie <andrew.eddie@jamboworks.com>
|
||||
* @version $Id: SvnCheckoutTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.svn
|
||||
* @since 2.3.0
|
||||
*/
|
||||
class SvnCheckoutTask extends SvnBaseTask
|
||||
{
|
||||
/**
|
||||
* Which Revision to Export
|
||||
*
|
||||
* @todo check if version_control_svn supports constants
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $revision = 'HEAD';
|
||||
|
||||
/**
|
||||
* The main entry point
|
||||
*
|
||||
* @throws BuildException
|
||||
*/
|
||||
function main()
|
||||
{
|
||||
$this->setup('checkout');
|
||||
|
||||
$this->log("Checking out SVN repository to '" . $this->getToDir() . "'". ($this->revision=='HEAD'?'':" (revision: {$this->revision})"));
|
||||
|
||||
// revision
|
||||
$switches = array(
|
||||
'r' => $this->revision,
|
||||
);
|
||||
|
||||
$this->run(array($this->getToDir()), $switches);
|
||||
}
|
||||
|
||||
public function setRevision($revision)
|
||||
{
|
||||
$this->revision = $revision;
|
||||
}
|
||||
}
|
113
airtime_mvc/library/phing/tasks/ext/svn/SvnCommitTask.php
Normal file
113
airtime_mvc/library/phing/tasks/ext/svn/SvnCommitTask.php
Normal file
|
@ -0,0 +1,113 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: SvnCommitTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
require_once 'phing/tasks/ext/svn/SvnBaseTask.php';
|
||||
|
||||
/**
|
||||
* Commits changes in a local working copy to the repository
|
||||
*
|
||||
* @author Johan Persson <johanp@aditus.nu>
|
||||
* @version $Id: SvnCommitTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.svn
|
||||
* @since 2.4.0
|
||||
*/
|
||||
class SvnCommitTask extends SvnBaseTask
|
||||
{
|
||||
/**
|
||||
* Commit message
|
||||
*/
|
||||
private $message = '';
|
||||
|
||||
/**
|
||||
* Property name where we store the revision number of the just
|
||||
* commited version.
|
||||
*/
|
||||
private $propertyName = "svn.committedrevision";
|
||||
|
||||
/**
|
||||
* Sets the commit message
|
||||
*/
|
||||
function setMessage($message)
|
||||
{
|
||||
$this->message = $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the commit message
|
||||
*/
|
||||
function getMessage()
|
||||
{
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the property to use for returned revision
|
||||
*/
|
||||
function setPropertyName($propertyName)
|
||||
{
|
||||
$this->propertyName = $propertyName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the property to use for returned revision
|
||||
*/
|
||||
function getPropertyName()
|
||||
{
|
||||
return $this->propertyName;
|
||||
}
|
||||
|
||||
/**
|
||||
* The main entry point
|
||||
*
|
||||
* @throws BuildException
|
||||
*/
|
||||
function main()
|
||||
{
|
||||
if( trim($this->message) === '' )
|
||||
{
|
||||
throw new BuildException('SVN Commit message can not be empty.');
|
||||
}
|
||||
|
||||
$this->setup('commit');
|
||||
|
||||
$this->log("Commiting SVN working copy at '" . $this->getWorkingCopy() . "' with message '".$this->GetMessage()."'");
|
||||
|
||||
$output = $this->run(array(), array('message' => $this->GetMessage() ) );
|
||||
|
||||
if( preg_match('/[\s]*Committed revision[\s]+([\d]+)/', $output, $matches) )
|
||||
{
|
||||
$this->project->setProperty($this->getPropertyName(), $matches[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
/**
|
||||
* If no new revision was committed set revision to "empty". Remember that
|
||||
* this is not necessarily an error. It could be that the specified working
|
||||
* copy is identical to to the copy in the repository and in that case
|
||||
* there will be no update and no new revision number.
|
||||
*/
|
||||
$this->project->setProperty($this->getPropertyName(), '' );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
64
airtime_mvc/library/phing/tasks/ext/svn/SvnCopyTask.php
Normal file
64
airtime_mvc/library/phing/tasks/ext/svn/SvnCopyTask.php
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
/**
|
||||
* 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';
|
||||
require_once 'phing/tasks/ext/svn/SvnBaseTask.php';
|
||||
|
||||
/**
|
||||
* Copies a repository from the repository url to another
|
||||
*
|
||||
* @version $Id: SvnCopyTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.svn
|
||||
* @since 2.3.0
|
||||
*/
|
||||
class SvnCopyTask extends SvnBaseTask
|
||||
{
|
||||
private $message = "";
|
||||
|
||||
/**
|
||||
* Sets the message
|
||||
*/
|
||||
function setMessage($message)
|
||||
{
|
||||
$this->message = $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the message
|
||||
*/
|
||||
function getMessage()
|
||||
{
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
/**
|
||||
* The main entry point
|
||||
*
|
||||
* @throws BuildException
|
||||
*/
|
||||
function main()
|
||||
{
|
||||
$this->setup('copy');
|
||||
|
||||
$this->log("Copying SVN repository from '" . $this->getRepositoryUrl() . "' to '" . $this->getToDir() . "'");
|
||||
|
||||
$this->run(array($this->getToDir()), array('message' => $this->getMessage()));
|
||||
}
|
||||
}
|
||||
|
69
airtime_mvc/library/phing/tasks/ext/svn/SvnExportTask.php
Normal file
69
airtime_mvc/library/phing/tasks/ext/svn/SvnExportTask.php
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: SvnExportTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
require_once 'phing/tasks/ext/svn/SvnBaseTask.php';
|
||||
|
||||
/**
|
||||
* Exports/checks out a repository to a local directory
|
||||
* with authentication
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @author Andrew Eddie <andrew.eddie@jamboworks.com>
|
||||
* @version $Id: SvnExportTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.svn
|
||||
* @since 2.2.0
|
||||
*/
|
||||
class SvnExportTask extends SvnBaseTask
|
||||
{
|
||||
/**
|
||||
* Which Revision to Export
|
||||
*
|
||||
* @todo check if version_control_svn supports constants
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $revision = 'HEAD';
|
||||
|
||||
/**
|
||||
* The main entry point
|
||||
*
|
||||
* @throws BuildException
|
||||
*/
|
||||
function main()
|
||||
{
|
||||
$this->setup('export');
|
||||
|
||||
$this->log("Exporting SVN repository to '" . $this->getToDir() . "'");
|
||||
|
||||
// revision
|
||||
$switches = array(
|
||||
'r' => $this->revision,
|
||||
);
|
||||
|
||||
$this->run(array($this->getToDir()), $switches);
|
||||
}
|
||||
|
||||
public function setRevision($revision)
|
||||
{
|
||||
$this->revision = $revision;
|
||||
}
|
||||
}
|
100
airtime_mvc/library/phing/tasks/ext/svn/SvnLastRevisionTask.php
Normal file
100
airtime_mvc/library/phing/tasks/ext/svn/SvnLastRevisionTask.php
Normal file
|
@ -0,0 +1,100 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: SvnLastRevisionTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
require_once 'phing/tasks/ext/svn/SvnBaseTask.php';
|
||||
|
||||
/**
|
||||
* Stores the number of the last revision of a workingcopy in a property
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: SvnLastRevisionTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.svn
|
||||
* @see VersionControl_SVN
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class SvnLastRevisionTask extends SvnBaseTask
|
||||
{
|
||||
private $propertyName = "svn.lastrevision";
|
||||
private $forceCompatible = false;
|
||||
|
||||
/**
|
||||
* Sets the name of the property to use
|
||||
*/
|
||||
function setPropertyName($propertyName)
|
||||
{
|
||||
$this->propertyName = $propertyName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the property to use
|
||||
*/
|
||||
function getPropertyName()
|
||||
{
|
||||
return $this->propertyName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to force compatibility with older SVN versions (< 1.2)
|
||||
*/
|
||||
public function forceCompatible($force)
|
||||
{
|
||||
$this->forceCompatible = (bool) $force;
|
||||
}
|
||||
|
||||
/**
|
||||
* The main entry point
|
||||
*
|
||||
* @throws BuildException
|
||||
*/
|
||||
function main()
|
||||
{
|
||||
$this->setup('info');
|
||||
|
||||
if ($this->forceCompatible)
|
||||
{
|
||||
$output = $this->run();
|
||||
|
||||
if (preg_match('/Rev:[\s]+([\d]+)/', $output, $matches))
|
||||
{
|
||||
$this->project->setProperty($this->getPropertyName(), $matches[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BuildException("Failed to parse the output of 'svn info'.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$output = $this->run(array('--xml'));
|
||||
|
||||
if ($xmlObj = @simplexml_load_string($output))
|
||||
{
|
||||
$lastRevision = (int)$xmlObj->entry['revision'];
|
||||
$this->project->setProperty($this->getPropertyName(), $lastRevision);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BuildException("Failed to parse the output of 'svn info --xml'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
67
airtime_mvc/library/phing/tasks/ext/svn/SvnUpdateTask.php
Normal file
67
airtime_mvc/library/phing/tasks/ext/svn/SvnUpdateTask.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: SvnUpdateTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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';
|
||||
require_once 'phing/tasks/ext/svn/SvnBaseTask.php';
|
||||
|
||||
/**
|
||||
* Updates a repository in local directory
|
||||
*
|
||||
* @author Andrew Eddie <andrew.eddie@jamboworks.com>
|
||||
* @version $Id: SvnUpdateTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.svn
|
||||
* @since 2.3.0
|
||||
*/
|
||||
class SvnUpdateTask extends SvnBaseTask
|
||||
{
|
||||
/**
|
||||
* Which Revision to Export
|
||||
*
|
||||
* @todo check if version_control_svn supports constants
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $revision = 'HEAD';
|
||||
|
||||
/**
|
||||
* The main entry point
|
||||
*
|
||||
* @throws BuildException
|
||||
*/
|
||||
function main()
|
||||
{
|
||||
$this->setup('update');
|
||||
|
||||
$this->log("Updating SVN repository at '" . $this->getToDir() . "'". ($this->revision=='HEAD'?'':" (revision: {$this->revision})"));
|
||||
|
||||
// revision
|
||||
$switches = array(
|
||||
'r' => $this->revision,
|
||||
);
|
||||
|
||||
$this->run(array($this->getToDir()), $switches);
|
||||
}
|
||||
|
||||
public function setRevision($revision)
|
||||
{
|
||||
$this->revision = $revision;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue