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

updated phing to 3 version #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
composer.lock

custom.type.properties
custom.task.properties

.buildpath
.DS_Store
.idea
Expand All @@ -6,7 +11,6 @@
.*.sw*
.*.un~
build/
composer.lock
nbproject
tmp/
/vendor
/vendor
16 changes: 13 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,23 @@
"email": "[email protected]"
}
],
"prefer-stable": true,
"minimum-stability": "dev",
"require": {
"php": ">=5.3",
"phing/phing": ">=2.7.0"
"php": "^7.3 || ^7.4 || ^8.0 || ^8.1 || ^8.2 || ^8.3",
"ext-json": "*",
"mehr-als-nix/parallel": "^1.0",
"phing/phing": "*"
},
"autoload": {
"psr-4": {
"MaK\\Phing\\Task\\": "src/"
}
},
"config": {
"sort-packages": true,
"allow-plugins": {
"phing/phing-composer-configurator": true
}
}
}
}
93 changes: 52 additions & 41 deletions src/ForeachParallelTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@

namespace MaK\Phing\Task;

use \BuildException;
use \FileList;
use \FileSet;
use \Mapper;
use \PhingFile;
use \Project;
use \Task;

use \DocBlox_Parallel_Manager,
\DocBlox_Parallel_Worker;
use MehrAlsNix\Parallel\Manager;
use MehrAlsNix\Parallel\Worker;
use Phing\Exception\BuildException;
use Phing\Io\File;
use Phing\Io\FileSystem;
use Phing\Project;
use Phing\Task;
use Phing\Task\System\PhingTask;
use Phing\Task\System\PropertyTask;
use Phing\Type\FileList;
use Phing\Type\FileSet;
use Phing\Type\Mapper;

/**
* <foreach_parallel> task
Expand Down Expand Up @@ -63,6 +65,12 @@
*/
class ForeachParallelTask extends Task
{
/**
* The called Phing task.
*
* @var PhingTask
*/
private $callee;

/** Delimter-separated list of values to process. */
private $list;
Expand Down Expand Up @@ -107,7 +115,7 @@ class ForeachParallelTask extends Task
* Total number of directories processed
* @var integer
*/
private $total_dirs = 0;
private $total_dirs = 0;

private function getCallee()
{
Expand All @@ -116,6 +124,7 @@ private function getCallee()
$callee->setTaskName($this->getTaskName());
$callee->setLocation($this->getLocation());
$callee->init();
$this->callee = $callee;

return $callee;
}
Expand All @@ -136,17 +145,14 @@ public function main()
throw new BuildException("You must supply a target to perform");
}

@include_once 'phing/contrib/DocBlox/Parallel/Manager.php';
@include_once 'phing/contrib/DocBlox/Parallel/Worker.php';
@include_once 'phing/contrib/DocBlox/Parallel/WorkerPipe.php';
if (!class_exists('DocBlox_Parallel_Worker')) {
if (!class_exists(Worker::class)) {
throw new BuildException(
'ForeachParallelTask depends on DocBlox being installed and on include_path.',
'ForeachParallelTask depends on phpDocumentor/Parallel being installed and on include_path.',
$this->getLocation()
);
}

$parallelManager = new DocBlox_Parallel_Manager();
$parallelManager = new Manager();
$parallelManager->setProcessLimit($this->threadCount);

$mapper = null;
Expand All @@ -170,7 +176,8 @@ public function main()
}
$value = array_shift($value);
}
$this->log("Setting param '$this->param' to value '$value'" . ($premapped ? " (mapped from '$premapped')" : ''), Project::MSG_VERBOSE);
$this->log("Setting param '$this->param' to value '$value'" . ($premapped ? " (mapped from '$premapped')" : ''),
Project::MSG_VERBOSE);
$callee = $this->getCallee();
$callee->setTarget($this->calleeTarget);
$callee->setInheritAll(true);
Expand All @@ -180,7 +187,7 @@ public function main()
$prop->setOverride(true);
$prop->setName($this->param);
$prop->setValue($value);
$worker = new DocBlox_Parallel_Worker(
$worker = new Worker(
array($callee, 'main'),
array($callee)
);
Expand All @@ -198,31 +205,33 @@ public function main()

// filesets
foreach ($this->filesets as $fs) {
$ds = $fs->getDirectoryScanner($this->project);
$ds = $fs->getDirectoryScanner($this->project);
$srcFiles = $ds->getIncludedFiles();
$srcDirs = $ds->getIncludedDirectories();
$srcDirs = $ds->getIncludedDirectories();

$this->process($parallelManager, $this->getCallee(), $fs->getDir($this->project), $srcFiles, $srcDirs);
}

$parallelManager->execute();

if ($this->list === null) {
$this->log("Processed {$this->total_dirs} directories and {$this->total_files} files", Project::MSG_VERBOSE);
$this->log("Processed {$this->total_dirs} directories and {$this->total_files} files",
Project::MSG_VERBOSE);
} else {
$this->log("Processed $total_entries entr" . ($total_entries > 1 ? 'ies' : 'y') . " in list", Project::MSG_VERBOSE);
$this->log("Processed $total_entries entr" . ($total_entries > 1 ? 'ies' : 'y') . " in list",
Project::MSG_VERBOSE);
}
}

