Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unified tool resolution #736

Closed
patriksvensson opened this issue Mar 4, 2016 · 2 comments
Closed

Unified tool resolution #736

patriksvensson opened this issue Mar 4, 2016 · 2 comments
Assignees
Milestone

Comments

@patriksvensson
Copy link
Member

We need a common way of registering and resolving tools/addins in Cake. There are some addins that require this functionality, and it would be nice to actually have a proper tool resolution strategy in place that we can use outside of tools.

  • Should allow a user to globally set a tool path from the script.
  • Should be able to register tools by their file name.
  • Should be able to resolve tools by their file name.
  • The IPackageInstaller implementations should be able to:
    • Register paths to downloaded tools.

This would allow us to version tools correctly.

Proposition (API)

// Not super happy about this name.
public interface IToolService
{
  void Register(FilePath path);
  FilePath Resolve(string tool);
}

public interface ICakeContext
{
  IToolService Tools { get; }
}

Proposition (implementation)

Someone who wants to override this behavior could easily use
the default implementation and only provide a new IToolResolutionStrategy.

Of course we need to have a mechanism to register services before
the Cake container has been fully built but that's a problem for
another issue.

public interface IToolRepository
{
  void Register(FilePath path);
  IEnumerable<FilePath> Find(string tool);
}

public interface IToolResolutionStrategy
{
  FilePath Resolve(IToolRepository registry, string tool);
}

public sealed class ToolResolver : IToolService
{
  private readonly IToolRepository _repository;
  private readonly IToolResolutionStrategy _strategy;

  public ToolResolver(IToolRepository repository, IToolResolutionStrategy strategy)
  {
    _repository = repository;
    _strategy = strategy;
  }

  public void Register(FilePath path)
  {
    _repository.Register(path);
  }

  public FilePath Resolve(string tool)
  {
    _strategy.Resolve(_repository, tool);
  }
}

Usage

// Register a tool.
context.Tools.Register("C:/Temp/xunit-console.exe");

// Later in the xUnit tool wrapper, we resolve it like this.
var path = context.Tools.Resolve("xunit-console.exe");
@patriksvensson patriksvensson self-assigned this Mar 4, 2016
@patriksvensson patriksvensson changed the title Unified tool and addin resolution Unified tool resolution Mar 6, 2016
@dbent dbent mentioned this issue Mar 12, 2016
@devlead devlead added this to the v0.12.0 milestone Apr 28, 2016
@stffabi
Copy link
Contributor

stffabi commented May 19, 2016

Would it be possible at the same time the support of "Tools" which don't need to provide ".exe" Files? We have for example another NuGet Package which includes MsBuild Loggers we would like to use. If that would be supported, we could do something like the following in order to resolve the path to the logger.

var path = context.Tools.Resolve("MsBuildXmlLogger.dll");

@patriksvensson
Copy link
Member Author

@stffabi Thanks for your feedback! Add an issue about that you want tools to be able to consist of *.dll as well and we can continue the discussion there.

@gep13 gep13 closed this as completed in 7dd9118 May 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants