kpm 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db96b11608798cde3ec2a9dfd2efaa308454f4e4
4
- data.tar.gz: 61338181fe1bdf34b9c1cd94b13bd7b44478034c
3
+ metadata.gz: 7bd75221bd8f34ed62f708280f0daf46b888d9c4
4
+ data.tar.gz: 524193c742b657dd1df0a613327746a920b66303
5
5
  SHA512:
6
- metadata.gz: 03cf860cb590f67dbd904e8b26f77f7d479289b7c1a8c62bf623505736925f3e58bd8b5811f8c096103f71d17834d234d379668e891575c57612e4a13258cd42
7
- data.tar.gz: c1eced6bfdef0b4003a7f0ba6bfc612e5702d10b0fc3fb2e5993e89e3cf39d3d0d6981e0668c79ee084c5a56c6daf9d75282ff207df3f7a5c4bffda80597915b
6
+ metadata.gz: bca02c62a3a8eaa29d2633515d5e0fe8155e48d743981437ee069333b06db82018862eba5d4845aad89a7f0dc849533393908a7de717b5bd3559287baa0d52cc
7
+ data.tar.gz: a476e9358742d977dcdcd1f5e878ad2e0806274ac9548f48372859432c82e1bc90bb8f8cce73532f5eae29200e812634d5b7e28a362fb3dbf94b93594e30e1a9
@@ -0,0 +1,50 @@
1
+ KPM: the Kill Bill Package Manager
2
+ ==================================
3
+
4
+ The goal of KPM is to facilitate the installation of Kill Bill and its plugins.
5
+
6
+ kpm can be used interactively to search and download individual artifacts (Kill Bill war, plugins, etc.) or to perform an automatic Kill Bill installation using a configuration file.
7
+
8
+ Installation
9
+ ------------
10
+
11
+ gem install kpm
12
+
13
+ Ruby 2.1+ or JRuby 1.7.11+ is recommended.
14
+
15
+ Quick start
16
+ -----------
17
+
18
+ Create a kpm.yml file as follows:
19
+
20
+ killbill:
21
+ version: 0.12.1
22
+ webapp_path: /opt/tomcat/webapps/ROOT
23
+ plugins_dir: /var/tmp/bundles
24
+ plugins:
25
+ java:
26
+ - name: analytics-plugin
27
+ version: 0.7.2
28
+ ruby:
29
+ - name: stripe-plugin
30
+ version: 0.2.1
31
+ kaui:
32
+ version: LATEST
33
+ webapp_path: /opt/tomcat/webapps/kaui
34
+
35
+ This instructs kpm to:
36
+ * Download the Kill Bill war (version 0.12.1) and install it as `/opt/tomcat/webapps/ROOT`
37
+ * Setup the Analytics (Java) plugin (version 0.7.2) and the Stripe (Ruby) plugin (version 0.2.1) under `/var/tmp/bundles`
38
+ * Download the latest Kaui war and install it as `/opt/tomcat/webapps/kaui`
39
+
40
+ To start the installation:
41
+
42
+ kpm install kpm.yml
43
+
44
+ To help you with discovery of plugins, you can run
45
+
46
+ kpm search_for_plugins
47
+
48
+ This will list available (official) plugins. We maintain a list of recommended versions to use at https://github.com/killbill/killbill-cloud/blob/master/kpm/lib/kpm/plugins_directory.yml.
49
+
50
+ There are more advanced commands and options available, just run `kpm --help` for details.
data/lib/kpm.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  module KPM
2
2
  autoload :Utils, 'kpm/utils'
3
3
  autoload :BaseArtifact, 'kpm/base_artifact'
4
+ autoload :Sha1Checker, 'kpm/sha1_checker'
4
5
  autoload :KillbillServerArtifact, 'kpm/killbill_server_artifact'
5
6
  autoload :KillbillPluginArtifact, 'kpm/killbill_plugin_artifact'
6
7
  autoload :KauiArtifact, 'kpm/kaui_artifact'
@@ -35,9 +35,9 @@ module KPM
35
35
  KAUI_CLASSIFIER = nil
36
36
 
37
37
  class << self
38
- def pull(logger, group_id, artifact_id, packaging='jar', classifier=nil, version='LATEST', destination_path=nil, overrides={}, ssl_verify=true)
38
+ def pull(logger, group_id, artifact_id, packaging='jar', classifier=nil, version='LATEST', destination_path=nil, sha1_file=nil, force_download=false, overrides={}, ssl_verify=true)
39
39
  coordinates = build_coordinates(group_id, artifact_id, packaging, classifier, version)
