From 18f57f36ed9828eb360bb4233e57a3e253870a5b Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Thu, 18 Jan 2024 19:45:05 -0600 Subject: [PATCH 1/4] Add JRuby extension to the gem This pulls in the nkf extension implementation from JRuby. The build and load logic has been updated along the same lines as ruby/digest and the gem appears to build correctly for the -java platform. Fixes #13 --- .gitignore | 3 + Rakefile | 16 +- ext/java/org/jruby/ext/nkf/Command.java | 59 ++ ext/java/org/jruby/ext/nkf/CommandParser.java | 71 +++ ext/java/org/jruby/ext/nkf/NKFLibrary.java | 13 + ext/java/org/jruby/ext/nkf/Option.java | 81 +++ ext/java/org/jruby/ext/nkf/Options.java | 110 ++++ ext/java/org/jruby/ext/nkf/RubyNKF.java | 602 ++++++++++++++++++ lib/nkf.rb | 6 + nkf.gemspec | 14 +- 10 files changed, 970 insertions(+), 5 deletions(-) create mode 100644 ext/java/org/jruby/ext/nkf/Command.java create mode 100644 ext/java/org/jruby/ext/nkf/CommandParser.java create mode 100644 ext/java/org/jruby/ext/nkf/NKFLibrary.java create mode 100644 ext/java/org/jruby/ext/nkf/Option.java create mode 100644 ext/java/org/jruby/ext/nkf/Options.java create mode 100644 ext/java/org/jruby/ext/nkf/RubyNKF.java create mode 100644 lib/nkf.rb diff --git a/.gitignore b/.gitignore index adca777..fdd6ba5 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,6 @@ *.bundle *.dll *.so +lib/nkf.jar +.idea +nkf.iml diff --git a/Rakefile b/Rakefile index 38ba558..042b220 100644 --- a/Rakefile +++ b/Rakefile @@ -7,6 +7,18 @@ Rake::TestTask.new(:test) do |t| t.test_files = FileList["test/**/test_*.rb"] end -require 'rake/extensiontask' -Rake::ExtensionTask.new("nkf") +if RUBY_ENGINE == "jruby" + require "rake/javaextensiontask" + Rake::JavaExtensionTask.new("nkf") do |ext| + ext.source_version = "1.8" + ext.target_version = "1.8" + ext.ext_dir = "ext/java" + end + + task :build => :compile +else + require 'rake/extensiontask' + Rake::ExtensionTask.new("nkf") +end + task :default => :test diff --git a/ext/java/org/jruby/ext/nkf/Command.java b/ext/java/org/jruby/ext/nkf/Command.java new file mode 100644 index 0000000..adf38fa --- /dev/null +++ b/ext/java/org/jruby/ext/nkf/Command.java @@ -0,0 +1,59 @@ +/***** 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) 2011 Koichiro Ohba + * + * 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.nkf; + +import java.util.List; +import java.util.ArrayList; + +public class Command { + private final List