Class: LdpTestsuiteWrapper::Instance
- Inherits:
-
Object
- Object
- LdpTestsuiteWrapper::Instance
- Defined in:
- lib/ldp_testsuite_wrapper/instance.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
Instance Method Summary collapse
-
#clean! ⇒ Object
Clean up any files ldp_testsuite_wrapper may have downloaded.
- #configure ⇒ Object
-
#exec(options = {}) ⇒ StringIO
Run the LDP test suite If you want to pass a boolean flag, include it in the
options
hash with its value set totrue
the key will be converted into a boolean flag for you. -
#extract ⇒ String
extract a copy of test suite to instance_dir Does noting if test suite already exists at instance_dir.
- #extract_and_configure ⇒ Object
-
#initialize(options = {}) ⇒ Instance
constructor
A new instance of Instance.
- #instance_dir ⇒ Object
-
#version ⇒ Object
rubocop:enable Lint/RescueException.
Constructor Details
#initialize(options = {}) ⇒ Instance
Returns a new instance of Instance.
23 24 25 |
# File 'lib/ldp_testsuite_wrapper/instance.rb', line 23 def initialize( = {}) @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
14 15 16 |
# File 'lib/ldp_testsuite_wrapper/instance.rb', line 14 def @options end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
14 15 16 |
# File 'lib/ldp_testsuite_wrapper/instance.rb', line 14 def pid @pid end |
Instance Method Details
#clean! ⇒ Object
Clean up any files ldp_testsuite_wrapper may have downloaded
96 97 98 99 100 101 102 |
# File 'lib/ldp_testsuite_wrapper/instance.rb', line 96 def clean! remove_instance_dir! FileUtils.remove_entry(download_path) if File.exist?(download_path) FileUtils.remove_entry(tmp_save_dir, true) if File.exist? tmp_save_dir FileUtils.remove_entry(md5sum_path) if File.exist? md5sum_path FileUtils.remove_entry(version_file) if File.exist? version_file end |
#configure ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/ldp_testsuite_wrapper/instance.rb', line 104 def configure return if File.exist? ldp_testsuite_binary Dir.chdir(instance_dir) do `mvn package` end end |
#exec(options = {}) ⇒ StringIO
Run the LDP test suite If you want to pass a boolean flag, include it in the options
hash with its value set to true
the key will be converted into a boolean flag for you.
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 |
# File 'lib/ldp_testsuite_wrapper/instance.rb', line 33 def exec( = {}) extract_and_configure silence_output = !.delete(:output) args = if .is_a? Array else .merge().map do |k, v| case v when true "-#{k}" when false, nil # don't return anything else ["-#{k}", v.to_s] end end.flatten.compact end args = ['java', '-jar', ldp_testsuite_binary] + args if IO.respond_to? :popen4 # JRuby env_str = env.map { |k, v| "#{Shellwords.escape(k)}=#{Shellwords.escape(v)}" }.join(' ') pid, input, output, error = IO.popen4(env_str + ' ' + args.join(' ')) @pid = pid stringio = StringIO.new if verbose? && !silence_output IO.copy_stream(output, $stderr) IO.copy_stream(error, $stderr) else IO.copy_stream(output, stringio) IO.copy_stream(error, stringio) end input.close output.close error.close exit_status = Process.waitpid2(@pid).last else IO.popen(env, args + [err: [:child, :out]]) do |io| stringio = StringIO.new if verbose? && !silence_output IO.copy_stream(io, $stderr) else IO.copy_stream(io, stringio) end @pid = io.pid _, exit_status = Process.wait2(io.pid) end end stringio.rewind [exit_status, stringio] end |
#extract ⇒ String
extract a copy of test suite to instance_dir Does noting if test suite already exists at instance_dir
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 |
# File 'lib/ldp_testsuite_wrapper/instance.rb', line 127 def extract return instance_dir if extracted? zip_path = download begin Zip::File.open(zip_path) do |zip_file| # Handle entries one by one zip_file.each do |entry| dest_file = File.join(tmp_save_dir, entry.name) FileUtils.remove_entry(dest_file, true) entry.extract(dest_file) end end rescue Exception => e abort "Unable to unzip #{zip_path} into #{tmp_save_dir}: #{e.}" end begin FileUtils.remove_dir(instance_dir, true) FileUtils.cp_r File.join(tmp_save_dir, zip_root_directory), instance_dir rescue Exception => e abort "Unable to copy #{tmp_save_dir} to #{instance_dir}: #{e.}" end instance_dir ensure FileUtils.remove_entry tmp_save_dir if File.exist? tmp_save_dir end |
#extract_and_configure ⇒ Object
116 117 118 119 120 |
# File 'lib/ldp_testsuite_wrapper/instance.rb', line 116 def extract_and_configure instance_dir = extract configure instance_dir end |
#instance_dir ⇒ Object
112 113 114 |
# File 'lib/ldp_testsuite_wrapper/instance.rb', line 112 def instance_dir @instance_dir ||= .fetch(:instance_dir, File.join(Dir.tmpdir, File.basename(download_url, '.zip'))) end |
#version ⇒ Object
rubocop:enable Lint/RescueException
159 160 161 |
# File 'lib/ldp_testsuite_wrapper/instance.rb', line 159 def version .fetch(:version) end |