40
- pull_and_put_in_place(logger, coordinates, destination_path, is_ruby_plugin_and_should_skip_top_dir(group_id, artifact_id), overrides, ssl_verify)
40
+ pull_and_put_in_place(logger, coordinates, destination_path, is_ruby_plugin_and_should_skip_top_dir(group_id, artifact_id), sha1_file, force_download, overrides, ssl_verify)
41
41
  end
42
42
 
43
43
  def nexus_remote(overrides={}, ssl_verify=true)
@@ -53,7 +53,7 @@ module KPM
53
53
 
54
54
  protected
55
55
 
56
- def pull_and_put_in_place(logger, coordinates, destination_path=nil, skip_top_dir=true, overrides={}, ssl_verify=true)
56
+ def pull_and_put_in_place(logger, coordinates, destination_path=nil, skip_top_dir=true, sha1_file=nil, force_download=false, overrides={}, ssl_verify=true)
57
57
  destination_path = KPM::root if destination_path.nil?
58
58
 
59
59
  # Create the destination directory
@@ -64,60 +64,103 @@ module KPM
64
64
  end
65
65
  FileUtils.mkdir_p(destination_dir)
66
66
 
67
+ # Build artifact info
68
+ artifact_info = artifact_info(coordinates, destination_path, overrides, ssl_verify)
69
+ if !force_download && skip_if_exists(artifact_info, coordinates, sha1_file)
70
+ logger.info "Skipping installation of #{coordinates} to #{artifact_info[:file_path]}, file already exists"
71
+ artifact_info[:skipped] = true
72
+ return artifact_info
73
+ end
74
+
67
75
  # Download the artifact in a temporary directory in case of failures
68
- info = {}
69
76
  Dir.mktmpdir do |tmp_destination_dir|
70
77
  logger.info " Starting download of #{coordinates} to #{tmp_destination_dir}"
71
78
 
72
- info = pull_and_verify(logger, coordinates, tmp_destination_dir, overrides, ssl_verify)
73
-
74
- # Move the file to the final destination, unpacking if necessary
75
- is_tgz = info[:file_path].end_with?('.tar.gz') || info[:file_path].end_with?('.tgz')
76
- if is_tgz
77
- Utils.unpack_tgz(info[:file_path], destination_path, skip_top_dir)
78
- FileUtils.rm info[:file_path]
79
+ downloaded_artifact_info = pull_and_verify(logger, artifact_info[:sha1], coordinates, tmp_destination_dir, sha1_file, overrides, ssl_verify)
80
+ if artifact_info[:is_tgz]
81
+ Utils.unpack_tgz(downloaded_artifact_info[:file_path], destination_path, skip_top_dir)
82
+ FileUtils.rm downloaded_artifact_info[:file_path]
79
83
  else
80
- FileUtils.mv info[:file_path], destination_path
84
+ FileUtils.mv downloaded_artifact_info[:file_path], destination_path
85
+ artifact_info[:size] = downloaded_artifact_info[:size]
81
86
  end
87
+ logger.info "Successful installation of #{coordinates} to #{artifact_info[:file_path]}"
88
+ end
89
+ artifact_info
90
+ end
82
91
 
83
- # Update the info hash with the real destination
84
- if File.directory?(destination_path) && !is_tgz
85
- destination = File.join(File.expand_path(destination_path), info[:file_name])
86
- else
87
- destination = destination_path
88
- end
89
- info[:file_path] = File.expand_path(destination)
92
+ def skip_if_exists(artifact_info, coordinates, sha1_file)
90
93
 
91
- if is_tgz
92
- info[:file_name] = nil
93
- info[:size] = nil
94
- else
95
- info[:file_name] = File.basename(destination)
96
- end
94
+ # Unclear if this is even possible
95
+ return false if artifact_info[:sha1].nil?
96
+
97
+ # Check entry in sha1_file if exists
98
+ if sha1_file && File.exists?(sha1_file)
99
+ sha1_checker = Sha1Checker.from_file(sha1_file)
100
+ local_sha1 = sha1_checker.sha1(coordinates)
101
+ return true if local_sha1 == artifact_info[:sha1]
102
+ end
97
103
 
