kpm 0.7.2 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +2 -0
- data/.rubocop.yml +138 -0
- data/Gemfile +2 -0
- data/README.adoc +144 -107
- data/Rakefile +2 -1
- data/bin/kpm +4 -2
- data/kpm.gemspec +11 -8
- data/lib/kpm.rb +3 -0
- data/lib/kpm/account.rb +268 -338
- data/lib/kpm/base_artifact.rb +33 -39
- data/lib/kpm/base_installer.rb +69 -83
- data/lib/kpm/blob.rb +29 -0
- data/lib/kpm/cli.rb +3 -1
- data/lib/kpm/coordinates.rb +10 -12
- data/lib/kpm/database.rb +94 -113
- data/lib/kpm/diagnostic_file.rb +126 -147
- data/lib/kpm/formatter.rb +76 -48
- data/lib/kpm/inspector.rb +24 -34
- data/lib/kpm/installer.rb +53 -46
- data/lib/kpm/kaui_artifact.rb +4 -3
- data/lib/kpm/killbill_plugin_artifact.rb +10 -7
- data/lib/kpm/killbill_server_artifact.rb +13 -12
- data/lib/kpm/migrations.rb +26 -11
- data/lib/kpm/nexus_helper/actions.rb +52 -9
- data/lib/kpm/nexus_helper/cloudsmith_api_calls.rb +83 -0
- data/lib/kpm/nexus_helper/github_api_calls.rb +70 -0
- data/lib/kpm/nexus_helper/nexus_api_calls_v2.rb +130 -108
- data/lib/kpm/nexus_helper/nexus_facade.rb +5 -3
- data/lib/kpm/plugins_directory.rb +9 -8
- data/lib/kpm/plugins_directory.yml +14 -173
- data/lib/kpm/plugins_manager.rb +29 -24
- data/lib/kpm/sha1_checker.rb +31 -18
- data/lib/kpm/system.rb +104 -135
- data/lib/kpm/system_helpers/cpu_information.rb +56 -55
- data/lib/kpm/system_helpers/disk_space_information.rb +60 -63
- data/lib/kpm/system_helpers/entropy_available.rb +37 -39
- data/lib/kpm/system_helpers/memory_information.rb +52 -51
- data/lib/kpm/system_helpers/os_information.rb +45 -47
- data/lib/kpm/system_helpers/system_proxy.rb +10 -10
- data/lib/kpm/tasks.rb +381 -438
- data/lib/kpm/tenant_config.rb +68 -83
- data/lib/kpm/tomcat_manager.rb +10 -8
- data/lib/kpm/trace_logger.rb +18 -16
- data/lib/kpm/uninstaller.rb +81 -14
- data/lib/kpm/utils.rb +13 -14
- data/lib/kpm/version.rb +3 -1
- data/packaging/Gemfile +2 -0
- data/pom.xml +211 -40
- data/spec/kpm/remote/base_artifact_spec.rb +20 -20
- data/spec/kpm/remote/base_installer_spec.rb +35 -34
- data/spec/kpm/remote/cloudsmith_api_calls_spec.rb +40 -0
- data/spec/kpm/remote/github_api_calls_spec.rb +40 -0
- data/spec/kpm/remote/installer_spec.rb +80 -79
- data/spec/kpm/remote/kaui_artifact_spec.rb +7 -6
- data/spec/kpm/remote/killbill_plugin_artifact_spec.rb +25 -30
- data/spec/kpm/remote/killbill_server_artifact_spec.rb +17 -16
- data/spec/kpm/remote/migrations_spec.rb +12 -11
- data/spec/kpm/remote/nexus_facade_spec.rb +32 -28
- data/spec/kpm/remote/tenant_config_spec.rb +30 -29
- data/spec/kpm/remote/tomcat_manager_spec.rb +4 -3
- data/spec/kpm/unit/actions_spec.rb +52 -0
- data/spec/kpm/unit/base_artifact_spec.rb +19 -18
- data/spec/kpm/unit/cpu_information_spec.rb +67 -0
- data/spec/kpm/unit/disk_space_information_spec.rb +47 -0
- data/spec/kpm/unit/entropy_information_spec.rb +36 -0
- data/spec/kpm/unit/formatter_spec.rb +163 -0
- data/spec/kpm/unit/inspector_spec.rb +34 -42
- data/spec/kpm/unit/installer_spec.rb +7 -6
- data/spec/kpm/unit/memory_information_spec.rb +102 -0
- data/spec/kpm/unit/os_information_spec.rb +38 -0
- data/spec/kpm/unit/plugins_directory_spec.rb +38 -22
- data/spec/kpm/unit/plugins_manager_spec.rb +62 -66
- data/spec/kpm/unit/sha1_checker_spec.rb +107 -60
- data/spec/kpm/unit/uninstaller_spec.rb +118 -72
- data/spec/kpm/unit_mysql/account_spec.rb +127 -142
- data/spec/spec_helper.rb +20 -18
- data/tasks/package.rake +18 -18
- metadata +42 -22
    
        data/lib/kpm/sha1_checker.rb
    CHANGED
    
    | @@ -1,20 +1,21 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 1 3 | 
             
            require 'logger'
         | 
