Module: Buildr::ArtifactSearch

Extended by:
ArtifactSearch
Included in:
ArtifactSearch
Defined in:
lib/buildr/packaging/artifact_search.rb

Overview

Search best artifact version from remote repositories

Instance Method Summary collapse

Instance Method Details

#best_version(spec, *methods) ⇒ Object

TODO: return the url for best matching repo



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/buildr/packaging/artifact_search.rb', line 35

def best_version(spec, *methods)
  spec = Artifact.to_hash(spec)
  spec[:version] = requirement = VersionRequirement.create(spec[:version])
  select = lambda do |candidates|
    candidates.find { |candidate| requirement.satisfied_by?(candidate) }
  end
  result = nil
  methods = search_methods if methods.empty?
  if requirement.composed?
    until result || methods.empty?
      method = methods.shift
      type = method.keys.first
      from = method[type]
      if (include.empty? || !(include & [:all, type, from]).empty?) &&
          (exclude & [:all, type, from]).empty?
        if from.respond_to?(:call)
          versions = from.call(spec.dup)
        else
          versions = send("#{type}_versions", spec.dup, *from)
        end
        result = select[versions]
      end
    end
  end
  result ||= requirement.default
  raise "Could not find #{Artifact.to_spec(spec)}"  +
    "\n You may need to use an specific version instead of a requirement" unless result
  spec.merge :version => result
end

#exclude(method = nil) ⇒ Object



30
31
32
# File 'lib/buildr/packaging/artifact_search.rb', line 30

def exclude(method = nil)
  (@excludes ||= []).tap { push method if method }
end

#include(method = nil) ⇒ Object



26
27
28
# File 'lib/buildr/packaging/artifact_search.rb', line 26

def include(method = nil)
  (@includes ||= []).tap { push method if method }
end

#requirement?(spec) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/buildr/packaging/artifact_search.rb', line 65

def requirement?(spec)
  VersionRequirement.requirement?(spec[:version])
end