98
- logger.info "Successful installation of #{coordinates} to #{info[:file_path]}"
104
+ # If not using sha1_file mechanism, exit early if file_path odes not exist or is a directory
105
+ if !File.exists?(artifact_info[:file_path]) ||
106
+ File.directory?(artifact_info[:file_path])
107
+ return false
99
108
  end
109
+
110
+ # Finally check if remote_sha1 matches what we have locally
111
+ local_sha1 = Digest::SHA1.file(artifact_info[:file_path]).hexdigest
112
+ local_sha1 == artifact_info[:sha1]
113
+ end
114
+
115
+
116
+ def artifact_info(coordinates, destination_path, overrides={}, ssl_verify=true)
117
+
118
+ info = {}
119
+ nexus_info = nexus_remote(overrides, ssl_verify).get_artifact_info(coordinates)
120
+
121
+ xml = REXML::Document.new(nexus_info)
122
+ repository_path = xml.elements['//repositoryPath'].text unless xml.elements['//repositoryPath'].nil?
123
+ sha1 = xml.elements['//sha1'].text unless xml.elements['//sha1'].nil?
124
+ version = xml.elements['//version'].text unless xml.elements['//version'].nil?
125
+
126
+ info[:sha1] = sha1
127
+ info[:version] = version
128
+ info[:is_tgz] = repository_path.end_with?('.tar.gz') || repository_path.end_with?('.tgz')
129
+ if File.directory?(destination_path) && !info[:is_tgz]
130
+ destination = File.join(File.expand_path(destination_path), File.basename(repository_path))
131
+ info[:file_name] = File.basename(repository_path)
132
+ else
133
+ # The destination was a fully specified path or this is an archive and we keep the directory
134
+ destination = destination_path
135
+ info[:file_name] = File.basename(destination_path) if !info[:is_tgz]
136
+ end
137
+ info[:file_path] = File.expand_path(destination)
138
+ info[:skipped] = false
100
139
  info
101
140
  end
102
141
 
103
- def pull_and_verify(logger, coordinates, destination_dir, overrides={}, ssl_verify=true)
142
+
143
+ def pull_and_verify(logger, remote_sha1, coordinates, destination_dir, sha1_file, overrides={}, ssl_verify=true)
104
144
  info = nexus_remote(overrides, ssl_verify).pull_artifact(coordinates, destination_dir)
105
- raise ArtifactCorruptedException unless verify(logger, coordinates, info[:file_path], overrides, ssl_verify)
145
+ raise ArtifactCorruptedException unless verify(logger, info[:file_path], remote_sha1)
146
+
147
+ if sha1_file
148
+ sha1_checker = Sha1Checker.from_file(sha1_file)
149
+ sha1_checker.add_or_modify_entry!(coordinates, remote_sha1)
150
+ end
151
+
106
152
  info
107
153
  end
108
154
 
109
- def verify(logger, coordinates, file_path, overrides={}, ssl_verify=true)
110
- artifact_info = nexus_remote(overrides, ssl_verify).get_artifact_info(coordinates)
111
- sha1_element = REXML::Document.new(artifact_info).elements['//sha1']
155
+ def verify(logger, file_path, remote_sha1)
112
156
  # Can't check :(
113
- if sha1_element.nil?
114
- logger.warn("Unable to find sha1 in Nexus repo for #{coordinates}. Artifact info: #{artifact_info.inspect}")
157
+ if remote_sha1.nil?
158
+ logger.warn("Unable to verify sha1 for #{coordinates}. Artifact info: #{artifact_info.inspect}")
115
159
  return true
116
160
  end
117
161
 
118
162
  local_sha1 = Digest::SHA1.file(file_path).hexdigest
119
- sha1 = sha1_element.text
120
- local_sha1 == sha1
163
+ local_sha1 == remote_sha1
121
164
  end
122
165
 
123
166
  def build_coordinates(group_id, artifact_id, packaging, classifier, version=nil)
@@ -4,6 +4,7 @@ require 'yaml'
4
4
  module KPM
5
5
  class Installer
6
6
  LATEST_VERSION = 'LATEST'
7
+ SHA1_FILENAME = 'sha1.yml'
7
8
 
8
9
  def self.from_file(config_path, logger=nil)
9
10
  Installer.new(YAML::load_file(config_path), logger)
@@ -25,7 +26,7 @@ module KPM
25
26
  @nexus_ssl_verify = !@nexus_config.nil? ? @nexus_config['ssl_verify'] : true
26
27
  end
27
28
 
28
- def install
29
+ def install(force_download=false)
29
30
  unless @config.nil?
