Example #1
0
 /**
  * Executes a given plugin, with options and returns the result.
  */
 public function executePlugin($plugin, $options)
 {
     // Any plugin name without a namespace separator is a PHPCI built in plugin
     // if not we assume it's a fully name-spaced class name that implements the plugin interface.
     // If not the factory will throw an exception.
     if (strpos($plugin, '\\') === false) {
         $class = str_replace('_', ' ', $plugin);
         $class = ucwords($class);
         $class = 'PHPCI\\Plugin\\' . str_replace(' ', '', $class);
     } else {
         $class = $plugin;
     }
     if (!class_exists($class)) {
         $this->logger->logFailure(Lang::get('plugin_missing', $plugin));
         return false;
     }
     $rtn = true;
     // Try running it:
     try {
         $obj = $this->pluginFactory->buildPlugin($class, $options);
         if (!$obj->execute()) {
             $rtn = false;
         }
     } catch (\Exception $ex) {
         $this->logger->logFailure(Lang::get('exception') . $ex->getMessage(), $ex);
         $rtn = false;
     }
     return $rtn;
 }
Example #2
0
 public function testLogFailure_AddsExceptionContext()
 {
     $message = "Testing";
     $exception = new \Exception("Expected Exception");
     $this->mockLogger->log(Argument::type('string'), Argument::type('string'), Argument::withEntry('exception', $exception))->shouldBeCalledTimes(1);
     $this->testedBuildLogger->logFailure($message, $exception);
 }
Example #3
0
 /**
  * Find a binary required by a plugin.
  * @param string $binary
  * @param null $buildPath
  * @return null|string
  */
 public function findBinary($binary, $buildPath = null)
 {
     $binaryPath = null;
     $composerBin = $this->getComposerBinDir(realpath($buildPath));
     if (is_string($binary)) {
         $binary = array($binary);
     }
     foreach ($binary as $bin) {
         $this->logger->log("Looking for binary: " . $bin, LogLevel::DEBUG);
         if (is_dir($composerBin) && is_file($composerBin . '/' . $bin)) {
             $this->logger->log("Found in " . $composerBin . ": " . $bin, LogLevel::DEBUG);
             $binaryPath = $composerBin . '/' . $bin;
             break;
         }
         if (is_file($this->rootDir . $bin)) {
             $this->logger->log("Found in root: " . $bin, LogLevel::DEBUG);
             $binaryPath = $this->rootDir . $bin;
             break;
         }
         if (is_file($this->rootDir . 'vendor/bin/' . $bin)) {
             $this->logger->log("Found in vendor/bin: " . $bin, LogLevel::DEBUG);
             $binaryPath = $this->rootDir . 'vendor/bin/' . $bin;
             break;
         }
         $findCmdResult = $this->findGlobalBinary($bin);
         if (is_file($findCmdResult)) {
             $this->logger->log("Found in " . $findCmdResult, LogLevel::DEBUG);
             $binaryPath = $findCmdResult;
             break;
         }
     }
     return $binaryPath;
 }
Example #4
0
 /**
  * Find a binary required by a plugin.
  * @param string $binary
  * @param null $buildPath
  * @return null|string
  */
 public function findBinary($binary, $buildPath = null)
 {
     $binaryPath = null;
     $composerBin = $this->getComposerBinDir(realpath($buildPath));
     if (is_string($binary)) {
         $binary = array($binary);
     }
     foreach ($binary as $bin) {
         $this->logger->log(Lang::get('looking_for_binary', $bin), LogLevel::DEBUG);
         if (is_dir($composerBin) && is_file($composerBin . '/' . $bin)) {
             $this->logger->log(Lang::get('found_in_path', $composerBin, $bin), LogLevel::DEBUG);
             $binaryPath = $composerBin . '/' . $bin;
             break;
         }
         if (is_file($this->rootDir . $bin)) {
             $this->logger->log(Lang::get('found_in_path', 'root', $bin), LogLevel::DEBUG);
             $binaryPath = $this->rootDir . $bin;
             break;
         }
         if (is_file($this->rootDir . 'vendor/bin/' . $bin)) {
             $this->logger->log(Lang::get('found_in_path', 'vendor/bin', $bin), LogLevel::DEBUG);
             $binaryPath = $this->rootDir . 'vendor/bin/' . $bin;
             break;
         }
         $findCmdResult = $this->findGlobalBinary($bin);
         if (is_file($findCmdResult)) {
             $this->logger->log(Lang::get('found_in_path', '', $bin), LogLevel::DEBUG);
             $binaryPath = $findCmdResult;
             break;
         }
     }
     return $binaryPath;
 }
