Skip to content

Commit

Permalink
fix(NugetServer): .library files where not supported correctly
Browse files Browse the repository at this point in the history
(cherry picked from commit e9a243d)
  • Loading branch information
iadonkey committed Aug 6, 2024
1 parent 783adbe commit 0e56275
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
5 changes: 5 additions & 0 deletions TwinpackShared/Protocol/Nuget/BeckhoffServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,10 @@ public override async Task<PackageVersionGetResponse> ResolvePackageVersionAsync
library.Name = "TwinCAT.XAE.PLC.Lib." + library.Name;
return await base.ResolvePackageVersionAsync(library, preferredTarget, preferredConfiguration, preferredBranch, cancellationToken);
}

protected override int EvaluateCompiled(string tags)
{
return 1;
}
}
}
29 changes: 20 additions & 9 deletions TwinpackShared/Protocol/Nuget/NugetServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using WixToolset.Dtf.WindowsInstaller.Package;
using NuGet.Packaging.Core;
using System.Data;
using EnvDTE;

namespace Twinpack.Protocol
{
Expand Down Expand Up @@ -180,7 +181,7 @@ public async Task<Tuple<IEnumerable<PackageVersionGetResponse>, bool>> GetPackag
Branch = "main",
Target = "TC3.1",
Configuration = "Release",
Compiled = 1,
Compiled = EvaluateCompiled(x.Tags),
//Notes =,
//PackageType,
Binary = null,
Expand Down Expand Up @@ -232,8 +233,8 @@ await resource.CopyNupkgToStreamAsync(

var msis = packageFiles.Where(x => x.EndsWith(".msi", StringComparison.InvariantCultureIgnoreCase));
var libraries = packageFiles.Where(x =>
x.EndsWith(".library", StringComparison.InvariantCultureIgnoreCase) ||
Path.GetExtension(x).StartsWith(".compiled-library"));
(packageVersion.Compiled == 0 && x.EndsWith(".library", StringComparison.InvariantCultureIgnoreCase)) ||
(packageVersion.Compiled == 1 && Path.GetExtension(x).StartsWith(".compiled-library")));

if(libraries.Count() == 1)
{
Expand All @@ -243,7 +244,7 @@ await resource.CopyNupkgToStreamAsync(
{
try
{
var extension = library.EndsWith(".library") ? "compiled-library" : "library";
var extension = packageVersion.Compiled == 1 ? "compiled-library" : "library";
var filePath = $@"{cachePath ?? DefaultLibraryCachePath}\{packageVersion.Target}";
var fileName = $@"{filePath}\{packageVersion.Name}_{packageVersion.Version}.{extension}";
Directory.CreateDirectory(filePath);
Expand Down Expand Up @@ -279,14 +280,18 @@ await resource.CopyNupkgToStreamAsync(
pkg.ExtractFiles();
}

var files = Directory.GetFiles(tempFolderPath, "*", SearchOption.AllDirectories).Where(x => Path.GetExtension(x) == ".library" || Path.GetExtension(x).StartsWith(".compiled-library"));
var files = Directory.GetFiles(tempFolderPath, "*", SearchOption.AllDirectories)
.Where(x =>
(packageVersion.Compiled == 0 && Path.GetExtension(x) == ".library") ||
(packageVersion.Compiled == 1 && Path.GetExtension(x).StartsWith(".compiled-library")));

if(files.Count() != 1)
{
throw new Exceptions.GetException("nupkg contains a msi file that contains more than one library!");
}
foreach (var f in files)
{
var extension = Path.GetExtension(f).StartsWith(".compiled-library") ? "compiled-library" : "library";
var extension = packageVersion.Compiled == 1 ? "compiled-library" : "library";
var filePath = $@"{cachePath ?? DefaultLibraryCachePath}\{packageVersion.Target}";
var fileName = $@"{filePath}\{packageVersion.Name}_{packageVersion.Version}.{extension}";
Directory.CreateDirectory(filePath);
Expand All @@ -302,7 +307,7 @@ await resource.CopyNupkgToStreamAsync(
}
else
{
throw new Exceptions.GetException("nupkg should contain a single msi or library file!");
throw new Exceptions.GetException($"nupkg should contain a single .msi or {(packageVersion.Compiled == 1 ? ".compiled-library" : ".library")} file!");
}
}
}
Expand Down Expand Up @@ -374,7 +379,7 @@ public virtual async Task<PackageVersionGetResponse> GetPackageVersionAsync(PlcL
Branch = "main",
Target = "TC3.1",
Configuration = "Release",
Compiled = 1,
Compiled = EvaluateCompiled(dependency.Tags),
Notes = dependency.Description,
//PackageType,
Binary = null,
Expand Down Expand Up @@ -408,7 +413,7 @@ public virtual async Task<PackageVersionGetResponse> GetPackageVersionAsync(PlcL
Branch = "main",
Target = "TC3.1",
Configuration = "Release",
Compiled = 1,
Compiled = EvaluateCompiled(x.Tags),
Notes = x.Description,
//PackageType,
Binary = null,
Expand Down Expand Up @@ -561,5 +566,11 @@ private string EvaluateTitle(IPackageSearchMetadata x)

return title;
}

protected virtual int EvaluateCompiled(string tags)
{
var tagList = tags.Split(' ').ToList();
return tagList.IndexOf("tp-compiled-library") >= 0 ? 1 : 0;
}
}
}

0 comments on commit 0e56275

Please sign in to comment.