30
31
  install_killbill_server
31
32
  install_plugins
@@ -34,6 +35,7 @@ module KPM
34
35
  unless @kaui_config.nil?
35
36
  install_kaui
36
37
  end
38
+ @force_download = force_download
37
39
  end
38
40
 
39
41
  private
@@ -46,12 +48,11 @@ module KPM
46
48
  version = @config['version'] || LATEST_VERSION
47
49
  webapp_path = @config['webapp_path'] || KPM::root
48
50
 
49
- KPM::KillbillServerArtifact.pull(@logger, group_id, artifact_id, packaging, classifier, version, webapp_path, @nexus_config, @nexus_ssl_verify)
51
+ KPM::KillbillServerArtifact.pull(@logger, group_id, artifact_id, packaging, classifier, version, webapp_path, nil, @force_download, @nexus_config, @nexus_ssl_verify)
50
52
  end
51
53
 
52
54
  def install_plugins
53
55
  bundles_dir = @config['plugins_dir']
54
-
55
56
  install_java_plugins(bundles_dir)
56
57
  install_ruby_plugins(bundles_dir)
57
58
  end
@@ -67,8 +68,9 @@ module KPM
67
68
  classifier = plugin['classifier'] || KPM::BaseArtifact::KILLBILL_JAVA_PLUGIN_CLASSIFIER
68
69
  version = plugin['version'] || LATEST_VERSION
69
70
  destination = "#{bundles_dir}/plugins/java/#{artifact_id}/#{version}"
71
+ sha1_file = "#{bundles_dir}/#{SHA1_FILENAME}"
70
72
 
71
- infos << KPM::KillbillPluginArtifact.pull(@logger, group_id, artifact_id, packaging, classifier, version, destination, @nexus_config, @nexus_ssl_verify)
73
+ infos << KPM::KillbillPluginArtifact.pull(@logger, group_id, artifact_id, packaging, classifier, version, destination, sha1_file, @force_download, @nexus_config, @nexus_ssl_verify)
72
74
  end
73
75
 
74
76
  infos
@@ -85,8 +87,9 @@ module KPM
85
87
  classifier = plugin['classifier'] || KPM::BaseArtifact::KILLBILL_RUBY_PLUGIN_CLASSIFIER
86
88
  version = plugin['version'] || LATEST_VERSION
87
89
  destination = "#{bundles_dir}/plugins/ruby"
90
+ sha1_file = "#{bundles_dir}/#{SHA1_FILENAME}"
88
91
 
89
- infos << KPM::KillbillPluginArtifact.pull(@logger, group_id, artifact_id, packaging, classifier, version, destination, @nexus_config, @nexus_ssl_verify)
92
+ infos << KPM::KillbillPluginArtifact.pull(@logger, group_id, artifact_id, packaging, classifier, version, destination, sha1_file, @force_download, @nexus_config, @nexus_ssl_verify)
90
93
  end
91
94
 
92
95
  infos
@@ -102,7 +105,7 @@ module KPM
102
105
  version = @config['default_bundles_version'] || LATEST_VERSION
103
106
  destination = "#{@config['plugins_dir']}/platform"
104
107
 
105
- info = KPM::BaseArtifact.pull(@logger, group_id, artifact_id, packaging, classifier, version, destination, @nexus_config, @nexus_ssl_verify)
108
+ info = KPM::BaseArtifact.pull(@logger, group_id, artifact_id, packaging, classifier, version, destination, nil, @force_download, @nexus_config, @nexus_ssl_verify)
106
109
 
107
110
  # The special JRuby bundle needs to be called jruby.jar
108
111
  # TODO .first - code smell
@@ -119,7 +122,7 @@ module KPM
119
122
  version = @kaui_config['version'] || LATEST_VERSION
120
123
  webapp_path = @kaui_config['webapp_path'] || KPM::root
121
124
 
122
- KPM::KauiArtifact.pull(@logger, group_id, artifact_id, packaging, classifier, version, webapp_path, @nexus_config, @nexus_ssl_verify)
125
+ KPM::KauiArtifact.pull(@logger, group_id, artifact_id, packaging, classifier, version, webapp_path, nil, @force_download, @nexus_config, @nexus_ssl_verify)
123
126
  end
124
127
  end
125
128
  end
@@ -21,7 +21,7 @@
21
21
  :paypal:
22
22
  :type: :ruby
23
23
  :artifact_id: paypal-express-plugin
