Module: BuildrDependencyExtensions::HelperFunctions

Defined in:
lib/buildr-dependency-extensions/helper.rb

Class Method Summary collapse

Class Method Details

.get_all_versions(artifact, original_set) ⇒ Object

returns all versions of artifact in original_set sorted using the Version sorting order



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/buildr-dependency-extensions/helper.rb', line 12

def HelperFunctions.get_all_versions artifact, original_set
  original_artifact_hash = Artifact.to_hash(artifact)

  new_set = original_set.select do |candidate_artifact|
    candidate_hash = Artifact.to_hash(candidate_artifact)
    candidate_hash[:group] == original_artifact_hash[:group] &&
      candidate_hash[:id] == original_artifact_hash[:id]  &&
      candidate_hash[:type] == original_artifact_hash[:type] &&
      candidate_hash[:classifier] == original_artifact_hash[:classifier]
  end

  new_set = new_set.uniq.sort.reverse
  new_set.
    map { |artifact| Artifact.to_hash(artifact)[:version] }.
    map { |version_string| Version.new version_string}
end

.get_all_versions_sorted_by_depth(artifact, original_set) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/buildr-dependency-extensions/helper.rb', line 29

def HelperFunctions.get_all_versions_sorted_by_depth artifact, original_set
  original_artifact_hash = Artifact.to_hash(artifact)

  new_set = original_set.select do |candidate_artifact|
    candidate_hash = Artifact.to_hash(candidate_artifact)
    candidate_hash[:group] == original_artifact_hash[:group] &&
      candidate_hash[:id] == original_artifact_hash[:id]  &&
      candidate_hash[:type] == original_artifact_hash[:type] &&
      candidate_hash[:classifier] == original_artifact_hash[:classifier]
  end

  new_set = new_set.uniq
  # Sort using the version first, so in case of conflict we use the higher version
  new_set = new_set.sort {|x,y| Version.new(x.to_hash[:version]) <=> Version.new(x.to_hash[:version])}.reverse
  new_set = new_set.sort {|x,y| x.depth <=> y.depth}
  new_set.
    map { |artifact| Artifact.to_hash(artifact)[:version] }.
    map { |version_string| Version.new version_string}
end

.get_unique_group_artifact(set) ⇒ Object

Change the version number to 0 and invoke uniq on the resulting array to get a unique set of artifacts (ignoring the version number)



6
7
8
9
# File 'lib/buildr-dependency-extensions/helper.rb', line 6

def HelperFunctions.get_unique_group_artifact set
  new_set = set.map { |artifact| hash = Artifact.to_hash(artifact); hash[:version] = 0; Artifact.to_spec(hash) }
  new_set.uniq
end

.is_artifact?(task) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/buildr-dependency-extensions/helper.rb', line 49

def HelperFunctions.is_artifact? task
  task.respond_to?(:to_spec) && task.respond_to?(:to_hash)
end