Skip to content

Commit

Permalink
Fix handling of not found nuget packages (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
RuzmanovDev authored Nov 8, 2024
1 parent 28ea7a7 commit 23d6a61
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private async Task<PackageXmlDocumentModel> GetPackageXmlDocument(string id, str

PackageSpecificationResponseModel specification = await this.GetPackageSpecification(id, version, sources);

if (specification.SpecResponse == null || specification.SpecResponse.StatusCode != HttpStatusCode.OK)
if (specification?.SpecResponse == null || specification.SpecResponse.StatusCode != HttpStatusCode.OK)
{
return null;
}
Expand Down Expand Up @@ -135,7 +135,6 @@ private async Task<PackageSpecificationResponseModel> GetPackageSpecification(st
if (packageSepc.SpecResponse == null)
{
this.logger.LogError("Unable to retrieve package with name: {Id} and version: {Version} from any of the provided sources: {Sources}", id, version, nugetPackageSources.Select(s => s.Source));
throw new UpgradeException("Upgrade failed!");
}

return packageSepc;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.Extensions.Logging;
using NuGet.Configuration;
using Sitefinity_CLI.Exceptions;
using Sitefinity_CLI.Model;
using Sitefinity_CLI.PackageManagement.Contracts;
using Sitefinity_CLI.Services.Contracts;
Expand Down Expand Up @@ -81,6 +82,10 @@ private async Task GenerateProjectUpgradeConfigSection(

this.logger.LogInformation($"Collecting Sitefinity NuGet package tree for '{projectFilePath}'...");
NuGetPackage currentSitefinityVersionPackageTree = await this.sitefinityPackageManager.GetSitefinityPackageTree(currentSitefinityVersion.ToString(), packageSources);
if (currentSitefinityVersionPackageTree == null)
{
throw new UpgradeException("Unable to obtain current Sitefinity dependency tree");
}

this.processedPackagesPerProjectCache[projectFilePath] = new HashSet<string>();
if (!this.TryAddPackageTreeToProjectUpgradeConfigSection(powerShellXmlConfig, projectNode, projectFilePath, currentSitefinityVersionPackageTree, newSitefinityVersionPackageTree))
Expand Down
15 changes: 12 additions & 3 deletions Sitefinity CLI/Services/SitefinityNugetPackageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Sitefinity_CLI.PackageManagement.Implementations;
using Sitefinity_CLI.Services.Contracts;
using NuGet.Configuration;
using Sitefinity_CLI.Exceptions;

namespace Sitefinity_CLI.Services
{
Expand All @@ -21,12 +22,16 @@ public SitefinityNugetPackageService(ISitefinityPackageManager sitefinityPackage
this.dotnetCliClient = dotnetCliClient;
this.httpClient = httpClientFactory.CreateClient();
}

public async Task<NuGetPackage> PrepareSitefinityUpgradePackage(UpgradeOptions options, IEnumerable<string> sitefinityProjectFilePaths)
{
IEnumerable<PackageSource> packageSources = this.sitefinityPackageManager.GetNugetPackageSources(options.NugetConfigPath);

NuGetPackage newSitefinityPackage = await this.sitefinityPackageManager.GetSitefinityPackageTree(options.VersionAsString, packageSources);
if (newSitefinityPackage == null)
{
throw new UpgradeException($"Unable to prepare upgrade package for version: {options.Version}");
}

this.sitefinityPackageManager.Restore(options.SolutionPath);
this.sitefinityPackageManager.SetTargetFramework(sitefinityProjectFilePaths, options.VersionAsString);
Expand Down Expand Up @@ -84,7 +89,7 @@ public async Task<string> GetLatestSitefinityVersion()

private async Task<NuGetPackage> GetLatestCompatibleVersion(string packageId, Version sitefinityVersion, IEnumerable<PackageSource> packageSources)
{
IEnumerable<string> versions = this.dotnetCliClient.GetPackageVersionsInNugetSources(packageId, null);
IEnumerable<string> versions = this.dotnetCliClient.GetPackageVersionsInNugetSources(packageId, null);

NuGetPackage compatiblePackage = null;

Expand All @@ -93,7 +98,11 @@ private async Task<NuGetPackage> GetLatestCompatibleVersion(string packageId, Ve
bool isIncompatible = false;
NuGetPackage package = await this.sitefinityPackageManager.GetPackageTree(packageId, version, packageSources, package =>
{
isIncompatible = this.IsSitefinityPackage(package.Id) && new Version(package.Version) > sitefinityVersion;
if (package != null)
{
isIncompatible = this.IsSitefinityPackage(package.Id) && new Version(package.Version) > sitefinityVersion;
}

return isIncompatible;
});

Expand Down
4 changes: 2 additions & 2 deletions Sitefinity CLI/Sitefinity CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<TargetFramework>net8.0</TargetFramework>
<AssemblyName>sf</AssemblyName>
<RootNamespace>Sitefinity_CLI</RootNamespace>
<AssemblyVersion>1.1.0.53</AssemblyVersion>
<AssemblyVersion>1.1.0.54</AssemblyVersion>
<Version>1.1.0</Version>
<FileVersion>1.1.0.53</FileVersion>
<FileVersion>1.1.0.54</FileVersion>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
Expand Down

0 comments on commit 23d6a61

Please sign in to comment.