kpm 0.7.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +138 -0
  4. data/Gemfile +2 -0
  5. data/README.adoc +144 -107
  6. data/Rakefile +2 -1
  7. data/bin/kpm +4 -2
  8. data/kpm.gemspec +11 -8
  9. data/lib/kpm.rb +3 -0
  10. data/lib/kpm/account.rb +268 -338
  11. data/lib/kpm/base_artifact.rb +33 -39
  12. data/lib/kpm/base_installer.rb +69 -83
  13. data/lib/kpm/blob.rb +29 -0
  14. data/lib/kpm/cli.rb +3 -1
  15. data/lib/kpm/coordinates.rb +10 -12
  16. data/lib/kpm/database.rb +94 -113
  17. data/lib/kpm/diagnostic_file.rb +126 -147
  18. data/lib/kpm/formatter.rb +76 -48
  19. data/lib/kpm/inspector.rb +24 -34
  20. data/lib/kpm/installer.rb +53 -46
  21. data/lib/kpm/kaui_artifact.rb +4 -3
  22. data/lib/kpm/killbill_plugin_artifact.rb +10 -7
  23. data/lib/kpm/killbill_server_artifact.rb +13 -12
  24. data/lib/kpm/migrations.rb +26 -11
  25. data/lib/kpm/nexus_helper/actions.rb +52 -9
  26. data/lib/kpm/nexus_helper/cloudsmith_api_calls.rb +83 -0
  27. data/lib/kpm/nexus_helper/github_api_calls.rb +70 -0
  28. data/lib/kpm/nexus_helper/nexus_api_calls_v2.rb +130 -108
  29. data/lib/kpm/nexus_helper/nexus_facade.rb +5 -3
  30. data/lib/kpm/plugins_directory.rb +9 -8
  31. data/lib/kpm/plugins_directory.yml +14 -173
  32. data/lib/kpm/plugins_manager.rb +29 -24
  33. data/lib/kpm/sha1_checker.rb +31 -18
  34. data/lib/kpm/system.rb +104 -135
  35. data/lib/kpm/system_helpers/cpu_information.rb +56 -55
  36. data/lib/kpm/system_helpers/disk_space_information.rb +60 -63
  37. data/lib/kpm/system_helpers/entropy_available.rb +37 -39
  38. data/lib/kpm/system_helpers/memory_information.rb +52 -51
  39. data/lib/kpm/system_helpers/os_information.rb +45 -47
  40. data/lib/kpm/system_helpers/system_proxy.rb +10 -10
  41. data/lib/kpm/tasks.rb +381 -438
  42. data/lib/kpm/tenant_config.rb +68 -83
  43. data/lib/kpm/tomcat_manager.rb +10 -8
  44. data/lib/kpm/trace_logger.rb +18 -16
  45. data/lib/kpm/uninstaller.rb +81 -14
  46. data/lib/kpm/utils.rb +13 -14
  47. data/lib/kpm/version.rb +3 -1
  48. data/packaging/Gemfile +2 -0
  49. data/pom.xml +211 -40
  50. data/spec/kpm/remote/base_artifact_spec.rb +20 -20
  51. data/spec/kpm/remote/base_installer_spec.rb +35 -34
  52. data/spec/kpm/remote/cloudsmith_api_calls_spec.rb +40 -0
  53. data/spec/kpm/remote/github_api_calls_spec.rb +40 -0
  54. data/spec/kpm/remote/installer_spec.rb +80 -79
  55. data/spec/kpm/remote/kaui_artifact_spec.rb +7 -6
  56. data/spec/kpm/remote/killbill_plugin_artifact_spec.rb +25 -30
  57. data/spec/kpm/remote/killbill_server_artifact_spec.rb +17 -16
  58. data/spec/kpm/remote/migrations_spec.rb +12 -11
  59. data/spec/kpm/remote/nexus_facade_spec.rb +32 -28
  60. data/spec/kpm/remote/tenant_config_spec.rb +30 -29
  61. data/spec/kpm/remote/tomcat_manager_spec.rb +4 -3
  62. data/spec/kpm/unit/actions_spec.rb +52 -0
  63. data/spec/kpm/unit/base_artifact_spec.rb +19 -18
  64. data/spec/kpm/unit/cpu_information_spec.rb +67 -0
  65. data/spec/kpm/unit/disk_space_information_spec.rb +47 -0
  66. data/spec/kpm/unit/entropy_information_spec.rb +36 -0
  67. data/spec/kpm/unit/formatter_spec.rb +163 -0
  68. data/spec/kpm/unit/inspector_spec.rb +34 -42
  69. data/spec/kpm/unit/installer_spec.rb +7 -6
  70. data/spec/kpm/unit/memory_information_spec.rb +102 -0
  71. data/spec/kpm/unit/os_information_spec.rb +38 -0
  72. data/spec/kpm/unit/plugins_directory_spec.rb +38 -22
  73. data/spec/kpm/unit/plugins_manager_spec.rb +62 -66
  74. data/spec/kpm/unit/sha1_checker_spec.rb +107 -60
  75. data/spec/kpm/unit/uninstaller_spec.rb +118 -72
  76. data/spec/kpm/unit_mysql/account_spec.rb +127 -142
  77. data/spec/spec_helper.rb +20 -18
  78. data/tasks/package.rake +18 -18
  79. metadata +42 -22
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'digest/sha1'
2
4
  require 'rexml/document'
