diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..234188d --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +PATH_add bin diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..c4c202d --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,30 @@ +name: Ruby + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + test: + + runs-on: ubuntu-latest + + strategy: + matrix: + ruby-version: [jruby-9.3] + + steps: + - uses: actions/checkout@v2 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + bundler-cache: true + - name: Install dependencies + run: bundle install + - name: Run RuboCop + run: bundle exec rubocop + - name: Run test + run: bundle exec rake specs diff --git a/.gitignore b/.gitignore index 526e583..abf24fc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ pkg -# no Gemfile.lock -Gemfile.lock .ruby-version *.gem target diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..41952bf --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,6 @@ +repos: +- repo: https://github.com/mattlqx/pre-commit-ruby + rev: v1.3.5 + hooks: + - id: rubocop + diff --git a/.rubocop.yml b/.rubocop.yml index b3135d3..cab39d6 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,32 +1,34 @@ -AllCops: - TargetRubyVersion: 2.1 - Exclude: - - 'Gemfile.lock' - - pkg/**/* - -Style/Copyright: - Enabled: false +require: + - rubocop-rake + - rubocop-performance -Style/Documentation: - Enabled: false +AllCops: + TargetRubyVersion: 2.6 + NewCops: enable -Style/SafeNavigation: +Metrics: Enabled: false -Style/SymbolArray: - EnforcedStyle: brackets +Naming/FileName: + Exclude: + - lib/jar-dependencies.rb -Style/FrozenStringLiteralComment: - Enabled: false +Performance/Casecmp: + AutoCorrect: false -Style/Dir: +Style/Alias: + EnforcedStyle: prefer_alias_method +Style/BlockDelimiters: + IgnoredMethods: [] +Style/Documentation: Enabled: false - -Layout/IndentHeredoc: +Style/EnvHome: Enabled: false - -Layout/MultilineMethodCallIndentation: - EnforcedStyle: indented - -Performance/RegexpMatch: +Style/FetchEnvVar: Enabled: false +Style/HashSyntax: + EnforcedStyle: ruby19_no_mixed_keys +Style/RescueStandardError: + EnforcedStyle: implicit +Style/TernaryParentheses: + EnforcedStyle: require_parentheses_when_complex diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 3c9b721..0000000 --- a/.travis.yml +++ /dev/null @@ -1,26 +0,0 @@ -language: java -dist: xenial -sudo: false -before_script: - - export MAVEN_SKIP_RC=true -env: - - GOAL=test - # the install_ruby_maven_when_needed can not resolve ruby-maven on travis - # gemspecs was and is very fragile - probably remove it completely as it is doing too much in one go - - GOAL='verify -Dmaven.test.skip -Dinvoker.test=*,!install*,!gemspecs' -jdk: - - openjdk8 - - openjdk11 -install: ./mvnw initialize -script: ./mvnw $GOAL -matrix: - include: - - dist: precise - jdk: openjdk7 - env: GOAL=test - - dist: trusty - jdk: oraclejdk8 - env: GOAL=test - - dist: trusty - jdk: oraclejdk8 - env: GOAL='verify -Dmaven.test.skip -Dinvoker.test=*,!install*,!gemspecs' diff --git a/Gemfile b/Gemfile index 4e304c7..7f4f5e9 100644 --- a/Gemfile +++ b/Gemfile @@ -1,9 +1,5 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true + source 'https://rubygems.org' gemspec - -gem 'copyright-header', '1.0.8', platform: :mri, group: :copyright - -gem 'pry', require: false, group: :development -gem 'ffi', '~> 1.11.3', require: false, group: :development diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..94430c6 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,63 @@ +PATH + remote: . + specs: + jar-dependencies (0.4.1) + +GEM + remote: https://rubygems.org/ + specs: + ast (2.4.2) + columnize (0.9.0) + json (2.6.2-java) + linecache (1.3.1-java) + minitest (5.10.3) + parallel (1.22.1) + parser (3.1.2.0) + ast (~> 2.4.1) + rainbow (3.1.1) + rake (13.0.6) + regexp_parser (2.5.0) + rexml (3.2.5) + rubocop (1.31.1) + json (~> 2.3) + parallel (~> 1.10) + parser (>= 3.1.0.0) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.18.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 1.4.0, < 3.0) + rubocop-ast (1.18.0) + parser (>= 3.1.1.0) + rubocop-performance (1.14.2) + rubocop (>= 1.7.0, < 2.0) + rubocop-ast (>= 0.4.0) + rubocop-rake (0.6.0) + rubocop (~> 1.0) + ruby-debug (0.11.0) + columnize (>= 0.1) + linecache (~> 1.3.1) + ruby-debug-base (~> 0.11.0.0) + ruby-debug-base (0.11.0-java) + ruby-maven (3.3.13) + ruby-maven-libs (~> 3.3.9) + ruby-maven-libs (3.3.9) + ruby-progressbar (1.11.0) + unicode-display_width (2.2.0) + +PLATFORMS + universal-java-11 + +DEPENDENCIES + jar-dependencies! + minitest (~> 5.10.0) + rake (~> 13.0) + rubocop (~> 1.31) + rubocop-performance (~> 1.14) + rubocop-rake (~> 0.6) + ruby-debug (~> 0.11) + ruby-maven (~> 3.3) + +BUNDLED WITH + 2.3.16 diff --git a/Mavenfile b/Mavenfile index 76a5221..435754a 100644 --- a/Mavenfile +++ b/Mavenfile @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true gemfile @@ -59,5 +59,3 @@ profile id: :release do default_goal :deploy end end - -# vim: syntax=Ruby diff --git a/Rakefile b/Rakefile index 083bba5..288002a 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,12 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true task default: [:specs] +require 'bundler/gem_tasks' +require 'rubocop/rake_task' + +RuboCop::RakeTask.new + desc 'run specs' task :specs do $LOAD_PATH << 'specs' @@ -10,24 +15,3 @@ task :specs do require File.basename(f.sub(/.rb$/, '')) end end - -task :headers do - require 'copyright_header' - - s = Gem::Specification.load(Dir['*gemspec'].first) - - args = { - license: s.license, - copyright_software: s.name, - copyright_software_description: s.description, - copyright_holders: s.authors, - copyright_years: [Time.now.year], - add_path: 'lib', - output_dir: './' - } - - command_line = CopyrightHeader::CommandLine.new(args) - command_line.execute -end - -# vim: syntax=Ruby diff --git a/Readme.md b/Readme.md index cb475cf..1ee0bfc 100644 --- a/Readme.md +++ b/Readme.md @@ -47,7 +47,7 @@ during installation. If you do not want to vendor jars into a gem then **jar-dependency** gem can vendor them when you install the gem. In that case do not use -`Jars::JarInstaller.install_jars` from the above rake tasks. +`Jars::Installer.install_jars` from the above rake tasks. **NOTE**: Recent JRuby comes with **jar-dependencies** as default gem, for older versions for the feature to work you need to gem install **jar-dependencies** first diff --git a/bin/rake b/bin/rake new file mode 100755 index 0000000..9646b91 --- /dev/null +++ b/bin/rake @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rake' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) + +bundle_binstub = File.expand_path('bundle', __dir__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300).include?('This file was generated by Bundler') + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require 'rubygems' +require 'bundler/setup' + +load Gem.bin_path('rake', 'rake') diff --git a/bin/rubocop b/bin/rubocop new file mode 100755 index 0000000..786dcf0 --- /dev/null +++ b/bin/rubocop @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rubocop' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) + +bundle_binstub = File.expand_path('bundle', __dir__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300).include?('This file was generated by Bundler') + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require 'rubygems' +require 'bundler/setup' + +load Gem.bin_path('rubocop', 'rubocop') diff --git a/example/Gemfile b/example/Gemfile index 0ccfd03..6cfda8f 100644 --- a/example/Gemfile +++ b/example/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # bundle install will download and install the jar dependencies # as well create the lib/example_jars.rb which loads the jars at # runtime diff --git a/example/Rakefile b/example/Rakefile index ed9b372..54dc2d2 100644 --- a/example/Rakefile +++ b/example/Rakefile @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true require 'rspec/core/rake_task' require 'jars/classpath' @@ -6,14 +6,13 @@ require 'rake/javaextensiontask' require 'jars/installer' task :install_jars do - Jars::JarInstaller.new.vendor_jars - # Jars::JarInstaller.new.install_jars + Jars::Installer.new.vendor_jars end desc 'Compiles extension and run specs' -task default: [:compile, :spec] +task default: %i[compile spec] -spec = eval File.read('example.gemspec') +spec = eval File.read('example.gemspec') # rubocop:disable Security/Eval desc 'compile src/main/java/** into lib/example.jar' Rake::JavaExtensionTask.new('example', spec) do |ext| @@ -26,10 +25,8 @@ end require 'rubygems/package_task' Gem::PackageTask.new(spec) do desc 'Pack gem' - task package: [:install_jars, :compile] + task package: %i[install_jars compile] end desc 'Run specs' RSpec::Core::RakeTask.new - -# vim: syntax=Ruby diff --git a/example/example.gemspec b/example/example.gemspec index c922aee..af6b8f5 100644 --- a/example/example.gemspec +++ b/example/example.gemspec @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true Gem::Specification.new do |s| # this is only needed to retrieve the latest version of jar-dependencies @@ -21,6 +21,8 @@ Gem::Specification.new do |s| s.files << Dir['*file'] s.files << 'example.gemspec' + s.required_ruby_version = '>= 2.6' + # constrain the version of jar-dependencies itself s.add_runtime_dependency 'jar-dependencies', "~> #{version}" @@ -51,6 +53,5 @@ Gem::Specification.new do |s| # avoids to install it on the fly when jar-dependencies needs it s.add_development_dependency 'ruby-maven', '~> 3.3', '>= 3.3.8' + s.metadata['rubygems_mfa_required'] = 'true' end - -# vim: syntax=Ruby diff --git a/example/lib/example.rb b/example/lib/example.rb index cf721a0..f83eae9 100644 --- a/example/lib/example.rb +++ b/example/lib/example.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # this require will load ALL dependent jars or the jars from Jars.lock if # the lock file exeists require 'example_jars' diff --git a/example/lib/example/bc_info.rb b/example/lib/example/bc_info.rb index cd25990..3f247d2 100644 --- a/example/lib/example/bc_info.rb +++ b/example/lib/example/bc_info.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # loads all dependent jars and exmaple.jar require 'example' diff --git a/example/spec/first_spec.rb b/example/spec/first_spec.rb index a88ea53..08347b5 100644 --- a/example/spec/first_spec.rb +++ b/example/spec/first_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'spec_helper' require 'example/bc_info' diff --git a/example/spec/second_spec.rb b/example/spec/second_spec.rb index 6167230..b4c9dc4 100644 --- a/example/spec/second_spec.rb +++ b/example/spec/second_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'spec_helper' describe 'java class App from src/main/java/**' do diff --git a/example/spec/spec_helper.rb b/example/spec/spec_helper.rb index 301fde8..2114422 100644 --- a/example/spec/spec_helper.rb +++ b/example/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # load all jars including with scope test require 'jars/classpath' Jars::Classpath.require(:test) diff --git a/examples/gem-with-jar-dependencies-and-bundler/Gemfile b/examples/gem-with-jar-dependencies-and-bundler/Gemfile index fa75df1..7f4f5e9 100644 --- a/examples/gem-with-jar-dependencies-and-bundler/Gemfile +++ b/examples/gem-with-jar-dependencies-and-bundler/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' gemspec diff --git a/examples/gem-with-jar-dependencies-and-bundler/lib/mygem.rb b/examples/gem-with-jar-dependencies-and-bundler/lib/mygem.rb index b71b91c..6dae9ea 100644 --- a/examples/gem-with-jar-dependencies-and-bundler/lib/mygem.rb +++ b/examples/gem-with-jar-dependencies-and-bundler/lib/mygem.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + # can be hardcoded here but for copy the example around that is easier -require Dir[File.dirname(__FILE__) + '/*_jars.rb'].first +require Dir["#{File.dirname(__FILE__)}/*_jars.rb"].first diff --git a/examples/gem-with-jar-dependencies-and-bundler/mygem.gemspec b/examples/gem-with-jar-dependencies-and-bundler/mygem.gemspec index c5717ea..502891c 100644 --- a/examples/gem-with-jar-dependencies-and-bundler/mygem.gemspec +++ b/examples/gem-with-jar-dependencies-and-bundler/mygem.gemspec @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true # use the version from the main project require "#{File.dirname File.expand_path(__FILE__)}/../../lib/jars/version" @@ -18,10 +18,11 @@ Gem::Specification.new do |s| s.files += Dir['*file'] s.files += Dir['*.gemspec'] + s.required_ruby_version = '>= 2.6' + s.requirements << 'jar org.slf4j, slf4j-api, 1.7.7' s.requirements << 'jar org.slf4j, slf4j-simple, 1.7.7, :scope => :test' s.add_runtime_dependency 'jar-dependencies', "~> #{Jars::VERSION}" + s.metadata['rubygems_mfa_required'] = 'true' end - -# vim: syntax=Ruby diff --git a/examples/gem-with-jar-dependencies-and-bundler/test.rb b/examples/gem-with-jar-dependencies-and-bundler/test.rb index 4d251ba..aadcd76 100644 --- a/examples/gem-with-jar-dependencies-and-bundler/test.rb +++ b/examples/gem-with-jar-dependencies-and-bundler/test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # setup env $LOAD_PATH << 'lib' @@ -11,4 +13,4 @@ logger = org.slf4j.LoggerFactory.get_logger('root') logger.info('hello') -logger.info("used classpath:\n\t" + $CLASSPATH.collect(&:to_s).join("\n\t")) +logger.info("used classpath:\n\t#{$CLASSPATH.collect(&:to_s).join("\n\t")}") diff --git a/examples/gem-with-jar-dependencies/Gemfile b/examples/gem-with-jar-dependencies/Gemfile index fa75df1..7f4f5e9 100644 --- a/examples/gem-with-jar-dependencies/Gemfile +++ b/examples/gem-with-jar-dependencies/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' gemspec diff --git a/examples/gem-with-jar-dependencies/lib/mygem.rb b/examples/gem-with-jar-dependencies/lib/mygem.rb index b71b91c..6dae9ea 100644 --- a/examples/gem-with-jar-dependencies/lib/mygem.rb +++ b/examples/gem-with-jar-dependencies/lib/mygem.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + # can be hardcoded here but for copy the example around that is easier -require Dir[File.dirname(__FILE__) + '/*_jars.rb'].first +require Dir["#{File.dirname(__FILE__)}/*_jars.rb"].first diff --git a/examples/gem-with-jar-dependencies/mygem.gemspec b/examples/gem-with-jar-dependencies/mygem.gemspec index 5e33c11..5ab614e 100644 --- a/examples/gem-with-jar-dependencies/mygem.gemspec +++ b/examples/gem-with-jar-dependencies/mygem.gemspec @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true Gem::Specification.new do |s| s.name = File.basename(File.dirname(File.expand_path(__FILE__))) @@ -16,8 +16,9 @@ Gem::Specification.new do |s| s.files += Dir['*file'] s.files += Dir['*.gemspec'] + s.required_ruby_version = '>= 2.6' + s.requirements << 'jar org.slf4j, slf4j-api, 1.7.7' s.requirements << 'jar org.slf4j, slf4j-simple, 1.7.7, :scope => :test' + s.metadata['rubygems_mfa_required'] = 'true' end - -# vim: syntax=Ruby diff --git a/examples/gem-with-jar-dependencies/test.rb b/examples/gem-with-jar-dependencies/test.rb index 4d251ba..aadcd76 100644 --- a/examples/gem-with-jar-dependencies/test.rb +++ b/examples/gem-with-jar-dependencies/test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # setup env $LOAD_PATH << 'lib' @@ -11,4 +13,4 @@ logger = org.slf4j.LoggerFactory.get_logger('root') logger.info('hello') -logger.info("used classpath:\n\t" + $CLASSPATH.collect(&:to_s).join("\n\t")) +logger.info("used classpath:\n\t#{$CLASSPATH.collect(&:to_s).join("\n\t")}") diff --git a/examples/gem-with-java-extension-and-jar-dependencies/using-maven/Gemfile b/examples/gem-with-java-extension-and-jar-dependencies/using-maven/Gemfile index fa75df1..7f4f5e9 100644 --- a/examples/gem-with-java-extension-and-jar-dependencies/using-maven/Gemfile +++ b/examples/gem-with-java-extension-and-jar-dependencies/using-maven/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' gemspec diff --git a/examples/gem-with-java-extension-and-jar-dependencies/using-maven/lib/mygem.rb b/examples/gem-with-java-extension-and-jar-dependencies/using-maven/lib/mygem.rb index 64a564c..9add045 100644 --- a/examples/gem-with-java-extension-and-jar-dependencies/using-maven/lib/mygem.rb +++ b/examples/gem-with-java-extension-and-jar-dependencies/using-maven/lib/mygem.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # can be hardcoded here but for copy the example around that is easier -require Dir[File.dirname(__FILE__) + '/*_jars.rb'].first -require Dir[File.dirname(__FILE__) + '/*jar'].first +require Dir["#{File.dirname(__FILE__)}/*_jars.rb"].first +require Dir["#{File.dirname(__FILE__)}/*jar"].first diff --git a/examples/gem-with-java-extension-and-jar-dependencies/using-maven/mygem.gemspec b/examples/gem-with-java-extension-and-jar-dependencies/using-maven/mygem.gemspec index ece8215..31d3ec5 100644 --- a/examples/gem-with-java-extension-and-jar-dependencies/using-maven/mygem.gemspec +++ b/examples/gem-with-java-extension-and-jar-dependencies/using-maven/mygem.gemspec @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true # use the version from the main project require "#{File.dirname File.expand_path(__FILE__)}/../../../lib/jars/version" @@ -19,10 +19,11 @@ Gem::Specification.new do |s| s.files += Dir['*.file'] s.files += Dir['*.gemspec'] + s.required_ruby_version = '>= 2.6' + s.requirements << 'jar org.slf4j, slf4j-api, 1.7.7' s.requirements << 'jar org.slf4j, slf4j-simple, 1.7.7, :scope => :test' s.add_runtime_dependency 'jar-dependencies', "~> #{Jars::VERSION}" + s.metadata['rubygems_mfa_required'] = 'true' end - -# vim: syntax=Ruby diff --git a/examples/gem-with-java-extension-and-jar-dependencies/using-maven/test.rb b/examples/gem-with-java-extension-and-jar-dependencies/using-maven/test.rb index dc1c7ea..95c470d 100644 --- a/examples/gem-with-java-extension-and-jar-dependencies/using-maven/test.rb +++ b/examples/gem-with-java-extension-and-jar-dependencies/using-maven/test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # setup env $LOAD_PATH << 'lib' diff --git a/examples/gem-with-java-extension-and-jar-dependencies/using-rake-compiler/Gemfile b/examples/gem-with-java-extension-and-jar-dependencies/using-rake-compiler/Gemfile index fa75df1..7f4f5e9 100644 --- a/examples/gem-with-java-extension-and-jar-dependencies/using-rake-compiler/Gemfile +++ b/examples/gem-with-java-extension-and-jar-dependencies/using-rake-compiler/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' gemspec diff --git a/examples/gem-with-java-extension-and-jar-dependencies/using-rake-compiler/Rakefile b/examples/gem-with-java-extension-and-jar-dependencies/using-rake-compiler/Rakefile index 808c581..03592a6 100644 --- a/examples/gem-with-java-extension-and-jar-dependencies/using-rake-compiler/Rakefile +++ b/examples/gem-with-java-extension-and-jar-dependencies/using-rake-compiler/Rakefile @@ -1,9 +1,9 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true require 'jars/classpath' require 'rake/javaextensiontask' -spec = eval File.read('mygem.gemspec') +spec = eval File.read('mygem.gemspec') # rubocop:disable Security/Eval Rake::JavaExtensionTask.new('mygem', spec) do |ext| ext.classpath = Jars::Classpath.new.classpath_string ext.ext_dir = 'ext' @@ -16,5 +16,3 @@ Gem::PackageTask.new(spec) do desc 'Pack gem' task package: [:compile] end - -# vim: syntax=Ruby diff --git a/examples/gem-with-java-extension-and-jar-dependencies/using-rake-compiler/lib/mygem.rb b/examples/gem-with-java-extension-and-jar-dependencies/using-rake-compiler/lib/mygem.rb index 64a564c..9add045 100644 --- a/examples/gem-with-java-extension-and-jar-dependencies/using-rake-compiler/lib/mygem.rb +++ b/examples/gem-with-java-extension-and-jar-dependencies/using-rake-compiler/lib/mygem.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # can be hardcoded here but for copy the example around that is easier -require Dir[File.dirname(__FILE__) + '/*_jars.rb'].first -require Dir[File.dirname(__FILE__) + '/*jar'].first +require Dir["#{File.dirname(__FILE__)}/*_jars.rb"].first +require Dir["#{File.dirname(__FILE__)}/*jar"].first diff --git a/examples/gem-with-java-extension-and-jar-dependencies/using-rake-compiler/mygem.gemspec b/examples/gem-with-java-extension-and-jar-dependencies/using-rake-compiler/mygem.gemspec index 3af46be..e2f316a 100644 --- a/examples/gem-with-java-extension-and-jar-dependencies/using-rake-compiler/mygem.gemspec +++ b/examples/gem-with-java-extension-and-jar-dependencies/using-rake-compiler/mygem.gemspec @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true # use the version from the main project require "#{File.dirname File.expand_path(__FILE__)}/../../../lib/jars/version" @@ -19,6 +19,8 @@ Gem::Specification.new do |s| s.files += Dir['*.file'] s.files += Dir['*.gemspec'] + s.required_ruby_version = '>= 2.6' + s.requirements << 'jar org.slf4j, slf4j-api, 1.7.7' s.requirements << 'jar org.slf4j, slf4j-simple, 1.7.7, :scope => :test' @@ -27,6 +29,5 @@ Gem::Specification.new do |s| s.add_development_dependency 'rake', '~> 10.3' # needed to compile ext/** and create jar file s.add_development_dependency 'rake-compiler', '~> 0.9' + s.metadata['rubygems_mfa_required'] = 'true' end - -# vim: syntax=Ruby diff --git a/examples/gem-with-java-extension-and-jar-dependencies/using-rake-compiler/test.rb b/examples/gem-with-java-extension-and-jar-dependencies/using-rake-compiler/test.rb index dc1c7ea..95c470d 100644 --- a/examples/gem-with-java-extension-and-jar-dependencies/using-rake-compiler/test.rb +++ b/examples/gem-with-java-extension-and-jar-dependencies/using-rake-compiler/test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # setup env $LOAD_PATH << 'lib' diff --git a/examples/gem-with-java-extension-and-jar-dependencies/using-ruby-maven/Gemfile b/examples/gem-with-java-extension-and-jar-dependencies/using-ruby-maven/Gemfile index fa75df1..7f4f5e9 100644 --- a/examples/gem-with-java-extension-and-jar-dependencies/using-ruby-maven/Gemfile +++ b/examples/gem-with-java-extension-and-jar-dependencies/using-ruby-maven/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' gemspec diff --git a/examples/gem-with-java-extension-and-jar-dependencies/using-ruby-maven/Rakefile b/examples/gem-with-java-extension-and-jar-dependencies/using-ruby-maven/Rakefile index 7cc8fa4..11f9371 100644 --- a/examples/gem-with-java-extension-and-jar-dependencies/using-ruby-maven/Rakefile +++ b/examples/gem-with-java-extension-and-jar-dependencies/using-ruby-maven/Rakefile @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true require 'ruby-maven' desc 'Pack jar after compiling classes' @@ -14,9 +14,7 @@ end task default: [:compile] require 'rubygems/package_task' -Gem::PackageTask.new(eval(File.read('mygem.gemspec'))) do +Gem::PackageTask.new(eval(File.read('mygem.gemspec'))) do # rubocop:disable Security/Eval desc 'Pack gem' task package: [:compile] end - -# vim: syntax=Ruby diff --git a/examples/gem-with-java-extension-and-jar-dependencies/using-ruby-maven/lib/mygem.rb b/examples/gem-with-java-extension-and-jar-dependencies/using-ruby-maven/lib/mygem.rb index 64a564c..9add045 100644 --- a/examples/gem-with-java-extension-and-jar-dependencies/using-ruby-maven/lib/mygem.rb +++ b/examples/gem-with-java-extension-and-jar-dependencies/using-ruby-maven/lib/mygem.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # can be hardcoded here but for copy the example around that is easier -require Dir[File.dirname(__FILE__) + '/*_jars.rb'].first -require Dir[File.dirname(__FILE__) + '/*jar'].first +require Dir["#{File.dirname(__FILE__)}/*_jars.rb"].first +require Dir["#{File.dirname(__FILE__)}/*jar"].first diff --git a/examples/gem-with-java-extension-and-jar-dependencies/using-ruby-maven/mygem.gemspec b/examples/gem-with-java-extension-and-jar-dependencies/using-ruby-maven/mygem.gemspec index 726802f..ff8a135 100644 --- a/examples/gem-with-java-extension-and-jar-dependencies/using-ruby-maven/mygem.gemspec +++ b/examples/gem-with-java-extension-and-jar-dependencies/using-ruby-maven/mygem.gemspec @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true # use the version from the main project require "#{File.dirname File.expand_path(__FILE__)}/../../lib/jars/version" @@ -19,10 +19,11 @@ Gem::Specification.new do |s| s.files += Dir['*.file'] s.files += Dir['*.gemspec'] + s.required_ruby_version = '>= 2.6' + s.requirements << 'jar org.slf4j, slf4j-api, 1.7.7' s.requirements << 'jar org.slf4j, slf4j-simple, 1.7.7, :scope => :test' s.add_runtime_dependency 'jar-dependencies', "~> #{Jars::VERSION}" + s.metadata['rubygems_mfa_required'] = 'true' end - -# vim: syntax=Ruby diff --git a/examples/gem-with-java-extension-and-jar-dependencies/using-ruby-maven/test.rb b/examples/gem-with-java-extension-and-jar-dependencies/using-ruby-maven/test.rb index dc1c7ea..95c470d 100644 --- a/examples/gem-with-java-extension-and-jar-dependencies/using-ruby-maven/test.rb +++ b/examples/gem-with-java-extension-and-jar-dependencies/using-ruby-maven/test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # setup env $LOAD_PATH << 'lib' diff --git a/examples/gem-with-java-extension/using-maven/lib/mygem.rb b/examples/gem-with-java-extension/using-maven/lib/mygem.rb index ae1401f..ca56541 100644 --- a/examples/gem-with-java-extension/using-maven/lib/mygem.rb +++ b/examples/gem-with-java-extension/using-maven/lib/mygem.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + # can be hardcoded here but for copy the example around that is easier -require Dir[File.dirname(__FILE__) + '/*jar'].first +require Dir["#{File.dirname(__FILE__)}/*jar"].first diff --git a/examples/gem-with-java-extension/using-maven/mygem.gemspec b/examples/gem-with-java-extension/using-maven/mygem.gemspec index db49f65..21825e9 100644 --- a/examples/gem-with-java-extension/using-maven/mygem.gemspec +++ b/examples/gem-with-java-extension/using-maven/mygem.gemspec @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true # use the version from the main project require "#{File.dirname File.expand_path(__FILE__)}/../../lib/jars/version" @@ -14,10 +14,11 @@ Gem::Specification.new do |s| # nice to have s.platform = 'java' + s.required_ruby_version = '>= 2.6' + s.files = Dir['lib/**/*.rb'] s.files += Dir['lib/*.jar'] s.files += Dir['*.file'] s.files += Dir['*.gemspec'] + s.metadata['rubygems_mfa_required'] = 'true' end - -# vim: syntax=Ruby diff --git a/examples/gem-with-java-extension/using-maven/test.rb b/examples/gem-with-java-extension/using-maven/test.rb index 2f00d35..2ff4cbd 100644 --- a/examples/gem-with-java-extension/using-maven/test.rb +++ b/examples/gem-with-java-extension/using-maven/test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # setup env $LOAD_PATH << 'lib' @@ -5,4 +7,4 @@ require 'mygem' # use it -puts Java::App.hello('world')) +puts Java::App.hello('world') diff --git a/examples/gem-with-java-extension/using-rake-compiler/Rakefile b/examples/gem-with-java-extension/using-rake-compiler/Rakefile index bc84366..19986e4 100644 --- a/examples/gem-with-java-extension/using-rake-compiler/Rakefile +++ b/examples/gem-with-java-extension/using-rake-compiler/Rakefile @@ -1,9 +1,9 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true require 'jars/classpath' require 'rake/javaextensiontask' -spec = eval File.read('mygem.gemspec') +spec = eval File.read('mygem.gemspec') # rubocop:disable Security/Eval Rake::JavaExtensionTask.new('mygem', spec) do |ext| ext.ext_dir = 'ext' end @@ -15,5 +15,3 @@ Gem::PackageTask.new(spec) do desc 'Pack gem' task package: [:compile] end - -# vim: syntax=Ruby diff --git a/examples/gem-with-java-extension/using-rake-compiler/lib/mygem.rb b/examples/gem-with-java-extension/using-rake-compiler/lib/mygem.rb index ae1401f..ca56541 100644 --- a/examples/gem-with-java-extension/using-rake-compiler/lib/mygem.rb +++ b/examples/gem-with-java-extension/using-rake-compiler/lib/mygem.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + # can be hardcoded here but for copy the example around that is easier -require Dir[File.dirname(__FILE__) + '/*jar'].first +require Dir["#{File.dirname(__FILE__)}/*jar"].first diff --git a/examples/gem-with-java-extension/using-rake-compiler/mygem.gemspec b/examples/gem-with-java-extension/using-rake-compiler/mygem.gemspec index 026cd1f..ef4b9c1 100644 --- a/examples/gem-with-java-extension/using-rake-compiler/mygem.gemspec +++ b/examples/gem-with-java-extension/using-rake-compiler/mygem.gemspec @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true # use the version from the main project require "#{File.dirname File.expand_path(__FILE__)}/../../../lib/jars/version" @@ -19,9 +19,10 @@ Gem::Specification.new do |s| s.files += Dir['*.file'] s.files += Dir['*.gemspec'] + s.required_ruby_version = '>= 2.6' + s.add_development_dependency 'rake', '~> 10.3' # needed to compile ext/** and create jar file s.add_development_dependency 'rake-compile', '~> 0.9' + s.metadata['rubygems_mfa_required'] = 'true' end - -# vim: syntax=Ruby diff --git a/examples/gem-with-java-extension/using-rake-compiler/test.rb b/examples/gem-with-java-extension/using-rake-compiler/test.rb index 2f00d35..2ff4cbd 100644 --- a/examples/gem-with-java-extension/using-rake-compiler/test.rb +++ b/examples/gem-with-java-extension/using-rake-compiler/test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # setup env $LOAD_PATH << 'lib' @@ -5,4 +7,4 @@ require 'mygem' # use it -puts Java::App.hello('world')) +puts Java::App.hello('world') diff --git a/examples/gem-with-java-extension/using-ruby-maven/Rakefile b/examples/gem-with-java-extension/using-ruby-maven/Rakefile index 7cc8fa4..11f9371 100644 --- a/examples/gem-with-java-extension/using-ruby-maven/Rakefile +++ b/examples/gem-with-java-extension/using-ruby-maven/Rakefile @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true require 'ruby-maven' desc 'Pack jar after compiling classes' @@ -14,9 +14,7 @@ end task default: [:compile] require 'rubygems/package_task' -Gem::PackageTask.new(eval(File.read('mygem.gemspec'))) do +Gem::PackageTask.new(eval(File.read('mygem.gemspec'))) do # rubocop:disable Security/Eval desc 'Pack gem' task package: [:compile] end - -# vim: syntax=Ruby diff --git a/examples/gem-with-java-extension/using-ruby-maven/lib/mygem.rb b/examples/gem-with-java-extension/using-ruby-maven/lib/mygem.rb index ae1401f..ca56541 100644 --- a/examples/gem-with-java-extension/using-ruby-maven/lib/mygem.rb +++ b/examples/gem-with-java-extension/using-ruby-maven/lib/mygem.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + # can be hardcoded here but for copy the example around that is easier -require Dir[File.dirname(__FILE__) + '/*jar'].first +require Dir["#{File.dirname(__FILE__)}/*jar"].first diff --git a/examples/gem-with-java-extension/using-ruby-maven/mygem.gemspec b/examples/gem-with-java-extension/using-ruby-maven/mygem.gemspec index 13ba5fb..307c869 100644 --- a/examples/gem-with-java-extension/using-ruby-maven/mygem.gemspec +++ b/examples/gem-with-java-extension/using-ruby-maven/mygem.gemspec @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true # use the version from the main project require "#{File.dirname File.expand_path(__FILE__)}/../../lib/jars/version" @@ -19,6 +19,8 @@ Gem::Specification.new do |s| s.files += Dir['*.file'] s.files += Dir['*.gemspec'] + s.required_ruby_version = '>= 2.6' + # declare the jar dependencies s.requirements << 'jar org.slf4j, slf4j-api, 1.7.7' s.requirements << 'jar org.slf4j, slf4j-simple, 1.7.7, :scope => :test' @@ -26,6 +28,5 @@ Gem::Specification.new do |s| s.add_development_dependency 'rake', '~> 10.3' # needed to compile src/main/java/** and create jar file s.add_development_dependency 'ruby-maven', '~> 3.3' + s.metadata['rubygems_mfa_required'] = 'true' end - -# vim: syntax=Ruby diff --git a/examples/gem-with-java-extension/using-ruby-maven/test.rb b/examples/gem-with-java-extension/using-ruby-maven/test.rb index 2f00d35..2ff4cbd 100644 --- a/examples/gem-with-java-extension/using-ruby-maven/test.rb +++ b/examples/gem-with-java-extension/using-ruby-maven/test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # setup env $LOAD_PATH << 'lib' @@ -5,4 +7,4 @@ require 'mygem' # use it -puts Java::App.hello('world')) +puts Java::App.hello('world') diff --git a/examples/sinatra-app/having-gems-with-jar-dependencies/Gemfile b/examples/sinatra-app/having-gems-with-jar-dependencies/Gemfile index 0517647..72c07a7 100644 --- a/examples/sinatra-app/having-gems-with-jar-dependencies/Gemfile +++ b/examples/sinatra-app/having-gems-with-jar-dependencies/Gemfile @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true source 'https://rubygems.org' @@ -10,5 +10,3 @@ group :development do gem 'jar-dependencies', '0.3.0' gem 'ruby-maven', '~> 3.3', '>= 3.3.8' end - -# vim: syntax=Ruby diff --git a/examples/sinatra-app/having-gems-with-jar-dependencies/app/hellowarld.rb b/examples/sinatra-app/having-gems-with-jar-dependencies/app/hellowarld.rb index 8007fe8..f74a206 100644 --- a/examples/sinatra-app/having-gems-with-jar-dependencies/app/hellowarld.rb +++ b/examples/sinatra-app/having-gems-with-jar-dependencies/app/hellowarld.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'sinatra' require 'json' require 'ostruct' @@ -8,9 +10,8 @@ require 'leafy/rack/admin' require 'leafy/rack/instrumented' -data = OpenStruct.new -data.surname = 'meier' -data.firstname = 'christian' +Data = Struct.new(:surname, :firstname) +data = Data.new('meier', 'christian') configure do metrics = Leafy::Metrics::Registry.new @@ -29,9 +30,7 @@ end health.register('app.health') do - if data.surname.length + data.firstname.length < 4 - 'stored names are too short' - end + 'stored names are too short' if data.surname.length + data.firstname.length < 4 end set :histogram, metrics.register_histogram('app.name_length') diff --git a/examples/sinatra-app/having-gems-with-jar-dependencies/config.ru b/examples/sinatra-app/having-gems-with-jar-dependencies/config.ru index 2c111f1..f9ac439 100644 --- a/examples/sinatra-app/having-gems-with-jar-dependencies/config.ru +++ b/examples/sinatra-app/having-gems-with-jar-dependencies/config.ru @@ -1,4 +1,6 @@ -$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) +# frozen_string_literal: true + +$LOAD_PATH.unshift(__dir__) require 'bundler/setup' diff --git a/examples/sinatra-app/having-jarfile-and-gems-with-jar-dependencies/Gemfile b/examples/sinatra-app/having-jarfile-and-gems-with-jar-dependencies/Gemfile index 0517647..72c07a7 100644 --- a/examples/sinatra-app/having-jarfile-and-gems-with-jar-dependencies/Gemfile +++ b/examples/sinatra-app/having-jarfile-and-gems-with-jar-dependencies/Gemfile @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true source 'https://rubygems.org' @@ -10,5 +10,3 @@ group :development do gem 'jar-dependencies', '0.3.0' gem 'ruby-maven', '~> 3.3', '>= 3.3.8' end - -# vim: syntax=Ruby diff --git a/examples/sinatra-app/having-jarfile-and-gems-with-jar-dependencies/Jarfile b/examples/sinatra-app/having-jarfile-and-gems-with-jar-dependencies/Jarfile index 0b1f609..b9536cb 100644 --- a/examples/sinatra-app/having-jarfile-and-gems-with-jar-dependencies/Jarfile +++ b/examples/sinatra-app/having-jarfile-and-gems-with-jar-dependencies/Jarfile @@ -1 +1,3 @@ +# frozen_string_literal: true + jar 'org.slf4j:slf4j-simple', '1.7.12' diff --git a/examples/sinatra-app/having-jarfile-and-gems-with-jar-dependencies/app/hellowarld.rb b/examples/sinatra-app/having-jarfile-and-gems-with-jar-dependencies/app/hellowarld.rb index 8007fe8..f74a206 100644 --- a/examples/sinatra-app/having-jarfile-and-gems-with-jar-dependencies/app/hellowarld.rb +++ b/examples/sinatra-app/having-jarfile-and-gems-with-jar-dependencies/app/hellowarld.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'sinatra' require 'json' require 'ostruct' @@ -8,9 +10,8 @@ require 'leafy/rack/admin' require 'leafy/rack/instrumented' -data = OpenStruct.new -data.surname = 'meier' -data.firstname = 'christian' +Data = Struct.new(:surname, :firstname) +data = Data.new('meier', 'christian') configure do metrics = Leafy::Metrics::Registry.new @@ -29,9 +30,7 @@ end health.register('app.health') do - if data.surname.length + data.firstname.length < 4 - 'stored names are too short' - end + 'stored names are too short' if data.surname.length + data.firstname.length < 4 end set :histogram, metrics.register_histogram('app.name_length') diff --git a/examples/sinatra-app/having-jarfile-and-gems-with-jar-dependencies/config.ru b/examples/sinatra-app/having-jarfile-and-gems-with-jar-dependencies/config.ru index 2c111f1..f9ac439 100644 --- a/examples/sinatra-app/having-jarfile-and-gems-with-jar-dependencies/config.ru +++ b/examples/sinatra-app/having-jarfile-and-gems-with-jar-dependencies/config.ru @@ -1,4 +1,6 @@ -$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) +# frozen_string_literal: true + +$LOAD_PATH.unshift(__dir__) require 'bundler/setup' diff --git a/bin/lock_jars b/exe/lock_jars similarity index 76% rename from bin/lock_jars rename to exe/lock_jars index 1ccc861..f883227 100755 --- a/bin/lock_jars +++ b/exe/lock_jars @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + require 'jar_dependencies' require 'optparse' options = {} @@ -25,11 +27,14 @@ optparse = OptionParser.new do |opts| options[:tree] = t end - opts.on('-u', '--update JAR_COORDINATE', 'Resolves given dependency and use latest version. JAR_COORDINATE is either artifact_id or group_id:artifact_id') do |u| + opts.on('-u', '--update JAR_COORDINATE', + 'Resolves given dependency and use latest version. ' \ + 'JAR_COORDINATE is either artifact_id or group_id:artifact_id') do |u| options[:update] = u end - opts.on('--vendor-dir DIRECTORY', 'Vendor directory where to copy the installed jars.', 'add this directory to $LOAD_PATH or set JARS_HOME respectively.') do |dir| + opts.on('--vendor-dir DIRECTORY', 'Vendor directory where to copy the installed jars.' \ + 'add this directory to $LOAD_PATH or set JARS_HOME respectively.') do |dir| options[:vendor_dir] = dir end diff --git a/bin/vendor_jars b/exe/vendor_jars similarity index 70% rename from bin/vendor_jars rename to exe/vendor_jars index 88f2d64..f4d83c4 100755 --- a/bin/vendor_jars +++ b/exe/vendor_jars @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + require 'jars/installer' Jars::Installer.vendor_jars! diff --git a/integration/bundle_with_path/Gemfile b/integration/bundle_with_path/Gemfile index fa75df1..7f4f5e9 100644 --- a/integration/bundle_with_path/Gemfile +++ b/integration/bundle_with_path/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' gemspec diff --git a/integration/bundle_with_path/Mavenfile b/integration/bundle_with_path/Mavenfile index dec2784..d77b6d5 100644 --- a/integration/bundle_with_path/Mavenfile +++ b/integration/bundle_with_path/Mavenfile @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true repository id: 'rubygems-releases', url: 'http://rubygems-proxy.torquebox.org/releases' @@ -26,5 +26,3 @@ gem 'ruby-maven', '${ruby-maven.version}' jruby_plugin :gem, '${jruby.plugins.version}' do execute_goal :initialize end - -# vim: syntax=Ruby diff --git a/integration/bundle_with_path/bundle.rb b/integration/bundle_with_path/bundle.rb index 8ca2aaf..c6037c5 100644 --- a/integration/bundle_with_path/bundle.rb +++ b/integration/bundle_with_path/bundle.rb @@ -1,11 +1,9 @@ +# frozen_string_literal: true -file = File.expand_path('../../../jar-dependencies.gemspec', __FILE__) -spec = Dir.chdir(File.dirname(file)) do - eval(File.read(file)) -end +require_relative '../../lib/jars/version' # force to use prereleased gem -gem 'jar-dependencies', spec.version +gem 'jar-dependencies', Jars::VERSION require 'jar-dependencies' require 'bundler/friendly_errors' diff --git a/integration/bundle_with_path/mygem.gemspec b/integration/bundle_with_path/mygem.gemspec index eafbaf8..de6ffd5 100644 --- a/integration/bundle_with_path/mygem.gemspec +++ b/integration/bundle_with_path/mygem.gemspec @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true Gem::Specification.new do |s| s.name = 'foo' @@ -7,7 +7,7 @@ Gem::Specification.new do |s| s.summary = 'foo' s.requirements << 'jar io.dropwizard.metrics:metrics-healthchecks, 3.1.0' s.platform = 'java' + s.required_ruby_version = '>= 2.6' s.add_runtime_dependency 'jar-dependencies' + s.metadata['rubygems_mfa_required'] = 'true' end - -# vim: syntax=Ruby diff --git a/integration/bundle_with_path_to_gemspec/Gemfile b/integration/bundle_with_path_to_gemspec/Gemfile index 085a2e1..8b7cf25 100644 --- a/integration/bundle_with_path_to_gemspec/Gemfile +++ b/integration/bundle_with_path_to_gemspec/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' gem 'foo', path: File.dirname(__FILE__), require: false diff --git a/integration/bundle_with_path_to_gemspec/Mavenfile b/integration/bundle_with_path_to_gemspec/Mavenfile index 732b5b9..2211a31 100644 --- a/integration/bundle_with_path_to_gemspec/Mavenfile +++ b/integration/bundle_with_path_to_gemspec/Mavenfile @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true plugin_repository id: 'rubygems-releases', url: 'http://rubygems-proxy.torquebox.org/releases' @@ -10,5 +10,3 @@ jruby_plugin :gem, filename: 'bundle', args: 'install' do gem 'bundler', '${bundler.version}' gem 'jar-dependencies', '${jar-dependencies.version}' end - -# vim: syntax=Ruby diff --git a/integration/bundle_with_path_to_gemspec/mygem.gemspec b/integration/bundle_with_path_to_gemspec/mygem.gemspec index 6145e29..7c88d94 100644 --- a/integration/bundle_with_path_to_gemspec/mygem.gemspec +++ b/integration/bundle_with_path_to_gemspec/mygem.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Gem::Specification.new do |s| s.name = 'foo' version = '0.0.1' @@ -5,4 +7,6 @@ Gem::Specification.new do |s| s.version = mdata ? mdata[1] : version s.authors = ['foo'] s.summary = 'foo' + s.required_ruby_version = '>= 2.6' + s.metadata['rubygems_mfa_required'] = 'true' end diff --git a/integration/bundle_with_two_gemspecs/Gemfile b/integration/bundle_with_two_gemspecs/Gemfile index 1e1872c..550597e 100644 --- a/integration/bundle_with_two_gemspecs/Gemfile +++ b/integration/bundle_with_two_gemspecs/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' gemspec name: 'wat_two_gemspecs' diff --git a/integration/bundle_with_two_gemspecs/Mavenfile b/integration/bundle_with_two_gemspecs/Mavenfile index 732b5b9..2211a31 100644 --- a/integration/bundle_with_two_gemspecs/Mavenfile +++ b/integration/bundle_with_two_gemspecs/Mavenfile @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true plugin_repository id: 'rubygems-releases', url: 'http://rubygems-proxy.torquebox.org/releases' @@ -10,5 +10,3 @@ jruby_plugin :gem, filename: 'bundle', args: 'install' do gem 'bundler', '${bundler.version}' gem 'jar-dependencies', '${jar-dependencies.version}' end - -# vim: syntax=Ruby diff --git a/integration/bundle_with_two_gemspecs/another_gemspec.gemspec b/integration/bundle_with_two_gemspecs/another_gemspec.gemspec index 7f6f037..abddf1d 100644 --- a/integration/bundle_with_two_gemspecs/another_gemspec.gemspec +++ b/integration/bundle_with_two_gemspecs/another_gemspec.gemspec @@ -1,5 +1,6 @@ +# frozen_string_literal: true -lib = File.expand_path('../lib', __FILE__) +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'another_gemspec/version' @@ -15,6 +16,7 @@ Gem::Specification.new do |spec| spec.files = `git ls-files -z`.split("\x0") spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } - spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ['lib'] + spec.metadata['rubygems_mfa_required'] = 'true' + spec.required_ruby_version = '>= 2.6' end diff --git a/integration/bundle_with_two_gemspecs/lib/another_gemspec/version.rb b/integration/bundle_with_two_gemspecs/lib/another_gemspec/version.rb index c52aff3..003d559 100644 --- a/integration/bundle_with_two_gemspecs/lib/another_gemspec/version.rb +++ b/integration/bundle_with_two_gemspecs/lib/another_gemspec/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module AnotherGemspec - VERSION = '0.0.1'.freeze + VERSION = '0.0.1' end diff --git a/integration/bundle_with_two_gemspecs/lib/wat_two_gemspecs.rb b/integration/bundle_with_two_gemspecs/lib/wat_two_gemspecs.rb index 6fd8a93..ea34b67 100644 --- a/integration/bundle_with_two_gemspecs/lib/wat_two_gemspecs.rb +++ b/integration/bundle_with_two_gemspecs/lib/wat_two_gemspecs.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'wat_two_gemspecs/version' module WatTwoGemspecs diff --git a/integration/bundle_with_two_gemspecs/lib/wat_two_gemspecs/version.rb b/integration/bundle_with_two_gemspecs/lib/wat_two_gemspecs/version.rb index f782df4..9c13b7c 100644 --- a/integration/bundle_with_two_gemspecs/lib/wat_two_gemspecs/version.rb +++ b/integration/bundle_with_two_gemspecs/lib/wat_two_gemspecs/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module WatTwoGemspecs - VERSION = '0.0.1'.freeze + VERSION = '0.0.1' end diff --git a/integration/bundle_with_two_gemspecs/wat_two_gemspecs.gemspec b/integration/bundle_with_two_gemspecs/wat_two_gemspecs.gemspec index b8688c3..2a4b9e4 100644 --- a/integration/bundle_with_two_gemspecs/wat_two_gemspecs.gemspec +++ b/integration/bundle_with_two_gemspecs/wat_two_gemspecs.gemspec @@ -1,5 +1,6 @@ +# frozen_string_literal: true -lib = File.expand_path('../lib', __FILE__) +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'wat_two_gemspecs/version' @@ -15,9 +16,11 @@ Gem::Specification.new do |spec| spec.files = `git ls-files -z`.split("\x0") spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } - spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ['lib'] + s.required_ruby_version = '>= 2.6' + spec.add_development_dependency 'bundler', '~> 1.7' spec.add_development_dependency 'rake', '~> 10.0' + spec.metadata['rubygems_mfa_required'] = 'true' end diff --git a/integration/depending_gems/Mavenfile b/integration/depending_gems/Mavenfile index abeb414..2cf1855 100644 --- a/integration/depending_gems/Mavenfile +++ b/integration/depending_gems/Mavenfile @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true group_id 'jar-dependencies' @@ -11,11 +11,11 @@ properties('gem.home' => '${project.basedir}/pkg/rubygems', phase :test do execute 'verify' do |ctx| - log = File.read(ctx.basedir.to_pathname + '/build.log') + log = File.read("#{ctx.basedir.to_pathname}/build.log") ['io.dropwizard.metrics:metrics-json:3.1.0', 'io.dropwizard.metrics:metrics-jvm:3.1.0', 'io.dropwizard.metrics:metrics-core:3.1.0'].each do |expected| - raise "log does not contain '#{expected}'" unless log =~ /#{expected}/ + raise "log does not contain '#{expected}'" unless /#{expected}/.match?(log) puts "log contains '#{expected}'" end diff --git a/integration/depending_gems/biglib/Gemfile b/integration/depending_gems/biglib/Gemfile index d911f81..fcc71d8 100644 --- a/integration/depending_gems/biglib/Gemfile +++ b/integration/depending_gems/biglib/Gemfile @@ -1,9 +1,7 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true source 'https://rubygems.org' gem 'simplelib', path: '../simplelib' gemspec - -# vim: syntax=Ruby diff --git a/integration/depending_gems/biglib/Mavenfile b/integration/depending_gems/biglib/Mavenfile index a62bb8e..906f918 100644 --- a/integration/depending_gems/biglib/Mavenfile +++ b/integration/depending_gems/biglib/Mavenfile @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true properties('gem.home' => '${basedir}/../pkg', 'gem.path' => '${gem.home}') @@ -27,5 +27,3 @@ plugin('org.codehaus.mojo:exec-maven-plugin', '1.2', 'org.jruby.Main', '-S', 'bundle', 'install']) end - -# vim: syntax=Ruby diff --git a/integration/depending_gems/biglib/biglib.gemspec b/integration/depending_gems/biglib/biglib.gemspec index beef6dc..84ff264 100644 --- a/integration/depending_gems/biglib/biglib.gemspec +++ b/integration/depending_gems/biglib/biglib.gemspec @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true Gem::Specification.new do |s| s.name = 'biglib' @@ -12,11 +12,12 @@ Gem::Specification.new do |s| s.homepage = 'https://example.com' s.description = 'more examples' + s.required_ruby_version = '>= 2.6' + s.requirements << 'jar io.dropwizard.metrics:metrics-json, 3.1.0' s.requirements << 'jar io.dropwizard.metrics:metrics-jvm, 3.1.0' s.add_runtime_dependency 'jar-dependencies' s.add_development_dependency 'simplelib', '1' + s.metadata['rubygems_mfa_required'] = 'true' end - -# vim: syntax=Ruby diff --git a/integration/depending_gems/simplelib/Mavenfile b/integration/depending_gems/simplelib/Mavenfile index b892e0c..d8ece61 100644 --- a/integration/depending_gems/simplelib/Mavenfile +++ b/integration/depending_gems/simplelib/Mavenfile @@ -1,7 +1,5 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true properties('gem.home' => '${basedir}/../pkg', 'gem.path' => '${gem.home}') gemspec - -# vim: syntax=Ruby diff --git a/integration/depending_gems/simplelib/simplelib.gemspec b/integration/depending_gems/simplelib/simplelib.gemspec index af020ac..a337e02 100644 --- a/integration/depending_gems/simplelib/simplelib.gemspec +++ b/integration/depending_gems/simplelib/simplelib.gemspec @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true Gem::Specification.new do |s| s.name = 'simplelib' @@ -12,9 +12,10 @@ Gem::Specification.new do |s| s.homepage = 'https://example.com' s.description = 'more examples' + s.required_ruby_version = '>= 2.6' + s.requirements << 'jar io.dropwizard.metrics:metrics-core, 3.1.0' s.add_runtime_dependency 'jar-dependencies' + s.metadata['rubygems_mfa_required'] = 'true' end - -# vim: syntax=Ruby diff --git a/integration/gemspec_with_classifier_and_exclusions/Gemfile b/integration/gemspec_with_classifier_and_exclusions/Gemfile index 851fabc..5f10ba8 100644 --- a/integration/gemspec_with_classifier_and_exclusions/Gemfile +++ b/integration/gemspec_with_classifier_and_exclusions/Gemfile @@ -1,2 +1,4 @@ +# frozen_string_literal: true + source 'https://rubygems.org' gemspec diff --git a/integration/gemspec_with_classifier_and_exclusions/Mavenfile b/integration/gemspec_with_classifier_and_exclusions/Mavenfile index 05c0fc5..19aa9c8 100644 --- a/integration/gemspec_with_classifier_and_exclusions/Mavenfile +++ b/integration/gemspec_with_classifier_and_exclusions/Mavenfile @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true repository id: 'rubygems-releases', url: 'http://rubygems-proxy.torquebox.org/releases' @@ -40,5 +40,3 @@ gem 'ruby-maven', '${ruby-maven.version}' jruby_plugin :gem, '${jruby.plugins.version}' do execute_goal :initialize end - -# vim: syntax=Ruby diff --git a/integration/gemspec_with_classifier_and_exclusions/mygem.gemspec b/integration/gemspec_with_classifier_and_exclusions/mygem.gemspec index fcae2ac..f626142 100644 --- a/integration/gemspec_with_classifier_and_exclusions/mygem.gemspec +++ b/integration/gemspec_with_classifier_and_exclusions/mygem.gemspec @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true Gem::Specification.new do |s| s.name = 'mygem' @@ -10,7 +10,7 @@ Gem::Specification.new do |s| s.requirements << 'jar org.slf4j:slf4j-simple:1.7.7, :scope => :provided' s.requirements << 'jar junit:junit:4.12, :scope => :test' s.platform = 'java' + s.required_ruby_version = '>= 2.6' s.add_runtime_dependency 'jar-dependencies' + s.metadata['rubygems_mfa_required'] = 'true' end - -# vim: syntax=Ruby diff --git a/integration/gemspec_with_system_jar/Mavenfile b/integration/gemspec_with_system_jar/Mavenfile index f3e6e11..5325666 100644 --- a/integration/gemspec_with_system_jar/Mavenfile +++ b/integration/gemspec_with_system_jar/Mavenfile @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true id 'jar-dependencies:gemspec_with_system_jar:0' @@ -14,5 +14,3 @@ properties('gem.home' => '${project.basedir}/../rubygems', jruby_plugin :gem, '${jruby.plugins.version}' do execute_goal :initialize end - -# vim: syntax=Ruby diff --git a/integration/gemspec_with_system_jar/gem/Mavenfile b/integration/gemspec_with_system_jar/gem/Mavenfile index 982d724..601da33 100644 --- a/integration/gemspec_with_system_jar/gem/Mavenfile +++ b/integration/gemspec_with_system_jar/gem/Mavenfile @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true inherit 'jar-dependencies:gemspec_with_system_jar:0' do # TODO: should not be needed with ruby-maven @@ -9,12 +9,8 @@ gemspec # use the current jar dependencies gem model.dependencies.each do |d| - if d.artifact_id == 'jar-dependencies' - d.version = '${jar-dependencies.version}' - end + d.version = '${jar-dependencies.version}' if d.artifact_id == 'jar-dependencies' end properties('gem.home' => '${project.basedir}/../../rubygems', 'gem.path' => '${gem.home}') - -# vim: syntax=Ruby diff --git a/integration/gemspec_with_system_jar/gem/lib/first.rb b/integration/gemspec_with_system_jar/gem/lib/first.rb index b160d65..0bd992c 100644 --- a/integration/gemspec_with_system_jar/gem/lib/first.rb +++ b/integration/gemspec_with_system_jar/gem/lib/first.rb @@ -1 +1,3 @@ +# frozen_string_literal: true + require 'with-system-jar_jars' diff --git a/integration/gemspec_with_system_jar/gem/with-system-jar.gemspec b/integration/gemspec_with_system_jar/gem/with-system-jar.gemspec index 0802812..e02afb0 100644 --- a/integration/gemspec_with_system_jar/gem/with-system-jar.gemspec +++ b/integration/gemspec_with_system_jar/gem/with-system-jar.gemspec @@ -1,9 +1,6 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true -file = File.expand_path('../../../../jar-dependencies.gemspec', __FILE__) -spec = Dir.chdir(File.dirname(file)) do - eval(File.read(file)) -end +require_relative '../../../lib/jars/version' Gem::Specification.new do |s| s.name = 'with-system-jar' @@ -15,9 +12,10 @@ Gem::Specification.new do |s| s.platform = 'java' s.files = Dir['lib/**/*.rb'] + Dir['*.gemspec'] - s.add_runtime_dependency 'jar-dependencies', spec.version + s.required_ruby_version = '>= 2.6' + + s.add_runtime_dependency 'jar-dependencies', Jars::VERSION s.requirements << "jar 'org.apache.hbase:hbase-annotations', '=0.98.7-hadoop2'" + s.metadata['rubygems_mfa_required'] = 'true' end - -# vim: syntax=Ruby diff --git a/integration/gemspec_with_system_jar/verify/Mavenfile b/integration/gemspec_with_system_jar/verify/Mavenfile index 7c91a5f..5bd60d2 100644 --- a/integration/gemspec_with_system_jar/verify/Mavenfile +++ b/integration/gemspec_with_system_jar/verify/Mavenfile @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true inherit 'jar-dependencies:gemspec_with_system_jar:0' do # TODO: should not be needed with ruby-maven @@ -28,5 +28,3 @@ end properties('gem.home' => '${project.basedir}/../../rubygems', 'gem.path' => '${gem.home}') - -# vim: syntax=Ruby diff --git a/integration/gemspec_with_system_jar/verify/test.rb b/integration/gemspec_with_system_jar/verify/test.rb index b6eeead..5c3ea3b 100644 --- a/integration/gemspec_with_system_jar/verify/test.rb +++ b/integration/gemspec_with_system_jar/verify/test.rb @@ -1,18 +1,13 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true -file = File.expand_path('../../../../jar-dependencies.gemspec', __FILE__) -spec = Dir.chdir(File.dirname(file)) do - eval(File.read(file)) -end +require_relative '../../../lib/jars/version' # force to use prereleased gem -gem 'jar-dependencies', spec.version +gem 'jar-dependencies', Jars::VERSION require 'jar-dependencies' -Gem.install(File.expand_path('../../gem/pkg/with-system-jar-1.1.1.gem', __FILE__)) +Gem.install(File.expand_path('../gem/pkg/with-system-jar-1.1.1.gem', __dir__)) require 'first' raise "missing tools.jar, not found in #{$CLASSPATH.inspect}" unless $CLASSPATH.detect { |c| c =~ /tools.jar/ } - -# vim: syntax=Ruby diff --git a/integration/install_ruby_maven_when_needed/Mavenfile b/integration/install_ruby_maven_when_needed/Mavenfile index 8c6ad1e..40dff07 100644 --- a/integration/install_ruby_maven_when_needed/Mavenfile +++ b/integration/install_ruby_maven_when_needed/Mavenfile @@ -1,9 +1,7 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true id 'jar-dependencies:install-ruby-maven:0' packaging 'pom' modules %w[gem verify] - -# vim: syntax=Ruby diff --git a/integration/install_ruby_maven_when_needed/gem/Mavenfile b/integration/install_ruby_maven_when_needed/gem/Mavenfile index f414cb6..c7a60f9 100644 --- a/integration/install_ruby_maven_when_needed/gem/Mavenfile +++ b/integration/install_ruby_maven_when_needed/gem/Mavenfile @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true inherit 'jar-dependencies:install-ruby-maven:0' do # TODO: should not be needed with ruby-maven @@ -9,12 +9,8 @@ gemspec # use the current jar dependencies gem model.dependencies.each do |d| - if d.artifact_id == 'jar-dependencies' - d.version = '${jar-dependencies.version}' - end + d.version = '${jar-dependencies.version}' if d.artifact_id == 'jar-dependencies' end properties('gem.home' => '${project.basedir}/../../rubygems', 'gem.path' => '${gem.home}') - -# vim: syntax=Ruby diff --git a/integration/install_ruby_maven_when_needed/gem/lib/my.rb b/integration/install_ruby_maven_when_needed/gem/lib/my.rb index b6a4700..2481538 100644 --- a/integration/install_ruby_maven_when_needed/gem/lib/my.rb +++ b/integration/install_ruby_maven_when_needed/gem/lib/my.rb @@ -1 +1,3 @@ +# frozen_string_literal: true + require 'my_jars' diff --git a/integration/install_ruby_maven_when_needed/gem/lib/my_jars.rb b/integration/install_ruby_maven_when_needed/gem/lib/my_jars.rb index 4b40fcf..af41c9f 100644 --- a/integration/install_ruby_maven_when_needed/gem/lib/my_jars.rb +++ b/integration/install_ruby_maven_when_needed/gem/lib/my_jars.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # this is a generated file, to avoid over-writing it just delete this comment require 'jar_dependencies' diff --git a/integration/install_ruby_maven_when_needed/gem/my.gemspec b/integration/install_ruby_maven_when_needed/gem/my.gemspec index b80eb00..4dbd958 100644 --- a/integration/install_ruby_maven_when_needed/gem/my.gemspec +++ b/integration/install_ruby_maven_when_needed/gem/my.gemspec @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true Gem::Specification.new do |s| s.name = 'my' @@ -11,10 +11,11 @@ Gem::Specification.new do |s| s.files << Dir['*file'] s.files << 'my.gemspec' + s.required_ruby_version = '>= 2.6' + s.add_runtime_dependency 'jar-dependencies' s.platform = 'java' s.requirements << "jar 'com.fasterxml.jackson.core:jackson-core', '2.3.0'" + s.metadata['rubygems_mfa_required'] = 'true' end - -# vim: syntax=Ruby diff --git a/integration/install_ruby_maven_when_needed/verify/Gemfile b/integration/install_ruby_maven_when_needed/verify/Gemfile index 4b493f7..aa7365f 100644 --- a/integration/install_ruby_maven_when_needed/verify/Gemfile +++ b/integration/install_ruby_maven_when_needed/verify/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' gemspec path: '../gem' diff --git a/integration/install_ruby_maven_when_needed/verify/Mavenfile b/integration/install_ruby_maven_when_needed/verify/Mavenfile index dd89113..26e69ce 100644 --- a/integration/install_ruby_maven_when_needed/verify/Mavenfile +++ b/integration/install_ruby_maven_when_needed/verify/Mavenfile @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true inherit 'jar-dependencies:install-ruby-maven:0' do # TODO: should not be needed with ruby-maven @@ -37,5 +37,3 @@ gem 'bundler', '${bundler.version}' jruby_plugin :gem, '${jruby.plugins.version}' do execute_goal :initialize end - -# vim: syntax=Ruby diff --git a/integration/install_ruby_maven_when_needed/verify/test_bundler.rb b/integration/install_ruby_maven_when_needed/verify/test_bundler.rb index 9ee1f9b..e99296a 100644 --- a/integration/install_ruby_maven_when_needed/verify/test_bundler.rb +++ b/integration/install_ruby_maven_when_needed/verify/test_bundler.rb @@ -1,19 +1,17 @@ +# frozen_string_literal: true + gemspecs = File.join(Gem.dir, 'specifications', 'ruby-maven-*gemspec') Dir[gemspecs].each do |f| - begin - File.delete(f) - rescue - nil - end + File.delete(f) +rescue + nil end version = ARGV[0] gem 'jar-dependencies', version.sub(/-SNAPSHOT/, '') Kernel.at_exit do - if Dir[gemspecs].size != 2 - raise "did not find two ruby-maven gems installed #{Dir[gemspecs]}" - end + raise "did not find two ruby-maven gems installed #{Dir[gemspecs]}" if Dir[gemspecs].size != 2 end # this is like: gem install --ignore-dependencies, ../gem/pkg/my-1.1.1.gem diff --git a/integration/install_ruby_maven_when_needed/verify/test_gem.rb b/integration/install_ruby_maven_when_needed/verify/test_gem.rb index 6d19f5a..26781a7 100644 --- a/integration/install_ruby_maven_when_needed/verify/test_gem.rb +++ b/integration/install_ruby_maven_when_needed/verify/test_gem.rb @@ -1,21 +1,19 @@ +# frozen_string_literal: true + gemspecs = File.join(Gem.dir, 'specifications', 'ruby-maven-*gemspec') Dir[gemspecs].each do |f| - begin - File.delete(f) - rescue - nil - end + File.delete(f) +rescue + nil end version = ARGV[0] gem 'jar-dependencies', version.sub(/-SNAPSHOT/, '') Kernel.at_exit do - if Dir[gemspecs].size != 2 - raise "did not find two ruby-maven gems installed #{Dir[gemspecs]}" - end + raise "did not find two ruby-maven gems installed #{Dir[gemspecs]}" if Dir[gemspecs].size != 2 end # this is like: gem install --ignore-dependencies, ../gem/pkg/my-1.1.1.gem -ARGV.replace(['install', '--ignore-dependencies', File.expand_path('../../gem/pkg/my-1.1.1.gem', __FILE__)]) +ARGV.replace(['install', '--ignore-dependencies', File.expand_path('../gem/pkg/my-1.1.1.gem', __dir__)]) load File.join(JRuby.runtime.instance_config.jruby_home, 'bin/gem') diff --git a/integration/jars_lock_gemfile/Gemfile b/integration/jars_lock_gemfile/Gemfile index ef349f1..a10b1f8 100644 --- a/integration/jars_lock_gemfile/Gemfile +++ b/integration/jars_lock_gemfile/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' gem 'leafy-metrics', '0.6.1' diff --git a/integration/jars_lock_gemfile/Jarfile b/integration/jars_lock_gemfile/Jarfile index a69dc7c..7951db3 100644 --- a/integration/jars_lock_gemfile/Jarfile +++ b/integration/jars_lock_gemfile/Jarfile @@ -1,2 +1,3 @@ +# frozen_string_literal: true jar 'org.slf4j:slf4j-simple:1.7.7' diff --git a/integration/jars_lock_gemfile/Mavenfile b/integration/jars_lock_gemfile/Mavenfile index cd83e10..56308a4 100644 --- a/integration/jars_lock_gemfile/Mavenfile +++ b/integration/jars_lock_gemfile/Mavenfile @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true repository id: 'rubygems-releases', url: 'http://rubygems-proxy.torquebox.org/releases' @@ -46,5 +46,3 @@ gem 'ruby-maven', '${ruby-maven.version}' jruby_plugin :gem, '${jruby.plugins.version}' do execute_goal :initialize end - -# vim: syntax=Ruby diff --git a/integration/jars_lock_gemfile/test.rb b/integration/jars_lock_gemfile/test.rb index a0a677d..54b5da8 100644 --- a/integration/jars_lock_gemfile/test.rb +++ b/integration/jars_lock_gemfile/test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + unless defined? Jars # trigger to require of Jars.lock require 'leafy-metrics' diff --git a/integration/jars_lock_gemspec_with_jars/Mavenfile b/integration/jars_lock_gemspec_with_jars/Mavenfile index 269b4bd..b146fe3 100644 --- a/integration/jars_lock_gemspec_with_jars/Mavenfile +++ b/integration/jars_lock_gemspec_with_jars/Mavenfile @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true repository id: 'rubygems-releases', url: 'http://rubygems-proxy.torquebox.org/releases' @@ -8,7 +8,6 @@ phase :test do environmentVariables: { 'GEM_HOME' => '${gem.home}', 'GEM_PATH' => '${gem.home}', 'JARS_VERBOSE' => true }) do - # need to uninstall bundler otherwise it finds the Gemfile from the project # root. bundler does descend the directory until it finds a Gemfile. execute_goal(:exec, @@ -49,5 +48,3 @@ gem 'ruby-maven', '${ruby-maven.version}' jruby_plugin :gem, '${jruby.plugins.version}' do execute_goal :initialize end - -# vim: syntax=Ruby diff --git a/integration/jars_lock_gemspec_with_jars/first.gemspec b/integration/jars_lock_gemspec_with_jars/first.gemspec index d5fb241..06859f0 100644 --- a/integration/jars_lock_gemspec_with_jars/first.gemspec +++ b/integration/jars_lock_gemspec_with_jars/first.gemspec @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true Gem::Specification.new do |s| s.name = 'first' @@ -11,10 +11,12 @@ Gem::Specification.new do |s| s.files << 'first.gemspec' s.platform = 'java' + + s.required_ruby_version = '>= 2.6' + s.add_runtime_dependency 'jar-dependencies', '~> 0.1' s.requirements << "jar 'org.apache.hbase:hbase-annotations', '=0.98.7-hadoop2', ['junit:junit']" s.requirements << 'jar org.jruby:jruby, 1.7.20, :scope => :provided' + s.metadata['rubygems_mfa_required'] = 'true' end - -# vim: syntax=Ruby diff --git a/integration/jars_lock_gemspec_with_jars/test.rb b/integration/jars_lock_gemspec_with_jars/test.rb index 49f06c0..90936f9 100644 --- a/integration/jars_lock_gemspec_with_jars/test.rb +++ b/integration/jars_lock_gemspec_with_jars/test.rb @@ -1,10 +1,13 @@ +# frozen_string_literal: true + unless defined? Jars require 'jar-dependencies' # trigger to require of Jars.lock require_jar('org.apache.hbase', 'hbase-annotations', '0.98.7-hadoop2') end -['hbase-annotations-0.98.7-hadoop2.jar', '/tools.jar', 'findbugs-annotations-1.3.9-1.jar', 'log4j-1.2.17.jar'].each do |jar| +['hbase-annotations-0.98.7-hadoop2.jar', '/tools.jar', 'findbugs-annotations-1.3.9-1.jar', + 'log4j-1.2.17.jar'].each do |jar| raise "missing #{jar}" unless $CLASSPATH.detect { |c| c =~ /#{jar}/ } end diff --git a/integration/lock_jars/Gemfile b/integration/lock_jars/Gemfile index 5706589..b68eb02 100644 --- a/integration/lock_jars/Gemfile +++ b/integration/lock_jars/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' # needed otherwise the integration test find the one from the parent directory diff --git a/integration/lock_jars/Jarfile b/integration/lock_jars/Jarfile index c37e826..e80906f 100644 --- a/integration/lock_jars/Jarfile +++ b/integration/lock_jars/Jarfile @@ -1 +1,3 @@ +# frozen_string_literal: true + jar 'org.bouncycastle:bcpkix-jdk15on:1.54' diff --git a/integration/lock_jars/Mavenfile b/integration/lock_jars/Mavenfile index 25479d0..34cc66a 100644 --- a/integration/lock_jars/Mavenfile +++ b/integration/lock_jars/Mavenfile @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true extension 'org.torquebox.mojo:mavengem-wagon:0.2.0' @@ -31,5 +31,3 @@ gem 'ruby-maven', '${ruby-maven.version}' jruby_plugin :gem, '${jruby.plugins.version}' do execute_goal :initialize end - -# vim: syntax=Ruby diff --git a/integration/nested_jars_lock_from_classloader/Mavenfile b/integration/nested_jars_lock_from_classloader/Mavenfile index ec2242e..aaf734c 100644 --- a/integration/nested_jars_lock_from_classloader/Mavenfile +++ b/integration/nested_jars_lock_from_classloader/Mavenfile @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true packaging 'jar' @@ -23,5 +23,3 @@ end properties('gem.home' => '${project.basedir}/pkg/rubygems', 'gem.path' => '${gem.home}') - -# vim: syntax=Ruby diff --git a/integration/nested_jars_lock_from_classloader/test.rb b/integration/nested_jars_lock_from_classloader/test.rb index dfd2ea6..7a97905 100644 --- a/integration/nested_jars_lock_from_classloader/test.rb +++ b/integration/nested_jars_lock_from_classloader/test.rb @@ -1,18 +1,16 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true require 'jar-dependencies' require 'minitest/autorun' -basedir = ENV_JAVA['jars.home'] = File.expand_path(File.dirname(__FILE__)) +basedir = ENV_JAVA['jars.home'] = __dir__ describe Jars do it 'requires Jars.lock from required jars' do Jars.require_jars_lock - list = $CLASSPATH.collect do |c| - c.sub /file:#{basedir}\//, '' + $CLASSPATH.collect do |c| + c.sub(%r{file:#{basedir}/}, '') end.must_equal ['org/example/nested/1.0/nested-1.0.jar', 'jline/jline/2.11/jline-2.11.jar'] end end - -# vim: syntax=Ruby diff --git a/integration/require_tests/Mavenfile b/integration/require_tests/Mavenfile index 3a7af4d..0973664 100644 --- a/integration/require_tests/Mavenfile +++ b/integration/require_tests/Mavenfile @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true packaging 'pom' @@ -34,5 +34,3 @@ end properties('gem.home' => '${project.basedir}/pkg/rubygems', 'gem.path' => '${gem.home}') - -# vim: syntax=Ruby diff --git a/integration/require_tests/test_freeze_loading.rb b/integration/require_tests/test_freeze_loading.rb index 59fd4aa..4e60863 100644 --- a/integration/require_tests/test_freeze_loading.rb +++ b/integration/require_tests/test_freeze_loading.rb @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true require 'jar-dependencies' @@ -6,15 +6,12 @@ raise 'expected no env variable for freeze' if ENV[Jars::NO_REQUIRE] -if $CLASSPATH.detect { |c| c =~ /bouncycastle/ } - raise 'expected no bouncycastle jars in classpath' -end +raise 'expected no bouncycastle jars in classpath' if $CLASSPATH.detect { |c| c.include?('bouncycastle') } begin require 'openssl' raise 'expected LoadError' rescue LoadError + # expected end - -# vim: syntax=Ruby diff --git a/integration/require_tests/test_no_more_warnings.rb b/integration/require_tests/test_no_more_warnings.rb index 0c9f216..5c37ea3 100644 --- a/integration/require_tests/test_no_more_warnings.rb +++ b/integration/require_tests/test_no_more_warnings.rb @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true require 'jar-dependencies' @@ -6,15 +6,11 @@ raise 'expected no env variable for freeze' if ENV[Jars::NO_REQUIRE] -if $CLASSPATH.detect { |c| c =~ /bouncycastle/ } - raise 'expected no bouncycastle jars in classpath' -end +raise 'expected no bouncycastle jars in classpath' if $CLASSPATH.detect { |c| c.include?('bouncycastle') } require 'openssl' -unless $CLASSPATH.detect { |c| c =~ /bouncycastle/ } - raise 'did not find bouncycastle jars' -end +raise 'did not find bouncycastle jars' unless $CLASSPATH.detect { |c| c.include?('bouncycastle') } $stderr = StringIO.new @@ -23,5 +19,3 @@ raise 'no warning on jar conflics after freeze' unless $stderr.string.empty? $stderr = STDERR - -# vim: syntax=Ruby diff --git a/integration/vendor_jars/Gemfile b/integration/vendor_jars/Gemfile index 5706589..b68eb02 100644 --- a/integration/vendor_jars/Gemfile +++ b/integration/vendor_jars/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' # needed otherwise the integration test find the one from the parent directory diff --git a/integration/vendor_jars/Mavenfile b/integration/vendor_jars/Mavenfile index d6872b7..e6f5875 100644 --- a/integration/vendor_jars/Mavenfile +++ b/integration/vendor_jars/Mavenfile @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true extension 'org.torquebox.mojo:mavengem-wagon:0.2.0' @@ -30,5 +30,3 @@ gem 'ruby-maven', '${ruby-maven.version}' jruby_plugin :gem, '${jruby.plugins.version}' do execute_goal :initialize end - -# vim: syntax=Ruby diff --git a/integration/vendor_jars/my.gemspec b/integration/vendor_jars/my.gemspec index c922aee..af6b8f5 100644 --- a/integration/vendor_jars/my.gemspec +++ b/integration/vendor_jars/my.gemspec @@ -1,4 +1,4 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true Gem::Specification.new do |s| # this is only needed to retrieve the latest version of jar-dependencies @@ -21,6 +21,8 @@ Gem::Specification.new do |s| s.files << Dir['*file'] s.files << 'example.gemspec' + s.required_ruby_version = '>= 2.6' + # constrain the version of jar-dependencies itself s.add_runtime_dependency 'jar-dependencies', "~> #{version}" @@ -51,6 +53,5 @@ Gem::Specification.new do |s| # avoids to install it on the fly when jar-dependencies needs it s.add_development_dependency 'ruby-maven', '~> 3.3', '>= 3.3.8' + s.metadata['rubygems_mfa_required'] = 'true' end - -# vim: syntax=Ruby diff --git a/integration/vendor_jars/test.rb b/integration/vendor_jars/test.rb index e2ec2dd..e4c7561 100644 --- a/integration/vendor_jars/test.rb +++ b/integration/vendor_jars/test.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + require 'jars/installer' Jars::Installer.vendor_jars! diff --git a/jar-dependencies.gemspec b/jar-dependencies.gemspec index 48623e6..4f506ef 100644 --- a/jar-dependencies.gemspec +++ b/jar-dependencies.gemspec @@ -1,44 +1,52 @@ -#-*- mode: ruby -*- +# frozen_string_literal: true + +require_relative 'lib/jars/version' Gem::Specification.new do |s| s.name = 'jar-dependencies' - path = File.expand_path('lib/jars/version.rb', File.dirname(__FILE__)) - s.version = File.read(path).match(/\s*VERSION\s*=\s*['"](.*)['"]/)[1] + s.version = Jars::VERSION s.author = 'christian meier' s.email = ['mkristian@web.de'] s.summary = 'manage jar dependencies for gems' s.homepage = 'https://github.com/mkristian/jar-dependencies' - s.bindir = 'bin' - s.executables = [lock_jars = 'lock_jars'.freeze] + s.bindir = 'exe' + s.executables = [lock_jars = 'lock_jars'] s.license = 'MIT' - s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR).select do |file| - file =~ /^lib\// || - %w[Mavenfile Rakefile].include?(file) || - ['Readme.md', 'jar-dependencies.gemspec', 'MIT-LICENSE'].include?(file) - end + s.files = Dir['{lib}/**/*'] + %w[Mavenfile Rakefile Readme.md jar-dependencies.gemspec MIT-LICENSE] + + s.description = <<~TEXT + manage jar dependencies for gems and keep track which jar was already + loaded using maven artifact coordinates. it warns on version conflicts and + loads only ONE jar assuming the first one is compatible to the second one + otherwise your project needs to lock down the right version by providing a + Jars.lock file. + TEXT - s.description = 'manage jar dependencies for gems and keep track which jar was already loaded using maven artifact coordinates. it warns on version conflicts and loads only ONE jar assuming the first one is compatible to the second one otherwise your project needs to lock down the right version by providing a Jars.lock file.' + s.required_ruby_version = '>= 2.6' s.add_development_dependency 'minitest', '~> 5.10.0' - s.add_development_dependency 'rake', '~> 10.2' - s.add_development_dependency 'ruby-maven', ruby_maven_version = '~> 3.3.11'.freeze + s.add_development_dependency 'rake', '~> 13.0' + s.add_development_dependency 'rubocop', '~> 1.31' + s.add_development_dependency 'rubocop-performance', '~> 1.14' + s.add_development_dependency 'rubocop-rake', '~> 0.6' + s.add_development_dependency 'ruby-debug', '~> 0.11' + s.add_development_dependency 'ruby-maven', ruby_maven_version = '~> 3.3' - s.post_install_message = <.*/m, '').sub(/.*/m, '') + local_repo = doc.sub(%r{.*}m, '').sub(/.*/m, '') # replace maven like system properties embedded into the string local_repo.gsub!(/\$\{[a-zA-Z.]+\}/) do |a| ENV_JAVA[a[2..-2]] || a @@ -328,7 +333,7 @@ def detect_local_repository(settings) end def to_jar(group_id, artifact_id, version, classifier = nil) - file = String.new("#{group_id.tr('.', '/')}/#{artifact_id}/#{version}/#{artifact_id}-#{version}") + file = +"#{group_id.tr('.', '/')}/#{artifact_id}/#{version}/#{artifact_id}-#{version}" file << "-#{classifier}" if classifier file << '.jar' file @@ -353,17 +358,22 @@ def do_require(*args) require jar end rescue LoadError => e - raise "\n\n\tyou might need to reinstall the gem which depends on the missing jar or in case there is Jars.lock then resolve the jars with `lock_jars` command\n\n" + e.message + ' (LoadError)' + raise "\n\n\tyou might need to reinstall the gem which depends on the " \ + 'missing jar or in case there is Jars.lock then resolve the jars with ' \ + "`lock_jars` command\n\n#{e.message} (LoadError)" end - end # class << self + end end def require_jar(*args, &block) return nil unless Jars.require? + result = Jars.require_jar(*args, &block) if result.is_a? String - args << (block.call || Jars::UNKNOWN) if args.size == 2 && block_given? - Jars.warn { "--- jar coordinate #{args[0..-2].join(':')} already loaded with version #{result} - omit version #{args[-1]}" } + args << (yield || Jars::UNKNOWN) if args.size == 2 && block + Jars.warn do + "--- jar coordinate #{args[0..-2].join(':')} already loaded with version #{result} - omit version #{args[-1]}" + end Jars.debug { " try to load from #{caller.join("\n\t")}" } return false end diff --git a/lib/jar_install_post_install_hook.rb b/lib/jar_install_post_install_hook.rb index 9910a26..a6d588d 100644 --- a/lib/jar_install_post_install_hook.rb +++ b/lib/jar_install_post_install_hook.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # # Copyright (C) 2014 Christian Meier # @@ -21,7 +23,7 @@ if defined?(JRUBY_VERSION) && Gem.post_install_hooks.empty? Gem.post_install do |gem_installer| - require "jars/post_install_hook" + require 'jars/post_install_hook' Jars.post_install_hook(gem_installer) end end diff --git a/lib/jar_installer.rb b/lib/jar_installer.rb deleted file mode 100644 index 8b52d2c..0000000 --- a/lib/jar_installer.rb +++ /dev/null @@ -1 +0,0 @@ -require 'jars/installer' diff --git a/lib/jars/attach_jars_pom.rb b/lib/jars/attach_jars_pom.rb index 0c3771a..37c20d4 100644 --- a/lib/jars/attach_jars_pom.rb +++ b/lib/jars/attach_jars_pom.rb @@ -1,13 +1,17 @@ +# frozen_string_literal: true + # this file is maven DSL (0..10_000).each do |i| coord = ENV_JAVA["jars.#{i}"] break unless coord + artifact = Maven::Tools::Artifact.from_coordinate(coord) exclusions = [] (0..10_000).each do |j| exclusion = ENV_JAVA["jars.#{i}.exclusions.#{j}"] break unless exclusion + exclusions << exclusion end scope = ENV_JAVA["jars.#{i}.scope"] diff --git a/lib/jars/classpath.rb b/lib/jars/classpath.rb index 68e59f6..a6d6732 100644 --- a/lib/jars/classpath.rb +++ b/lib/jars/classpath.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'jars/maven_exec' require 'jars/lock' require 'fileutils' @@ -38,15 +40,11 @@ def dependencies_list deps = Jars.lock_path(mvn.basedir) @deps = deps if deps && File.exist?(deps) end - if @deps - @deps - else - resolve_dependencies - end + @deps || resolve_dependencies end private :dependencies_list - DEPENDENCY_LIST = 'dependencies.list'.freeze + DEPENDENCY_LIST = 'dependencies.list' def resolve_dependencies basedir = workdir('pkg') || workdir('target') || workdir('') deps = File.join(basedir, DEPENDENCY_LIST) @@ -63,10 +61,10 @@ def require(scope = nil) require_jar(*jar.gacv) end end - if scope.nil? || scope == :runtime - process(:provided) do |jar| - Jars.mark_as_required(*jar.gacv) - end + return unless scope.nil? || scope == :runtime + + process(:provided) do |jar| + Jars.mark_as_required(*jar.gacv) end end diff --git a/lib/jars/gemspec_artifacts.rb b/lib/jars/gemspec_artifacts.rb index eaa29bf..9def815 100644 --- a/lib/jars/gemspec_artifacts.rb +++ b/lib/jars/gemspec_artifacts.rb @@ -1,60 +1,64 @@ +# frozen_string_literal: true + module Jars class MavenVersion < String - def self.new(*args) - if args.empty? || (args.size == 1 && args[0].nil?) - nil - else - low, high = convert(args[0]) - low, high = convert(args[1], low, high) if args[1] =~ /[=~><]/ - if low == high - low + class << self + def new(*args) + if args.empty? || (args.size == 1 && args[0].nil?) + nil else - super "#{low || '[0'},#{high || ')'}" + low, high = convert(args[0]) + low, high = convert(args[1], low, high) if /[=~><]/.match?(args[1]) + if low == high + low + else + super "#{low || '[0'},#{high || ')'}" + end end end - end private - def self.convert(arg, low = nil, high = nil) - if arg =~ /~>/ - val = arg.sub(/~>\s*/, '') - last = val =~ /\./ ? val.sub(/\.[0-9]*[a-z]+.*$/, '').sub(/\.[^.]+$/, '.99999') : '99999' - ["[#{snapshot_version(val)}", "#{snapshot_version(last)}]"] - elsif arg =~ />=/ - val = arg.sub(/>=\s*/, '') - ["[#{snapshot_version(val)}", (nil || high)] - elsif arg =~ /<=/ - val = arg.sub(/<=\s*/, '') - [(nil || low), "#{snapshot_version(val)}]"] - # treat '!' the same way as '>' since maven can not describe such range - elsif arg =~ /[!>]/ - val = arg.sub(/[!>]\s*/, '') - ["(#{snapshot_version(val)}", (nil || high)] - elsif arg =~ /') + val = arg.sub(/~>\s*/, '') + last = val.include?('.') ? val.sub(/\.[0-9]*[a-z]+.*$/, '').sub(/\.[^.]+$/, '.99999') : '99999' + ["[#{snapshot_version(val)}", "#{snapshot_version(last)}]"] + elsif arg.include?('>=') + val = arg.sub(/>=\s*/, '') + ["[#{snapshot_version(val)}", (nil || high)] + elsif arg.include?('<=') + val = arg.sub(/<=\s*/, '') + [(nil || 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)] + elsif arg.include?('<') + val = arg.sub(/<\s*/, '') + [(nil || low), "#{snapshot_version(val)})"] + elsif arg.include?('=') + val = arg.sub(/=\s*/, '') + # for prereleased version pick the maven version (no version range) + if /[a-z]|[A-Z]/.match?(val) + [val, val] + else + ["[#{val}", "#{val}.0.0.0.0.1)"] + end else - ["[#{val}", "#{val}.0.0.0.0.1)"] + # no conversion here, i.e. assume maven version + [arg, arg] end - else - # no conversion here, i.e. assume maven version - [arg, arg] end - end - def self.snapshot_version(val) - if val.match(/[a-z]|[A-Z]/) && !val.match(/-SNAPSHOT|[${}]/) - val + '-SNAPSHOT' - else - val + def snapshot_version(val) + if val.match(/[a-z]|[A-Z]/) && !val.match(/-SNAPSHOT|[${}]/) + "#{val}-SNAPSHOT" + else + val + end end - end + end end class GemspecArtifacts @@ -101,9 +105,11 @@ def self.new(line) line = line.strip index = line.index(/\s/) return nil if index.nil? + type = line[0..index].strip return nil unless ALLOWED_TYPES.member?(type) - line = line[index..-1] + + line = line[index..] line.gsub!(/['"]/, '') line.strip! @@ -118,20 +124,20 @@ def self.new(line) end exclusions = nil line.sub!(/[,:]\s*\[(.+:.+,?\s*)+\]$/) do |a| - exclusions = Exclusions.new(a[1..-1].strip) + exclusions = Exclusions.new(a[1..].strip) '' end line.strip! line.gsub!(/,\s*/, ':') - if line =~ /[\[\(\)\]]/ - index = line.index(/[\[\(].+$/) - version = line[index..-1].sub(/:/, ', ') + if /[\[()\]]/.match?(line) + index = line.index(/[\[(].+$/) + version = line[index..].sub(/:/, ', ') line = line[0..index - 1].strip.sub(/:$/, '') else - index = line.index(/[:][^:]+$/) - version = line[index + 1..-1] + index = line.index(/:[^:]+$/) + version = line[index + 1..] line = line[0..index - 1].strip end @@ -153,7 +159,7 @@ def to_s args << @classifier if @classifier args << @version args << @exclusions.to_s if @exclusions - "#{@type} #{group_id}:#{args[1..-1].join(', ')}" + "#{@type} #{group_id}:#{args[1..].join(', ')}" end def to_gacv @@ -190,7 +196,7 @@ def key def initialize(spec) @artifacts = [] spec.requirements.each do |req| - req.split(/\n/).each do |line| + req.split("\n").each do |line| if (a = Artifact.new(line)) @artifacts << a end diff --git a/lib/jars/gemspec_pom.rb b/lib/jars/gemspec_pom.rb index 27e356b..834b2fc 100644 --- a/lib/jars/gemspec_pom.rb +++ b/lib/jars/gemspec_pom.rb @@ -1,5 +1,11 @@ +# frozen_string_literal: true + # this file is maven DSL and used by maven via jars/maven_exec.rb -eval(File.read(File.join(File.dirname(__FILE__), 'attach_jars_pom.rb'))) +def eval_file(file) + file = File.join(__dir__, file) + eval(File.read(file), nil, file) # rubocop:disable Security/Eval +end -eval(File.read(File.join(File.dirname(__FILE__), 'output_jars_pom.rb'))) +eval_file('attach_jars_pom.rb') +eval_file('output_jars_pom.rb') diff --git a/lib/jars/installer.rb b/lib/jars/installer.rb index adde4b5..f5b3d97 100644 --- a/lib/jars/installer.rb +++ b/lib/jars/installer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'jar_dependencies' require 'jars/maven_exec' @@ -7,7 +9,7 @@ class Dependency attr_reader :path, :file, :gav, :scope, :type, :coord def self.new(line) - super if line =~ /:jar:|:pom:/ + super if /:jar:|:pom:/.match?(line) end def setup_type(line) @@ -32,21 +34,21 @@ def setup_scope(line) end private :setup_scope - REG = /:jar:|:pom:|:test:|:compile:|:runtime:|:provided:|:system:/ - EMPTY = ''.freeze + REG = /:jar:|:pom:|:test:|:compile:|:runtime:|:provided:|:system:/.freeze + EMPTY = '' def initialize(line) setup_type(line) line.strip! @coord = line.sub(/:[^:]+:([A-Z]:\\)?[^:]+$/, EMPTY) first, second = @coord.split(/:#{type}:/) - group_id, artifact_id = first.split(/:/) + group_id, artifact_id = first.split(':') parts = group_id.split('.') parts << artifact_id parts << second.split(':')[-1] @file = line.slice(@coord.length, line.length).sub(REG, EMPTY).strip - last = @file.reverse.index(/\\|\//) - parts << line[-last..-1] + last = @file.reverse.index(%r{\\|/}) + parts << line[-last..] @path = File.join(parts).strip setup_scope(line) @@ -60,8 +62,8 @@ def system? end end - def self.install_jars(write_require_file = false) - new.install_jars(write_require_file) + def self.install_jars(write_require_file: false) + new.install_jars(write_require_file: write_require_file) end def self.load_from_maven(file) @@ -73,76 +75,53 @@ def self.load_from_maven(file) result end - def self.write_require_file(require_filename) - warn 'deprecated' - if needs_to_write?(require_filename) - FileUtils.mkdir_p(File.dirname(require_filename)) - f = File.open(require_filename, 'w') - f.puts COMMENT - f.puts "require 'jar_dependencies'" - f.puts - f - end - end - def self.vendor_file(dir, dep) - if !dep.system? && dep.type == :jar && dep.scope == :runtime - vendored = File.join(dir, dep.path) - FileUtils.mkdir_p(File.dirname(vendored)) - FileUtils.cp(dep.file, vendored) - end - end + return unless !dep.system? && dep.type == :jar && dep.scope == :runtime - def self.write_dep(file, _dir, dep, _vendor) - warn 'deprecated' - print_require_jar(file, dep) + vendored = File.join(dir, dep.path) + FileUtils.mkdir_p(File.dirname(vendored)) + FileUtils.cp(dep.file, vendored) end - def self.print_require_jar(file, dep, fallback = false) + def self.print_require_jar(file, dep, fallback: false) return if dep.type != :jar || dep.scope != :runtime + if dep.system? - file.puts("require '#{dep.file}'") if file + file&.puts("require '#{dep.file}'") elsif dep.scope == :runtime if fallback - file.puts(" require '#{dep.path}'") if file + file&.puts(" require '#{dep.path}'") else - file.puts(" require_jar '#{dep.gav.gsub(':', "', '")}'") if file + file&.puts(" require_jar '#{dep.gav.gsub(':', "', '")}'") end end end - COMMENT = '# this is a generated file, to avoid over-writing it just delete this comment'.freeze + COMMENT = '# this is a generated file, to avoid over-writing it just delete this comment' def self.needs_to_write?(require_filename) require_filename && (!File.exist?(require_filename) || File.read(require_filename).match(COMMENT)) end - def self.install_deps(deps, dir, require_filename, vendor) - warn 'deprecated' - write_require_jars(deps, require_filename) - vendor_jars(deps, dir) if dir && vendor - end - def self.write_require_jars(deps, require_filename) - if needs_to_write?(require_filename) - FileUtils.mkdir_p(File.dirname(require_filename)) - File.open(require_filename, 'w') do |f| - f.puts COMMENT - f.puts 'begin' - f.puts " require 'jar_dependencies'" - f.puts 'rescue LoadError' - deps.each do |dep| - # do not use require_jar method - print_require_jar(f, dep, true) - end - f.puts 'end' - f.puts - f.puts 'if defined? Jars' - deps.each do |dep| - print_require_jar(f, dep) - end - f.puts 'end' - yield f if block_given? + return unless needs_to_write?(require_filename) + + FileUtils.mkdir_p(File.dirname(require_filename)) + File.open(require_filename, 'w') do |f| + f.puts COMMENT + f.puts 'begin' + f.puts " require 'jar_dependencies'" + f.puts 'rescue LoadError' + deps.each do |dep| + # do not use require_jar method + print_require_jar(f, dep, fallback: true) end + f.puts 'end' + f.puts + f.puts 'if defined? Jars' + deps.each do |dep| + print_require_jar(f, dep) + end + f.puts 'end' end end @@ -160,8 +139,9 @@ def spec @mvn.spec end - def vendor_jars(write_require_file = true, vendor_dir = nil) - return unless has_jars? + def vendor_jars(vendor_dir = nil, write_require_file: true) + return unless jars? + if Jars.to_prop(Jars::VENDOR) == 'false' vendor_dir = nil else @@ -171,16 +151,17 @@ def vendor_jars(write_require_file = true, vendor_dir = nil) end def self.vendor_jars!(vendor_dir = nil) - new.vendor_jars!(true, vendor_dir) + new.vendor_jars!(vendor_dir) end - def vendor_jars!(write_require_file = true, vendor_dir = nil) + def vendor_jars!(vendor_dir = nil, write_require_file: true) vendor_dir ||= spec.require_path do_install(vendor_dir, write_require_file) end - def install_jars(write_require_file = true) - return unless has_jars? + def install_jars(write_require_file: true) + return unless jars? + do_install(nil, write_require_file) end @@ -188,12 +169,12 @@ def ruby_maven_install_options=(options) @mvn.ruby_maven_install_options = options end - def has_jars? + def jars? # first look if there are any requirements in the spec # and then if gem depends on jar-dependencies for runtime. # only then install the jars declared in the requirements result = (spec = self.spec) && !spec.requirements.empty? && - spec.dependencies.detect { |d| d.name == 'jar-dependencies' && d.type == :runtime } != nil + spec.dependencies.detect { |d| d.name == 'jar-dependencies' && d.type == :runtime } if result && spec.platform.to_s != 'java' Jars.warn "\njar dependencies found on non-java platform gem - do not install jars\n" false @@ -201,7 +182,6 @@ def has_jars? result end end - alias jars? has_jars? private @@ -209,6 +189,7 @@ def do_install(vendor_dir, write_require_file) if !spec.require_paths.include?(vendor_dir) && vendor_dir raise "vendor dir #{vendor_dir} not in require_paths of gemspec #{spec.require_paths}" end + target_dir = File.join(@mvn.basedir, vendor_dir || spec.require_path) jars_file = File.join(target_dir, "#{spec.name}_jars.rb") @@ -223,7 +204,7 @@ def do_install(vendor_dir, write_require_file) end deps = install_dependencies self.class.write_require_jars(deps, jars_file) - self.class.vendor_jars(deps, target_dir) if vendor_dir + self.class.vendor_jars(target_dir, write_require_file: deps) if vendor_dir end def install_dependencies @@ -237,6 +218,4 @@ def install_dependencies FileUtils.rm_f(deps) if deps end end - # to stay backward compatible - JarInstaller = Installer unless defined? JarInstaller end diff --git a/lib/jars/lock.rb b/lib/jars/lock.rb index c5e0f00..e776f35 100644 --- a/lib/jars/lock.rb +++ b/lib/jars/lock.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'jars/maven_exec' module Jars @@ -38,7 +40,7 @@ def path ENV_JAVA[a[2..-2]] || a end else - File.join(Jars.home, group_id.gsub(/[.]/, '/'), artifact_id, version, gacv[1..-1].join('-') + '.jar') + File.join(Jars.home, group_id.gsub(/[.]/, '/'), artifact_id, version, "#{gacv[1..].join('-')}.jar") end end end @@ -51,10 +53,11 @@ def initialize(file) def process(scope) scope ||= :runtime File.read(@file).each_line do |line| - next if line !~ /:.+:/ - jar = JarDetails.new(line.strip.sub(/:jar:/, ':').sub(/:$/, ': ').split(/:/)) + next unless /:.+:/.match?(line) + + jar = JarDetails.new(line.strip.sub(/:jar:/, ':').sub(/:$/, ': ').split(':')) case scope - when :all + when :all, :test yield jar when :compile # jar.scope is maven scope @@ -65,8 +68,6 @@ def process(scope) when :runtime # jar.scope is maven scope yield jar if (jar.scope != :test) && (jar.scope != :provided) - when :test - yield jar end end end diff --git a/lib/jars/lock_down.rb b/lib/jars/lock_down.rb index 9e2950e..fc2cd4c 100644 --- a/lib/jars/lock_down.rb +++ b/lib/jars/lock_down.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'fileutils' require 'jar_dependencies' require 'jars/version' @@ -15,7 +17,7 @@ def initialize(debug, verbose) def maven_new factory = MavenFactory.new({}, @debug, @verbose) - pom = File.expand_path('../lock_down_pom.rb', __FILE__) + pom = File.expand_path('lock_down_pom.rb', __dir__) m = factory.maven_new(pom) m['jruby.plugins.version'] = Jars::JRUBY_PLUGINS_VERSION m['dependency.plugin.version'] = Jars::DEPENDENCY_PLUGIN_VERSION @@ -41,50 +43,40 @@ def attach_jar_coordinates_from_bundler_dependencies(maven) # TODO: make this group a commandline option Bundler.setup('default') maven.property('jars.bundler', true) - done = [] - index = 0 cwd = File.expand_path('.') Gem.loaded_specs.each do |_name, spec| # if gemspec is local then include all dependencies - maven.attach_jars(spec, cwd == spec.full_gem_path) + maven.attach_jars(spec, all_dependencies: cwd == spec.full_gem_path) end - rescue Exception => e - case e.class.to_s - when 'LoadError' - if Jars.verbose? - warn e.message - warn 'no bundler found - ignore Gemfile if exists' - end - when 'Bundler::GemfileNotFound' - # do nothing then as we have bundler but no Gemfile - when 'Bundler::GemNotFound' - warn "can not setup bundler with #{Bundler.default_lockfile}" - raise e - else - # reraise exception so user sees it - raise e + rescue LoadError => e + if Jars.verbose? + warn e.message + warn 'no bundler found - ignore Gemfile if exists' end + rescue Bundler::GemfileNotFound + # do nothing then as we have bundler but no Gemfile + rescue Bundler::GemNotFound + warn "can not setup bundler with #{Bundler.default_lockfile}" + raise ensure $LOAD_PATH.replace(load_path) end - def lock_down(options = {}) - vendor_dir = File.expand_path(options[:vendor_dir]) if options[:vendor_dir] + def lock_down(vendor_dir = nil, force: false, update: false, tree: nil) out = File.expand_path('.jars.output') - tree = File.expand_path('.jars.tree') + tree_provided = tree + tree ||= File.expand_path('.jars.tree') maven.property('jars.outputFile', out) maven.property('maven.repo.local', Jars.local_maven_repo) - maven.property('jars.home', vendor_dir) if vendor_dir + maven.property('jars.home', File.expand_path(vendor_dir)) if vendor_dir maven.property('jars.lock', File.expand_path(Jars.lock)) - maven.property('jars.force', options[:force] == true) - maven.property('jars.update', options[:update]) if options[:update] + maven.property('jars.force', force) + maven.property('jars.update', update) if update # tell not to use Jars.lock as part of POM when running mvn maven.property('jars.skip.lock', true) args = ['gem:jars-lock'] - if options[:tree] - args += ['dependency:tree', '-P -gemfile.lock', '-DoutputFile=' + tree] - end + args += ['dependency:tree', '-P -gemfile.lock', "-DoutputFile=#{tree}"] if tree_provided puts puts '-- jar root dependencies --' @@ -99,7 +91,7 @@ def lock_down(options = {}) puts end puts - puts File.read(out).gsub(/#{File.dirname(out)}\//, '') + puts File.read(out).gsub("#{File.dirname(out)}/", '') puts ensure FileUtils.rm_f out diff --git a/lib/jars/lock_down_pom.rb b/lib/jars/lock_down_pom.rb index 5dd05ea..3dffa35 100644 --- a/lib/jars/lock_down_pom.rb +++ b/lib/jars/lock_down_pom.rb @@ -1,8 +1,15 @@ +# frozen_string_literal: true + # this file is maven DSL and used by maven via jars/lock_down.rb basedir(ENV_JAVA['jars.basedir']) -eval(File.read(File.join(File.dirname(__FILE__), 'attach_jars_pom.rb'))) +def eval_file(file) + file = File.join(__dir__, file) + eval(File.read(file), nil, file) # rubocop:disable Security/Eval +end + +eval_file('attach_jars_pom.rb') jfile = ENV_JAVA['jars.jarfile'] jarfile(jfile) if jfile @@ -14,17 +21,15 @@ # from each gemspec file. otherwise we need to resolve # the gemspec artifact in the maven way unless ENV_JAVA['jars.bundler'] - begin gemspec rescue nil end - end properties('project.build.sourceEncoding' => 'utf-8') plugin :dependency, ENV_JAVA['dependency.plugin.version'] -eval(File.read(File.join(File.dirname(__FILE__), 'output_jars_pom.rb'))) +eval_file('output_jars_pom.rb') diff --git a/lib/jars/maven_exec.rb b/lib/jars/maven_exec.rb index 14f08a6..798c018 100644 --- a/lib/jars/maven_exec.rb +++ b/lib/jars/maven_exec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'jar_dependencies' require 'jars/maven_factory' @@ -23,11 +25,11 @@ def initialize(spec = nil) setup(spec) rescue StandardError, LoadError => e # If spec load fails, skip looking for jar-dependencies - warn 'jar-dependencies: ' + e.to_s + warn "jar-dependencies: #{e}" warn e.backtrace.join("\n") if Jars.verbose? end - def setup(spec = nil, allow_no_file = false) + def setup(spec = nil, allow_no_file: false) spec ||= find_spec(allow_no_file) case spec @@ -35,7 +37,7 @@ def setup(spec = nil, allow_no_file = false) @specfile = File.expand_path(spec) @basedir = File.dirname(@specfile) Dir.chdir(@basedir) do - spec = eval(File.read(@specfile), TOPLEVEL_BINDING, @specfile) + spec = eval(File.read(@specfile), TOPLEVEL_BINDING, @specfile) # rubocop:disable Security/Eval end when Gem::Specification if File.exist?(spec.loaded_from) @@ -46,12 +48,13 @@ def setup(spec = nil, allow_no_file = false) # there the spec_file is "not installed" but inside # the gem_dir directory Dir.chdir(spec.gem_dir) do - setup(nil, true) + setup(nil, allow_no_file: true) end end - when NilClass + when nil + # ignore else - Jars.debug('spec must be either String or Gem::Specification. ' + + Jars.debug('spec must be either String or Gem::Specification. ' \ 'File an issue on github if you need it.') end @spec = spec @@ -63,10 +66,10 @@ def ruby_maven_install_options=(options) def resolve_dependencies_list(file) factory = MavenFactory.new(@options) - maven = factory.maven_new(File.expand_path('../gemspec_pom.rb', __FILE__)) + maven = factory.maven_new(File.expand_path('gemspec_pom.rb', __dir__)) is_local_file = File.expand_path(File.dirname(@specfile)) == File.expand_path(Dir.pwd) - maven.attach_jars(@spec, is_local_file) + maven.attach_jars(@spec, all_dependencies: is_local_file) maven['jars.specfile'] = @specfile.to_s maven['outputAbsoluteArtifactFilename'] = 'true' diff --git a/lib/jars/maven_factory.rb b/lib/jars/maven_factory.rb index 6e9db23..4a22f08 100644 --- a/lib/jars/maven_factory.rb +++ b/lib/jars/maven_factory.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + require 'jar_dependencies' require 'jars/gemspec_artifacts' module Jars class MavenFactory module AttachJars - def attach_jars(spec, all_dependencies = false) + def attach_jars(spec, all_dependencies: false) @index ||= 0 @done ||= [] @@ -63,17 +65,13 @@ def setup(maven) end maven['verbose'] = (@debug || @verbose) == true - if Jars.maven_settings - maven.options['-s'] = Jars::MavenSettings.effective_settings - end + maven.options['-s'] = Jars::MavenSettings.effective_settings if Jars.maven_settings maven['maven.repo.local'] = java.io.File.new(Jars.local_maven_repo).absolute_path.to_s maven end - private - def lazy_load_maven add_gem_to_load_path('ruby-maven') add_gem_to_load_path('ruby-maven-libs') @@ -97,15 +95,15 @@ def find_spec_via_rubygems(name, req) def add_gem_to_load_path(name) # if the gem is already activated => good return if Gem.loaded_specs[name] + # just install gem if needed and add it to the load_path # and leave activated gems as they are req = requirement(name) - unless spec = find_spec_via_rubygems(name, req) + unless (spec = find_spec_via_rubygems(name, req)) spec = install_gem(name, req) end - unless spec - raise "failed to resolve gem '#{name}' if you're using Bundler add it as a dependency" - end + raise "failed to resolve gem '#{name}' if you're using Bundler add it as a dependency" unless spec + path = File.join(spec.full_gem_path, spec.require_path) $LOAD_PATH << path unless $LOAD_PATH.include?(path) end @@ -127,7 +125,8 @@ def install_gem(name, req) warn e.inspect.to_s warn e.backtrace.join("\n") end - raise "there was an error installing '#{name} (#{req})' #{@options[:domain]}. please install it manually: #{e.inspect}" + raise "there was an error installing '#{name} (#{req})' " \ + "#{@options[:domain]}. please install it manually: #{e.inspect}" end end end diff --git a/lib/jars/maven_settings.rb b/lib/jars/maven_settings.rb index 0410816..7fbe1c6 100644 --- a/lib/jars/maven_settings.rb +++ b/lib/jars/maven_settings.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rubygems/uri_formatter' module Jars class MavenSettings @@ -5,23 +7,17 @@ class MavenSettings class << self def local_settings - unless instance_variable_defined?(:@_jars_maven_local_settings_) - @_jars_maven_local_settings_ = nil - end - if @_jars_maven_local_settings_.nil? - if settings = Jars.absolute('settings.xml') - @_jars_maven_local_settings_ = settings if File.exist?(settings) - end + @_jars_maven_local_settings_ = nil unless instance_variable_defined?(:@_jars_maven_local_settings_) + if @_jars_maven_local_settings_.nil? && (settings = Jars.absolute('settings.xml')) && File.exist?(settings) + @_jars_maven_local_settings_ = settings end @_jars_maven_local_settings_ || nil end def user_settings - unless instance_variable_defined?(:@_jars_maven_user_settings_) - @_jars_maven_user_settings_ = nil - end + @_jars_maven_user_settings_ = nil unless instance_variable_defined?(:@_jars_maven_user_settings_) if @_jars_maven_user_settings_.nil? - if settings = Jars.absolute(Jars.to_prop(MAVEN_SETTINGS)) + if (settings = Jars.absolute(Jars.to_prop(MAVEN_SETTINGS))) unless File.exist?(settings) Jars.warn { "configured ENV['#{MAVEN_SETTINGS}'] = '#{settings}' not found" } settings = false @@ -36,9 +32,7 @@ def user_settings end def effective_settings - unless instance_variable_defined?(:@_jars_effective_maven_settings_) - @_jars_effective_maven_settings_ = nil - end + @_jars_effective_maven_settings_ = nil unless instance_variable_defined?(:@_jars_effective_maven_settings_) if @_jars_effective_maven_settings_.nil? begin require 'rubygems/request' @@ -48,12 +42,11 @@ def effective_settings rescue Jars.debug('ignore rubygems proxy configuration as rubygems is too old') end - if http.nil? && https.nil? - @_jars_effective_maven_settings_ = settings - else - @_jars_effective_maven_settings_ = - setup_interpolated_settings(http, https) || settings - end + @_jars_effective_maven_settings_ = if http.nil? && https.nil? + settings + else + setup_interpolated_settings(http, https) || settings + end end @_jars_effective_maven_settings_ end @@ -69,18 +62,14 @@ def reset end def settings - unless instance_variable_defined?(:@_jars_maven_settings_) - @_jars_maven_settings_ = nil - end + @_jars_maven_settings_ = nil unless instance_variable_defined?(:@_jars_maven_settings_) local_settings || user_settings if @_jars_maven_settings_.nil? end def global_settings - unless instance_variable_defined?(:@_jars_maven_global_settings_) - @_jars_maven_global_settings_ = nil - end + @_jars_maven_global_settings_ = nil unless instance_variable_defined?(:@_jars_maven_global_settings_) if @_jars_maven_global_settings_.nil? - if mvn_home = ENV['M2_HOME'] || ENV['MAVEN_HOME'] + if (mvn_home = ENV['M2_HOME'] || ENV['MAVEN_HOME']) settings = File.join(mvn_home, 'conf/settings.xml') settings = false unless File.exist?(settings) else diff --git a/lib/jars/output_jars_pom.rb b/lib/jars/output_jars_pom.rb index cf05188..c141aa2 100644 --- a/lib/jars/output_jars_pom.rb +++ b/lib/jars/output_jars_pom.rb @@ -1,8 +1,16 @@ +# frozen_string_literal: true + # this file is maven DSL if ENV_JAVA['jars.quiet'] != 'true' model.dependencies.each do |d| - puts ' ' + d.group_id + ':' + d.artifact_id + (d.classifier ? ':' + d.classifier : '') + ':' + d.version + ':' + (d.scope || 'compile') - puts ' exclusions: ' + d.exclusions.collect { |e| e.group_id + ':' + e.artifact_id }.join unless d.exclusions.empty? + puts " #{d.group_id}:#{d.artifact_id}" \ + "#{d.classifier ? ":#{d.classifier}" : ''}" \ + ":#{d.version}:#{d.scope || 'compile'}" + next if d.exclusions.empty? + + puts " exclusions: #{d.exclusions.collect do |e| + "#{e.group_id}:#{e.artifact_id}" + end.join}" end end diff --git a/lib/jars/post_install_hook.rb b/lib/jars/post_install_hook.rb index 90c2a5c..2550a1a 100644 --- a/lib/jars/post_install_hook.rb +++ b/lib/jars/post_install_hook.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # # Copyright (C) 2014 Christian Meier # @@ -21,9 +23,9 @@ module Jars def self.post_install_hook(gem_installer) - return if (ENV["JARS_SKIP"] || ENV_JAVA["jars.skip"]) == "true" + return if (ENV['JARS_SKIP'] || ENV_JAVA['jars.skip']) == 'true' - require "jars/installer" + require 'jars/installer' jars = Jars::Installer.new(gem_installer.spec) jars.ruby_maven_install_options = gem_installer.options || {} jars.vendor_jars diff --git a/lib/jars/setup.rb b/lib/jars/setup.rb index 1b5c0db..88914c4 100644 --- a/lib/jars/setup.rb +++ b/lib/jars/setup.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # to do as bundler does and allow to load Jars.lock via # require 'jars/setup'. can be useful via commandline -rjars/setup # or tell bundler autorequire to load it diff --git a/lib/jars/version.rb b/lib/jars/version.rb index 561a732..d2da757 100644 --- a/lib/jars/version.rb +++ b/lib/jars/version.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + module Jars - VERSION = '0.4.1'.freeze - JRUBY_PLUGINS_VERSION = '1.1.3'.freeze - DEPENDENCY_PLUGIN_VERSION = '2.8'.freeze + VERSION = '0.4.1' + JRUBY_PLUGINS_VERSION = '1.1.3' + DEPENDENCY_PLUGIN_VERSION = '2.8' end diff --git a/lib/rubygems_plugin.rb b/lib/rubygems_plugin.rb index 2c7645c..1f4fca1 100644 --- a/lib/rubygems_plugin.rb +++ b/lib/rubygems_plugin.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # # Copyright (C) 2014 Christian Meier # @@ -19,4 +21,4 @@ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # -require "jar_install_post_install_hook" +require 'jar_install_post_install_hook' diff --git a/specs/classpath_spec.rb b/specs/classpath_spec.rb index 2dbf63c..3676f8a 100644 --- a/specs/classpath_spec.rb +++ b/specs/classpath_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path('setup', File.dirname(__FILE__)) require 'yaml' @@ -5,17 +7,22 @@ module Helper def self.prepare!(array) + exclusions = %w[ + org/yaml/snakeyaml/snakeyaml.jar + org/jruby/dirgra/dirgra.jar + org/jruby/yecht/yecht.jar + ] result = array.collect do |a| a.sub(/-native.jar$/, '.jar') - .sub(/-[^-]+$/, '.jar') - .sub(/[^\/]+\/([^\/]+)$/, '\1') - .sub(/^.*META-INF.jruby.home.lib.ruby.s....../, '') - .sub(/.*#{Jars.home}./, '') - .sub(/.*#{Jars.local_maven_repo}./, '') - .sub(/.*repository./, '') # make sure we trim this - end.select { |a| a != 'org/yaml/snakeyaml/snakeyaml.jar' && a != 'org/jruby/dirgra/dirgra.jar' && a != 'org/jruby/yecht/yecht.jar' } + .sub(/-[^-]+$/, '.jar') + .sub(%r{[^/]+/([^/]+)$}, '\1') + .sub(/^.*META-INF.jruby.home.lib.ruby.s....../, '') + .sub(/.*#{Jars.home}./, '') + .sub(/.*#{Jars.local_maven_repo}./, '') + .sub(/.*repository./, '') # make sure we trim this + end - exclusions # omit ruby-maven jars - result.delete_if { |c| c =~ /ruby-maven/ } + result.delete_if { |c| c.include?('ruby-maven') } result.uniq.sort end @@ -39,17 +46,66 @@ def self.prepare(array) let(:example_spec) { File.join(pwd, '..', 'example', 'example.gemspec') } - let(:example_expected) { ['com/fasterxml/jackson/core/jackson-databind/2.5.1/jackson-databind-2.5.1.jar', 'io/dropwizard/dropwizard-jackson/0.8.0-rc5/dropwizard-jackson-0.8.0-rc5.jar', 'com/fasterxml/classmate/1.0.0/classmate-1.0.0.jar', 'io/dropwizard/dropwizard-util/0.8.0-rc5/dropwizard-util-0.8.0-rc5.jar', 'com/fasterxml/jackson/module/jackson-module-afterburner/2.5.1/jackson-module-afterburner-2.5.1.jar', 'com/fasterxml/jackson/datatype/jackson-datatype-guava/2.5.1/jackson-datatype-guava-2.5.1.jar', 'org/bouncycastle/bcpkix-jdk15on/1.49/bcpkix-jdk15on-1.49.jar', 'org/bouncycastle/bcprov-jdk15on/1.49/bcprov-jdk15on-1.49.jar', 'com/google/code/findbugs/jsr305/3.0.0/jsr305-3.0.0.jar', 'org/jboss/logging/jboss-logging/3.1.3.GA/jboss-logging-3.1.3.GA.jar', 'io/dropwizard/metrics/metrics-core/3.1.0/metrics-core-3.1.0.jar', 'org/slf4j/jcl-over-slf4j/1.7.10/jcl-over-slf4j-1.7.10.jar', 'org/slf4j/log4j-over-slf4j/1.7.10/log4j-over-slf4j-1.7.10.jar', 'org/hibernate/hibernate-validator/5.1.3.Final/hibernate-validator-5.1.3.Final.jar', 'ch/qos/logback/logback-core/1.1.2/logback-core-1.1.2.jar', 'com/fasterxml/jackson/core/jackson-core/2.5.1/jackson-core-2.5.1.jar', 'org/slf4j/jul-to-slf4j/1.7.10/jul-to-slf4j-1.7.10.jar', 'io/dropwizard/dropwizard-logging/0.8.0-rc5/dropwizard-logging-0.8.0-rc5.jar', 'org/glassfish/javax.el/3.0.0/javax.el-3.0.0.jar', 'io/dropwizard/metrics/metrics-logback/3.1.0/metrics-logback-3.1.0.jar', 'com/google/guava/guava/18.0/guava-18.0.jar', 'com/fasterxml/jackson/datatype/jackson-datatype-jdk7/2.5.1/jackson-datatype-jdk7-2.5.1.jar', 'io/dropwizard/dropwizard-validation/0.8.0-rc5/dropwizard-validation-0.8.0-rc5.jar', 'javax/validation/validation-api/1.1.0.Final/validation-api-1.1.0.Final.jar', 'ch/qos/logback/logback-classic/1.1.2/logback-classic-1.1.2.jar', 'com/google/protobuf/protobuf-java/2.2.0/protobuf-java-2.2.0-lite.jar', 'com/fasterxml/jackson/core/jackson-annotations/2.5.0/jackson-annotations-2.5.0.jar', 'org/slf4j/slf4j-api/1.7.7/slf4j-api-1.7.7.jar', 'com/fasterxml/jackson/datatype/jackson-datatype-joda/2.5.1/jackson-datatype-joda-2.5.1.jar', 'org/eclipse/jetty/jetty-util/9.2.9.v20150224/jetty-util-9.2.9.v20150224.jar'] } + let(:example_expected) do + ['com/fasterxml/jackson/core/jackson-databind/2.5.1/jackson-databind-2.5.1.jar', + 'io/dropwizard/dropwizard-jackson/0.8.0-rc5/dropwizard-jackson-0.8.0-rc5.jar', + 'com/fasterxml/classmate/1.0.0/classmate-1.0.0.jar', + 'io/dropwizard/dropwizard-util/0.8.0-rc5/dropwizard-util-0.8.0-rc5.jar', + 'com/fasterxml/jackson/module/jackson-module-afterburner/2.5.1/jackson-module-afterburner-2.5.1.jar', + 'com/fasterxml/jackson/datatype/jackson-datatype-guava/2.5.1/jackson-datatype-guava-2.5.1.jar', + 'org/bouncycastle/bcpkix-jdk15on/1.49/bcpkix-jdk15on-1.49.jar', + 'org/bouncycastle/bcprov-jdk15on/1.49/bcprov-jdk15on-1.49.jar', + 'com/google/code/findbugs/jsr305/3.0.0/jsr305-3.0.0.jar', + 'org/jboss/logging/jboss-logging/3.1.3.GA/jboss-logging-3.1.3.GA.jar', + 'io/dropwizard/metrics/metrics-core/3.1.0/metrics-core-3.1.0.jar', + 'org/slf4j/jcl-over-slf4j/1.7.10/jcl-over-slf4j-1.7.10.jar', + 'org/slf4j/log4j-over-slf4j/1.7.10/log4j-over-slf4j-1.7.10.jar', + 'org/hibernate/hibernate-validator/5.1.3.Final/hibernate-validator-5.1.3.Final.jar', + 'ch/qos/logback/logback-core/1.1.2/logback-core-1.1.2.jar', + 'com/fasterxml/jackson/core/jackson-core/2.5.1/jackson-core-2.5.1.jar', + 'org/slf4j/jul-to-slf4j/1.7.10/jul-to-slf4j-1.7.10.jar', + 'io/dropwizard/dropwizard-logging/0.8.0-rc5/dropwizard-logging-0.8.0-rc5.jar', + 'org/glassfish/javax.el/3.0.0/javax.el-3.0.0.jar', + 'io/dropwizard/metrics/metrics-logback/3.1.0/metrics-logback-3.1.0.jar', + 'com/google/guava/guava/18.0/guava-18.0.jar', + 'com/fasterxml/jackson/datatype/jackson-datatype-jdk7/2.5.1/jackson-datatype-jdk7-2.5.1.jar', + 'io/dropwizard/dropwizard-validation/0.8.0-rc5/dropwizard-validation-0.8.0-rc5.jar', + 'javax/validation/validation-api/1.1.0.Final/validation-api-1.1.0.Final.jar', + 'ch/qos/logback/logback-classic/1.1.2/logback-classic-1.1.2.jar', + 'com/google/protobuf/protobuf-java/2.2.0/protobuf-java-2.2.0-lite.jar', + 'com/fasterxml/jackson/core/jackson-annotations/2.5.0/jackson-annotations-2.5.0.jar', + 'org/slf4j/slf4j-api/1.7.7/slf4j-api-1.7.7.jar', + 'com/fasterxml/jackson/datatype/jackson-datatype-joda/2.5.1/jackson-datatype-joda-2.5.1.jar', + 'org/eclipse/jetty/jetty-util/9.2.9.v20150224/jetty-util-9.2.9.v20150224.jar'] + end let(:expected_with_bc) { example_expected + bouncycastle } let(:lock_expected) do - ['org/apache/maven/maven-repository-metadata/3.1.0/maven-repository-metadata-3.1.0.jar', 'com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.jar', 'org/apache/httpcomponents/httpclient/4.2.3/httpclient-4.2.3.jar', 'org/sonatype/sisu/sisu-guice/3.1.0/sisu-guice-no_aop-3.1.0.jar', '${java.home}/../lib/tools.jar', 'org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar'] + ['org/apache/maven/maven-repository-metadata/3.1.0/maven-repository-metadata-3.1.0.jar', + 'com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.jar', + 'org/apache/httpcomponents/httpclient/4.2.3/httpclient-4.2.3.jar', + 'org/sonatype/sisu/sisu-guice/3.1.0/sisu-guice-no_aop-3.1.0.jar', + '${java.home}/../lib/tools.jar', + 'org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar'] end - let(:lock_expected_runtime) { ['org/apache/maven/maven-repository-metadata/3.1.0/maven-repository-metadata-3.1.0.jar', 'org/sonatype/sisu/sisu-guice/3.1.0/sisu-guice-no_aop-3.1.0.jar', '${java.home}/../lib/tools.jar', 'org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar'] } + let(:lock_expected_runtime) do + ['org/apache/maven/maven-repository-metadata/3.1.0/maven-repository-metadata-3.1.0.jar', + 'org/sonatype/sisu/sisu-guice/3.1.0/sisu-guice-no_aop-3.1.0.jar', + '${java.home}/../lib/tools.jar', + 'org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar'] + end - let(:lock_expected_test) { ['org/apache/maven/maven-repository-metadata/3.1.0/maven-repository-metadata-3.1.0.jar', 'com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.jar', 'org/apache/httpcomponents/httpclient/4.2.3/httpclient-4.2.3.jar', 'org/sonatype/sisu/sisu-guice/3.1.0/sisu-guice-no_aop-3.1.0.jar', '${java.home}/../lib/tools.jar', 'org/slf4j/slf4j-api/1.6.2/slf4j-api-1.6.2.jar', 'org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar'] } + let(:lock_expected_test) do + ['org/apache/maven/maven-repository-metadata/3.1.0/maven-repository-metadata-3.1.0.jar', + 'com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.jar', + 'org/apache/httpcomponents/httpclient/4.2.3/httpclient-4.2.3.jar', + 'org/sonatype/sisu/sisu-guice/3.1.0/sisu-guice-no_aop-3.1.0.jar', + '${java.home}/../lib/tools.jar', + 'org/slf4j/slf4j-api/1.6.2/slf4j-api-1.6.2.jar', + 'org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar'] + end let(:bc_prov) { ['org/bouncycastle/bcprov-jdk15on/1.49/bcprov-jdk15on-1.49.jar'] } @@ -69,9 +125,15 @@ def self.prepare(array) Dir.chdir(File.dirname(example_spec)) do Helper.prepare(subject.classpath).must_equal Helper.prepare(example_expected) - Helper.prepare(subject.classpath(:compile)).must_equal Helper.prepare(expected_with_bc + ['org/slf4j/slf4j-simple/1.7.7/slf4j-simple-1.7.7.jar']) + Helper.prepare(subject.classpath(:compile)).must_equal Helper.prepare( + expected_with_bc + ['org/slf4j/slf4j-simple/1.7.7/slf4j-simple-1.7.7.jar'] + ) - Helper.prepare(subject.classpath(:test)).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(:test)).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(:runtime)).must_equal Helper.prepare(example_expected) end @@ -80,13 +142,22 @@ 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(: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']) - - 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']) - - Helper.prepare(subject.classpath_string(:runtime).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'] + ) + + 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' + ]) + + Helper.prepare(subject.classpath_string(:runtime).split(File::PATH_SEPARATOR)) + .must_equal Helper.prepare(example_expected) end end @@ -95,19 +166,19 @@ def self.prepare(array) skip('TODO just use some empty jars for this spec') - skip('jruby-9.0.0.x can not require jruby core jars') if JRUBY_VERSION =~ /9.0.0.0/ + skip('jruby-9.0.0.x can not require jruby core jars') if JRUBY_VERSION.match?(/9.0.0.0/) old = $CLASSPATH.to_a # sometimes the $CLASSPATH can already have BC jars # and it is not possible to unload entries from $CLASSPATH - expected = if old.detect { |c| c =~ /bcprov-jdk15on/ } - if old.detect { |c| c =~ /bcpkix-jdk15on/ } + expected = if old.detect { |c| c.include?('bcprov-jdk15on') } + if old.detect { |c| c.include?('bcpkix-jdk15on') } [] else bc_pkix - end - elsif old.detect { |c| c =~ /bcpkix-jdk15on/ } + end + elsif old.detect { |c| c.include?('bcpkix-jdk15on') } bc_prov else bouncycastle @@ -143,6 +214,6 @@ def self.prepare(array) subject.require require_jar 'example', 'example', '1' - $CLASSPATH.detect { |c| c =~ /example/ }.must_be_nil + $CLASSPATH.detect { |c| c.include?('example') }.must_be_nil end end diff --git a/specs/dependency_spec.rb b/specs/dependency_spec.rb index b081450..ab3ba92 100644 --- a/specs/dependency_spec.rb +++ b/specs/dependency_spec.rb @@ -1,16 +1,19 @@ +# frozen_string_literal: true + require File.expand_path('setup', File.dirname(__FILE__)) require 'jar_installer' -describe Jars::JarInstaller::Dependency do +# rubocop:disable Layout/LineLength +describe Jars::Installer::Dependency do it 'should parse dependency line only if it is jar or pom' do - Jars::JarInstaller::Dependency.new('something').must_be_nil - Jars::JarInstaller::Dependency.new(' org.apache.maven:maven-repository-metadata:jar:3.1.0:compile:/usr/local/repository/org/apache/maven/maven-repository-metadata/3.1.0/maven-repository-metadata-3.1.0.jar').wont_be_nil - Jars::JarInstaller::Dependency.new(' org.apache.maven:maven-repository-metadata:pom:3.1.0:compile:/usr/local/repository/org/apache/maven/maven-repository-metadata/3.1.0/maven-repository-metadata-3.1.0.jar').wont_be_nil + Jars::Installer::Dependency.new(+'something').must_be_nil + Jars::Installer::Dependency.new(+' org.apache.maven:maven-repository-metadata:jar:3.1.0:compile:/usr/local/repository/org/apache/maven/maven-repository-metadata/3.1.0/maven-repository-metadata-3.1.0.jar').wont_be_nil + Jars::Installer::Dependency.new(+' org.apache.maven:maven-repository-metadata:pom:3.1.0:compile:/usr/local/repository/org/apache/maven/maven-repository-metadata/3.1.0/maven-repository-metadata-3.1.0.jar').wont_be_nil end it 'should parse dependency line test scope' do - dep = Jars::JarInstaller::Dependency.new(' org.apache.maven:maven-repository-metadata:jar:3.1.0:test:/usr/local/repository/org/apache/maven/maven-repository-metadata/3.1.0/maven-repository-metadata-3.1.0.jar') + dep = Jars::Installer::Dependency.new(+' org.apache.maven:maven-repository-metadata:jar:3.1.0:test:/usr/local/repository/org/apache/maven/maven-repository-metadata/3.1.0/maven-repository-metadata-3.1.0.jar') dep.type.must_equal :jar dep.scope.must_equal :test dep.gav.must_equal 'org.apache.maven:maven-repository-metadata:3.1.0' @@ -20,7 +23,7 @@ end it 'should parse dependency line provided scope' do - dep = Jars::JarInstaller::Dependency.new(' org.apache.maven:maven-repository-metadata:jar:3.1.0:provided:/usr/local/repository/org/apache/maven/maven-repository-metadata/3.1.0/maven-repository-metadata-3.1.0.jar') + dep = Jars::Installer::Dependency.new(+' org.apache.maven:maven-repository-metadata:jar:3.1.0:provided:/usr/local/repository/org/apache/maven/maven-repository-metadata/3.1.0/maven-repository-metadata-3.1.0.jar') dep.type.must_equal :jar dep.scope.must_equal :provided dep.gav.must_equal 'org.apache.maven:maven-repository-metadata:3.1.0' @@ -30,7 +33,7 @@ end it 'should parse dependency line runtim scope' do - dep = Jars::JarInstaller::Dependency.new(' org.apache.maven:maven-repository-metadata:jar:3.1.0:compile:/usr/local/repository/org/apache/maven/maven-repository-metadata/3.1.0/maven-repository-metadata-3.1.0.jar') + dep = Jars::Installer::Dependency.new(+' org.apache.maven:maven-repository-metadata:jar:3.1.0:compile:/usr/local/repository/org/apache/maven/maven-repository-metadata/3.1.0/maven-repository-metadata-3.1.0.jar') dep.type.must_equal :jar dep.scope.must_equal :runtime dep.gav.must_equal 'org.apache.maven:maven-repository-metadata:3.1.0' @@ -38,7 +41,7 @@ dep.path.must_equal 'org/apache/maven/maven-repository-metadata/3.1.0/maven-repository-metadata-3.1.0.jar' dep.file.must_equal '/usr/local/repository/org/apache/maven/maven-repository-metadata/3.1.0/maven-repository-metadata-3.1.0.jar' - dep = Jars::JarInstaller::Dependency.new(' org.apache.maven:maven-repository-metadata:jar:3.1.0:runtime:/usr/local/repository/org/apache/maven/maven-repository-metadata/3.1.0/maven-repository-metadata-3.1.0.jar') + dep = Jars::Installer::Dependency.new(+' org.apache.maven:maven-repository-metadata:jar:3.1.0:runtime:/usr/local/repository/org/apache/maven/maven-repository-metadata/3.1.0/maven-repository-metadata-3.1.0.jar') dep.type.must_equal :jar dep.scope.must_equal :runtime dep.gav.must_equal 'org.apache.maven:maven-repository-metadata:3.1.0' @@ -48,7 +51,7 @@ end it 'should parse pom dependency' do - dep = Jars::JarInstaller::Dependency.new(' org.apache.maven:maven-repository-metadata:pom:3.1.0:compile:/usr/local/repository/org/apache/maven/maven-repository-metadata/3.1.0/maven-repository-metadata-3.1.0.pom') + dep = Jars::Installer::Dependency.new(+' org.apache.maven:maven-repository-metadata:pom:3.1.0:compile:/usr/local/repository/org/apache/maven/maven-repository-metadata/3.1.0/maven-repository-metadata-3.1.0.pom') dep.type.must_equal :pom dep.scope.must_equal :runtime dep.gav.must_equal 'org.apache.maven:maven-repository-metadata:3.1.0' @@ -58,7 +61,7 @@ end it 'should parse dependency where artifact_id has dots' do - dep = Jars::JarInstaller::Dependency.new(' org.eclipse.sisu:org.eclipse.sisu.plexus:jar:0.0.0.M2a:compile:/usr/local/repository/org/eclipse/sisu/org.eclipse.sisu.plexus/0.0.0.M2a/org.eclipse.sisu.plexus-0.0.0.M2a.jar') + dep = Jars::Installer::Dependency.new(+' org.eclipse.sisu:org.eclipse.sisu.plexus:jar:0.0.0.M2a:compile:/usr/local/repository/org/eclipse/sisu/org.eclipse.sisu.plexus/0.0.0.M2a/org.eclipse.sisu.plexus-0.0.0.M2a.jar') dep.type.must_equal :jar dep.scope.must_equal :runtime dep.gav.must_equal 'org.eclipse.sisu:org.eclipse.sisu.plexus:0.0.0.M2a' @@ -68,7 +71,7 @@ end it 'should parse dependency with classifier' do - dep = Jars::JarInstaller::Dependency.new(' org.sonatype.sisu:sisu-guice:jar:no_aop:3.1.0:compile:/usr/local/repository/org/sonatype/sisu/sisu-guice/3.1.0/sisu-guice-3.1.0-no_aop.jar') + dep = Jars::Installer::Dependency.new(+' org.sonatype.sisu:sisu-guice:jar:no_aop:3.1.0:compile:/usr/local/repository/org/sonatype/sisu/sisu-guice/3.1.0/sisu-guice-3.1.0-no_aop.jar') dep.type.must_equal :jar dep.scope.must_equal :runtime dep.gav.must_equal 'org.sonatype.sisu:sisu-guice:no_aop:3.1.0' @@ -78,7 +81,7 @@ end it 'should parse dependency on windows' do - dep = Jars::JarInstaller::Dependency.new(' org.sonatype.sisu:sisu-guice:jar:no_aop:3.1.0:compile:C:\\Users\\Local\\repository\\org\\sonatype\\sisu\\sisu-guice\\3.1.0\\sisu-guice-3.1.0-no_aop.jar') + dep = Jars::Installer::Dependency.new(+' org.sonatype.sisu:sisu-guice:jar:no_aop:3.1.0:compile:C:\\Users\\Local\\repository\\org\\sonatype\\sisu\\sisu-guice\\3.1.0\\sisu-guice-3.1.0-no_aop.jar') dep.type.must_equal :jar dep.scope.must_equal :runtime dep.gav.must_equal 'org.sonatype.sisu:sisu-guice:no_aop:3.1.0' @@ -87,3 +90,4 @@ dep.file.must_equal 'C:\\Users\\Local\\repository\\org\\sonatype\\sisu\\sisu-guice\\3.1.0\\sisu-guice-3.1.0-no_aop.jar' end end +# rubocop:enable Layout/LineLength diff --git a/specs/example/gem_with_require_relative/gem_with_require_relative.gemspec b/specs/example/gem_with_require_relative/gem_with_require_relative.gemspec index 96ab6d0..d1d36b3 100644 --- a/specs/example/gem_with_require_relative/gem_with_require_relative.gemspec +++ b/specs/example/gem_with_require_relative/gem_with_require_relative.gemspec @@ -1,4 +1,8 @@ -require_relative 'version.rb' +# frozen_string_literal: true + +require_relative 'version' Gem::Specification.new do |spec| + spec.required_ruby_version = '>= 2.6' + spec.metadata['rubygems_mfa_required'] = 'true' end diff --git a/specs/example/gem_with_require_relative/version.rb b/specs/example/gem_with_require_relative/version.rb index e69de29..8e9b8f9 100644 --- a/specs/example/gem_with_require_relative/version.rb +++ b/specs/example/gem_with_require_relative/version.rb @@ -0,0 +1 @@ +# frozen_string_literal: true diff --git a/specs/gemspec_artifacts_spec.rb b/specs/gemspec_artifacts_spec.rb index 0c64458..2165943 100644 --- a/specs/gemspec_artifacts_spec.rb +++ b/specs/gemspec_artifacts_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path('setup', File.dirname(__FILE__)) require 'jars/gemspec_artifacts' @@ -15,7 +17,7 @@ ex = Jars::GemspecArtifacts::Exclusion.new(line) ex.to_s.must_equal expected line = ' group:artifact ' - ex = Jars::GemspecArtifacts::Exclusion.new(line + ' :extra:asd') + ex = Jars::GemspecArtifacts::Exclusion.new("#{line} :extra:asd") ex.to_s.must_equal expected end end @@ -59,7 +61,7 @@ Jars::GemspecArtifacts::Artifact.new('bla bla bla').must_be_nil end - [:jar, :pom].each do |type| + %i[jar pom].each do |type| it "parse and to_s of simple GAV #{type}" do expected = "#{type} g:a, 1" a = Jars::GemspecArtifacts::Artifact.new(expected) @@ -102,6 +104,7 @@ a.to_s.must_equal expected line = "#{type} 'g:a', '1', '[a:b]'" a = Jars::GemspecArtifacts::Artifact.new(line) + a.to_s.must_equal expected line = "#{type} 'g:a', '1', ['a:b']" a = Jars::GemspecArtifacts::Artifact.new(line) a.to_s.must_equal expected @@ -199,7 +202,7 @@ it 'retrieves artifacts from gemspec' do spec = Dir.chdir(File.dirname(example_spec)) do - eval(File.read(example_spec)) + eval(File.read(example_spec)) # rubocop:disable Security/Eval end artifacts = Jars::GemspecArtifacts.new(spec) artifacts[0].to_s.must_equal('jar org.bouncycastle:bcpkix-jdk15on, 1.49') diff --git a/specs/jar_installer_spec.rb b/specs/jar_installer_spec.rb index b97ae37..e580a8b 100644 --- a/specs/jar_installer_spec.rb +++ b/specs/jar_installer_spec.rb @@ -1,17 +1,20 @@ +# frozen_string_literal: true + require File.expand_path('setup', File.dirname(__FILE__)) require 'jar_installer' require 'fileutils' require 'rubygems/specification' -class Jars::Installer - def do_install(vendor, write) - @vendor = vendor - @write = write - end +module Jars + class Installer + def do_install(vendor, write) + @vendor = vendor + @write = write + end - attr_reader :vendor - attr_reader :write + attr_reader :vendor, :write + end end describe Jars::Installer do let(:file) { File.join(pwd, 'deps.txt') } @@ -37,22 +40,19 @@ def do_install(vendor, write) it 'generates non-vendored require-file' do deps = Jars::Installer.load_from_maven(file) - Jars::Installer.install_deps(deps, dir, jars, false) + Jars::Installer.write_require_jars(deps, jars) File.read(jars).each_line do |line| - if line.size > 30 && !line.match(/^#/) - line.must_match /^\s{2}require(_jar)?\s'.+'$/ - end + line.must_match(/^\s{2}require(_jar)?\s'.+'$/) if line.size > 30 && !line.match(/^#/) end Dir[File.join(dir, '**')].size.must_equal 1 end it 'generates vendored require-file' do deps = Jars::Installer.load_from_maven(file) - Jars::Installer.install_deps(deps, dir, jars, true) + Jars::Installer.write_require_jars(deps, jars) + Jars::Installer.vendor_jars(deps, dir) File.read(jars).each_line do |line| - if line.size > 30 && !line.match(/^#/) - line.must_match /^\s{2}require(_jar)?\s'.+'$/ - end + line.must_match(/^\s{2}require(_jar)?\s'.+'$/) if line.size > 30 && !line.match(/^#/) end Dir[File.join(dir, '**', '*.jar')].size.must_equal 45 end diff --git a/specs/jars_spec.rb b/specs/jars_spec.rb index 7494626..b880c2a 100644 --- a/specs/jars_spec.rb +++ b/specs/jars_spec.rb @@ -1,17 +1,19 @@ +# frozen_string_literal: true + require File.expand_path('setup', File.dirname(__FILE__)) require 'stringio' describe Jars do - @@_env_ = ENV.dup - before do + @env = ENV.dup # helpful when debugging Jars.reset end after do Jars.reset - ENV.clear; ENV.replace @@_env_ # restore ENV + ENV.clear + ENV.replace @env # restore ENV end it 'extract property' do @@ -57,7 +59,7 @@ it 'extract maven settings' do settings = Jars.maven_settings - settings.sub(/.*\.m2./, '').must_equal 'settings.xml' if settings + settings&.sub(/.*\.m2./, '')&.must_equal 'settings.xml' ENV['JARS_MAVEN_SETTINGS'] = 'specs/settings.xml' Jars.reset @@ -91,7 +93,8 @@ it "determines JARS_HOME (when no ENV['HOME'] present)" do ENV['M2_HOME'] = ENV['MAVEN_HOME'] = '' # so that it won't interfere - env_home = ENV['HOME']; ENV.delete('HOME') + env_home = ENV['HOME'] + ENV.delete('HOME') ENV['JARS_QUIET'] = true.to_s ENV['JARS_MAVEN_SETTINGS'] = 'does-not-exist/settings.xml' Jars.home.must_equal(File.join(env_home, '.m2', 'repository')) @@ -100,7 +103,7 @@ it 'determines JARS_HOME (from global settings.xml)' do ENV['JARS_LOCAL_MAVEN_REPO'] = nil ENV['HOME'] = "/tmp/oul'bollocks!" - ENV['M2_HOME'] = File.expand_path(File.dirname(__FILE__)) + ENV['M2_HOME'] = __dir__ ENV_JAVA['repo.path'] = 'specs' Jars.home.must_equal('specs/repository') ENV['JARS_LOCAL_MAVEN_REPO'] = nil @@ -110,6 +113,7 @@ -> { require_jar('org.something', 'slf4j-simple', '1.6.6') }.must_raise RuntimeError end + # rubocop:disable Layout/LineLength it 'does not require jar but sets version to unknown' do ENV['JARS_HOME'] = File.join('specs', 'repo') Jars.reset @@ -118,10 +122,9 @@ require_jar('org.slf4j', 'slf4j-simple') { nil }.must_equal true $stderr = StringIO.new - require_jar('org.slf4j', 'slf4j-simple'){ '1.6.6' }.must_equal false + require_jar('org.slf4j', 'slf4j-simple') { '1.6.6' }.must_equal false $stderr.string.must_equal "--- jar coordinate org.slf4j:slf4j-simple already loaded with version unknown - omit version 1.6.6\n" - ensure $stderr = STDERR ENV['JARS_HOME'] = nil @@ -135,7 +138,7 @@ begin require_jar('org.slf4j', 'slf4j-simple', '1.6.6').must_equal true $stderr = StringIO.new - require_jar('org.slf4j', 'slf4j-simple'){ '1.6.6' }.must_equal false + require_jar('org.slf4j', 'slf4j-simple') { '1.6.6' }.must_equal false $stderr.string.must_equal '' $stderr = StringIO.new @@ -149,7 +152,6 @@ $stderr = StringIO.new require_jar('org.slf4j', 'slf4j-simple') { nil }.must_equal false $stderr.string.must_equal "--- jar coordinate org.slf4j:slf4j-simple already loaded with version 1.6.6 - omit version unknown\n" - ensure $stderr = STDERR ENV['JARS_HOME'] = nil @@ -179,89 +181,73 @@ ENV['JARS_HOME'] = nil end end + # rubocop:enable Layout/LineLength it 'freezes jar loading unless jar is not loaded yet' do - begin - size = $CLASSPATH.length + size = $CLASSPATH.length - Jars.freeze_loading + Jars.freeze_loading - require 'jopenssl/version' + require 'jopenssl/version' - require_jar 'org.bouncycastle', 'bcpkix-jdk15on', Jopenssl::Version::BOUNCY_CASTLE_VERSION + require_jar 'org.bouncycastle', 'bcpkix-jdk15on', JOpenSSL::BOUNCY_CASTLE_VERSION - $CLASSPATH.length.must_equal size + $CLASSPATH.length.must_equal size - $stderr = StringIO.new + $stderr = StringIO.new - require_jar 'org.bouncycastle', 'bcpkix-jdk15on', '1.46' + require_jar 'org.bouncycastle', 'bcpkix-jdk15on', '1.46' - $stderr.string.must_equal '' - rescue LoadError => e - p e - skip 'assume we have an old jruby' - rescue NameError => e - p e - skip 'assume we have an old jruby' - ensure - $stderr = STDERR - end + $stderr.string.must_equal '' + rescue LoadError, NameError => e + p e + skip 'assume we have an old jruby' + ensure + $stderr = STDERR end it 'allows to programatically disable require_jar' do - begin - require 'jopenssl/version' + require 'jopenssl/version' - size = $CLASSPATH.length + size = $CLASSPATH.length - Jars.require = false + Jars.require = false - out = require_jar 'org.bouncycastle', 'bcpkix-jdk15on', Jopenssl::Version::BOUNCY_CASTLE_VERSION - assert_nil out + out = require_jar 'org.bouncycastle', 'bcpkix-jdk15on', JOpenSSL::BOUNCY_CASTLE_VERSION + assert_nil out - out = require_jar 'org.jruby', 'jruby-rack', '1.1.16' - assert_nil out + out = require_jar 'org.jruby', 'jruby-rack', '1.1.16' + assert_nil out - $CLASSPATH.length.must_equal size - rescue LoadError => e - p e - skip 'assume we have an old jruby' - rescue NameError => e - p e - skip 'assume we have an old jruby' - end + $CLASSPATH.length.must_equal size + rescue LoadError, NameError => e + p e + skip 'assume we have an old jruby' end it 'does not warn on conflicts after turning into silent mode' do - begin - size = $CLASSPATH.length - # TODO: use jline instead to avoid this skip - if $CLASSPATH.detect { |a| a =~ /bcpkix-jdk15on/ } != nil - skip('$CLASSPATH is not clean - need to skip spec') - end + size = $CLASSPATH.length + # TODO: use jline instead to avoid this skip + skip('$CLASSPATH is not clean - need to skip spec') if $CLASSPATH.detect { |a| a.include?('bcpkix-jdk15on') } - Jars.no_more_warnings + Jars.no_more_warnings - require 'jopenssl/version' + require 'jopenssl/version' - if require_jar('org.bouncycastle', 'bcpkix-jdk15on', Jopenssl::Version::BOUNCY_CASTLE_VERSION) - $CLASSPATH.length.must_equal (size + 1) - end + if require_jar('org.bouncycastle', 'bcpkix-jdk15on', JOpenSSL::BOUNCY_CASTLE_VERSION) + $CLASSPATH.length.must_equal(size + 1) + end - $stderr = StringIO.new + $stderr = StringIO.new - require_jar 'org.bouncycastle', 'bcpkix-jdk15on', '1.46' + require_jar 'org.bouncycastle', 'bcpkix-jdk15on', '1.46' - $stderr.string.must_equal '' + $stderr.string.must_equal '' - $stderr = STDERR - rescue LoadError => e - p e - skip 'assume we have an old jruby' - rescue NameError => e - p e - skip 'assume we have an old jruby' - end + $stderr = STDERR + rescue LoadError, NameError => e + p e + skip 'assume we have an old jruby' end it 'no warnings on reload' do @@ -275,20 +261,21 @@ end it 'requires jars from various default places' do - pwd = File.expand_path('..', __FILE__) + pwd = File.expand_path(__dir__) $LOAD_PATH << File.join(pwd, 'path') $stderr = StringIO.new + Jars.require_jars_lock # make sure we locked with no lock file Dir.chdir(pwd) do require_jar 'more', 'sample', '4' require_jar 'more', 'sample', '2' require_jar 'more', 'sample', '3' end - $stderr.string.wont_match /omit version 1/ - $stderr.string.must_match /omit version 2/ - $stderr.string.must_match /omit version 3/ - $stderr.string.wont_match /omit version 4/ + $stderr.string.wont_match(/omit version 1/) + $stderr.string.must_match(/omit version 2/) + $stderr.string.must_match(/omit version 3/) + $stderr.string.wont_match(/omit version 4/) $stderr = STDERR diff --git a/specs/maven_exec_spec.rb b/specs/maven_exec_spec.rb index 24a9050..06c57c1 100644 --- a/specs/maven_exec_spec.rb +++ b/specs/maven_exec_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path('setup', File.dirname(__FILE__)) require 'jars/maven_exec' @@ -8,7 +10,9 @@ let(:pwd) { File.dirname(File.expand_path(__FILE__)) } let(:example_spec) { File.join(pwd, '..', 'example', 'example.gemspec') } - let(:spec_with_require_relative) { File.join(pwd, 'example', 'gem_with_require_relative', 'gem_with_require_relative.gemspec') } + let(:spec_with_require_relative) do + File.join(pwd, 'example', 'gem_with_require_relative', 'gem_with_require_relative.gemspec') + end after do Jars.reset @@ -16,26 +20,24 @@ it 'should not warn if gemspec contains require_relative' do Dir.chdir File.dirname(spec_with_require_relative) do - begin - $stderr = StringIO.new - jar = Jars::MavenExec.new - $stderr.string.must_equal '' - ensure - $stderr = STDERR - end + $stderr = StringIO.new + Jars::MavenExec.new + $stderr.string.must_equal '' + ensure + $stderr = STDERR end end it 'finds the gemspec file when the Gem::Specification.spec_file is wrong' do spec = Dir.chdir(File.dirname(example_spec)) do - eval(File.read(example_spec)) + eval(File.read(example_spec)) # rubocop:disable Security/Eval end spec.loaded_from = spec.spec_file # mimic bundler case FileUtils.rm_f(spec.spec_file) - def spec.gem_dir=(d) - @d = d + def spec.gem_dir=(dir) + @d = dir end def spec.gem_dir diff --git a/specs/maven_factory_spec.rb b/specs/maven_factory_spec.rb index 74f55c3..c45d756 100644 --- a/specs/maven_factory_spec.rb +++ b/specs/maven_factory_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path('setup', File.dirname(__FILE__)) require 'jars/maven_factory' diff --git a/specs/setup.rb b/specs/setup.rb index 1e1e22f..0a893aa 100644 --- a/specs/setup.rb +++ b/specs/setup.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # single spec setup $LOAD_PATH.unshift File.join(File.dirname(File.expand_path(__FILE__)), '../lib') @@ -10,7 +12,6 @@ begin require 'minitest' rescue LoadError + # ignore end require 'minitest/autorun' - -require 'pry'