Class: OSGi::Container
Overview
This class represents an OSGi container. It contains the bundles, fragments, and the location of the OSGi container. A typical OSGi container is an Eclipse instance.
Instance Attribute Summary collapse
-
#bundles ⇒ Object
readonly
bundles: the bundles of the eclipse instance loaded on startup location: the location of the Eclipse instance.
-
#fragments ⇒ Object
readonly
bundles: the bundles of the eclipse instance loaded on startup location: the location of the Eclipse instance.
-
#location ⇒ Object
readonly
bundles: the bundles of the eclipse instance loaded on startup location: the location of the Eclipse instance.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#find(criteria = {}) ⇒ Object
Return the list of bundles and fragments that match the criteria passed as arguments Possible criterias: name: the name of the bundle version: the version of the bundle exports_package: a package exported by the bundle.
-
#find_fragments(criteria = {:host => "", :version => ""}) ⇒ Object
Return the list of fragments that match the criteria passed as arguments Possible criterias: host: the name of the host bundle version: the version of the bundle.
-
#initialize(location, plugin_locations = ["dropins", "plugins"]) ⇒ Container
constructor
Default constructor for a Container.
-
#parse(dir) ⇒ Object
Parses the directory and grabs the plugins, adding the created bundle objects to @bundles.
Constructor Details
#initialize(location, plugin_locations = ["dropins", "plugins"]) ⇒ Container
Default constructor for a Container
location: the location of the Eclipse instance plugin_locations, default value is [“dropins”, “plugins”] create_bundle_info, default value is true
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/buildr4osgi/osgi/container.rb', line 35 def initialize(location, plugin_locations = ["dropins", "plugins"]) @location = location @bundles = [] @fragments = [] plugin_locations.each do |p_loc| p_loc_complete = File.join(@location, p_loc) warn "Folder #{p_loc_complete} not found!" if !File.exists? p_loc_complete parse(p_loc_complete) if File.exists? p_loc_complete end info("Done parsing #{location}") end |
Instance Attribute Details
#bundles ⇒ Object (readonly)
bundles: the bundles of the eclipse instance loaded on startup location: the location of the Eclipse instance
28 29 30 |
# File 'lib/buildr4osgi/osgi/container.rb', line 28 def bundles @bundles end |
#fragments ⇒ Object (readonly)
bundles: the bundles of the eclipse instance loaded on startup location: the location of the Eclipse instance
28 29 30 |
# File 'lib/buildr4osgi/osgi/container.rb', line 28 def fragments @fragments end |
#location ⇒ Object (readonly)
bundles: the bundles of the eclipse instance loaded on startup location: the location of the Eclipse instance
28 29 30 |
# File 'lib/buildr4osgi/osgi/container.rb', line 28 def location @location end |
Instance Method Details
#==(other) ⇒ Object
141 142 143 144 |
# File 'lib/buildr4osgi/osgi/container.rb', line 141 def ==(other) false unless other.is_a? Container return location == other.location end |
#find(criteria = {}) ⇒ Object
Return the list of bundles and fragments that match the criteria passed as arguments Possible criterias:
name: the name of the bundle
version: the version of the bundle
exports_package: a package exported by the bundle
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/buildr4osgi/osgi/container.rb', line 100 def find(criteria = {}) selected = bundles + fragments if (criteria[:name]) selected = selected.select {|b| b.name == criteria[:name]} end if (criteria[:exports_package]) selected = selected.select {|b| !(b.exported_packages.select {|package| package.name == criteria[:exports_package] && (criteria[:version].nil? || criteria[:version].in_range(package.version)) }.empty?) } else if (criteria[:version]) if criteria[:version].is_a?(VersionRange) selected = selected.select {|b| criteria[:version].in_range(b.version)} else selected = selected.select {|b| b.version == criteria[:version]} end end end selected end |
#find_fragments(criteria = {:host => "", :version => ""}) ⇒ Object
Return the list of fragments that match the criteria passed as arguments Possible criterias:
host: the name of the host bundle
version: the version of the bundle
130 131 132 133 134 135 136 137 138 139 |
# File 'lib/buildr4osgi/osgi/container.rb', line 130 def find_fragments(criteria = {:host => "", :version => ""}) selected = fragments if (criteria[:host]) selected = selected.select {|b| b.fragment.name == criteria[:host]} end if (criteria[:version]) selected = selected.select {|b| b.fragment.version == criteria[:version]} end selected end |
#parse(dir) ⇒ Object
Parses the directory and grabs the plugins, adding the created bundle objects to @bundles.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/buildr4osgi/osgi/container.rb', line 48 def parse(dir) Dir.open(dir) do |plugins| plugins.entries.each do |plugin| absolute_plugin_path = "#{plugins.path}#{File::SEPARATOR}#{plugin}" if (/.*\.jar$/.match(plugin)) zipfile = Zip::ZipFile.open(absolute_plugin_path) entry = zipfile.find_entry("META-INF/MANIFEST.MF") if (entry != nil) manifest = Manifest.read(zipfile.read("META-INF/MANIFEST.MF")) bundle = Bundle.fromManifest(manifest, absolute_plugin_path) if bundle.nil? elsif bundle.fragment? @fragments << bundle else @bundles << bundle end end zipfile.close else # take care of the folder if (File.directory?(absolute_plugin_path) && !(plugin == "." || plugin == "..")) if (!File.exists? ["#{absolute_plugin_path}", "META-INF", "MANIFEST.MF"].join(File::SEPARATOR)) #recursive approach: we have a folder wih no MANIFEST.MF, we should look into it. parse(absolute_plugin_path) else next if File.exists? "#{absolute_plugin_path}/feature.xml" # avoid parsing features. begin manifest = Manifest.read((file = File.open("#{absolute_plugin_path}/META-INF/MANIFEST.MF")).read) rescue file.close end bundle = Bundle.fromManifest(manifest, absolute_plugin_path) if bundle.nil? elsif bundle.fragment? @fragments << bundle else @bundles << bundle end end end end end end @bundles = @bundles.compact @fragments = @fragments.compact end |