Removed hacks for Windows OS (Because it isn't work fine all the same)
This commit is contained in:
parent
7e735bbb3b
commit
8779880a8f
23 changed files with 36 additions and 240 deletions
|
|
@ -113,11 +113,7 @@ class Builder implements LoggerAwareInterface
|
|||
$pluginFactory = $this->buildPluginFactory($build);
|
||||
$this->pluginExecutor = new Plugin\Util\Executor($pluginFactory, $this->buildLogger);
|
||||
|
||||
$executorClass = 'PHPCensor\Helper\UnixCommandExecutor';
|
||||
if (IS_WIN) {
|
||||
$executorClass = 'PHPCensor\Helper\WindowsCommandExecutor';
|
||||
}
|
||||
|
||||
$executorClass = 'PHPCensor\Helper\UnixCommandExecutor';
|
||||
$this->commandExecutor = new $executorClass(
|
||||
$this->buildLogger,
|
||||
ROOT_DIR,
|
||||
|
|
|
|||
|
|
@ -22,16 +22,7 @@ class SshKey
|
|||
public function generate()
|
||||
{
|
||||
$tempPath = sys_get_temp_dir() . '/';
|
||||
|
||||
// FastCGI fix for Windows machines, where temp path is not available to
|
||||
// PHP, and defaults to the unwritable system directory. If the temp
|
||||
// path is pointing to the system directory, shift to the 'TEMP'
|
||||
// sub-folder, which should also exist, but actually be writable.
|
||||
if (IS_WIN && $tempPath == getenv("SystemRoot") . '/') {
|
||||
$tempPath = getenv("SystemRoot") . '/TEMP/';
|
||||
}
|
||||
|
||||
$keyFile = $tempPath . md5(microtime(true));
|
||||
$keyFile = $tempPath . md5(microtime(true));
|
||||
|
||||
if (!is_dir($tempPath)) {
|
||||
mkdir($tempPath);
|
||||
|
|
|
|||
|
|
@ -1,30 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2014, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCensor\Helper;
|
||||
|
||||
/**
|
||||
* Windows-specific extension of the CommandExecutor class.
|
||||
* @package PHPCensor\Helper
|
||||
*/
|
||||
class WindowsCommandExecutor extends BaseCommandExecutor
|
||||
{
|
||||
/**
|
||||
* Use 'where' on Windows to find a binary, rather than 'which'
|
||||
* @param string $binary
|
||||
* @return null|string
|
||||
*/
|
||||
protected function findGlobalBinary($binary)
|
||||
{
|
||||
$command = sprintf('where %s', $binary);
|
||||
$result = shell_exec($command);
|
||||
|
||||
return trim($result);
|
||||
}
|
||||
}
|
||||
|
|
@ -272,9 +272,9 @@ class Build extends BuildBase
|
|||
|
||||
if (is_link($buildPath)) {
|
||||
// Remove the symlink without using recursive.
|
||||
exec(sprintf(IS_WIN ? 'rmdir /S /Q "%s"' : 'rm "%s"', $buildPath));
|
||||
exec(sprintf('rm "%s"', $buildPath));
|
||||
} else {
|
||||
exec(sprintf(IS_WIN ? 'rmdir /S /Q "%s"' : 'rm -Rf "%s"', $buildPath));
|
||||
exec(sprintf('rm -Rf "%s"', $buildPath));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,9 +47,6 @@ class LocalBuild extends Build
|
|||
return $this->handleSymlink($builder, $reference, $buildPath);
|
||||
} else {
|
||||
$cmd = 'cp -Rf "%s" "%s/"';
|
||||
if (IS_WIN) {
|
||||
$cmd = 'xcopy /E /Y "%s" "%s/*"';
|
||||
}
|
||||
$builder->executeCommand($cmd, $reference, $buildPath);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -77,11 +77,8 @@ class RemoteGitBuild extends Build
|
|||
*/
|
||||
protected function cloneBySsh(Builder $builder, $cloneTo)
|
||||
{
|
||||
$keyFile = $this->writeSshKey($cloneTo);
|
||||
|
||||
if (!IS_WIN) {
|
||||
$gitSshWrapper = $this->writeSshWrapper($cloneTo, $keyFile);
|
||||
}
|
||||
$keyFile = $this->writeSshKey($cloneTo);
|
||||
$gitSshWrapper = $this->writeSshWrapper($cloneTo, $keyFile);
|
||||
|
||||
// Do the git clone:
|
||||
$cmd = 'git clone --recursive ';
|
||||
|
|
@ -93,10 +90,7 @@ class RemoteGitBuild extends Build
|
|||
}
|
||||
|
||||
$cmd .= ' -b %s %s "%s"';
|
||||
|
||||
if (!IS_WIN) {
|
||||
$cmd = 'export GIT_SSH="'.$gitSshWrapper.'" && ' . $cmd;
|
||||
}
|
||||
$cmd = 'export GIT_SSH="'.$gitSshWrapper.'" && ' . $cmd;
|
||||
|
||||
$success = $builder->executeCommand($cmd, $this->getBranch(), $this->getCloneUrl(), $cloneTo);
|
||||
|
||||
|
|
@ -106,9 +100,7 @@ class RemoteGitBuild extends Build
|
|||
|
||||
// Remove the key file and git wrapper:
|
||||
unlink($keyFile);
|
||||
if (!IS_WIN) {
|
||||
unlink($gitSshWrapper);
|
||||
}
|
||||
unlink($gitSshWrapper);
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
|
@ -122,9 +114,8 @@ class RemoteGitBuild extends Build
|
|||
protected function postCloneSetup(Builder $builder, $cloneTo)
|
||||
{
|
||||
$success = true;
|
||||
$commit = $this->getCommitId();
|
||||
|
||||
$chdir = IS_WIN ? 'cd /d "%s"' : 'cd "%s"';
|
||||
$commit = $this->getCommitId();
|
||||
$chdir = 'cd "%s"';
|
||||
|
||||
if (!empty($commit) && $commit != 'Manual') {
|
||||
$cmd = $chdir . ' && git checkout %s --quiet';
|
||||
|
|
|
|||
|
|
@ -119,19 +119,15 @@ class SubversionBuild extends Build
|
|||
{
|
||||
$cmd = $this->svnCommand . ' %s "%s"';
|
||||
|
||||
if (!IS_WIN) {
|
||||
$keyFile = $this->writeSshKey($cloneTo);
|
||||
$sshWrapper = $this->writeSshWrapper($cloneTo, $keyFile);
|
||||
$cmd = 'export SVN_SSH="' . $sshWrapper . '" && ' . $cmd;
|
||||
}
|
||||
$keyFile = $this->writeSshKey($cloneTo);
|
||||
$sshWrapper = $this->writeSshWrapper($cloneTo, $keyFile);
|
||||
$cmd = 'export SVN_SSH="' . $sshWrapper . '" && ' . $cmd;
|
||||
|
||||
$success = $builder->executeCommand($cmd, $this->getCloneUrl(), $cloneTo);
|
||||
|
||||
if (!IS_WIN) {
|
||||
// Remove the key file and svn wrapper:
|
||||
unlink($keyFile);
|
||||
unlink($sshWrapper);
|
||||
}
|
||||
// Remove the key file and svn wrapper:
|
||||
unlink($keyFile);
|
||||
unlink($sshWrapper);
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,9 +49,7 @@ class CleanBuild extends Plugin
|
|||
public function execute()
|
||||
{
|
||||
$cmd = 'rm -Rf "%s"';
|
||||
if (IS_WIN) {
|
||||
$cmd = 'rmdir /S /Q "%s"';
|
||||
}
|
||||
|
||||
$this->builder->executeCommand($cmd, $this->builder->buildPath . 'composer.phar');
|
||||
$this->builder->executeCommand($cmd, $this->builder->buildPath . 'composer.lock');
|
||||
|
||||
|
|
|
|||
|
|
@ -129,10 +129,6 @@ class Codeception extends Plugin implements ZeroConfigPluginInterface
|
|||
|
||||
$cmd = 'cd "%s" && ' . $codeception . ' run -c "%s" --xml ' . $this->args;
|
||||
|
||||
if (IS_WIN) {
|
||||
$cmd = 'cd /d "%s" && ' . $codeception . ' run -c "%s" --xml ' . $this->args;
|
||||
}
|
||||
|
||||
$configPath = $this->builder->buildPath . $configPath;
|
||||
$success = $this->builder->executeCommand($cmd, $this->builder->buildPath, $configPath);
|
||||
|
||||
|
|
|
|||
|
|
@ -104,14 +104,7 @@ class Composer extends Plugin implements ZeroConfigPluginInterface
|
|||
public function execute()
|
||||
{
|
||||
$composerLocation = $this->builder->findBinary(['composer', 'composer.phar']);
|
||||
|
||||
$cmd = '';
|
||||
|
||||
if (IS_WIN) {
|
||||
$cmd = 'php ';
|
||||
}
|
||||
|
||||
$cmd .= $composerLocation . ' --no-ansi --no-interaction ';
|
||||
$cmd = $composerLocation . ' --no-ansi --no-interaction ';
|
||||
|
||||
if ($this->preferDist) {
|
||||
$this->builder->log('Using --prefer-dist flag');
|
||||
|
|
|
|||
|
|
@ -62,9 +62,6 @@ class CopyBuild extends Plugin
|
|||
$this->wipeExistingDirectory();
|
||||
|
||||
$cmd = 'mkdir -p "%s" && cp -R "%s" "%s"';
|
||||
if (IS_WIN) {
|
||||
$cmd = 'mkdir -p "%s" && xcopy /E "%s" "%s"';
|
||||
}
|
||||
|
||||
$success = $this->builder->executeCommand($cmd, $this->directory, $build, $this->directory);
|
||||
|
||||
|
|
@ -97,9 +94,6 @@ class CopyBuild extends Plugin
|
|||
if ($this->ignore) {
|
||||
foreach ($this->builder->ignore as $file) {
|
||||
$cmd = 'rm -Rf "%s/%s"';
|
||||
if (IS_WIN) {
|
||||
$cmd = 'rmdir /S /Q "%s\%s"';
|
||||
}
|
||||
$this->builder->executeCommand($cmd, $this->directory, $file);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,18 +74,12 @@ class Grunt extends Plugin
|
|||
{
|
||||
// if npm does not work, we cannot use grunt, so we return false
|
||||
$cmd = 'cd %s && npm install';
|
||||
if (IS_WIN) {
|
||||
$cmd = 'cd /d %s && npm install';
|
||||
}
|
||||
if (!$this->builder->executeCommand($cmd, $this->directory)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// build the grunt command
|
||||
$cmd = 'cd %s && ' . $this->grunt;
|
||||
if (IS_WIN) {
|
||||
$cmd = 'cd /d %s && ' . $this->grunt;
|
||||
}
|
||||
$cmd .= ' --no-color';
|
||||
$cmd .= ' --gruntfile %s';
|
||||
$cmd .= ' %s'; // the task that will be executed
|
||||
|
|
|
|||
|
|
@ -74,18 +74,12 @@ class Gulp extends Plugin
|
|||
{
|
||||
// if npm does not work, we cannot use gulp, so we return false
|
||||
$cmd = 'cd %s && npm install';
|
||||
if (IS_WIN) {
|
||||
$cmd = 'cd /d %s && npm install';
|
||||
}
|
||||
if (!$this->builder->executeCommand($cmd, $this->directory)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// build the gulp command
|
||||
$cmd = 'cd %s && ' . $this->gulp;
|
||||
if (IS_WIN) {
|
||||
$cmd = 'cd /d %s && ' . $this->gulp;
|
||||
}
|
||||
$cmd .= ' --no-color';
|
||||
$cmd .= ' --gulpfile %s';
|
||||
$cmd .= ' %s'; // the task that will be executed
|
||||
|
|
|
|||
|
|
@ -55,11 +55,10 @@ class Wipe extends Plugin
|
|||
}
|
||||
if (is_dir($this->directory)) {
|
||||
$cmd = 'rm -Rf "%s"';
|
||||
if (IS_WIN) {
|
||||
$cmd = 'rmdir /S /Q "%s"';
|
||||
}
|
||||
|
||||
return $this->builder->executeCommand($cmd, $this->directory);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,18 +42,14 @@ class Factory
|
|||
* Check PosixProcessControl, WindowsProcessControl and UnixProcessControl, in that order.
|
||||
*
|
||||
* @return ProcessControlInterface
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function createProcessControl()
|
||||
{
|
||||
switch (true) {
|
||||
case PosixProcessControl::isAvailable():
|
||||
return new PosixProcessControl();
|
||||
|
||||
case WindowsProcessControl::isAvailable():
|
||||
return new WindowsProcessControl();
|
||||
|
||||
case UnixProcessControl::isAvailable():
|
||||
return new UnixProcessControl();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,56 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2015, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCensor\ProcessControl;
|
||||
|
||||
/**
|
||||
* Control processes using the "tasklist" and "taskkill" commands.
|
||||
*
|
||||
* @author Adirelle <adirelle@gmail.com>
|
||||
*/
|
||||
class WindowsProcessControl implements ProcessControlInterface
|
||||
{
|
||||
/**
|
||||
* Check if the process is running using the "tasklist" command.
|
||||
*
|
||||
* @param integer $pid
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isRunning($pid)
|
||||
{
|
||||
$lastLine = exec(sprintf('tasklist /fi "PID eq %d" /nh /fo csv 2>nul:', $pid));
|
||||
$record = str_getcsv($lastLine);
|
||||
return isset($record[1]) && intval($record[1]) === $pid;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function kill($pid, $forcefully = false)
|
||||
{
|
||||
$result = 1;
|
||||
|
||||
exec(sprintf("taskkill /t /pid %d %s 2>nul:", $pid, $forcefully ? '/f' : ''));
|
||||
|
||||
return !$result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the commands "tasklist" and "taskkill" are available.
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public static function isAvailable()
|
||||
{
|
||||
return DIRECTORY_SEPARATOR === '\\' && exec("where tasklist") && exec("where taskkill");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue