summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen George <sfgeorge@users.noreply.github.com>2019-10-20 16:42:36 -0500
committerSutou Kouhei <kou@clear-code.com>2019-10-21 06:42:36 +0900
commit2b8ada9f162a3ee0af253390b06bbf1bc2e8014a (patch)
treeb3944de14e8891ead1dc0676d6f51b6f0eb27648
parent37483c61ba627f105ca6dcc7331641ede72da73d (diff)
downloadrake-compiler-2b8ada9f162a3ee0af253390b06bbf1bc2e8014a.tar.gz
Make lint options customizable (#158)
* Make customizable compiler Xlint option for JRuby native extension * [CS] restructure and fix indentation of (defaults) spec * Add specs for lint_option * [DOC] CHANGELOG: stub changelog entry for the next release * [DOC] CHANGELOG: Make customizable compiler Xlint option for JRuby native extension * Use "-Xlint" option for JRuby native extension by default. `javac -help -X` > -Xlint Enable recommended warnings
-rw-r--r--History.txt13
-rw-r--r--lib/rake/javaextensiontask.rb17
-rw-r--r--spec/lib/rake/javaextensiontask_spec.rb30
3 files changed, 59 insertions, 1 deletions
diff --git a/History.txt b/History.txt
index 0c0b68c..09343dd 100644
--- a/History.txt
+++ b/History.txt
@@ -1,3 +1,16 @@
+=== develop
+
+* Changes:
+ * Use "-Xlint" option for JRuby native extension by default.
+ #158 [Patch by Stephen George]
+
+* Enhancements:
+ * Make customizable compiler Xlint option for JRuby native extension.
+ #118 [Patch by Hiroshi Hatake]
+
+* Bugfixes:
+ *
+
=== 1.0.8 / 2019-09-21
* Enhancements:
diff --git a/lib/rake/javaextensiontask.rb b/lib/rake/javaextensiontask.rb
index 162a463..0963338 100644
--- a/lib/rake/javaextensiontask.rb
+++ b/lib/rake/javaextensiontask.rb
@@ -19,6 +19,9 @@ module Rake
attr_accessor :encoding
+ # Specify lint option
+ attr_accessor :lint_option
+
def platform
@platform ||= 'java'
end
@@ -36,6 +39,7 @@ module Rake
@target_version = '1.6'
@encoding = nil
@java_compiling = nil
+ @lint_option = nil
end
def define
@@ -98,7 +102,7 @@ execute the Rake compilation task using the JRuby interpreter.
classpath_arg = java_classpath_arg(@classpath)
debug_arg = @debug ? '-g' : ''
- sh "javac #{java_encoding_arg} #{java_extdirs_arg} -target #{@target_version} -source #{@source_version} -Xlint:unchecked #{debug_arg} #{classpath_arg} -d #{tmp_path} #{source_files.join(' ')}"
+ sh "javac #{java_encoding_arg} #{java_extdirs_arg} -target #{@target_version} -source #{@source_version} #{java_lint_arg @lint_option} #{debug_arg} #{classpath_arg} -d #{tmp_path} #{source_files.join(' ')}"
# Checkpoint file
touch "#{tmp_path}/.build"
@@ -254,5 +258,16 @@ execute the Rake compilation task using the JRuby interpreter.
jruby_cpath ? "-cp \"#{jruby_cpath}\"" : ""
end
+ #
+ # Convert a `-Xlint:___` linting option such as `deprecation` into a full javac argument, such as `-Xlint:deprecation`.
+ #
+ # @param [String] lint_option A `-Xlint:___` linting option such as `deprecation`, `all`, `none`, etc.
+ # @return [String] Default: _Simply `-Xlint` is run, which enables recommended warnings.
+ #
+ def java_lint_arg(lint_option)
+ return '-Xlint' unless lint_option
+
+ "-Xlint:#{lint_option}"
+ end
end
end
diff --git a/spec/lib/rake/javaextensiontask_spec.rb b/spec/lib/rake/javaextensiontask_spec.rb
index 06ba2f5..353c40f 100644
--- a/spec/lib/rake/javaextensiontask_spec.rb
+++ b/spec/lib/rake/javaextensiontask_spec.rb
@@ -76,9 +76,14 @@ describe Rake::JavaExtensionTask do
@ext.config_options.should be_empty
end
+ it 'should have no lint option preset to delegate' do
+ @ext.lint_option.should be_falsey
+ end
+
it 'should default to Java platform' do
@ext.platform.should == 'java'
end
+ end
context '(tasks)' do
before :each do
@@ -165,6 +170,31 @@ describe Rake::JavaExtensionTask do
end
end
end
+
+ context 'A custom extension' do
+ let(:extension) do
+ Rake::JavaExtensionTask.new('extension_two') do |ext|
+ ext.lint_option = lint_option if lint_option
+ end
+ end
+
+ context 'without a specified lint option' do
+ let(:lint_option) { nil }
+
+ it 'should honor the lint option' do
+ (extension.lint_option).should be_falsey
+ (extension.send :java_lint_arg, extension.lint_option).should eq '-Xlint'
+ end
+ end
+
+ context "with a specified lint option of 'deprecated'" do
+ let(:lint_option) { 'deprecated'.freeze }
+
+ it 'should honor the lint option' do
+ (extension.lint_option).should eq lint_option
+ (extension.send :java_lint_arg, extension.lint_option).should eq '-Xlint:deprecated'
+ end
+ end
end
end
private