24
- :stable_version: 1.7.1
24
+ :stable_version: 1.8.1
25
25
  :require:
26
26
  - :signature
27
27
  - :login
@@ -29,6 +29,6 @@
29
29
  :stripe:
30
30
  :type: :ruby
31
31
  :artifact_id: stripe-plugin
32
- :stable_version: 0.2.0
32
+ :stable_version: 0.2.1
33
33
  :require:
34
34
  - :api_secret_key
@@ -0,0 +1,61 @@
1
+ require 'logger'
2
+ require 'yaml'
3
+
4
+ module KPM
5
+ class Sha1Checker
6
+
7
+ def self.from_file(sha1_file, logger=nil)
8
+ Sha1Checker.new(sha1_file, logger)
9
+ end
10
+
11
+ def initialize(sha1_file, logger=nil)
12
+ @sha1_file = sha1_file
13
+ init!
14
+
15
+ if logger.nil?
16
+ @logger = Logger.new(STDOUT)
17
+ @logger.level = Logger::INFO
18
+ else
19
+ @logger = logger
20
+ end
21
+ end
22
+
23
+ def sha1(coordinates)
24
+ @sha1_config['sha1'][coordinates]
25
+ end
26
+
27
+ def add_or_modify_entry!(coordinates, sha1)
28
+ @sha1_config['sha1'][coordinates] = sha1
29
+ save!
30
+ end
31
+
32
+ private
33
+
34
+ def save!
35
+ Dir.mktmpdir do |tmp_destination_dir|
36
+ tmp_file = File.join(tmp_destination_dir, File.basename(@sha1_file))
37
+ File.open(tmp_file, 'w') do |file|
38
+ file.write(@sha1_config.to_yaml)
39
+ end
40
+ FileUtils.copy(tmp_file, @sha1_file)
41
+ end
42
+ reload!
43
+ end
44
+
45
+ def init!
46
+ if !File.exists?(@sha1_file)
47
+ init_config = {}
48
+ init_config['sha1'] = {}
49
+ File.open(@sha1_file, 'w') do |file|
50
+ file.write(init_config.to_yaml)
51
+ end
52
+ end
53
+ reload!
54
+ end
55
+
56
+ def reload!
57
+ @sha1_config = YAML::load_file(@sha1_file)
58
+ end
59
+
60
+ end
61
+ end
@@ -18,15 +18,24 @@ module KPM
18
18
  :default => true,
19
19
  :desc => 'Set to false to disable SSL Verification.'
20
20
 
21
+
21
22
  desc 'install config_file', 'Install Kill Bill server and plugins according to the specified YAML configuration file.'
23
+ method_option :force_download,
24
+ :type => :boolean,
25
+ :default => false,
26
+ :desc => 'Force download of the artifact even if it exists'
22
27
  def install(config_file)
23
- Installer.from_file(config_file).install
28
+ Installer.from_file(config_file).install(options[:force_download])
24
29
  end
25
30
 
26
31
  method_option :destination,
27
32
  :type => :string,
28
33
  :default => nil,
29
34
  :desc => 'A different folder other than the current working directory.'
35
+ method_option :force_download,
36
+ :type => :boolean,
37
+ :default => false,
38
+ :desc => 'Force download of the artifact even if it exists'
30
39
  desc 'pull_kb_server_war version', 'Pulls Kill Bill server war from Sonatype and places it on your machine.'
31
40
  def pull_kb_server_war(version='LATEST')
32
41
  response = KillbillServerArtifact.pull(logger,
@@ -36,6 +45,8 @@ module KPM
36
45
  KillbillServerArtifact::KILLBILL_CLASSIFIER,
37
46
  version,
38
47
  options[:destination],
48
+ nil,
49
+ options[:force_download],
39
50
  options[:overrides],
40
51
  options[:ssl_verify])
41
52
  say "Artifact has been retrieved and can be found at path: #{response[:file_path]}", :green
@@ -54,6 +65,10 @@ module KPM
54
65
  :type => :string,
55
66
  :default => nil,
56
67
  :desc => 'A different folder other than the current working directory.'
68
+ method_option :force_download,
69
+ :type => :boolean,
70
+ :default => false,
71
+ :desc => 'Force download of the artifact even if it exists'
57
72
  desc 'pull_kp_server_war version', 'Pulls Kill Pay server war from Sonatype and places it on your machine.'
58
73
  def pull_kp_server_war(version='LATEST')
