1.0.0 Alpha Release #59

Merged
netkas merged 213 commits from v1.0.0_alpha into master 2023-01-29 23:27:58 +00:00
3 changed files with 76 additions and 39 deletions
Showing only changes of commit b0d6654e95 - Show all commits

View file

@ -4,13 +4,21 @@
use Exception;
use ncc\Abstracts\ConsoleColors;
use ncc\Abstracts\RemoteSource;
use ncc\Abstracts\BuiltinRemoteSourceType;
use ncc\Abstracts\DefinedRemoteSourceType;
use ncc\Abstracts\RemoteSourceType;
use ncc\Abstracts\Scopes;
use ncc\Classes\ComposerExtension\ComposerSource;
use ncc\Classes\ComposerExtension\ComposerSourceBuiltin;
use ncc\Classes\GithubExtension\GithubService;
use ncc\Classes\GitlabExtension\GitlabService;
use ncc\Exceptions\FileNotFoundException;
use ncc\Exceptions\InstallationException;
use ncc\Exceptions\PackageLockException;
use ncc\Exceptions\RuntimeException;
use ncc\Exceptions\VersionNotFoundException;
use ncc\Managers\CredentialManager;
use ncc\Managers\PackageManager;
use ncc\Managers\RemoteSourcesManager;
use ncc\Objects\CliHelpSection;
use ncc\Objects\Package;
use ncc\Objects\RemotePackageInput;
@ -32,6 +40,7 @@
{
try
{
Console::outException('Example Error', new Exception('test'), 1);
self::installPackage($args);
return;
}
@ -191,32 +200,57 @@
return;
}
$path = $package;
$parsed_source = new RemotePackageInput($path);
if($parsed_source->Vendor !== null && $parsed_source->Package !== null)
// check if authentication is provided
$entry_arg = ($args['auth'] ?? null);
$credential_manager = new CredentialManager();
$credential = $credential_manager->getVault()->getEntry($entry_arg);
if($credential == null)
{
if($parsed_source->Source == null)
{
Console::outError('No source specified', true, 1);
Console::outError(sprintf('Unknown credential entry \'%s\'', $entry_arg), true, 1);
return;
}
switch($parsed_source->Source)
if(!$credential->isCurrentlyDecrypted())
{
// Try 3 times
for($i = 0; $i < 3; $i++)
{
case RemoteSource::Composer:
try
{
$path = ComposerSource::fetch($parsed_source);
$credential->unlock(Console::passwordInput(sprintf('Enter Password for %s: ', $credential->getName())));
}
catch (RuntimeException $e)
{
Console::outException(sprintf('Failed to unlock credential %s', $credential->getName()), $e, 1);
return;
}
if($credential->isCurrentlyDecrypted())
break;
Console::outWarning(sprintf('Invalid password, %d attempts remaining', 2 - $i));
}
if(!$credential->isCurrentlyDecrypted())
{
Console::outError('Failed to unlock credential', true, 1);
return;
}
}
$path = $package;
$parsed_source = new RemotePackageInput($path);
if($parsed_source->Vendor !== null && $parsed_source->Package !== null)
{
try
{
$path = $package_manager->fetchFromSource($parsed_source->toString());
}
catch (Exception $e)
{
Console::outException(sprintf('Failed to fetch package %s', $package), $e, 1);
return;
}
default:
Console::outError('Cannot install package from source: ' . $parsed_source->Source, true, 1);
Console::outException('Failed to fetch package from source', $e, 1);
return;
}
}

View file

@ -110,10 +110,13 @@
$extension = $package->Header->CompilerExtension->Extension;
$installation_paths = new InstallationPaths($this->PackagesPath . DIRECTORY_SEPARATOR . $package->Assembly->Package . '=' . $package->Assembly->Version);
$installer = match ($extension) {
$installer = match ($extension)
{
CompilerExtensions::PHP => new PhpInstaller($package),
default => throw new UnsupportedCompilerExtensionException('The compiler extension \'' . $extension . '\' is not supported'),
};
$execution_pointer_manager = new ExecutionPointerManager();
PackageCompiler::compilePackageConstants($package, [
ConstantReferences::Install => $installation_paths
@ -407,24 +410,19 @@
*
* @param string $source
* @return string
* @throws AccessDeniedException
* @throws FileNotFoundException
* @throws IOException
* @throws InstallationException
* @throws MissingDependencyException
* @throws NotImplementedException
* @throws PackageAlreadyInstalledException
* @throws PackageLockException
* @throws PackageNotFoundException
* @throws PackageParsingException
* @throws UnsupportedCompilerExtensionException
* @throws UnsupportedRunnerException
* @throws VersionNotFoundException
*/
public function installFromSource(string $source): string
{
$package_path = $this->fetchFromSource($source);
return $this->install($package_path);
try
{
$package = $this->fetchFromSource($source);
return $this->install($package);
}
catch(Exception $e)
{
throw new InstallationException('Cannot install package from source, ' . $e->getMessage(), $e);
}
}
/**
@ -481,6 +479,11 @@
case DependencySourceType::StaticLinking:
throw new PackageNotFoundException('Static linking not possible, package ' . $dependency->Name . ' is not installed');
case DependencySourceType::RemoteSource:
Console::outDebug('installing from remote source ' . $dependency->Source);
$this->installFromSource($dependency->Source);
break;
default:
throw new NotImplementedException('Dependency source type ' . $dependency->SourceType . ' is not implemented');
}

View file

@ -30,7 +30,7 @@
/**
* Optional. The actual source where NCC can fetch the dependency from
*
* @var DependencySourceType|string|null
* @var string|null
*/
public $Source;