fcrepo_wrapper 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +1 -1
- data/exe/fcrepo_wrapper +5 -1
- data/lib/fcrepo_wrapper.rb +4 -0
- data/lib/fcrepo_wrapper/configuration.rb +147 -0
- data/lib/fcrepo_wrapper/downloader.rb +18 -0
- data/lib/fcrepo_wrapper/instance.rb +47 -181
- data/lib/fcrepo_wrapper/md5.rb +44 -0
- data/lib/fcrepo_wrapper/settings.rb +39 -0
- data/lib/fcrepo_wrapper/version.rb +1 -1
- data/spec/fixtures/sample_config.yml +1 -0
- data/spec/lib/fcrepo_wrapper/configuration_spec.rb +36 -0
- data/spec/lib/fcrepo_wrapper/instance_spec.rb +31 -0
- metadata +14 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32ab8e3c5f45580a33497d826bf7b1b709b51780
|
4
|
+
data.tar.gz: 40bf4c99f37dfb5dd1e0a3c669e656d4a7757831
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bb4083970b80e8c68b3421d93b2af097d77d2629fcbcfa1ea655f0a537d42242705e347b83893550fdba64380f6c858c09ac5827c21b93b1a6ad68dc673e9f9
|
7
|
+
data.tar.gz: 4140735815d94087e4f7b93adbe981fdbb99e33ed7e7fe75720db8c173e64be028dd5927615d4badef76e5816207f204e1561c559a1b35fedffdaee34c6cc16c
|
data/.gitignore
CHANGED
data/README.md
CHANGED
data/exe/fcrepo_wrapper
CHANGED
@@ -8,6 +8,10 @@ options = {}
|
|
8
8
|
OptionParser.new do |opts|
|
9
9
|
opts.banner = "Usage: fcrepo_wrapper [options]"
|
10
10
|
|
11
|
+
opts.on("--config", "Load configuration from a file") do |v|
|
12
|
+
options[:config] = v
|
13
|
+
end
|
14
|
+
|
11
15
|
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
12
16
|
options[:verbose] = v
|
13
17
|
end
|
@@ -20,7 +24,7 @@ OptionParser.new do |opts|
|
|
20
24
|
options[:version] = v
|
21
25
|
end
|
22
26
|
|
23
|
-
opts.on("-pPORT", "--port PORT", "Specify the port fcrepo should run at (default:
|
27
|
+
opts.on("-pPORT", "--port PORT", "Specify the port fcrepo should run at (default: 8080)") do |p|
|
24
28
|
if p == 'random'
|
25
29
|
options[:port] = nil
|
26
30
|
else
|
data/lib/fcrepo_wrapper.rb
CHANGED
@@ -0,0 +1,147 @@
|
|
1
|
+
module FcrepoWrapper
|
2
|
+
class Configuration
|
3
|
+
attr_reader :options
|
4
|
+
def initialize(options)
|
5
|
+
@options = read_config(options[:config], options[:verbose])
|
6
|
+
.merge options
|
7
|
+
end
|
8
|
+
|
9
|
+
def instance_dir
|
10
|
+
@instance_dir ||= options.fetch(:instance_dir, File.join(Dir.tmpdir, File.basename(download_url, ".jar")))
|
11
|
+
end
|
12
|
+
|
13
|
+
def download_url
|
14
|
+
@download_url ||= options.fetch(:url, default_download_url)
|
15
|
+
end
|
16
|
+
|
17
|
+
def default_download_path
|
18
|
+
File.join(download_dir, File.basename(download_url))
|
19
|
+
end
|
20
|
+
|
21
|
+
def download_path
|
22
|
+
@download_path ||= options.fetch(:download_path, default_download_path)
|
23
|
+
end
|
24
|
+
|
25
|
+
def md5sum_path
|
26
|
+
File.join(download_dir, File.basename(md5url))
|
27
|
+
end
|
28
|
+
|
29
|
+
def tmp_save_dir
|
30
|
+
@tmp_save_dir ||= Dir.mktmpdir
|
31
|
+
end
|
32
|
+
|
33
|
+
def version
|
34
|
+
@version ||= options.fetch(:version, FcrepoWrapper.default_fcrepo_version)
|
35
|
+
end
|
36
|
+
|
37
|
+
def version_file
|
38
|
+
options.fetch(:version_file, File.join(instance_dir, "VERSION"))
|
39
|
+
end
|
40
|
+
|
41
|
+
def binary_path
|
42
|
+
File.join(instance_dir, "fcrepo-webapp-#{version}-jetty-console.jar")
|
43
|
+
end
|
44
|
+
|
45
|
+
def md5url
|
46
|
+
"https://github.com/fcrepo4/fcrepo4/releases/download/fcrepo-#{version}/fcrepo-webapp-#{version}-jetty-console.jar.md5"
|
47
|
+
end
|
48
|
+
|
49
|
+
def fcrepo_options
|
50
|
+
options.fetch(:fcrepo_options, headless: nil)
|
51
|
+
end
|
52
|
+
|
53
|
+
def env
|
54
|
+
options.fetch(:env, {})
|
55
|
+
end
|
56
|
+
|
57
|
+
def verbose?
|
58
|
+
!!options.fetch(:verbose, false)
|
59
|
+
end
|
60
|
+
|
61
|
+
def managed?
|
62
|
+
File.exists?(instance_dir)
|
63
|
+
end
|
64
|
+
|
65
|
+
# @return a list of arguments to pass to the JVM
|
66
|
+
def java_options
|
67
|
+
options.fetch(:java_options, default_java_options) + ['-jar', binary_path]
|
68
|
+
end
|
69
|
+
|
70
|
+
def default_java_options
|
71
|
+
['-Dfcrepo.log.http.api=WARN',
|
72
|
+
# To avoid "WARN: The namespace of predicate:
|
73
|
+
# info:fedora/fedora-system:def/relations-external#isPartOf
|
74
|
+
# was possibly misinterpreted as:
|
75
|
+
# info:fedora/fedora-system:def/relations-external#."
|
76
|
+
'-Dfcrepo.log.kernel=ERROR',
|
77
|
+
("-Dfcrepo.home=#{fcrepo_home_dir}" if fcrepo_home_dir),
|
78
|
+
("-Dfcrepo.spring.jms.configuration=#{spring_noop_file}" unless jms_enabled?),
|
79
|
+
'-Xmx512m'].compact
|
80
|
+
end
|
81
|
+
|
82
|
+
def fcrepo_home_dir
|
83
|
+
options[:fcrepo_home_dir]
|
84
|
+
end
|
85
|
+
|
86
|
+
def port
|
87
|
+
# Check if the port option has been explicitly set to nil.
|
88
|
+
# this means to start fcrepo_wrapper on a random open port
|
89
|
+
return nil if options.key?(:port) && !options[:port]
|
90
|
+
options[:port] || FcrepoWrapper.default_instance_options[:port]
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
def read_config(config_file, verbose)
|
96
|
+
default_configuration_paths.each do |p|
|
97
|
+
path = File.expand_path(p)
|
98
|
+
config_file ||= path if File.exist? path
|
99
|
+
end
|
100
|
+
|
101
|
+
unless config_file
|
102
|
+
$stdout.puts "No config specified" if verbose
|
103
|
+
return {}
|
104
|
+
end
|
105
|
+
|
106
|
+
$stdout.puts "Loading configuration from #{config_file}" if verbose
|
107
|
+
config = YAML.load(ERB.new(IO.read(config_file)).result(binding))
|
108
|
+
unless config
|
109
|
+
$stderr.puts "Unable to parse config #{config_file}" if verbose
|
110
|
+
return {}
|
111
|
+
end
|
112
|
+
config.each_with_object({}) { |(k, v), h| h[k.to_sym] = v.to_s }
|
113
|
+
end
|
114
|
+
|
115
|
+
def default_configuration_paths
|
116
|
+
['.fcrepo_wrapper', '~/.fcrepo_wrapper']
|
117
|
+
end
|
118
|
+
|
119
|
+
def download_dir
|
120
|
+
@download_dir ||= options.fetch(:download_dir, Dir.tmpdir)
|
121
|
+
FileUtils.mkdir_p @download_dir
|
122
|
+
@download_dir
|
123
|
+
end
|
124
|
+
|
125
|
+
def default_download_url
|
126
|
+
@default_url ||= "https://github.com/fcrepo4/fcrepo4/releases/download/fcrepo-#{version}/fcrepo-webapp-#{version}-jetty-console.jar"
|
127
|
+
end
|
128
|
+
|
129
|
+
def random_open_port
|
130
|
+
socket = Socket.new(:INET, :STREAM, 0)
|
131
|
+
begin
|
132
|
+
socket.bind(Addrinfo.tcp('127.0.0.1', 0))
|
133
|
+
socket.local_address.ip_port
|
134
|
+
ensure
|
135
|
+
socket.close
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def spring_noop_file
|
140
|
+
'file://' + File.expand_path('../../../data/spring-noop.xml', __FILE__)
|
141
|
+
end
|
142
|
+
|
143
|
+
def jms_enabled?
|
144
|
+
options.fetch(:enable_jms, true)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module FcrepoWrapper
|
2
|
+
class Downloader
|
3
|
+
def self.fetch_with_progressbar(url, output)
|
4
|
+
pbar = ProgressBar.create(title: File.basename(url), total: nil, format: "%t: |%B| %p%% (%e )")
|
5
|
+
open(url, content_length_proc: lambda do|t|
|
6
|
+
if t && 0 < t
|
7
|
+
pbar.total = t
|
8
|
+
end
|
9
|
+
end,
|
10
|
+
progress_proc: lambda do|s|
|
11
|
+
pbar.progress = s
|
12
|
+
end) do |io|
|
13
|
+
IO.copy_stream(io, output)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -11,7 +11,7 @@ require 'tmpdir'
|
|
11
11
|
|
12
12
|
module FcrepoWrapper
|
13
13
|
class Instance
|
14
|
-
attr_reader :
|
14
|
+
attr_reader :config, :pid
|
15
15
|
|
16
16
|
##
|
17
17
|
# @param [Hash] options
|
@@ -29,7 +29,11 @@ module FcrepoWrapper
|
|
29
29
|
# @option options [Hash] :fcrepo_options
|
30
30
|
# @option options [Hash] :env
|
31
31
|
def initialize(options = {})
|
32
|
-
@
|
32
|
+
@config = Settings.new(Configuration.new(options))
|
33
|
+
end
|
34
|
+
|
35
|
+
def md5
|
36
|
+
@md5 ||= MD5.new(config)
|
33
37
|
end
|
34
38
|
|
35
39
|
def wrap(&_block)
|
@@ -40,30 +44,9 @@ module FcrepoWrapper
|
|
40
44
|
stop
|
41
45
|
end
|
42
46
|
|
43
|
-
# @return a list of arguments to pass to the JVM
|
44
|
-
def java_options
|
45
|
-
options.fetch(:java_options, default_java_options) + ['-jar', binary_path]
|
46
|
-
end
|
47
|
-
|
48
|
-
def default_java_options
|
49
|
-
['-Dfcrepo.log.http.api=WARN',
|
50
|
-
# To avoid "WARN: The namespace of predicate:
|
51
|
-
# info:fedora/fedora-system:def/relations-external#isPartOf
|
52
|
-
# was possibly misinterpreted as:
|
53
|
-
# info:fedora/fedora-system:def/relations-external#."
|
54
|
-
'-Dfcrepo.log.kernel=ERROR',
|
55
|
-
("-Dfcrepo.home=#{fcrepo_home_dir}" if fcrepo_home_dir),
|
56
|
-
("-Dfcrepo.spring.jms.configuration=#{spring_noop_file}" unless jms_enabled?),
|
57
|
-
'-Xmx512m'].compact
|
58
|
-
end
|
59
|
-
|
60
|
-
def fcrepo_home_dir
|
61
|
-
options[:fcrepo_home_dir]
|
62
|
-
end
|
63
|
-
|
64
47
|
def process_arguments
|
65
|
-
["java"] + java_options +
|
66
|
-
fcrepo_options.merge(port: port)
|
48
|
+
["java"] + config.java_options +
|
49
|
+
config.fcrepo_options.merge(port: port)
|
67
50
|
.map { |k, v| ["--#{k}", "#{v}"].reject(&:empty?) }.flatten
|
68
51
|
end
|
69
52
|
|
@@ -71,8 +54,8 @@ module FcrepoWrapper
|
|
71
54
|
# Start fcrepo and wait for it to become available
|
72
55
|
def start
|
73
56
|
extract_and_configure
|
74
|
-
if managed?
|
75
|
-
@pid = spawn(env, *process_arguments)
|
57
|
+
if config.managed?
|
58
|
+
@pid = spawn(config.env, *process_arguments)
|
76
59
|
|
77
60
|
# Wait for fcrepo to start
|
78
61
|
while !status
|
@@ -84,7 +67,7 @@ module FcrepoWrapper
|
|
84
67
|
##
|
85
68
|
# Stop fcrepo and wait for it to finish exiting
|
86
69
|
def stop
|
87
|
-
if managed? && started?
|
70
|
+
if config.managed? && started?
|
88
71
|
Process.kill 'HUP', pid
|
89
72
|
|
90
73
|
# Wait for fcrepo to stop
|
@@ -101,7 +84,7 @@ module FcrepoWrapper
|
|
101
84
|
##
|
102
85
|
# Stop fcrepo and wait for it to finish exiting
|
103
86
|
def restart
|
104
|
-
if managed? && started?
|
87
|
+
if config.managed? && started?
|
105
88
|
stop
|
106
89
|
start
|
107
90
|
end
|
@@ -110,12 +93,16 @@ module FcrepoWrapper
|
|
110
93
|
##
|
111
94
|
# Check the status of a managed fcrepo service
|
112
95
|
def status
|
113
|
-
return true unless managed?
|
96
|
+
return true unless config.managed?
|
114
97
|
return false if pid.nil?
|
115
98
|
|
116
99
|
begin
|
117
100
|
Process.getpgid(pid)
|
101
|
+
rescue Errno::ESRCH
|
102
|
+
return false
|
103
|
+
end
|
118
104
|
|
105
|
+
begin
|
119
106
|
TCPSocket.new(host, port).close
|
120
107
|
|
121
108
|
Net::HTTP.start(host, port) do |http|
|
@@ -123,7 +110,7 @@ module FcrepoWrapper
|
|
123
110
|
end
|
124
111
|
|
125
112
|
true
|
126
|
-
rescue Errno::
|
113
|
+
rescue Errno::ECONNREFUSED, Errno::EINVAL
|
127
114
|
false
|
128
115
|
end
|
129
116
|
end
|
@@ -140,11 +127,18 @@ module FcrepoWrapper
|
|
140
127
|
'127.0.0.1'
|
141
128
|
end
|
142
129
|
|
143
|
-
##
|
144
|
-
# Get the port this fcrepo instance is running at
|
145
130
|
def port
|
146
|
-
|
147
|
-
|
131
|
+
config.port
|
132
|
+
end
|
133
|
+
|
134
|
+
##
|
135
|
+
# Get a (likely) URL to the fcrepo instance
|
136
|
+
def url
|
137
|
+
"http://#{host}:#{port}/"
|
138
|
+
end
|
139
|
+
|
140
|
+
def version
|
141
|
+
config.version
|
148
142
|
end
|
149
143
|
|
150
144
|
##
|
@@ -152,32 +146,22 @@ module FcrepoWrapper
|
|
152
146
|
def clean!
|
153
147
|
stop
|
154
148
|
remove_instance_dir!
|
155
|
-
FileUtils.remove_entry(download_path) if File.exists?(download_path)
|
156
|
-
FileUtils.remove_entry(tmp_save_dir, true) if File.exists? tmp_save_dir
|
157
|
-
|
158
|
-
FileUtils.remove_entry(version_file) if File.exists? version_file
|
149
|
+
FileUtils.remove_entry(config.download_path) if File.exists?(config.download_path)
|
150
|
+
FileUtils.remove_entry(config.tmp_save_dir, true) if File.exists? config.tmp_save_dir
|
151
|
+
md5.clean!
|
152
|
+
FileUtils.remove_entry(config.version_file) if File.exists? config.version_file
|
159
153
|
end
|
160
154
|
|
161
155
|
##
|
162
156
|
# Clean up any files in the fcrepo instance dir
|
163
157
|
def remove_instance_dir!
|
164
|
-
FileUtils.remove_entry(instance_dir, true) if File.exists? instance_dir
|
165
|
-
end
|
166
|
-
|
167
|
-
##
|
168
|
-
# Get a (likely) URL to the fcrepo instance
|
169
|
-
def url
|
170
|
-
"http://#{host}:#{port}/"
|
158
|
+
FileUtils.remove_entry(config.instance_dir, true) if File.exists? config.instance_dir
|
171
159
|
end
|
172
160
|
|
173
161
|
def configure
|
174
162
|
raise_error_unless_extracted
|
175
163
|
end
|
176
164
|
|
177
|
-
def instance_dir
|
178
|
-
@instance_dir ||= options.fetch(:instance_dir, File.join(Dir.tmpdir, File.basename(download_url, ".jar")))
|
179
|
-
end
|
180
|
-
|
181
165
|
def extract_and_configure
|
182
166
|
instance_dir = extract
|
183
167
|
configure
|
@@ -188,164 +172,46 @@ module FcrepoWrapper
|
|
188
172
|
# Does noting if fcrepo already exists at instance_dir
|
189
173
|
# @return [String] instance_dir Directory where fcrepo has been installed
|
190
174
|
def extract
|
191
|
-
return instance_dir if extracted?
|
175
|
+
return config.instance_dir if extracted?
|
192
176
|
|
193
177
|
jar_file = download
|
194
178
|
|
195
|
-
FileUtils.mkdir_p instance_dir
|
196
|
-
FileUtils.cp jar_file, binary_path
|
197
|
-
self.extracted_version = version
|
179
|
+
FileUtils.mkdir_p config.instance_dir
|
180
|
+
FileUtils.cp jar_file, config.binary_path
|
181
|
+
self.extracted_version = config.version
|
198
182
|
|
199
|
-
instance_dir
|
183
|
+
config.instance_dir
|
200
184
|
end
|
201
185
|
# rubocop:enable Lint/RescueException
|
202
186
|
|
203
|
-
def version
|
204
|
-
@version ||= options.fetch(:version, FcrepoWrapper.default_fcrepo_version)
|
205
|
-
end
|
206
|
-
|
207
187
|
protected
|
208
188
|
|
209
189
|
def extracted?
|
210
|
-
File.exists?(binary_path) && extracted_version == version
|
190
|
+
File.exists?(config.binary_path) && extracted_version == config.version
|
211
191
|
end
|
212
192
|
|
213
193
|
def download
|
214
|
-
unless File.exists?(download_path) && validate?(download_path)
|
215
|
-
fetch_with_progressbar download_url, download_path
|
216
|
-
validate! download_path
|
217
|
-
end
|
218
|
-
download_path
|
219
|
-
end
|
220
|
-
|
221
|
-
def validate?(file)
|
222
|
-
return true if options[:validate] == false
|
223
|
-
|
224
|
-
Digest::MD5.file(file).hexdigest == expected_md5sum
|
225
|
-
end
|
226
|
-
|
227
|
-
def validate!(file)
|
228
|
-
unless validate? file
|
229
|
-
raise "MD5 mismatch" unless options[:ignore_md5sum]
|
194
|
+
unless File.exists?(config.download_path) && validate?(config.download_path)
|
195
|
+
Downloader.fetch_with_progressbar config.download_url, config.download_path
|
196
|
+
validate! config.download_path
|
230
197
|
end
|
198
|
+
config.download_path
|
231
199
|
end
|
232
200
|
|
233
201
|
private
|
234
202
|
|
235
|
-
def download_url
|
236
|
-
@download_url ||= options.fetch(:url, default_download_url)
|
237
|
-
end
|
238
|
-
|
239
|
-
def default_download_url
|
240
|
-
@default_url ||= "https://github.com/fcrepo4/fcrepo4/releases/download/fcrepo-#{version}/fcrepo-webapp-#{version}-jetty-console.jar"
|
241
|
-
end
|
242
|
-
|
243
|
-
def md5url
|
244
|
-
"https://github.com/fcrepo4/fcrepo4/releases/download/fcrepo-#{version}/fcrepo-webapp-#{version}-jetty-console.jar.md5"
|
245
|
-
end
|
246
|
-
|
247
|
-
def fcrepo_options
|
248
|
-
options.fetch(:fcrepo_options, headless: nil)
|
249
|
-
end
|
250
|
-
|
251
|
-
def env
|
252
|
-
options.fetch(:env, {})
|
253
|
-
end
|
254
|
-
|
255
|
-
def download_path
|
256
|
-
@download_path ||= options.fetch(:download_path, default_download_path)
|
257
|
-
end
|
258
|
-
|
259
|
-
def default_download_path
|
260
|
-
File.join(download_dir, File.basename(download_url))
|
261
|
-
end
|
262
|
-
|
263
|
-
def download_dir
|
264
|
-
@download_dir ||= options.fetch(:download_dir, Dir.tmpdir)
|
265
|
-
FileUtils.mkdir_p @download_dir
|
266
|
-
@download_dir
|
267
|
-
end
|
268
|
-
|
269
|
-
def verbose?
|
270
|
-
!!options.fetch(:verbose, false)
|
271
|
-
end
|
272
|
-
|
273
|
-
def managed?
|
274
|
-
File.exists?(instance_dir)
|
275
|
-
end
|
276
|
-
|
277
|
-
def version_file
|
278
|
-
options.fetch(:version_file, File.join(instance_dir, "VERSION"))
|
279
|
-
end
|
280
|
-
|
281
|
-
def expected_md5sum
|
282
|
-
@md5sum ||= options.fetch(:md5sum, open(md5file).read.split(" ").first)
|
283
|
-
end
|
284
|
-
|
285
|
-
def binary_path
|
286
|
-
File.join(instance_dir, "fcrepo-webapp-#{version}-jetty-console.jar")
|
287
|
-
end
|
288
|
-
|
289
|
-
def md5sum_path
|
290
|
-
File.join(download_dir, File.basename(md5url))
|
291
|
-
end
|
292
|
-
|
293
|
-
def tmp_save_dir
|
294
|
-
@tmp_save_dir ||= Dir.mktmpdir
|
295
|
-
end
|
296
|
-
|
297
|
-
def fetch_with_progressbar(url, output)
|
298
|
-
pbar = ProgressBar.create(title: File.basename(url), total: nil, format: "%t: |%B| %p%% (%e )")
|
299
|
-
open(url, content_length_proc: lambda do|t|
|
300
|
-
if t && 0 < t
|
301
|
-
pbar.total = t
|
302
|
-
end
|
303
|
-
end,
|
304
|
-
progress_proc: lambda do|s|
|
305
|
-
pbar.progress = s
|
306
|
-
end) do |io|
|
307
|
-
IO.copy_stream(io, output)
|
308
|
-
end
|
309
|
-
end
|
310
|
-
|
311
|
-
def md5file
|
312
|
-
unless File.exists? md5sum_path
|
313
|
-
fetch_with_progressbar md5url, md5sum_path
|
314
|
-
end
|
315
|
-
|
316
|
-
md5sum_path
|
317
|
-
end
|
318
|
-
|
319
203
|
def extracted_version
|
320
|
-
File.read(version_file).strip if File.exists? version_file
|
204
|
+
File.read(config.version_file).strip if File.exists? config.version_file
|
321
205
|
end
|
322
206
|
|
323
207
|
def extracted_version=(version)
|
324
|
-
File.open(version_file, "w") do |f|
|
208
|
+
File.open(config.version_file, "w") do |f|
|
325
209
|
f.puts version
|
326
210
|
end
|
327
211
|
end
|
328
212
|
|
329
|
-
def random_open_port
|
330
|
-
socket = Socket.new(:INET, :STREAM, 0)
|
331
|
-
begin
|
332
|
-
socket.bind(Addrinfo.tcp('127.0.0.1', 0))
|
333
|
-
socket.local_address.ip_port
|
334
|
-
ensure
|
335
|
-
socket.close
|
336
|
-
end
|
337
|
-
end
|
338
|
-
|
339
213
|
def raise_error_unless_extracted
|
340
|
-
raise RuntimeError, "there is no fcrepo instance at #{instance_dir}. Run FcrepoWrapper.extract first." unless extracted?
|
341
|
-
end
|
342
|
-
|
343
|
-
def spring_noop_file
|
344
|
-
'file://' + File.expand_path('../../../data/spring-noop.xml', __FILE__)
|
345
|
-
end
|
346
|
-
|
347
|
-
def jms_enabled?
|
348
|
-
options.fetch(:enable_jms, true)
|
214
|
+
raise RuntimeError, "there is no fcrepo instance at #{config.instance_dir}. Run FcrepoWrapper.extract first." unless extracted?
|
349
215
|
end
|
350
216
|
end
|
351
217
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module FcrepoWrapper
|
2
|
+
class MD5
|
3
|
+
attr_reader :config
|
4
|
+
def initialize(config)
|
5
|
+
@config = config
|
6
|
+
end
|
7
|
+
|
8
|
+
def clean!
|
9
|
+
FileUtils.remove_entry(config.md5sum_path) if File.exists? config.md5sum_path
|
10
|
+
end
|
11
|
+
|
12
|
+
def validate?(file)
|
13
|
+
return true if config.validate == false
|
14
|
+
|
15
|
+
Digest::MD5.file(file).hexdigest == expected_sum
|
16
|
+
end
|
17
|
+
|
18
|
+
def validate!(file)
|
19
|
+
unless validate? file
|
20
|
+
raise "MD5 mismatch" unless config.ignore_md5sum
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def expected_sum
|
27
|
+
@md5sum ||= config.md5sum
|
28
|
+
@md5sum ||= read_file
|
29
|
+
end
|
30
|
+
|
31
|
+
def read_file
|
32
|
+
open(md5file).read.split(" ").first
|
33
|
+
end
|
34
|
+
|
35
|
+
def md5file
|
36
|
+
unless File.exists? config.md5sum_path
|
37
|
+
Downloader.fetch_with_progressbar config.md5url, config.md5sum_path
|
38
|
+
end
|
39
|
+
|
40
|
+
config.md5sum_path
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module FcrepoWrapper
|
2
|
+
# Configuraton that comes from static and dynamic sources.
|
3
|
+
class Settings < Delegator
|
4
|
+
def __getobj__
|
5
|
+
@static_config # return object we are delegating to, required
|
6
|
+
end
|
7
|
+
|
8
|
+
alias static_config __getobj__
|
9
|
+
|
10
|
+
def __setobj__(obj)
|
11
|
+
@static_config = obj
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(static_config)
|
15
|
+
super
|
16
|
+
@static_config = static_config
|
17
|
+
end
|
18
|
+
|
19
|
+
##
|
20
|
+
# Get the port this fcrepo instance is running at
|
21
|
+
def port
|
22
|
+
@port ||= static_config.port
|
23
|
+
@port ||= random_open_port.to_s
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def random_open_port
|
29
|
+
socket = Socket.new(:INET, :STREAM, 0)
|
30
|
+
begin
|
31
|
+
socket.bind(Addrinfo.tcp('127.0.0.1', 0))
|
32
|
+
socket.local_address.ip_port
|
33
|
+
ensure
|
34
|
+
socket.close
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
port: 9999
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FcrepoWrapper::Configuration do
|
4
|
+
let(:config) { described_class.new options }
|
5
|
+
|
6
|
+
describe "#port" do
|
7
|
+
subject { config.port }
|
8
|
+
|
9
|
+
context "when port is set to nil" do
|
10
|
+
let(:options) { { port: nil } }
|
11
|
+
it { is_expected.to eq nil }
|
12
|
+
end
|
13
|
+
|
14
|
+
context "when port is not set" do
|
15
|
+
let(:options) { {} }
|
16
|
+
it { is_expected.to eq '8080' }
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when a port is provided" do
|
20
|
+
let(:options) { { port: '8888' } }
|
21
|
+
it { is_expected.to eq '8888' }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#read_config" do
|
26
|
+
before do
|
27
|
+
allow(config).to receive(:default_configuration_paths).and_return([])
|
28
|
+
end
|
29
|
+
let(:options) { { config: 'spec/fixtures/sample_config.yml' } }
|
30
|
+
it "uses values from the config file" do
|
31
|
+
expect(config.port).to eq '9999'
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FcrepoWrapper::Instance do
|
4
|
+
let(:wrapper) { described_class.new }
|
5
|
+
|
6
|
+
describe "#host" do
|
7
|
+
subject { wrapper.host }
|
8
|
+
it { is_expected.to eq '127.0.0.1' }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#port" do
|
12
|
+
subject { wrapper.port }
|
13
|
+
it { is_expected.to eq '8080' }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#url" do
|
17
|
+
subject { wrapper.url }
|
18
|
+
it { is_expected.to eq 'http://127.0.0.1:8080/' }
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#version" do
|
22
|
+
subject { wrapper.version }
|
23
|
+
it { is_expected.to eq '4.5.0' }
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#md5" do
|
27
|
+
subject { wrapper.md5 }
|
28
|
+
it { is_expected.to be_instance_of FcrepoWrapper::MD5 }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fcrepo_wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Beer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-progressbar
|
@@ -116,10 +116,17 @@ files:
|
|
116
116
|
- exe/fcrepo_wrapper
|
117
117
|
- fcrepo_wrapper.gemspec
|
118
118
|
- lib/fcrepo_wrapper.rb
|
119
|
+
- lib/fcrepo_wrapper/configuration.rb
|
120
|
+
- lib/fcrepo_wrapper/downloader.rb
|
119
121
|
- lib/fcrepo_wrapper/instance.rb
|
122
|
+
- lib/fcrepo_wrapper/md5.rb
|
120
123
|
- lib/fcrepo_wrapper/rake_task.rb
|
124
|
+
- lib/fcrepo_wrapper/settings.rb
|
121
125
|
- lib/fcrepo_wrapper/tasks/fcrepo_wrapper.rake
|
122
126
|
- lib/fcrepo_wrapper/version.rb
|
127
|
+
- spec/fixtures/sample_config.yml
|
128
|
+
- spec/lib/fcrepo_wrapper/configuration_spec.rb
|
129
|
+
- spec/lib/fcrepo_wrapper/instance_spec.rb
|
123
130
|
- spec/lib/fcrepo_wrapper_spec.rb
|
124
131
|
- spec/spec_helper.rb
|
125
132
|
homepage: https://github.com/cbeer/fcrepo_wrapper
|
@@ -142,10 +149,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
149
|
version: '0'
|
143
150
|
requirements: []
|
144
151
|
rubyforge_project:
|
145
|
-
rubygems_version: 2.
|
152
|
+
rubygems_version: 2.5.1
|
146
153
|
signing_key:
|
147
154
|
specification_version: 4
|
148
155
|
summary: Solr 5 service wrapper
|
149
156
|
test_files:
|
157
|
+
- spec/fixtures/sample_config.yml
|
158
|
+
- spec/lib/fcrepo_wrapper/configuration_spec.rb
|
159
|
+
- spec/lib/fcrepo_wrapper/instance_spec.rb
|
150
160
|
- spec/lib/fcrepo_wrapper_spec.rb
|
151
161
|
- spec/spec_helper.rb
|
162
|
+
has_rdoc:
|