lib/kpm/installer.rb in kpm-0.7.2 vs lib/kpm/installer.rb in kpm-0.8.0
- old
+ new
@@ -1,90 +1,100 @@
+# frozen_string_literal: true
+
require 'logger'
require 'pathname'
require 'yaml'
module KPM
class Installer < BaseInstaller
-
- def self.from_file(config_path=nil, logger=nil)
- if config_path.nil?
- # Install Kill Bill, Kaui and the KPM plugin by default
- config = build_default_config
- else
- config = YAML::load_file(config_path)
- end
+ def self.from_file(config_path = nil, logger = nil)
+ config = if config_path.nil?
+ # Install Kill Bill, Kaui and the KPM plugin by default
+ build_default_config
+ else
+ YAML.load_file(config_path)
+ end
Installer.new(config, logger)
end
- def self.build_default_config(all_kb_versions=nil)
+ def self.build_default_config(all_kb_versions = nil)
latest_stable_version = get_kb_latest_stable_version(all_kb_versions)
{
- 'killbill' => {
- 'version' => latest_stable_version.to_s,
- 'plugins' => {
- 'ruby' => [
- {'name' => 'kpm'}
- ]
- }
- },
- 'kaui' => {
- # Note: we assume no unstable version of Kaui is published today
- 'version' => 'LATEST'
- }
+ 'killbill' => {
+ 'version' => latest_stable_version.to_s
+ },
+ 'kaui' => {
+ # Note: we assume no unstable version of Kaui is published today
+ 'version' => 'LATEST'
+ }
}
end
- def self.get_kb_latest_stable_version(all_kb_versions=nil)
+ def self.get_kb_latest_stable_version(all_kb_versions = nil)
all_kb_versions ||= KillbillServerArtifact.versions(KillbillServerArtifact::KILLBILL_ARTIFACT_ID,
KillbillServerArtifact::KILLBILL_PACKAGING,
KillbillServerArtifact::KILLBILL_CLASSIFIER,
nil,
true).to_a
latest_stable_version = Gem::Version.new('0.0.0')
all_kb_versions.each do |kb_version|
- version = Gem::Version.new(kb_version) rescue nil
+ version = begin
+ Gem::Version.new(kb_version)
+ rescue StandardError
+ nil
+ end
next if version.nil?
- major, minor, patch, pre = version.segments
+ _major, minor, _patch, pre = version.segments
next if !pre.nil? || minor.nil? || minor.to_i.odd?
latest_stable_version = version if version > latest_stable_version
end
latest_stable_version.to_s
end
- def initialize(raw_config, logger=nil)
+ def initialize(raw_config, logger = nil)
@config = raw_config['killbill']
@kaui_config = raw_config['kaui']
@config['version'] = KPM::Installer.get_kb_latest_stable_version if !@config.nil? && (@config['version'].nil? || @config['version'] == 'LATEST')
if logger.nil?
logger = Logger.new(STDOUT)
logger.level = Logger::INFO
end
- nexus_config = !@config.nil? ? @config['nexus'] : (!@kaui_config.nil? ? @kaui_config['nexus'] : nil)
+ nexus_config = if !@config.nil?
+ @config['nexus']
+ elsif !@kaui_config.nil?
+ @kaui_config['nexus']
+ else
+ nil
+ end
nexus_ssl_verify = !nexus_config.nil? ? nexus_config['ssl_verify'] : true
super(logger, nexus_config, nexus_ssl_verify)
end
- def install(force_download=false, verify_sha1=true)
- bundles_dir = !@config.nil? ? @config['plugins_dir'] : (!@kaui_config.nil? ? @kaui_config['plugins_dir'] : nil)
+ def install(force_download = false, verify_sha1 = true)
+ bundles_dir = if !@config.nil?
+ @config['plugins_dir']
+ elsif !@kaui_config.nil?
+ @kaui_config['plugins_dir']
+ else
+ nil
+ end
bundles_dir ||= DEFAULT_BUNDLES_DIR
help = nil
unless @config.nil?
help = install_tomcat if @config['webapp_path'].nil?
install_killbill_server(@config['group_id'], @config['artifact_id'], @config['packaging'], @config['classifier'], @config['version'], @config['webapp_path'], bundles_dir, force_download, verify_sha1)
install_plugins(bundles_dir, @config['version'], force_download, verify_sha1)
- unless @config['default_bundles'] == false
- install_default_bundles(bundles_dir, @config['default_bundles_version'], @config['version'], force_download, verify_sha1)
- end
+ install_default_bundles(bundles_dir, @config['default_bundles_version'], @config['version'], force_download, verify_sha1) unless @config['default_bundles'] == false
clean_up_descriptors(bundles_dir)
end
unless @kaui_config.nil?
if @kaui_config['webapp_path'].nil?
@@ -93,27 +103,25 @@
end
install_kaui(@kaui_config['group_id'], @kaui_config['artifact_id'], @kaui_config['packaging'], @kaui_config['classifier'], @kaui_config['version'], @kaui_config['webapp_path'], bundles_dir, force_download, verify_sha1)
end
- @trace_logger.add('help',help)
+ @trace_logger.add('help', nil, help)
@trace_logger.to_json
end
private
- def install_tomcat(dir=Dir.pwd)
+ def install_tomcat(dir = Dir.pwd)
# Download and unpack Tomcat
manager = KPM::TomcatManager.new(dir, @logger)
manager.download
# Update main config
root_war_path = manager.setup
@config['webapp_path'] = root_war_path
- unless @kaui_config.nil?
- @kaui_config['webapp_path'] = Pathname.new(File.dirname(root_war_path)).join('kaui.war').to_s
- end
+ @kaui_config['webapp_path'] = Pathname.new(File.dirname(root_war_path)).join('kaui.war').to_s unless @kaui_config.nil?
# Help message
manager.help
end
@@ -121,28 +129,28 @@
install_java_plugins(bundles_dir, raw_kb_version, force_download, verify_sha1)
install_ruby_plugins(bundles_dir, raw_kb_version, force_download, verify_sha1)
end
def install_java_plugins(bundles_dir, raw_kb_version, force_download, verify_sha1)
- return if @config['plugins'].nil? or @config['plugins']['java'].nil?
+ return if @config['plugins'].nil? || @config['plugins']['java'].nil?
infos = []
@config['plugins']['java'].each do |plugin|
infos << install_plugin(plugin['name'], raw_kb_version, plugin['group_id'], plugin['artifact_id'], plugin['packaging'], plugin['classifier'], plugin['version'], bundles_dir, 'java', force_download, verify_sha1, false)
end
infos
end
def install_ruby_plugins(bundles_dir, raw_kb_version, force_download, verify_sha1)
- return if @config['plugins'].nil? or @config['plugins']['ruby'].nil?
+ return if @config['plugins'].nil? || @config['plugins']['ruby'].nil?
- verify_jruby_jar=true
+ verify_jruby_jar = true
infos = []
@config['plugins']['ruby'].each do |plugin|
infos << install_plugin(plugin['name'], raw_kb_version, plugin['group_id'], plugin['artifact_id'], plugin['packaging'], plugin['classifier'], plugin['version'], bundles_dir, 'ruby', force_download, verify_sha1, verify_jruby_jar)
- verify_jruby_jar=false
+ verify_jruby_jar = false
end
infos
end
@@ -159,15 +167,15 @@
plugins_manager = KPM::PluginsManager.new(plugins_installation_path, @logger)
plugin_identifiers = plugins_manager.read_plugin_identifiers
removed_identifiers = []
plugin_identifiers.each do |plugin_key, plugin|
- if !installed_plugins.has_key?(plugin['plugin_name'])
- _, plugin_entry = plugins_manager.get_identifier_key_and_entry(plugin_key)
- plugins_manager.remove_plugin_identifier_key(plugin_key)
- removed_identifiers << plugin_entry
- end
+ next if installed_plugins.key?(plugin['plugin_name'])
+
+ _, plugin_entry = plugins_manager.get_identifier_key_and_entry(plugin_key)
+ plugins_manager.remove_plugin_identifier_key(plugin_key)
+ removed_identifiers << plugin_entry
end
removed_identifiers
end
@@ -180,8 +188,7 @@
classifier: removed['classifier'],
version: removed['version'])
sha1checker.remove_entry!(coordinates)
end
end
-
end
end