59
74
  response = KillbillServerArtifact.pull(logger,
@@ -63,6 +78,8 @@ module KPM
63
78
  KillbillServerArtifact::KILLPAY_CLASSIFIER,
64
79
  version,
65
80
  options[:destination],
81
+ nil,
82
+ options[:force_download],
66
83
  options[:overrides],
67
84
  options[:ssl_verify])
68
85
  say "Artifact has been retrieved and can be found at path: #{response[:file_path]}", :green
@@ -81,6 +98,14 @@ module KPM
81
98
  :type => :string,
82
99
  :default => nil,
83
100
  :desc => 'A different folder other than the current working directory.'
101
+ method_option :force_download,
102
+ :type => :boolean,
103
+ :default => false,
104
+ :desc => 'Force download of the artifact even if it exists'
105
+ method_option :sha1_file,
106
+ :type => :string,
107
+ :default => nil,
108
+ :desc => 'Location of the sha1 file'
84
109
  desc 'pull_java_plugin artifact_id', 'Pulls a java plugin from Sonatype and places it on your machine.'
85
110
  def pull_java_plugin(artifact_id, version='LATEST')
86
111
  response = KillbillPluginArtifact.pull(logger,
@@ -90,6 +115,8 @@ module KPM
90
115
  KillbillPluginArtifact::KILLBILL_JAVA_PLUGIN_CLASSIFIER,
91
116
  version,
92
117
  options[:destination],
118
+ options[:sha1_file],
119
+ options[:force_download],
93
120
  options[:overrides],
94
121
  options[:ssl_verify])
95
122
  say "Artifact has been retrieved and can be found at path: #{response[:file_path]}", :green
@@ -99,6 +126,14 @@ module KPM
99
126
  :type => :string,
100
127
  :default => nil,
101
128
  :desc => 'A different folder other than the current working directory.'
129
+ method_option :force_download,
130
+ :type => :boolean,
131
+ :default => false,
132
+ :desc => 'Force download of the artifact even if it exists'
133
+ method_option :sha1_file,
134
+ :type => :string,
135
+ :default => nil,
136
+ :desc => 'Location of the sha1 file'
102
137
  desc 'pull_ruby_plugin artifact_id', 'Pulls a ruby plugin from Sonatype and places it on your machine.'
103
138
  def pull_ruby_plugin(artifact_id, version='LATEST')
104
139
  response = KillbillPluginArtifact.pull(logger,
@@ -108,6 +143,8 @@ module KPM
108
143
  KillbillPluginArtifact::KILLBILL_RUBY_PLUGIN_CLASSIFIER,
109
144
  version,
110
145
  options[:destination],
146
+ options[:sha1_file],
147
+ options[:force_download],
111
148
  options[:overrides],
112
149
  options[:ssl_verify])
113
150
  say "Artifact has been retrieved and can be found at path: #{response[:file_path]}", :green
@@ -132,6 +169,14 @@ module KPM
132
169
  :type => :string,
133
170
  :default => nil,
134
171
  :desc => 'A different folder other than the current working directory.'
172
+ method_option :force_download,
173
+ :type => :boolean,
174
+ :default => false,
175
+ :desc => 'Force download of the artifact even if it exists'
176
+ method_option :sha1_file,
177
+ :type => :string,
178
+ :default => nil,
179
+ :desc => 'Location of the sha1 file'
135
180
  desc 'pull_kaui_war version', 'Pulls Kaui war from Sonatype and places it on your machine.'
136
181
  def pull_kaui_war(version='LATEST')
137
182
  response = KauiArtifact.pull(logger,
@@ -141,6 +186,8 @@ module KPM
141
186
  KauiArtifact::KAUI_CLASSIFIER,
142
187
  version,
143
188
  options[:destination],
189
+ options[:sha1_file],
190
+ options[:force_download],
144
191
  options[:overrides],
145
192
  options[:ssl_verify])
146
193
  say "Artifact has been retrieved and can be found at path: #{response[:file_path]}", :green
@@ -1,3 +1,3 @@
1
1
  module KPM
2
- VERSION = '0.0.10'
2
+ VERSION = '0.0.11'
3
3
  end
@@ -10,14 +10,24 @@ describe KPM::BaseArtifact do
10
10
  it 'should be able to download and verify regular artifacts' do
11
11
  Dir.mktmpdir do |dir|
12
12
  test_download dir, 'foo-oss.pom.xml'
