Sha256: 42b3e716f63f8751f0e741cd681ec39babb611f56a9de0719991a50cbae24964

Contents?: true

Size: 1.63 KB

Versions: 6

Compression:

Stored size: 1.63 KB

Contents

require 'map'
require 'albacore'

module Physique
  module ToolLocator
    include Albacore::Logging

    @@registered_tools = {}

    def register_tool(name, executable, nuget_package = nil, nuget_path = nil)
    end

    def lookup_tool(name, project, package_folder)
    end

    # Allows you to locate a tool on disk given a file specification. For example...
    #
    #   locate_tool 'C:/Program Files/Microsoft SQL Server/**/Tools/Binn/SQLCMD.EXE'
    #
    # The tool sorts any matching executables in descending order to that the most recent version is returned. To
    # change this behavior call the method with the reverse option.
    #
    #   locate_tool 'C:/path/to/**/tool.exe', find_latest: false
    #
    # Throws a ToolNotFoundError if no tool could be found.
    def locate_tool(paths, options = {})
      # FileList only correctly handles forward-slashes, even on Windows
      paths = paths.gsub('\\', '/')

      debug { "Extracting paths from the following pattern #{paths}" }
      paths = FileList[paths] unless paths.respond_to?(:each)

      debug { "Attempting to locate tool in the following paths #{paths}" }
      opts = Map.options(options)
      opts = opts.apply :find_latest => true
      paths = paths.collect { |p| which(p) }.compact.sort
      paths = paths.reverse if opts[:find_latest]
      tool = paths.first

      raise ToolNotFoundError, "Could not find tool in the following paths: \n #{paths}" if tool.nil?
      tool
    end

    def which(exe)
      Albacore::CrossPlatformCmd.which(exe) ? exe : nil;
    end

    class ToolNotFoundError < Exception; end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
physique-0.3.10 lib/physique/tool_locator.rb
physique-0.3.9 lib/physique/tool_locator.rb
physique-0.3.8 lib/physique/tool_locator.rb
physique-0.3.7 lib/physique/tool_locator.rb
physique-0.3.6 lib/physique/tool_locator.rb
physique-0.3.5 lib/physique/tool_locator.rb