Skip to content

Commit

Permalink
jruby support
Browse files Browse the repository at this point in the history
  • Loading branch information
ahorek committed Sep 23, 2021
1 parent f2618fa commit 3c9e522
Show file tree
Hide file tree
Showing 7 changed files with 622 additions and 29 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: CI

on: [push, pull_request]

jobs:
host:
name: ${{ matrix.os }} ${{ matrix.ruby }}
if: ${{ github.repository == 'ruby/cgi' }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-20.04
- ubuntu-18.04
- macos-11.0
- macos-10.15
- windows-latest
ruby:
- '3.0'
- 2.7
- 2.6
- 2.5
- debug
include:
- { os: ubuntu-20.04, ruby: head, ignore-pkg-error: true }
- { os: windows-latest, ruby: mingw, ignore-pkg-error: true }
- { os: windows-latest, ruby: mswin, ignore-pkg-error: true }
- { os: ubuntu-20.04, ruby: jruby-head, ignore-pkg-error: true }
exclude:
- { os: windows-latest, ruby: debug }

steps:
- uses: actions/checkout@v2

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}

- run: bundle install

- run: rake compile

- run: rake build

- run: rake test

- run: gem install pkg/*.gem
continue-on-error: ${{ matrix.ignore-pkg-error || (matrix.ruby == 'debug') }}
22 changes: 0 additions & 22 deletions .github/workflows/test.yml

This file was deleted.

41 changes: 37 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,48 @@
require "bundler/gem_tasks"
require "rake/testtask"

helper = Bundler::GemHelper.instance

lib_dir = RUBY_ENGINE == 'jruby' ? "lib/java" : "lib"

require 'rake/javaextensiontask'
Rake::JavaExtensionTask.new("cgi") do |ext|
ext.source_version = '1.8'
ext.target_version = '1.8'
ext.ext_dir = 'ext/java'
ext.lib_dir = 'lib/java'
end

java_pkg = nil
task 'compile:java' do
java_pkg = Bundler::GemHelper.instance.build_java_gem
end

unless RUBY_ENGINE == 'jruby'
require 'rake/extensiontask'
Rake::ExtensionTask.new("cgi/escape")
end

def helper.build_java_gem
file_name = nil
sh([*gem_command, "build", "-V", "--platform=java", spec_path]) do
file_name = built_gem_path
pkg = File.join(base, "pkg")
FileUtils.mkdir_p(pkg)
FileUtils.mv(file_name, pkg)
file_name = File.basename(file_name)
Bundler.ui.confirm "#{name} #{version} built to pkg/#{file_name}."
file_name = File.join(pkg, file_name)
end
file_name
end

Rake::TestTask.new(:test) do |t|
t.libs << "test/lib"
t.libs << "test/lib" << lib_dir
t.ruby_opts << "-rhelper"
t.test_files = FileList['test/**/test_*.rb']
end

require 'rake/extensiontask'
Rake::ExtensionTask.new("cgi/escape")

task :sync_tool do
require 'fileutils'
FileUtils.cp "../ruby/tool/lib/core_assertions.rb", "./test/lib"
Expand Down
17 changes: 14 additions & 3 deletions cgi.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,21 @@ Gem::Specification.new do |spec|
spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = spec.homepage

spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
`git ls-files -z 2>/dev/null`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
end
spec.bindir = "exe"
spec.executables = []

spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
`git ls-files -z 2>/dev/null`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|.github)/}) }
end

spec.require_paths = ["lib"]

if Gem::Platform === spec.platform and spec.platform =~ 'java' or RUBY_ENGINE == 'jruby'
spec.platform = 'java'
spec.require_paths.concat ["lib/java"]
spec.files.reject! {|path| path.start_with?("ext/cgi/")}
spec.files.concat ["lib/java/cgi.jar"]
else
spec.files.reject! {|path| path.start_with?("lib/java/") || path.start_with?("ext/java/")}
end
end
Loading

0 comments on commit 3c9e522

Please sign in to comment.