lib/kpm/base_installer.rb in kpm-0.1.7 vs lib/kpm/base_installer.rb in kpm-0.2.0

- old
+ new

@@ -1,18 +1,16 @@ require 'pathname' +require 'zip' module KPM class BaseInstaller LATEST_VERSION = 'LATEST' SHA1_FILENAME = 'sha1.yml' DEFAULT_BUNDLES_DIR = Pathname.new('/var').join('tmp').join('bundles').to_s - - - - def initialize(logger, nexus_config, nexus_ssl_verify) + def initialize(logger, nexus_config = nil, nexus_ssl_verify = nil) @logger = logger @nexus_config = nexus_config @nexus_ssl_verify = nexus_ssl_verify end @@ -59,21 +57,18 @@ verify_sha1, @nexus_config, @nexus_ssl_verify) end + def install_plugin(plugin_key, raw_kb_version=nil, specified_group_id=nil, specified_artifact_id=nil, specified_packaging=nil, specified_classifier=nil, specified_version=nil, bundles_dir=nil, specified_type=nil, force_download=false, verify_sha1=true, verify_jruby_jar=false) - - def install_plugin(plugin_key, raw_kb_version=nil, specified_group_id=nil, specified_artifact_id=nil, specified_packaging=nil, specified_classifier=nil, specified_version=nil, bundles_dir=nil, specified_type=nil, force_download=false, verify_sha1=true) - # plugin_key needs to exist if plugin_key.nil? - @logger.warn("Aborting installation: User needs to specify a pluginKey") + @logger.warn('Aborting installation: User needs to specify a pluginKey') return nil end - # Lookup artifact and perform validation against input looked_up_group_id, looked_up_artifact_id, looked_up_packaging, looked_up_classifier, looked_up_version, looked_up_type = KPM::PluginsDirectory.lookup(plugin_key, true, raw_kb_version) return if !validate_installation_arg(plugin_key, 'group_id', specified_group_id, looked_up_group_id) return if !validate_installation_arg(plugin_key, 'artifact_id', specified_artifact_id, looked_up_artifact_id) return if !validate_installation_arg(plugin_key, 'packaging', specified_packaging, looked_up_packaging) @@ -107,19 +102,23 @@ packaging = specified_packaging || looked_up_packaging || KPM::BaseArtifact::KILLBILL_JAVA_PLUGIN_PACKAGING classifier = specified_classifier || looked_up_classifier || KPM::BaseArtifact::KILLBILL_JAVA_PLUGIN_CLASSIFIER version = specified_version || looked_up_version || LATEST_VERSION destination = plugins_dir.join('java').join(artifact_id).join(version) else + + warn_if_jruby_jar_missing(bundles_dir) if verify_jruby_jar + group_id = specified_group_id || looked_up_group_id || KPM::BaseArtifact::KILLBILL_RUBY_PLUGIN_GROUP_ID packaging = specified_packaging || looked_up_packaging || KPM::BaseArtifact::KILLBILL_RUBY_PLUGIN_PACKAGING classifier = specified_classifier || looked_up_classifier || KPM::BaseArtifact::KILLBILL_RUBY_PLUGIN_CLASSIFIER version = specified_version || looked_up_version || LATEST_VERSION destination = plugins_dir.join('ruby') end sha1_file = "#{bundles_dir}/#{SHA1_FILENAME}" + plugins_manager = PluginsManager.new(plugins_dir, @logger) + _, plugin_name = plugins_manager.get_plugin_key_and_name(plugin_key) - # Before we do the install we verify that the entry we have in the plugin_identifiers.json matches our current request coordinate_map = {:group_id => group_id, :artifact_id => artifact_id, :packaging => packaging, :classifier => classifier} return if !validate_plugin_key(plugins_dir, plugin_key, coordinate_map) @@ -128,10 +127,11 @@ group_id, artifact_id, packaging, classifier, version, + plugin_name, destination, sha1_file, force_download, verify_sha1, @nexus_config, @@ -166,24 +166,23 @@ update_plugin_identifier(plugins_dir, plugin_key, type.to_s, nil, artifact_info) artifact_info end - def uninstall_plugin(plugin_key, plugin_version=nil, bundles_dir=nil) - + def uninstall_plugin(plugin_name_or_key, plugin_version=nil, bundles_dir=nil) bundles_dir = Pathname.new(bundles_dir || DEFAULT_BUNDLES_DIR).expand_path plugins_dir = bundles_dir.join('plugins') plugins_manager = PluginsManager.new(plugins_dir, @logger) - plugin_name = plugins_manager.get_plugin_name_from_key(plugin_key) + plugin_key, plugin_name = plugins_manager.get_plugin_key_and_name(plugin_name_or_key) if plugin_name.nil? - @logger.warn("Cannot uninstall plugin: Unknown plugin_key = #{plugin_key}"); + @logger.warn("Cannot uninstall plugin: Unknown plugin name or plugin key = #{plugin_name_or_key}"); return end - modified = plugins_manager.uninstall(plugin_name, plugin_version) + modified = plugins_manager.uninstall(plugin_name, plugin_version || :all) plugins_manager.remove_plugin_identifier_key(plugin_key) modified end def install_default_bundles(bundles_dir, specified_version=nil, kb_version=nil, force_download=false, verify_sha1=true) @@ -260,7 +259,38 @@ def mark_as_active(plugins_dir, artifact_info, artifact_id=nil) # Mark this bundle as active plugins_manager = PluginsManager.new(plugins_dir, @logger) plugins_manager.set_active(artifact_info[:bundle_dir]) end + + def warn_if_jruby_jar_missing(bundles_dir) + platform_dir = bundles_dir.join('platform') + jruby_jar = platform_dir.join('jruby.jar') + if !File.exists?(jruby_jar) + @logger.warn(" Missing installation for jruby.jar under #{platform_dir}. This is required for ruby plugin installation"); + else + version = extract_jruby_jar_version(jruby_jar) + if version + @logger.info(" Detected jruby.jar version #{version}") + else + @logger.warn(" Failed to detect jruby.jar version for #{jruby_jar}"); + end + end + end + + def extract_jruby_jar_version(jruby_jar) + selected_entries = Zip::File.open(jruby_jar) do |zip_file| + zip_file.select do |entry| + entry.name == 'META-INF/maven/org.kill-bill.billing/killbill-platform-osgi-bundles-jruby/pom.properties' + end + end + + if selected_entries && selected_entries.size == 1 + zip_entry = selected_entries[0] + content = zip_entry.get_input_stream.read + return content.split("\n").select { |e| e.start_with?("version")}[0].split("=")[1] + end + nil + end + end end