Class: OSGi::BundlePackage

Inherits:
Object show all
Defined in:
lib/buildr4osgi/osgi/bundle_package.rb

Overview

A class to represent an OSGi bundle package. Created from the Import-Package or Provide-Package (Export-Package) header.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, version, args = {}) ⇒ BundlePackage

:nodoc:



24
25
26
27
28
29
30
# File 'lib/buildr4osgi/osgi/bundle_package.rb', line 24

def initialize(name, version, args = {}) #:nodoc:
  @name= name
  @is_export = args[:is_export]
  @version = (is_export ? version.gsub(/\"/, '') : VersionRange.parse(version, true)) if version
  @bundles = args[:bundles] || []
  @imports = args[:imports] || []
end

Instance Attribute Details

#bundlesObject

Returns the value of attribute bundles.



22
23
24
# File 'lib/buildr4osgi/osgi/bundle_package.rb', line 22

def bundles
  @bundles
end

#importsObject

Returns the value of attribute imports.



22
23
24
# File 'lib/buildr4osgi/osgi/bundle_package.rb', line 22

def imports
  @imports
end

#is_exportObject

Returns the value of attribute is_export.



22
23
24
# File 'lib/buildr4osgi/osgi/bundle_package.rb', line 22

def is_export
  @is_export
end

#nameObject

Returns the value of attribute name.



22
23
24
# File 'lib/buildr4osgi/osgi/bundle_package.rb', line 22

def name
  @name
end

#versionObject

Returns the value of attribute version.



22
23
24
# File 'lib/buildr4osgi/osgi/bundle_package.rb', line 22

def version
  @version
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

We just test the name and version as we want to be able to see if an unresolved package and a resolved one represent the same bundle package.



70
71
72
73
74
75
# File 'lib/buildr4osgi/osgi/bundle_package.rb', line 70

def ==(other)
  return false unless other.is_a? BundlePackage
  eql = name == other.name
  eql |= version.nil? ? other.version.nil? : version == other.version
  eql
end

#resolve(project, bundles = resolve_matching_artifacts(project)) ⇒ Object

Resolves the bundles that export this package.



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/buildr4osgi/osgi/bundle_package.rb', line 52

def resolve(project, bundles = resolve_matching_artifacts(project))
  bundles = case bundles.size
  when 0 then []
  when 1 then bundles
  else
    bundles = OSGi::PackageResolvingStrategies.send(project.osgi.options.package_resolving_strategy, name, bundles)
  end
  warn "No bundles found exporting the package #{name}; version=#{version}" if (bundles.empty?)
  bundles
  
end

#resolve_matching_artifacts(project) ⇒ Object

Resolves the matching artifacts associated with the project.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/buildr4osgi/osgi/bundle_package.rb', line 35

def resolve_matching_artifacts(project)
  # Collect the bundle projects
  # and extend them with the BundleProjectMatcher module
  b_projects = BundleProjects::bundle_projects.select {|p|
    unless p == project
      p.extend BundleProjectMatcher 
      p.matches(:exports_package => name, :version => version)
    end
  }
  return b_projects unless b_projects.empty?
  
  resolved = project.osgi.registry.resolved_containers.collect {|i| i.find(:exports_package => name, :version => version)}
  resolved.flatten.compact.collect{|b| b.dup}
end

#to_sObject

:nodoc:



64
65
66
# File 'lib/buildr4osgi/osgi/bundle_package.rb', line 64

def to_s #:nodoc:
  "Package #{name}; version #{version}"
end