lib/kpm/installer.rb in kpm-0.0.15 vs lib/kpm/installer.rb in kpm-0.1.0
- old
+ new
@@ -1,133 +1,99 @@
require 'logger'
+require 'pathname'
require 'yaml'
module KPM
- class Installer
- LATEST_VERSION = 'LATEST'
- SHA1_FILENAME = 'sha1.yml'
+ class Installer < BaseInstaller
- def self.from_file(config_path, logger=nil)
- Installer.new(YAML::load_file(config_path), logger)
+ def self.from_file(config_path=nil, logger=nil)
+ if config_path.nil?
+ # Install Kill Bill, Kaui and the KPM plugin by default
+ config = {'killbill' => {'version' => 'LATEST', 'plugins' => {'ruby' => [{'name' => 'kpm'}]}}, 'kaui' => {'version' => 'LATEST'}}
+ else
+ config = YAML::load_file(config_path)
+ end
+ Installer.new(config, logger)
end
def initialize(raw_config, logger=nil)
-
- raise(ArgumentError, 'killbill or kaui section must be specified') if raw_config['killbill'].nil? and raw_config['kaui'].nil?
- @config = raw_config['killbill']
+ @config = raw_config['killbill']
@kaui_config = raw_config['kaui']
if logger.nil?
- @logger = Logger.new(STDOUT)
- @logger.level = Logger::INFO
- else
- @logger = logger
+ logger = Logger.new(STDOUT)
+ logger.level = Logger::INFO
end
- @nexus_config = !@config.nil? ? @config['nexus'] : @kaui_config['nexus']
- @nexus_ssl_verify = !@nexus_config.nil? ? @nexus_config['ssl_verify'] : true
+ nexus_config = !@config.nil? ? @config['nexus'] : (!@kaui_config.nil? ? @kaui_config['nexus'] : nil)
+ 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)
- @force_download = force_download
- @verify_sha1 = verify_sha1
-
+ help = nil
unless @config.nil?
- @bundles_dir = @config['plugins_dir']
- @sha1_file = "#{@bundles_dir}/#{SHA1_FILENAME}"
-
- install_killbill_server
- install_plugins
- install_default_bundles
+ 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'], force_download, verify_sha1)
+ install_plugins(force_download, verify_sha1)
+ unless @config['default_bundles'] == false
+ install_default_bundles(@config['plugins_dir'], @config['default_bundles_version'], @config['version'], force_download, verify_sha1)
+ end
end
+
unless @kaui_config.nil?
- install_kaui
+ if @kaui_config['webapp_path'].nil?
+ @logger.warn('No webapp_path specified for Kaui, aborting installation')
+ return
+ end
+
+ install_kaui(@kaui_config['group_id'], @kaui_config['artifact_id'], @kaui_config['packaging'], @kaui_config['classifier'], @kaui_config['version'], @kaui_config['webapp_path'], force_download, verify_sha1)
end
+
+ help
end
private
- def install_killbill_server
- group_id = @config['group_id'] || KPM::BaseArtifact::KILLBILL_GROUP_ID
- artifact_id = @config['artifact_id'] || KPM::BaseArtifact::KILLBILL_ARTIFACT_ID
- packaging = @config['packaging'] || KPM::BaseArtifact::KILLBILL_PACKAGING
- classifier = @config['classifier'] || KPM::BaseArtifact::KILLBILL_CLASSIFIER
- version = @config['version'] || LATEST_VERSION
- webapp_path = @config['webapp_path'] || KPM::root
+ def install_tomcat(dir=Dir.pwd)
+ # Download and unpack Tomcat
+ manager = KPM::TomcatManager.new(dir, @logger)
+ manager.download
- KPM::KillbillServerArtifact.pull(@logger, group_id, artifact_id, packaging, classifier, version, webapp_path, nil, @force_download, @verify_sha1, @nexus_config, @nexus_ssl_verify)
+ # Update main config
+ root_war_path = manager.setup
+ @config['webapp_path'] = root_war_path
+ @kaui_config['webapp_path'] = Pathname.new(File.dirname(root_war_path)).join('kaui.war').to_s
+
+ # Help message
+ manager.help
end
- def install_plugins
- install_java_plugins
- install_ruby_plugins
+ def install_plugins(force_download, verify_sha1)
+ install_java_plugins(force_download, verify_sha1)
+ install_ruby_plugins(force_download, verify_sha1)
end
- def install_java_plugins
+ def install_java_plugins(force_download, verify_sha1)
return if @config['plugins'].nil? or @config['plugins']['java'].nil?
infos = []
@config['plugins']['java'].each do |plugin|
- group_id = plugin['group_id'] || KPM::BaseArtifact::KILLBILL_JAVA_PLUGIN_GROUP_ID
- artifact_id = plugin['artifact_id'] || plugin['name']
- packaging = plugin['packaging'] || KPM::BaseArtifact::KILLBILL_JAVA_PLUGIN_PACKAGING
- classifier = plugin['classifier'] || KPM::BaseArtifact::KILLBILL_JAVA_PLUGIN_CLASSIFIER
- version = plugin['version'] || LATEST_VERSION
- destination = "#{@bundles_dir}/plugins/java/#{artifact_id}/#{version}"
-
- infos << KPM::KillbillPluginArtifact.pull(@logger, group_id, artifact_id, packaging, classifier, version, destination, @sha1_file, @force_download, @verify_sha1, @nexus_config, @nexus_ssl_verify)
+ infos << install_plugin(plugin['group_id'], plugin['artifact_id'] || plugin['name'], plugin['packaging'], plugin['classifier'], plugin['version'], @config['plugins_dir'], 'java', force_download, verify_sha1)
end
infos
end
- def install_ruby_plugins
+ def install_ruby_plugins(force_download, verify_sha1)
return if @config['plugins'].nil? or @config['plugins']['ruby'].nil?
infos = []
@config['plugins']['ruby'].each do |plugin|
- group_id = plugin['group_id'] || KPM::BaseArtifact::KILLBILL_RUBY_PLUGIN_GROUP_ID
- artifact_id = plugin['artifact_id'] || plugin['name']
- packaging = plugin['packaging'] || KPM::BaseArtifact::KILLBILL_RUBY_PLUGIN_PACKAGING
- classifier = plugin['classifier'] || KPM::BaseArtifact::KILLBILL_RUBY_PLUGIN_CLASSIFIER
- version = plugin['version'] || LATEST_VERSION
- destination = "#{@bundles_dir}/plugins/ruby"
-
- infos << KPM::KillbillPluginArtifact.pull(@logger, group_id, artifact_id, packaging, classifier, version, destination, @sha1_file, @force_download, @verify_sha1, @nexus_config, @nexus_ssl_verify)
+ infos << install_plugin(plugin['group_id'], plugin['artifact_id'] || plugin['name'], plugin['packaging'], plugin['classifier'], plugin['version'], @config['plugins_dir'], 'ruby', force_download, verify_sha1)
end
infos
- end
-
- def install_default_bundles
- return if @config['default_bundles'] == false
-
- group_id = 'org.kill-bill.billing'
- artifact_id = 'killbill-platform-osgi-bundles-defaultbundles'
- packaging = 'tar.gz'
- classifier = nil
- version = @config['default_bundles_version'] || LATEST_VERSION
- destination = "#{@config['plugins_dir']}/platform"
-
- info = KPM::BaseArtifact.pull(@logger, group_id, artifact_id, packaging, classifier, version, destination, @sha1_file, @force_download, @verify_sha1, @nexus_config, @nexus_ssl_verify)
-
- # The special JRuby bundle needs to be called jruby.jar
- # TODO .first - code smell
- if !info[:skipped]
- File.rename Dir.glob("#{destination}/killbill-platform-osgi-bundles-jruby-*.jar").first, "#{destination}/jruby.jar"
- end
-
- info
- end
-
- def install_kaui
- group_id = @kaui_config['group_id'] || KPM::BaseArtifact::KAUI_GROUP_ID
- artifact_id = @kaui_config['artifact_id'] || KPM::BaseArtifact::KAUI_ARTIFACT_ID
- packaging = @kaui_config['packaging'] || KPM::BaseArtifact::KAUI_PACKAGING
- classifier = @kaui_config['classifier'] || KPM::BaseArtifact::KAUI_CLASSIFIER
- version = @kaui_config['version'] || LATEST_VERSION
- webapp_path = @kaui_config['webapp_path'] || KPM::root
-
- KPM::KauiArtifact.pull(@logger, group_id, artifact_id, packaging, classifier, version, webapp_path, nil, @force_download, @verify_sha1, @nexus_config, @nexus_ssl_verify)
end
end
end