diff --git a/.gitignore b/.gitignore index 3001e63..c788e08 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ +composer.lock + +custom.type.properties +custom.task.properties + .buildpath .DS_Store .idea @@ -6,7 +11,6 @@ .*.sw* .*.un~ build/ -composer.lock nbproject tmp/ -/vendor \ No newline at end of file +/vendor diff --git a/composer.json b/composer.json index 71a9251..990dd30 100644 --- a/composer.json +++ b/composer.json @@ -10,13 +10,23 @@ "email": "matthias@krauser.eu" } ], + "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 + } } -} \ No newline at end of file +} diff --git a/src/ForeachParallelTask.php b/src/ForeachParallelTask.php index 2145ada..cc2e40a 100644 --- a/src/ForeachParallelTask.php +++ b/src/ForeachParallelTask.php @@ -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; /** * task @@ -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; @@ -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() { @@ -116,6 +124,7 @@ private function getCallee() $callee->setTaskName($this->getTaskName()); $callee->setLocation($this->getLocation()); $callee->init(); + $this->callee = $callee; return $callee; } @@ -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; @@ -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); @@ -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) ); @@ -198,9 +205,9 @@ 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); } @@ -208,21 +215,23 @@ public function main() $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; @@ -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) ); @@ -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 = ""; @@ -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) ); @@ -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; } /** @@ -363,7 +374,7 @@ 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); @@ -371,7 +382,7 @@ public function createMapper() } /** - * @return Property + * @return PropertyTask */ public function createProperty() { @@ -386,6 +397,6 @@ public function createFileList() { $num = array_push($this->filelists, new FileList()); - return $this->filelists[$num-1]; + return $this->filelists[$num - 1]; } }