2011-04-26 03:57:55 +02:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
All code covered by the BSD license located at http://silverstripe.org/bsd-license/
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build task that provides some commonly used functionality
|
|
|
|
*
|
|
|
|
* @author marcus
|
|
|
|
*/
|
|
|
|
abstract class SilverStripeBuildTask extends Task {
|
2011-05-01 08:30:23 +02:00
|
|
|
|
|
|
|
protected $cleanupEnv = false;
|
2011-04-26 03:57:55 +02:00
|
|
|
|
|
|
|
protected function configureEnvFile() {
|
|
|
|
// fake the _ss_environment.php file for the moment
|
|
|
|
$ssEnv = <<<TEXT
|
|
|
|
<?php
|
|
|
|
// Set the \$_FILE_MAPPING for running the test cases, it's basically a fake but useful
|
|
|
|
global \$_FILE_TO_URL_MAPPING;
|
|
|
|
\$_FILE_TO_URL_MAPPING[dirname(__FILE__)] = 'http://localhost';
|
|
|
|
TEXT;
|
|
|
|
|
|
|
|
$envFile = dirname(dirname(__FILE__)).'/_ss_environment.php';
|
|
|
|
$this->cleanupEnv = false;
|
|
|
|
if (!file_exists($envFile)) {
|
|
|
|
file_put_contents($envFile, $ssEnv);
|
|
|
|
$this->cleanupEnv = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-28 23:49:56 +02:00
|
|
|
function cleanEnv() {
|
2011-04-26 03:57:55 +02:00
|
|
|
if ($this->cleanupEnv) {
|
|
|
|
$envFile = dirname(dirname(__FILE__)).'/_ss_environment.php';
|
|
|
|
if (file_exists($envFile)) {
|
|
|
|
unlink($envFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-28 23:49:56 +02:00
|
|
|
function devBuild() {
|
2012-04-12 11:15:32 +02:00
|
|
|
if (file_exists('framework/cli-script.php')) {
|
2011-04-26 03:57:55 +02:00
|
|
|
$this->log("Running dev/build");
|
2012-04-12 11:15:32 +02:00
|
|
|
$this->exec('php framework/cli-script.php dev/build');
|
2011-04-26 03:57:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get some input from the user
|
|
|
|
*
|
|
|
|
* @param string $prompt
|
|
|
|
* @return string
|
|
|
|
*/
|
2011-04-28 23:49:56 +02:00
|
|
|
function getInput($prompt) {
|
2011-04-26 03:57:55 +02:00
|
|
|
require_once 'phing/input/InputRequest.php';
|
|
|
|
$request = new InputRequest($prompt);
|
|
|
|
$request->setPromptChar(':');
|
|
|
|
|
|
|
|
$this->project->getInputHandler()->handleInput($request);
|
|
|
|
$value = $request->getInput();
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
2011-04-28 23:49:56 +02:00
|
|
|
function exec($cmd, $returnContent = false, $ignoreError = false) {
|
2011-04-26 03:57:55 +02:00
|
|
|
$ret = null;
|
|
|
|
$return = null;
|
2011-05-01 08:30:23 +02:00
|
|
|
|
2012-01-31 14:24:00 +01:00
|
|
|
$this->log($cmd, Project::MSG_VERBOSE);
|
2011-05-01 08:30:23 +02:00
|
|
|
|
2011-04-26 03:57:55 +02:00
|
|
|
if ($returnContent) {
|
|
|
|
$ret = shell_exec($cmd);
|
|
|
|
} else {
|
|
|
|
passthru($cmd, $return);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($return != 0 && !$ignoreError) {
|
|
|
|
throw new BuildException("Command '$cmd' failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
return $ret;
|
|
|
|
}
|
2012-04-12 11:15:32 +02:00
|
|
|
}
|