jarbler 0.2.3 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bba70c5fbf20494c82fc683d2e4ad8c39952000e8a525c7070f142219f7c38bd
4
- data.tar.gz: '085db112eb0163afbad08545074af2a3994ec6cc498f56b6da16910833c2fe62'
3
+ metadata.gz: ae7132c21c27b0d51a870c3e79470d83a4d4b6b088c474c8cdaf4cf4ed34a79c
4
+ data.tar.gz: 8e149011da1e3957f425f659a7ac35b47e1696b3896f1a617c6027d027a783bb
5
5
  SHA512:
6
- metadata.gz: 3a18adb5dfd17593a8c9fa8fb0c997b1e65544705a1074f39984923c6bfd9d82eb938c30b32b09339d349a17cb2e591ed817812060228bb94ecdb6e8cc890e2f
7
- data.tar.gz: 36b98d4f3293ffcc11bbec6ef8e53f57a934d7885d30be43c6ed4c0dbcf3c54802d606d6a5d11292c37a4e1681077a92ecc7f9d23a49008ada7b95c1b0634d17
6
+ metadata.gz: d0712390a6916ee50d063c3f9dcc92fc6389c3ca566bc0b089d5df0275e3044b0aee30d3dedbcaf8171642e8555958137ef8a1ab8d14123417af8bc4475fee44
7
+ data.tar.gz: b85408f04e6c496827c8fc78d34a78790e173721c6c10e9899e07a29c818d4986296bdfadf5cc79e1ff1de49ff5679d1982cfdc370c3bacca15786c62b7b9e85
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.1] - 2024-07-02
4
+
5
+ - Use file .ruby-version to define the JRuby version for the jar file only if .ruby-version contains a valid jRuby version
6
+
7
+
8
+ ## [0.3.0] - 2024-06-18
9
+
10
+ - excludes_from_compile specifies paths as the location in the jar file
11
+ - Desupport of configuration attribute include_gems_to_compile
12
+
3
13
  ## [0.2.3] - 2024-06-13
4
14
 
5
15
  - Show used configuration values in log output
data/README.md CHANGED
@@ -53,21 +53,20 @@ To create a template config file with information about all the supported config
53
53
  The default configuration is focused on Ruby on Rails applications.<br>
54
54
 
55
55
  ### Configuration options
56
- | Option | Default value | Description |
57
- |-------------------------|--------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|
58
- | compile_ruby_files | false | Ahead of time compilation of all .rb files of application and Gem dependencies to .class files. Only store .class files in jar. Requires JRuby runtime. |
59
- | executable | "bin/rails" | The ruby start file to run at execution of jar file. File extension .class is used automatically if start file is .rb and AOT compilation is used. |
60
- | executable_params | ["server", "-e", "production", "-p", "8080"] | Command line parameters to be used for the ruby executable |
61
- | excludes_from_compile | ["config"] | The files and dirs of the project to exclude from the compilation of .rb files |
62
- | excludes | ["tmp/cache", "tmp/pids", ...] (see generated template file for whole content) | The files and dirs of the project to exclude from the include option |
63
- | include_gems_to_compile | false | Should .rb files of the project gems also be compiled if compile_ruby_files = true |
64
- | includes | ["app", "bin", "config", ...] (see generated template file for whole content) | The files and dirs of the project to include in the jar file |
65
- | jar_name | &lt; Name of project dir &gt;.jar | The name of the generated jar file |
66
- | jruby_version | The current most recent JRuby version | The version of the JRuby runtime to use |
56
+ | Option | Default value | Description |
57
+ |-------------------------|------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|
58
+ | compile_ruby_files | false | Ahead of time compilation of all .rb files of application and Gem dependencies to .class files. Only store .class files in jar. Requires JRuby runtime. |
59
+ | executable | "bin/rails" | The ruby start file to run at execution of jar file. File extension .class is used automatically if start file is .rb and AOT compilation is used. |
60
+ | executable_params | ["server", "-e", "production", "-p", "8080"] | Command line parameters to be used for the ruby executable |
61
+ | excludes_from_compile | [] | The files and dirs of the project to exclude from the compilation of .rb files. Paths specifies the location in the jar file (e.g. ["app_root/file.rb"] ) |
62
+ | excludes | ["tmp/cache", "tmp/pids", ...] (see generated template file for whole content) | The files and dirs of the project to exclude from the include option |
63
+ | includes | ["app", "bin", "config", ...] (see generated template file for whole content) | The files and dirs of the project to include in the jar file |
64
+ | jar_name | &lt; Name of project dir &gt;.jar | The name of the generated jar file |
65
+ | jruby_version | A valid JRuby version from file '.ruby-version' or the current most recent version of the Gem 'jruby-jars' | The version of the JRuby runtime to use |
67
66
 
