- Corrected code-smell and code style issues in \ncc\Objects > Package
- Corrected code-smell and code style issues in `\ncc\Classes\NccExtension > PackageCompiler` - Corrected code-smell and code style issues in `\ncc\CLI > PackageManagerMenu` - Corrected code-smell and code style issues in `\ncc\Classes\PhpExtension > PhpCompiler` - Corrected code-smell and code style issues in `\ncc\Classes\PhpExtension > PhpInstaller` - Corrected code-smell and code style issues in `\ncc\Classes\PhpExtension > PhpRunner` - Corrected code-smell and code style issues in `\ncc\Objects > ProjectConfiguraiton` - Corrected code-smell and code style issues in `\ncc\Managers > ProjectManager` - Corrected code-smell and code style issues in `\ncc\Classes\Extensions\PythonExtension > Python2Runner` - Corrected code-smell and code style issues in `\ncc\Classes\Extensions\PythonExtension > Python3Runner` - Corrected code-smell and code style issues in `\ncc\Classes\Extensions\PythonExtension > PythonRunner` - Corrected code-smell and code style issues in `\ncc\Interfaces > RunnerInterface`
This commit is contained in:
parent
0820cd3c32
commit
57009c115f
20 changed files with 994 additions and 700 deletions
12
CHANGELOG.md
12
CHANGELOG.md
|
@ -67,6 +67,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- Corrected code-smell and code style issues in `\ncc\Utilities > IO`
|
||||
- Corrected code-smell and code style issues in `\ncc > ncc`
|
||||
- Corrected code-smell and code style issues in `\ncc\CLI > Main`
|
||||
- Corrected code-smell and code style issues in `\ncc\Objects > Package`
|
||||
- Corrected code-smell and code style issues in `\ncc\Classes\NccExtension > PackageCompiler`
|
||||
- Corrected code-smell and code style issues in `\ncc\CLI > PackageManagerMenu`
|
||||
- Corrected code-smell and code style issues in `\ncc\Classes\PhpExtension > PhpCompiler`
|
||||
- Corrected code-smell and code style issues in `\ncc\Classes\PhpExtension > PhpInstaller`
|
||||
- Corrected code-smell and code style issues in `\ncc\Classes\PhpExtension > PhpRunner`
|
||||
- Corrected code-smell and code style issues in `\ncc\Objects > ProjectConfiguraiton`
|
||||
- Corrected code-smell and code style issues in `\ncc\Managers > ProjectManager`
|
||||
- Corrected code-smell and code style issues in `\ncc\Classes\Extensions\PythonExtension > Python2Runner`
|
||||
- Corrected code-smell and code style issues in `\ncc\Classes\Extensions\PythonExtension > Python3Runner`
|
||||
- Corrected code-smell and code style issues in `\ncc\Classes\Extensions\PythonExtension > PythonRunner`
|
||||
- Corrected code-smell and code style issues in `\ncc\Interfaces > RunnerInterface`
|
||||
|
||||
## Removed
|
||||
- Removed `FileNotFoundException` and `DirectoryNotFoundException` from `\ncc\Exceptions`
|
||||
|
|
|
@ -1,32 +1,32 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright (c) Nosial 2022-2023, all rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
|
||||
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) Nosial 2022-2023, all rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
|
||||
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace ncc\CLI\Management;
|
||||
namespace ncc\CLI\Management;
|
||||
|
||||
use Exception;
|
||||
use JsonException;
|
||||
use ncc\Enums\ConsoleColors;
|
||||
use ncc\Enums\Options\InstallPackageOptions;
|
||||
use ncc\Enums\Scopes;
|
||||
use ncc\Exceptions\FileNotFoundException;
|
||||
use ncc\Exceptions\PackageLockException;
|
||||
use ncc\Exceptions\RuntimeException;
|
||||
use ncc\Exceptions\VersionNotFoundException;
|
||||
|
@ -156,14 +156,15 @@ namespace ncc\CLI\Management;
|
|||
*
|
||||
* @param $args
|
||||
* @return void
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
private static function semiDecompile($args): void
|
||||
{
|
||||
$path = ($args['package'] ?? $args['p']);
|
||||
|
||||
if(!file_exists($path) || !is_file($path) || !is_readable($path))
|
||||
throw new FileNotFoundException('The specified file \'' . $path .' \' does not exist or is not readable.');
|
||||
{
|
||||
Console::outError('The specified file does not exist or is not readable', true, 1);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -175,18 +176,35 @@ namespace ncc\CLI\Management;
|
|||
return;
|
||||
}
|
||||
|
||||
Console::out('magic_bytes: ' . json_encode(($package->MagicBytes?->toArray() ?? []), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
Console::out('header: ' . json_encode(($package->Header?->toArray() ?? []), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
Console::out('assembly: ' . json_encode(($package->Assembly?->toArray() ?? []), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
Console::out('main: ' . ($package->MainExecutionPolicy ?? 'N/A'));
|
||||
Console::out('installer: ' . ($package->Installer?->toArray() ?? 'N/A'));
|
||||
try
|
||||
{
|
||||
Console::out('magic_bytes: ' . json_encode(($package->magic_bytes?->toArray() ?? []), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
Console::out('header: ' . json_encode(($package->header?->toArray() ?? []), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
Console::out('assembly: ' . json_encode(($package->assembly?->toArray() ?? []), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
Console::out('installer: ' . json_encode(($package->installer?->toArray() ?? []), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
}
|
||||
catch(JsonException $e)
|
||||
{
|
||||
Console::outException('Error while printing package header', $e, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if($package->Dependencies !== null && count($package->Dependencies) > 0)
|
||||
Console::out('main: ' . ($package->main_execution_policy ?? 'N/A'));
|
||||
|
||||
if($package->dependencies !== null && count($package->dependencies) > 0)
|
||||
{
|
||||
Console::out('dependencies:');
|
||||
foreach($package->Dependencies as $dependency)
|
||||
foreach($package->dependencies as $dependency)
|
||||
{
|
||||
Console::out(' - ' . json_encode($dependency->toArray(), JSON_UNESCAPED_SLASHES));
|
||||
try
|
||||
{
|
||||
Console::out(' - ' . json_encode($dependency->toArray(), JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES));
|
||||
}
|
||||
catch(JsonException $e)
|
||||
{
|
||||
Console::outException('Error while printing dependency', $e, 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -194,12 +212,20 @@ namespace ncc\CLI\Management;
|
|||
Console::out('dependencies: N/A');
|
||||
}
|
||||
|
||||
if($package->ExecutionUnits !== null && count($package->ExecutionUnits) > 0)
|
||||
if($package->execution_units !== null && count($package->execution_units) > 0)
|
||||
{
|
||||
Console::out('execution_units:');
|
||||
foreach($package->ExecutionUnits as $unit)
|
||||
foreach($package->execution_units as $unit)
|
||||
{
|
||||
Console::out(' - ' . json_encode($unit->toArray(), JSON_UNESCAPED_SLASHES));
|
||||
try
|
||||
{
|
||||
Console::out(' - ' . json_encode($unit->toArray(), JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES));
|
||||
}
|
||||
catch(JsonException $e)
|
||||
{
|
||||
Console::outException('Error while printing execution unit', $e, 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -207,10 +233,10 @@ namespace ncc\CLI\Management;
|
|||
Console::out('execution_units: N/A');
|
||||
}
|
||||
|
||||
if($package->Resources !== null && count($package->Resources) > 0)
|
||||
if($package->resources !== null && count($package->resources) > 0)
|
||||
{
|
||||
Console::out('resources:');
|
||||
foreach($package->Resources as $resource)
|
||||
foreach($package->resources as $resource)
|
||||
{
|
||||
Console::out(' - ' . sprintf('%s - (%s)', $resource->Name, Functions::b2u(strlen($resource->Data))));
|
||||
}
|
||||
|
@ -220,12 +246,20 @@ namespace ncc\CLI\Management;
|
|||
Console::out('resources: N/A');
|
||||
}
|
||||
|
||||
if($package->Components !== null && count($package->Components) > 0)
|
||||
if($package->components !== null && count($package->components) > 0)
|
||||
{
|
||||
Console::out('components:');
|
||||
foreach($package->Components as $component)
|
||||
foreach($package->components as $component)
|
||||
{
|
||||
Console::out(' - ' . sprintf('#%s %s - %s', $component->data_types, $component->name, json_encode(($component->flags ?? []), JSON_UNESCAPED_SLASHES)));
|
||||
try
|
||||
{
|
||||
Console::out(' - ' . sprintf('#%s %s - %s', $component->data_types, $component->name, json_encode(($component->flags ?? []), JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES)));
|
||||
}
|
||||
catch(JsonException $e)
|
||||
{
|
||||
Console::outException('Error while printing component', $e, 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -264,7 +298,7 @@ namespace ncc\CLI\Management;
|
|||
{
|
||||
foreach($installed_packages as $package => $versions)
|
||||
{
|
||||
if(count($versions) == 0)
|
||||
if(count($versions) === 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -274,8 +308,10 @@ namespace ncc\CLI\Management;
|
|||
try
|
||||
{
|
||||
$package_version = $package_manager->getPackageVersion($package, $version);
|
||||
if($package_version == null)
|
||||
if($package_version === null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Console::out(sprintf('%s=%s (%s)',
|
||||
Console::formatColor($package, ConsoleColors::LIGHT_GREEN),
|
||||
|
@ -300,7 +336,6 @@ namespace ncc\CLI\Management;
|
|||
/**
|
||||
* @param $args
|
||||
* @return void
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
private static function installPackage($args): void
|
||||
{
|
||||
|
@ -319,9 +354,9 @@ namespace ncc\CLI\Management;
|
|||
|
||||
if($entry_arg !== null)
|
||||
{
|
||||
$credential = $credential_manager->getVault()->getEntry($entry_arg);
|
||||
$credential = $credential_manager->getVault()?->getEntry($entry_arg);
|
||||
|
||||
if($credential == null)
|
||||
if($credential === null)
|
||||
{
|
||||
Console::outError(sprintf('Unknown credential entry \'%s\'', $entry_arg), true, 1);
|
||||
return;
|
||||
|
@ -334,7 +369,7 @@ namespace ncc\CLI\Management;
|
|||
|
||||
if($credential !== null && !$credential->isCurrentlyDecrypted())
|
||||
{
|
||||
// Try 3 times
|
||||
// Try three times
|
||||
for($i = 0; $i < 3; $i++)
|
||||
{
|
||||
try
|
||||
|
@ -348,7 +383,9 @@ namespace ncc\CLI\Management;
|
|||
}
|
||||
|
||||
if($credential->isCurrentlyDecrypted())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
Console::outWarning(sprintf('Invalid password, %d attempts remaining', 2 - $i));
|
||||
}
|
||||
|
@ -377,7 +414,9 @@ namespace ncc\CLI\Management;
|
|||
}
|
||||
|
||||
if(!file_exists($path) || !is_file($path) || !is_readable($path))
|
||||
throw new FileNotFoundException('The specified file \'' . $path .' \' does not exist or is not readable.');
|
||||
{
|
||||
Console::outError('The specified file does not exist or is not readable', true, 1);
|
||||
}
|
||||
|
||||
$user_confirmation = false;
|
||||
if(isset($args['y']) || isset($args['Y']))
|
||||
|
@ -408,34 +447,61 @@ namespace ncc\CLI\Management;
|
|||
}
|
||||
|
||||
Console::out('Package installation details' . PHP_EOL);
|
||||
if(!is_null($package->Assembly->UUID))
|
||||
Console::out(' UUID: ' . Console::formatColor($package->Assembly->UUID, ConsoleColors::LIGHT_GREEN));
|
||||
if(!is_null($package->Assembly->Package))
|
||||
Console::out(' Package: ' . Console::formatColor($package->Assembly->Package, ConsoleColors::LIGHT_GREEN));
|
||||
if(!is_null($package->Assembly->Name))
|
||||
Console::out(' Name: ' . Console::formatColor($package->Assembly->Name, ConsoleColors::LIGHT_GREEN));
|
||||
if(!is_null($package->Assembly->Version))
|
||||
Console::out(' Version: ' . Console::formatColor($package->Assembly->Version, ConsoleColors::LIGHT_GREEN));
|
||||
if(!is_null($package->Assembly->Description))
|
||||
Console::out(' Description: ' . Console::formatColor($package->Assembly->Description, ConsoleColors::LIGHT_GREEN));
|
||||
if(!is_null($package->Assembly->Product))
|
||||
Console::out(' Product: ' . Console::formatColor($package->Assembly->Product, ConsoleColors::LIGHT_GREEN));
|
||||
if(!is_null($package->Assembly->Company))
|
||||
Console::out(' Company: ' . Console::formatColor($package->Assembly->Company, ConsoleColors::LIGHT_GREEN));
|
||||
if(!is_null($package->Assembly->Copyright))
|
||||
Console::out(' Copyright: ' . Console::formatColor($package->Assembly->Copyright, ConsoleColors::LIGHT_GREEN));
|
||||
if(!is_null($package->Assembly->Trademark))
|
||||
Console::out(' Trademark: ' . Console::formatColor($package->Assembly->Trademark, ConsoleColors::LIGHT_GREEN));
|
||||
|
||||
if(!is_null($package->assembly->UUID))
|
||||
{
|
||||
Console::out(' UUID: ' . Console::formatColor($package->assembly->UUID, ConsoleColors::LIGHT_GREEN));
|
||||
}
|
||||
|
||||
if(!is_null($package->assembly->Package))
|
||||
{
|
||||
Console::out(' Package: ' . Console::formatColor($package->assembly->Package, ConsoleColors::LIGHT_GREEN));
|
||||
}
|
||||
|
||||
if(!is_null($package->assembly->Name))
|
||||
{
|
||||
Console::out(' Name: ' . Console::formatColor($package->assembly->Name, ConsoleColors::LIGHT_GREEN));
|
||||
}
|
||||
|
||||
if(!is_null($package->assembly->Version))
|
||||
{
|
||||
Console::out(' Version: ' . Console::formatColor($package->assembly->Version, ConsoleColors::LIGHT_GREEN));
|
||||
}
|
||||
|
||||
if(!is_null($package->assembly->Description))
|
||||
{
|
||||
Console::out(' Description: ' . Console::formatColor($package->assembly->Description, ConsoleColors::LIGHT_GREEN));
|
||||
}
|
||||
|
||||
if(!is_null($package->assembly->Product))
|
||||
{
|
||||
Console::out(' Product: ' . Console::formatColor($package->assembly->Product, ConsoleColors::LIGHT_GREEN));
|
||||
}
|
||||
|
||||
if(!is_null($package->assembly->Company))
|
||||
{
|
||||
Console::out(' Company: ' . Console::formatColor($package->assembly->Company, ConsoleColors::LIGHT_GREEN));
|
||||
}
|
||||
|
||||
if(!is_null($package->assembly->Copyright))
|
||||
{
|
||||
Console::out(' Copyright: ' . Console::formatColor($package->assembly->Copyright, ConsoleColors::LIGHT_GREEN));
|
||||
}
|
||||
|
||||
if(!is_null($package->assembly->Trademark))
|
||||
{
|
||||
Console::out(' Trademark: ' . Console::formatColor($package->assembly->Trademark, ConsoleColors::LIGHT_GREEN));
|
||||
}
|
||||
Console::out((string)null);
|
||||
|
||||
if(count($package->Dependencies) > 0)
|
||||
if(count($package->dependencies) > 0)
|
||||
{
|
||||
$dependencies = [];
|
||||
foreach($package->Dependencies as $dependency)
|
||||
foreach($package->dependencies as $dependency)
|
||||
{
|
||||
$require_dependency = false;
|
||||
|
||||
if(!in_array(InstallPackageOptions::SKIP_DEPENDENCIES, $installer_options))
|
||||
if(!in_array(InstallPackageOptions::SKIP_DEPENDENCIES, $installer_options, true))
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -459,8 +525,10 @@ namespace ncc\CLI\Management;
|
|||
$dependency_version = null;
|
||||
}
|
||||
|
||||
if($dependency_version == null)
|
||||
if($dependency_version === null)
|
||||
{
|
||||
$require_dependency = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -481,28 +549,36 @@ namespace ncc\CLI\Management;
|
|||
}
|
||||
|
||||
Console::out(sprintf('Extension: %s',
|
||||
Console::formatColor($package->Header->CompilerExtension->Extension, ConsoleColors::GREEN)
|
||||
Console::formatColor($package->header->CompilerExtension->Extension, ConsoleColors::GREEN)
|
||||
));
|
||||
|
||||
if($package->Header->CompilerExtension->MaximumVersion !== null)
|
||||
if($package->header->CompilerExtension->MaximumVersion !== null)
|
||||
{
|
||||
Console::out(sprintf('Maximum Version: %s',
|
||||
Console::formatColor($package->Header->CompilerExtension->MaximumVersion, ConsoleColors::LIGHT_MAGENTA)
|
||||
Console::formatColor($package->header->CompilerExtension->MaximumVersion, ConsoleColors::LIGHT_MAGENTA)
|
||||
));
|
||||
}
|
||||
|
||||
if($package->Header->CompilerExtension->MinimumVersion !== null)
|
||||
|
||||
if($package->header->CompilerExtension->MinimumVersion !== null)
|
||||
{
|
||||
Console::out(sprintf('Minimum Version: %s',
|
||||
Console::formatColor($package->Header->CompilerExtension->MinimumVersion, ConsoleColors::LIGHT_MAGENTA)
|
||||
Console::formatColor($package->header->CompilerExtension->MinimumVersion, ConsoleColors::LIGHT_MAGENTA)
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
if(!$user_confirmation)
|
||||
$user_confirmation = Console::getBooleanInput(sprintf('Do you want to install %s', $package->Assembly->Package));
|
||||
{
|
||||
$user_confirmation = Console::getBooleanInput(sprintf('Do you want to install %s', $package->assembly->Package));
|
||||
}
|
||||
|
||||
if($user_confirmation)
|
||||
{
|
||||
try
|
||||
{
|
||||
$package_manager->install($path, $credential, $installer_options);
|
||||
Console::out(sprintf('Package %s installed successfully', $package->Assembly->Package));
|
||||
Console::out(sprintf('Package %s installed successfully', $package->assembly->Package));
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
|
@ -525,19 +601,20 @@ namespace ncc\CLI\Management;
|
|||
private static function uninstallPackage($args): void
|
||||
{
|
||||
$selected_package = ($args['package'] ?? $args['p']);
|
||||
$selected_version = null;
|
||||
if(isset($args['v']))
|
||||
$selected_version = $args['v'];
|
||||
if(isset($args['version']))
|
||||
$selected_version = $args['version'];
|
||||
$selected_version = $args['version'] ?? $args['v'] ?? null;
|
||||
|
||||
$user_confirmation = null;
|
||||
|
||||
// For undefined array key warnings
|
||||
if(isset($args['y']) || isset($args['Y']))
|
||||
{
|
||||
$user_confirmation = (bool)($args['y'] ?? $args['Y']);
|
||||
}
|
||||
|
||||
if($selected_package == null)
|
||||
if($selected_package === null)
|
||||
{
|
||||
Console::outError('Missing argument \'package\'', true, 1);
|
||||
}
|
||||
|
||||
$package_manager = new PackageManager();
|
||||
|
||||
|
@ -553,22 +630,24 @@ namespace ncc\CLI\Management;
|
|||
|
||||
$version_entry = null;
|
||||
if($version_entry !== null && $package_entry !== null)
|
||||
{
|
||||
/** @noinspection PhpRedundantOptionalArgumentInspection */
|
||||
$version_entry = $package_entry->getVersion($version_entry, false);
|
||||
}
|
||||
|
||||
if($package_entry == null)
|
||||
if($package_entry === null)
|
||||
{
|
||||
Console::outError(sprintf('Package "%s" is not installed', $selected_package), true, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if($version_entry == null && $selected_version !== null)
|
||||
if($version_entry === null && $selected_version !== null)
|
||||
{
|
||||
Console::outError(sprintf('Package "%s=%s" is not installed', $selected_package, $selected_version), true, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if($user_confirmation == null)
|
||||
if($user_confirmation === null)
|
||||
{
|
||||
if($selected_version !== null)
|
||||
{
|
||||
|
@ -579,13 +658,11 @@ namespace ncc\CLI\Management;
|
|||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!Console::getBooleanInput(sprintf('Do you want to uninstall all versions of %s', $selected_package)))
|
||||
{
|
||||
Console::outError('User cancelled operation', true, 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
|
@ -618,15 +695,14 @@ namespace ncc\CLI\Management;
|
|||
$user_confirmation = null;
|
||||
// For undefined array key warnings
|
||||
if(isset($args['y']) || isset($args['Y']))
|
||||
$user_confirmation = (bool)($args['y'] ?? $args['Y']);
|
||||
|
||||
if($user_confirmation == null)
|
||||
{
|
||||
if(!Console::getBooleanInput('Do you want to uninstall all packages'))
|
||||
{
|
||||
Console::outError('User cancelled operation', true, 1);
|
||||
return;
|
||||
}
|
||||
$user_confirmation = (bool)($args['y'] ?? $args['Y']);
|
||||
}
|
||||
|
||||
if(($user_confirmation === null) && !Console::getBooleanInput('Do you want to uninstall all packages'))
|
||||
{
|
||||
Console::outError('User cancelled operation', true, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
$package_manager = new PackageManager();
|
||||
|
|
|
@ -259,10 +259,10 @@ namespace ncc\Classes\ComposerExtension;
|
|||
$built_package = $project_manager->build();
|
||||
|
||||
// Copy the project to the build directory
|
||||
$out_path = $base_dir . DIRECTORY_SEPARATOR . 'build' . DIRECTORY_SEPARATOR . sprintf('%s.ncc', $project_configuration->Assembly->Package);
|
||||
$out_path = $base_dir . DIRECTORY_SEPARATOR . 'build' . DIRECTORY_SEPARATOR . sprintf('%s.ncc', $project_configuration->assembly->Package);
|
||||
$filesystem->copy($built_package, $out_path);
|
||||
$filesystem->remove($built_package);
|
||||
$built_packages[$project_configuration->Assembly->Package] = $out_path;
|
||||
$built_packages[$project_configuration->assembly->Package] = $out_path;
|
||||
}
|
||||
|
||||
return $built_packages;
|
||||
|
@ -340,32 +340,32 @@ namespace ncc\Classes\ComposerExtension;
|
|||
|
||||
if (isset($composer_package->Name))
|
||||
{
|
||||
$project_configuration->Assembly->Name = $composer_package->Name;
|
||||
$project_configuration->assembly->Name = $composer_package->Name;
|
||||
}
|
||||
|
||||
if (isset($composer_package->Description))
|
||||
{
|
||||
$project_configuration->Assembly->Description = $composer_package->Description;
|
||||
$project_configuration->assembly->Description = $composer_package->Description;
|
||||
}
|
||||
|
||||
if(isset($version_map[$composer_package->Name]))
|
||||
{
|
||||
$project_configuration->Assembly->Version = self::versionMap($composer_package->Name, $version_map);
|
||||
$project_configuration->assembly->Version = self::versionMap($composer_package->Name, $version_map);
|
||||
}
|
||||
|
||||
if($project_configuration->Assembly->Version === null || $project_configuration->Assembly->Version === '')
|
||||
if($project_configuration->assembly->Version === null || $project_configuration->assembly->Version === '')
|
||||
{
|
||||
$project_configuration->Assembly->Version = '1.0.0';
|
||||
$project_configuration->assembly->Version = '1.0.0';
|
||||
}
|
||||
|
||||
|
||||
$project_configuration->Assembly->UUID = Uuid::v1()->toRfc4122();
|
||||
$project_configuration->Assembly->Package = self::toPackageName($composer_package->Name);
|
||||
$project_configuration->assembly->UUID = Uuid::v1()->toRfc4122();
|
||||
$project_configuration->assembly->Package = self::toPackageName($composer_package->Name);
|
||||
|
||||
// Add the update source
|
||||
$project_configuration->Project->UpdateSource = new ProjectConfiguration\UpdateSource();
|
||||
$project_configuration->Project->UpdateSource->Source = sprintf('%s@composer', str_ireplace('\\', '/', $composer_package->Name));
|
||||
$project_configuration->Project->UpdateSource->Repository = null;
|
||||
$project_configuration->project->UpdateSource = new ProjectConfiguration\UpdateSource();
|
||||
$project_configuration->project->UpdateSource->Source = sprintf('%s@composer', str_ireplace('\\', '/', $composer_package->Name));
|
||||
$project_configuration->project->UpdateSource->Repository = null;
|
||||
|
||||
// Process the dependencies
|
||||
if($composer_package->Require !== null && count($composer_package->Require) > 0)
|
||||
|
@ -385,7 +385,7 @@ namespace ncc\Classes\ComposerExtension;
|
|||
$dependency->SourceType = DependencySourceType::LOCAL;
|
||||
$dependency->Version = self::versionMap($item->PackageName, $version_map);
|
||||
$dependency->Source = $package_name . '.ncc';
|
||||
$project_configuration->Build->addDependency($dependency);
|
||||
$project_configuration->build->addDependency($dependency);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -395,14 +395,14 @@ namespace ncc\Classes\ComposerExtension;
|
|||
$build_configuration->OutputPath = 'build';
|
||||
|
||||
// Apply the final properties
|
||||
$project_configuration->Build->Configurations[] = $build_configuration;
|
||||
$project_configuration->Build->DefaultConfiguration = 'default';
|
||||
$project_configuration->Build->SourcePath = '.src';
|
||||
$project_configuration->build->Configurations[] = $build_configuration;
|
||||
$project_configuration->build->DefaultConfiguration = 'default';
|
||||
$project_configuration->build->SourcePath = '.src';
|
||||
|
||||
// Apply a compiler extension
|
||||
$project_configuration->Project->Compiler->Extension = CompilerExtensions::PHP;
|
||||
$project_configuration->Project->Compiler->MinimumVersion = CompilerExtensionSupportedVersions::PHP[0];
|
||||
$project_configuration->Project->Compiler->MaximumVersion = CompilerExtensionSupportedVersions::PHP[(count(CompilerExtensionSupportedVersions::PHP) - 1)];
|
||||
$project_configuration->project->Compiler->Extension = CompilerExtensions::PHP;
|
||||
$project_configuration->project->Compiler->MinimumVersion = CompilerExtensionSupportedVersions::PHP[0];
|
||||
$project_configuration->project->Compiler->MaximumVersion = CompilerExtensionSupportedVersions::PHP[(count(CompilerExtensionSupportedVersions::PHP) - 1)];
|
||||
|
||||
return $project_configuration;
|
||||
}
|
||||
|
@ -793,7 +793,7 @@ namespace ncc\Classes\ComposerExtension;
|
|||
|
||||
if (count($static_files) > 0)
|
||||
{
|
||||
$project_configuration->Project->Options['static_files'] = $static_files;
|
||||
$project_configuration->project->Options['static_files'] = $static_files;
|
||||
|
||||
foreach ($static_files as $file)
|
||||
{
|
||||
|
|
|
@ -1,26 +1,26 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright (c) Nosial 2022-2023, all rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
|
||||
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) Nosial 2022-2023, all rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
|
||||
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace ncc\Classes\NccExtension;
|
||||
namespace ncc\Classes\NccExtension;
|
||||
|
||||
use Exception;
|
||||
use ncc\Enums\CompilerExtensions;
|
||||
|
@ -34,10 +34,9 @@ namespace ncc\Classes\NccExtension;
|
|||
use ncc\Exceptions\AccessDeniedException;
|
||||
use ncc\Exceptions\BuildConfigurationNotFoundException;
|
||||
use ncc\Exceptions\BuildException;
|
||||
use ncc\Exceptions\FileNotFoundException;
|
||||
use ncc\Exceptions\IOException;
|
||||
use ncc\Exceptions\MalformedJsonException;
|
||||
use ncc\Exceptions\PackagePreparationFailedException;
|
||||
use ncc\Exceptions\PathNotFoundException;
|
||||
use ncc\Exceptions\ProjectConfigurationNotFoundException;
|
||||
use ncc\Exceptions\RunnerExecutionException;
|
||||
use ncc\Exceptions\UnsupportedCompilerExtensionException;
|
||||
|
@ -64,12 +63,11 @@ namespace ncc\Classes\NccExtension;
|
|||
* @throws AccessDeniedException
|
||||
* @throws BuildConfigurationNotFoundException
|
||||
* @throws BuildException
|
||||
* @throws FileNotFoundException
|
||||
* @throws IOException
|
||||
* @throws MalformedJsonException
|
||||
* @throws PackagePreparationFailedException
|
||||
* @throws ProjectConfigurationNotFoundException
|
||||
* @throws UnsupportedCompilerExtensionException
|
||||
* @throws PathNotFoundException
|
||||
*/
|
||||
public static function compile(ProjectManager $manager, string $build_configuration=BuildConfigurationValues::DEFAULT): string
|
||||
{
|
||||
|
@ -77,31 +75,33 @@ namespace ncc\Classes\NccExtension;
|
|||
|
||||
if(Main::getLogLevel() !== null && Resolver::checkLogLevel(LogLevel::DEBUG, Main::getLogLevel()))
|
||||
{
|
||||
foreach($configuration->Assembly->toArray() as $prop => $value)
|
||||
foreach($configuration->assembly->toArray() as $prop => $value)
|
||||
{
|
||||
Console::outDebug(sprintf('assembly.%s: %s', $prop, ($value ?? 'n/a')));
|
||||
foreach($configuration->Project->Compiler->toArray() as $prop => $value)
|
||||
}
|
||||
foreach($configuration->project->Compiler->toArray() as $prop => $value)
|
||||
{
|
||||
Console::outDebug(sprintf('compiler.%s: %s', $prop, ($value ?? 'n/a')));
|
||||
}
|
||||
}
|
||||
|
||||
// Select the correct compiler for the specified extension
|
||||
/** @noinspection PhpSwitchCanBeReplacedWithMatchExpressionInspection */
|
||||
switch(strtolower($configuration->Project->Compiler->Extension))
|
||||
if (strtolower($configuration->project->Compiler->Extension) === CompilerExtensions::PHP)
|
||||
{
|
||||
case CompilerExtensions::PHP:
|
||||
/** @var CompilerInterface $Compiler */
|
||||
$Compiler = new PhpCompiler($configuration, $manager->getProjectPath());
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new UnsupportedCompilerExtensionException('The compiler extension \'' . $configuration->Project->Compiler->Extension . '\' is not supported');
|
||||
/** @var CompilerInterface $Compiler */
|
||||
$Compiler = new PhpCompiler($configuration, $manager->getProjectPath());
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UnsupportedCompilerExtensionException('The compiler extension \'' . $configuration->project->Compiler->Extension . '\' is not supported');
|
||||
}
|
||||
|
||||
$build_configuration = $configuration->Build->getBuildConfiguration($build_configuration)->Name;
|
||||
Console::out(sprintf('Building %s=%s', $configuration->Assembly->Package, $configuration->Assembly->Version));
|
||||
$build_configuration = $configuration->build->getBuildConfiguration($build_configuration)->Name;
|
||||
Console::out(sprintf('Building %s=%s', $configuration->assembly->Package, $configuration->assembly->Version));
|
||||
$Compiler->prepare($build_configuration);
|
||||
$Compiler->build();
|
||||
|
||||
return PackageCompiler::writePackage(
|
||||
return self::writePackage(
|
||||
$manager->getProjectPath(), $Compiler->getPackage(), $configuration, $build_configuration
|
||||
);
|
||||
}
|
||||
|
@ -121,14 +121,14 @@ namespace ncc\Classes\NccExtension;
|
|||
|
||||
try
|
||||
{
|
||||
if($project_type->ProjectType == ProjectType::COMPOSER)
|
||||
if($project_type->ProjectType === ProjectType::COMPOSER)
|
||||
{
|
||||
$project_path = ComposerSourceBuiltin::fromLocal($project_type->ProjectPath);
|
||||
}
|
||||
elseif($project_type->ProjectType == ProjectType::NCC)
|
||||
elseif($project_type->ProjectType === ProjectType::NCC)
|
||||
{
|
||||
$project_manager = new ProjectManager($project_type->ProjectPath);
|
||||
$project_manager->getProjectConfiguration()->Assembly->Version = $version;
|
||||
$project_manager->getProjectConfiguration()->assembly->Version = $version;
|
||||
$project_path = $project_manager->build();
|
||||
}
|
||||
else
|
||||
|
@ -139,7 +139,7 @@ namespace ncc\Classes\NccExtension;
|
|||
if($version !== null)
|
||||
{
|
||||
$package = Package::load($project_path);
|
||||
$package->Assembly->Version = Functions::convertToSemVer($version);
|
||||
$package->assembly->Version = Functions::convertToSemVer($version);
|
||||
$package->save($project_path);
|
||||
}
|
||||
|
||||
|
@ -159,25 +159,28 @@ namespace ncc\Classes\NccExtension;
|
|||
* @param ProjectConfiguration $configuration
|
||||
* @return array
|
||||
* @throws AccessDeniedException
|
||||
* @throws FileNotFoundException
|
||||
* @throws IOException
|
||||
* @throws PathNotFoundException
|
||||
* @throws RunnerExecutionException
|
||||
*/
|
||||
public static function compileExecutionPolicies(string $path, ProjectConfiguration $configuration): array
|
||||
{
|
||||
if(count($configuration->ExecutionPolicies) == 0)
|
||||
if(count($configuration->execution_policies) === 0)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
Console::out('Compiling Execution Policies');
|
||||
$total_items = count($configuration->ExecutionPolicies);
|
||||
$total_items = count($configuration->execution_policies);
|
||||
$execution_units = [];
|
||||
$processed_items = 1;
|
||||
|
||||
/** @var ProjectConfiguration\ExecutionPolicy $policy */
|
||||
foreach($configuration->ExecutionPolicies as $policy)
|
||||
foreach($configuration->execution_policies as $policy)
|
||||
{
|
||||
Console::outVerbose(sprintf('Compiling Execution Policy %s', $policy->Name));
|
||||
|
||||
/** @noinspection DisconnectedForeachInstructionInspection */
|
||||
if($total_items > 5)
|
||||
{
|
||||
Console::inlineProgressBar($processed_items, $total_items);
|
||||
|
@ -187,8 +190,10 @@ namespace ncc\Classes\NccExtension;
|
|||
$execution_units[] = Functions::compileRunner($unit_path, $policy);
|
||||
}
|
||||
|
||||
if(ncc::cliMode() && $total_items > 5)
|
||||
if($total_items > 5 && ncc::cliMode())
|
||||
{
|
||||
print(PHP_EOL);
|
||||
}
|
||||
|
||||
return $execution_units;
|
||||
}
|
||||
|
@ -210,7 +215,7 @@ namespace ncc\Classes\NccExtension;
|
|||
|
||||
// Write the package to disk
|
||||
$FileSystem = new Filesystem();
|
||||
$BuildConfiguration = $configuration->Build->getBuildConfiguration($build_configuration);
|
||||
$BuildConfiguration = $configuration->build->getBuildConfiguration($build_configuration);
|
||||
if(!$FileSystem->exists($path . $BuildConfiguration->OutputPath))
|
||||
{
|
||||
Console::outDebug(sprintf('creating output directory %s', $path . $BuildConfiguration->OutputPath));
|
||||
|
@ -219,7 +224,7 @@ namespace ncc\Classes\NccExtension;
|
|||
|
||||
// Finally write the package to the disk
|
||||
$FileSystem->mkdir($path . $BuildConfiguration->OutputPath);
|
||||
$output_file = $path . $BuildConfiguration->OutputPath . DIRECTORY_SEPARATOR . $package->Assembly->Package . '.ncc';
|
||||
$output_file = $path . $BuildConfiguration->OutputPath . DIRECTORY_SEPARATOR . $package->assembly->Package . '.ncc';
|
||||
if($FileSystem->exists($output_file))
|
||||
{
|
||||
Console::outDebug(sprintf('removing existing package %s', $output_file));
|
||||
|
@ -245,43 +250,44 @@ namespace ncc\Classes\NccExtension;
|
|||
* @param Package $package
|
||||
* @param array $refs
|
||||
* @return void
|
||||
* @noinspection PhpParameterByRefIsNotUsedAsReferenceInspection
|
||||
*/
|
||||
public static function compilePackageConstants(Package &$package, array $refs): void
|
||||
public static function compilePackageConstants(Package $package, array $refs): void
|
||||
{
|
||||
if($package->Assembly !== null)
|
||||
if($package->assembly !== null)
|
||||
{
|
||||
$assembly = [];
|
||||
foreach($package->Assembly->toArray() as $key => $value)
|
||||
|
||||
foreach($package->assembly->toArray() as $key => $value)
|
||||
{
|
||||
Console::outDebug(sprintf('compiling consts Assembly.%s (%s)', $key, implode(', ', array_keys($refs))));
|
||||
Console::outDebug(sprintf('compiling constant Assembly.%s (%s)', $key, implode(', ', array_keys($refs))));
|
||||
$assembly[$key] = self::compileConstants($value, $refs);
|
||||
}
|
||||
$package->Assembly = Assembly::fromArray($assembly);
|
||||
$package->assembly = Assembly::fromArray($assembly);
|
||||
|
||||
unset($assembly);
|
||||
}
|
||||
|
||||
if($package->ExecutionUnits !== null && count($package->ExecutionUnits) > 0)
|
||||
if($package->execution_units !== null && count($package->execution_units) > 0)
|
||||
{
|
||||
$units = [];
|
||||
foreach($package->ExecutionUnits as $executionUnit)
|
||||
foreach($package->execution_units as $executionUnit)
|
||||
{
|
||||
Console::outDebug(sprintf('compiling execution unit consts %s (%s)', $executionUnit->execution_policy->Name, implode(', ', array_keys($refs))));
|
||||
Console::outDebug(sprintf('compiling execution unit constant %s (%s)', $executionUnit->execution_policy->Name, implode(', ', array_keys($refs))));
|
||||
$units[] = self::compileExecutionUnitConstants($executionUnit, $refs);
|
||||
}
|
||||
$package->ExecutionUnits = $units;
|
||||
$package->execution_units = $units;
|
||||
unset($units);
|
||||
}
|
||||
|
||||
$compiled_constants = [];
|
||||
foreach($package->Header->RuntimeConstants as $name => $value)
|
||||
foreach($package->header->RuntimeConstants as $name => $value)
|
||||
{
|
||||
Console::outDebug(sprintf('compiling runtime const %s (%s)', $name, implode(', ', array_keys($refs))));
|
||||
Console::outDebug(sprintf('compiling runtime constant %s (%s)', $name, implode(', ', array_keys($refs))));
|
||||
$compiled_constants[$name] = self::compileConstants($value, $refs);
|
||||
}
|
||||
|
||||
$options = [];
|
||||
foreach($package->Header->Options as $name => $value)
|
||||
foreach($package->header->Options as $name => $value)
|
||||
{
|
||||
if(is_array($value))
|
||||
{
|
||||
|
@ -289,7 +295,9 @@ namespace ncc\Classes\NccExtension;
|
|||
foreach($value as $key => $val)
|
||||
{
|
||||
if(!is_string($val))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Console::outDebug(sprintf('compiling option %s.%s (%s)', $name, $key, implode(', ', array_keys($refs))));
|
||||
$options[$name][$key] = self::compileConstants($val, $refs);
|
||||
|
@ -302,8 +310,8 @@ namespace ncc\Classes\NccExtension;
|
|||
}
|
||||
}
|
||||
|
||||
$package->Header->Options = $options;
|
||||
$package->Header->RuntimeConstants = $compiled_constants;
|
||||
$package->header->Options = $options;
|
||||
$package->header->RuntimeConstants = $compiled_constants;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -370,23 +378,35 @@ namespace ncc\Classes\NccExtension;
|
|||
*/
|
||||
public static function compileConstants(?string $value, array $refs): ?string
|
||||
{
|
||||
if($value == null)
|
||||
if($value === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if(isset($refs[ConstantReferences::ASSEMBLY]))
|
||||
{
|
||||
$value = ConstantCompiler::compileAssemblyConstants($value, $refs[ConstantReferences::ASSEMBLY]);
|
||||
}
|
||||
|
||||
if(isset($refs[ConstantReferences::BUILD]))
|
||||
{
|
||||
$value = ConstantCompiler::compileBuildConstants($value);
|
||||
}
|
||||
|
||||
if(isset($refs[ConstantReferences::DATE_TIME]))
|
||||
{
|
||||
$value = ConstantCompiler::compileDateTimeConstants($value, $refs[ConstantReferences::DATE_TIME]);
|
||||
}
|
||||
|
||||
if(isset($refs[ConstantReferences::INSTALL]))
|
||||
{
|
||||
$value = ConstantCompiler::compileInstallConstants($value, $refs[ConstantReferences::INSTALL]);
|
||||
}
|
||||
|
||||
if(isset($refs[ConstantReferences::RUNTIME]))
|
||||
{
|
||||
$value = ConstantCompiler::compileRuntimeConstants($value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
|
|
@ -1,32 +1,32 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright (c) Nosial 2022-2023, all rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
|
||||
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) Nosial 2022-2023, all rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
|
||||
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace ncc\Classes\NccExtension;
|
||||
namespace ncc\Classes\NccExtension;
|
||||
|
||||
use ncc\Enums\Scopes;
|
||||
use ncc\Exceptions\AccessDeniedException;
|
||||
use ncc\Exceptions\FileNotFoundException;
|
||||
use ncc\Exceptions\IOException;
|
||||
use ncc\Exceptions\NoAvailableUnitsException;
|
||||
use ncc\Exceptions\PathNotFoundException;
|
||||
use ncc\Exceptions\RunnerExecutionException;
|
||||
use ncc\Managers\ExecutionPointerManager;
|
||||
use ncc\Objects\Package\ExecutionUnit;
|
||||
|
@ -42,15 +42,17 @@ namespace ncc\Classes\NccExtension;
|
|||
* @param ExecutionUnit $unit
|
||||
* @return void
|
||||
* @throws AccessDeniedException
|
||||
* @throws FileNotFoundException
|
||||
* @throws IOException
|
||||
* @throws NoAvailableUnitsException
|
||||
* @throws RunnerExecutionException
|
||||
* @throws PathNotFoundException
|
||||
*/
|
||||
public static function temporaryExecute(string $package, string $version, ExecutionUnit $unit): void
|
||||
{
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
||||
{
|
||||
throw new AccessDeniedException('Cannot temporarily execute a unit with insufficient permissions');
|
||||
}
|
||||
|
||||
$ExecutionPointerManager = new ExecutionPointerManager();
|
||||
$ExecutionPointerManager->addUnit($package, $version, $unit, true);
|
||||
|
|
|
@ -1,28 +1,30 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright (c) Nosial 2022-2023, all rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
|
||||
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) Nosial 2022-2023, all rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
|
||||
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace ncc\Classes\PerlExtension;
|
||||
namespace ncc\Classes\PerlExtension;
|
||||
|
||||
use ncc\Exceptions\FileNotFoundException;
|
||||
use ncc\Exceptions\AccessDeniedException;
|
||||
use ncc\Exceptions\IOException;
|
||||
use ncc\Exceptions\PathNotFoundException;
|
||||
use ncc\Interfaces\RunnerInterface;
|
||||
use ncc\Objects\Package\ExecutionUnit;
|
||||
use ncc\Objects\ProjectConfiguration\ExecutionPolicy;
|
||||
|
@ -33,13 +35,23 @@ namespace ncc\Classes\PerlExtension;
|
|||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @param string $path
|
||||
* @param ExecutionPolicy $policy
|
||||
* @return ExecutionUnit
|
||||
* @throws PathNotFoundException
|
||||
* @throws AccessDeniedException
|
||||
* @throws IOException
|
||||
*/
|
||||
public static function processUnit(string $path, ExecutionPolicy $policy): ExecutionUnit
|
||||
{
|
||||
$execution_unit = new ExecutionUnit();
|
||||
$policy->Execute->Target = null;
|
||||
|
||||
if(!file_exists($path) && !is_file($path))
|
||||
throw new FileNotFoundException($path);
|
||||
{
|
||||
throw new PathNotFoundException($path);
|
||||
}
|
||||
|
||||
$execution_unit->execution_policy = $policy;
|
||||
$execution_unit->Data = IO::fread($path);
|
||||
|
||||
|
|
|
@ -35,10 +35,10 @@
|
|||
use ncc\Exceptions\AccessDeniedException;
|
||||
use ncc\Exceptions\BuildConfigurationNotFoundException;
|
||||
use ncc\Exceptions\BuildException;
|
||||
use ncc\Exceptions\FileNotFoundException;
|
||||
use ncc\Exceptions\IOException;
|
||||
use ncc\Exceptions\PackageLockException;
|
||||
use ncc\Exceptions\PackagePreparationFailedException;
|
||||
use ncc\Exceptions\PathNotFoundException;
|
||||
use ncc\Exceptions\RunnerExecutionException;
|
||||
use ncc\Exceptions\VersionNotFoundException;
|
||||
use ncc\Interfaces\CompilerInterface;
|
||||
|
@ -103,34 +103,36 @@
|
|||
}
|
||||
|
||||
// Select the build configuration
|
||||
$selected_build_configuration = $this->project->Build->getBuildConfiguration($build_configuration);
|
||||
$selected_build_configuration = $this->project->build->getBuildConfiguration($build_configuration);
|
||||
|
||||
// Create the package object
|
||||
$this->package = new Package();
|
||||
$this->package->Assembly = $this->project->Assembly;
|
||||
$this->package->Dependencies = $this->project->Build->Dependencies;
|
||||
$this->package->MainExecutionPolicy = $this->project->Build->Main;
|
||||
$this->package->assembly = $this->project->assembly;
|
||||
$this->package->dependencies = $this->project->build->Dependencies;
|
||||
$this->package->main_execution_policy = $this->project->build->Main;
|
||||
|
||||
// Add the option to create a symbolic link to the package
|
||||
if(isset($this->project->Project->Options['create_symlink']) && $this->project->Project->Options['create_symlink'] === True)
|
||||
$this->package->Header->Options['create_symlink'] = true;
|
||||
if(isset($this->project->project->Options['create_symlink']) && $this->project->project->Options['create_symlink'] === True)
|
||||
{
|
||||
$this->package->header->Options['create_symlink'] = true;
|
||||
}
|
||||
|
||||
// Add both the defined constants from the build configuration and the global constants.
|
||||
// Global constants are overridden
|
||||
$this->package->Header->RuntimeConstants = [];
|
||||
$this->package->Header->RuntimeConstants = array_merge(
|
||||
$this->package->header->RuntimeConstants = [];
|
||||
$this->package->header->RuntimeConstants = array_merge(
|
||||
($selected_build_configuration->DefineConstants ?? []),
|
||||
($this->project->Build->DefineConstants ?? []),
|
||||
($this->package->Header->RuntimeConstants ?? [])
|
||||
($this->project->build->DefineConstants ?? []),
|
||||
($this->package->header->RuntimeConstants ?? [])
|
||||
);
|
||||
|
||||
$this->package->Header->CompilerExtension = $this->project->Project->Compiler;
|
||||
$this->package->Header->CompilerVersion = NCC_VERSION_NUMBER;
|
||||
$this->package->Header->Options = $this->project->Project->Options;
|
||||
$this->package->header->CompilerExtension = $this->project->project->Compiler;
|
||||
$this->package->header->CompilerVersion = NCC_VERSION_NUMBER;
|
||||
$this->package->header->Options = $this->project->project->Options;
|
||||
|
||||
if($this->project->Project->UpdateSource !== null)
|
||||
if($this->project->project->UpdateSource !== null)
|
||||
{
|
||||
$this->package->Header->UpdateSource = $this->project->Project->UpdateSource;
|
||||
$this->package->header->UpdateSource = $this->project->project->UpdateSource;
|
||||
}
|
||||
|
||||
Console::outDebug('scanning project files');
|
||||
|
@ -150,13 +152,16 @@
|
|||
|
||||
// Include file components that can be compiled
|
||||
$DirectoryScanner->setIncludes(ComponentFileExtensions::PHP);
|
||||
|
||||
if($selected_build_configuration->ExcludeFiles !== null && count($selected_build_configuration->ExcludeFiles) > 0)
|
||||
{
|
||||
$DirectoryScanner->setExcludes($selected_build_configuration->ExcludeFiles);
|
||||
$source_path = $this->path . $this->project->Build->SourcePath;
|
||||
}
|
||||
|
||||
$source_path = $this->path . $this->project->build->SourcePath;
|
||||
|
||||
// TODO: Re-implement the scanning process outside the compiler, as this is will be redundant
|
||||
// Scan for components first.
|
||||
|
||||
if(file_exists($source_path))
|
||||
{
|
||||
Console::outVerbose('Scanning for components... ');
|
||||
|
@ -166,18 +171,20 @@
|
|||
{
|
||||
// Ignore directories, they're not important. :-)
|
||||
if(is_dir($item->getPathName()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$Component = new Package\Component();
|
||||
$Component->name = Functions::removeBasename($item->getPathname(), $this->path);
|
||||
$this->package->Components[] = $Component;
|
||||
$this->package->components[] = $Component;
|
||||
|
||||
Console::outVerbose(sprintf('Found component %s', $Component->name));
|
||||
}
|
||||
|
||||
if(count($this->package->Components) > 0)
|
||||
if(count($this->package->components) > 0)
|
||||
{
|
||||
Console::outVerbose(count($this->package->Components) . ' component(s) found');
|
||||
Console::outVerbose(count($this->package->components) . ' component(s) found');
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -204,18 +211,20 @@
|
|||
{
|
||||
// Ignore directories, they're not important. :-)
|
||||
if(is_dir($item->getPathName()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$Resource = new Package\Resource();
|
||||
$Resource->Name = Functions::removeBasename($item->getPathname(), $this->path);
|
||||
$this->package->Resources[] = $Resource;
|
||||
$this->package->resources[] = $Resource;
|
||||
|
||||
Console::outVerbose(sprintf('found resource %s', $Resource->Name));
|
||||
}
|
||||
|
||||
if(count($this->package->Resources) > 0)
|
||||
if(count($this->package->resources) > 0)
|
||||
{
|
||||
Console::outVerbose(count($this->package->Resources) . ' resources(s) found');
|
||||
Console::outVerbose(count($this->package->resources) . ' resources(s) found');
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -228,10 +237,16 @@
|
|||
}
|
||||
|
||||
$selected_dependencies = [];
|
||||
if($this->project->Build->Dependencies !== null && count($this->project->Build->Dependencies) > 0)
|
||||
$selected_dependencies = array_merge($selected_dependencies, $this->project->Build->Dependencies);
|
||||
|
||||
if($this->project->build->Dependencies !== null && count($this->project->build->Dependencies) > 0)
|
||||
{
|
||||
$selected_dependencies = array_merge($selected_dependencies, $this->project->build->Dependencies);
|
||||
}
|
||||
|
||||
if($selected_build_configuration->Dependencies !== null && count($selected_build_configuration->Dependencies) > 0)
|
||||
{
|
||||
$selected_dependencies = array_merge($selected_dependencies, $selected_build_configuration->Dependencies);
|
||||
}
|
||||
|
||||
// Process the dependencies
|
||||
if(count($selected_dependencies) > 0)
|
||||
|
@ -241,7 +256,9 @@
|
|||
|
||||
$lib_path = $selected_build_configuration->OutputPath . DIRECTORY_SEPARATOR . 'libs';
|
||||
if($filesystem->exists($lib_path))
|
||||
{
|
||||
$filesystem->remove($lib_path);
|
||||
}
|
||||
|
||||
Console::outVerbose('Scanning for dependencies... ');
|
||||
foreach($selected_dependencies as $dependency)
|
||||
|
@ -254,12 +271,25 @@
|
|||
try
|
||||
{
|
||||
$out_path = $lib_path . DIRECTORY_SEPARATOR . sprintf('%s=%s.lib', $dependency->Name, $dependency->Version);
|
||||
$package = $package_lock_manager->getPackageLock()->getPackage($dependency->Name);
|
||||
|
||||
$package = $package_lock_manager->getPackageLock()?->getPackage($dependency->Name);
|
||||
if($package === null)
|
||||
{
|
||||
throw new PackageLockException('Cannot find package lock for dependency ' . $dependency->Name);
|
||||
}
|
||||
|
||||
$version = $package->getVersion($dependency->Version);
|
||||
if($version === null)
|
||||
{
|
||||
throw new VersionNotFoundException('Cannot find version ' . $dependency->Version . ' for dependency ' . $dependency->Name);
|
||||
}
|
||||
|
||||
Console::outDebug(sprintf('copying shadow package %s=%s to %s', $dependency->Name, $dependency->Version, $out_path));
|
||||
|
||||
if(!$filesystem->exists($lib_path))
|
||||
{
|
||||
$filesystem->mkdir($lib_path);
|
||||
}
|
||||
|
||||
$filesystem->copy($version->Location, $out_path);
|
||||
$dependency->Source = 'libs' . DIRECTORY_SEPARATOR . sprintf('%s=%s.lib', $dependency->Name, $dependency->Version);
|
||||
|
@ -284,9 +314,9 @@
|
|||
$this->package->addDependency($dependency);
|
||||
}
|
||||
|
||||
if(count($this->package->Dependencies) > 0)
|
||||
if(count($this->package->dependencies) > 0)
|
||||
{
|
||||
Console::outVerbose(count($this->package->Dependencies) . ' dependency(ies) found');
|
||||
Console::outVerbose(count($this->package->dependencies) . ' dependency(ies) found');
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -302,8 +332,9 @@
|
|||
* @return Package|null
|
||||
* @throws AccessDeniedException
|
||||
* @throws BuildException
|
||||
* @throws FileNotFoundException
|
||||
* @throws IOException
|
||||
* @throws PathNotFoundException
|
||||
* @throws RunnerExecutionException
|
||||
*/
|
||||
public function build(): ?Package
|
||||
{
|
||||
|
@ -312,7 +343,7 @@
|
|||
$this->compileResources();
|
||||
|
||||
PackageCompiler::compilePackageConstants($this->package, [
|
||||
ConstantReferences::ASSEMBLY => $this->project->Assembly,
|
||||
ConstantReferences::ASSEMBLY => $this->project->assembly,
|
||||
ConstantReferences::BUILD => null,
|
||||
ConstantReferences::DATE_TIME => time()
|
||||
]);
|
||||
|
@ -326,34 +357,43 @@
|
|||
* @return void
|
||||
* @throws AccessDeniedException
|
||||
* @throws BuildException
|
||||
* @throws FileNotFoundException
|
||||
* @throws IOException
|
||||
* @throws PathNotFoundException
|
||||
*/
|
||||
public function compileResources(): void
|
||||
{
|
||||
if($this->package == null)
|
||||
if($this->package === null)
|
||||
{
|
||||
throw new BuildException('The prepare() method must be called before building the package');
|
||||
}
|
||||
|
||||
if(count($this->package->Resources) == 0)
|
||||
if(count($this->package->resources) === 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Process the resources
|
||||
$total_items = count($this->package->Resources);
|
||||
$total_items = count($this->package->resources);
|
||||
$processed_items = 1;
|
||||
$resources = [];
|
||||
|
||||
if($total_items > 5)
|
||||
Console::out('Processing resources');
|
||||
|
||||
foreach($this->package->Resources as $resource)
|
||||
{
|
||||
Console::out('Processing resources');
|
||||
}
|
||||
|
||||
foreach($this->package->resources as $resource)
|
||||
{
|
||||
/** @noinspection DisconnectedForeachInstructionInspection */
|
||||
if($total_items > 5)
|
||||
{
|
||||
Console::inlineProgressBar($processed_items, $total_items);
|
||||
}
|
||||
|
||||
// Get the data and
|
||||
$resource->Data = IO::fread(Functions::correctDirectorySeparator($this->path . $resource->Name));
|
||||
$resource->Data = Base64::encode($resource->Data);
|
||||
$resource->Name = str_replace($this->project->Build->SourcePath, (string)null, $resource->Name);
|
||||
$resource->Name = str_replace($this->project->build->SourcePath, (string)null, $resource->Name);
|
||||
$resource->updateChecksum();
|
||||
$resources[] = $resource;
|
||||
|
||||
|
@ -361,7 +401,7 @@
|
|||
}
|
||||
|
||||
// Update the resources
|
||||
$this->package->Resources = $resources;
|
||||
$this->package->resources = $resources;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -370,26 +410,32 @@
|
|||
* @return void
|
||||
* @throws AccessDeniedException
|
||||
* @throws BuildException
|
||||
* @throws FileNotFoundException
|
||||
* @throws IOException
|
||||
* @throws PathNotFoundException
|
||||
*/
|
||||
public function compileComponents(): void
|
||||
{
|
||||
if($this->package == null)
|
||||
if($this->package === null)
|
||||
{
|
||||
throw new BuildException('The prepare() method must be called before building the package');
|
||||
}
|
||||
|
||||
if(count($this->package->Components) == 0)
|
||||
if(count($this->package->components) === 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$total_items = count($this->package->Components);
|
||||
$total_items = count($this->package->components);
|
||||
$processed_items = 1;
|
||||
$components = [];
|
||||
|
||||
if($total_items > 5)
|
||||
{
|
||||
Console::out('Compiling components');
|
||||
}
|
||||
|
||||
// Process the components and attempt to create an AST representation of the source
|
||||
foreach($this->package->Components as $component)
|
||||
foreach($this->package->components as $component)
|
||||
{
|
||||
if($total_items > 5)
|
||||
{
|
||||
|
@ -402,19 +448,10 @@
|
|||
try
|
||||
{
|
||||
$stmts = $parser->parse($content);
|
||||
$encoded = json_encode($stmts);
|
||||
$encoded = json_encode($stmts, JSON_THROW_ON_ERROR);
|
||||
unset($stmts);
|
||||
|
||||
if($encoded === false)
|
||||
{
|
||||
$component->data_types = ComponentDataType::BASE64_ENCODED;
|
||||
$component->data = Base64::encode($content);
|
||||
}
|
||||
else
|
||||
{
|
||||
$component->data_types = ComponentDataType::AST;
|
||||
$component->data = json_decode($encoded, true);
|
||||
}
|
||||
$component->data_types = ComponentDataType::AST;
|
||||
$component->data = json_decode($encoded, true, 512, JSON_THROW_ON_ERROR);
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
|
@ -425,28 +462,28 @@
|
|||
|
||||
unset($parser);
|
||||
|
||||
$component->name = str_replace($this->project->Build->SourcePath, (string)null, $component->name);
|
||||
$component->name = str_replace($this->project->build->SourcePath, (string)null, $component->name);
|
||||
$component->updateChecksum();
|
||||
$components[] = $component;
|
||||
$processed_items += 1;
|
||||
++$processed_items;
|
||||
|
||||
Console::outDebug(sprintf('processed component %s (%s)', $component->name, $component->data_types));
|
||||
}
|
||||
|
||||
// Update the components
|
||||
$this->package->Components = $components;
|
||||
$this->package->components = $components;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws AccessDeniedException
|
||||
* @throws FileNotFoundException
|
||||
* @throws IOException
|
||||
* @throws RunnerExecutionException
|
||||
* @throws PathNotFoundException
|
||||
*/
|
||||
public function compileExecutionPolicies(): void
|
||||
{
|
||||
$this->package->ExecutionUnits = PackageCompiler::compileExecutionPolicies($this->path, $this->project);
|
||||
$this->package->execution_units = PackageCompiler::compileExecutionPolicies($this->path, $this->project);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright (c) Nosial 2022-2023, all rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
|
||||
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) Nosial 2022-2023, all rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
|
||||
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
/** @noinspection PhpPropertyOnlyWrittenInspection */
|
||||
/** @noinspection PhpMissingFieldTypeInspection */
|
||||
|
@ -32,9 +32,8 @@
|
|||
use ncc\Exceptions\AccessDeniedException;
|
||||
use ncc\Exceptions\ComponentChecksumException;
|
||||
use ncc\Exceptions\ComponentDecodeException;
|
||||
use ncc\Exceptions\FileNotFoundException;
|
||||
use ncc\Exceptions\IOException;
|
||||
use ncc\Exceptions\NoUnitsFoundException;
|
||||
use ncc\Exceptions\PathNotFoundException;
|
||||
use ncc\Exceptions\ResourceChecksumException;
|
||||
use ncc\Exceptions\UnsupportedComponentTypeException;
|
||||
use ncc\Interfaces\InstallerInterface;
|
||||
|
@ -62,19 +61,13 @@
|
|||
/**
|
||||
* @var ReflectionClass[] Node type to reflection class map
|
||||
*/
|
||||
private $reflectionClassCache;
|
||||
|
||||
/**
|
||||
* @var Package
|
||||
*/
|
||||
private $package;
|
||||
private $reflection_class;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function __construct(Package $package)
|
||||
{
|
||||
$this->package = $package;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -89,11 +82,15 @@
|
|||
*/
|
||||
public function processComponent(Package\Component $component): ?string
|
||||
{
|
||||
if($component->data == null)
|
||||
if($component->data === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!$component->validate_checksum())
|
||||
{
|
||||
throw new ComponentChecksumException('Checksum validation failed for component ' . $component->name . ', the package may be corrupted.');
|
||||
}
|
||||
|
||||
switch($component->data_types)
|
||||
{
|
||||
|
@ -107,8 +104,7 @@
|
|||
throw new ComponentDecodeException('Cannot decode component: ' . $component->name . ', ' . $e->getMessage(), $e);
|
||||
}
|
||||
|
||||
$prettyPrinter = new Standard();
|
||||
return $prettyPrinter->prettyPrintFile($stmts);
|
||||
return (new Standard())->prettyPrintFile($stmts);
|
||||
|
||||
case ComponentDataType::BASE64_ENCODED:
|
||||
return Base64::decode($component->data);
|
||||
|
@ -135,6 +131,7 @@
|
|||
{
|
||||
$autoload_path = $installationPaths->getBinPath() . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||
$autoload_src = $this->generateAutoload($installationPaths->getSourcePath(), $autoload_path);
|
||||
|
||||
IO::fwrite($autoload_path, $autoload_src);
|
||||
}
|
||||
|
||||
|
@ -148,7 +145,10 @@
|
|||
public function processResource(Package\Resource $resource): ?string
|
||||
{
|
||||
if(!$resource->validateChecksum())
|
||||
{
|
||||
throw new ResourceChecksumException('Checksum validation failed for resource ' . $resource->Name . ', the package may be corrupted.');
|
||||
}
|
||||
|
||||
return Base64::decode($resource->Data);
|
||||
}
|
||||
|
||||
|
@ -168,10 +168,13 @@
|
|||
{
|
||||
return $this->decodeComment($value);
|
||||
}
|
||||
|
||||
return $this->decodeNode($value);
|
||||
}
|
||||
|
||||
return $this->decodeArray($value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
@ -183,10 +186,12 @@
|
|||
private function decodeArray(array $array) : array
|
||||
{
|
||||
$decodedArray = [];
|
||||
|
||||
foreach ($array as $key => $value)
|
||||
{
|
||||
$decodedArray[$key] = $this->decodeRecursive($value);
|
||||
}
|
||||
|
||||
return $decodedArray;
|
||||
}
|
||||
|
||||
|
@ -254,12 +259,12 @@
|
|||
*/
|
||||
private function reflectionClassFromNodeType(string $nodeType) : ReflectionClass
|
||||
{
|
||||
if (!isset($this->reflectionClassCache[$nodeType]))
|
||||
if (!isset($this->reflection_class[$nodeType]))
|
||||
{
|
||||
$className = $this->classNameFromNodeType($nodeType);
|
||||
$this->reflectionClassCache[$nodeType] = new ReflectionClass($className);
|
||||
$this->reflection_class[$nodeType] = new ReflectionClass($className);
|
||||
}
|
||||
return $this->reflectionClassCache[$nodeType];
|
||||
return $this->reflection_class[$nodeType];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -268,7 +273,7 @@
|
|||
*/
|
||||
private function classNameFromNodeType(string $nodeType) : string
|
||||
{
|
||||
$className = 'ncc\\ThirdParty\\nikic\\PhpParser\\Node\\' . strtr($nodeType, '_', '\\');
|
||||
$className = 'ncc\\ThirdParty\\nikic\\PhpParser\\Node\\' . str_replace('_', '\\', $nodeType);
|
||||
if (class_exists($className))
|
||||
{
|
||||
return $className;
|
||||
|
@ -291,8 +296,8 @@
|
|||
* @return string
|
||||
* @throws AccessDeniedException
|
||||
* @throws CollectorException
|
||||
* @throws FileNotFoundException
|
||||
* @throws IOException
|
||||
* @throws PathNotFoundException
|
||||
*/
|
||||
private function generateAutoload(string $src, string $output): string
|
||||
{
|
||||
|
@ -315,11 +320,8 @@
|
|||
$result = self::runCollector($factory, $configuration);
|
||||
|
||||
// Exception raises when there are no files in the project that can be processed by the autoloader
|
||||
|
||||
$template = IO::fread($configuration->getTemplate());
|
||||
|
||||
$builder = $factory->getRenderer($result);
|
||||
return $builder->render($template);
|
||||
return $factory->getRenderer($result)->render($template);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,30 +1,30 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright (c) Nosial 2022-2023, all rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
|
||||
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) Nosial 2022-2023, all rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
|
||||
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace ncc\Classes\PhpExtension;
|
||||
namespace ncc\Classes\PhpExtension;
|
||||
|
||||
use ncc\Exceptions\AccessDeniedException;
|
||||
use ncc\Exceptions\FileNotFoundException;
|
||||
use ncc\Exceptions\IOException;
|
||||
use ncc\Exceptions\PathNotFoundException;
|
||||
use ncc\Interfaces\RunnerInterface;
|
||||
use ncc\Objects\Package\ExecutionUnit;
|
||||
use ncc\Objects\ProjectConfiguration\ExecutionPolicy;
|
||||
|
@ -36,16 +36,20 @@ namespace ncc\Classes\PhpExtension;
|
|||
* @param string $path
|
||||
* @param ExecutionPolicy $policy
|
||||
* @return ExecutionUnit
|
||||
* @throws FileNotFoundException
|
||||
* @throws AccessDeniedException
|
||||
* @throws IOException
|
||||
* @throws PathNotFoundException
|
||||
*/
|
||||
public static function processUnit(string $path, ExecutionPolicy $policy): ExecutionUnit
|
||||
{
|
||||
$execution_unit = new ExecutionUnit();
|
||||
if(!file_exists($path) && !is_file($path))
|
||||
throw new FileNotFoundException($path);
|
||||
{
|
||||
throw new PathNotFoundException($path);
|
||||
}
|
||||
|
||||
$policy->Execute->Target = null;
|
||||
|
||||
$execution_unit->execution_policy = $policy;
|
||||
$execution_unit->Data = IO::fread($path);
|
||||
|
||||
|
|
|
@ -1,28 +1,30 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright (c) Nosial 2022-2023, all rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
|
||||
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) Nosial 2022-2023, all rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
|
||||
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace ncc\Classes\PythonExtension;
|
||||
namespace ncc\Classes\PythonExtension;
|
||||
|
||||
use ncc\Exceptions\FileNotFoundException;
|
||||
use ncc\Exceptions\AccessDeniedException;
|
||||
use ncc\Exceptions\IOException;
|
||||
use ncc\Exceptions\PathNotFoundException;
|
||||
use ncc\Interfaces\RunnerInterface;
|
||||
use ncc\Objects\Package\ExecutionUnit;
|
||||
use ncc\Objects\ProjectConfiguration\ExecutionPolicy;
|
||||
|
@ -33,12 +35,22 @@ namespace ncc\Classes\PythonExtension;
|
|||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @param string $path
|
||||
* @param ExecutionPolicy $policy
|
||||
* @return ExecutionUnit
|
||||
* @throws AccessDeniedException
|
||||
* @throws IOException
|
||||
* @throws PathNotFoundException
|
||||
*/
|
||||
public static function processUnit(string $path, ExecutionPolicy $policy): ExecutionUnit
|
||||
{
|
||||
$execution_unit = new ExecutionUnit();
|
||||
|
||||
if(!file_exists($path) && !is_file($path))
|
||||
throw new FileNotFoundException($path);
|
||||
{
|
||||
throw new PathNotFoundException($path);
|
||||
}
|
||||
|
||||
$policy->Execute->Target = null;
|
||||
$execution_unit->execution_policy = $policy;
|
||||
$execution_unit->Data = IO::fread($path);
|
||||
|
|
|
@ -1,28 +1,30 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright (c) Nosial 2022-2023, all rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
|
||||
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) Nosial 2022-2023, all rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
|
||||
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace ncc\Classes\PythonExtension;
|
||||
namespace ncc\Classes\PythonExtension;
|
||||
|
||||
use ncc\Exceptions\FileNotFoundException;
|
||||
use ncc\Exceptions\AccessDeniedException;
|
||||
use ncc\Exceptions\IOException;
|
||||
use ncc\Exceptions\PathNotFoundException;
|
||||
use ncc\Interfaces\RunnerInterface;
|
||||
use ncc\Objects\Package\ExecutionUnit;
|
||||
use ncc\Objects\ProjectConfiguration\ExecutionPolicy;
|
||||
|
@ -33,12 +35,22 @@ namespace ncc\Classes\PythonExtension;
|
|||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @param string $path
|
||||
* @param ExecutionPolicy $policy
|
||||
* @return ExecutionUnit
|
||||
* @throws PathNotFoundException
|
||||
* @throws AccessDeniedException
|
||||
* @throws IOException
|
||||
*/
|
||||
public static function processUnit(string $path, ExecutionPolicy $policy): ExecutionUnit
|
||||
{
|
||||
$execution_unit = new ExecutionUnit();
|
||||
|
||||
if(!file_exists($path) && !is_file($path))
|
||||
throw new FileNotFoundException($path);
|
||||
{
|
||||
throw new PathNotFoundException($path);
|
||||
}
|
||||
|
||||
$policy->Execute->Target = null;
|
||||
$execution_unit->execution_policy = $policy;
|
||||
$execution_unit->Data = IO::fread($path);
|
||||
|
|
|
@ -1,28 +1,30 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright (c) Nosial 2022-2023, all rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
|
||||
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) Nosial 2022-2023, all rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
|
||||
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace ncc\Classes\PythonExtension;
|
||||
namespace ncc\Classes\PythonExtension;
|
||||
|
||||
use ncc\Exceptions\FileNotFoundException;
|
||||
use ncc\Exceptions\AccessDeniedException;
|
||||
use ncc\Exceptions\IOException;
|
||||
use ncc\Exceptions\PathNotFoundException;
|
||||
use ncc\Interfaces\RunnerInterface;
|
||||
use ncc\Objects\Package\ExecutionUnit;
|
||||
use ncc\Objects\ProjectConfiguration\ExecutionPolicy;
|
||||
|
@ -33,12 +35,22 @@ namespace ncc\Classes\PythonExtension;
|
|||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @param string $path
|
||||
* @param ExecutionPolicy $policy
|
||||
* @return ExecutionUnit
|
||||
* @throws AccessDeniedException
|
||||
* @throws IOException
|
||||
* @throws PathNotFoundException
|
||||
*/
|
||||
public static function processUnit(string $path, ExecutionPolicy $policy): ExecutionUnit
|
||||
{
|
||||
$execution_unit = new ExecutionUnit();
|
||||
|
||||
if(!file_exists($path) && !is_file($path))
|
||||
throw new FileNotFoundException($path);
|
||||
{
|
||||
throw new PathNotFoundException($path);
|
||||
}
|
||||
|
||||
$policy->Execute->Target = null;
|
||||
$execution_unit->execution_policy = $policy;
|
||||
$execution_unit->Data = IO::fread($path);
|
||||
|
|
|
@ -1,29 +1,28 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright (c) Nosial 2022-2023, all rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
|
||||
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) Nosial 2022-2023, all rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
|
||||
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace ncc\Interfaces;
|
||||
namespace ncc\Interfaces;
|
||||
|
||||
use ncc\Exceptions\AccessDeniedException;
|
||||
use ncc\Exceptions\FileNotFoundException;
|
||||
use ncc\Exceptions\IOException;
|
||||
use ncc\Objects\Package\ExecutionUnit;
|
||||
use ncc\Objects\ProjectConfiguration\ExecutionPolicy;
|
||||
|
@ -36,7 +35,6 @@ namespace ncc\Interfaces;
|
|||
* @param string $path
|
||||
* @param ExecutionPolicy $policy
|
||||
* @return ExecutionUnit
|
||||
* @throws FileNotFoundException
|
||||
* @throws AccessDeniedException
|
||||
* @throws IOException
|
||||
*/
|
||||
|
|
|
@ -533,7 +533,7 @@
|
|||
|
||||
if($unit === null)
|
||||
{
|
||||
throw new NoAvailableUnitsException(sprintf('No execution unit named \'%s\' is available for package \'%s\'', $unit_name, $package->Assembly->Package));
|
||||
throw new NoAvailableUnitsException(sprintf('No execution unit named \'%s\' is available for package \'%s\'', $unit_name, $package->assembly->Package));
|
||||
}
|
||||
|
||||
// Get the required units
|
||||
|
@ -560,13 +560,13 @@
|
|||
}
|
||||
|
||||
// Install the units temporarily
|
||||
$this->addUnit($package->Assembly->Package, $package->Assembly->Version, $unit, true);
|
||||
$this->addUnit($package->assembly->Package, $package->assembly->Version, $unit, true);
|
||||
foreach($required_units as $r_unit)
|
||||
{
|
||||
$this->addUnit($package->Assembly->Package, $package->Assembly->Version, $r_unit, true);
|
||||
$this->addUnit($package->assembly->Package, $package->assembly->Version, $r_unit, true);
|
||||
}
|
||||
|
||||
$this->executeUnit($package->Assembly->Package, $package->Assembly->Version, $unit_name);
|
||||
$this->executeUnit($package->assembly->Package, $package->assembly->Version, $unit_name);
|
||||
$this->cleanTemporaryUnits();
|
||||
}
|
||||
|
||||
|
|
|
@ -137,14 +137,14 @@
|
|||
|
||||
$package = Package::load($package_path);
|
||||
|
||||
if(RuntimeCache::get(sprintf('installed.%s=%s', $package->Assembly->Package, $package->Assembly->Version)))
|
||||
if(RuntimeCache::get(sprintf('installed.%s=%s', $package->assembly->Package, $package->assembly->Version)))
|
||||
{
|
||||
Console::outDebug(sprintf('skipping installation of %s=%s, already processed', $package->Assembly->Package, $package->Assembly->Version));
|
||||
return $package->Assembly->Package;
|
||||
Console::outDebug(sprintf('skipping installation of %s=%s, already processed', $package->assembly->Package, $package->assembly->Version));
|
||||
return $package->assembly->Package;
|
||||
}
|
||||
|
||||
$extension = $package->Header->CompilerExtension->Extension;
|
||||
$installation_paths = new InstallationPaths($this->packages_path . DIRECTORY_SEPARATOR . $package->Assembly->Package . '=' . $package->Assembly->Version);
|
||||
$extension = $package->header->CompilerExtension->Extension;
|
||||
$installation_paths = new InstallationPaths($this->packages_path . DIRECTORY_SEPARATOR . $package->assembly->Package . '=' . $package->assembly->Version);
|
||||
|
||||
$installer = match ($extension)
|
||||
{
|
||||
|
@ -152,20 +152,20 @@
|
|||
default => throw new UnsupportedCompilerExtensionException('The compiler extension \'' . $extension . '\' is not supported'),
|
||||
};
|
||||
|
||||
if($this->getPackageVersion($package->Assembly->Package, $package->Assembly->Version) !== null)
|
||||
if($this->getPackageVersion($package->assembly->Package, $package->assembly->Version) !== null)
|
||||
{
|
||||
if(in_array(InstallPackageOptions::REINSTALL, $options, true))
|
||||
{
|
||||
if($this->getPackageLockManager()?->getPackageLock()?->packageExists($package->Assembly->Package, $package->Assembly->Version))
|
||||
if($this->getPackageLockManager()?->getPackageLock()?->packageExists($package->assembly->Package, $package->assembly->Version))
|
||||
{
|
||||
$this->getPackageLockManager()?->getPackageLock()?->removePackageVersion(
|
||||
$package->Assembly->Package, $package->Assembly->Version
|
||||
$package->assembly->Package, $package->assembly->Version
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new PackageAlreadyInstalledException('The package ' . $package->Assembly->Package . '=' . $package->Assembly->Version . ' is already installed');
|
||||
throw new PackageAlreadyInstalledException('The package ' . $package->assembly->Package . '=' . $package->assembly->Version . ' is already installed');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -175,9 +175,9 @@
|
|||
]);
|
||||
|
||||
// Process all the required dependencies before installing the package
|
||||
if($package->Dependencies !== null && count($package->Dependencies) > 0 && !in_array(InstallPackageOptions::SKIP_DEPENDENCIES, $options, true))
|
||||
if($package->dependencies !== null && count($package->dependencies) > 0 && !in_array(InstallPackageOptions::SKIP_DEPENDENCIES, $options, true))
|
||||
{
|
||||
foreach($package->Dependencies as $dependency)
|
||||
foreach($package->dependencies as $dependency)
|
||||
{
|
||||
// Uninstall the dependency if the option Reinstall is passed on
|
||||
if(in_array(InstallPackageOptions::REINSTALL, $options, true) && $this->getPackageLockManager()?->getPackageLock()?->packageExists($dependency->Name, $dependency->Version))
|
||||
|
@ -205,31 +205,31 @@
|
|||
Console::outDebug(sprintf('installer.bin_path: %s', $installation_paths->getBinPath()));
|
||||
Console::outDebug(sprintf('installer.src_path: %s', $installation_paths->getSourcePath()));
|
||||
|
||||
foreach($package->Assembly->toArray() as $prop => $value)
|
||||
foreach($package->assembly->toArray() as $prop => $value)
|
||||
{
|
||||
Console::outDebug(sprintf('assembly.%s: %s', $prop, ($value ?? 'n/a')));
|
||||
}
|
||||
|
||||
foreach($package->Header->CompilerExtension->toArray() as $prop => $value)
|
||||
foreach($package->header->CompilerExtension->toArray() as $prop => $value)
|
||||
{
|
||||
Console::outDebug(sprintf('header.compiler.%s: %s', $prop, ($value ?? 'n/a')));
|
||||
}
|
||||
}
|
||||
|
||||
Console::out('Installing ' . $package->Assembly->Package);
|
||||
Console::out('Installing ' . $package->assembly->Package);
|
||||
|
||||
// Four For Directory Creation, preInstall, postInstall & initData methods
|
||||
$steps = (4 + count($package->Components) + count ($package->Resources) + count ($package->ExecutionUnits));
|
||||
$steps = (4 + count($package->components) + count ($package->resources) + count ($package->execution_units));
|
||||
|
||||
// Include the Execution units
|
||||
if($package->Installer?->PreInstall !== null)
|
||||
if($package->installer?->PreInstall !== null)
|
||||
{
|
||||
$steps += count($package->Installer->PreInstall);
|
||||
$steps += count($package->installer->PreInstall);
|
||||
}
|
||||
|
||||
if($package->Installer?->PostInstall!== null)
|
||||
if($package->installer?->PostInstall!== null)
|
||||
{
|
||||
$steps += count($package->Installer->PostInstall);
|
||||
$steps += count($package->installer->PostInstall);
|
||||
}
|
||||
|
||||
$current_steps = 0;
|
||||
|
@ -277,9 +277,9 @@
|
|||
throw new InstallationException('Pre installation stage failed, ' . $e->getMessage(), $e);
|
||||
}
|
||||
|
||||
if($package->Installer?->PreInstall !== null && count($package->Installer->PreInstall) > 0)
|
||||
if($package->installer?->PreInstall !== null && count($package->installer->PreInstall) > 0)
|
||||
{
|
||||
foreach($package->Installer->PreInstall as $unit_name)
|
||||
foreach($package->installer->PreInstall as $unit_name)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -296,7 +296,7 @@
|
|||
}
|
||||
|
||||
// Process & Install the components
|
||||
foreach($package->Components as $component)
|
||||
foreach($package->components as $component)
|
||||
{
|
||||
Console::outDebug(sprintf('processing component %s (%s)', $component->name, $component->data_types));
|
||||
|
||||
|
@ -326,7 +326,7 @@
|
|||
}
|
||||
|
||||
// Process & Install the resources
|
||||
foreach($package->Resources as $resource)
|
||||
foreach($package->resources as $resource)
|
||||
{
|
||||
Console::outDebug(sprintf('processing resource %s', $resource->Name));
|
||||
|
||||
|
@ -356,7 +356,7 @@
|
|||
}
|
||||
|
||||
// Install execution units
|
||||
if($package->ExecutionUnits !== null && count($package->ExecutionUnits) > 0)
|
||||
if($package->execution_units !== null && count($package->execution_units) > 0)
|
||||
{
|
||||
Console::outDebug('package contains execution units, processing');
|
||||
|
||||
|
@ -364,10 +364,10 @@
|
|||
$unit_paths = [];
|
||||
|
||||
/** @var Package\ExecutionUnit $executionUnit */
|
||||
foreach($package->ExecutionUnits as $executionUnit)
|
||||
foreach($package->execution_units as $executionUnit)
|
||||
{
|
||||
Console::outDebug(sprintf('processing execution unit %s', $executionUnit->execution_policy->Name));
|
||||
$execution_pointer_manager->addUnit($package->Assembly->Package, $package->Assembly->Version, $executionUnit);
|
||||
$execution_pointer_manager->addUnit($package->assembly->Package, $package->assembly->Version, $executionUnit);
|
||||
++$current_steps;
|
||||
Console::inlineProgressBar($current_steps, $steps);
|
||||
}
|
||||
|
@ -380,17 +380,17 @@
|
|||
}
|
||||
|
||||
// After execution units are installed, create a symlink if needed
|
||||
if(isset($package->Header->Options['create_symlink']) && $package->Header->Options['create_symlink'])
|
||||
if(isset($package->header->Options['create_symlink']) && $package->header->Options['create_symlink'])
|
||||
{
|
||||
if($package->MainExecutionPolicy === null)
|
||||
if($package->main_execution_policy === null)
|
||||
{
|
||||
throw new InstallationException('Cannot create symlink, no main execution policy is defined');
|
||||
}
|
||||
|
||||
Console::outDebug(sprintf('creating symlink to %s', $package->Assembly->Package));
|
||||
Console::outDebug(sprintf('creating symlink to %s', $package->assembly->Package));
|
||||
|
||||
$SymlinkManager = new SymlinkManager();
|
||||
$SymlinkManager->add($package->Assembly->Package, $package->MainExecutionPolicy);
|
||||
$SymlinkManager->add($package->assembly->Package, $package->main_execution_policy);
|
||||
}
|
||||
|
||||
// Execute the post-installation stage after the installation is complete
|
||||
|
@ -408,11 +408,11 @@
|
|||
throw new InstallationException('Post installation stage failed, ' . $e->getMessage(), $e);
|
||||
}
|
||||
|
||||
if($package->Installer?->PostInstall !== null && count($package->Installer->PostInstall) > 0)
|
||||
if($package->installer?->PostInstall !== null && count($package->installer->PostInstall) > 0)
|
||||
{
|
||||
Console::outDebug('executing post-installation units');
|
||||
|
||||
foreach($package->Installer->PostInstall as $unit_name)
|
||||
foreach($package->installer->PostInstall as $unit_name)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -434,17 +434,17 @@
|
|||
Console::outDebug('no post-installation units to execute');
|
||||
}
|
||||
|
||||
if($package->Header->UpdateSource !== null && $package->Header->UpdateSource->Repository !== null)
|
||||
if($package->header->UpdateSource !== null && $package->header->UpdateSource->Repository !== null)
|
||||
{
|
||||
$sources_manager = new RemoteSourcesManager();
|
||||
if($sources_manager->getRemoteSource($package->Header->UpdateSource->Repository->Name) === null)
|
||||
if($sources_manager->getRemoteSource($package->header->UpdateSource->Repository->Name) === null)
|
||||
{
|
||||
Console::outVerbose('Adding remote source ' . $package->Header->UpdateSource->Repository->Name);
|
||||
Console::outVerbose('Adding remote source ' . $package->header->UpdateSource->Repository->Name);
|
||||
$defined_remote_source = new DefinedRemoteSource();
|
||||
$defined_remote_source->Name = $package->Header->UpdateSource->Repository->Name;
|
||||
$defined_remote_source->Host = $package->Header->UpdateSource->Repository->Host;
|
||||
$defined_remote_source->Type = $package->Header->UpdateSource->Repository->Type;
|
||||
$defined_remote_source->SSL = $package->Header->UpdateSource->Repository->SSL;
|
||||
$defined_remote_source->Name = $package->header->UpdateSource->Repository->Name;
|
||||
$defined_remote_source->Host = $package->header->UpdateSource->Repository->Host;
|
||||
$defined_remote_source->Type = $package->header->UpdateSource->Repository->Type;
|
||||
$defined_remote_source->SSL = $package->header->UpdateSource->Repository->SSL;
|
||||
|
||||
$sources_manager->addRemoteSource($defined_remote_source);
|
||||
}
|
||||
|
@ -453,9 +453,9 @@
|
|||
$this->getPackageLockManager()?->getPackageLock()?->addPackage($package, $installation_paths->getInstallationPath());
|
||||
$this->getPackageLockManager()?->save();
|
||||
|
||||
RuntimeCache::set(sprintf('installed.%s=%s', $package->Assembly->Package, $package->Assembly->Version), true);
|
||||
RuntimeCache::set(sprintf('installed.%s=%s', $package->assembly->Package, $package->assembly->Version), true);
|
||||
|
||||
return $package->Assembly->Package;
|
||||
return $package->assembly->Package;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -702,7 +702,7 @@
|
|||
|
||||
if ($dependency->SourceType !== null && !$dependency_met)
|
||||
{
|
||||
Console::outVerbose(sprintf('Installing dependency %s=%s for %s=%s', $dependency->Name, $dependency->Version, $package->Assembly->Package, $package->Assembly->Version));
|
||||
Console::outVerbose(sprintf('Installing dependency %s=%s for %s=%s', $dependency->Name, $dependency->Version, $package->assembly->Package, $package->assembly->Version));
|
||||
switch ($dependency->SourceType)
|
||||
{
|
||||
case DependencySourceType::LOCAL:
|
||||
|
@ -733,7 +733,7 @@
|
|||
}
|
||||
elseif(!$dependency_met)
|
||||
{
|
||||
throw new MissingDependencyException(sprintf('The dependency %s=%s for %s=%s is not met', $dependency->Name, $dependency->Version, $package->Assembly->Package, $package->Assembly->Version));
|
||||
throw new MissingDependencyException(sprintf('The dependency %s=%s for %s=%s is not met', $dependency->Name, $dependency->Version, $package->assembly->Package, $package->assembly->Version));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1024,22 +1024,22 @@
|
|||
*/
|
||||
private static function initData(Package $package, InstallationPaths $paths): void
|
||||
{
|
||||
Console::outVerbose(sprintf('Initializing data for %s', $package->Assembly->Name));
|
||||
Console::outVerbose(sprintf('Initializing data for %s', $package->assembly->Name));
|
||||
|
||||
// Create data files
|
||||
$dependencies = [];
|
||||
foreach($package->Dependencies as $dependency)
|
||||
foreach($package->dependencies as $dependency)
|
||||
{
|
||||
$dependencies[] = $dependency->toArray(true);
|
||||
}
|
||||
|
||||
$data_files = [
|
||||
$paths->getDataPath() . DIRECTORY_SEPARATOR . 'assembly' =>
|
||||
ZiProto::encode($package->Assembly->toArray(true)),
|
||||
ZiProto::encode($package->assembly->toArray(true)),
|
||||
$paths->getDataPath() . DIRECTORY_SEPARATOR . 'ext' =>
|
||||
ZiProto::encode($package->Header->CompilerExtension->toArray()),
|
||||
ZiProto::encode($package->header->CompilerExtension->toArray()),
|
||||
$paths->getDataPath() . DIRECTORY_SEPARATOR . 'const' =>
|
||||
ZiProto::encode($package->Header->RuntimeConstants),
|
||||
ZiProto::encode($package->header->RuntimeConstants),
|
||||
$paths->getDataPath() . DIRECTORY_SEPARATOR . 'dependencies' =>
|
||||
ZiProto::encode($dependencies),
|
||||
];
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
use ncc\Exceptions\AccessDeniedException;
|
||||
use ncc\Exceptions\BuildConfigurationNotFoundException;
|
||||
use ncc\Exceptions\BuildException;
|
||||
use ncc\Exceptions\FileNotFoundException;
|
||||
use ncc\Exceptions\InvalidPackageNameException;
|
||||
use ncc\Exceptions\InvalidProjectNameException;
|
||||
use ncc\Exceptions\IOException;
|
||||
|
@ -75,7 +74,6 @@
|
|||
*
|
||||
* @param string $path
|
||||
* @throws AccessDeniedException
|
||||
* @throws FileNotFoundException
|
||||
* @throws IOException
|
||||
* @throws MalformedJsonException
|
||||
* @throws PathNotFoundException
|
||||
|
@ -138,41 +136,41 @@
|
|||
$this->project_configuration = new ProjectConfiguration();
|
||||
|
||||
// Set the compiler information
|
||||
$this->project_configuration->Project->Compiler = $compiler;
|
||||
$this->project_configuration->project->Compiler = $compiler;
|
||||
|
||||
// Set the assembly information
|
||||
$this->project_configuration->Assembly->Name = $name;
|
||||
$this->project_configuration->Assembly->Package = $package;
|
||||
$this->project_configuration->Assembly->Version = '1.0.0';
|
||||
$this->project_configuration->Assembly->UUID = Uuid::v1()->toRfc4122();
|
||||
$this->project_configuration->assembly->Name = $name;
|
||||
$this->project_configuration->assembly->Package = $package;
|
||||
$this->project_configuration->assembly->Version = '1.0.0';
|
||||
$this->project_configuration->assembly->UUID = Uuid::v1()->toRfc4122();
|
||||
|
||||
// Set the build information
|
||||
$this->project_configuration->Build->SourcePath = $src;
|
||||
$this->project_configuration->build->SourcePath = $src;
|
||||
|
||||
if($this->project_configuration->Build->SourcePath === null)
|
||||
if($this->project_configuration->build->SourcePath === null)
|
||||
{
|
||||
$this->project_configuration->Build->SourcePath = $this->project_path;
|
||||
$this->project_configuration->build->SourcePath = $this->project_path;
|
||||
}
|
||||
|
||||
$this->project_configuration->Build->DefaultConfiguration = 'debug';
|
||||
$this->project_configuration->build->DefaultConfiguration = 'debug';
|
||||
|
||||
// Assembly constants if the program wishes to check for this
|
||||
$this->project_configuration->Build->DefineConstants['ASSEMBLY_NAME'] = '%ASSEMBLY.NAME%';
|
||||
$this->project_configuration->Build->DefineConstants['ASSEMBLY_PACKAGE'] = '%ASSEMBLY.PACKAGE%';
|
||||
$this->project_configuration->Build->DefineConstants['ASSEMBLY_VERSION'] = '%ASSEMBLY.VERSION%';
|
||||
$this->project_configuration->Build->DefineConstants['ASSEMBLY_UID'] = '%ASSEMBLY.UID%';
|
||||
$this->project_configuration->build->DefineConstants['ASSEMBLY_NAME'] = '%ASSEMBLY.NAME%';
|
||||
$this->project_configuration->build->DefineConstants['ASSEMBLY_PACKAGE'] = '%ASSEMBLY.PACKAGE%';
|
||||
$this->project_configuration->build->DefineConstants['ASSEMBLY_VERSION'] = '%ASSEMBLY.VERSION%';
|
||||
$this->project_configuration->build->DefineConstants['ASSEMBLY_UID'] = '%ASSEMBLY.UID%';
|
||||
|
||||
// Generate configurations
|
||||
$DebugConfiguration = new ProjectConfiguration\Build\BuildConfiguration();
|
||||
$DebugConfiguration->Name = 'debug';
|
||||
$DebugConfiguration->OutputPath = 'build/debug';
|
||||
$DebugConfiguration->DefineConstants["DEBUG"] = '1'; // Debugging constant if the program wishes to check for this
|
||||
$this->project_configuration->Build->Configurations[] = $DebugConfiguration;
|
||||
$this->project_configuration->build->Configurations[] = $DebugConfiguration;
|
||||
$ReleaseConfiguration = new ProjectConfiguration\Build\BuildConfiguration();
|
||||
$ReleaseConfiguration->Name = 'release';
|
||||
$ReleaseConfiguration->OutputPath = 'build/release';
|
||||
$ReleaseConfiguration->DefineConstants["DEBUG"] = '0'; // Debugging constant if the program wishes to check for this
|
||||
$this->project_configuration->Build->Configurations[] = $ReleaseConfiguration;
|
||||
$this->project_configuration->build->Configurations[] = $ReleaseConfiguration;
|
||||
|
||||
// Finally, create project.json
|
||||
$this->project_configuration->toFile($this->project_path . DIRECTORY_SEPARATOR . 'project.json');
|
||||
|
@ -197,8 +195,8 @@
|
|||
{
|
||||
if (
|
||||
$option === InitializeProjectOptions::CREATE_SOURCE_DIRECTORY &&
|
||||
!file_exists($this->project_configuration->Build->SourcePath) &&
|
||||
!mkdir($concurrentDirectory = $this->project_configuration->Build->SourcePath) &&
|
||||
!file_exists($this->project_configuration->build->SourcePath) &&
|
||||
!mkdir($concurrentDirectory = $this->project_configuration->build->SourcePath) &&
|
||||
!is_dir($concurrentDirectory)
|
||||
)
|
||||
{
|
||||
|
@ -221,11 +219,11 @@
|
|||
* Attempts to load the project configuration
|
||||
*
|
||||
* @return void
|
||||
* @throws MalformedJsonException
|
||||
* @throws ProjectConfigurationNotFoundException
|
||||
* @throws AccessDeniedException
|
||||
* @throws FileNotFoundException
|
||||
* @throws IOException
|
||||
* @throws MalformedJsonException
|
||||
* @throws PathNotFoundException
|
||||
* @throws ProjectConfigurationNotFoundException
|
||||
*/
|
||||
public function load(): void
|
||||
{
|
||||
|
@ -254,24 +252,16 @@
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the project's file path.
|
||||
* Returns the ProjectConfiguration object
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getProjectFilePath(): ?string
|
||||
{
|
||||
return $this->project_file_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ProjectConfiguration|null
|
||||
* @return ProjectConfiguration
|
||||
* @throws AccessDeniedException
|
||||
* @throws FileNotFoundException
|
||||
* @throws IOException
|
||||
* @throws MalformedJsonException
|
||||
* @throws PathNotFoundException
|
||||
* @throws ProjectConfigurationNotFoundException
|
||||
*/
|
||||
public function getProjectConfiguration(): ?ProjectConfiguration
|
||||
public function getProjectConfiguration(): ProjectConfiguration
|
||||
{
|
||||
if($this->project_configuration === null)
|
||||
{
|
||||
|
@ -298,13 +288,12 @@
|
|||
* @param string $build_configuration
|
||||
* @return string
|
||||
* @throws AccessDeniedException
|
||||
* @throws FileNotFoundException
|
||||
* @throws IOException
|
||||
* @throws MalformedJsonException
|
||||
* @throws ProjectConfigurationNotFoundException
|
||||
* @throws BuildConfigurationNotFoundException
|
||||
* @throws BuildException
|
||||
* @throws PackagePreparationFailedException
|
||||
* @throws IOException
|
||||
* @throws MalformedJsonException
|
||||
* @throws PathNotFoundException
|
||||
* @throws ProjectConfigurationNotFoundException
|
||||
* @throws UnsupportedCompilerExtensionException
|
||||
*/
|
||||
public function build(string $build_configuration=BuildConfigurationValues::DEFAULT): string
|
||||
|
|
|
@ -27,11 +27,11 @@
|
|||
use Exception;
|
||||
use ncc\Enums\EncoderType;
|
||||
use ncc\Enums\PackageStructureVersions;
|
||||
use ncc\Exceptions\FileNotFoundException;
|
||||
use ncc\Exceptions\InvalidPackageException;
|
||||
use ncc\Exceptions\InvalidProjectConfigurationException;
|
||||
use ncc\Exceptions\IOException;
|
||||
use ncc\Exceptions\PackageParsingException;
|
||||
use ncc\Exceptions\PathNotFoundException;
|
||||
use ncc\Objects\Package\Component;
|
||||
use ncc\Objects\Package\ExecutionUnit;
|
||||
use ncc\Objects\Package\Header;
|
||||
|
@ -51,76 +51,76 @@
|
|||
*
|
||||
* @var MagicBytes
|
||||
*/
|
||||
public $MagicBytes;
|
||||
public $magic_bytes;
|
||||
|
||||
/**
|
||||
* The true header of the package
|
||||
*
|
||||
* @var Header
|
||||
*/
|
||||
public $Header;
|
||||
public $header;
|
||||
|
||||
/**
|
||||
* The assembly object of the package
|
||||
*
|
||||
* @var Assembly
|
||||
*/
|
||||
public $Assembly;
|
||||
public $assembly;
|
||||
|
||||
/**
|
||||
* An array of dependencies that the package depends on
|
||||
*
|
||||
* @var Dependency[]
|
||||
*/
|
||||
public $Dependencies;
|
||||
public $dependencies;
|
||||
|
||||
/**
|
||||
* The Main Execution Policy object for the package if the package is an executable package.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $MainExecutionPolicy;
|
||||
public $main_execution_policy;
|
||||
|
||||
/**
|
||||
* The installer object that is used to install the package if the package is install-able
|
||||
*
|
||||
* @var Installer|null
|
||||
*/
|
||||
public $Installer;
|
||||
public $installer;
|
||||
|
||||
/**
|
||||
* An array of execution units defined in the package
|
||||
*
|
||||
* @var ExecutionUnit[]
|
||||
*/
|
||||
public $ExecutionUnits;
|
||||
public $execution_units;
|
||||
|
||||
/**
|
||||
* An array of resources that the package depends on
|
||||
*
|
||||
* @var Resource[]
|
||||
*/
|
||||
public $Resources;
|
||||
public $resources;
|
||||
|
||||
/**
|
||||
* An array of components for the package
|
||||
*
|
||||
* @var Component[]
|
||||
*/
|
||||
public $Components;
|
||||
public $components;
|
||||
|
||||
/**
|
||||
* Public Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->MagicBytes = new MagicBytes();
|
||||
$this->Header = new Header();
|
||||
$this->Assembly = new Assembly();
|
||||
$this->ExecutionUnits = [];
|
||||
$this->Components = [];
|
||||
$this->Dependencies = [];
|
||||
$this->Resources = [];
|
||||
$this->magic_bytes = new MagicBytes();
|
||||
$this->header = new Header();
|
||||
$this->assembly = new Assembly();
|
||||
$this->execution_units = [];
|
||||
$this->components = [];
|
||||
$this->dependencies = [];
|
||||
$this->resources = [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -131,16 +131,16 @@
|
|||
*/
|
||||
public function addDependency(Dependency $dependency): void
|
||||
{
|
||||
foreach($this->Dependencies as $dep)
|
||||
foreach($this->dependencies as $dep)
|
||||
{
|
||||
if($dep->Name == $dependency->Name)
|
||||
if($dep->Name === $dependency->Name)
|
||||
{
|
||||
$this->removeDependency($dep->Name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->Dependencies[] = $dependency;
|
||||
$this->dependencies[] = $dependency;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -151,11 +151,11 @@
|
|||
*/
|
||||
private function removeDependency(string $name): void
|
||||
{
|
||||
foreach($this->Dependencies as $key => $dep)
|
||||
foreach($this->dependencies as $key => $dep)
|
||||
{
|
||||
if($dep->Name == $name)
|
||||
if($dep->Name === $name)
|
||||
{
|
||||
unset($this->Dependencies[$key]);
|
||||
unset($this->dependencies[$key]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -175,25 +175,31 @@
|
|||
public function validate(bool $throw_exception=True): bool
|
||||
{
|
||||
// Validate the MagicBytes constructor
|
||||
if($this->MagicBytes == null)
|
||||
if($this->magic_bytes === null)
|
||||
{
|
||||
if($throw_exception)
|
||||
{
|
||||
throw new InvalidPackageException('The MagicBytes property is required and cannot be null');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validate the assembly object
|
||||
if($this->Assembly == null)
|
||||
if($this->assembly === null)
|
||||
{
|
||||
if($throw_exception)
|
||||
{
|
||||
throw new InvalidPackageException('The Assembly property is required and cannot be null');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!$this->Assembly->validate($throw_exception))
|
||||
if(!$this->assembly->validate($throw_exception))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// All checks have passed
|
||||
return true;
|
||||
|
@ -207,10 +213,12 @@
|
|||
*/
|
||||
public function getExecutionUnit(string $name): ?ExecutionUnit
|
||||
{
|
||||
foreach($this->ExecutionUnits as $unit)
|
||||
foreach($this->execution_units as $unit)
|
||||
{
|
||||
if($unit->execution_policy->Name == $name)
|
||||
if($unit->execution_policy->Name === $name)
|
||||
{
|
||||
return $unit;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -225,7 +233,7 @@
|
|||
*/
|
||||
public function save(string $output_path): void
|
||||
{
|
||||
$package_contents = $this->MagicBytes->toString() . ZiProto::encode($this->toArray(true));
|
||||
$package_contents = $this->magic_bytes->toString() . ZiProto::encode($this->toArray(true));
|
||||
IO::fwrite($output_path, $package_contents, 0777);
|
||||
}
|
||||
|
||||
|
@ -236,28 +244,32 @@
|
|||
*
|
||||
* @param string $path
|
||||
* @return Package
|
||||
* @throws FileNotFoundException
|
||||
* @throws PackageParsingException
|
||||
* @throws PathNotFoundException
|
||||
*/
|
||||
public static function load(string $path): Package
|
||||
{
|
||||
if(!file_exists($path) || !is_file($path) || !is_readable($path))
|
||||
{
|
||||
throw new FileNotFoundException('The file ' . $path . ' does not exist or is not readable');
|
||||
throw new PathNotFoundException($path);
|
||||
}
|
||||
|
||||
$handle = fopen($path, "rb");
|
||||
$header = fread($handle, 256); // Read the first 256 bytes of the file
|
||||
fclose($handle);
|
||||
|
||||
if(!strtoupper(substr($header, 0, 11)) == 'NCC_PACKAGE')
|
||||
if(stripos($header, 'NCC_PACKAGE') === 0)
|
||||
{
|
||||
throw new PackageParsingException('The package \'' . $path . '\' does not appear to be a valid NCC Package (Missing Header)');
|
||||
}
|
||||
|
||||
// Extract the package structure version
|
||||
$package_structure_version = strtoupper(substr($header, 11, 3));
|
||||
|
||||
if(!in_array($package_structure_version, PackageStructureVersions::ALL))
|
||||
{
|
||||
throw new PackageParsingException('The package \'' . $path . '\' has a package structure version of ' . $package_structure_version . ' which is not supported by this version NCC');
|
||||
}
|
||||
|
||||
// Extract the package encoding type and package type
|
||||
$encoding_header = strtoupper(substr($header, 14, 5));
|
||||
|
@ -320,19 +332,17 @@
|
|||
throw new PackageParsingException('Cannot determine the package type for the package \'' . $path . '\' (Got ' . $package_type . ')');
|
||||
}
|
||||
|
||||
// TODO: Implement encryption and compression parsing
|
||||
|
||||
// Assuming all is good, load the entire fire into memory and parse its contents
|
||||
try
|
||||
{
|
||||
$package = Package::fromArray(ZiProto::decode(substr(IO::fread($path), strlen($magic_bytes->toString()))));
|
||||
$package = self::fromArray(ZiProto::decode(substr(IO::fread($path), strlen($magic_bytes->toString()))));
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
throw new PackageParsingException('Cannot decode the contents of the package \'' . $path . '\', invalid encoding or the package is corrupted, ' . $e->getMessage(), $e);
|
||||
}
|
||||
|
||||
$package->MagicBytes = $magic_bytes;
|
||||
$package->magic_bytes = $magic_bytes;
|
||||
return $package;
|
||||
}
|
||||
|
||||
|
@ -346,29 +356,37 @@
|
|||
{
|
||||
$_components = [];
|
||||
/** @var Component $component */
|
||||
foreach($this->Components as $component)
|
||||
foreach($this->components as $component)
|
||||
{
|
||||
$_components[] = $component->toArray($bytecode);
|
||||
}
|
||||
|
||||
$_dependencies = [];
|
||||
/** @var Dependency $dependency */
|
||||
foreach($this->Dependencies as $dependency)
|
||||
foreach($this->dependencies as $dependency)
|
||||
{
|
||||
$_dependencies[] = $dependency->toArray($bytecode);
|
||||
}
|
||||
|
||||
$_resources = [];
|
||||
/** @var Resource $resource */
|
||||
foreach($this->Resources as $resource)
|
||||
foreach($this->resources as $resource)
|
||||
{
|
||||
$_resources[] = $resource->toArray($bytecode);
|
||||
}
|
||||
|
||||
$_execution_units = [];
|
||||
foreach($this->ExecutionUnits as $unit)
|
||||
foreach($this->execution_units as $unit)
|
||||
{
|
||||
$_execution_units[] = $unit->toArray($bytecode);
|
||||
}
|
||||
|
||||
return [
|
||||
($bytecode ? Functions::cbc('header') : 'header') => $this?->Header?->toArray($bytecode),
|
||||
($bytecode ? Functions::cbc('assembly') : 'assembly') => $this?->Assembly?->toArray($bytecode),
|
||||
($bytecode ? Functions::cbc('header') : 'header') => $this?->header?->toArray($bytecode),
|
||||
($bytecode ? Functions::cbc('assembly') : 'assembly') => $this?->assembly?->toArray($bytecode),
|
||||
($bytecode ? Functions::cbc('dependencies') : 'dependencies') => $_dependencies,
|
||||
($bytecode ? Functions::cbc('main_execution_policy') : 'main_execution_policy') => $this?->MainExecutionPolicy,
|
||||
($bytecode ? Functions::cbc('installer') : 'installer') => $this?->Installer?->toArray($bytecode),
|
||||
($bytecode ? Functions::cbc('main_execution_policy') : 'main_execution_policy') => $this?->main_execution_policy,
|
||||
($bytecode ? Functions::cbc('installer') : 'installer') => $this?->installer?->toArray($bytecode),
|
||||
($bytecode ? Functions::cbc('execution_units') : 'execution_units') => $_execution_units,
|
||||
($bytecode ? Functions::cbc('resources') : 'resources') => $_resources,
|
||||
($bytecode ? Functions::cbc('components') : 'components') => $_components
|
||||
|
@ -383,26 +401,32 @@
|
|||
{
|
||||
$object = new self();
|
||||
|
||||
$object->Header = Functions::array_bc($data, 'header');
|
||||
if($object->Header !== null)
|
||||
$object->Header = Header::fromArray($object->Header);
|
||||
$object->header = Functions::array_bc($data, 'header');
|
||||
if($object->header !== null)
|
||||
{
|
||||
$object->header = Header::fromArray($object->header);
|
||||
}
|
||||
|
||||
$object->Assembly = Functions::array_bc($data, 'assembly');
|
||||
if($object->Assembly !== null)
|
||||
$object->Assembly = Assembly::fromArray($object->Assembly);
|
||||
$object->assembly = Functions::array_bc($data, 'assembly');
|
||||
if($object->assembly !== null)
|
||||
{
|
||||
$object->assembly = Assembly::fromArray($object->assembly);
|
||||
}
|
||||
|
||||
$object->MainExecutionPolicy = Functions::array_bc($data, 'main_execution_policy');
|
||||
$object->main_execution_policy = Functions::array_bc($data, 'main_execution_policy');
|
||||
|
||||
$object->Installer = Functions::array_bc($data, 'installer');
|
||||
if($object->Installer !== null)
|
||||
$object->Installer = Installer::fromArray($object->Installer);
|
||||
$object->installer = Functions::array_bc($data, 'installer');
|
||||
if($object->installer !== null)
|
||||
{
|
||||
$object->installer = Installer::fromArray($object->installer);
|
||||
}
|
||||
|
||||
$_dependencies = Functions::array_bc($data, 'dependencies');
|
||||
if($_dependencies !== null)
|
||||
{
|
||||
foreach($_dependencies as $dependency)
|
||||
{
|
||||
$object->Dependencies[] = Dependency::fromArray($dependency);
|
||||
$object->dependencies[] = Dependency::fromArray($dependency);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -411,7 +435,7 @@
|
|||
{
|
||||
foreach($_resources as $resource)
|
||||
{
|
||||
$object->Resources[] = Resource::fromArray($resource);
|
||||
$object->resources[] = Resource::fromArray($resource);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -420,7 +444,7 @@
|
|||
{
|
||||
foreach($_components as $component)
|
||||
{
|
||||
$object->Components[] = Component::fromArray($component);
|
||||
$object->components[] = Component::fromArray($component);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -429,7 +453,7 @@
|
|||
{
|
||||
foreach($_execution_units as $unit)
|
||||
{
|
||||
$object->ExecutionUnits[] = ExecutionUnit::fromArray($unit);
|
||||
$object->execution_units[] = ExecutionUnit::fromArray($unit);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -84,24 +84,24 @@
|
|||
*/
|
||||
public function addPackage(Package $package, string $install_path): void
|
||||
{
|
||||
Console::outVerbose("Adding package {$package->Assembly->Package} to package lock file");
|
||||
Console::outVerbose("Adding package {$package->assembly->Package} to package lock file");
|
||||
|
||||
if(!isset($this->Packages[$package->Assembly->Package]))
|
||||
if(!isset($this->Packages[$package->assembly->Package]))
|
||||
{
|
||||
$package_entry = new PackageEntry();
|
||||
$package_entry->addVersion($package, $install_path, true);
|
||||
$package_entry->Name = $package->Assembly->Package;
|
||||
$package_entry->UpdateSource = $package->Header->UpdateSource;
|
||||
$package_entry->Name = $package->assembly->Package;
|
||||
$package_entry->UpdateSource = $package->header->UpdateSource;
|
||||
$package_entry->getDataPath();
|
||||
$this->Packages[$package->Assembly->Package] = $package_entry;
|
||||
$this->Packages[$package->assembly->Package] = $package_entry;
|
||||
$this->update();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->Packages[$package->Assembly->Package]->UpdateSource = $package->Header->UpdateSource;
|
||||
$this->Packages[$package->Assembly->Package]->addVersion($package, $install_path, true);
|
||||
$this->Packages[$package->Assembly->Package]->getDataPath();
|
||||
$this->Packages[$package->assembly->Package]->UpdateSource = $package->header->UpdateSource;
|
||||
$this->Packages[$package->assembly->Package]->addVersion($package, $install_path, true);
|
||||
$this->Packages[$package->assembly->Package]->getDataPath();
|
||||
$this->update();
|
||||
}
|
||||
|
||||
|
|
|
@ -154,14 +154,14 @@
|
|||
{
|
||||
try
|
||||
{
|
||||
if ($this->getVersion($package->Assembly->Version) !== null)
|
||||
if ($this->getVersion($package->assembly->Version) !== null)
|
||||
{
|
||||
if(!$overwrite)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->removeVersion($package->Assembly->Version);
|
||||
$this->removeVersion($package->assembly->Version);
|
||||
}
|
||||
}
|
||||
catch (VersionNotFoundException $e)
|
||||
|
@ -170,10 +170,10 @@
|
|||
}
|
||||
|
||||
$version = new VersionEntry();
|
||||
$version->Version = $package->Assembly->Version;
|
||||
$version->Compiler = $package->Header->CompilerExtension;
|
||||
$version->ExecutionUnits = $package->ExecutionUnits;
|
||||
$version->MainExecutionPolicy = $package->MainExecutionPolicy;
|
||||
$version->Version = $package->assembly->Version;
|
||||
$version->Compiler = $package->header->CompilerExtension;
|
||||
$version->ExecutionUnits = $package->execution_units;
|
||||
$version->MainExecutionPolicy = $package->main_execution_policy;
|
||||
$version->Location = $install_path;
|
||||
|
||||
foreach($version->ExecutionUnits as $unit)
|
||||
|
@ -181,7 +181,7 @@
|
|||
$unit->Data = null;
|
||||
}
|
||||
|
||||
foreach($package->Dependencies as $dependency)
|
||||
foreach($package->dependencies as $dependency)
|
||||
{
|
||||
$version->Dependencies[] = new DependencyEntry($dependency);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
use ncc\Enums\Options\BuildConfigurationValues;
|
||||
use ncc\Exceptions\AccessDeniedException;
|
||||
use ncc\Exceptions\BuildConfigurationNotFoundException;
|
||||
use ncc\Exceptions\FileNotFoundException;
|
||||
use ncc\Exceptions\InvalidBuildConfigurationException;
|
||||
use ncc\Exceptions\InvalidConstantNameException;
|
||||
use ncc\Exceptions\InvalidProjectBuildConfiguration;
|
||||
|
@ -36,6 +35,7 @@
|
|||
use ncc\Exceptions\InvalidPropertyValueException;
|
||||
use ncc\Exceptions\IOException;
|
||||
use ncc\Exceptions\MalformedJsonException;
|
||||
use ncc\Exceptions\PathNotFoundException;
|
||||
use ncc\Exceptions\RuntimeException;
|
||||
use ncc\Exceptions\UndefinedExecutionPolicyException;
|
||||
use ncc\Exceptions\UnsupportedCompilerExtensionException;
|
||||
|
@ -59,45 +59,45 @@
|
|||
*
|
||||
* @var Project
|
||||
*/
|
||||
public $Project;
|
||||
public $project;
|
||||
|
||||
/**
|
||||
* Assembly information for the build output
|
||||
*
|
||||
* @var Assembly
|
||||
*/
|
||||
public $Assembly;
|
||||
public $assembly;
|
||||
|
||||
/**
|
||||
* An array of execution policies
|
||||
*
|
||||
* @var ExecutionPolicy[]
|
||||
*/
|
||||
public $ExecutionPolicies;
|
||||
public $execution_policies;
|
||||
|
||||
/**
|
||||
* Execution Policies to execute by the NCC installer
|
||||
*
|
||||
* @var Installer|null
|
||||
*/
|
||||
public $Installer;
|
||||
public $installer;
|
||||
|
||||
/**
|
||||
* Build configuration for the project
|
||||
*
|
||||
* @var Build
|
||||
*/
|
||||
public $Build;
|
||||
public $build;
|
||||
|
||||
/**
|
||||
* Public Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->Project = new Project();
|
||||
$this->Assembly = new Assembly();
|
||||
$this->ExecutionPolicies = [];
|
||||
$this->Build = new Build();
|
||||
$this->project = new Project();
|
||||
$this->assembly = new Assembly();
|
||||
$this->execution_policies = [];
|
||||
$this->build = new Build();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -118,14 +118,21 @@
|
|||
*/
|
||||
public function validate(bool $throw_exception=True): bool
|
||||
{
|
||||
if(!$this->Project->validate($throw_exception))
|
||||
if(!$this->project->validate($throw_exception))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!$this->Assembly->validate($throw_exception))
|
||||
if(!$this->assembly->validate($throw_exception))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!$this->Build->validate($throw_exception))
|
||||
if(!$this->build->validate($throw_exception))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -134,24 +141,30 @@
|
|||
catch(Exception $e)
|
||||
{
|
||||
if($throw_exception)
|
||||
{
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if($this->Build->Main !== null)
|
||||
if($this->build->Main !== null)
|
||||
{
|
||||
if($this->ExecutionPolicies == null || count($this->ExecutionPolicies) == 0)
|
||||
if($this->execution_policies === null || count($this->execution_policies) === 0)
|
||||
{
|
||||
if($throw_exception)
|
||||
throw new UndefinedExecutionPolicyException(sprintf('Build configuration build.main uses an execution policy "%s" but no policies are defined', $this->Build->Main));
|
||||
{
|
||||
throw new UndefinedExecutionPolicyException(sprintf('Build configuration build.main uses an execution policy "%s" but no policies are defined', $this->build->Main));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$found = false;
|
||||
foreach($this->ExecutionPolicies as $policy)
|
||||
foreach($this->execution_policies as $policy)
|
||||
{
|
||||
if($policy->Name == $this->Build->Main)
|
||||
if($policy->Name === $this->build->Main)
|
||||
{
|
||||
$found = true;
|
||||
break;
|
||||
|
@ -161,14 +174,19 @@
|
|||
if(!$found)
|
||||
{
|
||||
if($throw_exception)
|
||||
throw new UndefinedExecutionPolicyException(sprintf('Build configuration build.main points to a undefined execution policy "%s"', $this->Build->Main));
|
||||
{
|
||||
throw new UndefinedExecutionPolicyException(sprintf('Build configuration build.main points to a undefined execution policy "%s"', $this->build->Main));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if($this->Build->Main == BuildConfigurationValues::ALL)
|
||||
if($this->build->Main === BuildConfigurationValues::ALL)
|
||||
{
|
||||
if($throw_exception)
|
||||
{
|
||||
throw new InvalidBuildConfigurationException(sprintf('Build configuration build.main cannot be set to "%s"', BuildConfigurationValues::ALL));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -182,10 +200,12 @@
|
|||
*/
|
||||
private function getExecutionPolicy(string $name): ?ExecutionPolicy
|
||||
{
|
||||
foreach($this->ExecutionPolicies as $executionPolicy)
|
||||
foreach($this->execution_policies as $executionPolicy)
|
||||
{
|
||||
if($executionPolicy->Name == $name)
|
||||
if($executionPolicy->Name === $name)
|
||||
{
|
||||
return $executionPolicy;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -201,80 +221,105 @@
|
|||
*/
|
||||
public function getRequiredExecutionPolicies(string $build_configuration=BuildConfigurationValues::DEFAULT): array
|
||||
{
|
||||
if($this->ExecutionPolicies == null || count($this->ExecutionPolicies) == 0)
|
||||
if($this->execution_policies === null || count($this->execution_policies) === 0)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
$defined_polices = [];
|
||||
$required_policies = [];
|
||||
|
||||
/** @var ExecutionPolicy $execution_policy */
|
||||
foreach($this->ExecutionPolicies as $execution_policy)
|
||||
foreach($this->execution_policies as $execution_policy)
|
||||
{
|
||||
$defined_polices[] = $execution_policy->Name;
|
||||
//$execution_policy->validate();
|
||||
}
|
||||
|
||||
// Check the installer by batch
|
||||
if($this->Installer !== null)
|
||||
if($this->installer !== null)
|
||||
{
|
||||
$array_rep = $this->Installer->toArray();
|
||||
$array_rep = $this->installer->toArray();
|
||||
/** @var string[] $value */
|
||||
foreach($array_rep as $key => $value)
|
||||
{
|
||||
if($value == null || count($value) == 0)
|
||||
if($value === null || count($value) === 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach($value as $unit)
|
||||
{
|
||||
if(!in_array($unit, $defined_polices))
|
||||
if(!in_array($unit, $defined_polices, true))
|
||||
{
|
||||
throw new UndefinedExecutionPolicyException('The property \'' . $key . '\' in the project configuration calls for an undefined execution policy \'' . $unit . '\'');
|
||||
if(!in_array($unit, $required_policies))
|
||||
}
|
||||
|
||||
if(!in_array($unit, $required_policies, true))
|
||||
{
|
||||
$required_policies[] = $unit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($this->Build->PreBuild !== null && count($this->Build->PostBuild) > 0)
|
||||
if($this->build->PreBuild !== null && count($this->build->PostBuild) > 0)
|
||||
{
|
||||
foreach($this->Build->PostBuild as $unit)
|
||||
foreach($this->build->PostBuild as $unit)
|
||||
{
|
||||
if(!in_array($unit, $defined_polices))
|
||||
if(!in_array($unit, $defined_polices, true))
|
||||
{
|
||||
throw new UndefinedExecutionPolicyException('The property \'build.pre_build\' in the project configuration calls for an undefined execution policy \'' . $unit . '\'');
|
||||
if(!in_array($unit, $required_policies))
|
||||
}
|
||||
|
||||
if(!in_array($unit, $required_policies, true))
|
||||
{
|
||||
$required_policies[] = $unit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($this->Build->PostBuild !== null && count($this->Build->PostBuild) > 0)
|
||||
if($this->build->PostBuild !== null && count($this->build->PostBuild) > 0)
|
||||
{
|
||||
foreach($this->Build->PostBuild as $unit)
|
||||
foreach($this->build->PostBuild as $unit)
|
||||
{
|
||||
if(!in_array($unit, $defined_polices))
|
||||
if(!in_array($unit, $defined_polices, true))
|
||||
{
|
||||
throw new UndefinedExecutionPolicyException('The property \'build.pre_build\' in the project configuration calls for an undefined execution policy \'' . $unit . '\'');
|
||||
if(!in_array($unit, $required_policies))
|
||||
}
|
||||
|
||||
if(!in_array($unit, $required_policies, true))
|
||||
{
|
||||
$required_policies[] = $unit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** @noinspection DegradedSwitchInspection */
|
||||
switch($build_configuration)
|
||||
{
|
||||
case BuildConfigurationValues::ALL:
|
||||
/** @var BuildConfiguration $configuration */
|
||||
foreach($this->Build->Configurations as $configuration)
|
||||
foreach($this->build->Configurations as $configuration)
|
||||
{
|
||||
foreach($this->processBuildPolicies($configuration, $defined_polices) as $policy)
|
||||
{
|
||||
if(!in_array($policy, $required_policies))
|
||||
if(!in_array($policy, $required_policies, true))
|
||||
{
|
||||
$required_policies[] = $policy;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$configuration = $this->Build->getBuildConfiguration($build_configuration);
|
||||
$configuration = $this->build->getBuildConfiguration($build_configuration);
|
||||
foreach($this->processBuildPolicies($configuration, $defined_polices) as $policy)
|
||||
{
|
||||
if(!in_array($policy, $required_policies))
|
||||
if(!in_array($policy, $required_policies, true))
|
||||
{
|
||||
$required_policies[] = $policy;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -282,42 +327,48 @@
|
|||
foreach($required_policies as $policy)
|
||||
{
|
||||
$execution_policy = $this->getExecutionPolicy($policy);
|
||||
if($execution_policy->ExitHandlers !== null)
|
||||
if($execution_policy?->ExitHandlers !== null)
|
||||
{
|
||||
if(
|
||||
$execution_policy->ExitHandlers->Success !== null &&
|
||||
$execution_policy->ExitHandlers->Success->Run !== null
|
||||
$execution_policy?->ExitHandlers->Success !== null &&
|
||||
$execution_policy?->ExitHandlers->Success->Run !== null
|
||||
)
|
||||
{
|
||||
if(!in_array($execution_policy->ExitHandlers->Success->Run, $defined_polices))
|
||||
throw new UndefinedExecutionPolicyException('The execution policy \'' . $execution_policy->Name . '\' Success exit handler points to a undefined execution policy \'' . $execution_policy->ExitHandlers->Success->Run . '\'');
|
||||
if(!in_array($execution_policy?->ExitHandlers->Success->Run, $defined_polices, true))
|
||||
{
|
||||
throw new UndefinedExecutionPolicyException('The execution policy \'' . $execution_policy?->Name . '\' Success exit handler points to a undefined execution policy \'' . $execution_policy?->ExitHandlers->Success->Run . '\'');
|
||||
}
|
||||
|
||||
if(!in_array($execution_policy->ExitHandlers->Success->Run, $required_policies))
|
||||
$required_policies[] = $execution_policy->ExitHandlers->Success->Run;
|
||||
if(!in_array($execution_policy?->ExitHandlers->Success->Run, $required_policies, true))
|
||||
{
|
||||
$required_policies[] = $execution_policy?->ExitHandlers->Success->Run;
|
||||
}
|
||||
}
|
||||
|
||||
if(
|
||||
$execution_policy->ExitHandlers->Warning !== null &&
|
||||
$execution_policy->ExitHandlers->Warning->Run !== null
|
||||
)
|
||||
if($execution_policy?->ExitHandlers->Warning !== null && $execution_policy?->ExitHandlers->Warning->Run !== null)
|
||||
{
|
||||
if(!in_array($execution_policy->ExitHandlers->Warning->Run, $defined_polices))
|
||||
throw new UndefinedExecutionPolicyException('The execution policy \'' . $execution_policy->Name . '\' Warning exit handler points to a undefined execution policy \'' . $execution_policy->ExitHandlers->Warning->Run . '\'');
|
||||
if(!in_array($execution_policy?->ExitHandlers->Warning->Run, $defined_polices, true))
|
||||
{
|
||||
throw new UndefinedExecutionPolicyException('The execution policy \'' . $execution_policy?->Name . '\' Warning exit handler points to a undefined execution policy \'' . $execution_policy?->ExitHandlers->Warning->Run . '\'');
|
||||
}
|
||||
|
||||
if(!in_array($execution_policy->ExitHandlers->Warning->Run, $required_policies))
|
||||
$required_policies[] = $execution_policy->ExitHandlers->Warning->Run;
|
||||
if(!in_array($execution_policy?->ExitHandlers->Warning->Run, $required_policies, true))
|
||||
{
|
||||
$required_policies[] = $execution_policy?->ExitHandlers->Warning->Run;
|
||||
}
|
||||
}
|
||||
|
||||
if(
|
||||
$execution_policy->ExitHandlers->Error !== null &&
|
||||
$execution_policy->ExitHandlers->Error->Run !== null
|
||||
)
|
||||
if($execution_policy?->ExitHandlers->Error !== null && $execution_policy?->ExitHandlers->Error->Run !== null)
|
||||
{
|
||||
if(!in_array($execution_policy->ExitHandlers->Error->Run, $defined_polices))
|
||||
throw new UndefinedExecutionPolicyException('The execution policy \'' . $execution_policy->Name . '\' Error exit handler points to a undefined execution policy \'' . $execution_policy->ExitHandlers->Error->Run . '\'');
|
||||
if(!in_array($execution_policy?->ExitHandlers->Error->Run, $defined_polices, true))
|
||||
{
|
||||
throw new UndefinedExecutionPolicyException('The execution policy \'' . $execution_policy?->Name . '\' Error exit handler points to a undefined execution policy \'' . $execution_policy?->ExitHandlers->Error->Run . '\'');
|
||||
}
|
||||
|
||||
if(!in_array($execution_policy->ExitHandlers->Error->Run, $required_policies))
|
||||
$required_policies[] = $execution_policy->ExitHandlers->Error->Run;
|
||||
if(!in_array($execution_policy?->ExitHandlers->Error->Run, $required_policies, true))
|
||||
{
|
||||
$required_policies[] = $execution_policy?->ExitHandlers->Error->Run;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -335,26 +386,41 @@
|
|||
public function toArray(bool $bytecode=false): array
|
||||
{
|
||||
$execution_policies = null;
|
||||
if($this->ExecutionPolicies !== null)
|
||||
if($this->execution_policies !== null)
|
||||
{
|
||||
$execution_policies = [];
|
||||
foreach($this->ExecutionPolicies as $executionPolicy)
|
||||
foreach($this->execution_policies as $executionPolicy)
|
||||
{
|
||||
$execution_policies[$executionPolicy->Name] = $executionPolicy->toArray($bytecode);
|
||||
}
|
||||
}
|
||||
|
||||
$results = [];
|
||||
if($this->Project !== null)
|
||||
$results[($bytecode ? Functions::cbc('project') : 'project')] = $this->Project->toArray($bytecode);
|
||||
if($this->Assembly !== null)
|
||||
$results['assembly'] = $this->Assembly->toArray($bytecode);
|
||||
if($this->Build !== null)
|
||||
$results[($bytecode ? Functions::cbc('build') : 'build')] = $this->Build->toArray($bytecode);
|
||||
if($this->Installer !== null)
|
||||
$results[($bytecode ? Functions::cbc('installer') : 'installer')] = $this->Installer->toArray($bytecode);
|
||||
if($this->project !== null)
|
||||
{
|
||||
$results[($bytecode ? Functions::cbc('project') : 'project')] = $this->project->toArray($bytecode);
|
||||
}
|
||||
|
||||
if($this->assembly !== null)
|
||||
{
|
||||
$results['assembly'] = $this->assembly->toArray($bytecode);
|
||||
}
|
||||
|
||||
if($this->build !== null)
|
||||
{
|
||||
$results[($bytecode ? Functions::cbc('build') : 'build')] = $this->build->toArray($bytecode);
|
||||
}
|
||||
|
||||
if($this->installer !== null)
|
||||
{
|
||||
$results[($bytecode ? Functions::cbc('installer') : 'installer')] = $this->installer->toArray($bytecode);
|
||||
}
|
||||
|
||||
if($execution_policies !== null && count($execution_policies) > 0)
|
||||
{
|
||||
$results[($bytecode ? Functions::cbc('execution_policies') : 'execution_policies')] = $execution_policies;
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
|
@ -365,10 +431,9 @@
|
|||
* @param bool $bytecode
|
||||
* @return void
|
||||
* @throws MalformedJsonException
|
||||
* @noinspection PhpMissingReturnTypeInspection
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
public function toFile(string $path, bool $bytecode=false)
|
||||
public function toFile(string $path, bool $bytecode=false): void
|
||||
{
|
||||
if(!$bytecode)
|
||||
{
|
||||
|
@ -387,26 +452,38 @@
|
|||
*/
|
||||
public static function fromArray(array $data): ProjectConfiguration
|
||||
{
|
||||
$ProjectConfigurationObject = new ProjectConfiguration();
|
||||
$object = new self();
|
||||
|
||||
if(isset($data['project']))
|
||||
$ProjectConfigurationObject->Project = Project::fromArray($data['project']);
|
||||
{
|
||||
$object->project = Project::fromArray($data['project']);
|
||||
}
|
||||
|
||||
if(isset($data['assembly']))
|
||||
$ProjectConfigurationObject->Assembly = Assembly::fromArray($data['assembly']);
|
||||
{
|
||||
$object->assembly = Assembly::fromArray($data['assembly']);
|
||||
}
|
||||
|
||||
if(isset($data['build']))
|
||||
$ProjectConfigurationObject->Build = Build::fromArray($data['build']);
|
||||
{
|
||||
$object->build = Build::fromArray($data['build']);
|
||||
}
|
||||
|
||||
if(isset($data['installer']))
|
||||
$ProjectConfigurationObject->Installer = Installer::fromArray($data['installer']);
|
||||
{
|
||||
$object->installer = Installer::fromArray($data['installer']);
|
||||
}
|
||||
|
||||
if(isset($data['execution_policies']))
|
||||
{
|
||||
$ProjectConfigurationObject->ExecutionPolicies = [];
|
||||
$object->execution_policies = [];
|
||||
foreach($data['execution_policies'] as $execution_policy)
|
||||
{
|
||||
$ProjectConfigurationObject->ExecutionPolicies[] = ExecutionPolicy::fromArray($execution_policy);
|
||||
$object->execution_policies[] = ExecutionPolicy::fromArray($execution_policy);
|
||||
}
|
||||
}
|
||||
|
||||
return $ProjectConfigurationObject;
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -414,15 +491,14 @@
|
|||
*
|
||||
* @param string $path
|
||||
* @return ProjectConfiguration
|
||||
* @throws FileNotFoundException
|
||||
* @throws MalformedJsonException
|
||||
* @throws AccessDeniedException
|
||||
* @throws IOException
|
||||
* @noinspection PhpUnused
|
||||
* @throws MalformedJsonException
|
||||
* @throws PathNotFoundException
|
||||
*/
|
||||
public static function fromFile(string $path): ProjectConfiguration
|
||||
{
|
||||
return ProjectConfiguration::fromArray(Functions::loadJsonFile($path, Functions::FORCE_ARRAY));
|
||||
return self::fromArray(Functions::loadJsonFile($path, Functions::FORCE_ARRAY));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -439,8 +515,11 @@
|
|||
{
|
||||
foreach ($configuration->PreBuild as $unit)
|
||||
{
|
||||
if (!in_array($unit, $defined_polices))
|
||||
if (!in_array($unit, $defined_polices, true))
|
||||
{
|
||||
throw new UndefinedExecutionPolicyException('The property \'pre_build\' in the build configuration \'' . $configuration->Name . '\' calls for an undefined execution policy \'' . $unit . '\'');
|
||||
}
|
||||
|
||||
$required_policies[] = $unit;
|
||||
}
|
||||
}
|
||||
|
@ -449,8 +528,11 @@
|
|||
{
|
||||
foreach ($configuration->PostBuild as $unit)
|
||||
{
|
||||
if (!in_array($unit, $defined_polices))
|
||||
if (!in_array($unit, $defined_polices, true))
|
||||
{
|
||||
throw new UndefinedExecutionPolicyException('The property \'pre_build\' in the build configuration \'' . $configuration->Name . '\' calls for an undefined execution policy \'' . $unit . '\'');
|
||||
}
|
||||
|
||||
$required_policies[] = $unit;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue