Skip to content

Commit

Permalink
Merge pull request #297 from unoplatform/dev/ds/use-root-xmlns
Browse files Browse the repository at this point in the history
Use root xmlns
  • Loading branch information
dansiegel authored Jun 19, 2024
2 parents f66b9b8 + 91cdad5 commit c76d92b
Show file tree
Hide file tree
Showing 19 changed files with 674 additions and 178 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
- name: Build - CI
run: |
$adjustedPackageVersion="${{ steps.gitversion.outputs.semVer }}".ToLower();
dotnet pack -c Release -p:PackageVersion=$adjustedPackageVersion -p:Version=${{ steps.gitversion.outputs.assemblySemVer }} -o .\artifacts src/Resizetizer/src/Resizetizer.csproj
dotnet pack -c Release -p:PackageVersion=$adjustedPackageVersion -p:Version=${{ steps.gitversion.outputs.assemblySemVer }} -o .\artifacts src/Resizetizer/src/Resizetizer.csproj
- name: Upload Artifacts
uses: actions/upload-artifact@v4
Expand All @@ -72,7 +72,7 @@ jobs:

- name: Run UnitTests
run: |
dotnet test src/Resizetizer/test/UnitTests/Resizetizer.UnitTests.csproj
dotnet test src/Resizetizer/test/UnitTests/Resizetizer.UnitTests.csproj -c Release -p:PackageVersion=$adjustedPackageVersion -p:Version=${{ steps.gitversion.outputs.assemblySemVer }} --logger GitHubActions --blame-crash --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
validation_5_2:
name: Validate 5.2 Samples
Expand Down
2 changes: 1 addition & 1 deletion src/.nuspec/Uno.Resizetizer.windows.skia.targets
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</Target>

<Target
Name="GenerateUnoSplashWindowsSkia"
Name="GenerateUnoSplashWindowsSkia"
BeforeTargets="ProcessUnoSplashScreens"
Condition="'$(DesignTimeBuild)' != 'True' And '@(UnoSplashScreen)' != ''"
Outputs="$(_UnoSplashStampFile)">
Expand Down
55 changes: 35 additions & 20 deletions src/Resizetizer/src/GeneratePackageAppxManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Linq;

namespace Uno.Resizetizer
Expand All @@ -15,9 +16,9 @@ public class GeneratePackageAppxManifest_v0 : Task
const string PackageVersionPlaceholder = "0.0.0.0";
const string ImageExtension = ".png";

const string ErrorVersionNumberCombination = "ApplicationDisplayVersion '{0}' was not a valid 3 part semver version number and/or ApplicationVersion '{1}' was not a valid integer.";
const string UapNamespace = "http://schemas.microsoft.com/appx/manifest/uap/windows10";

static readonly XNamespace xmlnsUap = "http://schemas.microsoft.com/appx/manifest/uap/windows10";
const string ErrorVersionNumberCombination = "ApplicationDisplayVersion '{0}' was not a valid 3 part semver version number and/or ApplicationVersion '{1}' was not a valid integer.";

[Required]
public string IntermediateOutputPath { get; set; } = null!;
Expand Down Expand Up @@ -91,7 +92,17 @@ public override bool Execute()
UpdateManifest(appx);
appx.Save(writer);
// Define the settings for the XmlWriter
var settings = new XmlWriterSettings
{
Indent = true,
Encoding = writer.Encoding,
NamespaceHandling = NamespaceHandling.OmitDuplicates,
OmitXmlDeclaration = false // Ensure the XML declaration is included
};
using var xmlWriter = XmlWriter.Create(writer, settings);
appx.Save(xmlWriter);
});

GeneratedAppxManifest = new TaskItem(filename);
Expand All @@ -109,6 +120,10 @@ void UpdateManifest(XDocument appx)
var appIconInfo = AppIcon?.Length > 0 ? ResizeImageInfo.Parse(AppIcon[0]) : null;
var splashInfo = SplashScreen?.Length > 0 ? ResizeImageInfo.Parse(SplashScreen[0]) : null;

var xmlnsUap = appx.Root.Attributes()
.Where(a => a.IsNamespaceDeclaration && a.Value == UapNamespace)
.Select(a => XNamespace.Get(a.Value))
.FirstOrDefault();
var xmlns = appx.Root!.GetDefaultNamespace();

// <Identity Name="" Version="" />
Expand Down Expand Up @@ -498,19 +513,19 @@ private static void SetDependencyTargetDeviceFamily(XDocument appx, string targe
if (targetDeviceFamilyElements is null || !targetDeviceFamilyElements.Any())
{
var universal = new XElement(xmlns + "TargetDeviceFamily");
universal.SetAttributeValue(xmlns + "Name", "Windows.Universal");
universal.SetAttributeValue("Name", "Windows.Universal");

var desktop = new XElement(xmlns + "TargetDeviceFamily");
desktop.SetAttributeValue(xmlns + "Name", "Windows.Desktop");
desktop.SetAttributeValue("Name", "Windows.Desktop");

dependencies.Add(universal, desktop);
targetDeviceFamilyElements = [universal, desktop];
}

foreach (var target in targetDeviceFamilyElements)
{
SetVersion(target, xmlns + "MinVersion", targetPlatformMinVersion);
SetVersion(target, xmlns + "MaxVersionTested", targetPlatformVersion);
SetVersion(target, "MinVersion", targetPlatformMinVersion);
SetVersion(target, "MaxVersionTested", targetPlatformVersion);
}
}

Expand All @@ -523,19 +538,19 @@ private static void SetVersion(XElement target, XName attributeName, string vers
}
}

static bool IsVersionAttribute(XAttribute attribute, XName attributeName)
{
var currentAttributeName = attribute.Name.LocalName;
var expectedAttributeName = attributeName.LocalName;

var currentAttributeNamespace = attribute.Name.Namespace.NamespaceName;
var expectedAttributeNamespace = attributeName.NamespaceName;

// The Version may not have a current Namespace and should use the default namespace
if (string.IsNullOrEmpty(currentAttributeNamespace))
return currentAttributeName == expectedAttributeName;

return currentAttributeName == expectedAttributeName && currentAttributeNamespace == expectedAttributeNamespace;
static bool IsVersionAttribute(XAttribute attribute, XName attributeName)
{
var currentAttributeName = attribute.Name.LocalName;
var expectedAttributeName = attributeName.LocalName;

var currentAttributeNamespace = attribute.Name.Namespace.NamespaceName;
var expectedAttributeNamespace = attributeName.NamespaceName;

// The Version may not have a current Namespace and should use the default namespace
if (string.IsNullOrEmpty(currentAttributeNamespace))
return currentAttributeName == expectedAttributeName;

return currentAttributeName == expectedAttributeName && currentAttributeNamespace == expectedAttributeNamespace;
}

public static bool TryMergeVersionNumbers(string? displayVersion, string? version, out string? finalVersion)
Expand Down
Loading

0 comments on commit c76d92b

Please sign in to comment.