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) + *Author*: [Llewellyn van der Merwe](mailto:joomla@vdm.io)
+ *Name*: [Component Builder](https://git.vdm.dev/joomla/Component-Builder) + *Name*: [Component Builder](https://git.vdm.dev/joomla/Component-Builder)
+ *First Build*: 30th April, 2015 + *First Build*: 30th April, 2015
+ *Last Build*: 18th May, 2023 + *Last Build*: 22nd May, 2023
+ *Version*: 3.1.24 + *Version*: 3.1.24
+ *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved. + *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved.
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt + *License*: GNU General Public License version 2 or later; see LICENSE.txt
+ *Line count*: **563855** + *Line count*: **559431**
+ *Field count*: **2041** + *Field count*: **2041**
+ *File count*: **3934** + *File count*: **3934**
+ *Folder count*: **432** + *Folder count*: **432**

View File

@ -144,11 +144,11 @@ TODO
+ *Author*: [Llewellyn van der Merwe](mailto:joomla@vdm.io) + *Author*: [Llewellyn van der Merwe](mailto:joomla@vdm.io)
+ *Name*: [Component Builder](https://git.vdm.dev/joomla/Component-Builder) + *Name*: [Component Builder](https://git.vdm.dev/joomla/Component-Builder)
+ *First Build*: 30th April, 2015 + *First Build*: 30th April, 2015
+ *Last Build*: 18th May, 2023 + *Last Build*: 22nd May, 2023
+ *Version*: 3.1.24 + *Version*: 3.1.24
+ *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved. + *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved.
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt + *License*: GNU General Public License version 2 or later; see LICENSE.txt
+ *Line count*: **563855** + *Line count*: **559431**
+ *Field count*: **2041** + *Field count*: **2041**
+ *File count*: **3934** + *File count*: **3934**
+ *Folder count*: **432** + *Folder count*: **432**

View File

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

View File

@ -69,6 +69,14 @@ class Power implements PowerInterface
**/ **/
public array $superpowers = []; 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. * The url to the power, if there is an error.
* *

View File

@ -232,9 +232,18 @@ class Infusion
array(&$context, &$path, &$key, &$powers) 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 // POWERREADME
$this->content->set_($key, 'POWERREADME', $this->reposreadme->get($powers)); $this->content->set_($key, 'POWERREADME', $this->reposreadme->get($powers));
// sort all powers
$this->sortPowers($powers);
// POWERINDEX // POWERINDEX
$this->content->set_($key, 'POWERINDEX', $this->index($powers)); $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 * Set the Powers code
* *

View File

@ -123,18 +123,13 @@ class Readme
$classes = []; $classes = [];
foreach ($powers as $guid => $power) foreach ($powers as $guid => $power)
{ {
$power_object = $this->power->get($guid); // add to the sort bucket
if (isset($power_object->parsed_class_code) && is_array($power_object->parsed_class_code)) $classes[] = [
{ 'namespace' => $power['namespace'],
// add to the sort bucket 'type' => $power['type'],
$classes[] = [ 'name' => $power['name'],
'namespace' => $power['namespace'], 'link' => $this->indexLinkPower($power)
'type' => $power['type'], ];
'name' => $power['name'],
'link' => $this->indexLinkPower($power),
'diagram' => $this->plantuml->classBasicDiagram($power, $power_object->parsed_class_code)
];
}
} }
return $this->readmeModel($classes); return $this->readmeModel($classes);
@ -152,11 +147,7 @@ class Readme
{ {
$this->sortClasses($classes, $this->defineTypeOrder()); $this->sortClasses($classes, $this->defineTypeOrder());
$result = $this->generateIndex($classes); return $this->generateIndex($classes);
$diagram_bucket = $this->generateDiagramBucket($classes);
return $result . $diagram_bucket;
} }
/** /**
@ -187,40 +178,6 @@ class Readme
return $result; 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 * Define the order of types for sorting purposes
* *
@ -318,24 +275,6 @@ class Readme
return strcmp($a['name'], $b['name']); 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 * Build the Link to the power in this repository
* *
@ -404,6 +343,5 @@ class Readme
{ {
return $power['spk']; 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\ObjectHelper;
use VDM\Joomla\Utilities\ArrayHelper; use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Utilities\StringHelper; use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Utilities\JsonHelper;
use VDM\Joomla\Utilities\FileHelper;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Placefix; use VDM\Joomla\Componentbuilder\Compiler\Utilities\Placefix;
@ -372,6 +374,9 @@ class Structure
{ {
foreach ($this->power->superpowers as $path => $powers) foreach ($this->power->superpowers as $path => $powers)
{ {
// get existing files
$this->loadExistingSuperPower($path);
// create the path if it does not exist // create the path if it does not exist
$this->folder->create($path, false); $this->folder->create($path, false);
@ -425,5 +430,21 @@ 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);
}
}
} }