3
5
 
4
6
  module KPM
5
-
6
7
  class ArtifactCorruptedException < IOError
7
8
  def message
8
9
  'Downloaded artifact failed checksum verification'
@@ -34,32 +35,32 @@ module KPM
34
35
  KAUI_CLASSIFIER = nil
35
36
 
36
37
  class << self
37
- def pull(logger, group_id, artifact_id, packaging='jar', classifier=nil, version='LATEST', destination_path=nil, sha1_file=nil, force_download=false, verify_sha1=true, overrides={}, ssl_verify=true)
38
- coordinate_map = {:group_id => group_id, :artifact_id => artifact_id, :packaging => packaging, :classifier => classifier, :version => version}
38
+ def pull(logger, group_id, artifact_id, packaging = 'jar', classifier = nil, version = 'LATEST', destination_path = nil, sha1_file = nil, force_download = false, verify_sha1 = true, overrides = {}, ssl_verify = true)
39
+ coordinate_map = { group_id: group_id, artifact_id: artifact_id, packaging: packaging, classifier: classifier, version: version }
39
40
  pull_and_put_in_place(logger, coordinate_map, nil, destination_path, false, sha1_file, force_download, verify_sha1, overrides, ssl_verify)
40
41
  end
41
42
 
42
- def pull_from_fs(logger, file_path, destination_path=nil)
43
+ def pull_from_fs(logger, file_path, destination_path = nil)
43
44
  pull_from_fs_and_put_in_place(logger, file_path, destination_path)
44
45
  end
45
46
 
46
- def nexus_remote(overrides={}, ssl_verify=true, logger=nil)
47
+ def nexus_remote(overrides = {}, ssl_verify = true, logger = nil)
47
48
  # overrides typically comes from the kpm.yml where we expect keys as String
48
- overrides_sym = (overrides || {}).each_with_object({}) {|(k,v), h| h[k.to_sym] = v}
49
+ overrides_sym = (overrides || {}).each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
49
50
  nexus_config = nexus_defaults.merge(overrides_sym)
50
- nexus_remote ||= KPM::NexusFacade::RemoteFactory.create(nexus_config, ssl_verify, logger)
51
+ KPM::NexusFacade::RemoteFactory.create(nexus_config, ssl_verify, logger)
51
52
  end
52
53
 
53
54
  def nexus_defaults
54
55
  {
55
- url: 'https://oss.sonatype.org',
56
- repository: 'releases'
56
+ url: 'https://oss.sonatype.org',
57
+ repository: 'releases'
57
58
  }
58
59
  end
59
60
 
60
61
  protected
61
62
 
62
- def pull_and_put_in_place(logger, coordinate_map, plugin_name, destination_path=nil, skip_top_dir=true, sha1_file=nil, force_download=false, verify_sha1=true, overrides={}, ssl_verify=true)
63
+ def pull_and_put_in_place(logger, coordinate_map, plugin_name, destination_path = nil, skip_top_dir = true, sha1_file = nil, force_download = false, verify_sha1 = true, overrides = {}, ssl_verify = true)
63
64
  # Build artifact info
64
65
  artifact_info = artifact_info(logger, coordinate_map, sha1_file, force_download, overrides, ssl_verify)
65
66
  artifact_info[:plugin_name] = plugin_name
@@ -104,7 +105,7 @@ module KPM
104
105
  logger.info " Starting download of #{coordinates} to #{tmp_destination_dir}"
