ldp_testsuite_wrapper 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,45 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2016-02-08 11:12:25 -0800 using RuboCop version 0.37.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Cop supports --auto-correct.
11
+ # Configuration parameters: AlignWith, SupportedStyles, AutoCorrect.
12
+ # SupportedStyles: keyword, variable, start_of_line
13
+ Lint/EndAlignment:
14
+ Enabled: false
15
+
16
+ # Offense count: 1
17
+ # Configuration parameters: CountComments.
18
+ Metrics/ClassLength:
19
+ Max: 158
20
+
21
+ # Offense count: 1
22
+ Metrics/CyclomaticComplexity:
23
+ Max: 10
24
+
25
+ # Offense count: 2
26
+ # Configuration parameters: CountComments.
27
+ Metrics/MethodLength:
28
+ Max: 49
29
+
30
+ # Offense count: 1
31
+ Metrics/PerceivedComplexity:
32
+ Max: 13
33
+
34
+ # Offense count: 2
35
+ Style/Documentation:
36
+ Exclude:
37
+ - 'spec/**/*'
38
+ - 'test/**/*'
39
+ - 'lib/ldp_testsuite_wrapper.rb'
40
+ - 'lib/ldp_testsuite_wrapper/instance.rb'
41
+
42
+ # Offense count: 1
43
+ Style/DoubleNegation:
44
+ Exclude:
45
+ - 'lib/ldp_testsuite_wrapper/instance.rb'
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ sudo: false
3
+ rvm:
4
+ - 2.2.0
5
+ - jruby-9.0.1.0
6
+ cache:
7
+ directories:
8
+ - /tmp/solr-5.1.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in solr_wrapper.gemspec
4
+ gemspec
5
+
6
+ gem 'byebug'
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Chris Beer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # ldp_testsuite_wrapper
2
+
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task default: ['spec']
data/coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'ldp_testsuite_wrapper'
4
+ require 'byebug'
5
+
6
+ LdpTestsuiteWrapper.default_instance.exec(ARGV)
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ldp_testsuite_wrapper/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ldp_testsuite_wrapper"
8
+ spec.version = LdpTestsuiteWrapper::VERSION
9
+ spec.authors = ["Chris Beer"]
10
+ spec.email = ["chris@cbeer.info"]
11
+ spec.summary = %q{LDP Test Suite service wrapper}
12
+ spec.homepage = "https://github.com/cbeer/ldp_testsuite_wrapper"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.bindir = 'exe'
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "rubyzip"
22
+ spec.add_dependency "ruby-progressbar"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.7"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+
27
+ spec.add_development_dependency "rspec"
28
+ spec.add_development_dependency "coveralls"
29
+ end
@@ -0,0 +1,234 @@
1
+ require 'digest'
2
+ require 'fileutils'
3
+ require 'json'
4
+ require 'open-uri'
5
+ require 'ruby-progressbar'
6
+ require 'securerandom'
7
+ require 'socket'
8
+ require 'stringio'
9
+ require 'tmpdir'
10
+ require 'zip'
11
+
12
+ module LdpTestsuiteWrapper
13
+ class Instance
14
+ attr_reader :options, :pid
15
+
16
+ ##
17
+ # @param [Hash] options
18
+ # @option options [String] :url
19
+ # @option options [String] :download_dir Local directory to store the downloaded Solr zip and its md5 file in (overridden by :download_path)
20
+ # @option options [String] :download_path Local path for storing the downloaded Solr zip file
21
+ # @option options [Boolean] :verbose return verbose info when running commands
22
+ # @option options [Hash] :env
23
+ def initialize(options = {})
24
+ @options = options
25
+ end
26
+
27
+ ##
28
+ # Run a bin/solr command
29
+ # @param [Hash] options key-value pairs to transform into command line arguments
30
+ # @return [StringIO] an IO object for the executed shell command
31
+ # @see https://github.com/apache/lucene-solr/blob/trunk/solr/bin/solr
32
+ # If you want to pass a boolean flag, include it in the +options+ hash with its value set to +true+
33
+ # the key will be converted into a boolean flag for you.
34
+ def exec(options = {})
35
+ extract_and_configure
36
+
37
+ silence_output = !options.delete(:output)
38
+
39
+ args = if options.is_a? Array
40
+ options
41
+ else
42
+ ldp_testsuite_options.merge(options).map do |k, v|
43
+ case v
44
+ when true
45
+ "-#{k}"
46
+ when false, nil
47
+ # don't return anything
48
+ else
49
+ ["-#{k}", v.to_s]
50
+ end
51
+ end.flatten.compact
52
+ end
53
+
54
+ args = ['java', '-jar', ldp_testsuite_binary] + args
55
+
56
+ if IO.respond_to? :popen4
57
+ # JRuby
58
+ env_str = env.map { |k, v| "#{Shellwords.escape(k)}=#{Shellwords.escape(v)}" }.join(' ')
59
+ pid, input, output, error = IO.popen4(env_str + ' ' + args.join(' '))
60
+ @pid = pid
61
+ stringio = StringIO.new
62
+ if verbose? && !silence_output
63
+ IO.copy_stream(output, $stderr)
64
+ IO.copy_stream(error, $stderr)
65
+ else
66
+ IO.copy_stream(output, stringio)
67
+ IO.copy_stream(error, stringio)
68
+ end
69
+
70
+ input.close
71
+ output.close
72
+ error.close
73
+ exit_status = Process.waitpid2(@pid).last
74
+ else
75
+ IO.popen(env, args + [err: [:child, :out]]) do |io|
76
+ stringio = StringIO.new
77
+
78
+ if verbose? && !silence_output
79
+ IO.copy_stream(io, $stderr)
80
+ else
81
+ IO.copy_stream(io, stringio)
82
+ end
83
+
84
+ @pid = io.pid
85
+
86
+ _, exit_status = Process.wait2(io.pid)
87
+ end
88
+ end
89
+
90
+ stringio.rewind
91
+
92
+ [exit_status, stringio]
93
+ end
94
+
95
+ ##
96
+ # Clean up any files ldp_testsuite_wrapper may have downloaded
97
+ def clean!
98
+ stop
99
+ remove_instance_dir!
100
+ FileUtils.remove_entry(download_path) if File.exist?(download_path)
101
+ FileUtils.remove_entry(tmp_save_dir, true) if File.exist? tmp_save_dir
102
+ FileUtils.remove_entry(md5sum_path) if File.exist? md5sum_path
103
+ FileUtils.remove_entry(version_file) if File.exist? version_file
104
+ end
105
+
106
+ def configure
107
+ return if File.exist? ldp_testsuite_binary
108
+
109
+ Dir.chdir(instance_dir) do
110
+ `mvn package`
111
+ end
112
+ end
113
+
114
+ def instance_dir
115
+ @instance_dir ||= options.fetch(:instance_dir, File.join(Dir.tmpdir, File.basename(download_url, '.zip')))
116
+ end
117
+
118
+ def extract_and_configure
119
+ instance_dir = extract
120
+ configure
121
+ instance_dir
122
+ end
123
+
124
+ # rubocop:disable Lint/RescueException
125
+
126
+ # extract a copy of solr to instance_dir
127
+ # Does noting if solr already exists at instance_dir
128
+ # @return [String] instance_dir Directory where solr has been installed
129
+ def extract
130
+ return instance_dir if extracted?
131
+
132
+ zip_path = download
133
+
134
+ begin
135
+ Zip::File.open(zip_path) do |zip_file|
136
+ # Handle entries one by one
137
+ zip_file.each do |entry|
138
+ dest_file = File.join(tmp_save_dir, entry.name)
139
+ FileUtils.remove_entry(dest_file, true)
140
+ entry.extract(dest_file)
141
+ end
142
+ end
143
+
144
+ rescue Exception => e
145
+ abort "Unable to unzip #{zip_path} into #{tmp_save_dir}: #{e.message}"
146
+ end
147
+
148
+ begin
149
+ FileUtils.remove_dir(instance_dir, true)
150
+ FileUtils.cp_r File.join(tmp_save_dir, "ldp-testsuite-#{version}"), instance_dir
151
+ rescue Exception => e
152
+ abort "Unable to copy #{tmp_save_dir} to #{instance_dir}: #{e.message}"
153
+ end
154
+
155
+ instance_dir
156
+ ensure
157
+ FileUtils.remove_entry tmp_save_dir if File.exist? tmp_save_dir
158
+ end
159
+ # rubocop:enable Lint/RescueException
160
+
161
+ def version
162
+ options.fetch(:version)
163
+ end
164
+
165
+ protected
166
+
167
+ def extracted?
168
+ File.exist?(ldp_testsuite_binary)
169
+ end
170
+
171
+ def download
172
+ unless File.exist?(download_path)
173
+ fetch_with_progressbar download_url, download_path
174
+ end
175
+ download_path
176
+ end
177
+
178
+ def ldp_testsuite_options
179
+ {}
180
+ end
181
+
182
+ private
183
+
184
+ def download_url
185
+ @download_url ||= options.fetch(:url, default_download_url)
186
+ end
187
+
188
+ def default_download_url
189
+ "https://github.com/w3c/ldp-testsuite/archive/#{version}.zip"
190
+ end
191
+
192
+ def env
193
+ options.fetch(:env, {})
194
+ end
195
+
196
+ def download_path
197
+ @download_path ||= options.fetch(:download_path, default_download_path)
198
+ end
199
+
200
+ def default_download_path
201
+ File.join(download_dir, File.basename(download_url))
202
+ end
203
+
204
+ def download_dir
205
+ @download_dir ||= options.fetch(:download_dir, Dir.tmpdir)
206
+ FileUtils.mkdir_p @download_dir
207
+ @download_dir
208
+ end
209
+
210
+ def verbose?
211
+ !!options.fetch(:verbose, false)
212
+ end
213
+
214
+ def ldp_testsuite_binary
215
+ File.join(instance_dir, 'target', "ldp-testsuite-#{version}-shaded.jar")
216
+ end
217
+
218
+ def tmp_save_dir
219
+ @tmp_save_dir ||= Dir.mktmpdir
220
+ end
221
+
222
+ def fetch_with_progressbar(url, output)
223
+ pbar = ProgressBar.create(title: File.basename(url), total: nil, format: '%t: |%B| %p%% (%e )')
224
+ open(url, content_length_proc: lambda do |t|
225
+ pbar.total = t if t && 0 < t
226
+ end,
227
+ progress_proc: lambda do |s|
228
+ pbar.progress = s
229
+ end) do |io|
230
+ IO.copy_stream(io, output)
231
+ end
232
+ end
233
+ end
234
+ end
@@ -0,0 +1,3 @@
1
+ module LdpTestsuiteWrapper
2
+ VERSION = '0.0.1'.freeze
3
+ end
@@ -0,0 +1,23 @@
1
+ require 'ldp_testsuite_wrapper/version'
2
+ require 'ldp_testsuite_wrapper/instance'
3
+
4
+ module LdpTestsuiteWrapper
5
+ def self.default_test_suite_version
6
+ '0.1.1'
7
+ end
8
+
9
+ def self.default_instance_options
10
+ @default_instance_options ||= {
11
+ port: '8983',
12
+ version: LdpTestsuiteWrapper.default_test_suite_version
13
+ }
14
+ end
15
+
16
+ def self.default_instance_options=(options)
17
+ @default_instance_options = options
18
+ end
19
+
20
+ def self.default_instance(options = {})
21
+ @default_instance ||= LdpTestsuiteWrapper::Instance.new default_instance_options.merge(options)
22
+ end
23
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe LdpTestsuiteWrapper do
4
+ describe '.default_instance_options=' do
5
+ it 'sets default options' do
6
+ LdpTestsuiteWrapper.default_instance_options = { port: '1234' }
7
+ expect(LdpTestsuiteWrapper.default_instance_options[:port]). to eq '1234'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'ldp_testsuite_wrapper'
5
+
6
+ require 'rspec'
7
+ FIXTURES_DIR = File.expand_path('fixtures', File.dirname(__FILE__))
8
+
9
+ RSpec.configure do |_config|
10
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ldp_testsuite_wrapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Chris Beer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-02-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubyzip
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ruby-progressbar
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: coveralls
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - chris@cbeer.info
100
+ executables:
101
+ - ldp_testsuite_wrapper
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".rubocop.yml"
108
+ - ".rubocop_hound.yml"
109
+ - ".rubocop_todo.yml"
110
+ - ".travis.yml"
111
+ - Gemfile
112
+ - LICENSE
113
+ - README.md
114
+ - Rakefile
115
+ - coveralls.yml
116
+ - exe/ldp_testsuite_wrapper
117
+ - ldp_testsuite_wrapper.gemspec
118
+ - lib/ldp_testsuite_wrapper.rb
119
+ - lib/ldp_testsuite_wrapper/instance.rb
120
+ - lib/ldp_testsuite_wrapper/version.rb
121
+ - spec/lib/ldp_testsuite_wrapper_spec.rb
122
+ - spec/spec_helper.rb
123
+ homepage: https://github.com/cbeer/ldp_testsuite_wrapper
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.4.5.1
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: LDP Test Suite service wrapper
147
+ test_files:
148
+ - spec/lib/ldp_testsuite_wrapper_spec.rb
149
+ - spec/spec_helper.rb