/**
* Processes a list of files & directories
*
* @param Task $callee
* @param PhingFile $fromDir
* @param array $srcFiles
* @param array $srcDirs
* @param Task $callee
* @param File $fromDir
* @param array $srcFiles
* @param array $srcDirs
*/
protected function process(DocBlox_Parallel_Manager $parallelManager, Task $callee, PhingFile $fromDir, $srcFiles, $srcDirs)
protected function process(Manager $parallelManager, Task $callee, File $fromDir, $srcFiles, $srcDirs)
{
$mapper = null;

Expand Down Expand Up @@ -254,14 +263,15 @@ protected function process(DocBlox_Parallel_Manager $parallelManager, Task $call
}

if ($this->param) {
$this->log("Setting param '$this->param' to value '$value'" . ($premapped ? " (mapped from '$premapped')" : ''), Project::MSG_VERBOSE);
$this->log("Setting param '$this->param' to value '$value'" . ($premapped ? " (mapped from '$premapped')" : ''),
Project::MSG_VERBOSE);
$prop = $callee->createProperty();
$prop->setOverride(true);
$prop->setName($this->param);
$prop->setValue($value);
}

$worker = new DocBlox_Parallel_Worker(
$worker = new Worker(
array($callee, 'main'),
array($callee)
);
Expand All @@ -272,7 +282,7 @@ protected function process(DocBlox_Parallel_Manager $parallelManager, Task $call
$dircount = count($srcDirs);
$this->total_dirs += $dircount;

for ($j = 0; $j < $dircount; $j++) {
for ($j = 0; $j < $dircount; $j++) {
$value = $srcDirs[$j];
$premapped = "";

Expand All @@ -293,14 +303,15 @@ protected function process(DocBlox_Parallel_Manager $parallelManager, Task $call
}

if ($this->param) {
$this->log("Setting param '$this->param' to value '$value'" . ($premapped ? " (mapped from '$premapped')" : ''), Project::MSG_VERBOSE);
$this->log("Setting param '$this->param' to value '$value'" . ($premapped ? " (mapped from '$premapped')" : ''),
Project::MSG_VERBOSE);
$prop = $callee->createProperty();
$prop->setOverride(true);
$prop->setName($this->param);
$prop->setValue($value);
}

$worker = new DocBlox_Parallel_Worker(
$worker = new Worker(
array($callee, 'main'),
array($callee)
);
Expand All @@ -311,27 +322,27 @@ protected function process(DocBlox_Parallel_Manager $parallelManager, Task $call

public function setList($list)
{
$this->list = (string) $list;
$this->list = (string)$list;
}

public function setTarget($target)
{
$this->calleeTarget = (string) $target;
$this->calleeTarget = (string)$target;
}

public function setParam($param)
{
$this->param = (string) $param;
$this->param = (string)$param;
}

public function setAbsparam($absparam)
{
$this->absparam = (string) $absparam;
$this->absparam = (string)$absparam;
}

public function setDelimiter($delimiter)
{
$this->delimiter = (string) $delimiter;
$this->delimiter = (string)$delimiter;
}

/**
Expand Down Expand Up @@ -363,15 +374,15 @@ public function addFileSet(FileSet $fs)
public function createMapper()
{
if ($this->mapperElement !== null) {
throw new BuildException("Cannot define more than one mapper", $this->location);
throw new BuildException("Cannot define more than one mapper", $this->getLocation());
}
$this->mapperElement = new Mapper($this->project);

return $this->mapperElement;
}

/**
* @return Property
* @return PropertyTask
*/
public function createProperty()
{
Expand All @@ -386,6 +397,6 @@ public function createFileList()
{
$num = array_push($this->filelists, new FileList());

return $this->filelists[$num-1];
return $this->filelists[$num - 1];
}
}