105
106
 
106
107
  downloaded_artifact_info = pull_and_verify(logger, artifact_info[:sha1], coordinates, tmp_destination_dir, sha1_file, verify_sha1, overrides, ssl_verify)
107
- remove_old_default_bundles(coordinate_map,artifact_info,downloaded_artifact_info)
108
+ remove_old_default_bundles(coordinate_map, artifact_info, downloaded_artifact_info)
108
109
  if artifact_info[:is_tgz]
109
110
  artifact_info[:bundle_dir] = Utils.unpack_tgz(downloaded_artifact_info[:file_path], artifact_info[:dir_name], skip_top_dir)
110
111
  FileUtils.rm downloaded_artifact_info[:file_path]
@@ -119,11 +120,11 @@ module KPM
119
120
  end
120
121
 
121
122
  # Logic similar than pull_and_put_in_place above
122
- def pull_from_fs_and_put_in_place(logger, file_path, destination_path=nil)
123
+ def pull_from_fs_and_put_in_place(logger, file_path, destination_path = nil)
123
124
  artifact_info = {
124
- :skipped => false,
125
- :repository_path => file_path,
126
- :is_tgz => file_path.end_with?('.tar.gz') || file_path.end_with?('.tgz')
125
+ skipped: false,
126
+ repository_path: file_path,
127
+ is_tgz: file_path.end_with?('.tar.gz') || file_path.end_with?('.tgz')
127
128
  }
128
129
 
129
130
  populate_fs_info(artifact_info, destination_path)
@@ -148,7 +149,7 @@ module KPM
148
149
  return false if artifact_info[:sha1].nil?
149
150
 
150
151
  # If there is no such sha1_file, we don't skip
151
- return false if sha1_file.nil? || !File.exists?(sha1_file)
152
+ return false if sha1_file.nil? || !File.exist?(sha1_file)
152
153
 
153
154
  #
154
155
  # At this point we have a valid sha1_file and a remote sha1
@@ -168,9 +169,9 @@ module KPM
168
169
  end
169
170
  end
170
171
 
171
- def artifact_info(logger, coordinate_map, sha1_file=nil, force_download=false, overrides={}, ssl_verify=true)
172
+ def artifact_info(logger, coordinate_map, sha1_file = nil, force_download = false, overrides = {}, ssl_verify = true)
172
173
  info = {
173
- :skipped => false
174
+ skipped: false
174
175
  }
175
176
 
176
177
  sha1_checker = sha1_file ? Sha1Checker.from_file(sha1_file) : nil
@@ -179,16 +180,14 @@ module KPM
179
180
  begin
180
181
  nexus_info = nexus_remote(overrides, ssl_verify, logger).get_artifact_info(coordinates)
181
182
  rescue KPM::NexusFacade::ArtifactMalformedException => e
182
- raise StandardError.new("Invalid coordinates #{coordinate_map}: #{e}")
183
+ raise StandardError, "Invalid coordinates #{coordinate_map}: #{e}"
183
184
  rescue StandardError => e
184
185
  logger.warn("Unable to retrieve coordinates #{coordinate_map}: #{e}")
185
186
  cached_coordinates = sha1_checker ? sha1_checker.artifact_info(coordinates) : nil
186
- if force_download || !cached_coordinates
187
- raise e
188
- else
189
- # Use the cache
190
- return cached_coordinates
191
- end
187
+ raise e if force_download || !cached_coordinates
188
+
189
+ # Use the cache
190
+ return cached_coordinates
192
191
  end
193
192
 
194
193
  xml = REXML::Document.new(nexus_info)
@@ -204,7 +203,7 @@ module KPM
204
203
 
205
204
  def update_destination_path(info, destination_path)
206
205
  # In case LATEST was specified, use the actual version as the directory name
207
- destination_path = KPM::root if destination_path.nil?
206
+ destination_path = KPM.root if destination_path.nil?
208
207
  plugin_dir, version_dir = File.split(destination_path)
209
208
  destination_path = Pathname.new(plugin_dir).join(info[:version]).to_s if version_dir == 'LATEST' && !info[:version].nil?
210
209
  destination_path
@@ -231,13 +230,14 @@ module KPM
231
230
  destination_path
232
231
  end
233
232
 