| 2 4 | 
             
            require 'yaml'
         | 
| 3 5 | 
             
            require 'pathname'
         | 
| 4 6 |  | 
| 5 7 | 
             
            module KPM
         | 
| 6 8 | 
             
              class Sha1Checker
         | 
| 7 | 
            -
             | 
| 8 | 
            -
                def self.from_file(sha1_file, logger=nil)
         | 
| 9 | 
            +
                def self.from_file(sha1_file, logger = nil)
         | 
| 9 10 | 
             
                  Sha1Checker.new(sha1_file, logger)
         | 
| 10 11 | 
             
                end
         | 
| 11 12 |  | 
| 12 | 
            -
                def initialize(sha1_file, logger=nil)
         | 
| 13 | 
            +
                def initialize(sha1_file, logger = nil)
         | 
| 13 14 | 
             
                  @sha1_file = sha1_file
         | 
| 14 15 | 
             
                  init!
         | 
| 15 16 |  | 
| 16 17 | 
             
                  if logger.nil?
         | 
| 17 | 
            -
                    @logger | 
| 18 | 
            +
                    @logger = Logger.new(STDOUT)
         | 
| 18 19 | 
             
                    @logger.level = Logger::INFO
         | 
| 19 20 | 
             
                  else
         | 
| 20 21 | 
             
                    @logger = logger
         | 
| @@ -22,20 +23,21 @@ module KPM | |
| 22 23 | 
             
                end
         | 
| 23 24 |  | 
| 24 25 | 
             
                def sha1(coordinates)
         | 
| 25 | 
            -
                   | 
| 26 | 
            +
                  sha1_cache[coordinates]
         | 
| 26 27 | 
             
                end
         | 
| 27 28 |  | 
| 28 | 
            -
                def all_sha1 | 
| 29 | 
            -
                   | 
| 29 | 
            +
                def all_sha1
         | 
| 30 | 
            +
                  sha1_cache
         | 
| 30 31 | 
             
                end
         | 
| 31 32 |  | 
| 32 33 | 
             
                def add_or_modify_entry!(coordinates, remote_sha1)
         | 
| 33 | 
            -
                   | 
| 34 | 
            +
                  sha1_cache[coordinates] = remote_sha1
         | 
| 34 35 | 
             
                  save!
         | 
| 35 36 | 
             
                end
         | 
| 36 37 |  | 
| 37 38 | 
             
                def remove_entry!(coordinates)
         | 
| 38 | 
            -
                   | 
| 39 | 
            +
                  sha1_cache.delete(coordinates)
         | 
| 40 | 
            +
                  nexus_cache.delete(coordinates)
         | 
| 39 41 | 
             
                  save!
         | 
| 40 42 | 
             
                end
         | 
| 41 43 |  | 
| @@ -43,10 +45,20 @@ module KPM | |
| 43 45 | 
             
                  nexus_cache[coordinates]
         | 
| 44 46 | 
             
                end
         | 
