jarbler 0.3.6 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1496bf31678cf15945cd367d656a6717df35552c3deacf4e44d0f0d8267e26a0
4
- data.tar.gz: 401efdc3ab67e9e913de4550ea108dc13899ececc0ab1b14267451e731803159
3
+ metadata.gz: 70f0325158bf02611ae188df443a2e22a3032f7b8e275e09d0e2ff8216476979
4
+ data.tar.gz: 1d5ca40cfa30dad802a394e4b4980854d0a0bb093cf00eafece8ef5b090e5c85
5
5
  SHA512:
6
- metadata.gz: 39a464b266c5f06ebf2270e117ba0f81a7fae012c70d5a18737b89e72ab9c3f99ea44d0aa5d898e55b4381789a21e7b2c2e1a1abbc3e781a0d10da12f272cce2
7
- data.tar.gz: 449426ef9a89c170efc469fc87ad179c2c89438580fac0cecbf19c6b06d7af048f0e345f3569aa46a6d4578ef3422602ea5f6acc84b3102544da8a43f7b4863c
6
+ metadata.gz: c3671a308f5c65bcc937676930c9792d6461db55f52e2dd6d609edb3ad1d75262164740b951d733fb71041954fc8ee3377b91122af78d0e1768e1977bc851470
7
+ data.tar.gz: c33d7b1affbcf4cdd4c7cb9f1e5ecf375e083266c59e077ed28d4532ded06b301d4b88b29e9afb63ba0c2d98c699ca9315d7afd35b3bb2037728d3e602693d4b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.1] - 2025-07-15
4
+
5
+ - config attribute 'gemfile_groups' established to specify the groups of the Gemfile which should be included in the jar file
6
+
7
+ ## [0.4.0] - 2025-04-24
8
+
9
+ - config attribute `compile_java_version` removed and replaced by 'java_opts'
10
+ - new config attribute `java_opts` allows to set additional options for the Java compiler used for jar file bootstrap code
11
+ - `java_opts` does not affect the optional AOT compilation of Ruby files.
12
+ - new config attribute `jrubyc_opts` allows to set additional options for JRuby's AOT compiler used for compilation of Ruby files
13
+
3
14
  ## [0.3.6] - 2025-03-31
4
15
 
5
16
  - remove temporary folder with extracted jar content after termination of Ruby code even if Ruby code terminates the JVM hard with 'exit' or 'System.exit'
data/README.md CHANGED
@@ -25,7 +25,7 @@ To create a jar file simply run "jarble" in your application's root directory.
25
25
 
26
26
  $ jarble
27
27
 
28
- To adjust Jarbler's configuration, modify the settings in config file ´config/jarble.rb´. The template for this config file you create by executing
28
+ To adjust Jarbler's configuration, modify the settings in config file `config/jarble.rb`. The template for this config file you create by executing
29
29
 
30
30
  $ jarble config
31
31
 
