summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSatoshi Tagomori <tagomoris@gmail.com>2022-01-22 12:14:26 +0900
committerGitHub <noreply@github.com>2022-01-22 12:14:26 +0900
commit36aad47324dafa08034f9813a11cabf5e1b40229 (patch)
tree54e99b12ef0ebe8b6680cffcbe2c618163bd5792
parent5df82aa81e04faa46e3139fe179e01b166d662cc (diff)
downloadrake-compiler-36aad47324dafa08034f9813a11cabf5e1b40229.tar.gz
Support --release option to build JRuby extension for older platforms (#201)
-rw-r--r--lib/rake/javaextensiontask.rb15
-rw-r--r--spec/lib/rake/javaextensiontask_spec.rb25
2 files changed, 38 insertions, 2 deletions
diff --git a/lib/rake/javaextensiontask.rb b/lib/rake/javaextensiontask.rb
index baf9c6c..5603afc 100644
--- a/lib/rake/javaextensiontask.rb
+++ b/lib/rake/javaextensiontask.rb
@@ -17,6 +17,9 @@ module Rake
# Generate class files for specific VM version
attr_accessor :target_version
+ # Compile for oldeer platform version
+ attr_accessor :release
+
attr_accessor :encoding
# Specify lint option
@@ -37,6 +40,7 @@ module Rake
@debug = false
@source_version = '1.7'
@target_version = '1.7'
+ @release = nil
@encoding = nil
@java_compiling = nil
@lint_option = nil
@@ -106,8 +110,7 @@ execute the Rake compilation task using the JRuby interpreter.
javac_command_line = [
"javac",
- "-target", @target_version,
- "-source", @source_version,
+ *java_target_args,
java_lint_arg,
"-d", tmp_path,
]
@@ -208,6 +211,14 @@ execute the Rake compilation task using the JRuby interpreter.
end
end
+ def java_target_args
+ if @release
+ ["--release=#{@release}"]
+ else
+ ["-target", @target_version, "-source", @source_version]
+ end
+ end
+
#
# Discover Java Extension Directories and build an extdirs arguments
#
diff --git a/spec/lib/rake/javaextensiontask_spec.rb b/spec/lib/rake/javaextensiontask_spec.rb
index 7d8999a..1072b88 100644
--- a/spec/lib/rake/javaextensiontask_spec.rb
+++ b/spec/lib/rake/javaextensiontask_spec.rb
@@ -175,11 +175,13 @@ describe Rake::JavaExtensionTask do
let(:extension) do
Rake::JavaExtensionTask.new('extension_two') do |ext|
ext.lint_option = lint_option if lint_option
+ ext.release = release if release
end
end
context 'without a specified lint option' do
let(:lint_option) { nil }
+ let(:release) { nil }
it 'should honor the lint option' do
(extension.lint_option).should be_falsey
@@ -189,12 +191,35 @@ describe Rake::JavaExtensionTask do
context "with a specified lint option of 'deprecated'" do
let(:lint_option) { 'deprecated'.freeze }
+ let(:release) { nil }
it 'should honor the lint option' do
(extension.lint_option).should eq lint_option
(extension.send :java_lint_arg).should eq '-Xlint:deprecated'
end
end
+
+ context "without release option" do
+ let(:lint_option) { nil }
+ let(:release) { nil }
+
+ it 'should generate -target and -source build options' do
+ extension.target_version = "1.8"
+ extension.source_version = "1.8"
+ (extension.send :java_target_args).should eq ["-target", "1.8", "-source", "1.8"]
+ end
+ end
+
+ context "with release option" do
+ let(:lint_option) { nil }
+ let(:release) { '8' }
+
+ it 'should generate --release option even with target_version/source_version' do
+ extension.target_version = "1.8"
+ extension.source_version = "1.8"
+ (extension.send :java_target_args).should eq ["--release=8"]
+ end
+ end
end
end
private