Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,17 @@ jobs:
- name: Run test
run: bundle exec rake compile test
timeout-minutes: 5

build-jruby:
name: build jruby
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: jruby-10
bundler-cache: true # 'bundle install' and cache
- name: Run test
run: bundle exec rake compile test
timeout-minutes: 5
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
*.bundle
*.so
*.dll
/ext/java/lib/zlib.jar
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ gem "test-unit"
gem "test-unit-ruby-core"
gem "rake"
gem "rake-compiler"
gem "ruby-maven", platform: :jruby
7 changes: 7 additions & 0 deletions Mavenfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#-*- mode: ruby -*-

jar 'org.jruby:jzlib:1.1.5'

plugin :dependency, '2.8', :outputFile => 'pkg/classpath'

# vim: syntax=Ruby
24 changes: 22 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,31 @@ end

Rake::TestTask.new(:test_internal) do |t|
t.libs << "test/lib"
t.libs << "ext/java/lib" if RUBY_ENGINE == "jruby"
t.ruby_opts << "-rhelper"
t.test_files = FileList["test/**/test_*.rb"]
end

require 'rake/extensiontask'
Rake::ExtensionTask.new("zlib")
if RUBY_PLATFORM =~ /java/
require 'rake/javaextensiontask'
Rake::JavaExtensionTask.new("zlib") do |ext|
require 'maven/ruby/maven'
# force load of versions to overwrite constants with values from repo.
load './ext/java/lib/zlib/versions.rb'
# uses Mavenfile to write classpath into pkg/classpath
# and tell maven via system properties the snakeyaml version
# this is basically the same as running from the commandline:
# rmvn dependency:build-classpath -Dsnakeyaml.version='use version from Psych::DEFAULT_SNAKEYAML_VERSION here'
Maven::Ruby::Maven.new.exec('dependency:build-classpath', '-Dverbose=true')
ext.source_version = '21'
ext.target_version = '21'
ext.classpath = File.read('pkg/classpath')
ext.ext_dir = 'ext/java'
ext.lib_dir = 'ext/java/lib'
end
else
require 'rake/extensiontask'
Rake::ExtensionTask.new("zlib")
end

task :default => [:compile, :test]
33 changes: 33 additions & 0 deletions ext/java/lib/zlib.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

require 'zlib.jar'
require 'zlib/versions'

require 'jar-dependencies'
require_jar('org.jruby', 'jzlib', Zlib::JZLIB_VERSION)

JRuby::Util.load_ext('org.jruby.ext.zlib.ZlibLibrary')

module Zlib
autoload :StringIO, 'stringio'

def self.gzip(src, opts = nil)
if Hash === opts
level = opts[:level]
strategy = opts[:strategy]
end
io = StringIO.new("".b)
GzipWriter.new(io, level, strategy) do |writer|
writer.write(src)
end
io.string
end

def self.gunzip(src)
io = StringIO.new(src)
reader = GzipReader.new(io)
result = reader.read
reader.close
result
end
end
5 changes: 5 additions & 0 deletions ext/java/lib/zlib/versions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

module Zlib
JZLIB_VERSION = "1.1.5"
end
Loading
Loading