68
67
 
69
68
  ## Troubleshooting
70
- * Set DEBUG=true in environment to get additional runtime information
69
+ * Set DEBUG=true in OS environment to get additional runtime information
71
70
  * The temporary folder with the extracted app and JRuby runtime files is not deleted after execution if DEBUG is set.
72
71
 
73
72
  ### Possible error messages
@@ -271,13 +271,9 @@ module Jarbler
271
271
 
272
272
  ruby_files = Find.find('.').select { |f| f =~ /\.rb$/ } # find all Ruby files in the current directory
273
273
 
274
- if !config.include_gems_to_compile
275
- ruby_files = ruby_files.select { |f| !(f =~ /\.#{File::SEPARATOR}gems#{File::SEPARATOR}/) } # Exclude ./gems/* directories from compiling
276
- end
277
-
278
274
  # Exclude named files or directories from compiling
279
275
  config.excludes_from_compile.each do |exclude|
280
- ruby_files = ruby_files.select { |f| !(f =~ /\.#{File::SEPARATOR}app_root#{File::SEPARATOR}#{exclude}/) }
276
+ ruby_files = ruby_files.select { |f| !(f =~ /\.#{File::SEPARATOR}#{exclude}/) }
281
277
  end
282
278
 
283
279
  ruby_files.each do |ruby_file|
@@ -3,7 +3,7 @@ require 'json'
3
3
 
4
4
  module Jarbler
5
5
  class Config
6
- attr_accessor :jar_name, :includes, :excludes, :jruby_version, :executable, :executable_params, :compile_ruby_files, :include_gems_to_compile, :excludes_from_compile
6
+ attr_accessor :jar_name, :includes, :excludes, :jruby_version, :executable, :executable_params, :compile_ruby_files, :excludes_from_compile
7
7
 
8
8
  CONFIG_FILE = 'config/jarble.rb'
9
9
  # create instance of Config class with defaults or from config file
@@ -31,13 +31,12 @@ module Jarbler
31
31
  puts "No configuration file found at #{File.join(Dir.pwd, CONFIG_FILE)}. Using default values."
32
32
  end
33
33
  puts "Used configuration values are:"
34
- puts " compile_ruby_files: #{config.compile_ruby_files}" if config.compile_ruby_files
35
- puts " excludes: #{config.excludes}" unless config.excludes.empty?
36
- puts " excludes_from_compile: #{config.excludes_from_compile}" unless config.excludes_from_compile.empty?
34
+ puts " compile_ruby_files: #{config.compile_ruby_files}"
35
+ puts " excludes: #{config.excludes}"
36
+ puts " excludes_from_compile: #{config.excludes_from_compile}"
37
37
  puts " executable: #{config.executable}"
38
- puts " executable_params: #{config.executable_params}" unless config.executable_params.empty?
39
- puts " include_gems_to_compile: #{config.include_gems_to_compile}" if config.include_gems_to_compile
40
- puts " includes: #{config.includes}" unless config.includes.empty?
38
+ puts " executable_params: #{config.executable_params}"
39
+ puts " includes: #{config.includes}"
41
40
  puts " jar_name: #{config.jar_name}"
42
41
  puts " jruby_version: #{config.jruby_version}"
43
42
  puts ""
@@ -47,10 +46,9 @@ module Jarbler
47
46
  def initialize
48
47
  @compile_ruby_files = false
49
48
  @excludes = %w(tmp/cache tmp/pids tmp/sockets vendor/bundle vendor/cache vendor/ruby)
50
- @excludes_from_compile = %w(config)
49
+ @excludes_from_compile = []
51
50
  @executable = 'bin/rails'
52
51
  @executable_params = %w(server -e production -p 8080)
53
- @include_gems_to_compile = false
54
52
  @includes = %w(app bin config config.ru db Gemfile Gemfile.lock lib log public Rakefile script vendor tmp)
55
53
  @jar_name = File.basename(Dir.pwd) + '.jar'
56
54
  @jruby_version = nil # determined automatically at runtime
@@ -88,10 +86,8 @@ module Jarbler
88
86
  # the original ruby files are not included in the jar file, so source code is not visible
89
87
  # config.compile_ruby_files = #{compile_ruby_files}
90
88
 
91
- # Compile also the .rb files of the gems of the project to Java .class files?
92
- # config.include_gems_to_compile = #{include_gems_to_compile}
93
-
94
89
  # Directories or files to exclude from the compilation if compile_ruby_files = true
90
+ # The paths map to the final location of files or dirs in the jar file, e.g. config.excludes_from_compile = ['gems', 'app_root/app/models']
95
91
  # config.excludes_from_compile = #{excludes_from_compile}
96
92
 
97
93
  ".split("\n"))
@@ -121,35 +117,51 @@ module Jarbler
121
117
 
122
118
  # define JRuby version if not set in config file
123
119
  def define_jruby_version
124
- unless @jruby_version # not defined in config file
125
- if File.exist?('.ruby-version')
126
- # read the file RAILS_ROOT/.ruby-version starting from char at position 6 to the end of the line
127
- self.jruby_version = File.read('.ruby-version')[6..20].strip
128
- debug "JRuby version from .ruby-version file: #{jruby_version}"
120
+ if @jruby_version.nil? && File.exist?('.ruby-version') # not yet defined in config file but .ruby-version file exists
121
+ # read the file RAILS_ROOT/.ruby-version starting from char at position 6 to the end of the line
122
+ full_jruby_version_string = File.read('.ruby-version')
123
+ if full_jruby_version_string[0..5] == 'jruby-'
124
+ @jruby_version = full_jruby_version_string[6..20].strip
125
+ if @jruby_version =~ /\d+\.\d+\.\d+\.\d+/ # check if the version is valid with four digits
126
+ debug "Jarbler::Config.define_jruby_version: JRuby version used from .ruby-version file: #{@jruby_version}"
127
+ else
128
+ debug "Jarbler::Config.define_jruby_version: Invalid JRuby version in .ruby-version file (not four digits delimited by dot): #{full_jruby_version_string}"
129
+ @jruby_version = nil
130
+ end
129
131
  else
130
- # no .ruby-version file, use JRuby version of the latest Gem
131
- # Fetch the gem specification from Rubygems.org
132
- # search for the gem and get the JSON response
133
- response = Gem::SpecFetcher.fetcher.search_for_dependency(Gem::Dependency.new('jruby-jars'))
134
- # extract the versions from the response
135
- self.jruby_version = response&.first&.first&.first&.version&.to_s
136
- raise "Unable to determine the latest available version of jruby-jars gem!\Rsponse = #{response.inspect}" unless self.jruby_version
137
-
138
- #command = "gem search --remote jruby-jars"
139
- #lines = `#{command}`
140
- #raise "Command \"#{command}\" failed with return code #{$?} and output:\n#{lines}" unless $?.success?
141
- #jruby_jars_line = lines.match(/^jruby-jars \((.*)\)/)
142
- #raise "No jruby-jars gem found in rubygems.org!" unless jruby_jars_line
143
- #self.jruby_version = /\((.*?)\)/.match(jruby_jars_line.to_s)[1]
144
- debug "JRuby version from latest jruby-jars gem: #{jruby_version}"
132
+ debug "Jarbler::Config.define_jruby_version: Version info from .ruby-version file not applicable: #{full_jruby_version_string}"
145
133
  end
146
134
  end
135
+
136
+ if @jruby_version.nil? # not yet defined in config file and .ruby-version file
137
+ # no .ruby-version file to be used, use JRuby version of the latest Gem
138
+ # Fetch the gem specification from Rubygems.org
139
+ # search for the gem and get the JSON response
140
+ response = Gem::SpecFetcher.fetcher.search_for_dependency(Gem::Dependency.new('jruby-jars'))
141
+ debug("Jarbler::Config.define_jruby_version: Response from search_for_dependency = #{response.inspect}")
142
+ # extract the versions from the response
143
+ @jruby_version = response&.first&.first&.first&.version&.to_s
144
+ raise "Unable to determine the latest available version of jruby-jars gem!\nResponse = #{response.inspect}" unless @jruby_version
145
+
146
+ #command = "gem search --remote jruby-jars"
147
+ #lines = `#{command}`
148
+ #raise "Command \"#{command}\" failed with return code #{$?} and output:\n#{lines}" unless $?.success?
149
+ #jruby_jars_line = lines.match(/^jruby-jars \((.*)\)/)
150
+ #raise "No jruby-jars gem found in rubygems.org!" unless jruby_jars_line
151
+ #self.jruby_version = /\((.*?)\)/.match(jruby_jars_line.to_s)[1]
152
+ debug "Jarbler::Config.define_jruby_version: JRuby version from latest jruby-jars gem: #{jruby_version}"
153
+ end
147
154
  end
148
155
 
149
156
  def debug(msg)
150
157
  puts msg if ENV['DEBUG']
151
158
  end
152
159
 
160
+ # Avoid exception if using depprecated config attribute include_gems_to_compile
161
+ def include_gems_to_compile=(_value)
162
+ puts "Configuration attribute 'include_gems_to_compile' is deprecated. Use 'excludes_from_compile = [\”gems\”]' instead."
163
+ end
164
+
153
165
  def validate_values
154
166
  raise "Invalid config value for jar name: #{jar_name}" unless jar_name =~ /\w+/
155
167
  raise "Invalid config value for executable: #{executable}" unless executable =~ /\w+/
@@ -158,8 +170,8 @@ module Jarbler
158
170
  raise "Invalid config value for excludes: #{excludes}" unless excludes.is_a?(Array)
159
171
  raise "Invalid config value for compile_ruby_files: #{compile_ruby_files}" unless [true, false].include?(compile_ruby_files)
160
172
  raise "compile_ruby_files = true is supported only with JRuby! Current runtime is '#{RUBY_ENGINE}'" if compile_ruby_files && (defined?(RUBY_ENGINE) && RUBY_ENGINE != 'jruby')
161
- raise "include_gems_to_compile = true is supported only if compile_ruby_files = true!" if include_gems_to_compile && !compile_ruby_files
162
173
  raise "Invalid config value for excludes_from_compile: #{excludes_from_compile}" unless excludes_from_compile.is_a?(Array)
174
+ raise "Invalid config value for jruby_version: #{jruby_version}" unless jruby_version.nil? || jruby_version =~ /\d+\.\d+\.\d+\.\d+/
163
175
  end
164
176
  end
165
177
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jarbler
4
- VERSION = "0.2.3"
5
- VERSION_DATE = "2024-06-13"
4
+ VERSION = "0.3.1"
5
+ VERSION_DATE = "2024-07-02"
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jarbler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ramm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-13 00:00:00.000000000 Z
11
+ date: 2024-07-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Pack a Ruby app combined with JRuby runtime and all its Gem dependencies
14
14
  into a jar file to simply run the app on any Java platform by '> java -jar file.jar'