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

- old
+ new

@@ -17,53 +17,77 @@ # A class to represent an OSGi bundle package. # Created from the Import-Package or Provide-Package (Export-Package) header. # class BundlePackage - attr_accessor :name, :version, :bundles, :imports, :is_export + attr_accessor :name, :version, :bundles, :imports, :is_export, :original_version, :optional def initialize(name, version, args = {}) #:nodoc: @name= name @is_export = args[:is_export] - @version = (is_export ? version.gsub(/\"/, '') : VersionRange.parse(version, true)) if version + @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 # # Resolves the matching artifacts associated with the project. # - def resolve_matching_artifacts(project) + def resolve_matching_artifacts # 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 + 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 = project.osgi.registry.resolved_containers.collect {|i| i.find(:exports_package => name, :version => version)} + resolved = OSGi.registry.resolved_containers.collect {|i| i.find(:exports_package => name, :version => version)} resolved.flatten.compact.collect{|b| b.dup} end # Resolves the bundles that export this package. # - def resolve(project, bundles = resolve_matching_artifacts(project)) + def resolve(bundles = resolve_matching_artifacts) bundles = case bundles.size when 0 then [] when 1 then bundles else - bundles = OSGi::PackageResolvingStrategies.send(project.osgi.options.package_resolving_strategy, name, bundles) + bundles = PackageResolvingStrategies.send(OSGi.options.package_resolving_strategy, name, bundles) end - warn "No bundles found exporting the package #{name}; version=#{version}" if (bundles.empty?) + 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 def to_s #:nodoc: "Package #{name}; version #{version}" + end + + # Important for maps. + # We absolutely want to avoid having to resolve several times the same package + # + def hash + return to_s.hash end # 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. def ==(other) \ No newline at end of file