@@ -45,7 +45,7 @@ Additional command line parameters are passed through to the executed Ruby app (
45
45
 
46
46
  ## Configuration
47
47
 
48
- The file config/jarble.rb contains the configuration for Jarbler.
48
+ The file `config/jarble.rb` contains the configuration for Jarbler.
49
49
  To create a template config file with information about all the supported configuration options, execute:
50
50
 
51
51
  $ jarble config
@@ -53,17 +53,19 @@ 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_java_version | none | Java version the compiled .class files should be compatible with. Controls the target and source version of the Java compiler if compile_ruby_files=true (javac -source and -target). E.g. "1.8" for Java 8. If not set then it generates the class file version according to your current Java version. |
59
- | compile_ruby_files | false | Ahead of time compilation of all .rb files of the application to .class files. Only the .class files are stored in the jar file. The Gem dependencies are not compiled. Requires JRuby as Ruby environment at compile time. |
60
- | 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. |
61
- | executable_params | ["server", "-e", "production", "-p", "8080"] | Command line parameters to be used for the ruby executable |
62
- | 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"] ) |
63
- | 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 |
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 | 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 |
56
+ | Option | Default value | Description |
57
+ |-----------------------|------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
58
+ | compile_ruby_files | false | Ahead of time compilation of all .rb files of the application to .class files.<br/>Only the .class files are stored in the jar file. The Gem dependencies are not compiled. Requires JRuby as Ruby environment at compile time. |
59
+ | 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"] ) |
60
+ | 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 |
61
+ | 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. |
62
+ | executable_params | ["server", "-e", "production", "-p", "8080"] | Command line parameters to be used for the ruby executable |
63
+ | gemfile_groups | [:default, :production] | List of groups from Gemfile to include in the jar file, e.g. [:default, :production, :development, :test].<br/>Group :default are all gems not assigned to a specific group. |
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
+ | java_opts | none | Additional options for the Java compiler (javac).<br/>Used for the compilation of the jar file bootstrap class JarMain.java.<br/>Does not influence the optional AOT compilation of the application's ruby files.<br/>E.g. control the class file version of the JarMain.class with `java_opts = '-target 1.8 -source 1.8‘`. |
67
+ | jrubyc_opts | [] | Additional options for the JRuby compiler (jrubyc).<br/>Used for the AOT compilation of the application's ruby files if `compile_ruby_files:true`.<br/><br/>Some of the possible values are:<ul><li>`-J<java opts>`options for javac if `--java` or `--javac` is also set in `jrubyc_opts`, otherwise ignored</li><li>`--java` Generate Java classes (.java) for a script containing Ruby class definitions</li><li>`--javac` Generate Java classes (.java and .class) for a script containing Ruby class definitions</li><li>`-c or --classpath PATH` Add a jar to the classpath for building</li><li>`--verbose` Log verbose output while compile</li></ul> |
68
+ | 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
69
 
68
70
 
69
71
  ## Troubleshooting
@@ -74,6 +76,9 @@ The default configuration is focused on Ruby on Rails applications.<br>
74
76
  * Gem::LoadError: You have already activated ..., but your Gemfile requires ... . Since ... is a default gem, you can either remove your dependency on it or try updating to a newer version of bundler that supports net-protocol as a default gem.
75
77
  * Reason: Mismatch between the version of the local requested gem and the version of the default gem
76
78
  * Solution: Update the default gems to the requested version
79
+ * TypeError:no implicit conversion of Symbol into Integer at lib/ruby/stdlib/jruby/compiler.rb:61
80
+ * Reason: There was an error in JRuby compiler upto 9.4.12.0 or 10.0.0.0. if combining `compile_ruby_files' with `java_opts`. See: https://github.com/jruby/jruby/issues/8795
81
+ * Solution: Avoid using this combination or use a newer JRuby version where this issue is fixed.
77
82
 
78
83
 
79
84
  ## Contributing
@@ -10,7 +10,7 @@ module Jarbler
10
10
  class Builder
11
11
  # Execute all functions needed to build the jar file
12
12
  # Should be executed in application directory of Rails/Ruby application
13
- # @return [void]
13
+ # @return [String] Ruby minor version of the JRuby jars with patch level set to 0
14
14
  def build_jar
15
15
  debug "Running with Ruby version '#{RUBY_VERSION}' on platform '#{RUBY_PLATFORM}'. Engine '#{RUBY_ENGINE}' version '#{RUBY_ENGINE_VERSION}'"
16
16
 
@@ -19,12 +19,8 @@ module Jarbler
19
19
  app_root = Dir.pwd
20
20
  debug "Project dir: #{app_root}"
21
21
 
22
- source_and_target = if config.compile_java_version
23
- "-source #{config.compile_java_version} -target #{config.compile_java_version}"
24
- end
25
-
26
22
  ruby_minor_version = copy_jruby_jars_to_staging(staging_dir) # Copy the jruby jars to the staging directory
27
- exec_command "javac -nowarn -Xlint:deprecation #{source_and_target} -d #{staging_dir} #{__dir__}/JarMain.java" # Compile the Java files
23
+ exec_command "javac -nowarn -Xlint:deprecation #{config.java_opts} -d #{staging_dir} #{__dir__}/JarMain.java" # Compile the Java files
28
24
 
29
25
  # Copy the application project to the staging directory
30
26
  FileUtils.mkdir_p("#{staging_dir}/app_root")
@@ -76,6 +72,7 @@ module Jarbler
76
72
  # place the jar in project directory
77
73
  file_utils_copy(config.jar_name, app_root)
78
74
  puts "Created jar file #{app_root}/#{config.jar_name}"
75
+ ruby_minor_version # Used in tests to know the target Gem dir
79
76
  end
80
77
  rescue Exception => e
81
78
  puts "Error: #{e.message}"
@@ -148,10 +145,10 @@ module Jarbler
148
145
  lockfile_parser = Bundler::LockfileParser.new(Bundler.read_file(Bundler.default_lockfile))
149
146
  lockfile_specs = lockfile_parser.specs
150
147
 
151
- Bundler.setup # Load Gems specified in Gemfile, ensure that Gem path also includes the Gems loaded into bundler dir
148
+ Bundler.setup(*config.gemfile_groups) # Load Gems specified in Gemfile, ensure that Gem path also includes the Gems loaded into bundler dir
152
149
  # filter Gems needed for production
153
150
  gemfile_specs = Bundler.definition.dependencies.select do |d|
154
- d.groups.include?(:default) || d.groups.include?(:production)
151
+ !(d.groups & config.gemfile_groups).empty? # Check if the Gem is in the groups specified in config.gemfile_groups
155
152
  end
156
153
 
157
154
  debug "Gems from Gemfile needed for production:"
@@ -328,7 +325,10 @@ module Jarbler
328
325
  debug "Compile Ruby file #{ruby_file}"
329
326
  full_file_name = File.join(Dir.pwd, ruby_file) # full name including path is required by the JRuby compiler
330
327
  begin
331
- status = JRuby::Compiler::compile_argv([full_file_name]) # compile the Ruby file
328
+ args = [full_file_name]
329
+ args.concat(config.jrubyc_opts)
330
+ args << "-t#{File.dirname(full_file_name)}" # target directory for the compiled class file
331
+ status = JRuby::Compiler::compile_argv(args) # compile the Ruby file
332
332
  if status == 0
333
333
  File.delete(full_file_name) # remove the original Ruby file to ensure that the compiled class file is used
334
334
  else
@@ -337,6 +337,7 @@ module Jarbler
337
337
  rescue Exception => e
338
338
  puts "Error compiling Ruby file '#{ruby_file}': #{e.class}:#{e.message}"
339
339
  puts "'#{ruby_file}' is not compiled and will be included in the jar file as original Ruby file"
340
+ puts e.backtrace.join("\n")
340
341
  end
341
342
  end
342
343
  rescue Exception => e
@@ -3,7 +3,18 @@ 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, :excludes_from_compile, :compile_java_version
6
+ attr_accessor :compile_java_version, # compile_java_version only for backward compatibility, use java_opts instead
7
+ :compile_ruby_files,
8
+ :excludes,
9
+ :excludes_from_compile,
10
+ :executable,
11
+ :executable_params,
12
+ :gemfile_groups,
13
+ :includes,
14
+ :java_opts,
15
+ :jar_name,
16
+ :jrubyc_opts,
17
+ :jruby_version
7
18
 
8
19
  CONFIG_FILE = 'config/jarble.rb'
9
20
  # create instance of Config class with defaults or from config file
@@ -19,8 +30,9 @@ module Jarbler
19
30
  config = Config.new
20
31
  end
21
32
  config.define_jruby_version
33
+
22
34
  # Replace .rb with .class if compile_ruby_files is true
23
- config.executable = config.executable.sub(/\.rb$/, '.class') if config.compile_ruby_files
35
+ config.executable = config.executable.sub(/\.rb$/, '.class') if config.compile_ruby_files && !config.excludes_from_compile.include?("app_root#{File::SEPARATOR}#{config.executable}")
24
36
 
25
37
  config.validate_values
26
38
 
@@ -31,29 +43,34 @@ module Jarbler
31
43
  puts "No configuration file found at #{File.join(Dir.pwd, CONFIG_FILE)}. Using default values."
32
44
  end
33
45
  puts "Used configuration values are:"
34
- puts " compile_java_version: #{config.compile_java_version}" if config.compile_ruby_files
35
46
  puts " compile_ruby_files: #{config.compile_ruby_files}"
36
47
  puts " excludes: #{config.excludes}"
37
48
  puts " excludes_from_compile: #{config.excludes_from_compile}" if config.compile_ruby_files
38
49
  puts " executable: #{config.executable}"
39
50
  puts " executable_params: #{config.executable_params}"
51
+ puts " gemfile_groups: #{config.gemfile_groups}"
40
52
  puts " includes: #{config.includes}"
41
53
  puts " jar_name: #{config.jar_name}"
54
+ puts " java_opts: #{config.java_opts}"
55
+ puts " jrubyc_opts: #{config.jruby_version}" if config.compile_ruby_files
42
56
  puts " jruby_version: #{config.jruby_version}"
43
57
  puts ""
44
58
  config
45
59
  end
46
60
 
47
61
  def initialize
48
- @compile_ruby_files = false
49
- @compile_java_version = nil # not specified by default
50
- @excludes = %w(tmp/cache tmp/pids tmp/sockets vendor/bundle vendor/cache vendor/ruby)
51
- @excludes_from_compile = []
52
- @executable = 'bin/rails'
53
- @executable_params = %w(server -e production -p 8080)
54
- @includes = %w(app bin config config.ru db Gemfile Gemfile.lock lib log public Rakefile script vendor tmp)
55
- @jar_name = File.basename(Dir.pwd) + '.jar'
56
- @jruby_version = nil # determined automatically at runtime
62
+ @compile_ruby_files = false
63
+ @compile_java_version = nil # deprecated, use java_opts instead
64
+ @excludes = %w(tmp/cache tmp/pids tmp/sockets vendor/bundle vendor/cache vendor/ruby)
65
+ @excludes_from_compile = []
66
+ @executable = 'bin/rails'
67
+ @executable_params = %w(server -e production -p 8080)
68
+ @gemfile_groups = [:default, :production]
69
+ @includes = %w(app bin config config.ru db Gemfile Gemfile.lock lib log public Rakefile script vendor tmp)
70
+ @java_opts = nil
71
+ @jar_name = File.basename(Dir.pwd) + '.jar'
72
+ @jrubyc_opts = []
73
+ @jruby_version = nil # determined automatically at runtime
57
74
  # execute additional block if given
58
75
  yield self if block_given?
59
76
  end
@@ -61,22 +78,17 @@ module Jarbler
61
78
  # Generate the template config file based on default values
62
79
  def create_config_file
63
80
  write_config_file("\
64
- # Name of the generated jar file
65
- # config.jar_name = '#{jar_name}'
66
-
67
- # Application directories or files to include in the jar file
68
- # config.includes = #{includes}
69
- # config.includes << 'additional'
81
+ # Compile the ruby files of the project to Java .class files with JRuby's ahead-of-time compiler?
82
+ # the original ruby files are not included in the jar file, so source code is not visible
83
+ # config.compile_ruby_files = #{compile_ruby_files}
70
84
 
71
85
  # Application directories or files to exclude from the jar file
72
86
  # config.excludes = #{excludes}
73
87
  # config.excludes << 'additional'
74
88
 
75
- # Use certain JRuby version
76
- # if not set (nil) then the version defined in .ruby-version
77
- # if not JRuby version defined here or in .ruby-version then the latest available JRuby version is used
78
- # config.jruby_version = '9.2.3.0'
79
- # config.jruby_version = nil
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']
91
+ # config.excludes_from_compile = #{excludes_from_compile}
80
92
 
81
93
  # The Ruby executable file to run, e.g. 'bin/rails' or 'bin/rake'
82
94
  # config.executable = '#{executable}'
@@ -84,18 +96,32 @@ module Jarbler
84
96
  # Additional command line parameters for the Ruby executable
85
97
  # config.executable_params = #{executable_params}
86
98
 
87
- # Compile the ruby files of the project to Java .class files with JRuby's ahead-of-time compiler?
88
- # the original ruby files are not included in the jar file, so source code is not visible
89
- # config.compile_ruby_files = #{compile_ruby_files}
99
+ # List of groups from Gemfile to include in the jar file, e.g. [:default, :production, :development, :test]
100
+ # group :default are all gems not assigned to a specific group
101
+ # config.gemfile_groups = #{gemfile_groups}
90
102
 
91
- # Java version the compiled .class files should be compatible with
92
- # controls the target and source version of the Java compiler (javac -source and -target)
93
- # if not set then it generates the class file version according to your current Java version
94
- # config.compile_java_version = '1.8'
103
+ # Application directories or files to include in the jar file
104
+ # config.includes = #{includes}
105
+ # config.includes << 'additional'
95
106
 
96
- # Directories or files to exclude from the compilation if compile_ruby_files = true
97
- # 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']
98
- # config.excludes_from_compile = #{excludes_from_compile}
107
+ # Name of the generated jar file
108
+ # config.jar_name = '#{jar_name}'
109
+
110
+ # Additional options for the Java compiler (javac).
111
+ # Used for the compilation of the jar file bootstrap class JarMain.java.
112
+ # Also used for the optional compilation of the ruby files if compile_ruby_files = true.
113
+ # E.g. control the class file version of the generated jar file with -source and -target
114
+ # config.java_opts = '-target 1.8 -source 1.8'
115
+
116
+ # Additional options for the JRuby compiler (jrubyc).
117
+ # Used for the optional compilation of the ruby files if compile_ruby_files = true.
118
+ # config.jrubyc_opts = ['--javac'. '--verbose']
119
+
120
+ # Use certain JRuby version
121
+ # if not set (nil) then the version defined in .ruby-version
122
+ # if not JRuby version defined here or in .ruby-version then the latest available JRuby version is used
123
+ # config.jruby_version = '9.2.3.0'
124
+ # config.jruby_version = nil
99
125
 
100
126
  ".split("\n"))
101
127
  end
@@ -164,14 +190,17 @@ module Jarbler
164
190
  end
165
191
 
166
192
  def validate_values
193
+ raise "compile_java_version is not valid any more! Use config.java_opts instead with -source and -target." if compile_java_version
167
194
  raise "Invalid config value for jar name: #{jar_name}" unless jar_name =~ /\w+/
168
195
  raise "Invalid config value for executable: #{executable}" unless executable =~ /\w+/
169
196
  raise "Invalid config value for executable params: #{executable_params}" unless executable_params.is_a?(Array)
197
+ raise "Invalid config value for gemfile groups: #{gemfile_groups}" unless gemfile_groups.is_a?(Array)
170
198
  raise "Invalid config value for includes: #{includes}" unless includes.is_a?(Array)
171
199
  raise "Invalid config value for excludes: #{excludes}" unless excludes.is_a?(Array)
172
200
  raise "Invalid config value for compile_ruby_files: #{compile_ruby_files}" unless [true, false].include?(compile_ruby_files)
173
201
  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')
174
202
  raise "Invalid config value for excludes_from_compile: #{excludes_from_compile}" unless excludes_from_compile.is_a?(Array)
203
+ raise "Invalid config value for jrubyc_opts, should by Array: #{jrubyc_opts}" unless jrubyc_opts.is_a?(Array)
175
204
  raise "Invalid config value for jruby_version: #{jruby_version}" unless jruby_version.nil? || jruby_version =~ /\d+\.\d+\.\d+\.\d+/
176
205
  end
177
206
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jarbler
4
- VERSION = "0.3.6"
5
- VERSION_DATE = "2025-03-31"
4
+ VERSION = "0.4.1"
5
+ VERSION_DATE = "2025-07-15"
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.3.6
4
+ version: 0.4.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: 2025-04-01 00:00:00.000000000 Z
11
+ date: 2025-07-15 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'