From aff20b59dcecc5b85896eafb16edc487294d3448 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Thu, 23 Sep 2021 22:19:35 -0500 Subject: [PATCH 01/13] JRuby impl and build support --- .gitignore | 2 ++ Rakefile | 19 +++++++++++++++---- lib/io/wait.rb | 6 ++++++ 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 lib/io/wait.rb diff --git a/.gitignore b/.gitignore index 844dd72..f323705 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ *.so ChangeLog Gemfile.lock +logs/ +lib/io/wait.jar diff --git a/Rakefile b/Rakefile index 2ae431f..f883ec1 100644 --- a/Rakefile +++ b/Rakefile @@ -13,11 +13,22 @@ if RUBY_VERSION < "2.6" end libs = [] else - require 'rake/extensiontask' - extask = Rake::ExtensionTask.new(name) do |x| - x.lib_dir.sub!(%r[(?=/|\z)], "/#{RUBY_VERSION}/#{x.platform}") + if RUBY_PLATFORM =~ /java/ + require 'rake/javaextensiontask' + Rake::JavaExtensionTask.new("wait") do |ext| + require 'maven/ruby/maven' + ext.source_version = '1.8' + ext.target_version = '1.8' + ext.ext_dir = 'ext/java' + ext.lib_dir = 'lib/io' + end + else + require 'rake/extensiontask' + extask = Rake::ExtensionTask.new(name) do |x| + x.lib_dir.sub!(%r[(?=/|\z)], "/#{RUBY_VERSION}/#{x.platform}") + end + libs = ["lib/#{RUBY_VERSION}/#{extask.platform}"] end - libs = ["lib/#{RUBY_VERSION}/#{extask.platform}"] end Rake::TestTask.new(:test) do |t| diff --git a/lib/io/wait.rb b/lib/io/wait.rb new file mode 100644 index 0000000..d19028c --- /dev/null +++ b/lib/io/wait.rb @@ -0,0 +1,6 @@ +if RUBY_ENGINE == 'jruby' + require 'io/wait.jar' + JRuby::Util.load_ext("org.jruby.ext.io.wait.IOWaitLibrary") +else + require 'io/wait.so' +end From 985635cfa6eccf2bd5e412beb3c558d9f5cf59b1 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Thu, 23 Sep 2021 22:21:01 -0500 Subject: [PATCH 02/13] Add JRuby to GHA workflows --- .github/workflows/jruby.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/jruby.yml diff --git a/.github/workflows/jruby.yml b/.github/workflows/jruby.yml new file mode 100644 index 0000000..27c645d --- /dev/null +++ b/.github/workflows/jruby.yml @@ -0,0 +1,20 @@ +name: jruby + +on: [push, pull_request] + +jobs: + build: + runs-on: ${{ github.workflow }}-latest + strategy: + matrix: + ruby: [ 'jruby', '9.3' ] + steps: + - uses: actions/checkout@v2 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + - name: Set up Bundler + run: gem install rake-compiler --no-document + - name: Run test + run: rake From ff181a8fad783c6e0259c3e08226800f06f2b193 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Thu, 23 Sep 2021 22:29:37 -0500 Subject: [PATCH 03/13] ENXIO raise is broken on JRuby 9.3 and earlier See jruby/jruby#6852 --- test/io/wait/test_io_wait_uncommon.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/io/wait/test_io_wait_uncommon.rb b/test/io/wait/test_io_wait_uncommon.rb index 7b92e4c..f60623b 100644 --- a/test/io/wait/test_io_wait_uncommon.rb +++ b/test/io/wait/test_io_wait_uncommon.rb @@ -14,6 +14,8 @@ def test_tty_wait def test_fifo_wait omit 'no mkfifo' unless File.respond_to?(:mkfifo) && IO.const_defined?(:NONBLOCK) + skip 'known bogus error in JRuby 9.3.0.0 and earlier' if RUBY_ENGINE == 'jruby' && JRUBY_VERSION < '9.3.1.0' + require 'tmpdir' Dir.mktmpdir('rubytest-fifo') do |dir| fifo = "#{dir}/fifo" From b1184a66fbed030ab5a6d6fb6f72914956e8ada5 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Mon, 29 Nov 2021 08:36:40 -0600 Subject: [PATCH 04/13] Add missing bits for JRuby --- Rakefile | 8 +- ext/java/lib/io/wait.rb | 2 + .../org/jruby/ext/io/wait/IOWaitLibrary.java | 198 ++++++++++++++++++ io-wait.gemspec | 10 +- lib/io/wait.rb | 6 - 5 files changed, 215 insertions(+), 9 deletions(-) create mode 100644 ext/java/lib/io/wait.rb create mode 100644 ext/java/org/jruby/ext/io/wait/IOWaitLibrary.java delete mode 100644 lib/io/wait.rb diff --git a/Rakefile b/Rakefile index f883ec1..a31ad01 100644 --- a/Rakefile +++ b/Rakefile @@ -13,7 +13,7 @@ if RUBY_VERSION < "2.6" end libs = [] else - if RUBY_PLATFORM =~ /java/ + if RUBY_ENGINE == 'jruby' require 'rake/javaextensiontask' Rake::JavaExtensionTask.new("wait") do |ext| require 'maven/ruby/maven' @@ -32,7 +32,11 @@ else end Rake::TestTask.new(:test) do |t| - t.libs = libs + if RUBY_ENGINE == "jruby" + t.libs = ["ext/java/lib", "lib"] + else + t.libs << extask.lib_dir + end t.libs << "test/lib" t.ruby_opts << "-rhelper" t.test_files = FileList["test/**/test_*.rb"] diff --git a/ext/java/lib/io/wait.rb b/ext/java/lib/io/wait.rb new file mode 100644 index 0000000..de3ae75 --- /dev/null +++ b/ext/java/lib/io/wait.rb @@ -0,0 +1,2 @@ +require 'io/wait.jar' +JRuby::Util.load_ext("org.jruby.ext.io.wait.IOWaitLibrary") diff --git a/ext/java/org/jruby/ext/io/wait/IOWaitLibrary.java b/ext/java/org/jruby/ext/io/wait/IOWaitLibrary.java new file mode 100644 index 0000000..c4ac97d --- /dev/null +++ b/ext/java/org/jruby/ext/io/wait/IOWaitLibrary.java @@ -0,0 +1,198 @@ +/***** BEGIN LICENSE BLOCK ***** + * Version: EPL 2.0/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Eclipse Public + * License Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.eclipse.org/legal/epl-v20.html + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * Copyright (C) 2006 Nick Sieger + * + * Alternatively, the contents of this file may be used under the terms of + * either of the GNU General Public License Version 2 or later (the "GPL"), + * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the EPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the EPL, the GPL or the LGPL. + ***** END LICENSE BLOCK *****/ + +package org.jruby.ext.io.wait; + +import org.jruby.Ruby; +import org.jruby.RubyBoolean; +import org.jruby.RubyClass; +import org.jruby.RubyIO; +import org.jruby.RubyNumeric; +import org.jruby.RubySymbol; +import org.jruby.RubyTime; +import org.jruby.anno.JRubyMethod; +import org.jruby.runtime.Helpers; +import org.jruby.runtime.ThreadContext; +import org.jruby.runtime.builtin.IRubyObject; +import org.jruby.runtime.load.Library; +import org.jruby.util.io.OpenFile; + +import java.nio.channels.SelectionKey; + +/** + * @author Nick Sieger + */ +public class IOWaitLibrary implements Library { + + public void load(Ruby runtime, boolean wrap) { + RubyClass ioClass = runtime.getIO(); + ioClass.defineAnnotatedMethods(IOWaitLibrary.class); + } + + @JRubyMethod + public static IRubyObject nread(ThreadContext context, IRubyObject _io) { + Ruby runtime = context.runtime; + OpenFile fptr; + int len; +// ioctl_arg n; + RubyIO io = (RubyIO)_io; + + fptr = io.getOpenFileChecked(); + fptr.checkReadable(context); + len = fptr.readPending(); + if (len > 0) return runtime.newFixnum(len); + // TODO: better effort to get available bytes from our channel +// if (!FIONREAD_POSSIBLE_P(fptr->fd)) return INT2FIX(0); +// if (ioctl(fptr->fd, FIONREAD, &n)) return INT2FIX(0); +// if (n > 0) return ioctl_arg2num(n); + // Because we can't get an actual system-level buffer available count, we fake it by returning 1 if ready + return RubyNumeric.int2fix(runtime, fptr.readyNow(context) ? 1 : 0); + } + + /** + * returns non-nil if input available without blocking, false if EOF or not open/readable, otherwise nil. + */ + @JRubyMethod(name = "ready?") + public static IRubyObject ready(ThreadContext context, IRubyObject _io) { + RubyIO io = (RubyIO)_io; + OpenFile fptr; +// ioctl_arg n; + + fptr = io.getOpenFileChecked(); + fptr.checkReadable(context); + if (fptr.readPending() != 0) return context.tru; + // TODO: better effort to get available bytes from our channel +// if (!FIONREAD_POSSIBLE_P(fptr->fd)) return Qnil; +// if (ioctl(fptr->fd, FIONREAD, &n)) return Qnil; +// if (n > 0) return Qtrue; + return RubyBoolean.newBoolean(context, fptr.readyNow(context)); + } + + @JRubyMethod(optional = 1) + public static IRubyObject wait_readable(ThreadContext context, IRubyObject _io, IRubyObject[] argv) { + RubyIO io = (RubyIO)_io; + OpenFile fptr = io.getOpenFileChecked(); + + fptr.checkReadable(context); + + long tv = prepareTimeout(context, argv); + + if (fptr.readPending() != 0) return context.tru; + + return doWait(context, io, fptr, tv, SelectionKey.OP_READ | SelectionKey.OP_ACCEPT); + } + + /** + * waits until input available or timed out and returns self, or nil when EOF reached. + */ + @JRubyMethod(optional = 1) + public static IRubyObject wait_writable(ThreadContext context, IRubyObject _io, IRubyObject[] argv) { + RubyIO io = (RubyIO)_io; + + OpenFile fptr = io.getOpenFileChecked(); + + fptr.checkWritable(context); + + long tv = prepareTimeout(context, argv); + + return doWait(context, io, fptr, tv, SelectionKey.OP_CONNECT | SelectionKey.OP_WRITE); + } + + @JRubyMethod(optional = 2) + public static IRubyObject wait(ThreadContext context, IRubyObject _io, IRubyObject[] argv) { + RubyIO io = (RubyIO)_io; + + OpenFile fptr = io.getOpenFileChecked(); + + int ops = 0; + + if (argv.length == 2) { + if (argv[1] instanceof RubySymbol) { + RubySymbol sym = (RubySymbol) argv[1]; + switch (sym.asJavaString()) { // 7 bit comparison + case "r": + case "read": + case "readable": + ops |= SelectionKey.OP_ACCEPT | SelectionKey.OP_READ; + break; + case "w": + case "write": + case "writable": + ops |= SelectionKey.OP_CONNECT | SelectionKey.OP_WRITE; + break; + case "rw": + case "read_write": + case "readable_writable": + ops |= SelectionKey.OP_ACCEPT | SelectionKey.OP_READ | SelectionKey.OP_CONNECT | SelectionKey.OP_WRITE; + break; + default: + throw context.runtime.newArgumentError("unsupported mode: " + sym); + } + } else { + throw context.runtime.newArgumentError("unsupported mode: " + argv[1].getType()); + } + } else { + ops |= SelectionKey.OP_ACCEPT | SelectionKey.OP_READ; + } + + if ((ops & SelectionKey.OP_READ) == SelectionKey.OP_READ && fptr.readPending() != 0) return context.tru; + + long tv = prepareTimeout(context, argv); + + return doWait(context, io, fptr, tv, ops); + } + + private static IRubyObject doWait(ThreadContext context, RubyIO io, OpenFile fptr, long tv, int ops) { + boolean ready = fptr.ready(context.runtime, context.getThread(), ops, tv); + fptr.checkClosed(); + if (ready) return io; + return context.nil; + } + + private static long prepareTimeout(ThreadContext context, IRubyObject[] argv) { + IRubyObject timeout; + long tv; + switch (argv.length) { + case 2: + case 1: + timeout = argv[0]; + break; + default: + timeout = context.nil; + } + + if (timeout.isNil()) { + tv = -1; + } + else { + tv = (long)(RubyTime.convertTimeInterval(context, timeout) * 1000); + if (tv < 0) throw context.runtime.newArgumentError("time interval must be positive"); + } + return tv; + } +} diff --git a/io-wait.gemspec b/io-wait.gemspec index fc79bb4..9e34215 100644 --- a/io-wait.gemspec +++ b/io-wait.gemspec @@ -19,8 +19,16 @@ Gem::Specification.new do |spec| (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features|rakelib)/|\.(?:git|travis|circleci)|appveyor|Rakefile)}) end end - spec.extensions = %w[ext/io/wait/extconf.rb] spec.bindir = "exe" spec.executables = [] spec.require_paths = ["lib"] + + if Gem::Platform === spec.platform and spec.platform =~ 'java' or RUBY_ENGINE == 'jruby' + spec.platform = 'java' + + spec.files += Dir["ext/java/**/*.{rb,java}", "lib/io/wait.jar"] + spec.require_paths += ["ext/java/lib"] + else + spec.extensions = %w[ext/io/wait/extconf.rb] + end end diff --git a/lib/io/wait.rb b/lib/io/wait.rb deleted file mode 100644 index d19028c..0000000 --- a/lib/io/wait.rb +++ /dev/null @@ -1,6 +0,0 @@ -if RUBY_ENGINE == 'jruby' - require 'io/wait.jar' - JRuby::Util.load_ext("org.jruby.ext.io.wait.IOWaitLibrary") -else - require 'io/wait.so' -end From 9d734ce4d6b1aca9fc1d403891570dc1203848dc Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Mon, 29 Nov 2021 08:37:22 -0600 Subject: [PATCH 05/13] Add me to authors for the JRuby bits --- io-wait.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/io-wait.gemspec b/io-wait.gemspec index 9e34215..17a8b29 100644 --- a/io-wait.gemspec +++ b/io-wait.gemspec @@ -3,8 +3,8 @@ _VERSION = "0.2.2" Gem::Specification.new do |spec| spec.name = "io-wait" spec.version = _VERSION - spec.authors = ["Nobu Nakada"] - spec.email = ["nobu@ruby-lang.org"] + spec.authors = ["Nobu Nakada", "Charles Oliver Nutter"] + spec.email = ["nobu@ruby-lang.org", "headius@headius.com"] spec.summary = %q{Waits until IO is readable or writable without blocking.} spec.description = %q{Waits until IO is readable or writable without blocking.} From 23322a99529a51b3034e74014e62e17f2c41cce6 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 30 Nov 2021 01:30:18 -0600 Subject: [PATCH 06/13] Update .github/workflows/jruby.yml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Pavel Rosický --- .github/workflows/jruby.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/jruby.yml b/.github/workflows/jruby.yml index 27c645d..3f465d9 100644 --- a/.github/workflows/jruby.yml +++ b/.github/workflows/jruby.yml @@ -4,7 +4,7 @@ on: [push, pull_request] jobs: build: - runs-on: ${{ github.workflow }}-latest + runs-on: ${{ matrix.os }}-latest strategy: matrix: ruby: [ 'jruby', '9.3' ] From 906e6c91a28204e537ddf58b01dfe5c4411f9be4 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 30 Nov 2021 01:43:02 -0600 Subject: [PATCH 07/13] Fix workflow for JRuby Missing OS and using bare version number '9.3'. --- .github/workflows/jruby.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/jruby.yml b/.github/workflows/jruby.yml index 3f465d9..a5896e5 100644 --- a/.github/workflows/jruby.yml +++ b/.github/workflows/jruby.yml @@ -7,7 +7,8 @@ jobs: runs-on: ${{ matrix.os }}-latest strategy: matrix: - ruby: [ 'jruby', '9.3' ] + ruby: [ 'jruby-9.3' ] + os: [ 'ubuntu' ] steps: - uses: actions/checkout@v2 - name: Set up Ruby From e1223647387eed1ded7b16b955431b038d05e346 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 30 Nov 2021 02:55:22 -0600 Subject: [PATCH 08/13] Add dependencies to Gemfile and install for CI --- .github/workflows/jruby.yml | 4 ++-- Gemfile | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/jruby.yml b/.github/workflows/jruby.yml index a5896e5..a9be405 100644 --- a/.github/workflows/jruby.yml +++ b/.github/workflows/jruby.yml @@ -15,7 +15,7 @@ jobs: uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} - - name: Set up Bundler - run: gem install rake-compiler --no-document + - name: Install dev dependencies + run: bundle install - name: Run test run: rake diff --git a/Gemfile b/Gemfile index 1f56ad8..c3ca75c 100644 --- a/Gemfile +++ b/Gemfile @@ -7,4 +7,6 @@ group :development do gem "rake" gem "rake-compiler" gem "test-unit" + gem 'ruby-maven', :platforms => :jruby end + From a486e23a4ccc02ce553ca04812f5b90c455512ac Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 1 Feb 2022 11:55:01 -0600 Subject: [PATCH 09/13] Align with master --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index a31ad01..b28a32e 100644 --- a/Rakefile +++ b/Rakefile @@ -35,7 +35,7 @@ Rake::TestTask.new(:test) do |t| if RUBY_ENGINE == "jruby" t.libs = ["ext/java/lib", "lib"] else - t.libs << extask.lib_dir + t.libs = libs end t.libs << "test/lib" t.ruby_opts << "-rhelper" From 45d707f71117b8336879717e3464e1f17b0523be Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 1 Feb 2022 11:55:11 -0600 Subject: [PATCH 10/13] Unskip passing test --- test/io/wait/test_io_wait_uncommon.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/test/io/wait/test_io_wait_uncommon.rb b/test/io/wait/test_io_wait_uncommon.rb index f60623b..1d123df 100644 --- a/test/io/wait/test_io_wait_uncommon.rb +++ b/test/io/wait/test_io_wait_uncommon.rb @@ -14,7 +14,6 @@ def test_tty_wait def test_fifo_wait omit 'no mkfifo' unless File.respond_to?(:mkfifo) && IO.const_defined?(:NONBLOCK) - skip 'known bogus error in JRuby 9.3.0.0 and earlier' if RUBY_ENGINE == 'jruby' && JRUBY_VERSION < '9.3.1.0' require 'tmpdir' Dir.mktmpdir('rubytest-fifo') do |dir| From ef64c22bcb05b08d2e8222d3fd49676f3fa64484 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Wed, 2 Feb 2022 09:02:46 -0600 Subject: [PATCH 11/13] Remove whitespace to return to vanilla Co-authored-by: Nobuyoshi Nakada --- test/io/wait/test_io_wait_uncommon.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/test/io/wait/test_io_wait_uncommon.rb b/test/io/wait/test_io_wait_uncommon.rb index 1d123df..7b92e4c 100644 --- a/test/io/wait/test_io_wait_uncommon.rb +++ b/test/io/wait/test_io_wait_uncommon.rb @@ -14,7 +14,6 @@ def test_tty_wait def test_fifo_wait omit 'no mkfifo' unless File.respond_to?(:mkfifo) && IO.const_defined?(:NONBLOCK) - require 'tmpdir' Dir.mktmpdir('rubytest-fifo') do |dir| fifo = "#{dir}/fifo" From f1d0ed39bf3d4abc0db50b7741dfd5df2cbc7be0 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Wed, 2 Feb 2022 10:33:44 -0600 Subject: [PATCH 12/13] Reduce diff and address review comments --- .gitignore | 3 +-- Gemfile | 1 - Rakefile | 10 ++++------ 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index f323705..869dee0 100644 --- a/.gitignore +++ b/.gitignore @@ -11,7 +11,6 @@ *.bundle *.dll *.so +*.jar ChangeLog Gemfile.lock -logs/ -lib/io/wait.jar diff --git a/Gemfile b/Gemfile index c3ca75c..2a4a57c 100644 --- a/Gemfile +++ b/Gemfile @@ -9,4 +9,3 @@ group :development do gem "test-unit" gem 'ruby-maven', :platforms => :jruby end - diff --git a/Rakefile b/Rakefile index b28a32e..138e84f 100644 --- a/Rakefile +++ b/Rakefile @@ -13,7 +13,8 @@ if RUBY_VERSION < "2.6" end libs = [] else - if RUBY_ENGINE == 'jruby' + case RUBY_ENGINE + when 'jruby' require 'rake/javaextensiontask' Rake::JavaExtensionTask.new("wait") do |ext| require 'maven/ruby/maven' @@ -22,6 +23,7 @@ else ext.ext_dir = 'ext/java' ext.lib_dir = 'lib/io' end + libs = ["ext/java/lib", "lib"] else require 'rake/extensiontask' extask = Rake::ExtensionTask.new(name) do |x| @@ -32,11 +34,7 @@ else end Rake::TestTask.new(:test) do |t| - if RUBY_ENGINE == "jruby" - t.libs = ["ext/java/lib", "lib"] - else - t.libs = libs - end + t.libs = libs t.libs << "test/lib" t.ruby_opts << "-rhelper" t.test_files = FileList["test/**/test_*.rb"] From d9664487830eaf8ec1bd81d3ca79abe538a9476d Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Wed, 2 Feb 2022 23:01:42 -0600 Subject: [PATCH 13/13] Address review comments * use case/when for chained ifs * include only necessary files for JRuby --- Rakefile | 34 ++++++++++++++++------------------ io-wait.gemspec | 2 +- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/Rakefile b/Rakefile index 138e84f..9013919 100644 --- a/Rakefile +++ b/Rakefile @@ -3,7 +3,18 @@ require "rake/testtask" name = "io/wait" -if RUBY_VERSION < "2.6" +case +when RUBY_ENGINE == "jruby" + require 'rake/javaextensiontask' + Rake::JavaExtensionTask.new("wait") do |ext| + require 'maven/ruby/maven' + ext.source_version = '1.8' + ext.target_version = '1.8' + ext.ext_dir = 'ext/java' + ext.lib_dir = 'lib/io' + end + libs = ["ext/java/lib", "lib"] +when RUBY_VERSION < "2.6" task :compile do # noop end @@ -13,24 +24,11 @@ if RUBY_VERSION < "2.6" end libs = [] else - case RUBY_ENGINE - when 'jruby' - require 'rake/javaextensiontask' - Rake::JavaExtensionTask.new("wait") do |ext| - require 'maven/ruby/maven' - ext.source_version = '1.8' - ext.target_version = '1.8' - ext.ext_dir = 'ext/java' - ext.lib_dir = 'lib/io' - end - libs = ["ext/java/lib", "lib"] - else - require 'rake/extensiontask' - extask = Rake::ExtensionTask.new(name) do |x| - x.lib_dir.sub!(%r[(?=/|\z)], "/#{RUBY_VERSION}/#{x.platform}") - end - libs = ["lib/#{RUBY_VERSION}/#{extask.platform}"] + require 'rake/extensiontask' + extask = Rake::ExtensionTask.new(name) do |x| + x.lib_dir.sub!(%r[(?=/|\z)], "/#{RUBY_VERSION}/#{x.platform}") end + libs = ["lib/#{RUBY_VERSION}/#{extask.platform}"] end Rake::TestTask.new(:test) do |t| diff --git a/io-wait.gemspec b/io-wait.gemspec index 17a8b29..56826df 100644 --- a/io-wait.gemspec +++ b/io-wait.gemspec @@ -26,7 +26,7 @@ Gem::Specification.new do |spec| if Gem::Platform === spec.platform and spec.platform =~ 'java' or RUBY_ENGINE == 'jruby' spec.platform = 'java' - spec.files += Dir["ext/java/**/*.{rb,java}", "lib/io/wait.jar"] + spec.files += Dir["ext/java/lib/io/wait.rb", "lib/io/wait.jar"] spec.require_paths += ["ext/java/lib"] else spec.extensions = %w[ext/io/wait/extconf.rb]