From 0a26d655c698e7664a0a97d72ef147ab17e79354 Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Wed, 31 Jan 2024 18:42:20 -0300 Subject: [PATCH 1/3] fix: Make it an array --- src/Resizetizer/src/GeneratePackageAppxManifest.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Resizetizer/src/GeneratePackageAppxManifest.cs b/src/Resizetizer/src/GeneratePackageAppxManifest.cs index d0a44571..fea255f9 100644 --- a/src/Resizetizer/src/GeneratePackageAppxManifest.cs +++ b/src/Resizetizer/src/GeneratePackageAppxManifest.cs @@ -24,7 +24,7 @@ public class GeneratePackageAppxManifest_v0 : Task public string IntermediateOutputPath { get; set; } = null!; [Required] - public ITaskItem AppxManifest { get; set; } = null!; + public ITaskItem[] AppxManifest { get; set; } = []; public string? TargetFramework { get; set; } @@ -60,7 +60,12 @@ public override bool Execute() var filename = Path.Combine(IntermediateOutputPath, GeneratedFilename ?? "Package.appxmanifest"); - var appx = XDocument.Load(AppxManifest.ItemSpec); + if (AppxManifest.Length > 1) + { + Log.LogWarning("Multiple AppxManifest files were provided. Only the first one will be used."); + } + + var appx = XDocument.Load(AppxManifest[0].ItemSpec); UpdateManifest(appx); From 10ded15eede002301dc07347a824490531d5a8e5 Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Wed, 31 Jan 2024 18:42:30 -0300 Subject: [PATCH 2/3] test: create a test to validate the change --- .../GeneratePackageAppxManifestTests.cs | 50 ++++++++++++++-- .../UnitTests/Resizetizer.UnitTests.csproj | 59 ++++++++++--------- 2 files changed, 76 insertions(+), 33 deletions(-) diff --git a/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs b/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs index 58966c12..3499f030 100644 --- a/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs +++ b/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs @@ -1,7 +1,8 @@ #nullable enable using Microsoft.Build.Framework; using Microsoft.Build.Utilities; -using System.Collections.Generic; +using System; +using System.Collections; using System.IO; using System.Linq; using System.Xml.Linq; @@ -26,13 +27,39 @@ protected GeneratePackageAppxManifest_v0 GetNewTask( IntermediateOutputPath = DestinationDirectory, BuildEngine = this, GeneratedFilename = generatedFilename, - AppxManifest = new TaskItem(manifest), + AppxManifest = [new TaskItem(manifest)], ApplicationId = guid, ApplicationDisplayVersion = displayVersion, ApplicationVersion = version, ApplicationTitle = displayName, - AppIcon = appIcon == null ? null : new[] { appIcon }, - SplashScreen = splashScreen == null ? null : new[] { splashScreen }, + AppIcon = appIcon == null ? null : [appIcon], + SplashScreen = splashScreen == null ? null : [splashScreen], + TargetFramework = "windows" + }; + } + + protected GeneratePackageAppxManifest_v0 GetNewTask( + ITaskItem[] appxManifests, + string? generatedFilename = null, + string? guid = null, + string? displayVersion = null, + string? version = null, + string? displayName = null, + ITaskItem? appIcon = null, + ITaskItem? splashScreen = null) + { + return new() + { + IntermediateOutputPath = DestinationDirectory, + BuildEngine = this, + GeneratedFilename = generatedFilename, + AppxManifest = appxManifests, + ApplicationId = guid, + ApplicationDisplayVersion = displayVersion, + ApplicationVersion = version, + ApplicationTitle = displayName, + AppIcon = appIcon == null ? null : [appIcon], + SplashScreen = splashScreen == null ? null : [splashScreen], TargetFramework = "windows" }; } @@ -45,6 +72,7 @@ public void FileIsGenerated(string? specificFn, string outputFn) var task = GetNewTask($"testdata/appxmanifest/typical.appxmanifest", generatedFilename: specificFn); var success = task.Execute(); + Assert.True(success, $"{task.GetType()}.Execute() failed: " + LogErrorEvents.FirstOrDefault()?.Message); Assert.True(File.Exists(Path.Combine(DestinationDirectory, outputFn)), "Package.appxmanifest file was not generated."); @@ -183,5 +211,19 @@ public void InvalidMergeVersionNumbers(string displayVersion, string appVersion) var result = GeneratePackageAppxManifest_v0.TryMergeVersionNumbers(displayVersion, appVersion, out var merged); Assert.False(result); } + + [Fact] + public void TaskShouldFileAWarningIfMoreThanOneManifestIsProvided() + { + // Arrange + var taskItem = new TaskItem("testdata/appxmanifest/typical.appxmanifest"); + var task = GetNewTask(appxManifests: [taskItem, taskItem]); + + // Act + task.Execute(); + + // Assert + Assert.True(LogWarningEvents.Count > 0, "Warnings should be greater than zero"); + } } } diff --git a/src/Resizetizer/test/UnitTests/Resizetizer.UnitTests.csproj b/src/Resizetizer/test/UnitTests/Resizetizer.UnitTests.csproj index 44545ef8..17fee812 100644 --- a/src/Resizetizer/test/UnitTests/Resizetizer.UnitTests.csproj +++ b/src/Resizetizer/test/UnitTests/Resizetizer.UnitTests.csproj @@ -1,36 +1,37 @@  - - net7.0 - Uno.Resizetizer.UnitTests - false - $(DefineConstants);WINDOWS - Debug;Release;DEBUG_RESIZETIZER - + + net7.0 + Uno.Resizetizer.UnitTests + false + $(DefineConstants);WINDOWS + Debug;Release;DEBUG_RESIZETIZER + latest + - - - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + - - - + + + - - - - - + + + + + From 26a33cd8a1ab87e99febf87bd6318545ae55ac92 Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Thu, 1 Feb 2024 22:10:49 -0300 Subject: [PATCH 3/3] chore: use the old API to make CI happy --- src/Resizetizer/src/GeneratePackageAppxManifest.cs | 2 +- .../UnitTests/GeneratePackageAppxManifestTests.cs | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Resizetizer/src/GeneratePackageAppxManifest.cs b/src/Resizetizer/src/GeneratePackageAppxManifest.cs index fea255f9..7437eeec 100644 --- a/src/Resizetizer/src/GeneratePackageAppxManifest.cs +++ b/src/Resizetizer/src/GeneratePackageAppxManifest.cs @@ -24,7 +24,7 @@ public class GeneratePackageAppxManifest_v0 : Task public string IntermediateOutputPath { get; set; } = null!; [Required] - public ITaskItem[] AppxManifest { get; set; } = []; + public ITaskItem[] AppxManifest { get; set; } = Array.Empty(); public string? TargetFramework { get; set; } diff --git a/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs b/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs index 3499f030..83b74a2e 100644 --- a/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs +++ b/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs @@ -27,13 +27,12 @@ protected GeneratePackageAppxManifest_v0 GetNewTask( IntermediateOutputPath = DestinationDirectory, BuildEngine = this, GeneratedFilename = generatedFilename, - AppxManifest = [new TaskItem(manifest)], + AppxManifest = new []{new TaskItem(manifest)}, ApplicationId = guid, ApplicationDisplayVersion = displayVersion, ApplicationVersion = version, - ApplicationTitle = displayName, - AppIcon = appIcon == null ? null : [appIcon], - SplashScreen = splashScreen == null ? null : [splashScreen], + ApplicationTitle = displayName,AppIcon = appIcon == null ? null : new[] { appIcon }, + SplashScreen = splashScreen == null ? null : new[] { splashScreen }, TargetFramework = "windows" }; } @@ -57,9 +56,8 @@ protected GeneratePackageAppxManifest_v0 GetNewTask( ApplicationId = guid, ApplicationDisplayVersion = displayVersion, ApplicationVersion = version, - ApplicationTitle = displayName, - AppIcon = appIcon == null ? null : [appIcon], - SplashScreen = splashScreen == null ? null : [splashScreen], + ApplicationTitle = displayName,AppIcon = appIcon == null ? null : new[] { appIcon }, + SplashScreen = splashScreen == null ? null : new[] { splashScreen }, TargetFramework = "windows" }; } @@ -217,7 +215,7 @@ public void TaskShouldFileAWarningIfMoreThanOneManifestIsProvided() { // Arrange var taskItem = new TaskItem("testdata/appxmanifest/typical.appxmanifest"); - var task = GetNewTask(appxManifests: [taskItem, taskItem]); + var task = GetNewTask(appxManifests: new [] {taskItem, taskItem}); // Act task.Execute();