Added Logging calls to \ncc\Managers > PackageManager
This commit is contained in:
parent
a995732ff7
commit
5d9f02512f
1 changed files with 53 additions and 21 deletions
|
@ -22,6 +22,7 @@
|
||||||
use ncc\Exceptions\AccessDeniedException;
|
use ncc\Exceptions\AccessDeniedException;
|
||||||
use ncc\Exceptions\FileNotFoundException;
|
use ncc\Exceptions\FileNotFoundException;
|
||||||
use ncc\Exceptions\InstallationException;
|
use ncc\Exceptions\InstallationException;
|
||||||
|
use ncc\Exceptions\InvalidPackageNameException;
|
||||||
use ncc\Exceptions\InvalidScopeException;
|
use ncc\Exceptions\InvalidScopeException;
|
||||||
use ncc\Exceptions\IOException;
|
use ncc\Exceptions\IOException;
|
||||||
use ncc\Exceptions\MissingDependencyException;
|
use ncc\Exceptions\MissingDependencyException;
|
||||||
|
@ -89,6 +90,7 @@
|
||||||
* @throws FileNotFoundException
|
* @throws FileNotFoundException
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @throws InstallationException
|
* @throws InstallationException
|
||||||
|
* @throws InvalidScopeException
|
||||||
* @throws MissingDependencyException
|
* @throws MissingDependencyException
|
||||||
* @throws NotImplementedException
|
* @throws NotImplementedException
|
||||||
* @throws PackageAlreadyInstalledException
|
* @throws PackageAlreadyInstalledException
|
||||||
|
@ -98,6 +100,7 @@
|
||||||
* @throws UnsupportedCompilerExtensionException
|
* @throws UnsupportedCompilerExtensionException
|
||||||
* @throws UnsupportedRunnerException
|
* @throws UnsupportedRunnerException
|
||||||
* @throws VersionNotFoundException
|
* @throws VersionNotFoundException
|
||||||
|
* @throws InvalidPackageNameException
|
||||||
*/
|
*/
|
||||||
public function install(string $package_path, ?Entry $entry=null, array $options=[]): string
|
public function install(string $package_path, ?Entry $entry=null, array $options=[]): string
|
||||||
{
|
{
|
||||||
|
@ -393,9 +396,12 @@
|
||||||
if($input->Version == null)
|
if($input->Version == null)
|
||||||
$input->Version = Versions::Latest;
|
$input->Version = Versions::Latest;
|
||||||
|
|
||||||
|
Console::outVerbose('Fetching package ' . $input->Package . ' from ' . $input->Source . ' (' . $input->Version . ')');
|
||||||
|
|
||||||
$remote_source_type = Resolver::detectRemoteSourceType($input->Source);
|
$remote_source_type = Resolver::detectRemoteSourceType($input->Source);
|
||||||
if($remote_source_type == RemoteSourceType::Builtin)
|
if($remote_source_type == RemoteSourceType::Builtin)
|
||||||
{
|
{
|
||||||
|
Console::outDebug('using builtin source ' . $input->Source);
|
||||||
switch($input->Source)
|
switch($input->Source)
|
||||||
{
|
{
|
||||||
case BuiltinRemoteSourceType::Composer:
|
case BuiltinRemoteSourceType::Composer:
|
||||||
|
@ -415,6 +421,7 @@
|
||||||
|
|
||||||
if($remote_source_type == RemoteSourceType::Defined)
|
if($remote_source_type == RemoteSourceType::Defined)
|
||||||
{
|
{
|
||||||
|
Console::outDebug('using defined source ' . $input->Source);
|
||||||
$remote_source_manager = new RemoteSourcesManager();
|
$remote_source_manager = new RemoteSourcesManager();
|
||||||
$source = $remote_source_manager->getRemoteSource($input->Source);
|
$source = $remote_source_manager->getRemoteSource($input->Source);
|
||||||
if($source == null)
|
if($source == null)
|
||||||
|
@ -427,11 +434,13 @@
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Console::outDebug(sprintf('fetching package %s from %s', $input->Package, $repositoryQueryResults->Files->ZipballUrl));
|
||||||
$archive = Functions::downloadGitServiceFile($repositoryQueryResults->Files->ZipballUrl, $entry);
|
$archive = Functions::downloadGitServiceFile($repositoryQueryResults->Files->ZipballUrl, $entry);
|
||||||
return PackageCompiler::tryCompile(Functions::extractArchive($archive), $repositoryQueryResults->Version);
|
return PackageCompiler::tryCompile(Functions::extractArchive($archive), $repositoryQueryResults->Version);
|
||||||
}
|
}
|
||||||
catch(Throwable $e)
|
catch(Throwable $e)
|
||||||
{
|
{
|
||||||
|
Console::outDebug('cannot fetch package from zipball url, ' . $e->getMessage());
|
||||||
$exceptions[] = $e;
|
$exceptions[] = $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -440,11 +449,13 @@
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Console::outDebug(sprintf('fetching package %s from %s', $input->Package, $repositoryQueryResults->Files->TarballUrl));
|
||||||
$archive = Functions::downloadGitServiceFile($repositoryQueryResults->Files->TarballUrl, $entry);
|
$archive = Functions::downloadGitServiceFile($repositoryQueryResults->Files->TarballUrl, $entry);
|
||||||
return PackageCompiler::tryCompile(Functions::extractArchive($archive), $repositoryQueryResults->Version);
|
return PackageCompiler::tryCompile(Functions::extractArchive($archive), $repositoryQueryResults->Version);
|
||||||
}
|
}
|
||||||
catch(Exception $e)
|
catch(Exception $e)
|
||||||
{
|
{
|
||||||
|
Console::outDebug('cannot fetch package from tarball url, ' . $e->getMessage());
|
||||||
$exceptions[] = $e;
|
$exceptions[] = $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -453,10 +464,12 @@
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Console::outDebug(sprintf('fetching package %s from %s', $input->Package, $repositoryQueryResults->Files->PackageUrl));
|
||||||
return Functions::downloadGitServiceFile($repositoryQueryResults->Files->PackageUrl, $entry);
|
return Functions::downloadGitServiceFile($repositoryQueryResults->Files->PackageUrl, $entry);
|
||||||
}
|
}
|
||||||
catch(Exception $e)
|
catch(Exception $e)
|
||||||
{
|
{
|
||||||
|
Console::outDebug('cannot fetch package from package url, ' . $e->getMessage());
|
||||||
$exceptions[] = $e;
|
$exceptions[] = $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -465,6 +478,7 @@
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Console::outDebug(sprintf('fetching package %s from %s', $input->Package, $repositoryQueryResults->Files->GitHttpUrl ?? $repositoryQueryResults->Files->GitSshUrl));
|
||||||
$git_repository = GitClient::cloneRepository($repositoryQueryResults->Files->GitHttpUrl ?? $repositoryQueryResults->Files->GitSshUrl);
|
$git_repository = GitClient::cloneRepository($repositoryQueryResults->Files->GitHttpUrl ?? $repositoryQueryResults->Files->GitSshUrl);
|
||||||
|
|
||||||
foreach(GitClient::getTags($git_repository) as $tag)
|
foreach(GitClient::getTags($git_repository) as $tag)
|
||||||
|
@ -475,9 +489,12 @@
|
||||||
return PackageCompiler::tryCompile($git_repository, $repositoryQueryResults->Version);
|
return PackageCompiler::tryCompile($git_repository, $repositoryQueryResults->Version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Console::outDebug('cannot fetch package from git repository, no matching tag found');
|
||||||
}
|
}
|
||||||
catch(Exception $e)
|
catch(Exception $e)
|
||||||
{
|
{
|
||||||
|
Console::outDebug('cannot fetch package from git repository, ' . $e->getMessage());
|
||||||
$exceptions[] = $e;
|
$exceptions[] = $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -525,6 +542,7 @@
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Console::outVerbose(sprintf('Installing package from source %s', $source));
|
||||||
$package = $this->fetchFromSource($source, $entry);
|
$package = $this->fetchFromSource($source, $entry);
|
||||||
return $this->install($package, $entry);
|
return $this->install($package, $entry);
|
||||||
}
|
}
|
||||||
|
@ -544,6 +562,8 @@
|
||||||
* @throws FileNotFoundException
|
* @throws FileNotFoundException
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @throws InstallationException
|
* @throws InstallationException
|
||||||
|
* @throws InvalidPackageNameException
|
||||||
|
* @throws InvalidScopeException
|
||||||
* @throws MissingDependencyException
|
* @throws MissingDependencyException
|
||||||
* @throws NotImplementedException
|
* @throws NotImplementedException
|
||||||
* @throws PackageAlreadyInstalledException
|
* @throws PackageAlreadyInstalledException
|
||||||
|
@ -562,18 +582,20 @@
|
||||||
|
|
||||||
if ($dependent_package !== null && $dependency->Version !== null && Validate::version($dependency->Version))
|
if ($dependent_package !== null && $dependency->Version !== null && Validate::version($dependency->Version))
|
||||||
{
|
{
|
||||||
|
Console::outDebug('dependency has version constraint, checking if package is installed');
|
||||||
$dependent_version = $this->getPackageVersion($dependency->Name, $dependency->Version);
|
$dependent_version = $this->getPackageVersion($dependency->Name, $dependency->Version);
|
||||||
if ($dependent_version !== null)
|
if ($dependent_version !== null)
|
||||||
$dependency_met = true;
|
$dependency_met = true;
|
||||||
}
|
}
|
||||||
elseif ($dependent_package !== null && $dependency->Version == null)
|
elseif ($dependent_package !== null && $dependency->Version == null)
|
||||||
{
|
{
|
||||||
|
Console::outDebug(sprintf('dependency %s has no version specified, assuming dependency is met', $dependency->Name));
|
||||||
$dependency_met = true;
|
$dependency_met = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($dependency->SourceType !== null)
|
Console::outDebug('dependency met: ' . ($dependency_met ? 'true' : 'false'));
|
||||||
{
|
|
||||||
if(!$dependency_met)
|
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)
|
switch ($dependency->SourceType)
|
||||||
|
@ -598,7 +620,6 @@
|
||||||
throw new NotImplementedException('Dependency source type ' . $dependency->SourceType . ' is not implemented');
|
throw new NotImplementedException('Dependency source type ' . $dependency->SourceType . ' is not implemented');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
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));
|
||||||
|
@ -614,6 +635,7 @@
|
||||||
*/
|
*/
|
||||||
public function getPackage(string $package): ?PackageEntry
|
public function getPackage(string $package): ?PackageEntry
|
||||||
{
|
{
|
||||||
|
Console::outDebug('getting package ' . $package);
|
||||||
return $this->getPackageLockManager()->getPackageLock()->getPackage($package);
|
return $this->getPackageLockManager()->getPackageLock()->getPackage($package);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -628,6 +650,7 @@
|
||||||
*/
|
*/
|
||||||
public function getPackageVersion(string $package, string $version): ?VersionEntry
|
public function getPackageVersion(string $package, string $version): ?VersionEntry
|
||||||
{
|
{
|
||||||
|
Console::outDebug('getting package version ' . $package . '=' . $version);
|
||||||
return $this->getPackage($package)?->getVersion($version);
|
return $this->getPackage($package)?->getVersion($version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -638,9 +661,11 @@
|
||||||
* @return VersionEntry|null
|
* @return VersionEntry|null
|
||||||
* @throws VersionNotFoundException
|
* @throws VersionNotFoundException
|
||||||
* @throws PackageLockException
|
* @throws PackageLockException
|
||||||
|
* @noinspection PhpUnused
|
||||||
*/
|
*/
|
||||||
public function getLatestVersion(string $package): ?VersionEntry
|
public function getLatestVersion(string $package): ?VersionEntry
|
||||||
{
|
{
|
||||||
|
Console::outDebug('getting latest version of package ' . $package);
|
||||||
return $this->getPackage($package)?->getVersion($this->getPackage($package)?->getLatestVersion());
|
return $this->getPackage($package)?->getVersion($this->getPackage($package)?->getLatestVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -775,12 +800,15 @@
|
||||||
|
|
||||||
if($filesystem->exists($version_entry->Location))
|
if($filesystem->exists($version_entry->Location))
|
||||||
{
|
{
|
||||||
|
Console::outVerbose(sprintf('Removing package files from %s', $version_entry->Location));
|
||||||
|
|
||||||
/** @var SplFileInfo $item */
|
/** @var SplFileInfo $item */
|
||||||
/** @noinspection PhpRedundantOptionalArgumentInspection */
|
/** @noinspection PhpRedundantOptionalArgumentInspection */
|
||||||
foreach($scanner($version_entry->Location, true) as $item)
|
foreach($scanner($version_entry->Location, true) as $item)
|
||||||
{
|
{
|
||||||
if(is_file($item->getPath()))
|
if(is_file($item->getPath()))
|
||||||
{
|
{
|
||||||
|
Console::outDebug('removing file ' . $item->getPath());
|
||||||
Console::outDebug(sprintf('deleting %s', $item->getPath()));
|
Console::outDebug(sprintf('deleting %s', $item->getPath()));
|
||||||
$filesystem->remove($item->getPath());
|
$filesystem->remove($item->getPath());
|
||||||
}
|
}
|
||||||
|
@ -828,6 +856,7 @@
|
||||||
foreach($package_entry->getVersions() as $version)
|
foreach($package_entry->getVersions() as $version)
|
||||||
{
|
{
|
||||||
$version_entry = $package_entry->getVersion($version);
|
$version_entry = $package_entry->getVersion($version);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$this->uninstallPackageVersion($package, $version_entry->Version);
|
$this->uninstallPackageVersion($package, $version_entry->Version);
|
||||||
|
@ -846,6 +875,8 @@
|
||||||
*/
|
*/
|
||||||
private static function initData(Package $package, InstallationPaths $paths): void
|
private static function initData(Package $package, InstallationPaths $paths): void
|
||||||
{
|
{
|
||||||
|
Console::outVerbose(sprintf('Initializing data for %s', $package->Assembly->Name));
|
||||||
|
|
||||||
// Create data files
|
// Create data files
|
||||||
$dependencies = [];
|
$dependencies = [];
|
||||||
foreach($package->Dependencies as $dependency)
|
foreach($package->Dependencies as $dependency)
|
||||||
|
@ -868,6 +899,7 @@
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Console::outDebug(sprintf('generating data file %s', $file));
|
||||||
IO::fwrite($file, $data);
|
IO::fwrite($file, $data);
|
||||||
}
|
}
|
||||||
catch (IOException $e)
|
catch (IOException $e)
|
||||||
|
|
Loading…
Add table
Reference in a new issue