Module: Puppet::Jenkins::Plugins
- Defined in:
- lib/puppet/jenkins/plugins.rb
Class Method Summary collapse
-
.available ⇒ Hash
A
Hash
containing a mapping of a plugin name to its manifest data. -
.exists? ⇒ Boolean
Determine whether or not the jenkins plugin directory exists.
-
.manifest_data(manifest_str) ⇒ Hash, NilClass
Return structured data for the given plugin manifest string.
Class Method Details
.available ⇒ Hash
Returns a Hash
containing a mapping of a plugin name to its manifest data.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/puppet/jenkins/plugins.rb', line 45 def self.available return {} unless exists? plugins = {} Dir.entries(Puppet::Jenkins.plugins_dir).each do |plugin| # Skip useless directories next if plugin == '..' next if plugin == '.' plugin_dir = File.join(Puppet::Jenkins.plugins_dir, plugin) # Without an unpacked plugin directory, we can't find a version next unless File.directory?(plugin_dir) manifest = File.join(plugin_dir, 'META-INF', 'MANIFEST.MF') begin manifest = manifest_data(File.read(manifest)) plugins[plugin] = manifest if manifest rescue StandardError # Nothing really to do about it, failing means no version which will # result in a new plugin if needed nil end end plugins end |
.exists? ⇒ Boolean
Determine whether or not the jenkins plugin directory exists
74 75 76 77 78 79 80 |
# File 'lib/puppet/jenkins/plugins.rb', line 74 def self.exists? home = Puppet::Jenkins.home_dir return false if home.nil? return false unless File.directory? Puppet::Jenkins.plugins_dir true end |
.manifest_data(manifest_str) ⇒ Hash, NilClass
Return structured data for the given plugin manifest string
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/puppet/jenkins/plugins.rb', line 13 def self.manifest_data(manifest_str) return {} if manifest_str.nil? || manifest_str.empty? data = {} manifest_str.split("\n").each do |line| next if line.empty? # Parse out "Plugin-Version: 1.2" for example parts = line.split(': ') # If the line starts with a space or we can't get at least two parts # (key and value), that means it's really just a word-wrap from the # previous line, and not a key, skip! next if parts.size < 2 next if parts.first[0] == ' ' key = parts.first.downcase.tr('-', '_').chomp # Skip garbage keys next if key.nil? || key.empty? # Re-join any colon delimited strings in the value back together, # e.g.: "http://wiki.jenkins-ci.org/display/JENKINS/Ant+Plugin" value = parts[1..-1].join(':').chomp data[key.to_sym] = value end data end |