Method: OSGi::Container#parse

Defined in:
lib/osgi/container.rb

#parse(dir) ⇒ Object

Parses the directory and grabs the plugins, adding the created bundle objects to @bundles.



47
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
# File 'lib/osgi/container.rb', line 47

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