forked from cake-contrib/Cake.Paket
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Updated docs, license, and copyright.
- Moved CakeModule assembly reference to assembly info. - Changed target framework to 4.5 - Massive overhaul of how the Module works. - Updated scripts
- Loading branch information
Showing
24 changed files
with
720 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
group Cake.Paket | ||
group cake.paket | ||
Cake.Core | ||
StyleCop.Analyzers | ||
StyleCop.Analyzers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Collections.Generic; | ||
using Cake.Core.IO; | ||
using Cake.Core.Packaging; | ||
|
||
namespace Cake.Paket.Module | ||
{ | ||
/// <summary> | ||
/// Represents a file locator for NuGet packages that returns relevant | ||
/// files for the current framework given the resource type. | ||
/// </summary> | ||
public interface INuGetContentResolver | ||
{ | ||
/// <summary> | ||
/// Gets the relevant files for a NuGet package | ||
/// given a path and a resource type. | ||
/// </summary> | ||
/// <param name="path">The path to search.</param> | ||
/// <param name="package">The package.</param> | ||
/// <param name="type">The resource type.</param> | ||
/// <returns>A collection of files.</returns> | ||
IReadOnlyCollection<IFile> GetFiles(DirectoryPath path, PackageReference package, PackageType type); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Cake.Core; | ||
using Cake.Core.IO; | ||
using Cake.Core.Packaging; | ||
|
||
namespace Cake.Paket.Module | ||
{ | ||
internal abstract class NuGetContentResolver : INuGetContentResolver | ||
{ | ||
private readonly IFileSystem _fileSystem; | ||
private readonly ICakeEnvironment _environment; | ||
private readonly IGlobber _globber; | ||
|
||
protected NuGetContentResolver( | ||
IFileSystem fileSystem, | ||
ICakeEnvironment environment, | ||
IGlobber globber) | ||
{ | ||
_fileSystem = fileSystem; | ||
_environment = environment; | ||
_globber = globber; | ||
} | ||
|
||
public IReadOnlyCollection<IFile> GetFiles(DirectoryPath path, PackageReference package, PackageType type) | ||
{ | ||
if (path == null) | ||
{ | ||
throw new ArgumentNullException(nameof(path)); | ||
} | ||
|
||
if (type == PackageType.Addin) | ||
{ | ||
return GetAddinAssemblies(path); | ||
} | ||
if (type == PackageType.Tool) | ||
{ | ||
return GetToolFiles(path, package); | ||
} | ||
|
||
throw new InvalidOperationException("Unknown resource type."); | ||
} | ||
|
||
protected abstract IReadOnlyCollection<IFile> GetAddinAssemblies(DirectoryPath path); | ||
|
||
private IReadOnlyCollection<IFile> GetToolFiles(DirectoryPath path, PackageReference package) | ||
{ | ||
var result = new List<IFile>(); | ||
var toolDirectory = _fileSystem.GetDirectory(path); | ||
if (toolDirectory.Exists) | ||
{ | ||
result.AddRange(GetFiles(path, package)); | ||
} | ||
return result; | ||
} | ||
|
||
private IEnumerable<IFile> GetFiles(DirectoryPath path, PackageReference package) | ||
{ | ||
var collection = new FilePathCollection(new PathComparer(_environment)); | ||
|
||
// Get default files (exe and dll). | ||
var patterns = new[] { path.FullPath + "/**/*.exe", path.FullPath + "/**/*.dll" }; | ||
foreach (var pattern in patterns) | ||
{ | ||
collection.Add(_globber.GetFiles(pattern)); | ||
} | ||
|
||
// Include files. | ||
if (package.Parameters.ContainsKey("include")) | ||
{ | ||
foreach (var include in package.Parameters["include"]) | ||
{ | ||
var includePath = string.Concat(path.FullPath, "/", include.TrimStart('/')); | ||
collection.Add(_globber.GetFiles(includePath)); | ||
} | ||
} | ||
|
||
// Exclude files. | ||
if (package.Parameters.ContainsKey("exclude")) | ||
{ | ||
foreach (var exclude in package.Parameters["exclude"]) | ||
{ | ||
var excludePath = string.Concat(path.FullPath, "/", exclude.TrimStart('/')); | ||
collection.Remove(_globber.GetFiles(excludePath)); | ||
} | ||
} | ||
|
||
// Return the files. | ||
return collection.Select(p => _fileSystem.GetFile(p)).ToArray(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,36 @@ | ||
using Cake.Core.Annotations; | ||
using System; | ||
using Cake.Core.Composition; | ||
using Cake.Core.Scripting; | ||
|
||
[assembly: CakeModule(typeof(Cake.Paket.Module.PaketModule))] | ||
using Cake.Core.Packaging; | ||
|
||
namespace Cake.Paket.Module | ||
{ | ||
public class PaketModule : ICakeModule | ||
/// <summary> | ||
/// The module responsible for registering | ||
/// default types in the Cake.Paket.Module assembly. | ||
/// </summary> | ||
public sealed class PaketModule : ICakeModule | ||
{ | ||
/// <summary> | ||
/// Performs custom registrations in the provided registrar. | ||
/// </summary> | ||
/// <param name="registrar">The container registrar.</param> | ||
public void Register(ICakeContainerRegistrar registrar) | ||
{ | ||
registrar.RegisterType<PaketScriptProcessor>().As<IScriptProcessor>().Singleton(); | ||
if (registrar == null) | ||
{ | ||
throw new ArgumentNullException(nameof(registrar)); | ||
} | ||
|
||
#if NETCORE | ||
// NuGet V3 | ||
registrar.RegisterType<V3.NuGetV3ContentResolver>().As<INuGetContentResolver>().Singleton(); | ||
#else | ||
// NuGet V2 | ||
registrar.RegisterType<V2.NuGetV2ContentResolver>().As<INuGetContentResolver>().Singleton(); | ||
#endif | ||
|
||
// URI resource support. | ||
registrar.RegisterType<PaketPackageInstaller>().As<IPackageInstaller>().Singleton(); | ||
} | ||
} | ||
} |
Oops, something went wrong.