234
- def pull_and_verify(logger, remote_sha1, coordinates, destination_dir, sha1_file, verify_sha1, overrides={}, ssl_verify=true)
233
+ def pull_and_verify(logger, remote_sha1, coordinates, destination_dir, sha1_file, verify_sha1, overrides = {}, ssl_verify = true)
235
234
  info = nexus_remote(overrides, ssl_verify, logger).pull_artifact(coordinates, destination_dir)
236
235
 
237
236
  # Always verify sha1 and if incorrect either throw or log when we are asked to bypass sha1 verification
238
237
  verified = verify(logger, coordinates, info[:file_path], remote_sha1)
239
- if !verified
238
+ unless verified
240
239
  raise ArtifactCorruptedException if verify_sha1
240
+
241
241
  logger.warn("Skip sha1 verification for #{coordinates}")
242
242
  end
243
243
 
@@ -258,13 +258,10 @@ module KPM
258
258
 
259
259
  local_sha1 = Digest::SHA1.file(file_path).hexdigest
260
260
  res = local_sha1 == remote_sha1
261
- if !res
262
- logger.warn("Sha1 verification failed for #{coordinates} : local_sha1 = #{local_sha1}, remote_sha1 = #{remote_sha1}")
263
- end
261
+ logger.warn("Sha1 verification failed for #{coordinates} : local_sha1 = #{local_sha1}, remote_sha1 = #{remote_sha1}") unless res
264
262
  res
265
263
  end
266
264
 
267
-
268
265
  # Magic methods...
269
266
 
270
267
  def path_looks_like_a_directory(path)
@@ -275,12 +272,12 @@ module KPM
275
272
 
276
273
  last_part = File.basename(path).downcase
277
274
 
278
- %w(.pom .xml .war .jar .xsd .tar.gz .tgz .gz .zip).each do |classic_file_extension|
275
+ %w[.pom .xml .war .jar .xsd .tar.gz .tgz .gz .zip].each do |classic_file_extension|
279
276
  return false if last_part.end_with?(classic_file_extension)
280
277
  end
281
278
 
282
279
  # Known magic files
283
- %w(root).each do |classic_filename|
280
+ %w[root].each do |classic_filename|
284
281
  return false if last_part == classic_filename
285
282
  end
286
283
 
@@ -296,12 +293,9 @@ module KPM
296
293
 
297
294
  existing_default_bundles.each do |bundle|
298
295
  bundle_name = Utils.get_plugin_name_from_file_path(bundle)
299
- is_downloaded = downloaded_default_bundles.index {|file_name| file_name.include? bundle_name}
300
- unless is_downloaded.nil?
301
- FileUtils.remove(bundle)
302
- end
296
+ is_downloaded = downloaded_default_bundles.index { |file_name| file_name.include? bundle_name }
297
+ FileUtils.remove(bundle) unless is_downloaded.nil?
303
298
  end
304
-
305
299
  end
306
300
  end
307
301
  end
@@ -1,9 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pathname'
2
4
  require 'zip'
3
5
 
4
6
  module KPM
5
7
  class BaseInstaller
6
-
7
8
  LATEST_VERSION = 'LATEST'
8
9
  SHA1_FILENAME = 'sha1.yml'
9
10
  DEFAULT_BUNDLES_DIR = Pathname.new('/var').join('tmp').join('bundles').to_s
@@ -15,13 +16,13 @@ module KPM
15
16
  @trace_logger = KPM::TraceLogger.new
16
17
  end
17
18
 
18
- def install_killbill_server(specified_group_id=nil, specified_artifact_id=nil, specified_packaging=nil, specified_classifier=nil, specified_version=nil, specified_webapp_path=nil, bundles_dir=nil, force_download=false, verify_sha1=true)
19
+ def install_killbill_server(specified_group_id = nil, specified_artifact_id = nil, specified_packaging = nil, specified_classifier = nil, specified_version = nil, specified_webapp_path = nil, bundles_dir = nil, force_download = false, verify_sha1 = true)
19
20
  group_id = specified_group_id || KPM::BaseArtifact::KILLBILL_GROUP_ID
20
21
  artifact_id = specified_artifact_id || KPM::BaseArtifact::KILLBILL_ARTIFACT_ID
21
22
  packaging = specified_packaging || KPM::BaseArtifact::KILLBILL_PACKAGING
22
23
  classifier = specified_classifier || KPM::BaseArtifact::KILLBILL_CLASSIFIER
23
24
  version = specified_version || LATEST_VERSION
