jarbler 0.1.1 → 0.1.3

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: a6c86b6661dda0e9669619c5bac4a954a400dbeed028cb1944b9f0b781b4771d
4
- data.tar.gz: 987e8bd4e2bd388f1b1642a8b9e911e9774e4c9870eb56c3bb85d053de1e1e1b
3
+ metadata.gz: fa38516809660fd2add2d7f1cb4a47bf48f219afb69adc2242f582c96b3b7a6f
4
+ data.tar.gz: 8f6cca1c0fbf6e892f7db511ba012de9fb9f3c96bfa49079e373172f0c9ee64a
5
5
  SHA512:
6
- metadata.gz: 4810b94071beeda3eea5fc513646b63033129e38b258b0d274e4b3384705f3b1034ff7a706cf90317c6c0dd5086fea572652c7b89ddeba62bb3faebc68d1f69d
7
- data.tar.gz: b6054b374c79cc5f1d4976d1b486fcc4730e088e54285edb3156f6cd592ca2bf8c665c8fcfbec383fc4e9e2132268744dec11fdc1e81b5fbf0dbdf0d9c5cd40d
6
+ metadata.gz: 3b01cbb87353587184e147d9082e5c8a4807afec0308a940c6c53c4b65a9df13aaa1eac32e1a0615fd0f4716c9e5d49b0a7138895dc5857f40f9c31f3de2fe6d
7
+ data.tar.gz: 1ab3a61b970c11b13e2ad118507dee7463460baf11c4d2dc617babf85f4e253206952245d5dbbcc1cb42356143b17d90fe3594c35564aa91b6462c49da862020
data/CHANGELOG.md CHANGED
@@ -7,3 +7,11 @@
7
7
  ## [0.1.1] - 2023-04-24
8
8
 
9
9
  - Fixed the bug 'java.lang.ClassNotFoundException: org.jruby.Main' with Windows
10
+
11
+ ## [0.1.2] - 2023-04-24
12
+
13
+ - extract valid Gem paths from Bundler instead of using the environment variable GEM_PATH
14
+
15
+ ## [0.1.3] - 2023-04-25
16
+
17
+ - Removed .jruby-version so that the jruby version is not fixed anymore
data/Gemfile CHANGED
@@ -5,11 +5,13 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in jarbler.gemspec
6
6
  gemspec
7
7
 
8
- gem "rake", "~> 13.0"
8
+ # gem "rake", "~> 13.0"
9
+ gem "rake"
9
10
 
10
11
  group(:test) do
11
12
  gem 'minitest'
12
13
  gem 'minitest-reporters'
13
14
  # needed for minitests
14
- gem 'jruby-jars'
15
+ # test should install the jruby-jars in right version itself
16
+ # gem 'jruby-jars'
15
17
  end
data/README.md CHANGED
@@ -55,6 +55,12 @@ The default executable parameters are "server -p 8080 -e production".
55
55
  * Set DEBUG=true in environment to get additional runtime information
56
56
  * The temporary folder with the extracted app and jRuby runtime files is not deleted after execution if DEBUG is set.
57
57
 
58
+ ### Possible error messages
59
+ * 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.
60
+ * Reason: Mismatch between the version of the local requested gem and the version of the default gem
61
+ * Solution: Update the default gems to the requested version
62
+
63
+
58
64
  ## Contributing
59
65
 
60
66
  Bug reports and pull requests are welcome on GitHub at https://github.com/rammpeter/jarbler. <br>
data/build_gem.sh CHANGED
@@ -1,4 +1,8 @@
1
- # Steps for creating gem
1
+ # Steps for creating gem in local environment
2
+
3
+ # remove existing gem file
4
+ rm -f jarbler-*.gem
5
+
2
6
  rake test
3
7
  if [ $? -ne 0 ]; then
4
8
  echo "Tests failed."
@@ -11,7 +15,7 @@ if [ $? -ne 0 ]; then
11
15
  exit 1
12
16
  fi
13
17
 
14
- gem install jarbler-0.1.0.gem
18
+ gem install `ls jarbler-*.gem`
15
19
  if [ $? -ne 0 ]; then
16
20
  echo "Gem install failed."
17
21
  exit 1
@@ -1,6 +1,9 @@
1
+ require 'rubygems'
2
+ require 'rubygems/dependency_installer'
1
3
  require 'bundler'
