From 9494a1ff472080e34e5d69efaebb840d09f2526f Mon Sep 17 00:00:00 2001 From: Chad Wilson <29788154+chadlwilson@users.noreply.github.com> Date: Mon, 16 Mar 2026 18:06:53 +0800 Subject: [PATCH] [build] upgrade rubocop and only run on jruby-10 We don't need to actually run rubocop via older JRuby; just ensure compatibility with JRuby 9.3 which can be addressed via .rubocop.yml target syntax. --- .github/workflows/main.yml | 3 ++- .rubocop.yml | 3 ++- Gemfile | 3 ++- lib/jar_dependencies.rb | 2 +- lib/jars/gemspec_artifacts.rb | 18 +++++++++--------- lib/jars/gemspec_pom.rb | 2 +- lib/jars/lock.rb | 2 +- lib/jars/lock_down.rb | 2 +- lib/jars/output_jars_pom.rb | 2 +- specs/classpath_spec.rb | 21 +++++++++++---------- specs/jar_installer_spec.rb | 4 ++-- specs/jars_spec.rb | 4 +--- 12 files changed, 34 insertions(+), 32 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c0bfcb3..8aef28f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,4 +27,5 @@ jobs: - name: Run test run: jruby -Ilib -rbundler/setup -S rake specs - name: Run RuboCop - run: jruby -Ilib -rbundler/setup -S rubocop lib + if: matrix.ruby-version == 'jruby-10.0' # Only run RuboCop on modern JRuby; target older jrubies via .rubocop.yml + run: jruby -Ilib -rbundler/setup -S rubocop lib specs diff --git a/.rubocop.yml b/.rubocop.yml index a453a79..9094bce 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,7 @@ -require: +plugins: - rubocop-rake - rubocop-performance + - rubocop-minitest AllCops: TargetRubyVersion: 2.6 diff --git a/Gemfile b/Gemfile index 74d1cdf..470ea63 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,8 @@ group :development do gem 'rake', require: false gem 'ruby-debug', '~> 0.11', require: false - gem 'rubocop', '~> 1.50.0', require: false + gem 'rubocop', require: false + gem 'rubocop-minitest', require: false gem 'rubocop-performance', require: false gem 'rubocop-rake', require: false end diff --git a/lib/jar_dependencies.rb b/lib/jar_dependencies.rb index 457b1cf..54232c7 100644 --- a/lib/jar_dependencies.rb +++ b/lib/jar_dependencies.rb @@ -95,7 +95,7 @@ def require? if @require.nil? if (require = to_boolean(REQUIRE)).nil? no_require = to_boolean(NO_REQUIRE) - @require = no_require.nil? ? true : !no_require + @require = no_require.nil? || !no_require else @require = require end diff --git a/lib/jars/gemspec_artifacts.rb b/lib/jars/gemspec_artifacts.rb index 7a4a6b3..3cf5664 100644 --- a/lib/jars/gemspec_artifacts.rb +++ b/lib/jars/gemspec_artifacts.rb @@ -12,7 +12,7 @@ def new(*args) if low == high low else - super "#{low || '[0'},#{high || ')'}" + super("#{low || '[0'},#{high || ')'}") end end end @@ -26,17 +26,17 @@ def convert(arg, low = nil, high = nil) ["[#{snapshot_version(val)}", "#{snapshot_version(last)}]"] elsif arg.include?('>=') val = arg.sub(/>=\s*/, '') - ["[#{snapshot_version(val)}", (nil || high)] + ["[#{snapshot_version(val)}", high] elsif arg.include?('<=') val = arg.sub(/<=\s*/, '') - [(nil || low), "#{snapshot_version(val)}]"] + [low, "#{snapshot_version(val)}]"] # treat '!' the same way as '>' since maven can not describe such range elsif /[!>]/.match?(arg) val = arg.sub(/[!>]\s*/, '') - ["(#{snapshot_version(val)}", (nil || high)] + ["(#{snapshot_version(val)}", high] elsif arg.include?('<') val = arg.sub(/<\s*/, '') - [(nil || low), "#{snapshot_version(val)})"] + [low, "#{snapshot_version(val)})"] elsif arg.include?('=') val = arg.sub(/=\s*/, '') # for prereleased version pick the maven version (no version range) @@ -133,12 +133,12 @@ def self.new(line) if /[\[()\]]/.match?(line) index = line.index(/[\[(].+$/) - version = line[index..].sub(/:/, ', ') - line = line[0..index - 1].strip.sub(/:$/, '') + version = line[index..].sub(':', ', ') + line = line[0..(index - 1)].strip.sub(/:$/, '') else index = line.index(/:[^:]+$/) - version = line[index + 1..] - line = line[0..index - 1].strip + version = line[(index + 1)..] + line = line[0..(index - 1)].strip end case line.count(':') diff --git a/lib/jars/gemspec_pom.rb b/lib/jars/gemspec_pom.rb index 834b2fc..d997623 100644 --- a/lib/jars/gemspec_pom.rb +++ b/lib/jars/gemspec_pom.rb @@ -4,7 +4,7 @@ def eval_file(file) file = File.join(__dir__, file) - eval(File.read(file), nil, file) # rubocop:disable Security/Eval + eval(File.read(file), nil, file) # rubocop:disable Security/Eval end eval_file('attach_jars_pom.rb') diff --git a/lib/jars/lock.rb b/lib/jars/lock.rb index 960dba7..c4fad5e 100644 --- a/lib/jars/lock.rb +++ b/lib/jars/lock.rb @@ -57,7 +57,7 @@ def process(scope) File.read(@file).each_line do |line| next unless /:.+:/.match?(line) - jar = JarDetails.new(line.strip.sub(/:jar:/, ':').sub(/:$/, ': ').split(':')) + jar = JarDetails.new(line.strip.sub(':jar:', ':').sub(/:$/, ': ').split(':')) case scope when :all, :test yield jar diff --git a/lib/jars/lock_down.rb b/lib/jars/lock_down.rb index fc2cd4c..4e9ebbb 100644 --- a/lib/jars/lock_down.rb +++ b/lib/jars/lock_down.rb @@ -44,7 +44,7 @@ def attach_jar_coordinates_from_bundler_dependencies(maven) Bundler.setup('default') maven.property('jars.bundler', true) cwd = File.expand_path('.') - Gem.loaded_specs.each do |_name, spec| + Gem.loaded_specs.each_value do |spec| # if gemspec is local then include all dependencies maven.attach_jars(spec, all_dependencies: cwd == spec.full_gem_path) end diff --git a/lib/jars/output_jars_pom.rb b/lib/jars/output_jars_pom.rb index c141aa2..f75cf9f 100644 --- a/lib/jars/output_jars_pom.rb +++ b/lib/jars/output_jars_pom.rb @@ -5,7 +5,7 @@ if ENV_JAVA['jars.quiet'] != 'true' model.dependencies.each do |d| puts " #{d.group_id}:#{d.artifact_id}" \ - "#{d.classifier ? ":#{d.classifier}" : ''}" \ + "#{":#{d.classifier}" if d.classifier}" \ ":#{d.version}:#{d.scope || 'compile'}" next if d.exclusions.empty? diff --git a/specs/classpath_spec.rb b/specs/classpath_spec.rb index f4e2e47..a2eee99 100644 --- a/specs/classpath_spec.rb +++ b/specs/classpath_spec.rb @@ -142,22 +142,23 @@ def self.prepare(array) it 'resolves classpath_string from gemspec' do ENV_JAVA['jars.quiet'] = 'true' Dir.chdir(File.dirname(example_spec)) do - _(Helper.prepare(subject.classpath_string.split(File::PATH_SEPARATOR))).must_equal Helper.prepare(example_expected) + _(Helper.prepare(subject.classpath_string.split(File::PATH_SEPARATOR))) + .must_equal Helper.prepare(example_expected) _(Helper.prepare(subject.classpath_string(:compile).split(File::PATH_SEPARATOR))) - .must_equal Helper.prepare( - expected_with_bc + ['org/slf4j/slf4j-simple/1.7.7/slf4j-simple-1.7.7.jar'] - ) + .must_equal Helper.prepare( + expected_with_bc + ['org/slf4j/slf4j-simple/1.7.7/slf4j-simple-1.7.7.jar'] + ) _(Helper.prepare(subject.classpath_string(:test).split(File::PATH_SEPARATOR))) - .must_equal Helper.prepare(expected_with_bc + [ - 'junit/junit/4.12/junit-4.12.jar', - 'org/slf4j/slf4j-simple/1.7.7/slf4j-simple-1.7.7.jar', - 'org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar' - ]) + .must_equal Helper.prepare(expected_with_bc + [ + 'junit/junit/4.12/junit-4.12.jar', + 'org/slf4j/slf4j-simple/1.7.7/slf4j-simple-1.7.7.jar', + 'org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar' + ]) _(Helper.prepare(subject.classpath_string(:runtime).split(File::PATH_SEPARATOR))) - .must_equal Helper.prepare(example_expected) + .must_equal Helper.prepare(example_expected) end end diff --git a/specs/jar_installer_spec.rb b/specs/jar_installer_spec.rb index d18b1ae..d522142 100644 --- a/specs/jar_installer_spec.rb +++ b/specs/jar_installer_spec.rb @@ -44,7 +44,7 @@ def do_install(vendor, write) File.read(jars).each_line do |line| _(line).must_match(/^\s{2}require(_jar)?\s'.+'$/) if line.size > 30 && !line.match(/^#/) end - _( Dir[File.join(dir, '**')].size ).must_equal 1 + _(Dir[File.join(dir, '**')].size).must_equal 1 end it 'generates vendored require-file' do @@ -54,7 +54,7 @@ def do_install(vendor, write) File.read(jars).each_line do |line| _(line).must_match(/^\s{2}require(_jar)?\s'.+'$/) if line.size > 30 && !line.match(/^#/) end - _( Dir[File.join(dir, '**', '*.jar')].size ).must_equal 45 + _(Dir[File.join(dir, '**', '*.jar')].size).must_equal 45 end it 'just skips install_jars and vendor_jars if there are no requirements' do diff --git a/specs/jars_spec.rb b/specs/jars_spec.rb index 9d42bfb..fac0b8a 100644 --- a/specs/jars_spec.rb +++ b/specs/jars_spec.rb @@ -165,7 +165,7 @@ begin $stderr = StringIO.new - -> { require_jar('org.slf4j', 'slf4j-simple', '1.6.6') }.must_raise RuntimeError + _ { require_jar('org.slf4j', 'slf4j-simple', '1.6.6') }.must_raise RuntimeError $stderr.flush @@ -246,7 +246,6 @@ load File.expand_path('lib/jar_dependencies.rb') _($stderr.string).must_equal '' - ensure $stderr = STDERR end @@ -267,7 +266,6 @@ _($stderr.string).must_match(/omit version 2/) _($stderr.string).must_match(/omit version 3/) _($stderr.string).wont_match(/omit version 4/) - ensure $stderr = STDERR