Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support for mn2pdf 1.97 #16

Merged
merged 1 commit into from
Aug 24, 2024
Merged
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
2 changes: 1 addition & 1 deletion lib/tebako-runtime/adapters/jing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# Unpack jing.jar
class Jing
tmp = DEFAULT_JAR
remove_const("DEFAULT_JAR")
remove_const("DEFAULT_JAR") if const_defined?("DEFAULT_JAR")
DEFAULT_JAR = TebakoRuntime.extract_memfs(tmp)

alias original_initialize initialize
Expand Down
23 changes: 20 additions & 3 deletions lib/tebako-runtime/adapters/mn2pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,27 @@
# POSSIBILITY OF SUCH DAMAGE.

# Unpack mn2pdf.jar
module Mn2pdf
remove_const("MN2PDF_JAR_PATH")
MN2PDF_JAR_PATH = TebakoRuntime.extract_memfs(File.join(TebakoRuntime.full_gem_path("mn2pdf"), "bin", "mn2pdf.jar"))

module TebakoRuntime
MN2PDF_J_PATH = TebakoRuntime.extract_memfs(File.join(TebakoRuntime.full_gem_path("mn2pdf"), "bin",
"mn2pdf.jar"))
end

if Mn2pdf.const_defined?("MN2PDF_JAR_PATH")
module Mn2pdf
remove_const("MN2PDF_JAR_PATH")
MN2PDF_JAR_PATH = TebakoRuntime::MN2PDF_J_PATH

Check warning on line 38 in lib/tebako-runtime/adapters/mn2pdf.rb

View check run for this annotation

Codecov / codecov/patch

lib/tebako-runtime/adapters/mn2pdf.rb#L36-L38

Added lines #L36 - L38 were not covered by tests
end
end

if Jvm.const_defined?("MN2PDF_JAR_PATH")
module Jvm
remove_const("MN2PDF_JAR_PATH")
MN2PDF_JAR_PATH = TebakoRuntime::MN2PDF_J_PATH
end
end

module Mn2pdf
singleton_class.send(:alias_method, :convert_orig, :convert)
singleton_class.send(:remove_method, :convert)

Expand Down
2 changes: 1 addition & 1 deletion lib/tebako-runtime/adapters/mnconvert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

# Unpack mn2pdf.jar
module MnConvert
remove_const("MNCONVERT_JAR_PATH")
remove_const("MNCONVERT_JAR_PATH") if const_defined?("MNCONVERT_JAR_PATH")
MNCONVERT_JAR_PATH = TebakoRuntime.extract_memfs(File.join(TebakoRuntime.full_gem_path("mnconvert"), "bin",
"mnconvert.jar"))

Expand Down
2 changes: 1 addition & 1 deletion lib/tebako-runtime/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
# POSSIBILITY OF SUCH DAMAGE.

module TebakoRuntime
VERSION = "0.5.3"
VERSION = "0.5.4"
end
20 changes: 10 additions & 10 deletions spec/pass_through_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
it "provides a stub for ffi gem in pass through mode on Windows" do
if RUBY_PLATFORM =~ /msys|mingw|cygwin/
if defined?(FFI)
FFI::Platform.send(:remove_const, :OS)
FFI::Platform.send(:remove_const, :ARCH)
FFI::Platform.send(:remove_const, :LIBPREFIX)
FFI::Platform.send(:remove_const, :LIBSUFFIX)
FFI::Platform.send(:remove_const, :PASS_THROUGH)
FFI::Platform.send(:remove_const, :OS) if Object.const_defined?(:OS)
FFI::Platform.send(:remove_const, :ARCH) if Object.const_defined?(:ARCH)
FFI::Platform.send(:remove_const, :LIBPREFIX) if Object.const_defined?(:LIBPREFIX)
FFI::Platform.send(:remove_const, :LIBSUFFIX) if Object.const_defined?(:LIBSUFFIX)
FFI::Platform.send(:remove_const, :PASS_THROUGH) if Object.const_defined?(:PASS_THROUGH)
end
ENV["TEBAKO_PASS_THROUGH"] = "1"
require "ffi"
Expand All @@ -52,11 +52,11 @@
after do
if RUBY_PLATFORM =~ /msys|mingw|cygwin/
ENV.delete("TEBAKO_PASS_THROUGH")
FFI::Platform.send(:remove_const, :OS)
FFI::Platform.send(:remove_const, :ARCH)
FFI::Platform.send(:remove_const, :LIBPREFIX)
FFI::Platform.send(:remove_const, :LIBSUFFIX)
FFI::Platform.send(:remove_const, :PASS_THROUGH)
FFI::Platform.send(:remove_const, :OS) if Object.const_defined?(:OS)
FFI::Platform.send(:remove_const, :ARCH) if Object.const_defined?(:ARCH)
FFI::Platform.send(:remove_const, :LIBPREFIX) if Object.const_defined?(:LIBPREFIX)
FFI::Platform.send(:remove_const, :LIBSUFFIX) if Object.const_defined?(:LIBSUFFIX)
FFI::Platform.send(:remove_const, :PASS_THROUGH) if Object.const_defined?(:PASS_THROUGH)
end
end
end
Expand Down
23 changes: 13 additions & 10 deletions spec/runtime_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def tmpdir_name
end

