lib/buildr4osgi/osgi/project_extension.rb in buildr4osgi-0.9.2 vs lib/buildr4osgi/osgi/project_extension.rb in buildr4osgi-0.9.3

- old
+ new

@@ -14,50 +14,73 @@ # the License. # Methods added to Project for compiling, handling of resources and generating source documentation. module OSGi + MISSING = "missing" + + RESOLVED = {} + + module BundleCollector #:nodoc: attr_accessor :bundles, :projects, :project_dependencies # Collects the bundles associated with a project. # Returns them as a sorted array. # def collect(project) + info "** Collecting dependencies for #{project}" @bundles = [] @projects = [] - project.manifest_dependencies().each {|dep| _collect(dep, project)} + dependencies = project.manifest_dependencies().each {|dep| ; _collect(dep)} + @projects.delete project # Remove our own reference if it was added. + info "** Done collecting dependencies for #{project}" + return dependencies end # Collects the bundles associated with the bundle # - def _collect(bundle, project) + def _collect(bundle) if bundle.is_a?(Bundle) - bundle = bundle.resolve(project) - unless bundle.nil? + unless ::OSGi::RESOLVED[bundle] + resolved = bundle.resolve + trace "Resolving #{bundle}: #{resolved}" + ::OSGi::RESOLVED[bundle] = resolved.nil? ? ::OSGi::MISSING : resolved + end + bundle = ::OSGi::RESOLVED[bundle] + unless bundle.nil? || bundle == ::OSGi::MISSING if bundle.is_a?(Buildr::Project) @projects << bundle elsif !(@bundles.include? bundle) @bundles << bundle - @bundles |= bundle.fragments(project) - (bundle.bundles + bundle.imports).each {|b| - _collect(b, project) + @bundles |= bundle.fragments + (bundle.bundles + bundle.imports).each {|import| + _collect import } end end elsif bundle.is_a?(BundlePackage) - bundle.resolve(project).each {|b| - if b.is_a?(Buildr::Project) - @projects << b - elsif !(@bundles.include? b) - @bundles << b - (b.bundles + b.imports).each {|import| - _collect(import, project) - } - end - } + unless ::OSGi::RESOLVED[bundle] + resolved = bundle.resolve + trace "Resolving #{bundle}: #{resolved}" + ::OSGi::RESOLVED[bundle] = (resolved.nil? || (resolved.is_a?(Array) && resolved.empty?)) ? ::OSGi::MISSING : resolved + end + bundle = ::OSGi::RESOLVED[bundle] + unless bundle.nil? || bundle == ::OSGi::MISSING + bundle.each {|b| + if b.is_a?(Buildr::Project) + @projects << b + elsif !(@bundles.include? b) + @bundles << b + @bundles |= b.fragments + (b.bundles + b.imports).each {|import| + _collect import + } + end + } + end elsif bundle.is_a?(Buildr::Project) @projects << bundle end end @@ -83,12 +106,16 @@ _dependencies[project.name] = bundles.collect {|b| b.to_s }.uniq.sort _projects[project.name] = projects.collect {|p| p.name}.uniq.sort dependencies = ::OSGi::Dependencies.new(project) dependencies.write(_projects.keys) {|hash, p| - hash[p]["dependencies"] |= _dependencies[p] - hash[p]["projects"] |= _projects[p] + unless _dependencies[p].nil? + hash[p]["dependencies"] = _dependencies[p] + end + unless _projects[p].nil? + hash[p]["projects"] = _projects[p] + end } end end end @@ -202,10 +229,22 @@ end # returns an array of the dependencies of the plugin, read from the manifest. def manifest_dependencies() as_bundle = Bundle.fromProject(self) - as_bundle.nil? ? [] : as_bundle.bundles.collect{|b| b.resolve(self)}.compact + as_bundle.imports.collect {|i| i.resolve(self)}.flatten + as_bundle.nil? ? [] : as_bundle.bundles.collect{|b| b.resolve}.compact + as_bundle.imports.collect {|i| i.resolve}.flatten + end + + # Returns the EE defined in the manifest if present. + def execution_environments() + # Code copied straight from Bundle.fromProject + packaging = project.packages.select {|package| package.is_a?(BundlePackaging)} + raise "More than one bundle packaging is defined over the project #{project.id}, see BOSGI-16." if packaging.size > 1 + return nil if packaging.empty? + m = ::Buildr::Packaging::Java::Manifest.new(File.exists?("META-INF/MANIFEST.MF") ? File.read("META-INF/MANIFEST.MF") : nil) + m.main.merge!(manifest) + m.main.merge!(packaging.first.manifest) + (Manifest.read(m.to_s).first["Bundle-RequiredExecutionEnvironment"] || {}).keys.compact.flatten.collect {|ee| OSGi.options.available_ee[ee]} end end end \ No newline at end of file