Class: OSGi::BundlePackage

Inherits:
Object
  • Object
show all
Defined in:
lib/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
31
32
33
34
35
36
37
# File 'lib/osgi/bundle_package.rb', line 24

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

Instance Attribute Details

#bundlesObject

Returns the value of attribute bundles.



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

def bundles
  @bundles
end

#importsObject

Returns the value of attribute imports.



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

def imports
  @imports
end

#is_exportObject

Returns the value of attribute is_export.



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

def is_export
  @is_export
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#optionalObject

Returns the value of attribute optional.



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

def optional
  @optional
end

#original_versionObject

Returns the value of attribute original_version.



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

def original_version
  @original_version
end

#versionObject

Returns the value of attribute version.



22
23
24
# File 'lib/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.



94
95
96
97
98
99
# File 'lib/osgi/bundle_package.rb', line 94

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

#hashObject

Important for maps. We absolutely want to avoid having to resolve several times the same package



88
89
90
# File 'lib/osgi/bundle_package.rb', line 88

def hash
  return to_s.hash
end

#resolve(bundles = resolve_matching_artifacts) ⇒ Object

Resolves the bundles that export this package.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/osgi/bundle_package.rb', line 58

def resolve(bundles = resolve_matching_artifacts)
  bundles = case bundles.size
  when 0 then []
  when 1 then bundles
  else
    bundles = PackageResolvingStrategies.send(OSGi.options.package_resolving_strategy, name, bundles)
  end
  if bundles.empty?
    
    return [] if OSGi.is_framework_package?(name) # Is the bundle part of the packages provided by default ?
      
      
    trace "original version: #{original_version}"
    if optional
      info "No bundles found exporting the optional package #{name};version=#{version} (#{original_version})"
    else
      warn "No bundles found exporting the package #{name};version=#{version} (#{original_version})"
    end
  end
  bundles
  
end

#resolve_matching_artifactsObject

Resolves the matching artifacts associated with the project.



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/osgi/bundle_package.rb', line 42

def resolve_matching_artifacts
  # Collect the bundle projects
  # and extend them with the BundleProjectMatcher module
  b_projects = BundleProjects::bundle_projects.select {|p|
    p.extend BundleProjectMatcher 
    p.matches(:exports_package => name, :version => version)
  }
  warn "*** SPLIT PACKAGE: #{self} is exported by more than one project: <#{b_projects.join(", ")}> ABORTING!" if b_projects.size > 1
  return b_projects unless b_projects.empty?
  
  resolved = OSGi.registry.resolved_containers.collect {|i| i.find(:exports_package => name, :version => version)}
  resolved.flatten.compact.collect{|b| b.dup}
end

#to_sObject

:nodoc:



81
82
83
# File 'lib/osgi/bundle_package.rb', line 81

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