2
4
  require 'find'
3
5
  require 'fileutils'
6
+ require 'yaml'
4
7
 
5
8
  module Jarbler
6
9
  class Builder
@@ -8,18 +11,16 @@ module Jarbler
8
11
  # Should be executed in application directory of Rails/Ruby application
9
12
  # @return [void]
10
13
  def build_jar
14
+ debug "Running with Ruby version '#{RUBY_VERSION}' on platform '#{RUBY_PLATFORM}'. Engine '#{RUBY_ENGINE}' version '#{RUBY_ENGINE_VERSION}'"
15
+
11
16
  # create a temporary directory for staging
12
17
  staging_dir = Dir.mktmpdir
13
18
 
14
- jarbler_lib_dir = __dir__
15
19
  app_root = Dir.pwd
16
20
  debug "Project dir: #{app_root}"
17
21
 
18
- # TODO: transform to internal bundler API call (check if jruby is installed + install if not)
19
- exec_command "gem install --no-doc jruby-jars -v #{config.jruby_version}" # Ensure that jruby-jars are installed in the requested version
20
- gem_search_locations = collect_gem_search_locations(app_root)
21
- ruby_version = copy_jruby_jars_to_staging(staging_dir, gem_search_locations) # Copy the jruby jars to the staging directory
22
- exec_command "javac -nowarn -Xlint:deprecation -source 8 -target 8 -d #{staging_dir} #{jarbler_lib_dir}/JarMain.java" # Compile the Java files
22
+ ruby_version = copy_jruby_jars_to_staging(staging_dir) # Copy the jruby jars to the staging directory
23
+ exec_command "javac -nowarn -Xlint:deprecation -source 8 -target 8 -d #{staging_dir} #{__dir__}/JarMain.java" # Compile the Java files
23
24
 
24
25
  # Copy the application project to the staging directory
25
26
  FileUtils.mkdir_p("#{staging_dir}/app_root")
@@ -34,10 +35,8 @@ module Jarbler
34
35
  FileUtils.mkdir_p("#{gem_target_location}/gems")
35
36
  FileUtils.mkdir_p("#{gem_target_location}/specifications")
36
37
 
37
- needed_gems = gem_dependencies # get the full names of the dependencies
38
- needed_gems.each do |gem_full_name|
39
- copy_gem_to_staging(gem_full_name, gem_target_location, gem_search_locations)
40
- end
38
+ # Copy the needed Gems to the staging directory
39
+ copy_needed_gems_to_staging(gem_target_location, app_root)
41
40
 
42
41
  Dir.chdir(staging_dir) do
43
42
  # create the manifest file
@@ -82,53 +81,36 @@ module Jarbler
82
81
 
83
82
  private
84
83
 
85
- # Find the locations where Gems are installed
86
- # @param [String] app_root Application root directory
87
- # @return [Array] Array of Gem locations
88
- def collect_gem_search_locations(app_root)
89
- # Search locations of gems in Gemfile.lock
90
- possible_gem_search_locations = []
91
- # Add possible local config first in search list
92
- possible_gem_search_locations << bundle_config_bundle_path(app_root) if bundle_config_bundle_path(app_root)
93
- ENV['GEM_PATH'].split(':').each do |gem_path|
94
- possible_gem_search_locations << gem_path
95
- end
96
- debug "Possible Gem locations: #{possible_gem_search_locations}"
97
- gem_search_locations = []
98
- # Check where inside this location the gems may be installed
99
- possible_gem_search_locations.each do |gem_search_location|
100
- valid_gem_search_location = nil # No valid path found yet
101
- Find.find(gem_search_location) do |path|
102
- if File.directory?(path) && File.exist?("#{path}/specifications") && File.exist?("#{path}/gems")
103
- valid_gem_search_location = path # Found a valid path
104
- Find.prune # Do not search deeper
105
- end
106
- end
107
- if valid_gem_search_location
108
- gem_search_locations << valid_gem_search_location
109
- else
110
- debug "No valid gem location found in #{gem_search_location}"
84
+
85
+ # Check if there is an additional local bundle path in .bundle/config
86
+ def bundle_config_bundle_path(rails_root)
87
+ bundle_path = nil # default
88
+ if File.exist?("#{rails_root}/.bundle/config")
89
+ bundle_config = YAML.load_file("#{rails_root}/.bundle/config")
90
+ if bundle_config && bundle_config['BUNDLE_PATH']
91
+ bundle_path = "#{rails_root}/#{bundle_config['BUNDLE_PATH']}"
92
+ debug "Local Gem path configured in #{rails_root}/.bundle/config: #{bundle_path}"
111
93
  end
