Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Add support for file-glob for file-based Import #79

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions Mono.Addins.Setup/Mono.Addins.Setup/SetupService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,8 @@ string BuildPackageInternal (IProgressStatus monitor, string targetDirectory, st
if (targetDirectory == null)
targetDirectory = basePath;

conf.SetBasePath (basePath);

// Generate the file name

string name;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using Microsoft.Extensions.Internal;

namespace Microsoft.Extensions.FileSystemGlobbing
{
/// <summary>
/// Represents a file that was matched by searching using a globbing pattern
/// </summary>
struct FilePatternMatch : IEquatable<FilePatternMatch>
{
/// <summary>
/// The path to the file matched
/// </summary>
/// <remarks>
/// If the matcher searched for "**/*.cs" using "src/Project" as the directory base and the pattern matcher found
/// "src/Project/Interfaces/IFile.cs", then Stem = "Interfaces/IFile.cs" and Path = "src/Project/Interfaces/IFile.cs".
/// </remarks>
public string Path { get; }

/// <summary>
/// The subpath to the matched file under the base directory searched
/// </summary>
/// <remarks>
/// If the matcher searched for "**/*.cs" using "src/Project" as the directory base and the pattern matcher found
/// "src/Project/Interfaces/IFile.cs",
/// then Stem = "Interfaces/IFile.cs" and Path = "src/Project/Interfaces/IFile.cs".
/// </remarks>
public string Stem { get; }

/// <summary>
/// Initializes new instance of <see cref="FilePatternMatch" />
/// </summary>
/// <param name="path">The path to the matched file</param>
/// <param name="stem">The stem</param>
public FilePatternMatch(string path, string stem)
{
Path = path;
Stem = stem;
}

/// <summary>
/// Determines if the specified match is equivalent to the current match using a case-insensitive comparison.
/// </summary>
/// <param name="other">The other match to be compared</param>
/// <returns>True if <see cref="Path" /> and <see cref="Stem" /> are equal using case-insensitive comparison</returns>
public bool Equals(FilePatternMatch other)
{
return string.Equals(other.Path, Path, StringComparison.OrdinalIgnoreCase) &&
string.Equals(other.Stem, Stem, StringComparison.OrdinalIgnoreCase);
}

/// <summary>
/// Determines if the specified object is equivalent to the current match using a case-insensitive comparison.
/// </summary>
/// <param name="obj">The object to be compared</param>
/// <returns>True when <see cref="Equals(FilePatternMatch)" /></returns>
public override bool Equals(object obj)
{
return Equals((FilePatternMatch) obj);
}

/// <summary>
/// Gets a hash for the file pattern match.
/// </summary>
/// <returns>Some number</returns>
public override int GetHashCode()
{
var hashCodeCombiner = HashCodeCombiner.Start();
hashCodeCombiner.Add(Path, StringComparer.OrdinalIgnoreCase);
hashCodeCombiner.Add(Stem, StringComparer.OrdinalIgnoreCase);

return hashCodeCombiner;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;

namespace Microsoft.Extensions.Internal
{
struct HashCodeCombiner
{
private long _combinedHash64;

public int CombinedHash
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get { return _combinedHash64.GetHashCode(); }
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private HashCodeCombiner(long seed)
{
_combinedHash64 = seed;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Add(IEnumerable e)
{
if (e == null)
{
Add(0);
}
else
{
var count = 0;
foreach (object o in e)
{
Add(o);
count++;
}
Add(count);
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator int(HashCodeCombiner self)
{
return self.CombinedHash;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Add(int i)
{
_combinedHash64 = ((_combinedHash64 << 5) + _combinedHash64) ^ i;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Add(string s)
{
var hashCode = (s != null) ? s.GetHashCode() : 0;
Add(hashCode);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Add(object o)
{
var hashCode = (o != null) ? o.GetHashCode() : 0;
Add(hashCode);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Add<TValue>(TValue value, IEqualityComparer<TValue> comparer)
{
var hashCode = value != null ? comparer.GetHashCode(value) : 0;
Add(hashCode);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static HashCodeCombiner Start()
{
return new HashCodeCombiner(0x1505L);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Generic;

namespace Microsoft.Extensions.FileSystemGlobbing.Internal
{
interface ILinearPattern : IPattern
{
IList<IPathSegment> Segments { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

namespace Microsoft.Extensions.FileSystemGlobbing.Internal
{
interface IPathSegment
{
bool CanProduceStem { get; }

bool Match(string value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

namespace Microsoft.Extensions.FileSystemGlobbing.Internal
{
interface IPattern
{
IPatternContext CreatePatternContextForInclude();

IPatternContext CreatePatternContextForExclude();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.IO;
using Microsoft.Extensions.FileSystemGlobbing;

namespace Microsoft.Extensions.FileSystemGlobbing.Internal
{
interface IPatternContext
{
void Declare(Action<IPathSegment, bool> onDeclare);

bool Test(DirectoryInfo directory);

PatternTestResult Test(FileInfo file);

void PushDirectory(DirectoryInfo directory);

void PopDirectory();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Generic;

namespace Microsoft.Extensions.FileSystemGlobbing.Internal
{
interface IRaggedPattern : IPattern
{
IList<IPathSegment> Segments { get; }

IList<IPathSegment> StartsWith { get; }

IList<IList<IPathSegment>> Contains { get; }

IList<IPathSegment> EndsWith { get; }
}
}
Loading