Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added keep going mode #347

Merged
merged 1 commit into from May 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions classes/phing/Phing.php
Expand Up @@ -86,6 +86,12 @@ class Phing
/** Names of classes to add as listeners to project */
private $listeners = array();

/**
* keep going mode
* @var bool $keepGoingMode
*/
private $keepGoingMode = false;

private $loggerClassname = null;

/** The class to handle input (can be only one). */
Expand Down Expand Up @@ -446,6 +452,8 @@ public function execute($args)
$this->setProperty($prop, $value);
}
}
} elseif ($arg == "-keep-going" || $arg == "-k") {
$this->keepGoingMode = true;
} elseif ($arg == "-longtargets") {
self::$definedProps->setProperty('phing.showlongtargets', 1);
} elseif ($arg == "-projecthelp" || $arg == "-targets" || $arg == "-list" || $arg == "-l" || $arg == "-p") {
Expand Down Expand Up @@ -593,6 +601,8 @@ public function runBuild()
throw $exc;
}

$project->setKeepGoingMode($this->keepGoingMode);

$project->setUserProperty("phing.version", $this->getPhingVersion());

$e = self::$definedProps->keys();
Expand Down Expand Up @@ -928,6 +938,7 @@ public static function printUsage()
$msg .= " -logger <classname> the class which is to perform logging" . PHP_EOL;
$msg .= " -f -buildfile <file> use given buildfile" . PHP_EOL;
$msg .= " -D<property>=<value> use value for given property" . PHP_EOL;
$msg .= " -keep-going, -k execute all targets that do not depend" . PHP_EOL;
$msg .= " -propertyfile <file> load all properties from file" . PHP_EOL;
$msg .= " -find <file> search for buildfile towards the root of the" . PHP_EOL;
$msg .= " filesystem and use it" . PHP_EOL;
Expand Down
67 changes: 61 additions & 6 deletions classes/phing/Project.php
Expand Up @@ -107,6 +107,11 @@ class Project
/** Build listeneers */
private $listeners = array();

/**
* Keep going flag.
*/
private $keepGoingMode = false;

/**
* Constructor, sets any default vars.
*/
Expand Down Expand Up @@ -561,6 +566,30 @@ public function getBasedir()
return $this->basedir;
}

/**
* Set &quot;keep-going&quot; mode. In this mode Ant will try to execute
* as many targets as possible. All targets that do not depend
* on failed target(s) will be executed. If the keepGoing settor/getter
* methods are used in conjunction with the <code>ant.executor.class</code>
* property, they will have no effect.
* @param keepGoingMode &quot;keep-going&quot; mode
*/
public function setKeepGoingMode($keepGoingMode)
{
$this->keepGoingMode = $keepGoingMode;
}

/**
* Return the keep-going mode. If the keepGoing settor/getter
* methods are used in conjunction with the <code>phing.executor.class</code>
* property, they will have no effect.
* @return bool &quot;keep-going&quot; mode
*/
public function isKeepGoingMode()
{
return $this->keepGoingMode;
}

/**
* Sets system properties and the environment variables for this project.
*
Expand Down Expand Up @@ -861,19 +890,45 @@ public function executeTarget($targetName)

$curIndex = (int) 0;
$curTarget = null;
$thrownException = null;
$buildException = null;
do {
try {
$curTarget = $sortedTargets[$curIndex++];
$curTarget->performTasks();
} catch (BuildException $exc) {
$this->log(
"Execution of target \"" . $curTarget->getName(
) . "\" failed for the following reason: " . $exc->getMessage(),
Project::MSG_ERR
);
throw $exc;
if (!($this->keepGoingMode)) {
throw $exc;
}
$thrownException = $exc;
}
if ($thrownException != null) {
if ($thrownException instanceof BuildException) {
$this->log(
"Target '" . $curTarget->getName()
. "' failed with message '"
. $thrownException->getMessage() . "'.", Project::MSG_ERR);
// only the first build exception is reported
if ($buildException === null) {
$buildException = $thrownException;
}
} else {
$this->log(
"Target '" . $curTarget->getName()
. "' failed with message '"
. $thrownException->getMessage() . "'." . PHP_EOL
. $thrownException->getTraceAsString(), Project::MSG_ERR
);
if ($buildException === null) {
$buildException = new BuildException($thrownException);
}
}
}
} while ($curTarget->getName() !== $targetName);

if ($buildException !== null) {
throw $buildException;
}
}

/**
Expand Down