lib/buildr4osgi/osgi/registry.rb in buildr4osgi-0.9.0 vs lib/buildr4osgi/osgi/registry.rb in buildr4osgi-0.9.2

- old
+ new

@@ -13,10 +13,32 @@ # License for the specific language governing permissions and limitations under # the License. module OSGi + OSGI_GROUP_ID = "osgi" + + class GroupMatcher + include Singleton + attr_accessor :group_matchers + + def initialize + @group_matchers = [] + # Default rule for Eclipse artifacts. + @group_matchers << Proc.new {|n| "org.eclipse" if n.match(/org\.eclipse\..*/) } + end + + def group(bundle) + return group(bundle.id) if bundle.is_a?(Bundle) + group_matchers.reverse.each do |group| + result = group.call(bundle) + return result unless result.nil? + end + OSGI_GROUP_ID + + end + end # # A class to hold the registered containers. It is possible to add containers until resolved_containers is called, # after which it is not possible to modify the registry anymore. # class Registry @@ -51,11 +73,59 @@ # This is a long running operation where all the containers are parsed. # # Containers are resolved only once. # def resolved_containers - @resolved_containers ||= containers.collect { |container| OSGi::Container.new(container) } + @resolved_containers ||= containers.collect { |container| Container.new(container) } @resolved_containers end end + class OSGi #:nodoc: + + attr_reader :options, :registry + + def initialize(project) + if (project.parent) + @options = project.parent.osgi.options.dup + @registry = project.parent.osgi.registry.dup + end + @options ||= Options.new + @registry ||= ::OSGi::Registry.new + end + + # The options for the osgi.options method + # package_resolving_strategy: + # The package resolving strategy, it should be a symbol representing a module function in the OSGi::PackageResolvingStrategies module. + # bundle_resolving_strategy: + # The bundle resolving strategy, it should be a symbol representing a module function in the OSGi::BundleResolvingStrategies module. + # group_matchers: + # A set of Proc objects to match a bundle to a groupId for maven. + # The array is examined with the latest added Procs first. + # The first proc to return a non-nil answer is used, otherwise the OGSGI_GROUP_ID constant is used. + class Options + attr_accessor :package_resolving_strategy, :bundle_resolving_strategy + + def initialize + @package_resolving_strategy = :all + @bundle_resolving_strategy = :latest + end + + end + end + + module OSGiOptions + include Extension + + # Makes a osgi instance available to the project. + # The osgi object may be used to access OSGi containers + # or set options, currently the resolving strategies. + def osgi + @osgi ||= OSGi.new(self) + @osgi + end + end +end + +class Buildr::Project + include OSGi::OSGiOptions end \ No newline at end of file