Module: KPM::Tasks

Included in:
Cli
Defined in:
lib/kpm/tasks.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# File 'lib/kpm/tasks.rb', line 10

def self.included(base)
  base.send :include, ::Thor::Actions
  base.class_eval do


    desc 'KPM version', 'Return current KPM version.'
    def version
      say "KPM version #{KPM::VERSION}"
    end

    class_option :overrides,
                 :type    => :hash,
                 :default => nil,
                 :desc    => "A hashed list of overrides. Available options are 'url', 'repository', 'username', and 'password'."

    class_option :ssl_verify,
                 :type    => :boolean,
                 :default => true,
                 :desc    => 'Set to false to disable SSL Verification.'

    method_option :force_download,
                  :type    => :boolean,
                  :default => false,
                  :desc    => 'Force download of the artifact even if it exists'
    method_option :verify_sha1,
                  :type    => :boolean,
                  :default => true,
                  :desc    => 'Validate sha1 sum'
    desc 'install config_file', 'Install Kill Bill server and plugins according to the specified YAML configuration file.'
    def install(config_file=nil)
      help = Installer.from_file(config_file).install(options[:force_download], options[:verify_sha1])
      say help, :green unless help.nil?
    end

    method_option :destination,
                  :type    => :string,
                  :default => nil,
                  :desc    => 'A different folder other than the default bundles directory.'
    method_option :force,
                  :type    => :boolean,
                  :default => nil,
                  :desc    => 'Don\'t ask for confirmation while deleting multiple versions of a plugin.'
    desc 'uninstall plugin', 'Uninstall the specified plugin, identified by its name or key, from current deployment'
    def uninstall(plugin)
      say 'Done!' if Uninstaller.new(options[:destination]).uninstall_plugin(plugin, options[:force])
    end

    method_option :destination,
                  :type    => :string,
                  :default => nil,
                  :desc    => 'A different folder other than the current working directory.'
    method_option :force_download,
                  :type    => :boolean,
                  :default => false,
                  :desc    => 'Force download of the artifact even if it exists'
    method_option :verify_sha1,
                  :type    => :boolean,
                  :default => true,
                  :desc    => 'Validate sha1 sum'
    desc 'pull_kb_server_war <version>', 'Pulls Kill Bill server war from Sonatype and places it on your machine. If version was not specified it uses the latest released version.'
    def pull_kb_server_war(version='LATEST')
      response = KillbillServerArtifact.pull(logger,
                                             KillbillServerArtifact::KILLBILL_GROUP_ID,
                                             KillbillServerArtifact::KILLBILL_ARTIFACT_ID,
                                             KillbillServerArtifact::KILLBILL_PACKAGING,
                                             KillbillServerArtifact::KILLBILL_CLASSIFIER,
                                             version,
                                             options[:destination],
                                             nil,
                                             options[:force_download],
                                             options[:verify_sha1],
                                             options[:overrides],
                                             options[:ssl_verify])
      say "Artifact has been retrieved and can be found at path: #{response[:file_path]}", :green
    end

    desc 'search_for_kb_server', 'Searches for all versions of Kill Bill server and prints them to the screen.'
    def search_for_kb_server
      say "Available versions: #{KillbillServerArtifact.versions(KillbillServerArtifact::KILLBILL_ARTIFACT_ID,
                                                                 KillbillServerArtifact::KILLBILL_PACKAGING,
                                                                 KillbillServerArtifact::KILLBILL_CLASSIFIER,
                                                                 options[:overrides],
                                                                 options[:ssl_verify]).to_a.join(', ')}", :green
    end

    method_option :destination,
                  :type    => :string,
                  :default => nil,
                  :desc    => 'A different folder other than the current working directory.'
    method_option :force_download,
                  :type    => :boolean,
                  :default => false,
                  :desc    => 'Force download of the artifact even if it exists'
    method_option :verify_sha1,
                  :type    => :boolean,
                  :default => true,
                  :desc    => 'Validates sha1 sum'
    desc 'pull_kp_server_war <version>', 'Pulls Kill Pay server war from Sonatype and places it on your machine. If version was not specified it uses the latest released version.'
    def pull_kp_server_war(version='LATEST')
      response = KillbillServerArtifact.pull(logger,
                                             KillbillServerArtifact::KILLBILL_GROUP_ID,
                                             KillbillServerArtifact::KILLPAY_ARTIFACT_ID,
                                             KillbillServerArtifact::KILLPAY_PACKAGING,
                                             KillbillServerArtifact::KILLPAY_CLASSIFIER,
                                             version,
                                             options[:destination],
                                             nil,
                                             options[:force_download],
                                             options[:verify_sha1],
                                             options[:overrides],
                                             options[:ssl_verify])
      say "Artifact has been retrieved and can be found at path: #{response[:file_path]}", :green
    end

    desc 'search_for_kp_server', 'Searches for all versions of Kill Pay server and prints them to the screen.'
    def search_for_kp_server
      say "Available versions: #{KillbillServerArtifact.versions(KillbillServerArtifact::KILLPAY_ARTIFACT_ID,
                                                                 KillbillServerArtifact::KILLPAY_PACKAGING,
                                                                 KillbillServerArtifact::KILLPAY_CLASSIFIER,
                                                                 options[:overrides],
                                                                 options[:ssl_verify]).to_a.join(', ')}", :green
    end

    method_option :group_id,
                  :type    => :string,
                  :default => KillbillPluginArtifact::KILLBILL_JAVA_PLUGIN_GROUP_ID,
                  :desc    => 'The plugin artifact group-id'
    method_option :artifact_id,
                  :type    => :string,
                  :default => nil,
                  :desc    => 'The plugin artifact id'
    method_option :version,
                  :type    => :string,
                  :default => nil,
                  :desc    => 'The plugin artifact version'
    method_option :packaging,
                  :type    => :string,
                  :default => KillbillPluginArtifact::KILLBILL_JAVA_PLUGIN_PACKAGING,
                  :desc    => 'The plugin artifact packaging'
    method_option :classifier,
                  :type    => :string,
                  :default => KillbillPluginArtifact::KILLBILL_JAVA_PLUGIN_CLASSIFIER,
                  :desc    => 'The plugin artifact classifier'
    method_option :from_source_file,
                  :type    => :string,
                  :default => nil,
                  :desc    => 'Specify the plugin jar that should be used for the installation.'
    method_option :destination,
                  :type    => :string,
                  :default => nil,
                  :desc    => 'A different folder other than the current working directory.'
    method_option :force_download,
                  :type    => :boolean,
                  :default => false,
                  :desc    => 'Force download of the artifact even if it exists'
    method_option :sha1_file,
                  :type    => :string,
                  :default => nil,
                  :desc    => 'Location of the sha1 file'
    method_option :verify_sha1,
                  :type    => :boolean,
                  :default => true,
                  :desc    => 'Validates sha1 sum'
    desc 'install_java_plugin plugin-key <kb-version>', 'Pulls a java plugin from Sonatype and installs it under the specified destination. If the kb-version has been specified, it is used to download the matching plugin artifact version; if not, it uses the specified plugin version or if null, the LATEST one.'
    def install_java_plugin(plugin_key, kb_version='LATEST')


      installer = BaseInstaller.new(logger,
                                    options[:overrides],
                                    options[:ssl_verify])

      if options[:from_source_file].nil?
        response = installer.install_plugin(plugin_key,
                                            kb_version,
                                            options[:group_id],
                                            options[:artifact_id],
                                            options[:packaging],
                                            options[:classifier],
                                            options[:version],
                                            options[:destination],
                                            'java',
                                            options[:force_download],
                                            options[:verify_sha1],
                                            false)
      else
        response = installer.install_plugin_from_fs(plugin_key, options[:from_source_file], nil, options[:version], options[:destination], 'java')
      end

      say "Artifact has been retrieved and can be found at path: #{response[:file_path]}", :green
    end




    method_option :group_id,
                  :type    => :string,
                  :default => KillbillPluginArtifact::KILLBILL_RUBY_PLUGIN_GROUP_ID,
                  :desc    => 'The plugin artifact group-id'
    method_option :artifact_id,
                  :type    => :string,
                  :default => nil,
                  :desc    => 'The plugin artifact id'
    method_option :version,
                  :type    => :string,
                  :default => nil,
                  :desc    => 'The plugin artifact version'
    method_option :packaging,
                  :type    => :string,
                  :default => KillbillPluginArtifact::KILLBILL_RUBY_PLUGIN_PACKAGING,
                  :desc    => 'The plugin artifact packaging'
    method_option :classifier,
                  :type    => :string,
                  :default => KillbillPluginArtifact::KILLBILL_RUBY_PLUGIN_CLASSIFIER,
                  :desc    => 'The plugin artifact classifier'
    method_option :from_source_file,
                  :type    => :string,
                  :default => nil,
                  :desc    => 'Specify the ruby plugin archive that should be used for the installation.'
    method_option :destination,
                  :type    => :string,
                  :default => nil,
                  :desc    => 'A different folder other than the current working directory.'
    method_option :force_download,
                  :type    => :boolean,
                  :default => false,
                  :desc    => 'Force download of the artifact even if it exists'
    method_option :sha1_file,
                  :type    => :string,
                  :default => nil,
                  :desc    => 'Location of the sha1 file'
    method_option :verify_sha1,
                  :type    => :boolean,
                  :default => true,
                  :desc    => 'Validates sha1 sum'
    desc 'install_ruby_plugin plugin-key <kb-version>', 'Pulls a ruby plugin from Sonatype and installs it under the specified destination. If the kb-version has been specified, it is used to download the matching plugin artifact version; if not, it uses the specified plugin version or if null, the LATEST one.'
    def install_ruby_plugin(plugin_key, kb_version='LATEST')
      installer = BaseInstaller.new(logger,
                        options[:overrides],
                        options[:ssl_verify])

      if options[:from_source_file].nil?
        response = installer.install_plugin(plugin_key,
                                            kb_version,
                                            options[:group_id],
                                            options[:artifact_id],
                                            options[:packaging],
                                            options[:classifier],
                                            options[:version],
                                            options[:destination],
                                            'ruby',
                                            options[:force_download],
                                            options[:verify_sha1],
                                            true)
      else
        response = installer.install_plugin_from_fs(plugin_key, options[:from_source_file], nil, nil, options[:destination], 'ruby')
      end

      say "Artifact has been retrieved and can be found at path: #{response[:file_path]}", :green

    end

    method_option :destination,
                  :type    => :string,
                  :default => nil,
                  :desc    => 'A different folder other than the default bundles directory.'
    method_option :force_download,
                  :type    => :boolean,
                  :default => false,
                  :desc    => 'Force download of the artifact even if it exists'
    method_option :verify_sha1,
                  :type    => :boolean,
                  :default => true,
                  :desc    => 'Validates sha1 sum'
    desc 'pull_defaultbundles <kb-version>', 'Pulls the default OSGI bundles from Sonatype and places it on your machine. If the kb-version has been specified, it is used to download the matching platform artifact; if not, it uses the latest released version.'
    def pull_defaultbundles(kb_version='LATEST')
      response = BaseInstaller.new(logger,
                                   options[:overrides],
                                   options[:ssl_verify])
                              .install_default_bundles(options[:destination],
                                                       nil,
                                                       kb_version,
                                                       options[:force_download],
                                                       options[:verify_sha1])
      say "Artifact has been retrieved and can be found at path: #{response[:file_path]}", :green
    end

    desc 'search_for_plugins', 'Searches for all available plugins and prints them to the screen.'
    def search_for_plugins
      all_plugins = KillbillPluginArtifact.versions(options[:overrides], options[:ssl_verify])

      result = ''
      all_plugins.each do |type, plugins|
        result << "Available #{type} plugins:\n"
        Hash[plugins.sort].each do |name, versions|
          result << "  #{name}: #{versions.to_a.join(', ')}\n"
        end
      end

      say result, :green
    end

    method_option :destination,
                  :type    => :string,
                  :default => nil,
                  :desc    => 'A different folder other than the current working directory.'
    method_option :force_download,
                  :type    => :boolean,
                  :default => false,
                  :desc    => 'Force download of the artifact even if it exists'
    method_option :sha1_file,
                  :type    => :string,
                  :default => nil,
                  :desc    => 'Location of the sha1 file'
    method_option :verify_sha1,
                  :type    => :boolean,
                  :default => true,
                  :desc    => 'Validates sha1 sum'
    desc 'pull_kaui_war <version>', 'Pulls Kaui war from Sonatype and places it on your machine. If version was not specified it uses the latest released version.'
    def pull_kaui_war(version='LATEST')
      response = KauiArtifact.pull(logger,
                                   KauiArtifact::KAUI_GROUP_ID,
                                   KauiArtifact::KAUI_ARTIFACT_ID,
                                   KauiArtifact::KAUI_PACKAGING,
                                   KauiArtifact::KAUI_CLASSIFIER,
                                   version,
                                   options[:destination],
                                   options[:sha1_file],
                                   options[:force_download],
                                   options[:verify_sha1],
                                   options[:overrides],
                                   options[:ssl_verify])
      say "Artifact has been retrieved and can be found at path: #{response[:file_path]}", :green
    end

    desc 'search_for_kaui', 'Searches for all versions of Kaui and prints them to the screen.'
    def search_for_kaui
      say "Available versions: #{KauiArtifact.versions(options[:overrides], options[:ssl_verify]).to_a.join(', ')}", :green
    end

    method_option :version,
                  :type => :string,
                  :default => 'LATEST',
                  :desc => 'Kill Bill version'
    desc 'info', 'Describe information about a Kill Bill version'
    def info

      say "Fetching info for version #{options[:version]}...\n"

      versions_info = KillbillServerArtifact.info(options[:version],
                                         options[:overrides],
                                         options[:ssl_verify])
      say "Dependencies for version #{options[:version]}\n  " + (versions_info.map {|k,v| "#{k} #{v}"}).join("\n  "), :green
      say "\n\n"

      resolved_kb_version = versions_info['killbill']
      kb_version = resolved_kb_version.split('.').slice(0,2).join(".")

      plugins_info = KPM::PluginsDirectory.list_plugins(true, kb_version)

      say "Known plugin for KB version #{options[:version]}\n  " + (plugins_info.map {|k,v| "#{k} #{v}"}).join("\n  "), :green
    end

    method_option :destination,
                  :type    => :string,
                  :default => nil,
                  :desc    => 'Folder where to download migration files.'
    method_option :token,
                  :type => :string,
                  :default => nil,
                  :desc => 'GitHub OAuth token.'
    desc 'migrations repository from to', 'Download migration files for Kill Bill or a plugin'
    def migrations(repository, from, to = nil)
      full_repo = repository.include?('/') ? repository : "killbill/#{repository}"
      dir = KPM::Migrations.new(from, to, full_repo, options[:token], logger).save(options[:destination])
      say (dir.nil? ? 'No migration required' : "Migrations can be found at #{dir}"), :green
    end

    method_option :destination,
                  :type    => :string,
                  :default => nil,
                  :desc    => 'A different folder other than the default bundles directory.'
    desc 'inspect', 'Inspect current deployment'
    def inspect
      inspector = KPM::Inspector.new
      all_plugins = inspector.inspect(options[:destination])
      #puts all_plugins.to_json
      inspector.format(all_plugins)
    end

    map :pull_ruby_plugin => :install_ruby_plugin,
        :pull_java_plugin => :install_java_plugin

    private

    def logger
      logger       = ::Logger.new(STDOUT)
      logger.level = Logger::INFO
      logger
    end
  end
end