Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using Microsoft.AspNetCore.StaticWebAssets.Tasks.Utils;
using Microsoft.Build.Framework;
using Microsoft.Extensions.FileSystemGlobbing;

namespace Microsoft.AspNetCore.StaticWebAssets.Tasks;

Expand Down Expand Up @@ -60,12 +59,15 @@ public override bool Execute()
var includePatterns = SplitPattern(IncludePatterns);
var excludePatterns = SplitPattern(ExcludePatterns);

var matcher = new Matcher();
matcher.AddIncludePatterns(includePatterns);
matcher.AddExcludePatterns(excludePatterns);
var matcher = new StaticWebAssetGlobMatcherBuilder()
.AddIncludePatterns(includePatterns)
.AddExcludePatterns(excludePatterns)
.Build();

var matchingCandidateAssets = new List<StaticWebAsset>();

var matchContext = StaticWebAssetGlobMatcher.CreateMatchContext();

// Add each candidate asset to each compression configuration with a matching pattern.
foreach (var asset in candidates)
{
Expand All @@ -80,9 +82,10 @@ public override bool Execute()
}

var relativePath = asset.ComputePathWithoutTokens(asset.RelativePath);
var match = matcher.Match(relativePath);
matchContext.SetPathAndReinitialize(relativePath.AsSpan());
var match = matcher.Match(matchContext);

if (!match.HasMatches)
if (!match.IsMatch)
{
Log.LogMessage(
MessageImportance.Low,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public override bool Execute()
var resultAssets = new List<StaticWebAsset>();
foreach (var (key, group) in existingAssets)
{
if (!ComputeReferenceStaticWebAssetItems.TryGetUniqueAsset(group, out var selected))
if (!TryGetUniqueAsset(group, out var selected))
{
if (selected == null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.Build.Framework;
Expand Down Expand Up @@ -36,7 +36,7 @@ public override bool Execute()
var resultAssets = new List<StaticWebAsset>();
foreach (var (key, group) in currentProjectAssets)
{
if (!ComputeStaticWebAssetsForCurrentProject.TryGetUniqueAsset(group, out var selected))
if (!TryGetUniqueAsset(group, out var selected))
{
if (selected == null)
{
Expand Down
13 changes: 0 additions & 13 deletions src/StaticWebAssetsSdk/Tasks/Data/ContentTypeMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
using System.Diagnostics;
using System.Globalization;
using Microsoft.Build.Framework;
using Microsoft.Extensions.FileSystemGlobbing;

namespace Microsoft.AspNetCore.StaticWebAssets.Tasks;

[DebuggerDisplay($"{{{nameof(GetDebuggerDisplay)}(),nq}}")]
internal struct ContentTypeMapping(string mimeType, string cache, string pattern, int priority)
{
private Matcher _matcher;

public string Pattern { get; set; } = pattern;

public string MimeType { get; set; } = mimeType;
Expand All @@ -27,15 +24,5 @@ internal struct ContentTypeMapping(string mimeType, string cache, string pattern
contentTypeMappings.GetMetadata(nameof(Pattern)),
int.Parse(contentTypeMappings.GetMetadata(nameof(Priority)), CultureInfo.InvariantCulture));

internal bool Matches(string identity)
{
if (_matcher == null)
{
_matcher = new Matcher();
_matcher.AddInclude(Pattern);
}
return _matcher.Match(identity).HasMatches;
}

private readonly string GetDebuggerDisplay() => $"Pattern: {Pattern}, MimeType: {MimeType}, Cache: {Cache}, Priority: {Priority}";
}
865 changes: 463 additions & 402 deletions src/StaticWebAssetsSdk/Tasks/Data/ContentTypeProvider.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/StaticWebAssetsSdk/Tasks/Data/StaticWebAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ internal string EmbedTokens(string relativePath)
var pattern = StaticWebAssetPathPattern.Parse(relativePath, Identity);
var resolver = StaticWebAssetTokenResolver.Instance;
pattern.EmbedTokens(this, resolver);
return pattern.RawPattern;
return pattern.RawPattern.ToString();
}

internal FileInfo ResolveFile() => ResolveFile(Identity, OriginalItemSpec);
Expand Down
Loading