112
94
  end
113
- debug "Valid Gem locations: #{gem_search_locations}"
114
- gem_search_locations
95
+ bundle_path
115
96
  end
116
97
 
117
- # Copy the Gem elements to the staging directory
118
- # @param [String] gem_full_name Full name of the Gem including version and platform
119
- # @param [String] staging_dir Path to the staging directory
120
- # @param [Array] gem_search_locations Array of Gem locations
98
+ # Copy the needed Gems to the staging directory
99
+ # @param [String] gem_target_location Path to the staging directory
121
100
  # @return [void]
122
- def copy_gem_to_staging(gem_full_name, gem_target_location, gem_search_locations)
123
- gem_search_locations.each do |gem_search_location|
124
- gem_dir = "#{gem_search_location}/gems/#{gem_full_name}"
125
- if File.exist?(gem_dir)
126
- file_utils_copy(gem_dir, "#{gem_target_location}/gems")
127
- file_utils_copy("#{gem_search_location}/specifications/#{gem_full_name}.gemspec", "#{gem_target_location}/specifications")
128
- return
129
- end
101
+ def copy_needed_gems_to_staging(gem_target_location, app_root)
102
+ #Bundler.with_unbundled_env do # No previous setting inherited like Gemfile location
103
+ # Bundler.reset! # Reset settings from previous Bundler.with_unbundled_env
104
+ needed_gems = gem_dependencies # get the full names of the dependencies
105
+ needed_gems.each do |needed_gem|
106
+ # Get the location of the needed gem
107
+ spec = Gem::Specification.find_by_name(needed_gem[:name], needed_gem[:version])
108
+ raise "Gem #{needed_gem[:full_name]} not found for copying" unless spec
109
+ debug "Found gem #{needed_gem[:full_name]} version #{needed_gem[:version]} in #{spec.gem_dir}"
110
+ file_utils_copy(spec.gem_dir, "#{gem_target_location}/gems")
111
+ file_utils_copy("#{spec.gem_dir}/../../specifications/#{needed_gem[:full_name]}.gemspec", "#{gem_target_location}/specifications")
112
+ # end
130
113
  end
131
- raise "Gem #{gem_name} (#{gem_version}) not found in any of the following locations:\n#{gem_search_locations.join("\n")}"
132
114
  end
133
115
 
134
116
  # Read the default/production dependencies from Gemfile.lock and Gemfile
@@ -137,7 +119,7 @@ module Jarbler
137
119
  needed_gems = []
138
120
  lockfile_specs = Bundler::LockfileParser.new(Bundler.read_file(Bundler.default_lockfile)).specs
139
121
 
140
- Bundler.setup # Load Gems specified in Gemfile
122
+ # Bundler.setup # Load Gems specified in Gemfile
141
123
  # filter Gems needed for production
142
124
  gemfile_specs = Bundler.definition.dependencies.select do |d|
143
125
  d.groups.include?(:default) || d.groups.include?(:production)
@@ -148,14 +130,16 @@ module Jarbler
148
130
  # find lockfile record for Gemfile spec
149
131
  lockfile_spec = lockfile_specs.find { |lockfile_spec| lockfile_spec.name == gemfile_spec.name }
150
132
  if lockfile_spec
151
- needed_gems << lockfile_spec.full_name unless needed_gems.include?(lockfile_spec.full_name)
133
+ unless needed_gems.map{|n| n[:fullname]}.include?(lockfile_spec.full_name)
134
+ needed_gems << { full_name: lockfile_spec.full_name, name: lockfile_spec.name, version: lockfile_spec.version }
135
+ end
152
136
  debug "Direct Gem dependency: #{lockfile_spec.full_name}"
153
137
  add_indirect_dependencies(lockfile_specs, lockfile_spec, needed_gems)
154
138
  else
155
139
  debug "Gem #{gemfile_spec.name} not found in Gemfile.lock"
156
140
  end
157
141
  end
158
- needed_gems.uniq.sort
142
+ needed_gems.uniq.sort{|a,b| a[:full_name] <=> b[:full_name]}
159
143
  end
