3 # Plugin definition classes
4 autoload :AgentDefinition, "mcollective/pluginpackager/agent_definition"
5 autoload :StandardDefinition, "mcollective/pluginpackager/standard_definition"
7 # Package implementation plugins
8 def self.load_packagers
9 PluginManager.find_and_load("pluginpackager")
16 # Fetch and return metadata from plugin DDL
17 def self.get_metadata(path, type)
18 ddl = DDL.new("package", type.to_sym, false)
21 ddl_file = File.read(Dir.glob(File.join(path, type, "*.ddl")).first)
23 raise "failed to load ddl file in plugin directory : #{File.join(path, type)}"
25 ddl.instance_eval ddl_file
27 return ddl.meta, ddl.requirements[:mcollective]
30 # Checks if a directory is present and not empty
31 def self.check_dir_present(path)
32 (File.directory?(path) && !Dir.glob(File.join(path, "*")).empty?)
35 # Quietly calls a block if verbose parameter is false
36 def self.execute_verbosely(verbose, &block)
38 old_stdout = $stdout.clone
39 $stdout.reopen(File.new("/dev/null", "w"))
43 $stdout.reopen old_stdout
46 $stdout.reopen old_stdout
53 # Checks if a build tool is present on the system
54 def self.command_available?(build_tool)
55 ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
56 builder = File.join(path, build_tool)
57 if File.exists?(builder)
64 def self.safe_system(*args)
65 raise(RuntimeError, "Failed: #{args.join(' ')}") unless system *args
68 # Filter out platform specific dependencies
69 # Given a list of dependencies named -
72 # PluginPackager.filter_dependencies('debian', dependencies)
74 def self.filter_dependencies(prefix, dependencies)
75 dependencies.map do |dependency|
76 if dependency[:name] =~ /^(\w+)::(\w+)/
78 dependency[:name] = $2
86 end.reject{ |dependency| dependency == nil }