13
+ # Verify we skip the second time
14
+ test_download dir, 'foo-oss.pom.xml', true
15
+ # Verify the download happens when we set force_download
16
+ test_download dir, 'foo-oss.pom.xml', false, true
13
17
  end
14
18
 
15
19
  Dir.mktmpdir do |dir|
16
- test_download dir
20
+ test_download dir, nil
21
+ # Verify we skip the second time
22
+ test_download dir, nil, true
23
+ # Verify the download happens when we set force_download
24
+ test_download dir, nil, false, true
17
25
  end
26
+
27
+
18
28
  end
19
29
 
20
- # This test makes sure the top level directory is correctly skipped
30
+ # This test makes sure the top level directory is correctly verify_is_skipped
21
31
  it 'should be able to download and verify .tar.gz ruby artifacts' do
22
32
  # Use the payment-test-plugin as a test, as it is fairly small (2.5M)
23
33
  group_id = 'org.kill-bill.billing.plugin.ruby'
@@ -57,10 +67,14 @@ describe KPM::BaseArtifact do
57
67
  end
58
68
  end
59
69
 
60
- def test_download(dir, filename=nil)
70
+
71
+ def test_download(dir, filename=nil, verify_is_skipped=false, force_download=false)
61
72
  path = filename.nil? ? dir : dir + '/' + filename
62
- info = KPM::BaseArtifact.pull(@logger, 'org.kill-bill.billing', 'killbill-oss-parent', 'pom', nil, 'LATEST', path)
73
+ info = KPM::BaseArtifact.pull(@logger, 'org.kill-bill.billing', 'killbill-oss-parent', 'pom', nil, 'LATEST', path, nil, force_download, {}, true)
63
74
  info[:file_name].should == (filename.nil? ? "killbill-oss-parent-#{info[:version]}.pom" : filename)
64
- info[:size].should == File.size(info[:file_path])
75
+ info[:skipped].should == verify_is_skipped
76
+ if !info[:skipped]
77
+ info[:size].should == File.size(info[:file_path])
78
+ end
65
79
  end