160
144
 
161
145
  # recurively find all indirect dependencies
@@ -168,8 +152,8 @@ module Jarbler
168
152
  lockfile_spec_found = lockfile_specs.find { |lockfile_spec| lockfile_spec.name == lockfile_spec_dep.name }
169
153
  if lockfile_spec_found
170
154
  debug "Indirect Gem dependency from #{lockfile_spec.full_name}: #{lockfile_spec_found.full_name}"
171
- unless needed_gems.include?(lockfile_spec_found.full_name)
172
- needed_gems << lockfile_spec_found.full_name
155
+ unless needed_gems.map{|n| n[:fullname]}.include?(lockfile_spec_found.full_name)
156
+ needed_gems << { full_name: lockfile_spec_found.full_name, name: lockfile_spec_found.name, version: lockfile_spec_found.version }
173
157
  add_indirect_dependencies(lockfile_specs, lockfile_spec_found, needed_gems)
174
158
  end
175
159
  else
@@ -193,33 +177,24 @@ module Jarbler
193
177
  @config
194
178
  end
195
179
 
196
- # Check if there is an additional local bundle path in .bundle/config
197
- def bundle_config_bundle_path(rails_root)
198
- bundle_path = nil # default
199
- if File.exist?("#{rails_root}/.bundle/config")
200
- bundle_config = YAML.load_file("#{rails_root}/.bundle/config")
201
- if bundle_config && bundle_config['BUNDLE_PATH']
202
- bundle_path = "#{rails_root}/#{bundle_config['BUNDLE_PATH']}"
203
- debug "Local Gem path configured in #{rails_root}/.bundle/config: #{bundle_path}"
204
- end
205
- end
206
- bundle_path
207
- end
208
-
209
180
  # Copy the jruby-jars to the staging directory
210
181
  # @param [String] staging_dir Path to the staging directory
211
182
  # @param [Array] gem_search_locations Array of Gem locations to look for jRuby jars
212
183
  # @return [String] the ruby version of the jRuby jars
213
- def copy_jruby_jars_to_staging(staging_dir, gem_search_locations)
214
- jruby_jars_location = nil
215
- gem_search_locations.each do |gem_search_location|
216
- gem_dir = "#{gem_search_location}/gems/jruby-jars-#{config.jruby_version}"
217
- if File.exist?(gem_dir)
218
- jruby_jars_location = gem_dir
219
- break
220
- end
221
- end
222
- raise "Could not determine location of jRuby jars for release '#{config.jruby_version}' in the following output:\n#{lines}" unless jruby_jars_location
184
+ def copy_jruby_jars_to_staging(staging_dir)
185
+
186
+ # Ensure that jruby-jars gem is installed, otherwise install it. Accepts also bundler path in .bundle/config
187
+ installer = Gem::DependencyInstaller.new
188
+ installed = installer.install('jruby-jars', config.jruby_version)
189
+ raise "jruby-jars gem not installed in version #{config.jruby_version}" if installed.empty?
190
+
191
+ jruby_jars_location = installed[0]&.full_gem_path
192
+ debug "jRuby jars installed at: #{jruby_jars_location}"
193
+
194
+ # Get the location of the jruby-jars gem
195
+ # spec = Gem::Specification.find_by_name('jruby-jars', config.jruby_version)
196
+ # jruby_jars_location = spec.gem_dir
197
+
223
198
  file_utils_copy("#{jruby_jars_location}/lib/jruby-core-#{config.jruby_version}-complete.jar", staging_dir)
224
199
  file_utils_copy("#{jruby_jars_location}/lib/jruby-stdlib-#{config.jruby_version}.jar", staging_dir)
225
200
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jarbler
4
- VERSION = "0.1.1"
5
- VERSION_DATE = "2023-04-24"
4
+ VERSION = "0.1.3"
5
+ VERSION_DATE = "2023-04-25"
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.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ramm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-24 00:00:00.000000000 Z
11
+ date: 2023-04-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Pack Ruby combined with jRuby runtime into a jar file to simply run the
14
14
  app on any Java platform by '> java -jar file.jar'
@@ -19,7 +19,6 @@ executables:
19
19
  extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
- - ".ruby-version"
23
22
  - CHANGELOG.md
24
23
  - Gemfile
25
24
  - LICENSE
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- ruby-3.2.2