lib/buildr4osgi/osgi/project_extension.rb in buildr4osgi-0.9.0 vs lib/buildr4osgi/osgi/project_extension.rb in buildr4osgi-0.9.2
- old
+ new
@@ -74,39 +74,22 @@
_dependencies = {}
_projects = {}
project.projects.each do |subp|
collect(subp)
_projects[subp.name] = projects.collect {|p| p.name}.uniq.sort
- _dependencies[subp.name] = bundles.sort
+ _dependencies[subp.name] = bundles.collect {|b| b.to_s }.uniq.sort
end
collect(project)
- _dependencies[project.name] = bundles.sort
+ _dependencies[project.name] = bundles.collect {|b| b.to_s }.uniq.sort
_projects[project.name] = projects.collect {|p| p.name}.uniq.sort
- def find_root(project)
- project.parent.nil? ? project : project.parent
- end
-
- base_dir = find_root(project).base_dir
- written_dependencies = YAML.load(File.read(File.join(base_dir, "dependencies.yml"))) if File.exists? File.join(base_dir, "dependencies.yml")
- written_dependencies ||= {}
- written_dependencies.extend SortedHash
-
-
- _projects.keys.each {|p|
- written_dependencies[p] ||= {}
- written_dependencies[p].extend SortedHash
- written_dependencies[p]["dependencies"] ||= []
- written_dependencies[p]["projects"] ||= []
- written_dependencies[p]["dependencies"] |= _dependencies[p]
- written_dependencies[p]["projects"] |= _projects[p]
- written_dependencies[p]["dependencies"].sort!
- written_dependencies[p]["projects"].sort!
+ dependencies = ::OSGi::Dependencies.new(project)
+ dependencies.write(_projects.keys) {|hash, p|
+ hash[p]["dependencies"] |= _dependencies[p]
+ hash[p]["projects"] |= _projects[p]
}
-
- Buildr::write File.join(base_dir, "dependencies.yml"), written_dependencies.to_yaml
end
end
end
class InstallTask < Rake::Task #:nodoc:
@@ -211,111 +194,22 @@
# Reads the dependencies from dependencies.yml
# and returns the direct dependencies of the project, as well as its project dependencies and their own dependencies.
# This method is used recursively, so beware of cyclic dependencies.
#
def dependencies(&block)
-
- deps = Dependencies.new
- deps.read(project)
- return deps.projects + deps.dependencies
+ deps = ::OSGi::Dependencies.new(project)
+ deps.read
+ deps.dependencies + deps.projects
end
-
- class OSGi #:nodoc:
-
- attr_reader :options, :registry
-
- def initialize(project)
- if (project.parent)
- @options = project.parent.osgi.options.dup
- @registry = project.parent.osgi.registry.dup
- end
- @options ||= Options.new
- @registry ||= ::OSGi::Registry.new
- end
-
- # The options for the osgi.options method
- # package_resolving_strategy:
- # The package resolving strategy, it should be a symbol representing a module function in the OSGi::PackageResolvingStrategies module.
- # bundle_resolving_strategy:
- # The bundle resolving strategy, it should be a symbol representing a module function in the OSGi::BundleResolvingStrategies module.
- class Options
- attr_accessor :package_resolving_strategy, :bundle_resolving_strategy
-
- def initialize
- @package_resolving_strategy = :all
- @bundle_resolving_strategy = :latest
- end
-
- end
- end
- # Makes a osgi instance available to the project.
- # The osgi object may be used to access OSGi containers
- # or set options, currently the resolving strategies.
- def osgi
- @osgi ||= OSGi.new(self)
- @osgi
- 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
end
end
- private
-
- #
- # A class to read dependencies.yml, and get a flat array of projects and dependencies for a project.
- class Dependencies
-
- attr_accessor :dependencies, :projects
-
- def read(project)
- def find_root(project)
- project.parent.nil? ? project : project.parent
- end
-
- base_dir = find_root(project).base_dir
- @dependencies = []
- @projects = []
- @deps_yml = {}
- return unless File.exists? File.join(base_dir, "dependencies.yml")
- @deps_yml =YAML.load(File.read(File.join(base_dir, "dependencies.yml")))
- return if @deps_yml[project.name].nil? || @deps_yml[project.name]["dependencies"].nil?
- _read(project.name, false)
- @dependencies = @dependencies.flatten.compact.uniq
- return @dependencies, @projects
- end
-
- private
-
- def _read(project, add_project = true)
- @dependencies |= @deps_yml[project]["dependencies"]
- projects << Buildr::project(project) if add_project
- @deps_yml[project]["projects"].each {|p| _read(p) unless projects.include?(p)}
- end
- end
-
- # Copy/pasted from here: http://snippets.dzone.com/posts/show/5811
- # no author information though.
- module SortedHash
-
- # Replacing the to_yaml function so it'll serialize hashes sorted (by their keys)
- #
- # Original function is in /usr/lib/ruby/1.8/yaml/rubytypes.rb
- def to_yaml( opts = {} )
- YAML::quick_emit( object_id, opts ) do |out|
- out.map( taguri, to_yaml_style ) do |map|
- sort.each do |k, v| # <-- here's my addition (the 'sort')
- map.add( k, v )
- end
- end
- end
- end
- end
end
module Buildr #:nodoc:
class Project #:nodoc:
include OSGi::ProjectExtension
\ No newline at end of file