From 0d5597e37fa7f247b5f42cc983accc710301b505 Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Mon, 22 May 2023 15:06:43 +0200 Subject: [PATCH] Fix repository indexing. --- README.md | 4 +- admin/README.txt | 4 +- componentbuilder.xml | 2 +- .../src/Componentbuilder/Compiler/Power.php | 8 ++ .../Compiler/Power/Infusion.php | 37 +++++++++ .../Compiler/Power/Repos/Readme.php | 80 +++---------------- .../Compiler/Power/Structure.php | 23 +++++- 7 files changed, 81 insertions(+), 77 deletions(-) diff --git a/README.md b/README.md index c7ba5f813..8604da1a1 100644 --- a/README.md +++ b/README.md @@ -144,11 +144,11 @@ TODO + *Author*: [Llewellyn van der Merwe](mailto:joomla@vdm.io) + *Name*: [Component Builder](https://git.vdm.dev/joomla/Component-Builder) + *First Build*: 30th April, 2015 -+ *Last Build*: 18th May, 2023 ++ *Last Build*: 22nd May, 2023 + *Version*: 3.1.24 + *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **563855** ++ *Line count*: **559431** + *Field count*: **2041** + *File count*: **3934** + *Folder count*: **432** diff --git a/admin/README.txt b/admin/README.txt index c7ba5f813..8604da1a1 100644 --- a/admin/README.txt +++ b/admin/README.txt @@ -144,11 +144,11 @@ TODO + *Author*: [Llewellyn van der Merwe](mailto:joomla@vdm.io) + *Name*: [Component Builder](https://git.vdm.dev/joomla/Component-Builder) + *First Build*: 30th April, 2015 -+ *Last Build*: 18th May, 2023 ++ *Last Build*: 22nd May, 2023 + *Version*: 3.1.24 + *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **563855** ++ *Line count*: **559431** + *Field count*: **2041** + *File count*: **3934** + *Folder count*: **432** diff --git a/componentbuilder.xml b/componentbuilder.xml index f6e06838b..04ef98e1a 100644 --- a/componentbuilder.xml +++ b/componentbuilder.xml @@ -1,7 +1,7 @@ COM_COMPONENTBUILDER - 18th May, 2023 + 22nd May, 2023 Llewellyn van der Merwe joomla@vdm.io https://dev.vdm.io diff --git a/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Power.php b/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Power.php index 115c10162..9c8ab17df 100644 --- a/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Power.php +++ b/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Power.php @@ -69,6 +69,14 @@ class Power implements PowerInterface **/ public array $superpowers = []; + /** + * Old super powers found in the local repos + * + * @var array + * @since 3.2.0 + **/ + public array $old_superpowers = []; + /** * The url to the power, if there is an error. * diff --git a/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Power/Infusion.php b/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Power/Infusion.php index c0dd35bf6..4b03a0c31 100644 --- a/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Power/Infusion.php +++ b/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Power/Infusion.php @@ -232,9 +232,18 @@ class Infusion array(&$context, &$path, &$key, &$powers) ); + // we add and all missing powers + if (isset($this->power->old_superpowers[$path])) + { + $this->mergePowers($powers, $this->power->old_superpowers[$path]); + } + // POWERREADME $this->content->set_($key, 'POWERREADME', $this->reposreadme->get($powers)); + // sort all powers + $this->sortPowers($powers); + // POWERINDEX $this->content->set_($key, 'POWERINDEX', $this->index($powers)); @@ -247,6 +256,34 @@ class Infusion } } + /** + * Merge the old missing powers found in local repository back into the index + * + * @return void + * @since 3.2.0 + */ + private function mergePowers(array &$powers, array &$old) + { + foreach ($old as $guid => $values) + { + if (!isset($powers[$guid])) + { + $powers[$guid] = $values; + } + } + } + + /** + * Sort Powers + * + * @return void + * @since 3.2.0 + */ + private function sortPowers(array &$powers) + { + ksort($powers, SORT_STRING); + } + /** * Set the Powers code * diff --git a/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Power/Repos/Readme.php b/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Power/Repos/Readme.php index d47ca4d41..d27d7ce32 100644 --- a/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Power/Repos/Readme.php +++ b/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Power/Repos/Readme.php @@ -123,18 +123,13 @@ class Readme $classes = []; foreach ($powers as $guid => $power) { - $power_object = $this->power->get($guid); - if (isset($power_object->parsed_class_code) && is_array($power_object->parsed_class_code)) - { - // add to the sort bucket - $classes[] = [ - 'namespace' => $power['namespace'], - 'type' => $power['type'], - 'name' => $power['name'], - 'link' => $this->indexLinkPower($power), - 'diagram' => $this->plantuml->classBasicDiagram($power, $power_object->parsed_class_code) - ]; - } + // add to the sort bucket + $classes[] = [ + 'namespace' => $power['namespace'], + 'type' => $power['type'], + 'name' => $power['name'], + 'link' => $this->indexLinkPower($power) + ]; } return $this->readmeModel($classes); @@ -152,11 +147,7 @@ class Readme { $this->sortClasses($classes, $this->defineTypeOrder()); - $result = $this->generateIndex($classes); - - $diagram_bucket = $this->generateDiagramBucket($classes); - - return $result . $diagram_bucket; + return $this->generateIndex($classes); } /** @@ -187,40 +178,6 @@ class Readme return $result; } - /** - * Generate the diagram bucket string for classes - * - * @param array $classes The sorted classes - * - * @return string The diagram bucket string - */ - private function generateDiagramBucket(array &$classes): string - { - $diagram_bucket = "\n\n# Class Diagrams\n"; - $current_namespace = null; - $diagrams = ''; - - foreach ($classes as $class) - { - if ($class['namespace'] !== $current_namespace) - { - if ($current_namespace !== null) - { - $diagram_bucket .= $this->generateNamespaceDiagram($current_namespace, $diagrams); - } - $current_namespace = $class['namespace']; - $diagrams = ''; - } - - $diagrams .= $class['diagram']; - } - - // Add the last namespace diagram - $diagram_bucket .= $this->generateNamespaceDiagram($current_namespace, $diagrams); - - return $diagram_bucket; - } - /** * Define the order of types for sorting purposes * @@ -318,24 +275,6 @@ class Readme return strcmp($a['name'], $b['name']); } - /** - * Generate a namespace diagram string - * - * @param string $current_namespace The current namespace - * @param string $diagrams The diagrams for the namespace - * - * @return string The namespace diagram string - */ - private function generateNamespaceDiagram(string $current_namespace, string $diagrams): string - { - $namespace_title = str_replace('\\', ' ', $current_namespace); - $diagram_code = "\n## {$namespace_title}\n> namespace {$current_namespace}\n"; - $diagram_code .= "```uml\n@startuml\n\n" . - $this->plantuml->namespaceDiagram($current_namespace, $diagrams) . "\n\n@enduml\n```\n"; - - return $diagram_code; - } - /** * Build the Link to the power in this repository * @@ -403,7 +342,6 @@ class Readme private function linkPowerSPK(array &$power): string { return $power['spk']; - } - + } } diff --git a/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Power/Structure.php b/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Power/Structure.php index 5549fd955..6178083d6 100644 --- a/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Power/Structure.php +++ b/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Power/Structure.php @@ -28,6 +28,8 @@ use VDM\Joomla\Componentbuilder\Compiler\Utilities\Files; use VDM\Joomla\Utilities\ObjectHelper; use VDM\Joomla\Utilities\ArrayHelper; use VDM\Joomla\Utilities\StringHelper; +use VDM\Joomla\Utilities\JsonHelper; +use VDM\Joomla\Utilities\FileHelper; use VDM\Joomla\Componentbuilder\Compiler\Utilities\Placefix; @@ -372,6 +374,9 @@ class Structure { foreach ($this->power->superpowers as $path => $powers) { + // get existing files + $this->loadExistingSuperPower($path); + // create the path if it does not exist $this->folder->create($path, false); @@ -424,6 +429,22 @@ class Structure } } } - + + /** + * Set the super power file paths + * + * @param string $repository The super power repository + * + * @return void + * @since 3.2.0 + */ + private function loadExistingSuperPower(string $repository) + { + if (($content = FileHelper::getContent($repository . '/super-powers.json', null)) !== null && + JsonHelper::check($content)) + { + $this->power->old_superpowers[$repository] = json_decode($content, true); + } + } }