Skip to content
This repository was archived by the owner on Sep 4, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 2 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
23 changes: 21 additions & 2 deletions Mono.Addins/Mono.Addins.Description/AddinDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
using Mono.Addins.Serialization;
using Mono.Addins.Database;
using System.Text;
using Microsoft.Extensions.FileSystemGlobbing;
using Microsoft.Extensions.FileSystemGlobbing.Abstractions;

namespace Mono.Addins.Description
{
Expand Down Expand Up @@ -381,11 +383,11 @@ public StringCollection AllFiles {
get {
StringCollection col = new StringCollection ();
foreach (string s in MainModule.AllFiles)
col.Add (s);
AddFileToCollection (col, s);

foreach (ModuleDescription mod in OptionalModules) {
foreach (string s in mod.AllFiles)
col.Add (s);
AddFileToCollection (col, s);
}
return col;
}
Expand Down Expand Up @@ -922,6 +924,7 @@ public static AddinDescription Read (string configFile)
config = Read (s, Path.GetDirectoryName (configFile));
}
config.configFile = configFile;
config.SetBasePath (Path.GetDirectoryName (configFile));
return config;
}

Expand Down Expand Up @@ -951,6 +954,7 @@ public static AddinDescription Read (Stream stream, string basePath)
public static AddinDescription Read (TextReader reader, string basePath)
{
AddinDescription config = new AddinDescription ();
config.SetBasePath (basePath);

try {
config.configDoc = new XmlDocument ();
Expand Down Expand Up @@ -1072,6 +1076,21 @@ static bool GetBool (string s, bool defval)
else
return s == "true" || s == "yes";
}

void AddFileToCollection (StringCollection collection, string file)
{
bool isSimpleFile = file.IndexOf ('*') == -1;
if (isSimpleFile) {
collection.Add (file);
return;
}

var matcher = new Matcher (StringComparison.OrdinalIgnoreCase);
matcher.AddInclude (file);
var files = matcher.Execute (new DirectoryInfoWrapper (new DirectoryInfo (BasePath))).Files;
foreach (var globbedFile in files)
collection.Add (globbedFile.Path);
}

internal static AddinDescription ReadBinary (FileDatabase fdb, string configFile)
{
Expand Down
3 changes: 3 additions & 0 deletions Mono.Addins/Mono.Addins.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<PackageReference Include="NuGet.Build.Packaging" Version="0.1.276" />
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I to keep Mono.Addins.dll standalone, without other NuGet dependencies. Either copy the globbing code here or use a custom one.

<Version>1.1.1</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
Expand Down
20 changes: 20 additions & 0 deletions Test/ImportGlobFileExtension/ImportGlobFileExtension.addin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Addin id = "ImportGlobFileExtension"
namespace = "SimpleApp"
name = "ImportGlobFileExtension"
author = "Jeremie Laval"
copyright = "GPL"
description = "ImportGlobFileExtension"
category = "SimpleApp/Extensions"
version = "0.1.0">

<Runtime>
<Import file="file1.txt" />
<Import file="dir1/*.bin" />
<Import file="dir2/**" />
</Runtime>

<Dependencies>
<Addin id="Core" version="0.1.0" />
</Dependencies>

</Addin>
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
19 changes: 19 additions & 0 deletions Test/UnitTests/TestAddinDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,25 @@ public void WriteCorePropertiesAsProps ()
XmlDocument doc2 = desc.SaveToXml ();
Assert.AreEqual (Util.Infoset (doc1), Util.Infoset (doc2));
}

[Test]
public void FileGlobbingTest ()
{
string pathToTestFolder = Path.Combine ("..", "..", "..", "ImportGlobFileExtension");
AddinDescription desc = AddinDescription.Read (Path.Combine (pathToTestFolder, "ImportGlobFileExtension.addin.xml"));

var allFiles = desc.AllFiles;
Assert.IsNotNull (allFiles);
CollectionAssert.IsNotEmpty (allFiles);
Assert.AreEqual (5, allFiles.Count);
CollectionAssert.AreEquivalent (new string [] {
"file1.txt",
Path.Combine ("dir1", "bar.bin"),
Path.Combine ("dir1", "foo.bin"),
Path.Combine ("dir2", "subdir", "subfile.txt"),
Path.Combine ("dir2", "subdir", "subsubdir", "subsubfile.txt")
}, allFiles);
}
}
}