jarbler 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile +4 -2
- data/README.md +6 -0
- data/build_gem.sh +6 -2
- data/lib/jarbler/builder.rb +54 -66
- data/lib/jarbler/version.rb +2 -2
- metadata +2 -3
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa38516809660fd2add2d7f1cb4a47bf48f219afb69adc2242f582c96b3b7a6f
|
4
|
+
data.tar.gz: 8f6cca1c0fbf6e892f7db511ba012de9fb9f3c96bfa49079e373172f0c9ee64a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b01cbb87353587184e147d9082e5c8a4807afec0308a940c6c53c4b65a9df13aaa1eac32e1a0615fd0f4716c9e5d49b0a7138895dc5857f40f9c31f3de2fe6d
|
7
|
+
data.tar.gz: 1ab3a61b970c11b13e2ad118507dee7463460baf11c4d2dc617babf85f4e253206952245d5dbbcc1cb42356143b17d90fe3594c35564aa91b6462c49da862020
|
data/CHANGELOG.md
CHANGED
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
|
-
|
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
|
18
|
+
gem install `ls jarbler-*.gem`
|
15
19
|
if [ $? -ne 0 ]; then
|
16
20
|
echo "Gem install failed."
|
17
21
|
exit 1
|
data/lib/jarbler/builder.rb
CHANGED
@@ -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
|
-
|
19
|
-
exec_command
|
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
|
-
|
38
|
-
|
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
|
-
|
86
|
-
#
|
87
|
-
|
88
|
-
|
89
|
-
#
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
# Check where inside this location the gems may be installed
|
95
|
-
possible_gem_search_locations.each do |gem_search_location|
|
96
|
-
if File.exist?(gem_search_location) && File.directory?(gem_search_location)
|
97
|
-
valid_gem_search_location = nil # No valid path found yet
|
98
|
-
Find.find(gem_search_location) do |path|
|
99
|
-
if File.directory?(path) && File.exist?("#{path}/specifications") && File.exist?("#{path}/gems")
|
100
|
-
valid_gem_search_location = path # Found a valid path
|
101
|
-
Find.prune # Do not search deeper
|
102
|
-
end
|
103
|
-
end
|
104
|
-
if valid_gem_search_location
|
105
|
-
gem_search_locations << valid_gem_search_location
|
106
|
-
else
|
107
|
-
debug "No valid gem location found in #{gem_search_location}"
|
108
|
-
end
|
109
|
-
else
|
110
|
-
debug("Gem location #{gem_search_location} does not exist or is not a directory")
|
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
|
-
|
114
|
-
gem_search_locations
|
95
|
+
bundle_path
|
115
96
|
end
|
116
97
|
|
117
|
-
# Copy the
|
118
|
-
# @param [String]
|
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
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
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
|
-
|
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
|
@@ -197,16 +181,20 @@ module Jarbler
|
|
197
181
|
# @param [String] staging_dir Path to the staging directory
|
198
182
|
# @param [Array] gem_search_locations Array of Gem locations to look for jRuby jars
|
199
183
|
# @return [String] the ruby version of the jRuby jars
|
200
|
-
def copy_jruby_jars_to_staging(staging_dir
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
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
|
+
|
210
198
|
file_utils_copy("#{jruby_jars_location}/lib/jruby-core-#{config.jruby_version}-complete.jar", staging_dir)
|
211
199
|
file_utils_copy("#{jruby_jars_location}/lib/jruby-stdlib-#{config.jruby_version}.jar", staging_dir)
|
212
200
|
|
data/lib/jarbler/version.rb
CHANGED
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.
|
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-
|
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
|