| 45 47 |  | 
| 46 | 
            -
                def cache_artifact_info( | 
| 48 | 
            +
                def cache_artifact_info(coordinates_with_maybe_latest, artifact_info)
         | 
| 49 | 
            +
                  return if artifact_info.nil?
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                  if coordinates_with_maybe_latest.end_with?('LATEST')
         | 
| 52 | 
            +
                    return nil if artifact_info[:version].nil?
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                    coordinates = coordinates_with_maybe_latest.gsub(/LATEST$/, artifact_info[:version])
         | 
| 55 | 
            +
                  else
         | 
| 56 | 
            +
                    coordinates = coordinates_with_maybe_latest
         | 
| 57 | 
            +
                  end
         | 
| 58 | 
            +
             | 
| 47 59 | 
             
                  # See BaseArtifact#artifact_info
         | 
| 48 | 
            -
                  nexus_keys = [ | 
| 49 | 
            -
                  nexus_cache[coordinates] = artifact_info | 
| 60 | 
            +
                  nexus_keys = %i[sha1 version repository_path is_tgz]
         | 
| 61 | 
            +
                  nexus_cache[coordinates] = artifact_info.select { |key, _| nexus_keys.include? key }
         | 
| 50 62 | 
             
                  save!
         | 
| 51 63 | 
             
                end
         | 
| 52 64 |  | 
| @@ -61,6 +73,10 @@ module KPM | |
| 61 73 |  | 
| 62 74 | 
             
                private
         | 
| 63 75 |  | 
| 76 | 
            +
                def sha1_cache
         | 
| 77 | 
            +
                  @sha1_config['sha1'] ||= {}
         | 
| 78 | 
            +
                end
         | 
| 79 | 
            +
             | 
| 64 80 | 
             
                def nexus_cache
         | 
| 65 81 | 
             
                  @sha1_config['nexus'] ||= {}
         | 
| 66 82 | 
             
                end
         | 
| @@ -81,7 +97,7 @@ module KPM | |
| 81 97 | 
             
                end
         | 
| 82 98 |  | 
| 83 99 | 
             
                def init!
         | 
| 84 | 
            -
                   | 
| 100 | 
            +
                  unless File.exist?(@sha1_file)
         | 
| 85 101 | 
             
                    create_sha1_directory_if_missing
         | 
| 86 102 | 
             
                    init_config = {}
         | 
| 87 103 | 
             
                    init_config['sha1'] = {}
         | 
| @@ -94,14 +110,11 @@ module KPM | |
| 94 110 |  | 
| 95 111 | 
             
                def create_sha1_directory_if_missing
         | 
| 96 112 | 
             
                  sha1_dir = Pathname(@sha1_file).dirname
         | 
| 97 | 
            -
                   | 
| 98 | 
            -
                    FileUtils.mkdir_p(sha1_dir)
         | 
| 99 | 
            -
                  end
         | 
| 113 | 
            +
                  FileUtils.mkdir_p(sha1_dir) unless File.directory?(sha1_dir)
         | 
| 100 114 | 
             
                end
         | 
| 101 115 |  | 
| 102 116 | 
             
                def reload!
         | 
| 103 | 
            -
                  @sha1_config = YAML | 
| 117 | 
            +
                  @sha1_config = YAML.load_file(@sha1_file)
         | 
| 104 118 | 
             
                end
         | 
| 105 | 
            -
             | 
| 106 119 | 
             
              end
         | 
| 107 120 | 
             
            end
         | 
    
        data/lib/kpm/system.rb
    CHANGED
    
    | @@ -1,21 +1,23 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 1 3 | 
             
            require 'yaml'
         | 
| 2 4 | 
             
            require_relative 'system_helpers/system_proxy'
         | 
| 3 5 |  | 
| 4 6 | 
             
            module KPM
         | 
| 5 7 | 
             
              class System
         | 
| 6 | 
            -
             | 
| 7 8 | 
             
                MAX_VALUE_COLUMN_WIDTH = 60
         | 
| 8 9 | 
             
                DEFAULT_BUNDLE_DIR = Dir['/var' + File::SEPARATOR + 'lib' + File::SEPARATOR + 'killbill' + File::SEPARATOR + 'bundles'][0] || Dir['/var' + File::SEPARATOR + 'tmp' + File::SEPARATOR + 'bundles'][0]
         | 
| 9 10 | 
             
                DEFAULT_KAUI_SEARCH_BASE_DIR = '**' + File::SEPARATOR + 'kaui'
         | 
| 10 11 | 
             
                DEFAULT_KILLBILL_SEARCH_BASE_DIR = '**' + File::SEPARATOR + 'ROOT'
         | 
| 11 12 |  | 
| 12 | 
            -
                def initialize
         | 
| 13 | 
            +
                def initialize(logger)
         | 
| 14 | 
            +
                  @logger = logger
         | 
| 13 15 | 
             
                  @formatter = KPM::Formatter.new
         | 
| 14 16 | 
             
                end
         | 
| 15 17 |  | 
| 16 18 | 
             
                def information(bundles_dir = nil, output_as_json = false, config_file = nil, kaui_web_path = nil, killbill_web_path = nil)
         | 
| 17 | 
            -
                   | 
| 18 | 
            -
                  killbill_information = show_killbill_information(kaui_web_path,killbill_web_path,output_as_json)
         | 
| 19 | 
            +
                  self.config = config_file
         | 
| 20 | 
            +
                  killbill_information = show_killbill_information(kaui_web_path, killbill_web_path, output_as_json)
         | 
| 19 21 |  | 
| 20 22 | 
             
                  java_version = `java -version 2>&1`.split("\n")[0].split('"')[1]
         | 
| 21 23 |  | 
| @@ -26,14 +28,14 @@ module KPM | |
| 26 28 | 
             
                  disk_space_information = show_disk_space_information(output_as_json)
         | 
| 27 29 | 
             
                  entropy_available = show_entropy_available(output_as_json)
         | 
| 28 30 |  | 
| 29 | 
            -
                   | 
| 30 | 
            -
                    command =  | 
| 31 | 
            -
                    java_system_information = show_java_system_information(command,output_as_json)
         | 
| 31 | 
            +
                  unless java_version.nil?
         | 
| 32 | 
            +
                    command = java_command
         | 
| 33 | 
            +
                    java_system_information = show_java_system_information(command, output_as_json)
         | 
| 32 34 | 
             
                  end
         | 
| 33 35 |  | 
| 34 | 
            -
                  plugin_information = show_plugin_information( | 
| 36 | 
            +
                  plugin_information = show_plugin_information(plugin_path || bundles_dir || DEFAULT_BUNDLE_DIR, output_as_json)
         | 
| 35 37 |  | 
| 36 | 
            -
                  json_data =  | 
| 38 | 
            +
                  json_data = {}
         | 
| 37 39 | 
             
                  json_data[:killbill_information] = killbill_information
         | 
| 38 40 | 
             
                  json_data[:environment_information] = environment_information
         | 
| 39 41 | 
             
                  json_data[:os_information] = os_information
         | 
| @@ -48,133 +50,117 @@ module KPM | |
| 48 50 | 
             
                end
         | 
| 49 51 |  | 
| 50 52 | 
             
                def show_killbill_information(kaui_web_path, killbill_web_path, output_as_json)
         | 
| 51 | 
            -
             | 
| 52 53 | 
             
                  kpm_version = KPM::VERSION
         | 
| 53 | 
            -
                  kaui_version =  | 
| 54 | 
            -
                  killbill_version =  | 
| 55 | 
            -
                  kaui_standalone_version =  | 
| 54 | 
            +
                  kaui_version = kaui_version(kaui_web_path || kaui_web_path)
         | 
| 55 | 
            +
                  killbill_version = killbill_version(killbill_web_path || killbill_web_path)
         | 
| 56 | 
            +
                  kaui_standalone_version = kaui_standalone_version(kaui_web_path || kaui_web_path)
         | 
| 56 57 |  | 
| 57 | 
            -
                  environment = Hash[: | 
| 58 | 
            -
                                     : | 
| 59 | 
            -
                                     : | 
| 60 | 
            -
                                     : | 
| 58 | 
            +
                  environment = Hash[kpm: { system: 'KPM', version: kpm_version },
         | 
| 59 | 
            +
                                     kaui: { system: 'Kaui', version: kaui_version.nil? ? 'not found' : kaui_version },
         | 
| 60 | 
            +
                                     kaui_standalone: { system: 'Kaui standalone', version: kaui_standalone_version.nil? ? 'not found' : kaui_standalone_version },
         | 
| 61 | 
            +
                                     killbill: { system: 'Killbill', version: killbill_version.nil? ? 'not found' : killbill_version }]
         | 
| 61 62 |  | 
| 62 | 
            -
                  labels = [{: | 
| 63 | 
            -
                            {: | 
| 63 | 
            +
                  labels = [{ label: :system },
         | 
| 64 | 
            +
                            { label: :version }]
         | 
| 64 65 |  | 
| 65 | 
            -
                   | 
| 66 | 
            -
                    @formatter.format(environment,labels)
         | 
| 67 | 
            -
                  end
         | 
| 66 | 
            +
                  @formatter.format(environment, labels) unless output_as_json
         | 
| 68 67 |  | 
| 69 68 | 
             
                  environment
         | 
| 70 69 | 
             
                end
         | 
| 71 70 |  | 
| 72 71 | 
             
                def show_environment_information(java_version, output_as_json)
         | 
| 72 | 
            +
                  environment = Hash[ruby: { environment: 'Ruby', version: RUBY_VERSION },
         | 
| 73 | 
            +
                                     java: { environment: 'Java', version: java_version.nil? ? 'no version found' : java_version }]
         | 
| 73 74 |  | 
| 74 | 
            -
                   | 
| 75 | 
            -
             | 
| 76 | 
            -
             | 
| 77 | 
            -
                  labels = [{:label => :environment},
         | 
| 78 | 
            -
                            {:label => :version}]
         | 
| 75 | 
            +
                  labels = [{ label: :environment },
         | 
| 76 | 
            +
                            { label: :version }]
         | 
| 79 77 |  | 
| 80 | 
            -
                   | 
| 81 | 
            -
                    @formatter.format(environment,labels)
         | 
| 82 | 
            -
                  end
         | 
| 78 | 
            +
                  @formatter.format(environment, labels) unless output_as_json
         | 
| 83 79 |  | 
| 84 80 | 
             
                  environment
         | 
| 85 81 | 
             
                end
         | 
| 86 82 |  | 
| 87 83 | 
             
                def show_cpu_information(output_as_json)
         | 
| 88 | 
            -
                   | 
| 89 | 
            -
                   | 
| 84 | 
            +
                  cpu_information = KPM::SystemProxy::CpuInformation.new
         | 
| 85 | 
            +
                  cpu_info = cpu_information.cpu_info
         | 
| 86 | 
            +
                  labels = cpu_information.labels
         | 
| 90 87 |  | 
| 91 | 
            -
                  unless output_as_json
         | 
| 92 | 
            -
                    @formatter.format(cpu_info,labels)
         | 
| 93 | 
            -
                  end
         | 
| 88 | 
            +
                  @formatter.format(cpu_info, labels) unless output_as_json
         | 
| 94 89 |  | 
| 95 90 | 
             
                  cpu_info
         | 
| 96 91 | 
             
                end
         | 
| 97 92 |  | 
| 98 93 | 
             
                def show_memory_information(output_as_json)
         | 
| 99 | 
            -
                   | 
| 100 | 
            -
                   | 
| 94 | 
            +
                  memory_information = KPM::SystemProxy::MemoryInformation.new
         | 
| 95 | 
            +
                  memory_info = memory_information.memory_info
         | 
| 96 | 
            +
                  labels = memory_information.labels
         | 
| 101 97 |  | 
| 102 | 
            -
                  unless output_as_json
         | 
| 103 | 
            -
                    @formatter.format(memory_info,labels)
         | 
| 104 | 
            -
                  end
         | 
| 98 | 
            +
                  @formatter.format(memory_info, labels) unless output_as_json
         | 
| 105 99 |  | 
| 106 100 | 
             
                  memory_info
         | 
| 107 101 | 
             
                end
         | 
| 108 102 |  | 
| 109 103 | 
             
                def show_disk_space_information(output_as_json)
         | 
| 110 | 
            -
                   | 
| 111 | 
            -
                   | 
| 104 | 
            +
                  disk_space_information = KPM::SystemProxy::DiskSpaceInformation.new
         | 
| 105 | 
            +
                  disk_space_info = disk_space_information.disk_space_info
         | 
| 106 | 
            +
                  labels = disk_space_information.labels
         | 
| 112 107 |  | 
| 113 | 
            -
                  unless output_as_json
         | 
| 114 | 
            -
                    @formatter.format(disk_space_info,labels)
         | 
| 115 | 
            -
                  end
         | 
| 108 | 
            +
                  @formatter.format(disk_space_info, labels) unless output_as_json
         | 
| 116 109 |  | 
| 117 110 | 
             
                  disk_space_info
         | 
| 118 111 | 
             
                end
         | 
| 119 112 |  | 
| 120 113 | 
             
                def show_entropy_available(output_as_json)
         | 
| 121 | 
            -
                   | 
| 122 | 
            -
                   | 
| 114 | 
            +
                  entropy_information = KPM::SystemProxy::EntropyAvailable.new
         | 
| 115 | 
            +
                  entropy_available = entropy_information.entropy_available
         | 
| 116 | 
            +
                  labels = entropy_information.labels
         | 
| 123 117 |  | 
| 124 | 
            -
                  unless output_as_json
         | 
| 125 | 
            -
                    @formatter.format(entropy_available,labels)
         | 
| 126 | 
            -
                  end
         | 
| 118 | 
            +
                  @formatter.format(entropy_available, labels) unless output_as_json
         | 
| 127 119 |  | 
| 128 120 | 
             
                  entropy_available
         | 
| 129 121 | 
             
                end
         | 
| 130 122 |  | 
| 131 123 | 
             
                def show_os_information(output_as_json)
         | 
| 132 | 
            -
                  os_information = KPM::SystemProxy::OsInformation. | 
| 133 | 
            -
                   | 
| 124 | 
            +
                  os_information = KPM::SystemProxy::OsInformation.new
         | 
| 125 | 
            +
                  os_info = os_information.os_info
         | 
| 126 | 
            +
                  labels = os_information.labels
         | 
| 134 127 |  | 
| 135 | 
            -
                  unless output_as_json
         | 
| 136 | 
            -
                    @formatter.format(os_information,labels)
         | 
| 137 | 
            -
                  end
         | 
| 128 | 
            +
                  @formatter.format(os_info, labels) unless output_as_json
         | 
| 138 129 |  | 
| 139 | 
            -
                   | 
| 130 | 
            +
                  os_info
         | 
| 140 131 | 
             
                end
         | 
| 141 132 |  | 
| 142 133 | 
             
                def show_java_system_information(command, output_as_json)
         | 
| 143 | 
            -
                  java_system =  | 
| 144 | 
            -
                  property_count = 0 | 
| 134 | 
            +
                  java_system = {}
         | 
| 135 | 
            +
                  property_count = 0
         | 
| 145 136 | 
             
                  last_key = ''
         | 
| 146 137 |  | 
| 147 138 | 
             
                  `#{command}`.split("\n").each do |prop|
         | 
| 148 | 
            -
             | 
| 149 | 
            -
                    if prop.to_s.strip.empty?
         | 
| 150 | 
            -
                      break;
         | 
| 151 | 
            -
                    end
         | 
| 139 | 
            +
                    break if prop.to_s.strip.empty?
         | 
| 152 140 |  | 
| 153 141 | 
             
                    if property_count > 0
         | 
| 154 142 | 
             
                      props = prop.split('=')
         | 
| 155 143 |  | 
| 156 | 
            -
                      if ( | 
| 144 | 
            +
                      if !(props[1].nil? && props[1].to_s.strip.size > MAX_VALUE_COLUMN_WIDTH) && output_as_json == false
         | 
| 157 145 |  | 
| 158 146 | 
             
                        chunks = ".{1,#{MAX_VALUE_COLUMN_WIDTH}}"
         | 
| 159 147 | 
             
                        props[1].to_s.scan(/#{chunks}/).each_with_index do |p, index|
         | 
| 160 | 
            -
             | 
| 161 | 
            -
                          java_system[property_count] = {:java_property => index.equal?(0) ? props[0] : '', :value => p}
         | 
| 148 | 
            +
                          java_system[property_count] = { java_property: index.equal?(0) ? props[0] : '', value: p }
         | 
| 162 149 | 
             
                          property_count += 1
         | 
| 163 | 
            -
             | 
| 164 150 | 
             
                        end
         | 
| 165 151 | 
             
                      elsif output_as_json
         | 
| 166 152 | 
             
                        key = (props[1].nil? ? last_key : props[0]).to_s.strip
         | 
| 167 153 | 
             
                        value = props[1].nil? ? props[0] : props[1]
         | 
| 168 154 |  | 
| 169 | 
            -
                        if java_system. | 
| 155 | 
            +
                        if java_system.key?(key)
         | 
| 170 156 | 
             
                          java_system[key][:value] = java_system[key][:value].to_s.concat(' ').concat(value)
         | 
| 171 157 | 
             
                        else
         | 
| 172 | 
            -
                          java_system[key] = {: | 
| 158 | 
            +
                          java_system[key] = { java_property: key, value: value }
         | 
| 173 159 | 
             
                        end
         | 
| 174 160 |  | 
| 175 161 | 
             
                      else
         | 
| 176 162 |  | 
| 177 | 
            -
                        java_system[property_count] = {: | 
| 163 | 
            +
                        java_system[property_count] = { java_property: props[1].nil? ? '' : props[0], value: props[1].nil? ? props[0] : props[1] }
         | 
| 178 164 |  | 
| 179 165 | 
             
                      end
         | 
| 180 166 |  | 
| @@ -182,22 +168,16 @@ module KPM | |
| 182 168 | 
             
                    end
         | 
| 183 169 |  | 
| 184 170 | 
             
                    property_count += 1
         | 
| 185 | 
            -
             | 
| 186 171 | 
             
                  end
         | 
| 187 | 
            -
                  labels = [{: | 
| 188 | 
            -
             | 
| 172 | 
            +
                  labels = [{ label: :java_property },
         | 
| 173 | 
            +
                            { label: :value }]
         | 
| 189 174 |  | 
| 190 | 
            -
             | 
| 191 | 
            -
                  if not output_as_json
         | 
| 192 | 
            -
                    @formatter.format(java_system,labels)
         | 
| 193 | 
            -
                  end
         | 
| 175 | 
            +
                  @formatter.format(java_system, labels) unless output_as_json
         | 
| 194 176 |  | 
| 195 177 | 
             
                  java_system
         | 
| 196 | 
            -
             | 
| 197 178 | 
             
                end
         | 
| 198 179 |  | 
| 199 180 | 
             
                def show_plugin_information(bundles_dir, output_as_json)
         | 
| 200 | 
            -
             | 
| 201 181 | 
             
                  if bundles_dir.nil?
         | 
| 202 182 | 
             
                    all_plugins = nil
         | 
| 203 183 | 
             
                  else
         | 
| @@ -206,28 +186,29 @@ module KPM | |
| 206 186 | 
             
                  end
         | 
| 207 187 |  | 
| 208 188 | 
             
                  unless output_as_json
         | 
| 209 | 
            -
                    if all_plugins.nil? || all_plugins. | 
| 189 | 
            +
                    if all_plugins.nil? || all_plugins.empty?
         | 
| 210 190 | 
             
                      puts "\e[91;1mNo KB plugin information available\e[0m\n\n"
         | 
| 211 191 | 
             
                    else
         | 
| 212 192 | 
             
                      @formatter.format(all_plugins)
         | 
| 213 193 | 
             
                    end
         | 
| 214 194 | 
             
                  end
         | 
| 215 195 |  | 
| 216 | 
            -
                  if output_as_json && (all_plugins.nil? || all_plugins. | 
| 217 | 
            -
                    all_plugins = 'No KB plugin information available'
         | 
| 218 | 
            -
                  end
         | 
| 196 | 
            +
                  all_plugins = 'No KB plugin information available' if output_as_json && (all_plugins.nil? || all_plugins.empty?)
         | 
| 219 197 | 
             
                  all_plugins
         | 
| 220 198 | 
             
                end
         | 
| 221 199 |  | 
| 222 | 
            -
                 | 
| 200 | 
            +
                private
         | 
| 201 | 
            +
             | 
| 202 | 
            +
                def kaui_standalone_version(kaui_web_path = nil)
         | 
| 223 203 | 
             
                  kaui_search_default_dir = kaui_web_path.nil? ? DEFAULT_KAUI_SEARCH_BASE_DIR : Dir[kaui_web_path][0]
         | 
| 224 204 | 
             
                  return nil if kaui_search_default_dir.nil?
         | 
| 225 | 
            -
             | 
| 205 | 
            +
             | 
| 206 | 
            +
                  kaui_search_default_dir.gsub!('.war', '')
         | 
| 226 207 | 
             
                  version = nil
         | 
| 227 208 |  | 
| 228 209 | 
             
                  yaml_file = kaui_search_default_dir + File::SEPARATOR + 'WEB-INF' + File::SEPARATOR + 'version.yml'
         | 
| 229 210 | 
             
                  unless Dir[yaml_file][0].nil?
         | 
| 230 | 
            -
                    yml_data = YAML | 
| 211 | 
            +
                    yml_data = YAML.load_file(Dir[yaml_file][0])
         | 
| 231 212 |  | 
| 232 213 | 
             
                    version = yml_data['version']
         | 
| 233 214 | 
             
                  end
         | 
| @@ -235,10 +216,11 @@ module KPM | |
| 235 216 | 
             
                  version
         | 
| 236 217 | 
             
                end
         | 
| 237 218 |  | 
| 238 | 
            -
                def  | 
| 219 | 
            +
                def kaui_version(kaui_web_path = nil)
         | 
| 239 220 | 
             
                  kaui_search_default_dir = kaui_web_path.nil? ? DEFAULT_KAUI_SEARCH_BASE_DIR : Dir[kaui_web_path][0]
         | 
| 240 221 | 
             
                  return nil if kaui_search_default_dir.nil?
         | 
| 241 | 
            -
             | 
| 222 | 
            +
             | 
| 223 | 
            +
                  kaui_search_default_dir.gsub!('.war', '')
         | 
| 242 224 | 
             
                  version = nil
         | 
| 243 225 |  | 
| 244 226 | 
             
                  gemfile = Dir[kaui_search_default_dir + File::SEPARATOR + 'WEB-INF' + File::SEPARATOR + 'Gemfile']
         | 
| @@ -246,13 +228,13 @@ module KPM | |
| 246 228 | 
             
                  unless gemfile[0].nil?
         | 
| 247 229 | 
             
                    absolute_gemfile_path = File.absolute_path(gemfile[0])
         | 
| 248 230 |  | 
| 249 | 
            -
                    version = open(absolute_gemfile_path) do |f|
         | 
| 231 | 
            +
                    version = File.open(absolute_gemfile_path, 'r') do |f|
         | 
| 250 232 | 
             
                      f.each_line.detect do |line|
         | 
| 251 | 
            -
             | 
| 252 | 
            -
             | 
| 233 | 
            +
                        next unless /kaui/.match(line)
         | 
| 234 | 
            +
             | 
| 235 | 
            +
                        version = /(\d+)\.(\d+)\.(\d+)/.match(line)
         | 
| 253 236 |  | 
| 254 | 
            -
             | 
| 255 | 
            -
                         end
         | 
| 237 | 
            +
                        break unless version.nil?
         | 
| 256 238 | 
             
                      end
         | 
| 257 239 | 
             
                      version
         | 
| 258 240 | 
             
                    end
         | 
| @@ -262,18 +244,19 @@ module KPM | |
| 262 244 | 
             
                  version
         | 
| 263 245 | 
             
                end
         | 
| 264 246 |  | 
| 265 | 
            -
                def  | 
| 247 | 
            +
                def killbill_version(killbill_web_path = nil)
         | 
| 266 248 | 
             
                  killbill_search_default_dir = killbill_web_path.nil? ? DEFAULT_KILLBILL_SEARCH_BASE_DIR : Dir[killbill_web_path][0]
         | 
| 267 249 | 
             
                  return nil if killbill_search_default_dir.nil?
         | 
| 268 | 
            -
                  killbill_search_default_dir.gsub!('.war','')
         | 
| 269 | 
            -
                  killbill_search_default_dir.gsub!('webapps','**')
         | 
| 270 250 |  | 
| 271 | 
            -
                   | 
| 251 | 
            +
                  killbill_search_default_dir.gsub!('.war', '')
         | 
| 252 | 
            +
                  killbill_search_default_dir.gsub!('webapps', '**')
         | 
| 253 | 
            +
             | 
| 254 | 
            +
                  file =  Dir[killbill_search_default_dir + File::SEPARATOR + 'META-INF' + File::SEPARATOR + '**' + File::SEPARATOR + 'pom.properties']
         | 
| 272 255 | 
             
                  version = nil
         | 
| 273 256 | 
             
                  unless file[0].nil?
         | 
| 274 257 | 
             
                    absolute_file_path = File.absolute_path(file[0])
         | 
| 275 258 |  | 
| 276 | 
            -
                    version = open(absolute_file_path) do |f|
         | 
| 259 | 
            +
                    version = File.open(absolute_file_path, 'r') do |f|
         | 
| 277 260 | 
             
                      f.each_line.detect do |line|
         | 
| 278 261 | 
             
                        version = /(\d+)\.(\d+)\.(\d+)/.match(line)
         | 
| 279 262 |  | 
| @@ -287,93 +270,79 @@ module KPM | |
| 287 270 | 
             
                  version
         | 
| 288 271 | 
             
                end
         | 
| 289 272 |  | 
| 290 | 
            -
                def  | 
| 273 | 
            +
                def java_command
         | 
| 291 274 | 
             
                  command = 'java -XshowSettings:properties -version 2>&1'
         | 
| 292 | 
            -
                  apache_tomcat_pid =  | 
| 275 | 
            +
                  apache_tomcat_pid = find_apache_tomcat_pid
         | 
| 276 | 
            +
                  @logger.debug("Found Tomcat PID: #{apache_tomcat_pid}")
         | 
| 293 277 |  | 
| 294 | 
            -
                   | 
| 295 | 
            -
                    command = "jcmd #{apache_tomcat_pid} VM.system_properties"
         | 
| 296 | 
            -
                  end
         | 
| 278 | 
            +
                  command = "jcmd #{apache_tomcat_pid} VM.system_properties" unless apache_tomcat_pid.nil?
         | 
| 297 279 |  | 
| 298 280 | 
             
                  command
         | 
| 299 281 | 
             
                end
         | 
| 300 282 |  | 
| 301 | 
            -
                def  | 
| 302 | 
            -
                  apache_tomcat_pid = nil | 
| 283 | 
            +
                def find_apache_tomcat_pid
         | 
| 284 | 
            +
                  apache_tomcat_pid = nil
         | 
| 303 285 | 
             
                  `jcmd -l 2>&1`.split("\n").each do |line|
         | 
| 304 | 
            -
             | 
| 305 286 | 
             
                    if /org.apache.catalina/.match(line)
         | 
| 306 287 | 
             
                      words = line.split(' ')
         | 
| 307 288 | 
             
                      apache_tomcat_pid = words[0]
         | 
| 308 289 | 
             
                    end
         | 
| 309 | 
            -
             | 
| 310 290 | 
             
                  end
         | 
| 311 291 |  | 
| 312 292 | 
             
                  return apache_tomcat_pid unless apache_tomcat_pid.nil?
         | 
| 313 293 |  | 
| 314 | 
            -
                  jcmd = ( | 
| 294 | 
            +
                  jcmd = (ENV['JAVA_HOME'] || '/**') + File::Separator + 'bin' + File::Separator + 'jcmd'
         | 
| 315 295 | 
             
                  jcmd = Dir[jcmd][0]
         | 
| 316 296 | 
             
                  return nil if jcmd.nil?
         | 
| 317 297 |  | 
| 318 | 
            -
                  apache_tomcat_pid = `#{jcmd} | awk '/org.apache.catalina/' | cut -d ' ' -f 1`.gsub("\n",'')
         | 
| 298 | 
            +
                  apache_tomcat_pid = `#{jcmd} | awk '/org.apache.catalina/' | cut -d ' ' -f 1`.gsub("\n", '')
         | 
| 319 299 | 
             
                  return nil if apache_tomcat_pid.nil? || apache_tomcat_pid.empty?
         | 
| 320 300 |  | 
| 321 301 | 
             
                  apache_tomcat_pid
         | 
| 322 302 | 
             
                end
         | 
| 323 303 |  | 
| 324 | 
            -
                def  | 
| 304 | 
            +
                def config=(config_file = nil)
         | 
| 325 305 | 
             
                  @config = nil
         | 
| 326 306 |  | 
| 327 | 
            -
                  if  | 
| 328 | 
            -
                    if not Dir[config_file][0].nil?
         | 
| 329 | 
            -
                      @config = YAML::load_file(config_file)
         | 
| 330 | 
            -
                    end
         | 
| 331 | 
            -
                  end
         | 
| 307 | 
            +
                  return if config_file.nil?
         | 
| 332 308 |  | 
| 309 | 
            +
                  @config = YAML.load_file(config_file) unless Dir[config_file][0].nil?
         | 
| 333 310 | 
             
                end
         | 
| 334 311 |  | 
| 335 | 
            -
                def  | 
| 336 | 
            -
                  kaui_web_path = nil | 
| 312 | 
            +
                def kaui_web_path
         | 
| 313 | 
            +
                  kaui_web_path = nil
         | 
| 337 314 |  | 
| 338 | 
            -
                   | 
| 315 | 
            +
                  unless @config.nil?
         | 
| 339 316 | 
             
                    config_kaui = @config['kaui']
         | 
| 340 317 |  | 
| 341 | 
            -
                     | 
| 342 | 
            -
                      kaui_web_path = Dir[config_kaui['webapp_path']][0]
         | 
| 343 | 
            -
                    end
         | 
| 318 | 
            +
                    kaui_web_path = Dir[config_kaui['webapp_path']][0] unless config_kaui.nil?
         | 
| 344 319 | 
             
                  end
         | 
| 345 320 |  | 
| 346 321 | 
             
                  kaui_web_path
         | 
| 347 322 | 
             
                end
         | 
| 348 323 |  | 
| 349 | 
            -
                def  | 
| 350 | 
            -
                  killbill_web_path = nil | 
| 324 | 
            +
                def killbill_web_path
         | 
| 325 | 
            +
                  killbill_web_path = nil
         | 
| 351 326 |  | 
| 352 | 
            -
                   | 
| 327 | 
            +
                  unless @config.nil?
         | 
| 353 328 | 
             
                    config_killbill = @config['killbill']
         | 
| 354 329 |  | 
| 355 | 
            -
                     | 
| 356 | 
            -
                      killbill_web_path = Dir[config_killbill['webapp_path']][0]
         | 
| 357 | 
            -
                    end
         | 
| 330 | 
            +
                    killbill_web_path = Dir[config_killbill['webapp_path']][0] unless config_killbill.nil?
         | 
| 358 331 | 
             
                  end
         | 
| 359 332 |  | 
| 360 333 | 
             
                  killbill_web_path
         | 
| 361 334 | 
             
                end
         | 
| 362 335 |  | 
| 363 | 
            -
                def  | 
| 364 | 
            -
                  plugin_path = nil | 
| 336 | 
            +
                def plugin_path
         | 
| 337 | 
            +
                  plugin_path = nil
         | 
| 365 338 |  | 
| 366 | 
            -
                   | 
| 339 | 
            +
                  unless @config.nil?
         | 
| 367 340 | 
             
                    config_killbill = @config['killbill']
         | 
| 368 341 |  | 
| 369 | 
            -
                     | 
| 370 | 
            -
                      plugin_path = Dir[config_killbill['plugins_dir']][0]
         | 
| 371 | 
            -
                    end
         | 
| 342 | 
            +
                    plugin_path = Dir[config_killbill['plugins_dir']][0] unless config_killbill.nil?
         | 
| 372 343 | 
             
                  end
         | 
| 373 344 |  | 
| 374 345 | 
             
                  plugin_path
         | 
| 375 346 | 
             
                end
         | 
| 376 | 
            -
             | 
| 377 347 | 
             
              end
         | 
| 378 | 
            -
             | 
| 379 | 
            -
            end
         | 
| 348 | 
            +
            end
         |