Example #5
0
 /**
  * Find a binary required by a plugin.
  * @param string $binary
  * @param bool $quiet
  * @return null|string
  */
 public function findBinary($binary, $quiet = false, $options = array())
 {
     $composerBin = $this->getComposerBinDir(realpath($this->buildPath));
     if (is_string($binary)) {
         $binary = array($binary);
     }
     //Set default binary paths
     $binPaths = array($composerBin . '/', $this->rootDir, $this->rootDir . 'vendor/bin/');
     if (!empty($options['path'])) {
         $binPaths[] = $options['path'] . '/';
         $binPaths[] = $this->rootDir . $options['path'] . '/';
         $binPaths[] = $this->buildPath . $options['path'] . '/';
     }
     foreach ($binary as $bin) {
         $this->logger->log(Lang::get('looking_for_binary', $bin), LogLevel::DEBUG);
         foreach ($binPaths as $path) {
             if (is_dir($path) && is_file($path . $bin)) {
                 $this->logger->log(Lang::get('found_in_path', $path, $bin), LogLevel::DEBUG);
                 return $path . $bin;
             }
         }
         $findCmdResult = $this->findGlobalBinary($bin);
         if (is_file($findCmdResult)) {
             $this->logger->log(Lang::get('found_in_path', '', $bin), LogLevel::DEBUG);
             return $findCmdResult;
         }
     }
     if ($quiet) {
         return;
     }
     throw new Exception(Lang::get('could_not_find', implode('/', $binary)));
 }
 /**
  * Find a binary required by a plugin.
  * @param string $binary
  * @param bool $quiet
  * @return null|string
  */
 public function findBinary($binary, $quiet = false)
 {
     $composerBin = $this->getComposerBinDir(realpath($this->buildPath));
     if (is_string($binary)) {
         $binary = array($binary);
     }
     foreach ($binary as $bin) {
         $this->logger->log(Lang::get('looking_for_binary', $bin), LogLevel::DEBUG);
         if (is_dir($composerBin) && is_file($composerBin . '/' . $bin)) {
             $this->logger->log(Lang::get('found_in_path', $composerBin, $bin), LogLevel::DEBUG);
             return $composerBin . '/' . $bin;
         }
         if (is_file($this->rootDir . $bin)) {
             $this->logger->log(Lang::get('found_in_path', 'root', $bin), LogLevel::DEBUG);
             return $this->rootDir . $bin;
         }
         if (is_file($this->rootDir . 'vendor/bin/' . $bin)) {
             $this->logger->log(Lang::get('found_in_path', 'vendor/bin', $bin), LogLevel::DEBUG);
             return $this->rootDir . 'vendor/bin/' . $bin;
         }
         $findCmdResult = $this->findGlobalBinary($bin);
         if (is_file($findCmdResult)) {
             $this->logger->log(Lang::get('found_in_path', '', $bin), LogLevel::DEBUG);
             return $findCmdResult;
         }
     }
     if ($quiet) {
         return;
     }
     throw new Exception(Lang::get('could_not_find', implode('/', $binary)));
 }
Example #7
0
 /**
  * Add a failure-coloured message to the log.
  * @param string $message
  * @param \Exception $exception The exception that caused the error.
  */
 public function logFailure($message, \Exception $exception = null)
 {
     $this->buildLogger->logFailure($message, $exception);
 }