diff --git a/providers/plugin.rb b/providers/plugin.rb index b6879deb3c..e65e2be375 100644 --- a/providers/plugin.rb +++ b/providers/plugin.rb @@ -58,77 +58,73 @@ def load_current_resource end end - private - -def current_version - current_version = nil - manifest_file = ::File.join(plugins_dir, @current_resource.name, 'META-INF', 'MANIFEST.MF') - if ::File.exist?(manifest_file) - manifest = IO.read(manifest_file) - if manifest =~ /^Plugin-Version:\s*(.+)$/ - current_version = $1.strip + def current_version + current_version = nil + manifest_file = ::File.join(plugins_dir, @current_resource.name, 'META-INF', 'MANIFEST.MF') + if ::File.exist?(manifest_file) + manifest = IO.read(manifest_file) + current_version = manifest.match(/^Plugin-Version:\s*(.+)$/).strip end + current_version end - current_version -end -def plugin_exists? - ::File.exists?(plugin_file_path) -end + def plugin_exists? + ::File.exists?(plugin_file_path) + end -def plugin_dir_path - ::File.join(plugins_dir, @new_resource.name) -end + def plugin_dir_path + ::File.join(plugins_dir, @new_resource.name) + end -def plugin_file_path - ::File.join(plugins_dir, "#{@new_resource.name}.jpi") -end + def plugin_file_path + ::File.join(plugins_dir, "#{@new_resource.name}.jpi") + end -def plugins_dir - ::File.join(node['jenkins']['server']['home'], 'plugins') -end + def plugins_dir + ::File.join(node['jenkins']['server']['home'], 'plugins') + end + def do_install_plugin + plugin_url = @new_resource.url + + # Plugins installed from the Jenkins Update Center are written to disk with + # the `*.jpi` extension. Although plugins downloaded from the Jenkins Mirror + # have an `*.hpi` extension we will save the plugins with a `*.jpi` extension + # to match Update Center's behavior. + remote_file plugin_file_path do + source plugin_url + owner node['jenkins']['server']['user'] + group node['jenkins']['server']['group'] + backup false + action :create + notifies :restart, 'service[jenkins' + notifies :create, 'ruby_block[block_until_operational' + end -def do_install_plugin - plugin_url = @new_resource.url - - # Plugins installed from the Jenkins Update Center are written to disk with - # the `*.jpi` extension. Although plugins downloaded from the Jenkins Mirror - # have an `*.hpi` extension we will save the plugins with a `*.jpi` extension - # to match Update Center's behavior. - remote_file plugin_file_path do - source plugin_url - owner node['jenkins']['server']['user'] - group node['jenkins']['server']['group'] - backup false - action :create - notifies :restart, "service[jenkins]" - notifies :create, "ruby_block[block_until_operational]" - end - file "#{plugin_file_path}.pinned" do - action :create_if_missing - owner node['jenkins']['server']['user'] - group node['jenkins']['server']['group'] + file "#{plugin_file_path}.pinned" do + action :create_if_missing + owner node['jenkins']['server']['user'] + group node['jenkins']['server']['group'] + end end -end - -def do_upgrade_plugin - do_install_plugin -end -def do_remove_plugin - file plugin_file_path do - action :delete - backup false - notifies :restart, "service[jenkins]" - notifies :create, "ruby_block[block_until_operational]" + def do_upgrade_plugin + do_install_plugin end - directory plugin_dir_path do - action :delete - recursive true - notifies :restart, "service[jenkins]" - notifies :create, "ruby_block[block_until_operational]" + def do_remove_plugin + file plugin_file_path do + action :delete + backup false + notifies :restart, 'service[jenkins]' + notifies :create, 'ruby_block[block_until_operational]' + end + + directory plugin_dir_path do + action :delete + recursive true + notifies :restart, 'service[jenkins]' + notifies :create, 'ruby_block[block_until_operational]' + end end -end diff --git a/resources/plugin.rb b/resources/plugin.rb index e30d1621f9..1bd7a98796 100644 --- a/resources/plugin.rb +++ b/resources/plugin.rb @@ -25,7 +25,7 @@ # If url isn't specified, a default URL based on the plugin name and version is returned def url(arg = nil) - if arg.nil? and @url.nil? + if arg.nil? && @url.nil? "#{node['jenkins']['mirror']}/plugins/#{name}/#{version}/#{name}.hpi" else set_or_return(:url, arg, :kind_of => String)