Fix repository indexing.

This commit is contained in:
Llewellyn van der Merwe 2023-05-22 15:06:43 +02:00
parent 407a8aa345
commit 0d5597e37f
Signed by untrusted user: Llewellyn
GPG Key ID: A9201372263741E7
7 changed files with 81 additions and 77 deletions

View File

@ -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**

View File

@ -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**

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="4" method="upgrade">
<name>COM_COMPONENTBUILDER</name>
<creationDate>18th May, 2023</creationDate>
<creationDate>22nd May, 2023</creationDate>
<author>Llewellyn van der Merwe</author>
<authorEmail>joomla@vdm.io</authorEmail>
<authorUrl>https://dev.vdm.io</authorUrl>

View File

@ -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.
*

View File

@ -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
*

View File

@ -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'];
}
}
}

View File

@ -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);
}
}
}