Module: OSGi::BundleResolvingStrategies

Defined in:
lib/buildr4osgi/osgi/resolving_strategies.rb

Overview

Functions declared on this module are used to select bundles amongst a list of them, when requiring bundles through the Require-Bundle header. Functions must have the signature (bundles)

where 
  bundles: an array of bundles

Class Method Summary collapse

Class Method Details

.latest(bundles) ⇒ Object

Default strategy: the bundle with the highest version number is returned.



72
73
74
# File 'lib/buildr4osgi/osgi/resolving_strategies.rb', line 72

def latest(bundles)
  bundles.sort {|a, b| a.version <=> b.version}.last
end

.oldest(bundles) ⇒ Object

The bundle with the lowest version number is returned.



79
80
81
# File 'lib/buildr4osgi/osgi/resolving_strategies.rb', line 79

def oldest(bundles)
  bundles.sort {|a, b| a.version <=> b.version}.first
end

.prompt(bundles) ⇒ Object

Default module function that prompts the user to select the bundle he’d like to select as dependencies.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/buildr4osgi/osgi/resolving_strategies.rb', line 86

def prompt(bundles)
  bundle = nil
  while (bundle.nil?)
    puts "Choose a bundle amongst those presented:\n" + bundles.sort! {|a, b| a.version <=> b.version }.
    collect {|b| "\t#{bundles.index(b) +1}. #{b.name} #{b.version}"}.join("\n")
    number = gets.chomp
    begin
      number = number.to_i
      number -= 1
      bundle = bundles[number] if number >= 0 # no negative indexing here.
      puts "Invalid index" if number < 0
    rescue Exception => e
      puts "Invalid index"
      #do nothing
    end
  end
  bundle
end