66
80
  end
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+ describe KPM::Sha1Checker do
4
+
5
+ before(:all) do
6
+ @logger = Logger.new(STDOUT)
7
+ @logger.level = Logger::INFO
8
+
9
+ tmp_destination_dir = Dir.tmpdir()
10
+ init_config = File.join(File.dirname(__FILE__), 'sha1_test.yml')
11
+ FileUtils.copy(init_config, tmp_destination_dir)
12
+ @tmp_config = File.join(tmp_destination_dir, 'sha1_test.yml')
13
+ puts "tmp config = #{@tmp_config}"
14
+ @sha1_checker = KPM::Sha1Checker.from_file(@tmp_config)
15
+ end
16
+
17
+ it 'should find matching sha1' do
18
+ existing = @sha1_checker.sha1('killbill-plugin-match-1.0.0.tar.gz')
19
+ existing.should_not be_nil
20
+ existing.should == 'fce068c3fd5f95646ce0d09852f43ff67f06f0b9'
21
+ end
22
+
23
+ it 'should NOT find sha1' do
24
+ existing = @sha1_checker.sha1('killbill-plugin-nomatch-1.0.0.tar.gz')
25
+ existing.should_not be_nil
26
+ existing.should_not == 'fce068c3fd5f95646ce0d09852f43ff67f06f0b9'
27
+ end
28
+
29
+ it 'should NOT find matching sha1' do
30
+ existing = @sha1_checker.sha1('killbill-plugin-foo-1.0.0.tar.gz')
31
+ existing.should be_nil
32
+ end
33
+
34
+ it 'should add an entry and find them all' do
35
+ @sha1_checker.add_or_modify_entry!('killbill-plugin-new-1.1.0.0.tar.gz', 'abc068c3fd5f95646ce0d09852f43ff67f06f111')
36
+
37
+ existing = @sha1_checker.sha1('killbill-plugin-match-1.0.0.tar.gz')
38
+ existing.should_not be_nil
39
+ existing.should == 'fce068c3fd5f95646ce0d09852f43ff67f06f0b9'
40
+
41
+ existing = @sha1_checker.sha1('killbill-plugin-new-1.1.0.0.tar.gz')
42
+ existing.should_not be_nil
43
+ existing.should == 'abc068c3fd5f95646ce0d09852f43ff67f06f111'
44
+
45
+
46
+ existing = @sha1_checker.sha1('killbill-plugin-other-1.0.0.tar.gz')
47
+ existing.should_not be_nil
48
+ existing.should == 'bbb068c3fd5f95646ce0d09852f43ff67f06fccc'
49
+ end
50
+
51
+ it 'should add allow to modify an entry and find them all' do
52
+
53
+ existing = @sha1_checker.sha1('killbill-plugin-match-1.0.0.tar.gz')
54
+ existing.should_not be_nil
55
+ existing.should == 'fce068c3fd5f95646ce0d09852f43ff67f06f0b9'
56
+
57
+ @sha1_checker.add_or_modify_entry!('killbill-plugin-match-1.0.0.tar.gz', 'dde068c3fd5f95646ce0d09852f43ff67f06f0aa')
58
+
59
+
60
+ existing = @sha1_checker.sha1('killbill-plugin-match-1.0.0.tar.gz')
61
+ existing.should_not be_nil
62
+ existing.should == 'dde068c3fd5f95646ce0d09852f43ff67f06f0aa'
63
+
64
+ existing = @sha1_checker.sha1('killbill-plugin-other-1.0.0.tar.gz')
65
+ existing.should_not be_nil
66
+ existing.should == 'bbb068c3fd5f95646ce0d09852f43ff67f06fccc'
67
+ end
68
+
69
+ it 'should work with empty config' do
70
+
71
+ tmp_destination_dir = Dir.tmpdir()
72
+ empty_config = File.join(tmp_destination_dir, 'sha1_test.yml')
73
+ if File.exists?(empty_config)
74
+ # Just to be sure
75
+ File.delete(empty_config)
76
+ end
77
+ @sha1_checker = KPM::Sha1Checker.from_file(empty_config)
78
+
79
+ @sha1_checker.add_or_modify_entry!('killbill-plugin-new-1.1.0.0.tar.gz', 'abc068c3fd5f95646ce0d09852f43ff67f06f111')
80
+ existing = @sha1_checker.sha1('killbill-plugin-new-1.1.0.0.tar.gz')
81
+ existing.should_not be_nil
82
+ existing.should == 'abc068c3fd5f95646ce0d09852f43ff67f06f111'
83
+ end
84
+
85
+
86
+ end
@@ -0,0 +1,4 @@
1
+ sha1:
2
+ killbill-plugin-match-1.0.0.tar.gz: fce068c3fd5f95646ce0d09852f43ff67f06f0b9
3
+ killbill-plugin-nomatch-1.0.0.tar.gz: ace068c3fd5f95646ce0d09852f43ff67f06f0b8
4
+ killbill-plugin-other-1.0.0.tar.gz: bbb068c3fd5f95646ce0d09852f43ff67f06fccc
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kpm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kill Bill core team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-18 00:00:00.000000000 Z
11
+ date: 2014-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline
@@ -90,6 +90,7 @@ files:
90
90
  - ".gemrelease"
91
91
  - ".gitignore"
92
92
  - Gemfile
93
+ - README.md
93
94
  - Rakefile
94
95
  - bin/kpm
95
96
  - install_example.yml
@@ -103,6 +104,7 @@ files:
103
104
  - lib/kpm/killbill_server_artifact.rb
104
105
  - lib/kpm/plugins_directory.rb
105
106
  - lib/kpm/plugins_directory.yml
107
+ - lib/kpm/sha1_checker.rb
106
108
  - lib/kpm/tasks.rb
107
109
  - lib/kpm/utils.rb
108
110
  - lib/kpm/version.rb
@@ -111,6 +113,8 @@ files:
111
113
  - spec/kpm/remote/kaui_artifact_spec.rb
112
114
  - spec/kpm/remote/killbill_plugin_artifact_spec.rb
113
115
  - spec/kpm/remote/killbill_server_artifact_spec.rb
116
+ - spec/kpm/unit/sha1_checker_spec.rb
117
+ - spec/kpm/unit/sha1_test.yml
114
118
  - spec/spec_helper.rb
115
119
  homepage: http://kill-bill.org
116
120
  licenses:
@@ -144,4 +148,6 @@ test_files:
144
148
  - spec/kpm/remote/kaui_artifact_spec.rb
145
149
  - spec/kpm/remote/killbill_plugin_artifact_spec.rb
146
150
  - spec/kpm/remote/killbill_server_artifact_spec.rb
151
+ - spec/kpm/unit/sha1_checker_spec.rb
152
+ - spec/kpm/unit/sha1_test.yml
147
153
  - spec/spec_helper.rb