Skip to content

Commit

Permalink
fix: nullpointer in set-version when package not available on any ser…
Browse files Browse the repository at this point in the history
…ver is used (only locally installed)
  • Loading branch information
zeugwerker committed Aug 20, 2024
1 parent a10c531 commit 8fb4155
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 35 deletions.
15 changes: 9 additions & 6 deletions TwinpackCore/Core/TwinpackService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -647,8 +647,8 @@ public async System.Threading.Tasks.Task SetPackageVersionAsync(string version,
_logger.Info("Synchronizing framework packages");

var nonFrameworkPackages = affectedPackages.Where(x => !frameworks.Contains(x.PackageVersion?.Framework)).ToList();
var configuredPackages = plcs
.SelectMany(
var configuredPackages = options?.PurgePackages == true
? plcs.SelectMany(
x => x.Packages.Select(y => new PackageItem
{
ProjectName = x.ProjectName,
Expand All @@ -659,18 +659,21 @@ public async System.Threading.Tasks.Task SetPackageVersionAsync(string version,
.Select(
x => new PackageItem(x)
{
Package = nonFrameworkPackages.FirstOrDefault(y => y.ProjectName == x.ProjectName && y.PlcName == x.PlcName && y.Config.Name == y.Config.Name)?.Package,
PackageVersion = new PackageVersionGetResponse(nonFrameworkPackages.FirstOrDefault(z => z.ProjectName == x.ProjectName && z.PlcName == x.PlcName && z.Config.Name == x.Config.Name)?.PackageVersion)
Package = new PackageGetResponse(nonFrameworkPackages.FirstOrDefault(y => y.ProjectName == x.ProjectName && y.PlcName == x.PlcName && x.Config.Name == y.Config.Name)?.Package),
PackageVersion = new PackageVersionGetResponse(nonFrameworkPackages.FirstOrDefault(y => y.ProjectName == x.ProjectName && y.PlcName == x.PlcName && x.Config.Name == y.Config.Name)?.PackageVersion)
{
Title = x.PackageVersion?.Title ?? x.Config.Name,
Name = x.Config.Name,
DistributorName = x.Config.DistributorName,
Version = x.Config.Version,
Branch = x.Config.Branch,
Target = x.Config.Target,
Configuration = x.Config.Configuration
Configuration = x.Config.Configuration,
}
}
)
.ToList();
.ToList()
: new List<PackageItem>();

var frameworkPackagesToAdd = new List<PackageItem>();
foreach (var project in _config.Projects)
Expand Down
58 changes: 29 additions & 29 deletions TwinpackCore/Protocol/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,23 @@ public PackageGetResponse() { }

public PackageGetResponse(PackageGetResponse package)
{
PackageId = package.PackageId;
Name = package.Name;
Title = package.Title;
Repository = package.Repository;
DistributorName = package.DistributorName;
DisplayName = package.DisplayName;
Description = package.Description;
Entitlement = package.Entitlement;
ProjectUrl = package.ProjectUrl;
IconUrl = package.IconUrl;
Authors = package.Authors;
License = package.License;
LicenseTmcBinary = package.LicenseTmcBinary;
LicenseBinary = package.LicenseBinary;
Branches = package.Branches?.Any() == true ? new List<string>(package.Branches) : new List<string>();
Targets = package.Branches?.Any() == true ? new List<string>(package.Targets) : new List<string>();
Configurations = package.Branches?.Any() == true ? new List<string>(package.Configurations) : new List<string>();
PackageId = package?.PackageId;
Name = package?.Name;
Title = package?.Title;
Repository = package?.Repository;
DistributorName = package?.DistributorName;
DisplayName = package?.DisplayName;
Description = package?.Description;
Entitlement = package?.Entitlement;
ProjectUrl = package?.ProjectUrl;
IconUrl = package?.IconUrl;
Authors = package?.Authors;
License = package?.License;
LicenseTmcBinary = package?.LicenseTmcBinary;
LicenseBinary = package?.LicenseBinary;
Branches = package?.Branches?.Any() == true ? new List<string>(package.Branches) : new List<string>();
Targets = package?.Branches?.Any() == true ? new List<string>(package.Targets) : new List<string>();
Configurations = package?.Branches?.Any() == true ? new List<string>(package.Configurations) : new List<string>();
}

[JsonPropertyName("package-id")]
Expand Down Expand Up @@ -182,18 +182,18 @@ public PackageVersionGetResponse(PackageGetResponse package) : base(package)

public PackageVersionGetResponse(PackageVersionGetResponse packageVersion) : base(packageVersion)
{
PackageVersionId = packageVersion.PackageVersionId;
Version = packageVersion.Version;
Branch = packageVersion.Branch;
Target = packageVersion.Target;
Configuration = packageVersion.Configuration;
Compiled = packageVersion.Compiled;
Notes = packageVersion.Notes;
PackageType = packageVersion.PackageType;
Binary = packageVersion.Binary;
BinaryDownloadUrl = packageVersion.BinaryDownloadUrl;
BinarySha256 = packageVersion.BinarySha256;
Dependencies = new List<PackageVersionGetResponse>(packageVersion.Dependencies);
PackageVersionId = packageVersion?.PackageVersionId;
Version = packageVersion?.Version;
Branch = packageVersion?.Branch;
Target = packageVersion?.Target;
Configuration = packageVersion?.Configuration;
Compiled = packageVersion?.Compiled ?? 0;
Notes = packageVersion?.Notes;
PackageType = packageVersion?.PackageType;
Binary = packageVersion?.Binary;
BinaryDownloadUrl = packageVersion?.BinaryDownloadUrl;
BinarySha256 = packageVersion?.BinarySha256;
Dependencies = packageVersion?.Dependencies == null ? new List<PackageVersionGetResponse>() : new List<PackageVersionGetResponse>(packageVersion?.Dependencies);
}

[JsonPropertyName("package-version-id")]
Expand Down

0 comments on commit 8fb4155

Please sign in to comment.