Skip to content

Commit 169a92d

Browse files
committed
refactor the plugin stage calling code.
1 parent 03aeb7e commit 169a92d

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

PHPCI/Builder.php

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -165,31 +165,33 @@ public function execute()
165165
$this->build->sendStatusPostback();
166166
$this->success = true;
167167

168-
try {
169-
// Set up the build:
170-
$this->setupBuild();
168+
// Set up the build:
169+
$this->setupBuild();
171170

172-
// Run the core plugin stages:
173-
foreach (array('setup', 'test', 'complete') as $stage) {
174-
$this->success &= $this->pluginExecutor->executePlugins($this->config, $stage);
175-
}
171+
// Run the core plugin stages:
172+
foreach (array('setup', 'test') as $stage) {
173+
$this->success &= $this->pluginExecutor->executePlugins($this->config, $stage);
174+
}
176175

177-
// Failed build? Execute failure plugins and then mark the build as failed.
178-
if (!$this->success) {
179-
$this->pluginExecutor->executePlugins($this->config, 'failure');
180-
throw new \Exception('BUILD FAILED!');
181-
}
176+
// Set the status so this can be used by complete, success and failure
177+
// stages.
178+
if ($this->success) {
179+
$this->build->setStatus(Build::STATUS_SUCCESS);
180+
}
181+
else {
182+
$this->build->setStatus(Build::STATUS_FAILED);
183+
}
182184

183-
// If we got this far, the build was successful!
184-
if ($this->success) {
185-
$this->build->setStatus(Build::STATUS_SUCCESS);
186-
$this->pluginExecutor->executePlugins($this->config, 'success');
187-
$this->logSuccess('BUILD SUCCESSFUL!');
188-
}
185+
// Complete stage plugins are always run
186+
$this->pluginExecutor->executePlugins($this->config, 'complete');
189187

190-
} catch (\Exception $ex) {
191-
$this->logFailure($ex->getMessage(), $ex);
192-
$this->build->setStatus(Build::STATUS_FAILED);
188+
if ($this->success) {
189+
$this->pluginExecutor->executePlugins($this->config, 'success');
190+
$this->logSuccess('BUILD SUCCESSFUL!');
191+
}
192+
else {
193+
$this->pluginExecutor->executePlugins($this->config, 'failure');
194+
$this->logFailure("BUILD FAILURE");
193195
}
194196

195197
// Clean up:

0 commit comments

Comments
 (0)