24
- webapp_path = specified_webapp_path || KPM::root
25
+ webapp_path = specified_webapp_path || KPM.root
25
26
  bundles_dir = Pathname.new(bundles_dir || DEFAULT_BUNDLES_DIR).expand_path
26
27
  sha1_file = "#{bundles_dir}/#{SHA1_FILENAME}"
27
28
 
@@ -32,60 +33,55 @@ module KPM
32
33
 
33
34
  @logger.debug("Installing Kill Bill server: group_id=#{group_id} artifact_id=#{artifact_id} packaging=#{packaging} classifier=#{classifier} version=#{version} webapp_path=#{webapp_path}")
34
35
  artifact_info = KPM::KillbillServerArtifact.pull(@logger,
35
- group_id,
36
- artifact_id,
37
- packaging,
38
- classifier,
39
- version,
40
- webapp_path,
41
- sha1_file,
42
- force_download,
43
- verify_sha1,
44
- @nexus_config,
45
- @nexus_ssl_verify)
36
+ group_id,
37
+ artifact_id,
38
+ packaging,
39
+ classifier,
40
+ version,
41
+ webapp_path,
42
+ sha1_file,
43
+ force_download,
44
+ verify_sha1,
45
+ @nexus_config,
46
+ @nexus_ssl_verify)
46
47
  # store trace info to be returned as JSON by the KPM::Installer.install method
47
- @trace_logger.add('killbill',
48
- artifact_info.merge({'status'=> (artifact_info[:skipped] ? 'UP_TO_DATE': 'INSTALLED'),
49
- :group_id => group_id, :artifact_id => artifact_id, :packaging => packaging, :classifier => classifier}))
48
+ @trace_logger.add('killbill', nil,
49
+ artifact_info.merge('status' => (artifact_info[:skipped] ? 'UP_TO_DATE' : 'INSTALLED'),
50
+ :group_id => group_id, :artifact_id => artifact_id, :packaging => packaging, :classifier => classifier))
50
51
  end
51
52
 
52
- def install_kaui(specified_group_id=nil, specified_artifact_id=nil, specified_packaging=nil, specified_classifier=nil, specified_version=nil, specified_webapp_path=nil, bundles_dir=nil, force_download=false, verify_sha1=true)
53
+ def install_kaui(specified_group_id = nil, specified_artifact_id = nil, specified_packaging = nil, specified_classifier = nil, specified_version = nil, specified_webapp_path = nil, bundles_dir = nil, force_download = false, verify_sha1 = true)
53
54
  group_id = specified_group_id || KPM::BaseArtifact::KAUI_GROUP_ID
54
55
  artifact_id = specified_artifact_id || KPM::BaseArtifact::KAUI_ARTIFACT_ID
55
56
  packaging = specified_packaging || KPM::BaseArtifact::KAUI_PACKAGING
56
57
  classifier = specified_classifier || KPM::BaseArtifact::KAUI_CLASSIFIER
57
58
  version = specified_version || LATEST_VERSION
58
- webapp_path = specified_webapp_path || KPM::root
59
+ webapp_path = specified_webapp_path || KPM.root
59
60
  bundles_dir = Pathname.new(bundles_dir || DEFAULT_BUNDLES_DIR).expand_path
60
61
  sha1_file = "#{bundles_dir}/#{SHA1_FILENAME}"
61
62
 
62
63
  @logger.debug("Installing Kaui: group_id=#{group_id} artifact_id=#{artifact_id} packaging=#{packaging} classifier=#{classifier} version=#{version} webapp_path=#{webapp_path}")
63
64
  artifact_info = KPM::KauiArtifact.pull(@logger,
64
- group_id,
65
- artifact_id,
66
- packaging,
67
- classifier,
68
- version,
69
- webapp_path,
70
- sha1_file,
71
- force_download,
72
- verify_sha1,
73
- @nexus_config,
74
- @nexus_ssl_verify)
65
+ group_id,
66
+ artifact_id,
67
+ packaging,
68
+ classifier,
69
+ version,
70
+ webapp_path,
71
+ sha1_file,
72
+ force_download,
73
+ verify_sha1,
74
+ @nexus_config,
75
+ @nexus_ssl_verify)
75
76
  # store trace info to be returned as JSON by the KPM::Installer.install method