it "processes a memfs file with default settings" do
TebakoRuntime.send(:remove_const, :COMPILER_MEMFS)
TebakoRuntime.send(:remove_const, :COMPILER_MEMFS) if defined?(TebakoRuntime::COMPILER_MEMFS)
TebakoRuntime::COMPILER_MEMFS = File.join(__dir__, "fixtures", "files")

test_file = File.join(TebakoRuntime::COMPILER_MEMFS, "test1.file")
Expand All @@ -75,7 +75,7 @@ def tmpdir_name
end

it "processes memfs files with the same extension when wild option is given" do
TebakoRuntime.send(:remove_const, :COMPILER_MEMFS)
TebakoRuntime.send(:remove_const, :COMPILER_MEMFS) if defined?(TebakoRuntime::COMPILER_MEMFS)
TebakoRuntime::COMPILER_MEMFS = File.join(__dir__, "fixtures", "files")

test1_file = File.join(TebakoRuntime::COMPILER_MEMFS, "test1.file")
Expand All @@ -89,7 +89,7 @@ def tmpdir_name

it "processes a memfs file with manually set cache folder" do
cache = Pathname.new(Dir.mktmpdir("test-"))
TebakoRuntime.send(:remove_const, :COMPILER_MEMFS)
TebakoRuntime.send(:remove_const, :COMPILER_MEMFS) if defined?(TebakoRuntime::COMPILER_MEMFS)
TebakoRuntime::COMPILER_MEMFS = File.join(__dir__, "fixtures", "files")

test_file = File.join(TebakoRuntime::COMPILER_MEMFS, "test1.file")
Expand All @@ -106,7 +106,7 @@ def tmpdir_name
end

it "processes a memfs file with quoted name" do
TebakoRuntime.send(:remove_const, :COMPILER_MEMFS)
TebakoRuntime.send(:remove_const, :COMPILER_MEMFS) if defined?(TebakoRuntime::COMPILER_MEMFS)
TebakoRuntime::COMPILER_MEMFS = File.join(__dir__, "fixtures", "files")

test_file = File.join(TebakoRuntime::COMPILER_MEMFS, "test1.file")
Expand All @@ -123,7 +123,7 @@ def tmpdir_name
end

it "provides an adapter for jing gem" do
TebakoRuntime.send(:remove_const, :COMPILER_MEMFS)
TebakoRuntime.send(:remove_const, :COMPILER_MEMFS) if defined?(TebakoRuntime::COMPILER_MEMFS)
TebakoRuntime::COMPILER_MEMFS = File.join(__dir__, "fixtures", "jing")
test_schema = File.join(TebakoRuntime::COMPILER_MEMFS, "schema.rnc")
test_xml = File.join(TebakoRuntime::COMPILER_MEMFS, "valid.xml")
Expand All @@ -139,9 +139,12 @@ def tmpdir_name
end

it "provides an adapter for mn2pdf gem" do
expect(TebakoRuntime).to receive(:extract_memfs).with(File.join(TebakoRuntime.full_gem_path("mn2pdf"), "bin",
"mn2pdf.jar")).and_call_original
fake_jar_path = "/tmp/mn2pdf.jar"
expect(TebakoRuntime).to receive(:extract_memfs).with(File.join(
TebakoRuntime.full_gem_path("mn2pdf"), "bin", "mn2pdf.jar"
)).and_return(fake_jar_path)
require "mn2pdf"
expect(Jvm::MN2PDF_JAR_PATH).to eq(fake_jar_path)
end

it "provides an adapter for mnconvert gem" do
Expand All @@ -151,7 +154,7 @@ def tmpdir_name
end

it "provides an adapter for net/http gem" do
TebakoRuntime.send(:remove_const, :COMPILER_MEMFS)
TebakoRuntime.send(:remove_const, :COMPILER_MEMFS) if defined?(TebakoRuntime::COMPILER_MEMFS)
TebakoRuntime::COMPILER_MEMFS = File.join(TebakoRuntime.full_gem_path("tebako-runtime"), "lib")

tfile = File.join(TebakoRuntime.full_gem_path("tebako-runtime"), "lib", "cert", "cacert.pem.mozilla")
Expand All @@ -170,7 +173,7 @@ def tmpdir_name
end

it "provides an adapter for sassc gem" do
TebakoRuntime.send(:remove_const, :COMPILER_MEMFS)
TebakoRuntime.send(:remove_const, :COMPILER_MEMFS) if defined?(TebakoRuntime::COMPILER_MEMFS)
TebakoRuntime::COMPILER_MEMFS = __dir__

require "sassc"
Expand Down Expand Up @@ -204,7 +207,7 @@ def tmpdir_name
end

it "provides an adapter for sinatra gem" do
TebakoRuntime.send(:remove_const, :COMPILER_MEMFS)
TebakoRuntime.send(:remove_const, :COMPILER_MEMFS) if defined?(TebakoRuntime::COMPILER_MEMFS)
TebakoRuntime::COMPILER_MEMFS = __dir__

require "sinatra"
Expand Down