jar-dependencies 0.6.0.pre3-java

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 92976e67d21610e137cef159d14a61f57c0c1b9c2215425d6165ebc0be0ff492
4
+ data.tar.gz: f1d11f3d54f78e14fde342fe99758821c2ce5726348d979d5e87d151a2b2b329
5
+ SHA512:
6
+ metadata.gz: c157385bf7ca957c668ff6d603aebe9059ab2f80ac04c106a03e3ec0867e4c842ae8eade15275adc57ee5482dea6f1223ec4390c61884642dc795cfce76bf4eb
7
+ data.tar.gz: 05a38e3355d651c13de3eb4b5aafa11f6505929675000bdbf3f3686cd87d7d5d899afa2d977f41fe84ca55d5f0c1b2d89ff001d8dc399cb9185f7c9448a4036a
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Christian Meier
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Mavenfile ADDED
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ gemfile
4
+
5
+ plugin_repository id: :mavengems, url: 'mavengem:https://rubygems.org'
6
+
7
+ jruby_plugin(:minitest, minispecDirectory: 'specs/*_spec.rb') do
8
+ execute_goals(:spec)
9
+ end
10
+
11
+ properties('jruby.versions' => ['${jruby.version}'].join(','),
12
+ # just lock the version
13
+ 'bundler.version' => '2.5.11',
14
+ 'jruby.version' => '9.4.8.0',
15
+ 'jruby.plugins.version' => '3.0.6',
16
+ 'push.skip' => true)
17
+
18
+ #plugin :invoker, '1.8' do
19
+ # execute_goals(:install, :run,
20
+ # id: 'integration-tests',
21
+ # projectsDirectory: 'integration',
22
+ # streamLogs: true,
23
+ # goals: ['install'],
24
+ # preBuildHookScript: 'setup.bsh',
25
+ # postBuildHookScript: 'verify.bsh',
26
+ # cloneProjectsTo: '${project.build.directory}',
27
+ # properties: { 'jar-dependencies.version' => '${project.version}',
28
+ # # use an old jruby with old ruby-maven here
29
+ # 'jruby.version' => '${jruby.version}',
30
+ # 'jruby.plugins.version' => '${jruby.plugins.version}',
31
+ # 'bundler.version' => '${bundler.version}', })
32
+ #end
33
+
34
+ distribution_management do
35
+ repository id: :ossrh, url: 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
36
+ end
37
+
38
+ profile id: :skip do
39
+ properties 'maven.test.skip' => true, 'invoker.skip' => true
40
+ end
41
+
42
+ profile id: :release do
43
+ properties 'maven.test.skip' => true, 'invoker.skip' => true, 'push.skip' => false
44
+
45
+ build do
46
+ default_goal :deploy
47
+ end
48
+ end
data/Rakefile ADDED
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ task default: [:specs]
4
+
5
+ require 'bundler/gem_tasks'
6
+ require 'rake/clean'
7
+
8
+ begin
9
+ require 'rubocop/rake_task'
10
+ RuboCop::RakeTask.new
11
+ rescue LoadError
12
+ # RuboCop not available; skip defining the task
13
+ end
14
+
15
+ desc 'run specs'
16
+ task :specs do
17
+ $LOAD_PATH << 'specs'
18
+
19
+ Dir['specs/*_spec.rb'].each do |f|
20
+ require File.basename(f.sub(/.rb$/, ''))
21
+ end
22
+ end
23
+
24
+ require_relative 'lib/jars/mima/version'
25
+
26
+ MIMA_VERSION = Jars::Mima::MIMA_VERSION
27
+ SLF4J_VERSION = Jars::Mima::SLF4J_VERSION
28
+ MIMA_JARS = Jars::Mima::JARS
29
+ MIMA_DIR = Jars::Mima::MIMA_DIR
30
+
31
+ MIMA_JARS.each_key { |jar| CLEAN.include(File.join(MIMA_DIR, jar)) }
32
+
33
+ desc 'download Mima (and dependent SLF4J) jars'
34
+ task :download_jars do
35
+ require 'fileutils'
36
+ require 'open-uri'
37
+ require 'digest/sha1'
38
+
39
+ FileUtils.mkdir_p(MIMA_DIR)
40
+
41
+ MIMA_JARS.each do |filename, info|
42
+ target = File.join(MIMA_DIR, filename)
43
+ if File.exist?(target)
44
+ verify_checksum(target, info[:sha1])
45
+ puts " exists: #{target}"
46
+ next
47
+ end
48
+
49
+ puts " downloading #{filename}..."
50
+ URI.open(info[:url]) do |remote| # rubocop:disable Security/Open
51
+ File.binwrite(target, remote.read)
52
+ end
53
+ verify_checksum(target, info[:sha1])
54
+ puts " saved: #{target}"
55
+ end
56
+ end
57
+
58
+ def verify_checksum(path, expected_sha1)
59
+ actual = Digest::SHA1.file(path).hexdigest
60
+ return if actual == expected_sha1
61
+
62
+ File.delete(path)
63
+ raise "SHA-1 mismatch for #{path}:\n " \
64
+ "expected: #{expected_sha1}\n " \
65
+ "actual: #{actual}"
66
+ end
data/Readme.md ADDED
@@ -0,0 +1,225 @@
1
+ # jar-dependencies
2
+
3
+ [![Gem Version](https://img.shields.io/gem/v/jar-dependencies)](https://rubygems.org/gems/jar-dependencies)
4
+ [![Build Status](https://github.com/jruby/jar-dependencies/actions/workflows/main.yml/badge.svg)](https://github.com/jruby/jar-dependencies/actions/workflows/main.yml?query=branch%3Amaster)
5
+
6
+ Add gem dependencies for jar files to ruby gems.
7
+
8
+ ## Getting control back over your jar
9
+
10
+ jar dependencies are declared in the gemspec of the gem using the same notation
11
+ as [JBundler](https://github.com/jruby/jbundler).
12
+
13
+ When using `require_jar` to load the jar into JRuby's classloader a version conflict
14
+ will be detected and only **ONE** jar gets loaded.
15
+ **jbundler** allows to select the version suitable for you application.
16
+
17
+ Most maven-artifacts do **NOT** use versions ranges but depend on a concrete version.
18
+ In such cases **jbundler** can always **overwrite** any such version.
19
+
20
+
21
+ ## Vendoring your jars before packing the jar
22
+
23
+ Add the following to your *Rakefile*:
24
+
25
+ ```ruby
26
+ require 'jars/installer'
27
+ task :install_jars do
28
+ Jars::Installer.vendor_jars!
29
+ end
30
+ ```
31
+
32
+ This will install (download) the dependent jars into **JARS_HOME** and create a
33
+ file **lib/my_gem_jars.rb**, which will be an enumeration of `require_jars`
34
+ statements to load all the jars.
35
+ The **vendor_jars** task will copy them into the **lib** directory of the gem.
36
+
37
+ The location where jars are cached is per default **$HOME/.m2/repository** the
38
+ same default as Maven uses to cache downloaded jar-artifacts.
39
+ It respects **$HOME/.m2/settings.xml** from Maven with mirror and other settings
40
+ or the environment variable **JARS_HOME**.
41
+
42
+ **IMPORTANT**: Make sure that jar-dependencies is only a **development dependency**
43
+ of your gem. If it is a runtime dependency the require_jars file will be overwritten
44
+ during installation.
45
+
46
+
47
+ ## Reduce the download and reuse the jars from maven local repository
48
+
49
+ If you do not want to vendor jars into a gem then **jar-dependency** gem can vendor
50
+ them when you install the gem. In that case do not use
51
+ `Jars::Installer.install_jars` from the above rake tasks.
52
+
53
+ **NOTE**: Recent JRuby comes with **jar-dependencies** as default gem, for older
54
+ versions for the feature to work you need to gem install **jar-dependencies** first
55
+ and for bundler need to use the **bundle-with-jars** command instead.
56
+
57
+ **IMPORTANT**: Make sure that jar-dependencies is a **runtime dependency** of your
58
+ gem so the require_jars file will be overwritten during installation with the
59
+ "correct" versions of the jars.
60
+
61
+
62
+ ## For development you do not need to vendor the jars at all
63
+
64
+ Set the environment variable
65
+
66
+ ```shell
67
+ export JARS_VENDOR=false
68
+ ```
69
+
70
+ to tell the jar_installer not vendor any jars, but only create the file with the
71
+ `require_jar` statements. This `require_jars` method will find the jar inside the
72
+ maven local repository and load it from there.
73
+
74
+
75
+ ## Some drawbacks
76
+
77
+ * First you need to install the jar-dependency gem with its development dependencies installed (then ruby-maven gets installed as well)
78
+ * Bundler does not install the jar-dependencies (unless JRuby adds the gem as default gem)
79
+ * You need ruby-maven doing the job of dependency resolution and downloading them. gems not part of <http://rubygems.org> will not work currently
80
+
81
+
82
+ ## JARs other than from maven-central
83
+
84
+ By default all jars need to come from maven-central (<search.maven.org>), in order
85
+ to use jars from any other repo you need to add it into your Maven *settings.xml*
86
+ and configure it in a way that works without an interactive prompt (username +
87
+ passwords needs to be part of the settings.xml file).
88
+
89
+ **NOTE:** Gems depending on jars other then maven-central will **NOT** work when
90
+ they get published on rubygems.org since the user of those gems will not have the
91
+ right settings.xml to allow them to access the jar dependencies.
92
+
93
+
94
+ ## Examples
95
+
96
+ An [example with rspec and all](example/Readme.md) walks you through setup and
97
+ shows how development works and shows what happens during installation.
98
+
99
+ There are some more examples with the various [project setups for gems and application](examples/README.md).
100
+ This includes using proper Maven for the project or ruby-maven with rake or
101
+ the rake-compiler in conjunction with jar-dependencies.
102
+
103
+ # Lock down versions
104
+
105
+ Whenever there are version ranges for jar dependencies it is advisable to lock down the versions of dependencies.
106
+ For the jar dependencies inside the gemspec declaration this can be done with:
107
+
108
+ ```shell
109
+ lock_jars
110
+ ```
111
+
112
+ This is also working in **any** project which uses a gem with
113
+ jar-dependencies. It also uses a Jarfile if present. See the [sinatra
114
+ application from the examples](examples/sinatra-app/having-jarfile-and-gems-with-jar-dependencies/).
115
+
116
+ This means for a project using bundler and jar-dependencies the setup is
117
+
118
+ ```shell
119
+ bundle install
120
+ lock_jars
121
+ ```
122
+
123
+ This will install both gems and jars for the project.
124
+
125
+ Update a specific version is done with (use only the artifact_id)
126
+
127
+ ```shell
128
+ lock_jars --update slf4j-api
129
+ ```
130
+
131
+ And look at the dependencies tree
132
+
133
+ ```shell
134
+ lock_jars --tree
135
+ ```
136
+
137
+ As `lock_jars` uses ruby-maven to resolve the jar dependencies.
138
+ Since jar-dependencies does not declare ruby-maven as runtime dependency
139
+ (you just not need ruby-maven during runtime only when you want to
140
+ setup the project it is needed) it is advicable to have it as
141
+ development dependency in your Gemfile.
142
+
143
+ # Proxy and mirror setup
144
+
145
+ Proxies and mirrors can be set up by the usual configuration of maven itself: [settings.xml](https://maven.apache.org/settings.html) - see the mirrors and proxy sections.
146
+
147
+ As jar-dependencies does only deal with jar and all jars need to come from maven central, it is only neccessary to mirror maven-central. An example of such a [settings-example.xml](setting.xml is here).
148
+
149
+ You also can add such a settings.xml to your project which jar-dependencies will use instad of the default maven locations. This allows to have a per-project configuration and also removes the need to users of your Ruby project to dive into maven in case you have company policy to use a local mirror for gem and jar artifacts.
150
+
151
+ jar-dependencies itself uses maven **only** for the jars and all gems are managed by RubyGems or Bundler or your favourite management tool. So any proxy/mirror settings which should affect gems need to be done in those tools.
152
+
153
+ # Gradle, Maven, etc
154
+
155
+ Dependency management frameworks like gradle (via jruby-gradle-plugin) or maven (via jruby-maven-plugins) can also use gem artifacts retrieved from rubygems.org.
156
+
157
+ Each of these tools (including jar-dependencies) does the dependency
158
+ resolution slightly different and in rare cases can produce different
159
+ outcomes. But overall each tool can manage both jars and gems and
160
+ their transitive dependencies.
161
+
162
+ Popular gems like jrjackson or nokogiri do not declare their jars in
163
+ the gemspec files and just load the bundle jars into jruby
164
+ classloader, can easily create problems as the jackson and
165
+ xalan/xerces libraries used by those gems are popular ones in the Java world.
166
+
167
+ # Troubleshooting
168
+
169
+ Jar dependency resolution uses the bundled Mima resolver. To get more
170
+ insight into jar-dependencies progress and warnings, enable verbose output:
171
+
172
+ ```shell
173
+ JARS_VERBOSE=true bundle install
174
+ JARS_VERBOSE=true gem install some_gem
175
+ ```
176
+
177
+
178
+ For Ruby-side debug diagnostics, including backtraces for suppressed setup
179
+ errors and jar loading decisions, enable debug output:
180
+
181
+ ```shell
182
+ JARS_DEBUG=true bundle install
183
+ JARS_DEBUG=true gem install some_gem
184
+ ```
185
+
186
+ # Configuration
187
+
188
+ <table border='1'>
189
+ <tr>
190
+ <td>ENV</td><td>java system property</td><td>default</td><td>description</td>
191
+ </tr>
192
+ <tr>
193
+ <td><tt>JARS_DEBUG</tt></td><td>jars.debug</td><td>false</td><td>if set to true it will produce Ruby-side debug diagnostics and implies verbose output</td>
194
+ </tr>
195
+ <tr>
196
+ <td><tt>JARS_VERBOSE</tt></td><td>jars.verbose</td><td>false</td><td>if set to true it will produce some extra resolver output</td>
197
+ </tr>
198
+ <tr>
199
+ <td><tt>JARS_HOME</tt></td><td>jars.home</td><td>$HOME/.m2/repository</td><td>filesystem location where to store the jar files and some metadata</td>
200
+ </tr>
201
+ <tr>
202
+ <td><tt>JARS_MAVEN_SETTINGS</tt></td><td>jars.maven.settings</td><td>$HOME/.m2/settings.xml</td><td>setting.xml for maven to use</td>
203
+ </tr>
204
+ <tr>
205
+ <td><tt>JARS_VENDOR</tt></td><td>jars.vendor</td><td>true</td><td>set to true means that the jars will be stored in JARS_HOME only</td>
206
+ </tr>
207
+ <tr>
208
+ <td><tt>JARS_SKIP</tt></td><td>jars.skip</td><td>true</td><td>do **NOT** install jar dependencies at all</td>
209
+ </tr>
210
+ </table>
211
+
212
+ # Motivation
213
+
214
+ In 2014, while tools such as [https://github.com/arrigonialberto86/ruby-band](https://github.com/arrigonialberto86/ruby-band) used [jbundler](https://github.com/jruby/jbundler) to manage their there was no easy or formal way to
215
+ - find out which JARs were added to the JRuby classloader
216
+ - to manage JRuby projects with Maven
217
+ - to build Java/JRuby gem extensions with [rake-compiler](https://github.com/luislavena/rake-compiler/issues/87).
218
+
219
+ With JRuby 9000 it was the right time to get jar dependencies "right".
220
+
221
+ # Developing
222
+
223
+ You must have the latest ruby-maven installed in your local JRuby.
224
+
225
+ ./mvnw install will build the gem and run integration tests
data/exe/lock_jars ADDED
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'jar_dependencies'
5
+ require 'optparse'
6
+ options = {}
7
+ optparse = OptionParser.new do |opts|
8
+ opts.banner = "Usage: #{File.basename(__FILE__)} [options]"
9
+
10
+ opts.separator ''
11
+ opts.separator 'Options:'
12
+ opts.separator ''
13
+
14
+ opts.on('-v', '--verbose', 'Output more information') do |t|
15
+ options[:verbose] = t
16
+ end
17
+
18
+ opts.on('-d', '--debug', 'Output debug information') do |t|
19
+ options[:debug] = t
20
+ end
21
+
22
+ opts.on('-f', '--force', 'Force creation of Jars.lock') do |t|
23
+ options[:force] = t
24
+ end
25
+
26
+ opts.on('-t', '--tree', 'Show dependency tree') do |t|
27
+ options[:tree] = t
28
+ end
29
+
30
+ opts.on('-u', '--update JAR_COORDINATE',
31
+ 'Resolves given dependency and use latest version. ' \
32
+ 'JAR_COORDINATE is either artifact_id or group_id:artifact_id') do |u|
33
+ options[:update] = u
34
+ end
35
+
36
+ opts.on('--vendor-dir DIRECTORY', 'Vendor directory where to copy the installed jars.' \
37
+ 'add this directory to $LOAD_PATH or set JARS_HOME respectively.') do |dir|
38
+ options[:vendor_dir] = dir
39
+ end
40
+
41
+ opts.on('-h', '--help', 'Display this screen') do
42
+ puts opts
43
+ exit
44
+ end
45
+
46
+ opts.separator ''
47
+ opts.separator 'THIS IS A EXPERIMETAL FEATURE !!!'
48
+ opts.separator ''
49
+ opts.separator '* load jars "Jars.lock" from current working directory: `Jars.require_jars_lock!`'
50
+ opts.separator '* classpath features: see `Jars::Classpath'
51
+ end
52
+ optparse.parse!
53
+
54
+ Jars.lock_down(debug: options.delete(:debug), verbose: options.delete(:verbose), **options)
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ File.expand_path('lib', File.dirname(__FILE__)).tap do |lib|
4
+ $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
5
+ end
6
+
7
+ require 'jars/version'
8
+ require 'jars/mima/version'
9
+
10
+ Gem::Specification.new do |s|
11
+ s.name = 'jar-dependencies'
12
+
13
+ s.version = Jars::VERSION
14
+ s.platform = 'java'
15
+
16
+ s.author = 'christian meier'
17
+ s.email = ['mkristian@web.de']
18
+ s.summary = 'manage jar dependencies for gems'
19
+ s.homepage = 'https://github.com/jruby/jar-dependencies'
20
+
21
+ s.bindir = 'exe'
22
+ s.executables = ['lock_jars']
23
+
24
+ s.license = 'MIT'
25
+
26
+ s.files = Dir['{lib}/**/*'] + %w[Mavenfile Rakefile Readme.md jar-dependencies.gemspec MIT-LICENSE]
27
+ # explicitly require the jars
28
+ s.files += Jars::Mima::JARS.each_key.map { File.join(Jars::Mima::MIMA_DIR, _1) }
29
+
30
+ s.description = <<~TEXT
31
+ manage jar dependencies for gems and keep track which jar was already
32
+ loaded using maven artifact coordinates. it warns on version conflicts and
33
+ loads only ONE jar assuming the first one is compatible to the second one
34
+ otherwise your project needs to lock down the right version by providing a
35
+ Jars.lock file.
36
+ TEXT
37
+
38
+ s.required_ruby_version = '>= 2.6'
39
+
40
+ s.metadata['rubygems_mfa_required'] = 'true'
41
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (C) 2014 Christian Meier
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
7
+ # this software and associated documentation files (the "Software"), to deal in
8
+ # the Software without restriction, including without limitation the rights to
9
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10
+ # the Software, and to permit persons to whom the Software is furnished to do so,
11
+ # subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #
23
+
24
+ require 'jar_dependencies'