Module: OSGi::BundleProjectMatcher

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

Overview

:nodoc: Module extending projects to find which matches criterias used to find bundles.

Instance Method Summary collapse

Instance Method Details

#matches(criteria = {:name => "", :version => "", :exports_package => "", :fragment_for => ""}) ⇒ Object

Find if the project matches a specific set of criteria passed as parameter The criteria are tested against the manifest of the project, using its bundle packages manifest options and the MANIFEST.MF master file.

Returns true if at least one of the packages defined by this project match the criteria.



30
31
32
33
34
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
64
65
66
67
68
# File 'lib/buildr4osgi/osgi/bundle.rb', line 30

def matches(criteria = {:name => "", :version => "", :exports_package => "", :fragment_for => ""})
  if File.exists?(File.join(base_dir, "META-INF", "MANIFEST.MF"))
    manifest = ::Buildr::Packaging::Java::Manifest.new(File.read(File.join(base_dir, "META-INF", "MANIFEST.MF")))
  end
  manifest ||= ::Buildr::Packaging::Java::Manifest.new()
  project.packages.select {|package| package.is_a? ::OSGi::BundlePackaging}.each {|p|
    package_manifest = manifest.dup
    package_manifest.main.merge!(p.manifest) if p.manifest
    package_manifest = Manifest.read(package_manifest.to_s)
    if criteria[:exports_package]
      if criteria[:version]
        matchdata = package_manifest.first[Bundle::B_EXPORT_PKG][criteria[:exports_package]] unless package_manifest.first[Bundle::B_EXPORT_PKG].nil?
        return false unless matchdata
        exported_package_version = matchdata["version"]
        if criteria[:version].is_a? VersionRange
          return criteria[:version].in_range(exported_package_version)
        else
          return criteria[:version] == exported_package_version
        end
      else
        return false if package_manifest.first[Bundle::B_EXPORT_PKG].nil?
        return !package_manifest.first[Bundle::B_EXPORT_PKG][criteria[:exports_package]].nil?
      end
    elsif (package_manifest.first[Bundle::B_NAME].keys.first == criteria[:name] || id == criteria[:name])
      
      if criteria[:version]
        if criteria[:version].is_a?(VersionRange)
          return criteria[:version].in_range(version)
        else
          return criteria[:version] == version
        end 
      else
        # depending just on the name, returning true then.
        return true
      end
    end
  }
  return false
end