Skip to content

Commit

Permalink
Merge pull request #214 from unoplatform/pj/change-prop-to-be-a-colle…
Browse files Browse the repository at this point in the history
…ction

Change the TaskItem on GenerateAppxManifestFile to be a collection
  • Loading branch information
dansiegel authored Feb 23, 2024
2 parents 2275320 + 26a33cd commit eab563e
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 35 deletions.
9 changes: 7 additions & 2 deletions src/Resizetizer/src/GeneratePackageAppxManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; } = Array.Empty<ITaskItem>();

public string? TargetFramework { get; set; }

Expand Down Expand Up @@ -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);

Expand Down
48 changes: 44 additions & 4 deletions src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -26,12 +27,36 @@ 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 : new[] { appIcon },
ApplicationTitle = displayName,AppIcon = appIcon == null ? null : new[] { appIcon },
SplashScreen = splashScreen == null ? null : new[] { 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 : new[] { appIcon },
SplashScreen = splashScreen == null ? null : new[] { splashScreen },
TargetFramework = "windows"
};
Expand All @@ -45,6 +70,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.");
Expand Down Expand Up @@ -183,5 +209,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: new [] {taskItem, taskItem});

// Act
task.Execute();

// Assert
Assert.True(LogWarningEvents.Count > 0, "Warnings should be greater than zero");
}
}
}
59 changes: 30 additions & 29 deletions src/Resizetizer/test/UnitTests/Resizetizer.UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<AssemblyName>Uno.Resizetizer.UnitTests</AssemblyName>
<IsPackable>false</IsPackable>
<DefineConstants Condition="'$(OS)' == 'Windows_NT'">$(DefineConstants);WINDOWS</DefineConstants>
<Configurations>Debug;Release;DEBUG_RESIZETIZER</Configurations>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<AssemblyName>Uno.Resizetizer.UnitTests</AssemblyName>
<IsPackable>false</IsPackable>
<DefineConstants Condition="'$(OS)' == 'Windows_NT'">$(DefineConstants);WINDOWS</DefineConstants>
<Configurations>Debug;Release;DEBUG_RESIZETIZER</Configurations>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="Microsoft.Build.Framework" Version="17.6.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.6.3" PrivateAssets="all" />
<PackageReference Include="SkiaSharp" Version="2.88.3" />
<PackageReference Include="SkiaSharp.Extended" Version="2.0.0-preview.61" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Svg.Skia" Version="0.5.18" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="Microsoft.Build.Framework" Version="17.6.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.6.3" PrivateAssets="all" />
<PackageReference Include="SkiaSharp" Version="2.88.3" />
<PackageReference Include="SkiaSharp.Extended" Version="2.0.0-preview.61" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Svg.Skia" Version="0.5.18" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Resizetizer.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Resizetizer.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="images\**" CopyToOutputDirectory="PreserveNewest" />
<None Include="testdata\**" CopyToOutputDirectory="PreserveNewest" />
<None Include="imageresults\**" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup>
<None Include="images\**" CopyToOutputDirectory="PreserveNewest" />
<None Include="testdata\**" CopyToOutputDirectory="PreserveNewest" />
<None Include="imageresults\**" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

</Project>

0 comments on commit eab563e

Please sign in to comment.