76
- @trace_logger.add('kaui',
77
- artifact_info.merge({'status'=> (artifact_info[:skipped] ? 'UP_TO_DATE': 'INSTALLED'),
78
- :group_id => group_id, :artifact_id => artifact_id, :packaging => packaging, :classifier => classifier}))
79
-
80
-
77
+ @trace_logger.add('kaui', nil,
78
+ artifact_info.merge('status' => (artifact_info[:skipped] ? 'UP_TO_DATE' : 'INSTALLED'),
79
+ :group_id => group_id, :artifact_id => artifact_id, :packaging => packaging, :classifier => classifier))
81
80
  end
82
81
 
83
- 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)
84
-
82
+ 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)
85
83
  # plugin_key needs to exist
86
- if plugin_key.nil?
87
- raise ArgumentError.new 'Aborting installation: User needs to specify a pluginKey'
88
- end
84
+ raise ArgumentError, 'Aborting installation: User needs to specify a pluginKey' if plugin_key.nil?
89
85
 
90
86
  # Lookup artifact and perform validation against input
91
87
  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)
@@ -95,21 +91,17 @@ module KPM
95
91
  validate_installation_arg!(plugin_key, 'type', specified_type, looked_up_type)
96
92
  validate_installation_arg!(plugin_key, 'classifier', specified_classifier, looked_up_classifier)
97
93
 
98
-
99
94
  # If there is no entry in plugins_directory.yml and the group_id is not the killbill default group_id, the key provided must be a user key and must have a namespace
100
95
  if looked_up_artifact_id.nil? &&
101
- specified_group_id != KPM::BaseArtifact::KILLBILL_JAVA_PLUGIN_GROUP_ID &&
102
- specified_group_id != KPM::BaseArtifact::KILLBILL_RUBY_PLUGIN_GROUP_ID &&
103
- plugin_key.split(':').size == 1
104
- raise ArgumentError.new "Aborting installation: pluginKey = #{plugin_key} does not exist in plugin_directory.yml so format of the key must have a user namespace (e.g namespace:key)"
96
+ specified_group_id != KPM::BaseArtifact::KILLBILL_JAVA_PLUGIN_GROUP_ID &&
97
+ specified_group_id != KPM::BaseArtifact::KILLBILL_RUBY_PLUGIN_GROUP_ID &&
98
+ plugin_key.split(':').size == 1
99
+ raise ArgumentError, "Aborting installation: pluginKey = #{plugin_key} does not exist in plugin_directory.yml so format of the key must have a user namespace (e.g namespace:key)"
105
100
  end
106
101
 
107
-
108
102
  # Specified parameters have always precedence except for the artifact_id (to map stripe to stripe-plugin)
109
103
  artifact_id = looked_up_artifact_id || specified_artifact_id
110
- if artifact_id.nil?
111
- raise ArgumentError.new "Aborting installation: unable to lookup plugin #{specified_artifact_id}"
112
- end
104
+ raise ArgumentError, "Aborting installation: unable to lookup plugin #{specified_artifact_id}" if artifact_id.nil?
113
105
 
114
106
  bundles_dir = Pathname.new(bundles_dir || DEFAULT_BUNDLES_DIR).expand_path
115
107
  plugins_dir = bundles_dir.join('plugins')
@@ -136,10 +128,9 @@ module KPM
136
128
  _, plugin_name = plugins_manager.get_plugin_key_and_name(plugin_key)
137
129
 
138
130
  # Before we do the install we verify that the entry we have in the plugin_identifiers.json matches our current request
139
- coordinate_map = {:group_id => group_id, :artifact_id => artifact_id, :packaging => packaging, :classifier => classifier}
131
+ coordinate_map = { group_id: group_id, artifact_id: artifact_id, packaging: packaging, classifier: classifier }
140
132
  validate_plugin_key!(plugins_dir, plugin_key, coordinate_map)
141
133
 
142
-
143
134
  @logger.debug("Installing plugin: group_id=#{group_id} artifact_id=#{artifact_id} packaging=#{packaging} classifier=#{classifier} version=#{version} destination=#{destination}")
144
135
  artifact_info = KPM::KillbillPluginArtifact.pull(@logger,
145
136
  group_id,
@@ -156,8 +147,8 @@ module KPM
156
147
  @nexus_ssl_verify)
157
148
  # store trace info to be returned as JSON by the KPM::Installer.install method
158
149
  @trace_logger.add('plugins', plugin_key,
159
- artifact_info.merge({'status'=> (artifact_info[:skipped] ? 'UP_TO_DATE': 'INSTALLED'),
160
- :group_id => group_id, :artifact_id => artifact_id, :packaging => packaging, :classifier => classifier}))
150
+ artifact_info.merge('status' => (artifact_info[:skipped] ? 'UP_TO_DATE' : 'INSTALLED'),
151
+ :group_id => group_id, :artifact_id => artifact_id, :packaging => packaging, :classifier => classifier))
161
152
 
162
153
  # Update with resolved version
163
154
  coordinate_map[:version] = artifact_info[:version]
@@ -169,14 +160,19 @@ module KPM
169
160
  artifact_info
170
161
  end
171
162
 
163
+ def install_plugin_from_fs(plugin_key, raw_file_path, name, version, bundles_dir = nil, type = 'java')
164
+ # Expand glob if needed
165
+ file_paths = Dir.glob(raw_file_path)
166
+ raise ArgumentError, "Cannot install plugin: no file found at #{raw_file_path}" if file_paths.empty?
167
+ raise ArgumentError, "Cannot install plugin: multiple files found at #{raw_file_path}" if file_paths.size > 1
168
+
169
+ file_path = file_paths[0]
172
170
 
173
- def install_plugin_from_fs(plugin_key, file_path, name, version, bundles_dir=nil, type='java')
174
171
  bundles_dir = Pathname.new(bundles_dir || DEFAULT_BUNDLES_DIR).expand_path
175
172
  plugins_dir = bundles_dir.join('plugins')
176
173
 
177
- if version.nil?
178
- version = Utils.get_version_from_file_path(file_path)
179
- end
174
+ version = Utils.get_version_from_file_path(file_path) if version.nil?
175
+ raise ArgumentError, 'Cannot install plugin: missing version' if version.nil?
180
176
 
181
177
  if type.to_s == 'java'
182
178
  plugin_name = name.nil? ? Utils.get_plugin_name_from_file_path(file_path) : name
@@ -194,28 +190,26 @@ module KPM
194
190
 
195
191
  # store trace info to be returned as JSON by the KPM::Installer.install method
196
192
  @trace_logger.add('plugins', plugin_key,
197
- artifact_info.merge({'status'=>'INSTALLED'}))
193
+ artifact_info.merge('status' => 'INSTALLED'))
198
194
 
199
195
  artifact_info
200
196
  end
201
197
 
202
- def uninstall_plugin(plugin_name_or_key, plugin_version=nil, bundles_dir=nil)
198
+ def uninstall_plugin(plugin_name_or_key, plugin_version = nil, bundles_dir = nil)
203
199
  bundles_dir = Pathname.new(bundles_dir || DEFAULT_BUNDLES_DIR).expand_path
204
200
  plugins_dir = bundles_dir.join('plugins')
205
201
 
206
202
  plugins_manager = PluginsManager.new(plugins_dir, @logger)
207
203
 
208
204
  plugin_key, plugin_name = plugins_manager.get_plugin_key_and_name(plugin_name_or_key)
209
- if plugin_name.nil?
210
- raise ArgumentError.new "Cannot uninstall plugin: Unknown plugin name or plugin key = #{plugin_name_or_key}"
211
- end
205
+ raise ArgumentError, "Cannot uninstall plugin: Unknown plugin name or plugin key = #{plugin_name_or_key}" if plugin_name.nil?
212
206
 
213
207
  modified = plugins_manager.uninstall(plugin_name, plugin_version || :all)
214
208
  plugins_manager.remove_plugin_identifier_key(plugin_key)
215
209
  modified
216
210
  end
217
211
 
218
- def install_default_bundles(bundles_dir, specified_version=nil, kb_version=nil, force_download=false, verify_sha1=true)
212
+ def install_default_bundles(bundles_dir, specified_version = nil, kb_version = nil, force_download = false, verify_sha1 = true)
219
213
  group_id = 'org.kill-bill.billing'
220
214
  artifact_id = 'killbill-platform-osgi-bundles-defaultbundles'
221
215
  packaging = 'tar.gz'
@@ -247,15 +241,13 @@ module KPM
247
241
  @nexus_config,
248
242
  @nexus_ssl_verify)
249
243
 
250
- @trace_logger.add('default_bundles',
251
- info.merge({'status'=> (info[:skipped] ? 'UP_TO_DATE': 'INSTALLED'),
252
- :group_id => group_id, :artifact_id => artifact_id, :packaging => packaging, :classifier => classifier}))
244
+ @trace_logger.add('default_bundles', nil,
245
+ info.merge('status' => (info[:skipped] ? 'UP_TO_DATE' : 'INSTALLED'),
246
+ :group_id => group_id, :artifact_id => artifact_id, :packaging => packaging, :classifier => classifier))
253
247
 
254
248
  # The special JRuby bundle needs to be called jruby.jar
255
249
  # TODO .first - code smell
256
- unless info[:skipped]
257
- File.rename Dir.glob("#{destination}/killbill-platform-osgi-bundles-jruby-*.jar").first, destination.join('jruby.jar')
258
- end
250
+ File.rename Dir.glob("#{destination}/killbill-platform-osgi-bundles-jruby-*.jar").first, destination.join('jruby.jar') unless info[:skipped]
259
251
 
260
252
  info
261
253
  end
@@ -263,21 +255,16 @@ module KPM
263
255
  private
264
256
 
265
257
  def validate_installation_arg!(plugin_key, arg_type, specified_arg, looked_up_arg)
266
-
267
258
  # If nothing was specified, or if we don't find anything from the lookup, nothing to validate against
268
- if specified_arg.nil? || looked_up_arg.nil?
269
- return
270
- end
259
+ return if specified_arg.nil? || looked_up_arg.nil?
271
260
 
272
- if specified_arg.to_s != looked_up_arg.to_s
273
- raise ArgumentError.new "Aborting installation for plugin_key #{plugin_key}: specified value #{specified_arg} for #{arg_type} does not match looked_up value #{looked_up_arg}"
274
- end
261
+ raise ArgumentError, "Aborting installation for plugin_key #{plugin_key}: specified value #{specified_arg} for #{arg_type} does not match looked_up value #{looked_up_arg}" if specified_arg.to_s != looked_up_arg.to_s
275
262
  end
276
263
 
277
264
  def validate_plugin_key!(plugins_dir, plugin_key, coordinate_map)
278
265
  plugins_manager = PluginsManager.new(plugins_dir, @logger)
279
266
  res = plugins_manager.validate_plugin_identifier_key(plugin_key, coordinate_map)
280
- raise ArgumentError.new "Failed to validate plugin key #{plugin_key}" if !res
267
+ raise ArgumentError, "Failed to validate plugin key #{plugin_key}" unless res
281
268
  end
282
269
 
283
270
  def update_plugin_identifier(plugins_dir, plugin_key, type, coordinate_map, artifact_info)
@@ -289,7 +276,7 @@ module KPM
289
276
  plugins_manager.add_plugin_identifier_key(plugin_key, plugin_name, type, coordinate_map)
290
277
  end
291
278
 
292
- def mark_as_active(plugins_dir, artifact_info, artifact_id=nil)
279
+ def mark_as_active(plugins_dir, artifact_info, _artifact_id = nil)
293
280
  # Mark this bundle as active
294
281
  plugins_manager = PluginsManager.new(plugins_dir, @logger)
295
282
  plugins_manager.set_active(artifact_info[:bundle_dir])
@@ -298,14 +285,14 @@ module KPM
298
285
  def warn_if_jruby_jar_missing(bundles_dir)
299
286
  platform_dir = bundles_dir.join('platform')
300
287
  jruby_jar = platform_dir.join('jruby.jar')
301
- if !File.exists?(jruby_jar)
302
- @logger.warn(" Missing installation for jruby.jar under #{platform_dir}. This is required for ruby plugin installation");
288
+ if !File.exist?(jruby_jar)
289
+ @logger.warn(" Missing installation for jruby.jar under #{platform_dir}. This is required for ruby plugin installation")
303
290
  else
304
291
  version = extract_jruby_jar_version(jruby_jar)
305
292
  if version
306
293
  @logger.info(" Detected jruby.jar version #{version}")
307
294
  else
308
- @logger.warn(" Failed to detect jruby.jar version for #{jruby_jar}");
295
+ @logger.warn(" Failed to detect jruby.jar version for #{jruby_jar}")
309
296
  end
310
297
  end
311
298
  end
@@ -320,10 +307,9 @@ module KPM
320
307
  if selected_entries && selected_entries.size == 1
321
308
  zip_entry = selected_entries[0]
322
309
  content = zip_entry.get_input_stream.read
323
- return content.split("\n").select { |e| e.start_with?("version")}[0].split("=")[1]
310
+ return content.split("\n").select { |e| e.start_with?('version') }[0].split('=')[1]
324
311
  end
325
312
  nil
326
313
  end
327
-
328
314
  end
329
315
  end