├── .envrc ├── specs ├── repository │ └── .keep ├── deps │ ├── asm-3.3.1.jar │ ├── cdi-api-1.0.jar │ ├── guava-10.0.1.jar │ ├── guice-3.0.jar │ ├── jsoup-1.7.1.jar │ ├── jsr305-1.3.9.jar │ ├── aopalliance-1.0.jar │ ├── commons-codec-1.6.jar │ ├── commons-io-2.0.1.jar │ ├── httpclient-4.2.3.jar │ ├── httpcore-4.2.3.jar │ ├── javax.inject-1.jar │ ├── jsr250-api-1.0.jar │ ├── maven-model-3.1.0.jar │ ├── netty-3.4.4.Final.jar │ ├── plexus-cipher-1.4.jar │ ├── sisu-guava-0.9.9.jar │ ├── slf4j-api-1.6.2.jar │ ├── wagon-file-2.4.jar │ ├── wagon-http-2.4.jar │ ├── aether-api-0.9.0.M2.jar │ ├── aether-impl-0.9.0.M2.jar │ ├── aether-spi-0.9.0.M2.jar │ ├── aether-util-0.9.0.M2.jar │ ├── async-http-client-1.7.6.jar │ ├── commons-logging-1.1.1.jar │ ├── maven-settings-3.1.0.jar │ ├── plexus-classworlds-2.4.jar │ ├── plexus-utils-3.0.10.jar │ ├── sisu-guice-3.1.0-no_aop.jar │ ├── wagon-http-shared4-2.4.jar │ ├── wagon-provider-api-1.0.jar │ ├── jboss-interceptor-api-1.1.jar │ ├── maven-aether-provider-3.1.0.jar │ ├── maven-model-builder-3.1.0.jar │ ├── maven-settings-builder-3.1.0.jar │ ├── plexus-interpolation-1.16.jar │ ├── plexus-sec-dispatcher-1.3.jar │ ├── aether-connector-file-0.9.0.M2.jar │ ├── aether-connector-wagon-0.9.0.M2.jar │ ├── maven-repository-metadata-3.1.0.jar │ ├── org.eclipse.sisu.inject-0.0.0.M2a.jar │ ├── org.eclipse.sisu.plexus-0.0.0.M2a.jar │ ├── plexus-component-annotations-1.5.5.jar │ └── aether-connector-asynchttpclient-0.9.0.M2.jar ├── Jars_no_jline.lock ├── example │ ├── gem_with_require_relative │ │ ├── version.rb │ │ └── gem_with_require_relative.gemspec │ └── example │ │ └── 1 │ │ └── example-1.jar ├── settings.xml ├── conf │ └── settings.xml ├── jars │ └── more │ │ └── sample │ │ └── 2 │ │ └── sample-2.jar ├── path │ └── more │ │ └── sample │ │ └── 4 │ │ └── sample-4.jar ├── vendor │ └── jars │ │ └── more │ │ └── sample │ │ └── 3 │ │ └── sample-3.jar ├── repo │ └── org │ │ └── slf4j │ │ └── slf4j-simple │ │ ├── 1.6.4 │ │ └── slf4j-simple-1.6.4.jar │ │ └── 1.6.6 │ │ └── slf4j-simple-1.6.6.jar ├── load_path │ └── org │ │ └── slf4j │ │ └── slf4j-simple │ │ └── 1.6.4 │ │ └── slf4j-simple-1.6.4.jar ├── Jars.lock ├── setup.rb ├── maven_exec_spec.rb ├── maven_factory_spec.rb ├── jar_installer_spec.rb └── deps.txt ├── integration ├── vendor_jars │ ├── lib │ │ └── .empty │ ├── test.rb │ ├── Gemfile │ ├── setup.bsh │ ├── Mavenfile │ ├── verify.bsh │ └── my.gemspec ├── bundle_with_path │ ├── invoker.properties │ ├── Gemfile │ ├── pom.xml │ ├── bundle.rb │ ├── mygem.gemspec │ ├── verify.bsh │ └── Mavenfile ├── bundle_with_path_to_gemspec │ ├── invoker.properties │ ├── Gemfile │ ├── pom.xml │ ├── mygem.gemspec │ └── Mavenfile ├── bundle_with_two_gemspecs │ ├── invoker.properties │ ├── lib │ │ ├── another_gemspec │ │ │ └── version.rb │ │ ├── wat_two_gemspecs │ │ │ └── version.rb │ │ └── wat_two_gemspecs.rb │ ├── Gemfile │ ├── pom.xml │ ├── Mavenfile │ ├── another_gemspec.gemspec │ └── wat_two_gemspecs.gemspec ├── nested_jars_lock_from_classloader │ ├── src │ │ └── main │ │ │ └── resources │ │ │ └── Jars.lock │ ├── jline │ │ └── jline │ │ │ └── 2.11 │ │ │ └── jline-2.11.jar │ ├── org │ │ └── example │ │ │ └── nested │ │ │ └── 1.0 │ │ │ └── nested-1.0.jar │ ├── test.rb │ └── Mavenfile ├── install_ruby_maven_when_needed │ ├── gem │ │ ├── lib │ │ │ ├── my.rb │ │ │ └── my_jars.rb │ │ ├── Mavenfile │ │ └── my.gemspec │ ├── verify │ │ ├── Gemfile │ │ ├── test_bundler.rb │ │ ├── test_gem.rb │ │ └── Mavenfile │ ├── Mavenfile │ ├── pom.xml │ └── verify.bsh ├── jars_lock_gemfile │ ├── Jarfile │ ├── Gemfile │ ├── setup.bsh │ ├── pom.xml │ ├── Jars.lock.old │ ├── test.rb │ ├── verify.bsh │ └── Mavenfile ├── lock_jars │ ├── Jarfile │ ├── Jars.lock │ ├── Gemfile │ ├── setup.bsh │ ├── verify.bsh │ └── Mavenfile ├── gemspec_with_system_jar │ ├── gem │ │ ├── lib │ │ │ └── first.rb │ │ ├── Mavenfile │ │ └── with-system-jar.gemspec │ ├── pom.xml │ ├── Mavenfile │ └── verify │ │ ├── test.rb │ │ └── Mavenfile ├── jars_lock_gemspec_with_jars │ ├── setup.bsh │ ├── pom.xml │ ├── test.rb │ ├── first.gemspec │ ├── verify.bsh │ └── Mavenfile ├── gemspec_with_classifier_and_exclusions │ ├── Gemfile │ ├── setup.bsh │ ├── verify.bsh │ ├── mygem.gemspec │ └── Mavenfile ├── require_tests │ ├── jline │ │ └── jline │ │ │ └── 2.11 │ │ │ └── jline-2.11.jar │ ├── test_freeze_loading.rb │ ├── test_no_more_warnings.rb │ └── Mavenfile └── depending_gems │ ├── biglib │ ├── Gemfile │ ├── biglib.gemspec │ └── Mavenfile │ ├── simplelib │ ├── Mavenfile │ └── simplelib.gemspec │ ├── pom.xml │ └── Mavenfile ├── example ├── .gitignore ├── Gemfile ├── lib │ ├── example.rb │ └── example │ │ └── bc_info.rb ├── spec │ ├── spec_helper.rb │ ├── first_spec.rb │ └── second_spec.rb ├── src │ └── main │ │ └── java │ │ └── App.java ├── Rakefile ├── settings.xml.example ├── example.gemspec └── Readme.md ├── examples ├── gem-with-java-extension │ ├── using-rake-compiler │ │ ├── .gitignore │ │ ├── ext │ │ │ └── App.java │ │ ├── lib │ │ │ └── mygem.rb │ │ ├── test.rb │ │ ├── README.md │ │ ├── Rakefile │ │ └── mygem.gemspec │ ├── using-maven │ │ ├── src │ │ │ └── main │ │ │ │ └── java │ │ │ │ └── App.java │ │ ├── lib │ │ │ └── mygem.rb │ │ ├── test.rb │ │ ├── .mvn │ │ │ └── extensions.xml │ │ ├── README.md │ │ └── mygem.gemspec │ └── using-ruby-maven │ │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── App.java │ │ ├── lib │ │ └── mygem.rb │ │ ├── test.rb │ │ ├── Rakefile │ │ ├── README.md │ │ └── mygem.gemspec ├── gem-with-java-extension-and-jar-dependencies │ ├── using-rake-compiler │ │ ├── .gitignore │ │ ├── Gemfile │ │ ├── ext │ │ │ └── App.java │ │ ├── lib │ │ │ └── mygem.rb │ │ ├── test.rb │ │ ├── Rakefile │ │ ├── README.md │ │ └── mygem.gemspec │ ├── using-maven │ │ ├── Gemfile │ │ ├── src │ │ │ └── main │ │ │ │ └── java │ │ │ │ └── App.java │ │ ├── lib │ │ │ └── mygem.rb │ │ ├── .mvn │ │ │ └── extensions.xml │ │ ├── test.rb │ │ ├── README.md │ │ └── mygem.gemspec │ └── using-ruby-maven │ │ ├── Gemfile │ │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── App.java │ │ ├── lib │ │ └── mygem.rb │ │ ├── test.rb │ │ ├── Rakefile │ │ ├── README.md │ │ └── mygem.gemspec ├── gem-with-jar-dependencies │ ├── Gemfile │ ├── lib │ │ └── mygem.rb │ ├── test.rb │ ├── mygem.gemspec │ └── README.md ├── gem-with-jar-dependencies-and-bundler │ ├── Gemfile │ ├── lib │ │ └── mygem.rb │ ├── test.rb │ ├── mygem.gemspec │ └── README.md ├── sinatra-app │ ├── having-jarfile-and-gems-with-jar-dependencies │ │ ├── Jarfile │ │ ├── config.ru │ │ ├── Gemfile │ │ ├── README.md │ │ ├── Gemfile.lock │ │ ├── app │ │ │ ├── views │ │ │ │ └── person.erb │ │ │ └── hellowarld.rb │ │ └── Jars.lock │ └── having-gems-with-jar-dependencies │ │ ├── config.ru │ │ ├── Gemfile │ │ ├── README.md │ │ ├── Gemfile.lock │ │ ├── app │ │ ├── views │ │ │ └── person.erb │ │ └── hellowarld.rb │ │ └── Jars.lock └── README.md ├── .mvn ├── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties └── extensions.xml ├── .gitignore ├── .pre-commit-config.yaml ├── exe ├── vendor_jars └── lock_jars ├── lib ├── jars │ ├── version.rb │ ├── setup.rb │ ├── gemspec_pom.rb │ ├── output_jars_pom.rb │ ├── settings.xml │ ├── attach_jars_pom.rb │ ├── lock_down_pom.rb │ ├── post_install_hook.rb │ ├── lock.rb │ ├── classpath.rb │ ├── maven_exec.rb │ ├── lock_down.rb │ ├── maven_factory.rb │ ├── maven_settings.rb │ ├── gemspec_artifacts.rb │ └── installer.rb ├── rubygems_plugin.rb ├── jar-dependencies.rb └── jar_install_post_install_hook.rb ├── Gemfile ├── Rakefile ├── .github └── workflows │ └── main.yml ├── .rubocop.yml ├── bin ├── rake └── rubocop ├── MIT-LICENSE ├── jar-dependencies.gemspec ├── settings-example.xml ├── Mavenfile ├── mvnw.cmd └── mvnw /.envrc: -------------------------------------------------------------------------------- 1 | PATH_add bin 2 | -------------------------------------------------------------------------------- /specs/repository/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/asm-3.3.1.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/cdi-api-1.0.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/guava-10.0.1.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/guice-3.0.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/jsoup-1.7.1.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/jsr305-1.3.9.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/aopalliance-1.0.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/commons-codec-1.6.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/commons-io-2.0.1.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/httpclient-4.2.3.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/httpcore-4.2.3.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/javax.inject-1.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/jsr250-api-1.0.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/maven-model-3.1.0.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/netty-3.4.4.Final.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/plexus-cipher-1.4.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/sisu-guava-0.9.9.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/slf4j-api-1.6.2.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/wagon-file-2.4.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/wagon-http-2.4.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /integration/vendor_jars/lib/.empty: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/aether-api-0.9.0.M2.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/aether-impl-0.9.0.M2.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/aether-spi-0.9.0.M2.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/aether-util-0.9.0.M2.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/async-http-client-1.7.6.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/commons-logging-1.1.1.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/maven-settings-3.1.0.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/plexus-classworlds-2.4.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/plexus-utils-3.0.10.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/sisu-guice-3.1.0-no_aop.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/wagon-http-shared4-2.4.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/wagon-provider-api-1.0.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/jboss-interceptor-api-1.1.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/maven-aether-provider-3.1.0.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/maven-model-builder-3.1.0.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/maven-settings-builder-3.1.0.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/plexus-interpolation-1.16.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/plexus-sec-dispatcher-1.3.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/aether-connector-file-0.9.0.M2.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/aether-connector-wagon-0.9.0.M2.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/maven-repository-metadata-3.1.0.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/org.eclipse.sisu.inject-0.0.0.M2a.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/org.eclipse.sisu.plexus-0.0.0.M2a.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/deps/plexus-component-annotations-1.5.5.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /specs/Jars_no_jline.lock: -------------------------------------------------------------------------------- 1 | example:example:2.1:provided: 2 | -------------------------------------------------------------------------------- /specs/deps/aether-connector-asynchttpclient-0.9.0.M2.jar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /integration/bundle_with_path/invoker.properties: -------------------------------------------------------------------------------- 1 | goal=compile 2 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | *.jar 2 | *_jars.rb 3 | *.lock 4 | pkg 5 | tmp 6 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension/using-rake-compiler/.gitignore: -------------------------------------------------------------------------------- 1 | tmp 2 | *jar 3 | -------------------------------------------------------------------------------- /integration/bundle_with_path_to_gemspec/invoker.properties: -------------------------------------------------------------------------------- 1 | invoker.goals = gem:exec -------------------------------------------------------------------------------- /integration/bundle_with_two_gemspecs/invoker.properties: -------------------------------------------------------------------------------- 1 | invoker.goals = gem:exec -------------------------------------------------------------------------------- /specs/example/gem_with_require_relative/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | -------------------------------------------------------------------------------- /specs/settings.xml: -------------------------------------------------------------------------------- 1 | 2 | specs 3 | 4 | -------------------------------------------------------------------------------- /integration/nested_jars_lock_from_classloader/src/main/resources/Jars.lock: -------------------------------------------------------------------------------- 1 | org.example:nested:1.0:compile: -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jruby/jar-dependencies/HEAD/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /integration/install_ruby_maven_when_needed/gem/lib/my.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'my_jars' 4 | -------------------------------------------------------------------------------- /integration/jars_lock_gemfile/Jarfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | jar 'org.slf4j:slf4j-simple:1.7.7' 4 | -------------------------------------------------------------------------------- /integration/lock_jars/Jarfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | jar 'org.bouncycastle:bcpkix-jdk15on:1.54' 4 | -------------------------------------------------------------------------------- /specs/conf/settings.xml: -------------------------------------------------------------------------------- 1 | 2 | ${repo.path}/repository 3 | 4 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension-and-jar-dependencies/using-rake-compiler/.gitignore: -------------------------------------------------------------------------------- 1 | tmp 2 | *jar 3 | *_jars.rb 4 | *lock 5 | -------------------------------------------------------------------------------- /integration/bundle_with_path/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source 'https://rubygems.org' 4 | 5 | gemspec 6 | -------------------------------------------------------------------------------- /integration/gemspec_with_system_jar/gem/lib/first.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'with-system-jar_jars' 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | pkg 2 | .ruby-version 3 | *.gem 4 | target 5 | build.log 6 | pom* 7 | specs/repository/* 8 | example/dependencies.list 9 | -------------------------------------------------------------------------------- /examples/gem-with-jar-dependencies/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source 'https://rubygems.org' 4 | 5 | gemspec 6 | -------------------------------------------------------------------------------- /integration/jars_lock_gemspec_with_jars/setup.bsh: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | 3 | new File(basedir, "Jars.lock").delete(); 4 | true; 5 | -------------------------------------------------------------------------------- /integration/lock_jars/Jars.lock: -------------------------------------------------------------------------------- 1 | org.bouncycastle:bcpkix-jdk15on:1.54:compile: 2 | org.bouncycastle:bcprov-jdk15on:1.54:compile: 3 | -------------------------------------------------------------------------------- /integration/vendor_jars/test.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'jars/installer' 4 | Jars::Installer.vendor_jars! 5 | -------------------------------------------------------------------------------- /specs/example/example/1/example-1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jruby/jar-dependencies/HEAD/specs/example/example/1/example-1.jar -------------------------------------------------------------------------------- /specs/jars/more/sample/2/sample-2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jruby/jar-dependencies/HEAD/specs/jars/more/sample/2/sample-2.jar -------------------------------------------------------------------------------- /specs/path/more/sample/4/sample-4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jruby/jar-dependencies/HEAD/specs/path/more/sample/4/sample-4.jar -------------------------------------------------------------------------------- /integration/gemspec_with_classifier_and_exclusions/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source 'https://rubygems.org' 4 | gemspec 5 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/mattlqx/pre-commit-ruby 3 | rev: v1.3.5 4 | hooks: 5 | - id: rubocop 6 | 7 | -------------------------------------------------------------------------------- /examples/gem-with-jar-dependencies-and-bundler/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source 'https://rubygems.org' 4 | 5 | gemspec 6 | -------------------------------------------------------------------------------- /exe/vendor_jars: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | require 'jars/installer' 5 | 6 | Jars::Installer.vendor_jars! 7 | -------------------------------------------------------------------------------- /integration/gemspec_with_classifier_and_exclusions/setup.bsh: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | 3 | new File(basedir, "Jars.lock").delete() || true; 4 | 5 | -------------------------------------------------------------------------------- /integration/jars_lock_gemfile/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source 'https://rubygems.org' 4 | 5 | gem 'leafy-metrics', '0.6.1' 6 | -------------------------------------------------------------------------------- /specs/vendor/jars/more/sample/3/sample-3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jruby/jar-dependencies/HEAD/specs/vendor/jars/more/sample/3/sample-3.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip 2 | -------------------------------------------------------------------------------- /examples/sinatra-app/having-jarfile-and-gems-with-jar-dependencies/Jarfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | jar 'org.slf4j:slf4j-simple', '1.7.12' 4 | -------------------------------------------------------------------------------- /integration/jars_lock_gemfile/setup.bsh: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | 3 | new File(basedir, "Jars.lock.old").renameTo(new File(basedir, "Jars.lock")); 4 | true; 5 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension-and-jar-dependencies/using-maven/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source 'https://rubygems.org' 4 | 5 | gemspec 6 | -------------------------------------------------------------------------------- /integration/install_ruby_maven_when_needed/verify/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source 'https://rubygems.org' 4 | 5 | gemspec path: '../gem' 6 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension-and-jar-dependencies/using-ruby-maven/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source 'https://rubygems.org' 4 | 5 | gemspec 6 | -------------------------------------------------------------------------------- /integration/bundle_with_two_gemspecs/lib/another_gemspec/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module AnotherGemspec 4 | VERSION = '0.0.1' 5 | end 6 | -------------------------------------------------------------------------------- /integration/bundle_with_two_gemspecs/lib/wat_two_gemspecs/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module WatTwoGemspecs 4 | VERSION = '0.0.1' 5 | end 6 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension-and-jar-dependencies/using-rake-compiler/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source 'https://rubygems.org' 4 | 5 | gemspec 6 | -------------------------------------------------------------------------------- /integration/require_tests/jline/jline/2.11/jline-2.11.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jruby/jar-dependencies/HEAD/integration/require_tests/jline/jline/2.11/jline-2.11.jar -------------------------------------------------------------------------------- /integration/depending_gems/biglib/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source 'https://rubygems.org' 4 | 5 | gem 'simplelib', path: '../simplelib' 6 | 7 | gemspec 8 | -------------------------------------------------------------------------------- /specs/repo/org/slf4j/slf4j-simple/1.6.4/slf4j-simple-1.6.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jruby/jar-dependencies/HEAD/specs/repo/org/slf4j/slf4j-simple/1.6.4/slf4j-simple-1.6.4.jar -------------------------------------------------------------------------------- /specs/repo/org/slf4j/slf4j-simple/1.6.6/slf4j-simple-1.6.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jruby/jar-dependencies/HEAD/specs/repo/org/slf4j/slf4j-simple/1.6.6/slf4j-simple-1.6.6.jar -------------------------------------------------------------------------------- /examples/gem-with-java-extension/using-rake-compiler/ext/App.java: -------------------------------------------------------------------------------- 1 | class App 2 | { 3 | public static String hello(String name) 4 | { 5 | return "hello " + name; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /integration/bundle_with_path_to_gemspec/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source 'https://rubygems.org' 4 | 5 | gem 'foo', path: File.dirname(__FILE__), require: false 6 | -------------------------------------------------------------------------------- /lib/jars/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module Jars 4 | VERSION = '0.5.5' 5 | JRUBY_PLUGINS_VERSION = '3.0.2' 6 | DEPENDENCY_PLUGIN_VERSION = '2.8' 7 | end 8 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension/using-maven/src/main/java/App.java: -------------------------------------------------------------------------------- 1 | class App 2 | { 3 | public static String hello(String name) 4 | { 5 | return "hello " + name; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /integration/depending_gems/simplelib/Mavenfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | properties('gem.home' => '${basedir}/../pkg', 4 | 'gem.path' => '${gem.home}') 5 | gemspec 6 | -------------------------------------------------------------------------------- /integration/lock_jars/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source 'https://rubygems.org' 4 | 5 | # needed otherwise the integration test find the one from the parent directory 6 | -------------------------------------------------------------------------------- /integration/vendor_jars/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source 'https://rubygems.org' 4 | 5 | # needed otherwise the integration test find the one from the parent directory 6 | -------------------------------------------------------------------------------- /specs/load_path/org/slf4j/slf4j-simple/1.6.4/slf4j-simple-1.6.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jruby/jar-dependencies/HEAD/specs/load_path/org/slf4j/slf4j-simple/1.6.4/slf4j-simple-1.6.4.jar -------------------------------------------------------------------------------- /examples/gem-with-java-extension/using-ruby-maven/src/main/java/App.java: -------------------------------------------------------------------------------- 1 | class App 2 | { 3 | public static String hello(String name) 4 | { 5 | return "hello " + name; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /integration/bundle_with_two_gemspecs/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source 'https://rubygems.org' 4 | 5 | gemspec name: 'wat_two_gemspecs' 6 | gemspec name: 'another_gemspec' 7 | -------------------------------------------------------------------------------- /integration/install_ruby_maven_when_needed/Mavenfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | id 'jar-dependencies:install-ruby-maven:0' 4 | 5 | packaging 'pom' 6 | 7 | modules %w[gem verify] 8 | -------------------------------------------------------------------------------- /integration/bundle_with_two_gemspecs/lib/wat_two_gemspecs.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'wat_two_gemspecs/version' 4 | 5 | module WatTwoGemspecs 6 | # Your code goes here... 7 | end 8 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension-and-jar-dependencies/using-maven/src/main/java/App.java: -------------------------------------------------------------------------------- 1 | class App 2 | { 3 | public static String hello(String name) 4 | { 5 | return "hello " + name; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension-and-jar-dependencies/using-rake-compiler/ext/App.java: -------------------------------------------------------------------------------- 1 | class App 2 | { 3 | public static String hello(String name) 4 | { 5 | return "hello " + name; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /integration/nested_jars_lock_from_classloader/jline/jline/2.11/jline-2.11.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jruby/jar-dependencies/HEAD/integration/nested_jars_lock_from_classloader/jline/jline/2.11/jline-2.11.jar -------------------------------------------------------------------------------- /examples/gem-with-java-extension-and-jar-dependencies/using-ruby-maven/src/main/java/App.java: -------------------------------------------------------------------------------- 1 | class App 2 | { 3 | public static String hello(String name) 4 | { 5 | return "hello " + name; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /examples/gem-with-jar-dependencies/lib/mygem.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # can be hardcoded here but for copy the example around that is easier 4 | require Dir["#{File.dirname(__FILE__)}/*_jars.rb"].first 5 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension/using-maven/lib/mygem.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # can be hardcoded here but for copy the example around that is easier 4 | require Dir["#{File.dirname(__FILE__)}/*jar"].first 5 | -------------------------------------------------------------------------------- /integration/nested_jars_lock_from_classloader/org/example/nested/1.0/nested-1.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jruby/jar-dependencies/HEAD/integration/nested_jars_lock_from_classloader/org/example/nested/1.0/nested-1.0.jar -------------------------------------------------------------------------------- /examples/gem-with-java-extension/using-ruby-maven/lib/mygem.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # can be hardcoded here but for copy the example around that is easier 4 | require Dir["#{File.dirname(__FILE__)}/*jar"].first 5 | -------------------------------------------------------------------------------- /integration/bundle_with_path/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | jar-dependencies.its 4 | bundle_with_path 5 | 0.0.0 6 | 7 | -------------------------------------------------------------------------------- /integration/depending_gems/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | jar-dependencies.its 4 | depending_gems 5 | 0.0.0 6 | 7 | -------------------------------------------------------------------------------- /examples/gem-with-jar-dependencies-and-bundler/lib/mygem.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # can be hardcoded here but for copy the example around that is easier 4 | require Dir["#{File.dirname(__FILE__)}/*_jars.rb"].first 5 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension/using-maven/test.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # setup env 4 | $LOAD_PATH << 'lib' 5 | 6 | # load our gem 7 | require 'mygem' 8 | 9 | # use it 10 | puts Java::App.hello('world') 11 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension/using-rake-compiler/lib/mygem.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # can be hardcoded here but for copy the example around that is easier 4 | require Dir["#{File.dirname(__FILE__)}/*jar"].first 5 | -------------------------------------------------------------------------------- /integration/jars_lock_gemfile/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | jar-dependencies.its 4 | jars_lock_gemfile 5 | 0.0.0 6 | 7 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension/using-ruby-maven/test.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # setup env 4 | $LOAD_PATH << 'lib' 5 | 6 | # load our gem 7 | require 'mygem' 8 | 9 | # use it 10 | puts Java::App.hello('world') 11 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension/using-rake-compiler/test.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # setup env 4 | $LOAD_PATH << 'lib' 5 | 6 | # load our gem 7 | require 'mygem' 8 | 9 | # use it 10 | puts Java::App.hello('world') 11 | -------------------------------------------------------------------------------- /integration/gemspec_with_system_jar/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | jar-dependencies.its 4 | gemspec_with_system_jar 5 | 0.0.0 6 | 7 | -------------------------------------------------------------------------------- /integration/bundle_with_two_gemspecs/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | jar-dependencies.its 4 | bundle_with_two_gemspecs 5 | 0.0.0 6 | 7 | -------------------------------------------------------------------------------- /integration/jars_lock_gemfile/Jars.lock.old: -------------------------------------------------------------------------------- 1 | io.dropwizard.metrics:metrics-core:3.1.0:compile: 2 | io.dropwizard.metrics:metrics-graphite:3.1.0:compile: 3 | io.dropwizard.metrics:metrics-jvm:3.1.0:compile: 4 | org.slf4j:slf4j-simple:1.7.7:compile: 5 | -------------------------------------------------------------------------------- /integration/bundle_with_path_to_gemspec/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | jar-dependencies.its 4 | bundle_with_path_to_gemspec 5 | 0.0.0 6 | 7 | -------------------------------------------------------------------------------- /integration/jars_lock_gemspec_with_jars/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | jar-dependencies.its 4 | jars_lock_gemspec_with_jars 5 | 0.0.0 6 | 7 | -------------------------------------------------------------------------------- /.mvn/extensions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | io.takari.polyglot 5 | polyglot-ruby 6 | 0.7.2 7 | 8 | 9 | -------------------------------------------------------------------------------- /integration/install_ruby_maven_when_needed/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | jar-dependencies.its 4 | install_ruby_maven_when_needed 5 | 0.0.0 6 | 7 | -------------------------------------------------------------------------------- /example/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # bundle install will download and install the jar dependencies 4 | # as well create the lib/example_jars.rb which loads the jars at 5 | # runtime 6 | 7 | source 'https://rubygems.org' 8 | 9 | gemspec 10 | -------------------------------------------------------------------------------- /examples/sinatra-app/having-gems-with-jar-dependencies/config.ru: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | $LOAD_PATH.unshift(__dir__) 4 | 5 | require 'bundler/setup' 6 | 7 | require 'app/hellowarld' 8 | 9 | map '/' do 10 | run Sinatra::Application 11 | end 12 | -------------------------------------------------------------------------------- /integration/jars_lock_gemfile/test.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | unless defined? Jars 4 | # trigger to require of Jars.lock 5 | require 'leafy-metrics' 6 | end 7 | 8 | raise "wrong number of entries in classpath #{$CLASSPATH}" if $CLASSPATH.size != 5 9 | -------------------------------------------------------------------------------- /example/lib/example.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # this require will load ALL dependent jars or the jars from Jars.lock if 4 | # the lock file exeists 5 | require 'example_jars' 6 | 7 | # this is the jar compiled from src/main/java/** 8 | require 'example.jar' 9 | -------------------------------------------------------------------------------- /examples/sinatra-app/having-jarfile-and-gems-with-jar-dependencies/config.ru: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | $LOAD_PATH.unshift(__dir__) 4 | 5 | require 'bundler/setup' 6 | 7 | require 'app/hellowarld' 8 | 9 | map '/' do 10 | run Sinatra::Application 11 | end 12 | -------------------------------------------------------------------------------- /specs/example/gem_with_require_relative/gem_with_require_relative.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative 'version' 4 | 5 | Gem::Specification.new do |spec| 6 | spec.required_ruby_version = '>= 2.6' 7 | spec.metadata['rubygems_mfa_required'] = 'true' 8 | end 9 | -------------------------------------------------------------------------------- /lib/jars/setup.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # to do as bundler does and allow to load Jars.lock via 4 | # require 'jars/setup'. can be useful via commandline -rjars/setup 5 | # or tell bundler autorequire to load it 6 | 7 | require 'jar_dependencies' 8 | 9 | Jars.setup 10 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension/using-maven/.mvn/extensions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | io.takari.polyglot 5 | polyglot-ruby 6 | 0.1.13 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # load all jars including with scope test 4 | require 'jars/classpath' 5 | Jars::Classpath.require(:test) 6 | 7 | p $CLASSPATH 8 | 9 | require 'rspec' 10 | 11 | RSpec.configure do |config| 12 | config.order = 'random' 13 | end 14 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension-and-jar-dependencies/using-maven/lib/mygem.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # can be hardcoded here but for copy the example around that is easier 4 | require Dir["#{File.dirname(__FILE__)}/*_jars.rb"].first 5 | require Dir["#{File.dirname(__FILE__)}/*jar"].first 6 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension-and-jar-dependencies/using-rake-compiler/lib/mygem.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # can be hardcoded here but for copy the example around that is easier 4 | require Dir["#{File.dirname(__FILE__)}/*_jars.rb"].first 5 | require Dir["#{File.dirname(__FILE__)}/*jar"].first 6 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension-and-jar-dependencies/using-ruby-maven/lib/mygem.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # can be hardcoded here but for copy the example around that is easier 4 | require Dir["#{File.dirname(__FILE__)}/*_jars.rb"].first 5 | require Dir["#{File.dirname(__FILE__)}/*jar"].first 6 | -------------------------------------------------------------------------------- /example/lib/example/bc_info.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # loads all dependent jars and exmaple.jar 4 | require 'example' 5 | 6 | java_import org.bouncycastle.jce.provider.BouncyCastleProvider 7 | 8 | module Example 9 | def self.bc_info 10 | BouncyCastleProvider.new.info 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension-and-jar-dependencies/using-maven/.mvn/extensions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | io.takari.polyglot 5 | polyglot-ruby 6 | 0.1.13 7 | 8 | 9 | -------------------------------------------------------------------------------- /examples/sinatra-app/having-gems-with-jar-dependencies/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source 'https://rubygems.org' 4 | 5 | gem 'leafy-complete', '0.6.2' 6 | 7 | gem 'sinatra', '~> 1.4' 8 | 9 | group :development do 10 | gem 'jar-dependencies', '0.3.0' 11 | gem 'ruby-maven', '~> 3.9', '>= 3.9.3' 12 | end 13 | -------------------------------------------------------------------------------- /integration/install_ruby_maven_when_needed/gem/lib/my_jars.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # this is a generated file, to avoid over-writing it just delete this comment 4 | require 'jar_dependencies' 5 | 6 | require_jar('org.bouncycastle', 'bcpkix-jdk15on', '1.49') 7 | require_jar('org.bouncycastle', 'bcprov-jdk15on', '1.49') 8 | -------------------------------------------------------------------------------- /example/spec/first_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative 'spec_helper' 4 | 5 | require 'example/bc_info' 6 | 7 | describe 'example using a class from the dependent jars' do 8 | it 'should load bouncy castle' do 9 | expect(Example.bc_info).to eq 'BouncyCastle Security Provider v1.49' 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /examples/sinatra-app/having-jarfile-and-gems-with-jar-dependencies/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source 'https://rubygems.org' 4 | 5 | gem 'leafy-complete', '0.6.2' 6 | 7 | gem 'sinatra', '~> 1.4' 8 | 9 | group :development do 10 | gem 'jar-dependencies', '0.3.0' 11 | gem 'ruby-maven', '~> 3.9', '>= 3.9.3' 12 | end 13 | -------------------------------------------------------------------------------- /lib/jars/gemspec_pom.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # this file is maven DSL and used by maven via jars/maven_exec.rb 4 | 5 | def eval_file(file) 6 | file = File.join(__dir__, file) 7 | eval(File.read(file), nil, file) # rubocop:disable Security/Eval 8 | end 9 | 10 | eval_file('attach_jars_pom.rb') 11 | eval_file('output_jars_pom.rb') 12 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension/using-rake-compiler/README.md: -------------------------------------------------------------------------------- 1 | # using rake and ruby-maven gem 2 | 3 | ## build compile and create jar 4 | 5 | ``` 6 | rake compile 7 | ``` 8 | 9 | ## pack gem 10 | 11 | ``` 12 | rake package 13 | ``` 14 | 15 | ## just run the code 16 | 17 | make sure you use jruby (via rbenv, rvm, etc) 18 | ``` 19 | jruby test.rb 20 | ``` -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source 'https://rubygems.org' 4 | 5 | gemspec 6 | 7 | group :development do 8 | gem 'rake', require: false 9 | gem 'ruby-debug', '~> 0.11', require: false 10 | 11 | gem 'rubocop', '~> 1.50.0', require: false 12 | gem 'rubocop-performance', require: false 13 | gem 'rubocop-rake', require: false 14 | end 15 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | task default: [:specs] 4 | 5 | require 'bundler/gem_tasks' 6 | require 'rubocop/rake_task' 7 | 8 | RuboCop::RakeTask.new 9 | 10 | desc 'run specs' 11 | task :specs do 12 | $LOAD_PATH << 'specs' 13 | 14 | Dir['specs/*_spec.rb'].each do |f| 15 | require File.basename(f.sub(/.rb$/, '')) 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /specs/Jars.lock: -------------------------------------------------------------------------------- 1 | org.apache.maven:maven-repository-metadata:3.1.0:compile: 2 | com.google.code.findbugs:jsr305:1.3.9:provided: 3 | org.apache.httpcomponents:httpclient:4.2.3:provided: 4 | org.sonatype.sisu:sisu-guice:no_aop:3.1.0:compile: 5 | jdk:tools:1.7:system:${java.home}/../lib/tools.jar 6 | org.slf4j:slf4j-api:1.6.2:test: 7 | org.sonatype.plexus:plexus-cipher:1.4:runtime: 8 | -------------------------------------------------------------------------------- /integration/install_ruby_maven_when_needed/verify.bsh: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import org.codehaus.plexus.util.FileUtils; 3 | 4 | String log = FileUtils.fileRead( new File( basedir, "build.log" ) ); 5 | String expected = "my-1.1.1-java/deps.lst"; 6 | if ( !log.contains( expected ) ) 7 | { 8 | throw new RuntimeException( "log file does not contain '" + expected + "'" ); 9 | } 10 | -------------------------------------------------------------------------------- /integration/bundle_with_path/bundle.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative '../../lib/jars/version' 4 | 5 | # force to use prereleased gem 6 | gem 'jar-dependencies', Jars::VERSION 7 | require 'jar-dependencies' 8 | 9 | require 'bundler/friendly_errors' 10 | Bundler.with_friendly_errors do 11 | require 'bundler/cli' 12 | Bundler::CLI.start(ARGV, debug: true) 13 | end 14 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension-and-jar-dependencies/using-maven/test.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # setup env 4 | $LOAD_PATH << 'lib' 5 | 6 | # load our gem and its jars 7 | require 'mygem' 8 | 9 | # load test jar 10 | require_jar 'org.slf4j', 'slf4j-simple', '1.7.7' 11 | 12 | # use it 13 | logger = org.slf4j.LoggerFactory.get_logger('root') 14 | logger.info(Java::App.hello('world')) 15 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension-and-jar-dependencies/using-ruby-maven/test.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # setup env 4 | $LOAD_PATH << 'lib' 5 | 6 | # load our gem and its jars 7 | require 'mygem' 8 | 9 | # load test jar 10 | require_jar 'org.slf4j', 'slf4j-simple', '1.7.7' 11 | 12 | # use it 13 | logger = org.slf4j.LoggerFactory.get_logger('root') 14 | logger.info(Java::App.hello('world')) 15 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension-and-jar-dependencies/using-rake-compiler/test.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # setup env 4 | $LOAD_PATH << 'lib' 5 | 6 | # load our gem and its jars 7 | require 'mygem' 8 | 9 | # load test jar 10 | require_jar 'org.slf4j', 'slf4j-simple', '1.7.7' 11 | 12 | # use it 13 | logger = org.slf4j.LoggerFactory.get_logger('root') 14 | logger.info(Java::App.hello('world')) 15 | -------------------------------------------------------------------------------- /integration/bundle_with_path_to_gemspec/mygem.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Gem::Specification.new do |s| 4 | s.name = 'foo' 5 | version = '0.0.1' 6 | mdata = version.match(/(\d+\.\d+\.\d+)/) 7 | s.version = mdata ? mdata[1] : version 8 | s.authors = ['foo'] 9 | s.summary = 'foo' 10 | s.required_ruby_version = '>= 2.6' 11 | s.metadata['rubygems_mfa_required'] = 'true' 12 | end 13 | -------------------------------------------------------------------------------- /specs/setup.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # single spec setup 4 | $LOAD_PATH.unshift File.join(File.dirname(File.expand_path(__FILE__)), '../lib') 5 | 6 | ENV['JARS_HOME'] = nil 7 | require 'jar_dependencies' 8 | 9 | p ENV['JARS_LOCAL_MAVEN_REPO'] = Jars.home 10 | Jars.reset 11 | 12 | begin 13 | require 'minitest' 14 | rescue LoadError 15 | # ignore 16 | end 17 | require 'minitest/autorun' 18 | -------------------------------------------------------------------------------- /example/src/main/java/App.java: -------------------------------------------------------------------------------- 1 | import org.bouncycastle.jce.provider.BouncyCastleProvider; 2 | 3 | class App 4 | { 5 | public static String bcInfo() { 6 | return new BouncyCastleProvider().getInfo(); 7 | } 8 | public static String jrubyVersion() { 9 | return org.jruby.runtime.Constants.VERSION; 10 | } 11 | public static String hello(String name) { 12 | return "hello " + name; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /integration/gemspec_with_system_jar/Mavenfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | id 'jar-dependencies:gemspec_with_system_jar:0' 4 | 5 | packaging 'pom' 6 | 7 | name 'aggregator' 8 | 9 | modules %w[gem verify] 10 | 11 | properties('gem.home' => '${project.basedir}/../rubygems', 12 | 'gem.path' => '${gem.home}') 13 | 14 | jruby_plugin :gem, '${jruby.plugins.version}' do 15 | execute_goal :initialize 16 | end 17 | -------------------------------------------------------------------------------- /examples/gem-with-jar-dependencies/test.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # setup env 4 | $LOAD_PATH << 'lib' 5 | 6 | # load our gem and its jars 7 | require 'mygem' 8 | 9 | # load test jar 10 | require_jar 'org.slf4j', 'slf4j-simple', '1.7.7' 11 | 12 | # use it 13 | logger = org.slf4j.LoggerFactory.get_logger('root') 14 | logger.info('hello') 15 | 16 | logger.info("used classpath:\n\t#{$CLASSPATH.collect(&:to_s).join("\n\t")}") 17 | -------------------------------------------------------------------------------- /examples/gem-with-jar-dependencies-and-bundler/test.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # setup env 4 | $LOAD_PATH << 'lib' 5 | 6 | # load our gem and its jars 7 | require 'mygem' 8 | 9 | # load test jar 10 | require_jar 'org.slf4j', 'slf4j-simple', '1.7.7' 11 | 12 | # use it 13 | logger = org.slf4j.LoggerFactory.get_logger('root') 14 | logger.info('hello') 15 | 16 | logger.info("used classpath:\n\t#{$CLASSPATH.collect(&:to_s).join("\n\t")}") 17 | -------------------------------------------------------------------------------- /integration/vendor_jars/setup.bsh: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | 3 | new File(basedir, "lib/com/fasterxml/classmate/1.0.0/classmate-1.0.0.jar").delete(); 4 | new File(basedir, "lib/com/google/guava/guava/18.0/guava-18.0.jar").delete(); 5 | new File(basedir, "lib/org/glassfish/javax.el/3.0.0/javax.el-3.0.0.jar").delete(); 6 | new File(basedir, "lib/com/fasterxml/classmate/1.0.0/classmate-1.0.0.jar").delete(); 7 | new File(basedir, "lib/example_jars.rb").delete(); 8 | true; 9 | -------------------------------------------------------------------------------- /example/spec/second_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative 'spec_helper' 4 | 5 | describe 'java class App from src/main/java/**' do 6 | it 'should load bouncy castle' do 7 | expect(Java::App.bc_info).to eq 'BouncyCastle Security Provider v1.49' 8 | expect(Java::App.jruby_version).to eq JRUBY_VERSION 9 | logger = org.slf4j.LoggerFactory.get_logger('root') 10 | logger.info(Java::App.hello('world')) 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /integration/bundle_with_path/mygem.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Gem::Specification.new do |s| 4 | s.name = 'foo' 5 | s.version = '0.0.1' 6 | s.authors = ['foo'] 7 | s.summary = 'foo' 8 | s.requirements << 'jar io.dropwizard.metrics:metrics-healthchecks, 3.1.0' 9 | s.platform = 'java' 10 | s.required_ruby_version = '>= 2.6' 11 | s.add_runtime_dependency 'jar-dependencies' 12 | s.metadata['rubygems_mfa_required'] = 'true' 13 | end 14 | -------------------------------------------------------------------------------- /integration/require_tests/test_freeze_loading.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'jar-dependencies' 4 | 5 | Jars.freeze_loading 6 | 7 | raise 'expected no env variable for freeze' if ENV[Jars::NO_REQUIRE] 8 | 9 | raise 'expected no bouncycastle jars in classpath' if $CLASSPATH.detect { |c| c.include?('bouncycastle') } 10 | 11 | begin 12 | require 'openssl' 13 | 14 | raise 'expected LoadError' 15 | rescue LoadError 16 | # expected 17 | end 18 | -------------------------------------------------------------------------------- /integration/bundle_with_path_to_gemspec/Mavenfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | plugin_repository id: 'mavengems', url: 'mavengem:https://rubygems.org' 4 | 5 | properties('gem.home' => '${project.basedir}/../../pkg/rubygems', 6 | 'gem.path' => '${gem.home}') 7 | 8 | jruby_plugin :gem, filename: 'bundle', args: 'install' do 9 | execute_goal :exec 10 | gem 'bundler', '${bundler.version}' 11 | gem 'jar-dependencies', '${jar-dependencies.version}' 12 | end 13 | -------------------------------------------------------------------------------- /integration/bundle_with_two_gemspecs/Mavenfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | plugin_repository id: 'mavengems', url: 'mavengem:https://rubygems.org' 4 | 5 | properties('gem.home' => '${project.basedir}/../../pkg/rubygems', 6 | 'gem.path' => '${gem.home}') 7 | 8 | jruby_plugin :gem, filename: 'bundle', args: 'install' do 9 | execute_goal :exec 10 | gem 'bundler', '${bundler.version}' 11 | gem 'jar-dependencies', '${jar-dependencies.version}' 12 | end 13 | -------------------------------------------------------------------------------- /integration/lock_jars/setup.bsh: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | 3 | new File(basedir, "repository/org/bouncycastle/bcpkix-jdk15on/1.54/bcpkix-jdk15on-1.54.jar").delete(); 4 | new File(basedir, "repository/org/bouncycastle/bcpkix-jdk15on/1.54/bcpkix-jdk15on-1.54.pom").delete(); 5 | new File(basedir, "repository/org/bouncycastle/bcprov-jdk15on/1.54/bcprov-jdk15on-1.54.jar").delete(); 6 | new File(basedir, "repository/org/bouncycastle/bcprov-jdk15on/1.54/bcprov-jdk15on-1.54.pom").delete(); 7 | true; 8 | -------------------------------------------------------------------------------- /integration/gemspec_with_system_jar/verify/test.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative '../../../lib/jars/version' 4 | 5 | # force to use prereleased gem 6 | gem 'jar-dependencies', Jars::VERSION 7 | require 'jar-dependencies' 8 | 9 | Gem.install(File.expand_path('../gem/pkg/with-system-jar-1.1.1.gem', __dir__)) 10 | 11 | require 'first' 12 | 13 | raise "missing tools.jar, not found in #{$CLASSPATH.inspect}" unless $CLASSPATH.detect { |c| c =~ /tools.jar/ } 14 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension/using-rake-compiler/Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'jars/classpath' 4 | require 'rake/javaextensiontask' 5 | 6 | spec = eval File.read('mygem.gemspec') # rubocop:disable Security/Eval 7 | Rake::JavaExtensionTask.new('mygem', spec) do |ext| 8 | ext.ext_dir = 'ext' 9 | end 10 | 11 | task default: [:compile] 12 | 13 | require 'rubygems/package_task' 14 | Gem::PackageTask.new(spec) do 15 | desc 'Pack gem' 16 | task package: [:compile] 17 | end 18 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension/using-maven/README.md: -------------------------------------------------------------------------------- 1 | # using maven-3.9.x to build jar and pack gem 2 | 3 | the ruby DSL for maven is configured by .mvn/extensions.xml 4 | 5 | ## build compile and create jar 6 | 7 | ``` 8 | mvn prepare-package 9 | ``` 10 | 11 | ## pack gem 12 | 13 | ``` 14 | mvn package 15 | ``` 16 | 17 | ## deploy gem tio rubygems.prg 18 | 19 | ``` 20 | mvn push 21 | ``` 22 | 23 | ## just run the code 24 | 25 | make sure you use jruby (via rbenv, rvm, etc) 26 | ``` 27 | jruby test.rb 28 | ``` -------------------------------------------------------------------------------- /integration/nested_jars_lock_from_classloader/test.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'jar-dependencies' 4 | require 'minitest/autorun' 5 | 6 | basedir = ENV_JAVA['jars.home'] = __dir__ 7 | 8 | describe Jars do 9 | it 'requires Jars.lock from required jars' do 10 | Jars.require_jars_lock 11 | 12 | $CLASSPATH.collect do |c| 13 | c.sub(%r{file:#{basedir}/}, '') 14 | end.must_equal ['org/example/nested/1.0/nested-1.0.jar', 'jline/jline/2.11/jline-2.11.jar'] 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/jars/output_jars_pom.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # this file is maven DSL 4 | 5 | if ENV_JAVA['jars.quiet'] != 'true' 6 | model.dependencies.each do |d| 7 | puts " #{d.group_id}:#{d.artifact_id}" \ 8 | "#{d.classifier ? ":#{d.classifier}" : ''}" \ 9 | ":#{d.version}:#{d.scope || 'compile'}" 10 | next if d.exclusions.empty? 11 | 12 | puts " exclusions: #{d.exclusions.collect do |e| 13 | "#{e.group_id}:#{e.artifact_id}" 14 | end.join}" 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension/using-ruby-maven/Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'ruby-maven' 4 | desc 'Pack jar after compiling classes' 5 | task :compile do 6 | RubyMaven.exec('prepare-package') 7 | end 8 | 9 | desc 'Clean build' 10 | task :clean do 11 | RubyMaven.exec('clean') 12 | end 13 | 14 | task default: [:compile] 15 | 16 | require 'rubygems/package_task' 17 | Gem::PackageTask.new(eval(File.read('mygem.gemspec'))) do # rubocop:disable Security/Eval 18 | desc 'Pack gem' 19 | task package: [:compile] 20 | end 21 | -------------------------------------------------------------------------------- /integration/gemspec_with_system_jar/gem/Mavenfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | inherit 'jar-dependencies:gemspec_with_system_jar:0' do 4 | # TODO: should not be needed with ruby-maven 5 | relative_path '../Mavenfile' 6 | end 7 | 8 | gemspec 9 | 10 | # use the current jar dependencies gem 11 | model.dependencies.each do |d| 12 | d.version = '${jar-dependencies.version}' if d.artifact_id == 'jar-dependencies' 13 | end 14 | 15 | properties('gem.home' => '${project.basedir}/../../rubygems', 16 | 'gem.path' => '${gem.home}') 17 | -------------------------------------------------------------------------------- /integration/install_ruby_maven_when_needed/gem/Mavenfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | inherit 'jar-dependencies:install-ruby-maven:0' do 4 | # TODO: should not be needed with ruby-maven 5 | relative_path '../Mavenfile' 6 | end 7 | 8 | gemspec 9 | 10 | # use the current jar dependencies gem 11 | model.dependencies.each do |d| 12 | d.version = '${jar-dependencies.version}' if d.artifact_id == 'jar-dependencies' 13 | end 14 | 15 | properties('gem.home' => '${project.basedir}/../../rubygems', 16 | 'gem.path' => '${gem.home}') 17 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension-and-jar-dependencies/using-ruby-maven/Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'ruby-maven' 4 | desc 'Pack jar after compiling classes' 5 | task :compile do 6 | RubyMaven.exec('prepare-package') 7 | end 8 | 9 | desc 'Clean build' 10 | task :clean do 11 | RubyMaven.exec('clean') 12 | end 13 | 14 | task default: [:compile] 15 | 16 | require 'rubygems/package_task' 17 | Gem::PackageTask.new(eval(File.read('mygem.gemspec'))) do # rubocop:disable Security/Eval 18 | desc 'Pack gem' 19 | task package: [:compile] 20 | end 21 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension/using-ruby-maven/README.md: -------------------------------------------------------------------------------- 1 | # using rake and ruby-maven gem 2 | 3 | ## setup 4 | 5 | ``` 6 | bundle install 7 | ``` 8 | 9 | which is important since it will create a file lib/gem-name_jars.rb 10 | and installs the jar dependencies into a local cache (local maven repository) 11 | 12 | ## build compile and create jar 13 | 14 | ``` 15 | rake compile 16 | ``` 17 | 18 | ## pack gem 19 | 20 | ``` 21 | rake package 22 | ``` 23 | 24 | ## just run the code 25 | 26 | make sure you use jruby (via rbenv, rvm, etc) 27 | ``` 28 | jruby test.rb 29 | ``` -------------------------------------------------------------------------------- /integration/jars_lock_gemspec_with_jars/test.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | unless defined? Jars 4 | require 'jar-dependencies' 5 | # trigger to require of Jars.lock 6 | require_jar('org.apache.hbase', 'hbase-annotations', '0.98.7-hadoop2') 7 | end 8 | 9 | ['hbase-annotations-0.98.7-hadoop2.jar', '/tools.jar', 'findbugs-annotations-1.3.9-1.jar', 10 | 'log4j-1.2.17.jar'].each do |jar| 11 | raise "missing #{jar}" unless $CLASSPATH.detect { |c| c =~ /#{jar}/ } 12 | end 13 | 14 | raise "too many entries in classpath #{$CLASSPATH}" if $CLASSPATH.size != 4 15 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension-and-jar-dependencies/using-rake-compiler/Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'jars/classpath' 4 | require 'rake/javaextensiontask' 5 | 6 | spec = eval File.read('mygem.gemspec') # rubocop:disable Security/Eval 7 | Rake::JavaExtensionTask.new('mygem', spec) do |ext| 8 | ext.classpath = Jars::Classpath.new.classpath_string 9 | ext.ext_dir = 'ext' 10 | end 11 | 12 | task default: [:compile] 13 | 14 | require 'rubygems/package_task' 15 | Gem::PackageTask.new(spec) do 16 | desc 'Pack gem' 17 | task package: [:compile] 18 | end 19 | -------------------------------------------------------------------------------- /examples/sinatra-app/having-gems-with-jar-dependencies/README.md: -------------------------------------------------------------------------------- 1 | assuming jruby is used via rbenv, rvm, etc 2 | 3 | ## setup 4 | 5 | ``` 6 | bundle install 7 | ``` 8 | 9 | which is important since it will create a file lib/gem-name_jars.rb 10 | and installs the jar dependencies into a local cache (local maven repository) 11 | 12 | ## use it 13 | 14 | ``` 15 | rackup 16 | ``` 17 | 18 | ## lock down version of jar dependencies 19 | 20 | lock down may or may not be needed. in case you want to lock down your versions for the jars execute: 21 | 22 | ``` 23 | lock_jars 24 | ``` 25 | 26 | -------------------------------------------------------------------------------- /integration/gemspec_with_classifier_and_exclusions/verify.bsh: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import org.codehaus.plexus.util.FileUtils; 3 | 4 | 5 | String log = FileUtils.fileRead( new File( basedir, "build.log" ) ); 6 | String expected = "org.slf4j:slf4j-simple:jar:1.7.7:provide"; 7 | if ( !log.contains( expected ) ) 8 | { 9 | throw new RuntimeException( "log file does not contain '" + expected + "'" ); 10 | } 11 | 12 | expected = "org.hamcrest:hamcrest-core:jar:1.3:test"; 13 | if ( !log.contains( expected ) ) 14 | { 15 | throw new RuntimeException( "log file does not contain '" + expected + "'" ); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /integration/install_ruby_maven_when_needed/verify/test_bundler.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | gemspecs = File.join(Gem.dir, 'specifications', 'ruby-maven-*gemspec') 4 | Dir[gemspecs].each do |f| 5 | File.delete(f) 6 | rescue 7 | nil 8 | end 9 | 10 | version = ARGV[0] 11 | gem 'jar-dependencies', version.sub(/-SNAPSHOT/, '') 12 | 13 | Kernel.at_exit do 14 | raise "did not find two ruby-maven gems installed #{Dir[gemspecs]}" if Dir[gemspecs].size != 2 15 | end 16 | 17 | # this is like: gem install --ignore-dependencies, ../gem/pkg/my-1.1.1.gem 18 | ARGV.replace(['install']) 19 | load File.join(Gem.bindir, 'bundle') 20 | -------------------------------------------------------------------------------- /lib/jars/settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | __HTTP_ACTIVE__ 4 | http 5 | __HTTP_SERVER__ 6 | __HTTP_PORT__ 7 | 10 | 11 | 12 | __HTTPS_ACTIVE__ 13 | https 14 | __HTTPS_SERVER__ 15 | __HTTPS_PORT__ 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /integration/depending_gems/simplelib/simplelib.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Gem::Specification.new do |s| 4 | s.name = 'simplelib' 5 | s.version = '1' 6 | s.author = 'christian meier' 7 | s.email = ['m.kristian@web.de'] 8 | 9 | s.platform = 'java' 10 | s.license = 'MIT' 11 | s.summary = 'simplelib' 12 | s.homepage = 'https://example.com' 13 | s.description = 'more examples' 14 | 15 | s.required_ruby_version = '>= 2.6' 16 | 17 | s.requirements << 'jar io.dropwizard.metrics:metrics-core, 3.1.0' 18 | 19 | s.add_runtime_dependency 'jar-dependencies' 20 | s.metadata['rubygems_mfa_required'] = 'true' 21 | end 22 | -------------------------------------------------------------------------------- /integration/install_ruby_maven_when_needed/gem/my.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Gem::Specification.new do |s| 4 | s.name = 'my' 5 | s.version = '1.1.1' 6 | s.author = 'example person' 7 | s.email = ['mail@example.com'] 8 | s.summary = 'test gem' 9 | 10 | s.files << Dir['lib/**/*.rb'] 11 | s.files << Dir['*file'] 12 | s.files << 'my.gemspec' 13 | 14 | s.required_ruby_version = '>= 2.6' 15 | 16 | s.add_runtime_dependency 'jar-dependencies' 17 | 18 | s.platform = 'java' 19 | s.requirements << "jar 'com.fasterxml.jackson.core:jackson-core', '2.3.0'" 20 | s.metadata['rubygems_mfa_required'] = 'true' 21 | end 22 | -------------------------------------------------------------------------------- /integration/require_tests/test_no_more_warnings.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'jar-dependencies' 4 | 5 | Jars.no_more_warnings 6 | 7 | raise 'expected no env variable for freeze' if ENV[Jars::NO_REQUIRE] 8 | 9 | raise 'expected no bouncycastle jars in classpath' if $CLASSPATH.detect { |c| c.include?('bouncycastle') } 10 | 11 | require 'openssl' 12 | 13 | raise 'did not find bouncycastle jars' unless $CLASSPATH.detect { |c| c.include?('bouncycastle') } 14 | 15 | $stderr = StringIO.new 16 | 17 | require_jar 'org.bouncycastle', 'bcpkix-jdk15on', '1.46' 18 | 19 | raise 'no warning on jar conflics after freeze' unless $stderr.string.empty? 20 | 21 | $stderr = STDERR 22 | -------------------------------------------------------------------------------- /examples/sinatra-app/having-jarfile-and-gems-with-jar-dependencies/README.md: -------------------------------------------------------------------------------- 1 | assuming jruby is used via rbenv, rvm, etc 2 | 3 | ## setup 4 | 5 | it needs to install/lockdown the gems and the jars in with two commands 6 | 7 | ### install/lockdown the gems 8 | 9 | ``` 10 | bundle install 11 | ``` 12 | 13 | which is important since it will create a file lib/gem-name_jars.rb 14 | and installs the jar dependencies into a local cache (local maven repository) 15 | 16 | ### install/lockdown the jars 17 | 18 | since there is Jarfile the jar dependencies from there only get installed with 19 | 20 | 21 | ``` 22 | lock_jars 23 | ``` 24 | 25 | ## use it 26 | 27 | ``` 28 | rackup 29 | ``` 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /integration/gemspec_with_system_jar/gem/with-system-jar.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative '../../../lib/jars/version' 4 | 5 | Gem::Specification.new do |s| 6 | s.name = 'with-system-jar' 7 | s.version = '1.1.1' 8 | s.author = 'example person' 9 | s.email = ['mail@example.com'] 10 | s.summary = 'first gem with jars vendored during installation' 11 | 12 | s.platform = 'java' 13 | s.files = Dir['lib/**/*.rb'] + Dir['*.gemspec'] 14 | 15 | s.required_ruby_version = '>= 2.6' 16 | 17 | s.add_runtime_dependency 'jar-dependencies', Jars::VERSION 18 | 19 | s.requirements << "jar 'org.apache.hbase:hbase-annotations', '=0.98.7-hadoop2'" 20 | s.metadata['rubygems_mfa_required'] = 'true' 21 | end 22 | -------------------------------------------------------------------------------- /integration/install_ruby_maven_when_needed/verify/test_gem.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | gemspecs = File.join(Gem.dir, 'specifications', 'ruby-maven-*gemspec') 4 | Dir[gemspecs].each do |f| 5 | File.delete(f) 6 | rescue 7 | nil 8 | end 9 | 10 | version = ARGV[0] 11 | gem 'jar-dependencies', version.sub(/-SNAPSHOT/, '') 12 | 13 | Kernel.at_exit do 14 | raise "did not find two ruby-maven gems installed #{Dir[gemspecs]}" if Dir[gemspecs].size != 2 15 | end 16 | 17 | # this is like: gem install --ignore-dependencies, ../gem/pkg/my-1.1.1.gem 18 | ARGV.replace(['install', '--ignore-dependencies', File.expand_path('../gem/pkg/my-1.1.1.gem', __dir__)]) 19 | load File.join(JRuby.runtime.instance_config.jruby_home, 'bin/gem') 20 | -------------------------------------------------------------------------------- /integration/gemspec_with_classifier_and_exclusions/mygem.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Gem::Specification.new do |s| 4 | s.name = 'mygem' 5 | s.version = '0.0.1' 6 | s.authors = ['foo'] 7 | s.summary = 'foo' 8 | s.requirements << 'jar io.dropwizard:dropwizard-logging, 0.8.0-rc5, :exclusions=> [ joda-time:joda-time ]' 9 | s.requirements << 'jar com.google.protobuf:protobuf-java, 2.2.0, :classifier => lite' 10 | s.requirements << 'jar org.slf4j:slf4j-simple:1.7.7, :scope => :provided' 11 | s.requirements << 'jar junit:junit:4.12, :scope => :test' 12 | s.platform = 'java' 13 | s.required_ruby_version = '>= 2.6' 14 | s.add_runtime_dependency 'jar-dependencies' 15 | s.metadata['rubygems_mfa_required'] = 'true' 16 | end 17 | -------------------------------------------------------------------------------- /integration/depending_gems/biglib/biglib.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Gem::Specification.new do |s| 4 | s.name = 'biglib' 5 | s.version = '1' 6 | s.author = 'christian meier' 7 | s.email = ['m.kristian@web.de'] 8 | 9 | s.platform = 'java' 10 | s.license = 'MIT' 11 | s.summary = 'biglib' 12 | s.homepage = 'https://example.com' 13 | s.description = 'more examples' 14 | 15 | s.required_ruby_version = '>= 2.6' 16 | 17 | s.requirements << 'jar io.dropwizard.metrics:metrics-json, 3.1.0' 18 | s.requirements << 'jar io.dropwizard.metrics:metrics-jvm, 3.1.0' 19 | 20 | s.add_runtime_dependency 'jar-dependencies' 21 | s.add_development_dependency 'simplelib', '1' 22 | s.metadata['rubygems_mfa_required'] = 'true' 23 | end 24 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension-and-jar-dependencies/using-rake-compiler/README.md: -------------------------------------------------------------------------------- 1 | # using ruby-maven gem build jar 2 | 3 | ## setup 4 | 5 | ``` 6 | bundle install 7 | ``` 8 | 9 | which is important since it will create a file lib/gem-name_jars.rb 10 | and installs the jar dependencies into a local cache (local maven repository) 11 | 12 | ## lock down version of jar dependencies 13 | 14 | lock down may or may not be needed (best just lock them down). in case you want to lock down your versions for the jars execute: 15 | 16 | ``` 17 | lock_jars 18 | ``` 19 | 20 | ## build compile and create jar 21 | 22 | ``` 23 | rake compile 24 | ``` 25 | 26 | ## use it 27 | 28 | ``` 29 | jruby test.rb 30 | ``` 31 | 32 | ## pack gem 33 | 34 | ``` 35 | rake package 36 | ``` 37 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension-and-jar-dependencies/using-ruby-maven/README.md: -------------------------------------------------------------------------------- 1 | # using ruby-maven gem build jar 2 | 3 | ## setup 4 | 5 | ``` 6 | bundle install 7 | ``` 8 | 9 | which is important since it will create a file lib/gem-name_jars.rb 10 | and installs the jar dependencies into a local cache (local maven repository) 11 | 12 | ## lock down version of jar dependencies 13 | 14 | lock down may or may not be needed (best just lock them down). in case you want to lock down your versions for the jars execute: 15 | 16 | ``` 17 | lock_jars 18 | ``` 19 | 20 | ## build compile and create jar 21 | 22 | ``` 23 | rake compile 24 | ``` 25 | 26 | ## use it 27 | 28 | ``` 29 | jruby test.rb 30 | ``` 31 | 32 | ## pack gem 33 | 34 | ``` 35 | rake package 36 | ``` 37 | -------------------------------------------------------------------------------- /integration/depending_gems/Mavenfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | group_id 'jar-dependencies' 4 | 5 | packaging 'pom' 6 | 7 | modules %w[simplelib biglib] 8 | 9 | properties('gem.home' => '${project.basedir}/pkg/rubygems', 10 | 'gem.path' => '${project.basedir}/pkg/rubygems') 11 | 12 | phase :test do 13 | execute 'verify' do |ctx| 14 | log = File.read("#{ctx.basedir.to_pathname}/build.log") 15 | ['io.dropwizard.metrics:metrics-json:3.1.0', 16 | 'io.dropwizard.metrics:metrics-jvm:3.1.0', 17 | 'io.dropwizard.metrics:metrics-core:3.1.0'].each do |expected| 18 | raise "log does not contain '#{expected}'" unless /#{expected}/.match?(log) 19 | 20 | puts "log contains '#{expected}'" 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /integration/jars_lock_gemspec_with_jars/first.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Gem::Specification.new do |s| 4 | s.name = 'first' 5 | s.version = '1.1.1' 6 | s.author = 'example person' 7 | s.email = ['mail@example.com'] 8 | s.summary = 'first gem with jars vendored during installation' 9 | 10 | s.files << Dir['*file'] 11 | s.files << 'first.gemspec' 12 | 13 | s.platform = 'java' 14 | 15 | s.required_ruby_version = '>= 2.6' 16 | 17 | s.add_runtime_dependency 'jar-dependencies', '~> 0.1' 18 | 19 | s.requirements << "jar 'org.apache.hbase:hbase-annotations', '=0.98.7-hadoop2', ['junit:junit']" 20 | s.requirements << 'jar org.jruby:jruby, 1.7.20, :scope => :provided' 21 | s.metadata['rubygems_mfa_required'] = 'true' 22 | end 23 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Ruby 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | test: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | strategy: 15 | matrix: 16 | ruby-version: [jruby-9.3, jruby-9.4] 17 | 18 | steps: 19 | - uses: actions/checkout@v2 20 | - name: Set up Ruby 21 | uses: ruby/setup-ruby@v1 22 | with: 23 | ruby-version: ${{ matrix.ruby-version }} 24 | bundler-cache: true 25 | - name: Install dependencies 26 | run: bundle install 27 | - name: Run test 28 | run: jruby -Ilib -rbundler/setup -S rake specs 29 | - name: Run RuboCop 30 | run: jruby -Ilib -rbundler/setup -S rubocop lib 31 | -------------------------------------------------------------------------------- /lib/jars/attach_jars_pom.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # this file is maven DSL 4 | 5 | 10_000.times do |i| 6 | coord = ENV_JAVA["jars.#{i}"] 7 | break unless coord 8 | 9 | artifact = Maven::Tools::Artifact.from_coordinate(coord) 10 | exclusions = [] 11 | 10_000.times do |j| 12 | exclusion = ENV_JAVA["jars.#{i}.exclusions.#{j}"] 13 | break unless exclusion 14 | 15 | exclusions << exclusion 16 | end 17 | scope = ENV_JAVA["jars.#{i}.scope"] 18 | artifact.scope = scope if scope 19 | classifier = ENV_JAVA["jars.#{i}.classifier"] 20 | artifact.classifier = classifier if classifier 21 | 22 | # declare the artifact inside the POM 23 | dependency_artifact(artifact) do 24 | exclusions.each do |ex| 25 | exclusion ex 26 | end 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension/using-maven/mygem.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # use the version from the main project 4 | require "#{File.dirname File.expand_path(__FILE__)}/../../lib/jars/version" 5 | 6 | Gem::Specification.new do |s| 7 | s.name = File.basename(File.dirname(File.expand_path(__FILE__))) 8 | s.version = '1.0.0' 9 | s.author = ['example person'] 10 | s.email = ['mail@example.com'] 11 | s.summary = "summary of #{s.name}" 12 | s.description = "description of #{s.name}" 13 | 14 | # nice to have 15 | s.platform = 'java' 16 | 17 | s.required_ruby_version = '>= 2.6' 18 | 19 | s.files = Dir['lib/**/*.rb'] 20 | s.files += Dir['lib/*.jar'] 21 | s.files += Dir['*.file'] 22 | s.files += Dir['*.gemspec'] 23 | s.metadata['rubygems_mfa_required'] = 'true' 24 | end 25 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | require: 2 | - rubocop-rake 3 | - rubocop-performance 4 | 5 | AllCops: 6 | TargetRubyVersion: 2.6 7 | NewCops: enable 8 | 9 | Metrics: 10 | Enabled: false 11 | 12 | Naming/FileName: 13 | Exclude: 14 | - lib/jar-dependencies.rb 15 | 16 | Performance/Casecmp: 17 | AutoCorrect: false 18 | 19 | Style/Alias: 20 | EnforcedStyle: prefer_alias_method 21 | Style/BlockDelimiters: 22 | IgnoredMethods: [] 23 | Style/Documentation: 24 | Enabled: false 25 | Style/EnvHome: 26 | Enabled: false 27 | Style/FetchEnvVar: 28 | Enabled: false 29 | Style/NilComparison: 30 | Enabled: false 31 | Style/HashSyntax: 32 | EnforcedStyle: ruby19_no_mixed_keys 33 | Style/RescueStandardError: 34 | EnforcedStyle: implicit 35 | Style/TernaryParentheses: 36 | EnforcedStyle: require_parentheses_when_complex 37 | -------------------------------------------------------------------------------- /examples/gem-with-jar-dependencies/mygem.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Gem::Specification.new do |s| 4 | s.name = File.basename(File.dirname(File.expand_path(__FILE__))) 5 | s.version = '1.0.0' 6 | s.author = ['example person'] 7 | s.email = ['mail@example.com'] 8 | s.summary = "summary of #{s.name}" 9 | s.description = "description of #{s.name}" 10 | 11 | # important to get the jars installed 12 | s.platform = 'java' 13 | 14 | s.files = Dir['lib/**/*.rb'] 15 | s.files += Dir['lib/**/*.jar'] 16 | s.files += Dir['*file'] 17 | s.files += Dir['*.gemspec'] 18 | 19 | s.required_ruby_version = '>= 2.6' 20 | 21 | s.requirements << 'jar org.slf4j, slf4j-api, 1.7.7' 22 | s.requirements << 'jar org.slf4j, slf4j-simple, 1.7.7, :scope => :test' 23 | s.metadata['rubygems_mfa_required'] = 'true' 24 | end 25 | -------------------------------------------------------------------------------- /bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'rake' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) 12 | 13 | bundle_binstub = File.expand_path('bundle', __dir__) 14 | 15 | if File.file?(bundle_binstub) 16 | if File.read(bundle_binstub, 300).include?('This file was generated by Bundler') 17 | load(bundle_binstub) 18 | else 19 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 20 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 21 | end 22 | end 23 | 24 | require 'rubygems' 25 | require 'bundler/setup' 26 | 27 | load Gem.bin_path('rake', 'rake') 28 | -------------------------------------------------------------------------------- /bin/rubocop: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'rubocop' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) 12 | 13 | bundle_binstub = File.expand_path('bundle', __dir__) 14 | 15 | if File.file?(bundle_binstub) 16 | if File.read(bundle_binstub, 300).include?('This file was generated by Bundler') 17 | load(bundle_binstub) 18 | else 19 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 20 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 21 | end 22 | end 23 | 24 | require 'rubygems' 25 | require 'bundler/setup' 26 | 27 | load Gem.bin_path('rubocop', 'rubocop') 28 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension-and-jar-dependencies/using-maven/README.md: -------------------------------------------------------------------------------- 1 | # using maven-3.9.x to build jar and pack gem 2 | 3 | the ruby DSL for maven is configured by .mvn/extensions.xml 4 | 5 | ## setup 6 | 7 | ``` 8 | bundle install 9 | ``` 10 | 11 | which is important since it will create a file **lib/_jars.rb** 12 | and installs the jar dependencies into a local cache (local maven-repository) 13 | 14 | ## build compile and create jar 15 | 16 | ``` 17 | mvn prepare-package 18 | ``` 19 | 20 | ## use it 21 | 22 | ``` 23 | jruby test.rb 24 | ``` 25 | 26 | ## lock down version of jar dependencies 27 | 28 | lock down may or may not be needed. in case you want to lock down your versions for the jars execute: 29 | 30 | ``` 31 | lock_jars 32 | ``` 33 | 34 | ## pack gem 35 | 36 | ``` 37 | mvn package 38 | ``` 39 | 40 | ## deploy gem to rubygems.prg 41 | 42 | ``` 43 | mvn push 44 | ``` -------------------------------------------------------------------------------- /integration/bundle_with_two_gemspecs/another_gemspec.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | lib = File.expand_path('lib', __dir__) 4 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 5 | require 'another_gemspec/version' 6 | 7 | Gem::Specification.new do |spec| 8 | spec.name = 'another_gemspec' 9 | spec.version = AnotherGemspec::VERSION 10 | spec.authors = ['Jason R. Clark'] 11 | spec.email = ['jclark@newrelic.com'] 12 | spec.summary = 'Wat, two gemspecs?' 13 | spec.description = 'Are you crazy?' 14 | spec.homepage = '' 15 | spec.license = 'MIT' 16 | 17 | spec.files = `git ls-files -z`.split("\x0") 18 | spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } 19 | spec.require_paths = ['lib'] 20 | spec.metadata['rubygems_mfa_required'] = 'true' 21 | spec.required_ruby_version = '>= 2.6' 22 | end 23 | -------------------------------------------------------------------------------- /integration/jars_lock_gemfile/verify.bsh: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import org.codehaus.plexus.util.FileUtils; 3 | 4 | 5 | String log = FileUtils.fileRead( new File( basedir, "build.log" ) ); 6 | 7 | String expected = "Jars.lock updated"; 8 | if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" ); 9 | 10 | String unexpected = "org.jruby:jruby-core:jar:1.7.20:provided"; 11 | if ( log.contains( unexpected ) ) throw new RuntimeException( "log file does contain unexpected '" + unexpected + "'" ); 12 | 13 | expected = "org.slf4j:slf4j-simple:jar:1.7.7:compile"; 14 | if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" ); 15 | 16 | expected = "io.dropwizard.metrics:metrics-core:jar:3.1.0:compile"; 17 | if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" ); 18 | -------------------------------------------------------------------------------- /example/Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rspec/core/rake_task' 4 | require 'jars/classpath' 5 | require 'rake/javaextensiontask' 6 | 7 | require 'jars/installer' 8 | task :install_jars do 9 | Jars::Installer.new.vendor_jars 10 | end 11 | 12 | desc 'Compiles extension and run specs' 13 | task default: %i[compile spec] 14 | 15 | spec = eval File.read('example.gemspec') # rubocop:disable Security/Eval 16 | 17 | desc 'compile src/main/java/** into lib/example.jar' 18 | Rake::JavaExtensionTask.new('example', spec) do |ext| 19 | ext.classpath = Jars::Classpath.new.classpath_string 20 | ext.source_version = '1.7' 21 | ext.target_version = '1.7' 22 | ext.ext_dir = 'src/main/java' 23 | end 24 | 25 | require 'rubygems/package_task' 26 | Gem::PackageTask.new(spec) do 27 | desc 'Pack gem' 28 | task package: %i[install_jars compile] 29 | end 30 | 31 | desc 'Run specs' 32 | RSpec::Core::RakeTask.new 33 | -------------------------------------------------------------------------------- /integration/nested_jars_lock_from_classloader/Mavenfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | packaging 'jar' 4 | 5 | gem 'jar-dependencies', '${jar-dependencies.version}' 6 | 7 | jruby_plugin :gem, '${jruby.plugins.version}' do 8 | execute_goal :initialize 9 | end 10 | 11 | pom 'org.jruby:jruby', '${jruby.version}' 12 | 13 | plugin('org.codehaus.mojo:exec-maven-plugin', '3.5.0', 14 | executable: :java, 15 | environmentVariables: { 'GEM_HOME' => '${gem.home}', 16 | 'GEM_PATH' => '${gem.home}' }) do 17 | execute_goal(:exec, id: 'no more warnings', phase: :test, 18 | arguments: ['-classpath', 19 | xml(''), 20 | 'org.jruby.Main', 21 | 'test.rb']) 22 | end 23 | 24 | properties('gem.home' => '${project.basedir}/pkg/rubygems', 25 | 'gem.path' => '${gem.home}') 26 | -------------------------------------------------------------------------------- /integration/bundle_with_path/verify.bsh: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import org.codehaus.plexus.util.FileUtils; 3 | 4 | 5 | String log = FileUtils.fileRead( new File( basedir, "build.log" ) ); 6 | String expected = "jar dependencies for foo-0.0.1-java.gemspec"; 7 | if ( !log.contains( expected ) ) 8 | { 9 | throw new RuntimeException( "log file does not contain '" + expected + "'" ); 10 | } 11 | 12 | expected = "lib/foo_jars.rb"; 13 | if ( ! new File( basedir, expected ).exists() ) 14 | { 15 | throw new RuntimeException( "log file does not exists '" + expected + "'" ); 16 | } 17 | 18 | // expected = "lib/io"; 19 | // if ( ! new File( basedir, expected ).exists() ) 20 | // { 21 | // throw new RuntimeException( "log file does exists '" + expected + "'" ); 22 | // } 23 | 24 | // expected = "lib/org"; 25 | // if ( ! new File( basedir, expected ).exists() ) 26 | // { 27 | // throw new RuntimeException( "log file does exists '" + expected + "'" ); 28 | // } 29 | 30 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension/using-rake-compiler/mygem.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # use the version from the main project 4 | require "#{File.dirname File.expand_path(__FILE__)}/../../../lib/jars/version" 5 | 6 | Gem::Specification.new do |s| 7 | s.name = File.basename(File.dirname(File.expand_path(__FILE__))) 8 | s.version = '1.0.0' 9 | s.author = ['example person'] 10 | s.email = ['mail@example.com'] 11 | s.summary = "summary of #{s.name}" 12 | s.description = "description of #{s.name}" 13 | 14 | # nice to have 15 | s.platform = 'java' 16 | 17 | s.files = Dir['lib/**/*.rb'] 18 | s.files += Dir['lib/*.jar'] 19 | s.files += Dir['*.file'] 20 | s.files += Dir['*.gemspec'] 21 | 22 | s.required_ruby_version = '>= 2.6' 23 | 24 | s.add_development_dependency 'rake', '~> 10.3' 25 | # needed to compile ext/** and create jar file 26 | s.add_development_dependency 'rake-compile', '~> 0.9' 27 | s.metadata['rubygems_mfa_required'] = 'true' 28 | end 29 | -------------------------------------------------------------------------------- /lib/jars/lock_down_pom.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # this file is maven DSL and used by maven via jars/lock_down.rb 4 | 5 | basedir(ENV_JAVA['jars.basedir']) 6 | 7 | def eval_file(file) 8 | file = File.join(__dir__, file) 9 | eval(File.read(file), nil, file) # rubocop:disable Security/Eval 10 | end 11 | 12 | eval_file('attach_jars_pom.rb') 13 | 14 | jfile = ENV_JAVA['jars.jarfile'] 15 | jarfile(jfile) if jfile 16 | 17 | # need to fix the version of this plugin for gem:jars_lock goal 18 | jruby_plugin :gem, ENV_JAVA['jruby.plugins.version'] 19 | 20 | # if you use bundler we collect all root jar dependencies 21 | # from each gemspec file. otherwise we need to resolve 22 | # the gemspec artifact in the maven way 23 | unless ENV_JAVA['jars.bundler'] 24 | begin 25 | gemspec 26 | rescue 27 | nil 28 | end 29 | end 30 | 31 | properties('project.build.sourceEncoding' => 'utf-8') 32 | 33 | plugin :dependency, ENV_JAVA['dependency.plugin.version'] 34 | 35 | eval_file('output_jars_pom.rb') 36 | -------------------------------------------------------------------------------- /examples/gem-with-jar-dependencies-and-bundler/mygem.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # use the version from the main project 4 | require "#{File.dirname File.expand_path(__FILE__)}/../../lib/jars/version" 5 | 6 | Gem::Specification.new do |s| 7 | s.name = File.basename(File.dirname(File.expand_path(__FILE__))) 8 | s.version = '1.0.0' 9 | s.author = ['example person'] 10 | s.email = ['mail@example.com'] 11 | s.summary = "summary of #{s.name}" 12 | s.description = "description of #{s.name}" 13 | 14 | # important to get the jars installed 15 | s.platform = 'java' 16 | 17 | s.files = Dir['lib/**/*.rb'] 18 | s.files += Dir['*file'] 19 | s.files += Dir['*.gemspec'] 20 | 21 | s.required_ruby_version = '>= 2.6' 22 | 23 | s.requirements << 'jar org.slf4j, slf4j-api, 1.7.7' 24 | s.requirements << 'jar org.slf4j, slf4j-simple, 1.7.7, :scope => :test' 25 | 26 | s.add_runtime_dependency 'jar-dependencies', "~> #{Jars::VERSION}" 27 | s.metadata['rubygems_mfa_required'] = 'true' 28 | end 29 | -------------------------------------------------------------------------------- /integration/bundle_with_two_gemspecs/wat_two_gemspecs.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | lib = File.expand_path('lib', __dir__) 4 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 5 | require 'wat_two_gemspecs/version' 6 | 7 | Gem::Specification.new do |spec| 8 | spec.name = 'wat_two_gemspecs' 9 | spec.version = WatTwoGemspecs::VERSION 10 | spec.authors = ['Jason R. Clark'] 11 | spec.email = ['jclark@newrelic.com'] 12 | spec.summary = 'Wat, two gemspecs?' 13 | spec.description = 'Are you crazy?' 14 | spec.homepage = '' 15 | spec.license = 'MIT' 16 | 17 | spec.files = `git ls-files -z`.split("\x0") 18 | spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } 19 | spec.require_paths = ['lib'] 20 | 21 | s.required_ruby_version = '>= 2.6' 22 | 23 | spec.add_development_dependency 'bundler', '~> 1.7' 24 | spec.add_development_dependency 'rake', '~> 10.0' 25 | spec.metadata['rubygems_mfa_required'] = 'true' 26 | end 27 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension-and-jar-dependencies/using-maven/mygem.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # use the version from the main project 4 | require "#{File.dirname File.expand_path(__FILE__)}/../../../lib/jars/version" 5 | 6 | Gem::Specification.new do |s| 7 | s.name = File.basename(File.dirname(File.expand_path(__FILE__))) 8 | s.version = '1.0.0' 9 | s.author = ['example person'] 10 | s.email = ['mail@example.com'] 11 | s.summary = "summary of #{s.name}" 12 | s.description = "description of #{s.name}" 13 | 14 | # nice to have 15 | s.platform = 'java' 16 | 17 | s.files = Dir['lib/**/*.rb'] 18 | s.files += Dir['lib/*.jar'] 19 | s.files += Dir['*.file'] 20 | s.files += Dir['*.gemspec'] 21 | 22 | s.required_ruby_version = '>= 2.6' 23 | 24 | s.requirements << 'jar org.slf4j, slf4j-api, 1.7.7' 25 | s.requirements << 'jar org.slf4j, slf4j-simple, 1.7.7, :scope => :test' 26 | 27 | s.add_runtime_dependency 'jar-dependencies', "~> #{Jars::VERSION}" 28 | s.metadata['rubygems_mfa_required'] = 'true' 29 | end 30 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension-and-jar-dependencies/using-ruby-maven/mygem.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # use the version from the main project 4 | require "#{File.dirname File.expand_path(__FILE__)}/../../lib/jars/version" 5 | 6 | Gem::Specification.new do |s| 7 | s.name = File.basename(File.dirname(File.expand_path(__FILE__))) 8 | s.version = '1.0.0' 9 | s.author = ['example person'] 10 | s.email = ['mail@example.com'] 11 | s.summary = "summary of #{s.name}" 12 | s.description = "description of #{s.name}" 13 | 14 | # important to get the jars installed 15 | s.platform = 'java' 16 | 17 | s.files = Dir['lib/**/*.rb'] 18 | s.files += Dir['lib/*.jar'] 19 | s.files += Dir['*.file'] 20 | s.files += Dir['*.gemspec'] 21 | 22 | s.required_ruby_version = '>= 2.6' 23 | 24 | s.requirements << 'jar org.slf4j, slf4j-api, 1.7.7' 25 | s.requirements << 'jar org.slf4j, slf4j-simple, 1.7.7, :scope => :test' 26 | 27 | s.add_runtime_dependency 'jar-dependencies', "~> #{Jars::VERSION}" 28 | s.metadata['rubygems_mfa_required'] = 'true' 29 | end 30 | -------------------------------------------------------------------------------- /integration/gemspec_with_system_jar/verify/Mavenfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | inherit 'jar-dependencies:gemspec_with_system_jar:0' do 4 | # TODO: should not be needed with ruby-maven 5 | relative_path '../Mavenfile' 6 | end 7 | 8 | packaging 'pom' 9 | 10 | gem 'jar-dependencies', '${jar-dependencies.version}' 11 | 12 | jruby_plugin :gem, '${jruby.plugins.version}' do 13 | execute_goal :initialize 14 | end 15 | 16 | pom 'org.jruby:jruby', '${jruby.version}' 17 | 18 | plugin('org.codehaus.mojo:exec-maven-plugin', '3.5.0', 19 | executable: :java, 20 | environmentVariables: { 'GEM_HOME' => '${gem.home}', 21 | 'GEM_PATH' => '${gem.home}' }) do 22 | execute_goal(:exec, phase: :test, 23 | arguments: ['-classpath', 24 | xml(''), 25 | 'org.jruby.Main', 26 | 'test.rb']) 27 | end 28 | 29 | properties('gem.home' => '${project.basedir}/../../rubygems', 30 | 'gem.path' => '${gem.home}') 31 | -------------------------------------------------------------------------------- /integration/lock_jars/verify.bsh: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import org.codehaus.plexus.util.FileUtils; 3 | 4 | 5 | String log = FileUtils.fileRead( new File( basedir, "build.log" ) ); 6 | 7 | String expected = "Jars.lock is up to date"; 8 | if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" ); 9 | 10 | File f = new File(basedir, "repository/org/bouncycastle/bcpkix-jdk15on/1.54/bcpkix-jdk15on-1.54.jar"); 11 | if (!f.exists()) throw new RuntimeException( "file " + f + " does not exists" ); 12 | 13 | f = new File(basedir, "repository/org/bouncycastle/bcpkix-jdk15on/1.54/bcpkix-jdk15on-1.54.pom"); 14 | if (!f.exists()) throw new RuntimeException( "file " + f + " does not exists" ); 15 | 16 | f = new File(basedir, "repository/org/bouncycastle/bcprov-jdk15on/1.54/bcprov-jdk15on-1.54.jar"); 17 | if (!f.exists()) throw new RuntimeException( "file " + f + " does not exists" ); 18 | 19 | f = new File(basedir, "repository/org/bouncycastle/bcprov-jdk15on/1.54/bcprov-jdk15on-1.54.pom"); 20 | if (!f.exists()) throw new RuntimeException( "file " + f + " does not exists" ); 21 | -------------------------------------------------------------------------------- /integration/bundle_with_path/Mavenfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | repository id: 'mavengems', url: 'mavengem:https://rubygems.org' 4 | 5 | plugin('org.codehaus.mojo:exec-maven-plugin', '3.5.0', 6 | executable: :java, 7 | environmentVariables: { 'GEM_HOME' => '${gem.home}', 8 | 'GEM_PATH' => '${gem.home}', 9 | 'JARS_VERBOSE' => true }) do 10 | execute_goal(:exec, phase: :compile, 11 | arguments: ['-classpath', 12 | xml(''), 13 | 'org.jruby.Main', 14 | 'bundle.rb']) 15 | end 16 | 17 | properties('gem.home' => '${project.basedir}/../rubygems', 18 | 'gem.path' => '${gem.home}') 19 | 20 | jar 'org.jruby:jruby-complete', '${jruby.version}' 21 | 22 | gem 'jar-dependencies', '${jar-dependencies.version}' 23 | gem 'bundler', '${bundler.version}' 24 | gem 'ruby-maven', '${ruby-maven.version}' 25 | 26 | jruby_plugin :gem, '${jruby.plugins.version}' do 27 | execute_goal :initialize 28 | end 29 | -------------------------------------------------------------------------------- /MIT-LICENSE: -------------------------------------------------------------------------------- 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. 21 | -------------------------------------------------------------------------------- /integration/depending_gems/biglib/Mavenfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | properties('gem.home' => '${basedir}/../pkg', 4 | 'gem.path' => '${gem.home}') 5 | 6 | repository id: 'mavengems', url: 'mavengem:https://rubygems.org' 7 | 8 | pom 'org.jruby:jruby', '${jruby.version}' 9 | 10 | gem 'jar-dependencies', '${jar-dependencies.version}' 11 | gem 'bundler', '${bundler.version}' 12 | gem 'ruby-maven', '${ruby-maven.version}' 13 | gem 'ruby-maven-libs', '3.9.3' 14 | 15 | jruby_plugin :gem, '${jruby.plugins.version}' do 16 | execute_goal :initialize 17 | end 18 | 19 | plugin('org.codehaus.mojo:exec-maven-plugin', '3.5.0', 20 | executable: :java, 21 | environmentVariables: { 'GEM_HOME' => '${gem.home}', 22 | 'GEM_PATH' => '${gem.home}', 23 | 'PATH' => '${gem.home}/bin${path.separator}${env.PATH}' }) do 24 | execute_goal(:exec, phase: :test, 25 | arguments: ['-classpath', 26 | xml(''), 27 | 'org.jruby.Main', 28 | '-S', 'bundle', 'install']) 29 | end 30 | -------------------------------------------------------------------------------- /integration/vendor_jars/Mavenfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | extension 'org.jruby.maven.mojo:mavengem-wagon:2.0.2' 4 | 5 | repository id: :mavengems, url: 'mavengem:https://rubygems.org' 6 | 7 | phase :test do 8 | plugin('org.codehaus.mojo:exec-maven-plugin', '3.5.0', 9 | executable: :java, 10 | environmentVariables: { 'GEM_HOME' => '${gem.home}', 11 | 'GEM_PATH' => '${gem.home}', 12 | 'JARS_VERBOSE' => true }) do 13 | execute_goal(:exec, 14 | id: 'jruby test.rb', 15 | arguments: ['-classpath', 16 | xml(''), 17 | 'org.jruby.Main', 18 | 'test.rb']) 19 | end 20 | end 21 | 22 | properties('gem.home' => '${project.basedir}/../rubygems', 23 | 'gem.path' => '${gem.home}') 24 | 25 | jar 'org.jruby:jruby-complete', '${jruby.version}' 26 | 27 | gem 'jar-dependencies', '${jar-dependencies.version}' 28 | gem 'ruby-maven', '${ruby-maven.version}' 29 | 30 | jruby_plugin :gem, '${jruby.plugins.version}' do 31 | execute_goal :initialize 32 | end 33 | -------------------------------------------------------------------------------- /integration/vendor_jars/verify.bsh: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import org.codehaus.plexus.util.FileUtils; 3 | 4 | 5 | String log = FileUtils.fileRead( new File( basedir, "build.log" ) ); 6 | 7 | String expected = "exclusions: joda-time:joda-time"; 8 | if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" ); 9 | 10 | File f = new File(basedir, "lib/example_jars.rb"); 11 | if (!f.exists()) throw new RuntimeException( "file " + f + " does not exists" ); 12 | 13 | f = new File(basedir, "lib/com/fasterxml/classmate/1.0.0/classmate-1.0.0.jar"); 14 | if (!f.exists()) throw new RuntimeException( "file " + f + " does not exists" ); 15 | 16 | f = new File(basedir, "lib/com/google/guava/guava/18.0/guava-18.0.jar"); 17 | if (!f.exists()) throw new RuntimeException( "file " + f + " does not exists" ); 18 | 19 | f = new File(basedir, "lib/org/glassfish/javax.el/3.0.0/javax.el-3.0.0.jar"); 20 | if (!f.exists()) throw new RuntimeException( "file " + f + " does not exists" ); 21 | 22 | f = new File(basedir, "lib/com/fasterxml/classmate/1.0.0/classmate-1.0.0.jar"); 23 | if (!f.exists()) throw new RuntimeException( "file " + f + " does not exists" ); 24 | -------------------------------------------------------------------------------- /examples/gem-with-jar-dependencies/README.md: -------------------------------------------------------------------------------- 1 | ## setup 2 | 3 | ``` 4 | vendor_jars 5 | ``` 6 | 7 | which is important since it will create a file lib/gem-name_jars.rb 8 | and installs the jar dependencies into a local cache (local maven repository) 9 | 10 | ## lock down version of jar dependencies 11 | 12 | lock down is optional and only needed once you see a warning about a version conflict. if you use maven recommended way of picking a concrete version for a jar then the need for lock_down is almost vanishing as the likelyhood of gems using the jar with different version is very small. 13 | 14 | in case you want or need to lock down your versions for the jars then execute: 15 | 16 | ``` 17 | lock_jars 18 | ``` 19 | 20 | ## pack gem 21 | 22 | ``` 23 | gem build mygem.gemspec 24 | ``` 25 | 26 | ## just run the code 27 | 28 | make sure you use jruby (via rbenv, rvm, etc) 29 | ``` 30 | ruby test.rb 31 | ``` 32 | 33 | ## alternative 34 | 35 | uses jar-dependency gem as runtime dependency in your gemspec and bundler can be an alternative way of setting up such gem: [with bundler](gem-with-jar-dependencies-and-bundler/README.md). also see the discussion on pros and cons and the end of that page. 36 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension/using-ruby-maven/mygem.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # use the version from the main project 4 | require "#{File.dirname File.expand_path(__FILE__)}/../../lib/jars/version" 5 | 6 | Gem::Specification.new do |s| 7 | s.name = File.basename(File.dirname(File.expand_path(__FILE__))) 8 | s.version = '1.0.0' 9 | s.author = ['example person'] 10 | s.email = ['mail@example.com'] 11 | s.summary = "summary of #{s.name}" 12 | s.description = "description of #{s.name}" 13 | 14 | # important to get the jars installed 15 | s.platform = 'java' 16 | 17 | s.files = Dir['lib/**/*.rb'] 18 | s.files += Dir['lib/*.jar'] 19 | s.files += Dir['*.file'] 20 | s.files += Dir['*.gemspec'] 21 | 22 | s.required_ruby_version = '>= 2.6' 23 | 24 | # declare the jar dependencies 25 | s.requirements << 'jar org.slf4j, slf4j-api, 1.7.7' 26 | s.requirements << 'jar org.slf4j, slf4j-simple, 1.7.7, :scope => :test' 27 | 28 | s.add_development_dependency 'rake', '~> 10.3' 29 | # needed to compile src/main/java/** and create jar file 30 | s.add_development_dependency 'ruby-maven', '~> 3.9' 31 | s.metadata['rubygems_mfa_required'] = 'true' 32 | end 33 | -------------------------------------------------------------------------------- /integration/jars_lock_gemspec_with_jars/verify.bsh: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import org.codehaus.plexus.util.FileUtils; 3 | 4 | 5 | String log = FileUtils.fileRead( new File( basedir, "build.log" ) ); 6 | 7 | String expected = "Jars.lock created"; 8 | if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" ); 9 | 10 | expected = "org.apache.hbase:hbase-annotations:jar:"; 11 | if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" ); 12 | 13 | expected = "jdk.tools:jdk.tools:jar:"; 14 | if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" ); 15 | 16 | expected = "com.github.stephenc.findbugs:findbugs-annotations:jar:"; 17 | if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" ); 18 | 19 | expected = "log4j:log4j:jar:"; 20 | if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" ); 21 | 22 | expected = "org.jruby:jruby:jar:"; 23 | if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" ); 24 | -------------------------------------------------------------------------------- /examples/gem-with-java-extension-and-jar-dependencies/using-rake-compiler/mygem.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # use the version from the main project 4 | require "#{File.dirname File.expand_path(__FILE__)}/../../../lib/jars/version" 5 | 6 | Gem::Specification.new do |s| 7 | s.name = File.basename(File.dirname(File.expand_path(__FILE__))) 8 | s.version = '1.0.0' 9 | s.author = ['example person'] 10 | s.email = ['mail@example.com'] 11 | s.summary = "summary of #{s.name}" 12 | s.description = "description of #{s.name}" 13 | 14 | # important to get the jars installed 15 | s.platform = 'java' 16 | 17 | s.files = Dir['lib/**/*.rb'] 18 | s.files += Dir['lib/*.jar'] 19 | s.files += Dir['*.file'] 20 | s.files += Dir['*.gemspec'] 21 | 22 | s.required_ruby_version = '>= 2.6' 23 | 24 | s.requirements << 'jar org.slf4j, slf4j-api, 1.7.7' 25 | s.requirements << 'jar org.slf4j, slf4j-simple, 1.7.7, :scope => :test' 26 | 27 | s.add_runtime_dependency 'jar-dependencies', "~> #{Jars::VERSION}" 28 | 29 | s.add_development_dependency 'rake', '~> 10.3' 30 | # needed to compile ext/** and create jar file 31 | s.add_development_dependency 'rake-compiler', '~> 0.9' 32 | s.metadata['rubygems_mfa_required'] = 'true' 33 | end 34 | -------------------------------------------------------------------------------- /lib/rubygems_plugin.rb: -------------------------------------------------------------------------------- 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 | require 'jars/post_install_hook' 24 | -------------------------------------------------------------------------------- /lib/jar-dependencies.rb: -------------------------------------------------------------------------------- 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' 25 | -------------------------------------------------------------------------------- /examples/sinatra-app/having-gems-with-jar-dependencies/Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | jar-dependencies (0.3.0) 5 | leafy-complete (0.6.2-java) 6 | leafy-health (~> 0.6.2) 7 | leafy-logger (~> 0.6.2) 8 | leafy-metrics (~> 0.6.2) 9 | leafy-rack (~> 0.6.2) 10 | leafy-health (0.6.2-java) 11 | jar-dependencies (~> 0.1) 12 | leafy-logger (0.6.2-java) 13 | jar-dependencies (~> 0.1) 14 | leafy-metrics (~> 0.6.2) 15 | leafy-metrics (0.6.2-java) 16 | jar-dependencies (~> 0.1) 17 | leafy-rack (0.6.2-java) 18 | jar-dependencies (~> 0.1) 19 | leafy-health (~> 0.6.2) 20 | leafy-logger (~> 0.6.2) 21 | leafy-metrics (~> 0.6.2) 22 | rack (1.6.13) 23 | rack-protection (1.5.5) 24 | rack 25 | ruby-maven (3.9.3) 26 | ruby-maven-libs (~> 3.9.9) 27 | ruby-maven-libs (3.9.9) 28 | sinatra (1.4.8) 29 | rack (~> 1.5) 30 | rack-protection (~> 1.4) 31 | tilt (>= 1.3, < 3) 32 | tilt (2.4.0) 33 | 34 | PLATFORMS 35 | universal-java-24 36 | 37 | DEPENDENCIES 38 | jar-dependencies (= 0.3.0) 39 | leafy-complete (= 0.6.2) 40 | ruby-maven (~> 3.9, >= 3.9.3) 41 | sinatra (~> 1.4) 42 | 43 | BUNDLED WITH 44 | 2.5.11 45 | -------------------------------------------------------------------------------- /lib/jar_install_post_install_hook.rb: -------------------------------------------------------------------------------- 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 | require 'jars/post_install_hook' 24 | -------------------------------------------------------------------------------- /examples/sinatra-app/having-jarfile-and-gems-with-jar-dependencies/Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | jar-dependencies (0.3.0) 5 | leafy-complete (0.6.2-java) 6 | leafy-health (~> 0.6.2) 7 | leafy-logger (~> 0.6.2) 8 | leafy-metrics (~> 0.6.2) 9 | leafy-rack (~> 0.6.2) 10 | leafy-health (0.6.2-java) 11 | jar-dependencies (~> 0.1) 12 | leafy-logger (0.6.2-java) 13 | jar-dependencies (~> 0.1) 14 | leafy-metrics (~> 0.6.2) 15 | leafy-metrics (0.6.2-java) 16 | jar-dependencies (~> 0.1) 17 | leafy-rack (0.6.2-java) 18 | jar-dependencies (~> 0.1) 19 | leafy-health (~> 0.6.2) 20 | leafy-logger (~> 0.6.2) 21 | leafy-metrics (~> 0.6.2) 22 | rack (1.6.13) 23 | rack-protection (1.5.5) 24 | rack 25 | ruby-maven (3.9.3) 26 | ruby-maven-libs (~> 3.9.9) 27 | ruby-maven-libs (3.9.9) 28 | sinatra (1.4.8) 29 | rack (~> 1.5) 30 | rack-protection (~> 1.4) 31 | tilt (>= 1.3, < 3) 32 | tilt (2.4.0) 33 | 34 | PLATFORMS 35 | universal-java-24 36 | 37 | DEPENDENCIES 38 | jar-dependencies (= 0.3.0) 39 | leafy-complete (= 0.6.2) 40 | ruby-maven (~> 3.9, >= 3.9.3) 41 | sinatra (~> 1.4) 42 | 43 | BUNDLED WITH 44 | 2.5.11 45 | -------------------------------------------------------------------------------- /integration/lock_jars/Mavenfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | extension 'org.jruby.maven.mojo:mavengem-wagon:2.0.2' 4 | 5 | repository id: :mavengems, url: 'mavengem:https://rubygems.org' 6 | 7 | phase :test do 8 | plugin('org.codehaus.mojo:exec-maven-plugin', '3.5.0', 9 | executable: :java, 10 | environmentVariables: { 'JARS_LOCAL_MAVEN_REPO' => '${basedir}/repository', 11 | 'GEM_HOME' => '${gem.home}', 12 | 'GEM_PATH' => '${gem.home}', 13 | 'JARS_VERBOSE' => true }) do 14 | execute_goal(:exec, 15 | id: 'jruby -S lock_jars', 16 | arguments: ['-classpath', 17 | xml(''), 18 | 'org.jruby.Main', 19 | '${gem.home}/bin/lock_jars', '--tree']) 20 | end 21 | end 22 | 23 | properties('gem.home' => '${project.basedir}/../rubygems', 24 | 'gem.path' => '${gem.home}') 25 | 26 | jar 'org.jruby:jruby-complete', '${jruby.version}' 27 | 28 | gem 'jar-dependencies', '${jar-dependencies.version}' 29 | gem 'ruby-maven', '${ruby-maven.version}' 30 | 31 | jruby_plugin :gem, '${jruby.plugins.version}' do 32 | execute_goal :initialize 33 | end 34 | -------------------------------------------------------------------------------- /integration/require_tests/Mavenfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | packaging 'pom' 4 | 5 | gem 'jar-dependencies', '${jar-dependencies.version}' 6 | 7 | jruby_plugin :gem, '${jruby.plugins.version}' do 8 | execute_goal :initialize 9 | end 10 | 11 | pom 'org.jruby:jruby', '${jruby.version}' 12 | 13 | plugin('org.codehaus.mojo:exec-maven-plugin', '3.5.0', 14 | executable: :java, 15 | environmentVariables: { 'GEM_HOME' => '${gem.home}', 16 | 'GEM_PATH' => '${gem.home}' }) do 17 | execute_goal(:exec, id: 'no more warnings', phase: :test, 18 | arguments: ['-classpath', 19 | xml(''), 20 | 'org.jruby.Main', 21 | 'test_no_more_warnings.rb']) 22 | execute_goal(:exec, id: 'freeze loading', phase: :test, 23 | arguments: ['-classpath', 24 | xml(''), 25 | 'org.jruby.Main', 26 | 'test_freeze_loading.rb']) 27 | execute_goal(:exec, id: 'ignore gemspec on require_jar', phase: :test, 28 | arguments: ['-classpath', 29 | xml(''), 30 | 'org.jruby.Main', 31 | '-I.', '-rjar-dependencies', '-e', 32 | 'require_jar "jline", "jline", "2.11"']) 33 | end 34 | 35 | properties('gem.home' => '${project.basedir}/pkg/rubygems', 36 | 'gem.path' => '${gem.home}') 37 | -------------------------------------------------------------------------------- /examples/sinatra-app/having-gems-with-jar-dependencies/app/views/person.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <%= @person.firstname %> <%= @person.surname %> 5 | 6 | 36 | 37 | 38 | 39 |

person

40 | 41 |
42 | Firstname 43 |
44 | 45 |
46 | Surname 47 |
48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /jar-dependencies.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative 'lib/jars/version' 4 | 5 | Gem::Specification.new do |s| 6 | s.name = 'jar-dependencies' 7 | 8 | s.version = Jars::VERSION 9 | 10 | s.author = 'christian meier' 11 | s.email = ['mkristian@web.de'] 12 | s.summary = 'manage jar dependencies for gems' 13 | s.homepage = 'https://github.com/mkristian/jar-dependencies' 14 | 15 | s.bindir = 'exe' 16 | s.executables = [lock_jars = 'lock_jars'] 17 | 18 | s.license = 'MIT' 19 | 20 | s.files = Dir['{lib}/**/*'] + %w[Mavenfile Rakefile Readme.md jar-dependencies.gemspec MIT-LICENSE] 21 | 22 | s.description = <<~TEXT 23 | manage jar dependencies for gems and keep track which jar was already 24 | loaded using maven artifact coordinates. it warns on version conflicts and 25 | loads only ONE jar assuming the first one is compatible to the second one 26 | otherwise your project needs to lock down the right version by providing a 27 | Jars.lock file. 28 | TEXT 29 | 30 | s.required_ruby_version = '>= 2.6' 31 | 32 | s.add_development_dependency 'minitest', '~> 5.10' 33 | s.add_development_dependency 'ruby-maven', ruby_maven_version = '~> 3.9' 34 | 35 | s.post_install_message = <<~TEXT 36 | 37 | if you want to use the executable #{lock_jars} then install ruby-maven gem before using #{lock_jars} 38 | 39 | $ gem install ruby-maven -v '#{ruby_maven_version}' 40 | 41 | or add it as a development dependency to your Gemfile 42 | 43 | gem 'ruby-maven', '#{ruby_maven_version}' 44 | 45 | TEXT 46 | s.metadata['rubygems_mfa_required'] = 'true' 47 | end 48 | -------------------------------------------------------------------------------- /lib/jars/post_install_hook.rb: -------------------------------------------------------------------------------- 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 | if defined?(JRUBY_VERSION) && Gem.post_install_hooks.empty? 25 | Gem.post_install do |gem_installer| 26 | if ENV['JARS_SKIP'] != 'true' && ENV_JAVA['jars.skip'] != 'true' 27 | require 'jars/installer' 28 | jars = Jars::Installer.new(gem_installer.spec) 29 | jars.ruby_maven_install_options = gem_installer.options || {} 30 | jars.vendor_jars 31 | end 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /examples/sinatra-app/having-jarfile-and-gems-with-jar-dependencies/app/views/person.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <%= @person.firstname %> <%= @person.surname %> 5 | 6 | 36 | 37 | 38 | 39 |

person

40 | 41 |
42 | Firstname 43 |
44 | 45 |
46 | Surname 47 |
48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /specs/maven_exec_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require File.expand_path('setup', File.dirname(__FILE__)) 4 | 5 | require 'jars/maven_exec' 6 | require 'fileutils' 7 | require 'stringio' 8 | 9 | describe Jars::MavenExec do 10 | let(:pwd) { File.dirname(File.expand_path(__FILE__)) } 11 | 12 | let(:example_spec) { File.join(pwd, '..', 'example', 'example.gemspec') } 13 | let(:spec_with_require_relative) do 14 | File.join(pwd, 'example', 'gem_with_require_relative', 'gem_with_require_relative.gemspec') 15 | end 16 | 17 | after do 18 | Jars.reset 19 | end 20 | 21 | it 'should not warn if gemspec contains require_relative' do 22 | Dir.chdir File.dirname(spec_with_require_relative) do 23 | $stderr = StringIO.new 24 | Jars::MavenExec.new 25 | _($stderr.string).must_equal '' 26 | ensure 27 | $stderr = STDERR 28 | end 29 | end 30 | 31 | it 'finds the gemspec file when the Gem::Specification.spec_file is wrong' do 32 | spec = Dir.chdir(File.dirname(example_spec)) do 33 | eval(File.read(example_spec)) # rubocop:disable Security/Eval 34 | end 35 | 36 | spec.loaded_from = spec.spec_file 37 | # mimic bundler case 38 | FileUtils.rm_f(spec.spec_file) 39 | def spec.gem_dir=(dir) 40 | @d = dir 41 | end 42 | 43 | def spec.gem_dir 44 | @d 45 | end 46 | spec.gem_dir = File.dirname(example_spec) 47 | # now test finding the gemspec file 48 | jar = Jars::MavenExec.new(spec) 49 | _(jar.instance_variable_get(:@basedir)).must_equal File.expand_path(spec.gem_dir) 50 | _(jar.instance_variable_get(:@specfile)).must_equal File.expand_path(example_spec) 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /integration/install_ruby_maven_when_needed/verify/Mavenfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | inherit 'jar-dependencies:install-ruby-maven:0' do 4 | # TODO: should not be needed with ruby-maven 5 | relative_path '../Mavenfile' 6 | end 7 | 8 | packaging 'pom' 9 | 10 | jar 'org.jruby:jruby-complete', '${jruby.version}' 11 | 12 | plugin('org.codehaus.mojo:exec-maven-plugin', '3.5.0', 13 | executable: :java, 14 | environmentVariables: { 'GEM_HOME' => '${gem.home}', 15 | 'GEM_PATH' => '${gem.home}', 16 | 'JARS_VERBOSE' => true, 17 | 'BUNDLER_GEMFILE' => '${basedir}/Gemfile', 18 | 'PATH' => '${gem.home}/bin${path.separator}${env.PATH}' }) do 19 | execute_goal(:exec, id: 'gem install', phase: :test, 20 | arguments: ['-classpath', 21 | xml(''), 22 | 'org.jruby.Main', 'test_gem.rb', '${jar-dependencies.version}']) 23 | execute_goal(:exec, id: 'bundle install', phase: :test, 24 | arguments: ['-classpath', 25 | xml(''), 26 | 'org.jruby.Main', 'test_bundler.rb', '${jar-dependencies.version}']) 27 | end 28 | 29 | properties('gem.home' => '${project.basedir}/../../rubygems', 30 | 'gem.path' => '${gem.home}') 31 | 32 | repository id: 'mavengems', url: 'mavengem:https://rubygems.org' 33 | 34 | gem 'jar-dependencies', '${jar-dependencies.version}' 35 | gem 'bundler', '${bundler.version}' 36 | 37 | jruby_plugin :gem, '${jruby.plugins.version}' do 38 | execute_goal :initialize 39 | end 40 | -------------------------------------------------------------------------------- /integration/gemspec_with_classifier_and_exclusions/Mavenfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | repository id: 'mavengems', url: 'mavengem:https://rubygems.org' 4 | 5 | plugin('org.codehaus.mojo:exec-maven-plugin', '3.5.0', 6 | executable: :java, 7 | environmentVariables: { 'GEM_HOME' => '${gem.home}', 8 | 'GEM_PATH' => '${gem.home}', 9 | 'JARS_VERBOSE' => true }) do 10 | execute_goal(:exec, 11 | id: 'Jars::Classpath.require', 12 | phase: :compile, 13 | arguments: ['-classpath', 14 | xml(''), 15 | 'org.jruby.Main', 16 | '-rjars/classpath', 17 | '-e', 18 | 'Jars::Classpath.require(:test);$CLASSPATH.each { |c| p c }']) 19 | execute_goal(:exec, 20 | id: 'lock_jars --tree', 21 | phase: :compile, 22 | arguments: ['-classpath', 23 | xml(''), 24 | 'org.jruby.Main', 25 | '${gem.home}/bin/lock_jars', 26 | '--tree']) 27 | 28 | # TODO: more tests on Jars::Classpath.require(:test) etc 29 | end 30 | 31 | properties('gem.home' => '${project.basedir}/../rubygems', 32 | 'gem.path' => '${gem.home}') 33 | 34 | jar 'org.jruby:jruby-complete', '${jruby.version}' 35 | 36 | gem 'jar-dependencies', '${jar-dependencies.version}' 37 | gem 'bundler', '${bundler.version}' 38 | gem 'ruby-maven', '${ruby-maven.version}' 39 | 40 | jruby_plugin :gem, '${jruby.plugins.version}' do 41 | execute_goal :initialize 42 | end 43 | -------------------------------------------------------------------------------- /settings-example.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | maven-central-mirror 15 | 16 | central 17 | https://artifactory.example.com/artifactory/all 18 | 19 | 20 | 21 | 22 | 23 | mavencentral 24 | 33 | 34 | 35 | central 36 | http://central 37 | 38 | true 39 | 40 | 41 | true 42 | 43 | 44 | 45 | 46 | 47 | central 48 | http://central 49 | 50 | true 51 | 52 | 53 | true 54 | 55 | 56 | 57 | 58 | 59 | 60 | mavencentral 61 | 62 | 63 | -------------------------------------------------------------------------------- /exe/lock_jars: -------------------------------------------------------------------------------- 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) 55 | -------------------------------------------------------------------------------- /examples/sinatra-app/having-gems-with-jar-dependencies/app/hellowarld.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'sinatra' 4 | require 'json' 5 | require 'ostruct' 6 | require 'leafy/metrics' 7 | require 'leafy/health' 8 | require 'leafy/instrumented/instrumented' 9 | require 'leafy/instrumented/collected_instrumented' 10 | require 'leafy/rack/admin' 11 | require 'leafy/rack/instrumented' 12 | 13 | Data = Struct.new(:surname, :firstname) 14 | data = Data.new('meier', 'christian') 15 | 16 | configure do 17 | metrics = Leafy::Metrics::Registry.new 18 | health = Leafy::Health::Registry.new 19 | 20 | use(Leafy::Rack::Admin, metrics, health) 21 | use(Leafy::Rack::Metrics, metrics) 22 | use(Leafy::Rack::Health, health) 23 | use(Leafy::Rack::Ping) 24 | use(Leafy::Rack::ThreadDump) 25 | use(Leafy::Rack::Instrumented, Leafy::Instrumented::Instrumented.new(metrics, 'webapp')) 26 | use(Leafy::Rack::Instrumented, Leafy::Instrumented::CollectedInstrumented.new(metrics, 'collected')) 27 | 28 | metrics.register_gauge('app.data_length') do 29 | data.surname.length + data.firstname.length 30 | end 31 | 32 | health.register('app.health') do 33 | 'stored names are too short' if data.surname.length + data.firstname.length < 4 34 | end 35 | 36 | set :histogram, metrics.register_histogram('app.name_length') 37 | end 38 | 39 | get '/app' do 40 | p @person = data 41 | erb :person 42 | end 43 | 44 | get '/person' do 45 | p @person = data 46 | content_type 'application/json' 47 | { surname: data.surname, firstname: data.firstname }.to_json 48 | end 49 | 50 | patch '/person' do 51 | payload = JSON.parse request.body.read 52 | data.send :"#{payload.keys.first}=", payload.values.first 53 | settings.histogram.update(data.surname.length + data.firstname.length) 54 | status 205 55 | end 56 | -------------------------------------------------------------------------------- /integration/jars_lock_gemfile/Mavenfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | repository id: 'mavengems', url: 'mavengem:https://rubygems.org' 4 | 5 | # gemfile 6 | 7 | gem 'leafy-metrics', '0.6.1' 8 | 9 | gem! 'bundler', '${bundler.version}' 10 | 11 | phase :test do 12 | plugin('org.codehaus.mojo:exec-maven-plugin', '3.5.0', 13 | executable: :java, 14 | environmentVariables: { 'GEM_HOME' => '${gem.home}', 15 | 'GEM_PATH' => '${gem.home}', 16 | 'JARS_VERBOSE' => true }) do 17 | execute_goal(:exec, 18 | id: 'jruby -S lock_jars', 19 | arguments: ['-classpath', 20 | xml(''), 21 | 'org.jruby.Main', 22 | '${gem.home}/bin/lock_jars', '--tree']) 23 | execute_goal(:exec, 24 | id: 'jruby test.rb', 25 | arguments: ['-classpath', 26 | xml(''), 27 | 'org.jruby.Main', 28 | 'test.rb']) 29 | execute_goal(:exec, 30 | id: 'jruby -r jars/setup test.rb', 31 | arguments: ['-classpath', 32 | xml(''), 33 | 'org.jruby.Main', 34 | '-rjars/setup', 'test.rb']) 35 | end 36 | end 37 | 38 | properties('gem.home' => '${project.basedir}/../rubygems', 39 | 'gem.path' => '${gem.home}') 40 | 41 | jar 'org.jruby:jruby-complete', '${jruby.version}' 42 | 43 | gem 'jar-dependencies', '${jar-dependencies.version}' 44 | gem 'ruby-maven', '${ruby-maven.version}' 45 | 46 | jruby_plugin :gem, '${jruby.plugins.version}' do 47 | execute_goal :initialize 48 | end 49 | -------------------------------------------------------------------------------- /examples/gem-with-jar-dependencies-and-bundler/README.md: -------------------------------------------------------------------------------- 1 | ## setup 2 | 3 | ``` 4 | bundle 5 | ``` 6 | 7 | which is important since it will create a file lib/gem-name_jars.rb 8 | and installs the jar dependencies into a local cache (local maven repository) 9 | 10 | ## lock down version of jar dependencies 11 | 12 | lock down is optional only needed when there is a version conflict actually happening. (see [gem with jar dependency]((gem-with-jar-dependencies-and-bundler/README.md#lock down version of jar dependencies)) 13 | 14 | in case you want or need to lock down your versions for the jars then execute: 15 | 16 | ``` 17 | lock_jars 18 | ``` 19 | 20 | ## pack gem 21 | 22 | ``` 23 | gem build mygem.gemspec 24 | ``` 25 | 26 | ## just run the code 27 | 28 | make sure you use jruby (via rbenv, rvm, etc) 29 | ``` 30 | ruby test.rb 31 | ``` 32 | 33 | 34 | ## pros and cons 35 | 36 | in the past there was problems with debian openjdk8 package which did not install the ca-certs in the java keystore and could not talk to maven central. the blame went naturally to the jar-dependencies project. 37 | 38 | all in all vendoring jars within the gem is the recommended way of doing things, as the eco-system of gems with such jars using jar-dependencies is not so huge to playout the pros and it is unlikely to run into extra trouble while installing the gem. 39 | 40 | ### pros 41 | 42 | - no jars get vendored inside the gem 43 | - gems and jars are more or less treated a like 44 | - you share the jars via the local maven repo between projects and/or gems 45 | 46 | ### cons 47 | 48 | - any problem with installing the jars during gem install is very hard to debug 49 | - any restricted access to the rubygems respository server needs to acompanied by the access rights for maven-central 50 | - proxy support for downloading jar might be buggy 51 | -------------------------------------------------------------------------------- /examples/sinatra-app/having-jarfile-and-gems-with-jar-dependencies/app/hellowarld.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'sinatra' 4 | require 'json' 5 | require 'ostruct' 6 | require 'leafy/metrics' 7 | require 'leafy/health' 8 | require 'leafy/instrumented/instrumented' 9 | require 'leafy/instrumented/collected_instrumented' 10 | require 'leafy/rack/admin' 11 | require 'leafy/rack/instrumented' 12 | 13 | Data = Struct.new(:surname, :firstname) 14 | data = Data.new('meier', 'christian') 15 | 16 | configure do 17 | metrics = Leafy::Metrics::Registry.new 18 | health = Leafy::Health::Registry.new 19 | 20 | use(Leafy::Rack::Admin, metrics, health) 21 | use(Leafy::Rack::Metrics, metrics) 22 | use(Leafy::Rack::Health, health) 23 | use(Leafy::Rack::Ping) 24 | use(Leafy::Rack::ThreadDump) 25 | use(Leafy::Rack::Instrumented, Leafy::Instrumented::Instrumented.new(metrics, 'webapp')) 26 | use(Leafy::Rack::Instrumented, Leafy::Instrumented::CollectedInstrumented.new(metrics, 'collected')) 27 | 28 | metrics.register_gauge('app.data_length') do 29 | data.surname.length + data.firstname.length 30 | end 31 | 32 | health.register('app.health') do 33 | 'stored names are too short' if data.surname.length + data.firstname.length < 4 34 | end 35 | 36 | set :histogram, metrics.register_histogram('app.name_length') 37 | end 38 | 39 | get '/app' do 40 | p @person = data 41 | erb :person 42 | end 43 | 44 | get '/person' do 45 | p @person = data 46 | content_type 'application/json' 47 | { surname: data.surname, firstname: data.firstname }.to_json 48 | end 49 | 50 | patch '/person' do 51 | payload = JSON.parse request.body.read 52 | data.send :"#{payload.keys.first}=", payload.values.first 53 | settings.histogram.update(data.surname.length + data.firstname.length) 54 | status 205 55 | end 56 | -------------------------------------------------------------------------------- /example/settings.xml.example: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | local-mirror 16 | 18 | external:*,!mavengems 19 | http://localhost:8081/nexus/content/groups/public 20 | 21 | 22 | 23 | 24 | 25 | local 26 | 35 | 36 | 37 | central 38 | http://central 39 | 40 | true 41 | 42 | 43 | true 44 | 45 | 46 | 47 | 48 | 49 | central 50 | http://central 51 | 52 | true 53 | 54 | 55 | true 56 | 57 | 58 | 59 | 60 | 61 | 62 | local 63 | 64 | 65 | -------------------------------------------------------------------------------- /lib/jars/lock.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'jars/maven_exec' 4 | 5 | module Jars 6 | class JarDetails < Array 7 | def scope 8 | self[-2].to_sym 9 | end 10 | 11 | def file 12 | file = self[-1].strip 13 | file.empty? ? path : file 14 | end 15 | 16 | def group_id 17 | self[0] 18 | end 19 | 20 | def artifact_id 21 | self[1] 22 | end 23 | 24 | def version 25 | self[-3] 26 | end 27 | 28 | def classifier 29 | return nil if size == 5 30 | 31 | self[2] 32 | end 33 | 34 | def gacv 35 | classifier ? self[0..3] : self[0..2] 36 | end 37 | 38 | def path 39 | if scope == :system 40 | # replace maven like system properties embedded into the string 41 | self[-1].gsub(/\$\{[a-zA-Z.]+\}/) do |a| 42 | ENV_JAVA[a[2..-2]] || a 43 | end 44 | else 45 | File.join(Jars.home, group_id.gsub(/[.]/, '/'), artifact_id, version, "#{gacv[1..].join('-')}.jar") 46 | end 47 | end 48 | end 49 | 50 | class Lock 51 | def initialize(file) 52 | @file = file 53 | end 54 | 55 | def process(scope) 56 | scope ||= :runtime 57 | File.read(@file).each_line do |line| 58 | next unless /:.+:/.match?(line) 59 | 60 | jar = JarDetails.new(line.strip.sub(/:jar:/, ':').sub(/:$/, ': ').split(':')) 61 | case scope 62 | when :all, :test 63 | yield jar 64 | when :compile 65 | # jar.scope is maven scope 66 | yield jar if jar.scope != :test 67 | when :provided 68 | # jar.scope is maven scope 69 | yield jar if jar.scope == :provided 70 | when :runtime 71 | # jar.scope is maven scope 72 | yield jar if (jar.scope != :test) && (jar.scope != :provided) 73 | end 74 | end 75 | end 76 | end 77 | end 78 | -------------------------------------------------------------------------------- /examples/sinatra-app/having-gems-with-jar-dependencies/Jars.lock: -------------------------------------------------------------------------------- 1 | io.dropwizard.metrics:metrics-healthchecks:3.1.0:compile: 2 | org.slf4j:slf4j-api:1.7.7:compile: 3 | io.dropwizard.metrics:metrics-jvm:3.1.0:compile: 4 | io.dropwizard.metrics:metrics-core:3.1.0:compile: 5 | io.dropwizard.metrics:metrics-graphite:3.1.0:compile: 6 | io.dropwizard:dropwizard-logging:0.8.0-rc5:compile: 7 | io.dropwizard:dropwizard-jackson:0.8.0-rc5:compile: 8 | com.google.guava:guava:18.0:compile: 9 | io.dropwizard:dropwizard-util:0.8.0-rc5:compile: 10 | com.google.code.findbugs:jsr305:3.0.0:compile: 11 | com.fasterxml.jackson.core:jackson-core:2.5.1:compile: 12 | com.fasterxml.jackson.datatype:jackson-datatype-jdk7:2.5.1:compile: 13 | com.fasterxml.jackson.datatype:jackson-datatype-guava:2.5.1:compile: 14 | com.fasterxml.jackson.module:jackson-module-afterburner:2.5.1:compile: 15 | com.fasterxml.jackson.datatype:jackson-datatype-joda:2.5.1:compile: 16 | io.dropwizard:dropwizard-validation:0.8.0-rc5:compile: 17 | org.hibernate:hibernate-validator:5.1.3.Final:compile: 18 | javax.validation:validation-api:1.1.0.Final:compile: 19 | org.jboss.logging:jboss-logging:3.1.3.GA:compile: 20 | com.fasterxml:classmate:1.0.0:compile: 21 | org.glassfish:javax.el:3.0.0:compile: 22 | io.dropwizard.metrics:metrics-logback:3.1.0:compile: 23 | org.slf4j:jul-to-slf4j:1.7.10:compile: 24 | ch.qos.logback:logback-core:1.1.2:compile: 25 | ch.qos.logback:logback-classic:1.1.2:compile: 26 | org.slf4j:log4j-over-slf4j:1.7.10:compile: 27 | org.slf4j:jcl-over-slf4j:1.7.10:compile: 28 | org.eclipse.jetty:jetty-util:9.2.9.v20150224:compile: 29 | io.dropwizard:dropwizard-configuration:0.8.0-rc5:compile: 30 | com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.5.1:compile: 31 | org.apache.commons:commons-lang3:3.3.2:compile: 32 | io.dropwizard.metrics:metrics-json:3.1.0:compile: 33 | com.fasterxml.jackson.core:jackson-databind:2.4.2:compile: 34 | com.fasterxml.jackson.core:jackson-annotations:2.4.0:compile: 35 | -------------------------------------------------------------------------------- /examples/sinatra-app/having-jarfile-and-gems-with-jar-dependencies/Jars.lock: -------------------------------------------------------------------------------- 1 | com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.5.1:compile: 2 | com.fasterxml.jackson.core:jackson-core:2.5.1:compile: 3 | com.fasterxml.jackson.core:jackson-databind:2.4.2:compile: 4 | com.fasterxml.jackson.core:jackson-annotations:2.4.0:compile: 5 | org.yaml:snakeyaml:1.14:compile: 6 | io.dropwizard.metrics:metrics-healthchecks:3.1.0:compile: 7 | org.slf4j:slf4j-api:1.7.7:compile: 8 | io.dropwizard:dropwizard-jackson:0.8.0-rc5:compile: 9 | com.google.guava:guava:18.0:compile: 10 | io.dropwizard:dropwizard-util:0.8.0-rc5:compile: 11 | com.google.code.findbugs:jsr305:3.0.0:compile: 12 | joda-time:joda-time:2.7:compile: 13 | com.fasterxml.jackson.datatype:jackson-datatype-jdk7:2.5.1:compile: 14 | com.fasterxml.jackson.datatype:jackson-datatype-guava:2.5.1:compile: 15 | com.fasterxml.jackson.module:jackson-module-afterburner:2.5.1:compile: 16 | com.fasterxml.jackson.datatype:jackson-datatype-joda:2.5.1:compile: 17 | ch.qos.logback:logback-classic:1.1.2:compile: 18 | ch.qos.logback:logback-core:1.1.2:compile: 19 | com.fasterxml:classmate:1.0.0:compile: 20 | org.slf4j:slf4j-simple:1.7.13:compile: 21 | io.dropwizard:dropwizard-configuration:0.8.0-rc5:compile: 22 | io.dropwizard:dropwizard-validation:0.8.0-rc5:compile: 23 | org.hibernate:hibernate-validator:5.1.3.Final:compile: 24 | javax.validation:validation-api:1.1.0.Final:compile: 25 | org.jboss.logging:jboss-logging:3.1.3.GA:compile: 26 | org.glassfish:javax.el:3.0.0:compile: 27 | org.apache.commons:commons-lang3:3.3.2:compile: 28 | io.dropwizard.metrics:metrics-json:3.1.0:compile: 29 | io.dropwizard.metrics:metrics-core:3.1.0:compile: 30 | io.dropwizard.metrics:metrics-graphite:3.1.0:compile: 31 | io.dropwizard.metrics:metrics-jvm:3.1.0:compile: 32 | org.slf4j:jcl-over-slf4j:1.7.10:compile: 33 | org.slf4j:log4j-over-slf4j:1.7.10:compile: 34 | org.slf4j:jul-to-slf4j:1.7.10:compile: 35 | io.dropwizard:dropwizard-logging:0.8.0-rc5:compile: 36 | io.dropwizard.metrics:metrics-logback:3.1.0:compile: 37 | org.eclipse.jetty:jetty-util:9.2.9.v20150224:compile: 38 | -------------------------------------------------------------------------------- /integration/jars_lock_gemspec_with_jars/Mavenfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | repository id: 'mavengems', url: 'mavengem:https://rubygems.org' 4 | 5 | phase :test do 6 | plugin('org.codehaus.mojo:exec-maven-plugin', '3.5.0', 7 | executable: :java, 8 | environmentVariables: { 'GEM_HOME' => '${gem.home}', 9 | 'GEM_PATH' => '${gem.home}', 10 | 'JARS_VERBOSE' => true }) do 11 | # need to uninstall bundler otherwise it finds the Gemfile from the project 12 | # root. bundler does descend the directory until it finds a Gemfile. 13 | execute_goal(:exec, 14 | id: 'jruby -S gem uninstall -a bundler', 15 | arguments: ['-classpath', 16 | xml(''), 17 | 'org.jruby.Main', 18 | '-S', 'gem', 'uninstall', '-a', 'bundler']) 19 | execute_goal(:exec, 20 | id: 'jruby -S lock_jars', 21 | arguments: ['-classpath', 22 | xml(''), 23 | 'org.jruby.Main', 24 | '${gem.home}/bin/lock_jars', '--tree']) 25 | execute_goal(:exec, 26 | id: 'jruby test.rb', 27 | arguments: ['-classpath', 28 | xml(''), 29 | 'org.jruby.Main', 30 | 'test.rb']) 31 | execute_goal(:exec, 32 | id: 'jruby -r jars/setup test.rb', 33 | arguments: ['-classpath', 34 | xml(''), 35 | 'org.jruby.Main', 36 | '-rjars/setup', 'test.rb']) 37 | end 38 | end 39 | 40 | properties('gem.home' => '${project.basedir}/../rubygems', 41 | 'gem.path' => '${gem.home}') 42 | 43 | jar 'org.jruby:jruby-complete', '${jruby.version}' 44 | 45 | gem 'jar-dependencies', '${jar-dependencies.version}' 46 | gem 'ruby-maven', '${ruby-maven.version}' 47 | 48 | jruby_plugin :gem, '${jruby.plugins.version}' do 49 | execute_goal :initialize 50 | end 51 | -------------------------------------------------------------------------------- /Mavenfile: -------------------------------------------------------------------------------- 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 | gem 'ruby-maven', '${ruby-maven.version}' 10 | end 11 | 12 | # retrieve the ruby-maven version 13 | gemfile_profile = @model.profiles.detect do |p| 14 | p.id.to_sym == :gemfile 15 | end || @model 16 | ruby_maven = gemfile_profile.dependencies.detect do |d| 17 | d.artifact_id == 'ruby-maven' 18 | end 19 | 20 | properties('jruby.versions' => ['${jruby.version}'].join(','), 21 | # just lock the version 22 | 'bundler.version' => '2.5.11', 23 | 'ruby-maven.version' => ruby_maven.version, 24 | 'jruby.version' => '9.4.8.0', 25 | 'jruby.plugins.version' => '3.0.2', 26 | 'push.skip' => true) 27 | 28 | plugin :invoker, '1.8' do 29 | execute_goals(:install, :run, 30 | id: 'integration-tests', 31 | projectsDirectory: 'integration', 32 | streamLogs: true, 33 | goals: ['install'], 34 | preBuildHookScript: 'setup.bsh', 35 | postBuildHookScript: 'verify.bsh', 36 | cloneProjectsTo: '${project.build.directory}', 37 | properties: { 'jar-dependencies.version' => '${project.version}', 38 | # use an old jruby with old ruby-maven here 39 | 'jruby.version' => '${jruby.version}', 40 | 'jruby.plugins.version' => '${jruby.plugins.version}', 41 | 'bundler.version' => '${bundler.version}', 42 | 'ruby-maven.version' => '${ruby-maven.version}' }) 43 | end 44 | 45 | distribution_management do 46 | repository id: :ossrh, url: 'https://oss.sonatype.org/service/local/staging/deploy/maven2/' 47 | end 48 | 49 | profile id: :skip do 50 | properties 'maven.test.skip' => true, 'invoker.skip' => true 51 | end 52 | 53 | profile id: :release do 54 | properties 'maven.test.skip' => true, 'invoker.skip' => true, 'push.skip' => false 55 | 56 | build do 57 | default_goal :deploy 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /example/example.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Gem::Specification.new do |s| 4 | # this is only needed to retrieve the latest version of jar-dependencies 5 | # so this can run as integration-test 6 | version = ENV_JAVA['jar-dependencies.version'] || '0.3.0' 7 | 8 | s.name = 'example' 9 | s.version = '2' 10 | s.author = 'example person' 11 | s.email = ['mail@example.com'] 12 | s.summary = 'gem with jar' 13 | s.description = 'gem with empty jar and jar dependencies' 14 | 15 | # important so jar-dependencies knows it should look for 16 | # jar declarations in the requirements section ! 17 | s.platform = 'java' 18 | 19 | s.files << Dir['lib/**/*.rb'] 20 | s.files << 'lib/example.jar' 21 | s.files << Dir['*file'] 22 | s.files << 'example.gemspec' 23 | 24 | s.required_ruby_version = '>= 2.6' 25 | 26 | # constrain the version of jar-dependencies itself 27 | s.add_runtime_dependency 'jar-dependencies', "~> #{version}" 28 | 29 | # the jar declarations 30 | s.requirements << 'jar org.bouncycastle:bcpkix-jdk15on, 1.49' 31 | s.requirements << 'jar org.bouncycastle:bcprov-jdk15on, 1.49' 32 | s.requirements << 'jar org.slf4j:slf4j-api, 1.7.7' 33 | 34 | # dependency where some transitive dependency gets excluded (jruby comes 35 | # with joda-time already bundled and this can cause classloader conflicts. 36 | # better just use the version of joda-time from jruby and hope it is 37 | # compatible) 38 | s.requirements << 'jar io.dropwizard:dropwizard-logging, 0.8.0-rc5, :exclusions=> [ joda-time:joda-time ]' 39 | 40 | # a jar dependency with a classifier 41 | s.requirements << 'jar com.google.protobuf:protobuf-java, 2.2.0, :classifier => lite' 42 | 43 | # needed for the tests 44 | s.requirements << 'jar junit:junit:4.12, :scope => :test' 45 | # this is part of the test and assumed to be provided during runtime 46 | s.requirements << 'jar org.slf4j:slf4j-simple, 1.7.7, :scope => :provided' 47 | 48 | s.add_development_dependency 'rake', '~> 10.3' 49 | s.add_development_dependency 'rspec', '~> 2.14' 50 | 51 | # needed to compile src/main/java/** into lib/example.jar 52 | s.add_development_dependency 'rake-compiler', '~> 0.9' 53 | 54 | # avoids to install it on the fly when jar-dependencies needs it 55 | s.add_development_dependency 'ruby-maven', '~> 3.9', '>= 3.9.3' 56 | s.metadata['rubygems_mfa_required'] = 'true' 57 | end 58 | -------------------------------------------------------------------------------- /integration/vendor_jars/my.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Gem::Specification.new do |s| 4 | # this is only needed to retrieve the latest version of jar-dependencies 5 | # so this can run as integration-test 6 | version = ENV_JAVA['jar-dependencies.version'] || '0.3.0' 7 | 8 | s.name = 'example' 9 | s.version = '2' 10 | s.author = 'example person' 11 | s.email = ['mail@example.com'] 12 | s.summary = 'gem with jar' 13 | s.description = 'gem with empty jar and jar dependencies' 14 | 15 | # important so jar-dependencies knows it should look for 16 | # jar declarations in the requirements section ! 17 | s.platform = 'java' 18 | 19 | s.files << Dir['lib/**/*.rb'] 20 | s.files << 'lib/example.jar' 21 | s.files << Dir['*file'] 22 | s.files << 'example.gemspec' 23 | 24 | s.required_ruby_version = '>= 2.6' 25 | 26 | # constrain the version of jar-dependencies itself 27 | s.add_runtime_dependency 'jar-dependencies', "~> #{version}" 28 | 29 | # the jar declarations 30 | s.requirements << 'jar org.bouncycastle:bcpkix-jdk15on, 1.49' 31 | s.requirements << 'jar org.bouncycastle:bcprov-jdk15on, 1.49' 32 | s.requirements << 'jar org.slf4j:slf4j-api, 1.7.7' 33 | 34 | # dependency where some transitive dependency gets excluded (jruby comes 35 | # with joda-time already bundled and this can cause classloader conflicts. 36 | # better just use the version of joda-time from jruby and hope it is 37 | # compatible) 38 | s.requirements << 'jar io.dropwizard:dropwizard-logging, 0.8.0-rc5, :exclusions=> [ joda-time:joda-time ]' 39 | 40 | # a jar dependency with a classifier 41 | s.requirements << 'jar com.google.protobuf:protobuf-java, 2.2.0, :classifier => lite' 42 | 43 | # needed for the tests 44 | s.requirements << 'jar junit:junit:4.12, :scope => :test' 45 | # this is part of the test and assumed to be provided during runtime 46 | s.requirements << 'jar org.slf4j:slf4j-simple, 1.7.7, :scope => :provided' 47 | 48 | s.add_development_dependency 'rake', '~> 10.3' 49 | s.add_development_dependency 'rspec', '~> 2.14' 50 | 51 | # needed to compile src/main/java/** into lib/example.jar 52 | s.add_development_dependency 'rake-compiler', '~> 0.9' 53 | 54 | # avoids to install it on the fly when jar-dependencies needs it 55 | s.add_development_dependency 'ruby-maven', '~> 3.9', '>= 3.9.3' 56 | s.metadata['rubygems_mfa_required'] = 'true' 57 | end 58 | -------------------------------------------------------------------------------- /lib/jars/classpath.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'jars/maven_exec' 4 | require 'jars/lock' 5 | require 'fileutils' 6 | 7 | module Jars 8 | class Classpath 9 | # convenient method 10 | def self.require(scope = nil) 11 | new.require(scope) 12 | end 13 | 14 | # convenient method 15 | def self.classpath(scope = nil) 16 | new.classpath(scope) 17 | end 18 | 19 | # convenient method 20 | def self.classpath_string(scope = nil) 21 | new.classpath_string(scope) 22 | end 23 | 24 | def initialize(spec = nil, deps = nil) 25 | @spec = spec 26 | @deps = deps 27 | end 28 | 29 | def mvn 30 | @mvn ||= MavenExec.new(@spec) 31 | end 32 | 33 | def workdir(dirname) 34 | dir = File.join(mvn.basedir, dirname) 35 | dir if File.directory?(dir) 36 | end 37 | 38 | def dependencies_list 39 | if @deps.nil? 40 | deps = Jars.lock_path(mvn.basedir) 41 | @deps = deps if deps && File.exist?(deps) 42 | end 43 | @deps || resolve_dependencies 44 | end 45 | private :dependencies_list 46 | 47 | DEPENDENCY_LIST = 'dependencies.list' 48 | def resolve_dependencies 49 | basedir = workdir('pkg') || workdir('target') || workdir('') 50 | deps = File.join(basedir, DEPENDENCY_LIST) 51 | mvn.resolve_dependencies_list(deps) 52 | deps 53 | end 54 | private :resolve_dependencies 55 | 56 | def require(scope = nil) 57 | process(scope) do |jar| 58 | if jar.scope == :system 59 | Kernel.require jar.path 60 | else 61 | require_jar(*jar.gacv) 62 | end 63 | end 64 | return unless scope.nil? || scope == :runtime 65 | 66 | process(:provided) do |jar| 67 | Jars.mark_as_required(*jar.gacv) 68 | end 69 | end 70 | 71 | def classpath(scope = nil) 72 | classpath = [] 73 | process(scope) do |jar| 74 | classpath << jar.file 75 | end 76 | classpath 77 | end 78 | 79 | def process(scope, &block) 80 | deps = dependencies_list 81 | Lock.new(deps).process(scope, &block) 82 | ensure 83 | # just delete the temporary file if it exists 84 | FileUtils.rm_f(DEPENDENCY_LIST) 85 | end 86 | private :process 87 | 88 | def classpath_string(scope = nil) 89 | classpath(scope).join(File::PATH_SEPARATOR) 90 | end 91 | end 92 | end 93 | -------------------------------------------------------------------------------- /lib/jars/maven_exec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'jar_dependencies' 4 | require 'jars/maven_factory' 5 | 6 | module Jars 7 | class MavenExec 8 | def find_spec(allow_no_file) 9 | specs = Dir['*.gemspec'] 10 | case specs.size 11 | when 0 12 | raise 'no gemspec found' unless allow_no_file 13 | when 1 14 | specs.first 15 | else 16 | raise 'more then one gemspec found. please specify a specfile' unless allow_no_file 17 | end 18 | end 19 | private :find_spec 20 | 21 | attr_reader :basedir, :spec, :specfile 22 | 23 | def initialize(spec = nil) 24 | @options = {} 25 | setup(spec) 26 | rescue StandardError, LoadError => e 27 | # If spec load fails, skip looking for jar-dependencies 28 | warn "jar-dependencies: #{e}" 29 | warn e.backtrace.join("\n") if Jars.verbose? 30 | end 31 | 32 | def setup(spec = nil, allow_no_file: false) 33 | spec ||= find_spec(allow_no_file) 34 | 35 | case spec 36 | when String 37 | @specfile = File.expand_path(spec) 38 | @basedir = File.dirname(@specfile) 39 | Dir.chdir(@basedir) do 40 | spec = eval(File.read(@specfile), TOPLEVEL_BINDING, @specfile) # rubocop:disable Security/Eval 41 | end 42 | when Gem::Specification 43 | if File.exist?(spec.loaded_from) 44 | @basedir = spec.gem_dir 45 | @specfile = spec.loaded_from 46 | else 47 | # this happens with bundle and local gems 48 | # there the spec_file is "not installed" but inside 49 | # the gem_dir directory 50 | Dir.chdir(spec.gem_dir) do 51 | setup(nil, allow_no_file: true) 52 | end 53 | end 54 | when nil 55 | # ignore 56 | else 57 | Jars.debug('spec must be either String or Gem::Specification. ' \ 58 | 'File an issue on github if you need it.') 59 | end 60 | @spec = spec 61 | end 62 | 63 | def ruby_maven_install_options=(options) 64 | @options = options 65 | end 66 | 67 | def resolve_dependencies_list(file) 68 | factory = MavenFactory.new(@options) 69 | maven = factory.maven_new(File.expand_path('gemspec_pom.rb', __dir__)) 70 | 71 | is_local_file = File.expand_path(File.dirname(@specfile)) == File.expand_path(Dir.pwd) 72 | maven.attach_jars(@spec, all_dependencies: is_local_file) 73 | 74 | maven['jars.specfile'] = @specfile.to_s 75 | maven['outputAbsoluteArtifactFilename'] = 'true' 76 | maven['includeTypes'] = 'jar' 77 | maven['outputScope'] = 'true' 78 | maven['useRepositoryLayout'] = 'true' 79 | maven['outputDirectory'] = Jars.home.to_s 80 | maven['outputFile'] = file.to_s 81 | 82 | maven.exec('dependency:copy-dependencies', 'dependency:list') 83 | end 84 | end 85 | end 86 | -------------------------------------------------------------------------------- /specs/maven_factory_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require File.expand_path('setup', File.dirname(__FILE__)) 4 | 5 | require 'jars/maven_factory' 6 | 7 | describe Jars::MavenFactory do 8 | after do 9 | ENV['JARS_VERBOSE'] = nil 10 | ENV['JARS_DEBUG'] = nil 11 | ENV['JARS_MAVEN_SETTINGS'] = nil 12 | Jars.reset 13 | end 14 | 15 | it 'uses logging config' do 16 | ENV['JARS_VERBOSE'] = nil 17 | ENV['JARS_DEBUG'] = nil 18 | Jars.reset 19 | maven = Jars::MavenFactory.new.maven_new('pom') 20 | _(maven.options.key?('--quiet')).must_equal true 21 | _(maven.options.key?('-X')).must_equal false 22 | _(maven.options['-Dverbose']).must_equal false 23 | 24 | ENV['JARS_VERBOSE'] = 'true' 25 | ENV['JARS_DEBUG'] = nil 26 | Jars.reset 27 | maven = Jars::MavenFactory.new.maven_new('pom') 28 | _(maven.options.key?('--quiet')).must_equal false 29 | _(maven.options.key?('-e')).must_equal true 30 | _(maven.options.key?('-X')).must_equal false 31 | _(maven.options['-Dverbose']).must_equal true 32 | 33 | ENV['JARS_VERBOSE'] = nil 34 | ENV['JARS_DEBUG'] = 'true' 35 | Jars.reset 36 | maven = Jars::MavenFactory.new.maven_new('pom') 37 | _(maven.options.key?('--quiet')).must_equal false 38 | _(maven.options.key?('-e')).must_equal false 39 | _(maven.options.key?('-X')).must_equal true 40 | _(maven.options['-Dverbose']).must_equal true 41 | 42 | ENV['JARS_VERBOSE'] = 'true' 43 | ENV['JARS_DEBUG'] = 'true' 44 | Jars.reset 45 | maven = Jars::MavenFactory.new.maven_new('pom') 46 | _(maven.options.key?('--quiet')).must_equal false 47 | _(maven.options.key?('-e')).must_equal true 48 | _(maven.options.key?('-X')).must_equal true 49 | _(maven.options['-Dverbose']).must_equal true 50 | end 51 | 52 | it 'uses proxy settings from Gem.configuration' do 53 | skip('pending until it realy works') 54 | ENV['JARS_MAVEN_SETTINGS'] = 'specs/does/no/exists/settings.xml' 55 | Gem.configuration[:proxy] = 'https://localhost:3128' 56 | Jars.reset 57 | maven = Jars::MavenFactory.new.maven_new('pom') 58 | _(maven.options.key?('-DproxySet=true')).must_equal true 59 | _(maven.options.key?('-DproxyHost=localhost')).must_equal true 60 | _(maven.options.key?('-DproxyPort=3128')).must_equal true 61 | 62 | Gem.configuration[:proxy] = :noproxy 63 | Jars.reset 64 | maven = Jars::MavenFactory.new.maven_new('pom') 65 | _(maven.options.key?('-DproxySet=true')).must_equal false 66 | _(maven.options.key?('-DproxyHost=localhost')).must_equal false 67 | _(maven.options.key?('-DproxyPort=3128')).must_equal false 68 | 69 | ENV['JARS_MAVEN_SETTINGS'] = 'specs/settings.xml' 70 | Gem.configuration[:proxy] = 'https://localhost:3128' 71 | Jars.reset 72 | maven = Jars::MavenFactory.new.maven_new('pom') 73 | _(maven.options.key?('-DproxySet=true')).must_equal false 74 | _(maven.options.key?('-DproxyHost=localhost')).must_equal false 75 | _(maven.options.key?('-DproxyPort=3128')).must_equal false 76 | end 77 | end 78 | -------------------------------------------------------------------------------- /example/Readme.md: -------------------------------------------------------------------------------- 1 | # walkthrough # 2 | 3 | (assume all commands will be executed via jruby !) 4 | 5 | bundle install 6 | lock_jars 7 | rake 8 | rake package 9 | 10 | * bundler will lock down the gem dependencies and generates the *_jars.rb file 11 | * lock\_jars does create JArs.lock file the version lock down of the 12 | jar dependencies. see ```lock_jars --help``` for more options. 13 | * the default rake task compile the java files and runs the specs after it 14 | * the rake task compiles the java files and builds the jar of the gem 15 | and packs everything into a gem 16 | 17 | now install the gem and look at the installed content 18 | 19 | gem install -l pkg/example-2-java.gem 20 | gem content example 21 | 22 | during installation the dependent jars get vendored (not the jar 23 | extension which is already part of the packed gem itself). 24 | 25 | to run the spec do (after ```bundle install```) 26 | 27 | bundle exec rake 28 | 29 | or 30 | 31 | bundle exec rake compile 32 | bundle exec rspec spec/*spec.rb 33 | 34 | 35 | if you look into the gem itself it just contains the following files: 36 | 37 | . 38 | ├── example.gemspec 39 | ├── lib│ 40 | | ├── example 41 | │ │ └── bc_info.rb 42 | │ ├── example.jar 43 | │ ├── example_jars.rb 44 | │ └── example.rb 45 | └── Rakefile 46 | 47 | and the installed gem looks like this 48 | 49 | . 50 | ├── Gemfile 51 | ├── Rakefile 52 | ├── example.gemspec 53 | └── lib 54 | ├── example 55 | │ └── bc_info.rb 56 | ├── example.jar 57 | ├── example.rb 58 | ├── example_jars.rb 59 | └── org 60 | ├── bouncycastle 61 | | ├── bcpkix-jdk15on 62 | │ │ └── 1.49 63 | │ │ └── bcpkix-jdk15on-1.49.jar 64 | │ └── bcprov-jdk15on 65 | │ └── 1.49 66 | │ └── bcprov-jdk15on-1.49.jar 67 | └── slf4j 68 | └── slf4j-api 69 | └── 1.7.7 70 | └── slf4j-api-1.7.7.jar 71 | 72 | in order to use the jar dependencies for development you need to run 73 | 74 | rake compile 75 | 76 | which builds the **lib/example.jar** and 77 | 78 | bundle install 79 | 80 | generates the **lib/example_jars.rb**. this file adds the jar dependencies to jruby's runtime when required. 81 | 82 | during development the jars will be stored in **$HOME/.m2/repository** 83 | (the maven default location). this local-maven-repository can be 84 | configured with the settings.xml from the project or at 85 | **$HOME/.m2/settings.xml**. from the local-maven-repository the jars 86 | get loaded. whenever you install the gem via bundler or rubygems then the 87 | jars will vendored inside the gem. 88 | 89 | in case you do not want to vendor your jars during installation, then you can set the environment **export JRUBY\_JARS\_VENDOR=false**. then the installed gem looks exactly like during development. 90 | 91 | in any case the execution of the example.rb file produces the same output. the local development 92 | 93 | $ jruby -Ilib -r example/bc_info -e 'puts Example.bc_info' 94 | 95 | or via the installed gem 96 | 97 | $ jruby -r example/bc_info -e 'puts Example.bc_info' 98 | 99 | gives: 100 | 101 | BouncyCastle Security Provider v1.49 102 | 103 | for mirror or proxy settings either use the settings.xml from the 104 | project or from $HOME/.m2/settings.xml and see maven documentions on 105 | more details on this and the settings.xml.example of here. 106 | -------------------------------------------------------------------------------- /lib/jars/lock_down.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'fileutils' 4 | require 'jar_dependencies' 5 | require 'jars/version' 6 | require 'jars/maven_factory' 7 | require 'jars/gemspec_artifacts' 8 | 9 | module Jars 10 | class LockDown 11 | attr_reader :debug, :verbose 12 | 13 | def initialize(debug, verbose) 14 | @debug = debug 15 | @verbose = verbose 16 | end 17 | 18 | def maven_new 19 | factory = MavenFactory.new({}, @debug, @verbose) 20 | pom = File.expand_path('lock_down_pom.rb', __dir__) 21 | m = factory.maven_new(pom) 22 | m['jruby.plugins.version'] = Jars::JRUBY_PLUGINS_VERSION 23 | m['dependency.plugin.version'] = Jars::DEPENDENCY_PLUGIN_VERSION 24 | m['jars.basedir'] = File.expand_path(basedir) 25 | jarfile = File.expand_path(Jars.jarfile) 26 | m['jars.jarfile'] = jarfile if File.exist?(jarfile) 27 | attach_jar_coordinates_from_bundler_dependencies(m) 28 | m 29 | end 30 | private :maven_new 31 | 32 | def maven 33 | @maven ||= maven_new 34 | end 35 | 36 | def basedir 37 | File.expand_path('.') 38 | end 39 | 40 | def attach_jar_coordinates_from_bundler_dependencies(maven) 41 | load_path = $LOAD_PATH.dup 42 | require 'bundler' 43 | # TODO: make this group a commandline option 44 | Bundler.setup('default') 45 | maven.property('jars.bundler', true) 46 | cwd = File.expand_path('.') 47 | Gem.loaded_specs.each do |_name, spec| 48 | # if gemspec is local then include all dependencies 49 | maven.attach_jars(spec, all_dependencies: cwd == spec.full_gem_path) 50 | end 51 | rescue LoadError => e 52 | if Jars.verbose? 53 | warn e.message 54 | warn 'no bundler found - ignore Gemfile if exists' 55 | end 56 | rescue Bundler::GemfileNotFound 57 | # do nothing then as we have bundler but no Gemfile 58 | rescue Bundler::GemNotFound 59 | warn "can not setup bundler with #{Bundler.default_lockfile}" 60 | raise 61 | ensure 62 | $LOAD_PATH.replace(load_path) 63 | end 64 | 65 | def lock_down(vendor_dir = nil, force: false, update: false, tree: nil) 66 | out = File.expand_path('.jars.output') 67 | tree_provided = tree 68 | tree ||= File.expand_path('.jars.tree') 69 | maven.property('jars.outputFile', out) 70 | maven.property('maven.repo.local', Jars.local_maven_repo) 71 | maven.property('jars.home', File.expand_path(vendor_dir)) if vendor_dir 72 | maven.property('jars.lock', File.expand_path(Jars.lock)) 73 | maven.property('jars.force', force) 74 | maven.property('jars.update', update) if update 75 | # tell not to use Jars.lock as part of POM when running mvn 76 | maven.property('jars.skip.lock', true) 77 | 78 | args = ['gem:jars-lock'] 79 | args += ['dependency:tree', '-P -gemfile.lock', "-DoutputFile=#{tree}"] if tree_provided 80 | 81 | puts 82 | puts '-- jar root dependencies --' 83 | puts 84 | status = maven.exec(*args) 85 | exit 1 unless status 86 | if File.exist?(tree) 87 | puts 88 | puts '-- jar dependency tree --' 89 | puts 90 | puts File.read(tree) 91 | puts 92 | end 93 | puts 94 | puts File.read(out).gsub("#{File.dirname(out)}/", '') 95 | puts 96 | ensure 97 | FileUtils.rm_f out 98 | FileUtils.rm_f tree 99 | end 100 | end 101 | end 102 | -------------------------------------------------------------------------------- /specs/jar_installer_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require File.expand_path('setup', File.dirname(__FILE__)) 4 | 5 | require 'jars/installer' 6 | require 'fileutils' 7 | require 'rubygems/specification' 8 | 9 | module Jars 10 | class Installer 11 | def do_install(vendor, write) 12 | @vendor = vendor 13 | @write = write 14 | end 15 | 16 | attr_reader :vendor, :write 17 | end 18 | end 19 | describe Jars::Installer do 20 | let(:file) { File.join(pwd, 'deps.txt') } 21 | 22 | let(:pwd) { File.dirname(File.expand_path(__FILE__)) } 23 | 24 | let(:dir) { File.join(pwd, '..', 'pkg', 'tmp') } 25 | 26 | let(:jars) { File.join(dir, 'test_jars.rb') } 27 | 28 | let(:example_spec) { File.join(pwd, '..', 'example', 'example.gemspec') } 29 | 30 | before do 31 | FileUtils.rm_rf(dir) 32 | FileUtils.mkdir_p(dir) 33 | end 34 | 35 | it 'loads dependencies from maven' do 36 | deps = Jars::Installer.load_from_maven(file) 37 | _(deps.size).must_equal 45 38 | deps.each { |d| _(d).must_be_kind_of(Jars::Installer::Dependency) } 39 | end 40 | 41 | it 'generates non-vendored require-file' do 42 | deps = Jars::Installer.load_from_maven(file) 43 | Jars::Installer.write_require_jars(deps, jars) 44 | File.read(jars).each_line do |line| 45 | _(line).must_match(/^\s{2}require(_jar)?\s'.+'$/) if line.size > 30 && !line.match(/^#/) 46 | end 47 | _( Dir[File.join(dir, '**')].size ).must_equal 1 48 | end 49 | 50 | it 'generates vendored require-file' do 51 | deps = Jars::Installer.load_from_maven(file) 52 | Jars::Installer.write_require_jars(deps, jars) 53 | Jars::Installer.vendor_jars(deps, dir) 54 | File.read(jars).each_line do |line| 55 | _(line).must_match(/^\s{2}require(_jar)?\s'.+'$/) if line.size > 30 && !line.match(/^#/) 56 | end 57 | _( Dir[File.join(dir, '**', '*.jar')].size ).must_equal 45 58 | end 59 | 60 | it 'just skips install_jars and vendor_jars if there are no requirements' do 61 | jar = Jars::Installer.new 62 | jar.install_jars 63 | # vendor method is a mocked method 64 | _(jar.vendor).must_be_nil 65 | jar.vendor_jars 66 | # vendor method is a mocked method 67 | _(jar.vendor).must_be_nil 68 | end 69 | 70 | it 'just skips install_jars and vendor_jars if platform is not java' do 71 | spec = Gem::Specification.load(example_spec) 72 | spec.platform = 'ruby' 73 | jar = Jars::Installer.new(spec) 74 | jar.install_jars 75 | # vendor method is a mocked method 76 | _(jar.vendor).must_be_nil 77 | jar.vendor_jars 78 | # vendor method is a mocked method 79 | _(jar.vendor).must_be_nil 80 | end 81 | 82 | it 'does install_jars and vendor_jars' do 83 | ENV['JARS_VENDOR'] = nil 84 | jar = Jars::Installer.new(example_spec) 85 | jar.install_jars 86 | # vendor method is a mocked method 87 | assert_nil jar.vendor 88 | ENV['JARS_VENDOR'] = 'false' 89 | jar.vendor_jars 90 | # vendor method is a mocked method 91 | assert_nil jar.vendor 92 | ENV['JARS_VENDOR'] = 'true' 93 | jar.vendor_jars 94 | # vendor method is a mocked method 95 | _(jar.vendor).must_equal 'lib' 96 | java.lang.System.set_property('jars.vendor', 'false') 97 | jar.vendor_jars 98 | # vendor method is a mocked method 99 | assert_nil jar.vendor 100 | end 101 | 102 | it 'installs dependencies ' do 103 | ENV['JARS_HOME'] = dir 104 | Jars.reset 105 | jar = Jars::Installer.new(example_spec) 106 | result = jar.send :install_dependencies 107 | _(result.size).must_equal 30 108 | result.each do |d| 109 | _(d.type).must_equal :jar 110 | _(d.scope).must_equal :runtime 111 | end 112 | ENV['JARS_HOME'] = nil 113 | end 114 | end 115 | -------------------------------------------------------------------------------- /specs/deps.txt: -------------------------------------------------------------------------------- 1 | 2 | The following files have been resolved: 3 | org.apache.maven:maven-repository-metadata:jar:3.1.0:compile:specs/deps/maven-repository-metadata-3.1.0.jar 4 | com.google.code.findbugs:jsr305:jar:1.3.9:compile:specs/deps/jsr305-1.3.9.jar 5 | org.slf4j:slf4j-api:jar:1.6.2:compile:specs/deps/slf4j-api-1.6.2.jar 6 | org.eclipse.sisu:org.eclipse.sisu.plexus:jar:0.0.0.M2a:compile:specs/deps/org.eclipse.sisu.plexus-0.0.0.M2a.jar 7 | org.apache.httpcomponents:httpcore:jar:4.2.3:compile:specs/deps/httpcore-4.2.3.jar 8 | com.google.inject:guice:jar:3.0:compile:specs/deps/guice-3.0.jar 9 | javax.annotation:jsr250-api:jar:1.0:compile:specs/deps/jsr250-api-1.0.jar 10 | com.google.guava:guava:jar:10.0.1:compile:specs/deps/guava-10.0.1.jar 11 | org.eclipse.sisu:org.eclipse.sisu.inject:jar:0.0.0.M2a:compile:specs/deps/org.eclipse.sisu.inject-0.0.0.M2a.jar 12 | commons-logging:commons-logging:jar:1.1.1:compile:specs/deps/commons-logging-1.1.1.jar 13 | org.apache.maven:maven-settings:jar:3.1.0:compile:specs/deps/maven-settings-3.1.0.jar 14 | org.apache.maven.wagon:wagon-file:jar:2.4:compile:specs/deps/wagon-file-2.4.jar 15 | org.eclipse.aether:aether-connector-wagon:jar:0.9.0.M2:compile:specs/deps/aether-connector-wagon-0.9.0.M2.jar 16 | org.eclipse.aether:aether-impl:jar:0.9.0.M2:compile:specs/deps/aether-impl-0.9.0.M2.jar 17 | com.ning:async-http-client:jar:1.7.6:compile:specs/deps/async-http-client-1.7.6.jar 18 | org.apache.maven.wagon:wagon-http-shared4:jar:2.4:compile:specs/deps/wagon-http-shared4-2.4.jar 19 | org.eclipse.aether:aether-util:jar:0.9.0.M2:compile:specs/deps/aether-util-0.9.0.M2.jar 20 | commons-io:commons-io:jar:2.0.1:compile:specs/deps/commons-io-2.0.1.jar 21 | org.apache.httpcomponents:httpclient:jar:4.2.3:compile:specs/deps/httpclient-4.2.3.jar 22 | org.sonatype.sisu:sisu-guice:jar:no_aop:3.1.0:compile:specs/deps/sisu-guice-3.1.0-no_aop.jar 23 | org.sonatype.plexus:plexus-cipher:jar:1.4:compile:specs/deps/plexus-cipher-1.4.jar 24 | org.eclipse.aether:aether-connector-file:jar:0.9.0.M2:compile:specs/deps/aether-connector-file-0.9.0.M2.jar 25 | org.apache.maven:maven-model:jar:3.1.0:compile:specs/deps/maven-model-3.1.0.jar 26 | org.sonatype.plexus:plexus-sec-dispatcher:jar:1.3:compile:specs/deps/plexus-sec-dispatcher-1.3.jar 27 | org.jboss.interceptor:jboss-interceptor-api:jar:1.1:compile:specs/deps/jboss-interceptor-api-1.1.jar 28 | org.eclipse.aether:aether-spi:jar:0.9.0.M2:compile:specs/deps/aether-spi-0.9.0.M2.jar 29 | org.apache.maven:maven-settings-builder:jar:3.1.0:compile:specs/deps/maven-settings-builder-3.1.0.jar 30 | org.codehaus.plexus:plexus-classworlds:jar:2.4:compile:specs/deps/plexus-classworlds-2.4.jar 31 | org.apache.maven:maven-aether-provider:jar:3.1.0:compile:specs/deps/maven-aether-provider-3.1.0.jar 32 | org.apache.maven.wagon:wagon-provider-api:jar:1.0:compile:specs/deps/wagon-provider-api-1.0.jar 33 | javax.inject:javax.inject:jar:1:compile:specs/deps/javax.inject-1.jar 34 | io.netty:netty:jar:3.4.4.Final:compile:specs/deps/netty-3.4.4.Final.jar 35 | org.apache.maven:maven-model-builder:jar:3.1.0:compile:specs/deps/maven-model-builder-3.1.0.jar 36 | org.codehaus.plexus:plexus-component-annotations:jar:1.5.5:compile:specs/deps/plexus-component-annotations-1.5.5.jar 37 | org.apache.maven.wagon:wagon-http:jar:2.4:compile:specs/deps/wagon-http-2.4.jar 38 | org.codehaus.plexus:plexus-utils:jar:3.0.10:compile:specs/deps/plexus-utils-3.0.10.jar 39 | aopalliance:aopalliance:jar:1.0:compile:specs/deps/aopalliance-1.0.jar 40 | org.eclipse.aether:aether-api:jar:0.9.0.M2:compile:specs/deps/aether-api-0.9.0.M2.jar 41 | org.eclipse.aether:aether-connector-asynchttpclient:jar:0.9.0.M2:compile:specs/deps/aether-connector-asynchttpclient-0.9.0.M2.jar 42 | org.jsoup:jsoup:jar:1.7.1:compile:specs/deps/jsoup-1.7.1.jar 43 | org.sonatype.sisu:sisu-guava:jar:0.9.9:compile:specs/deps/sisu-guava-0.9.9.jar 44 | org.codehaus.plexus:plexus-interpolation:jar:1.16:compile:specs/deps/plexus-interpolation-1.16.jar 45 | javax.enterprise:cdi-api:jar:1.0:compile:specs/deps/cdi-api-1.0.jar 46 | asm:asm:jar:3.3.1:compile:specs/deps/asm-3.3.1.jar 47 | commons-codec:commons-codec:jar:1.6:compile:specs/deps/commons-codec-1.6.jar 48 | 49 | -------------------------------------------------------------------------------- /lib/jars/maven_factory.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'jar_dependencies' 4 | require 'jars/gemspec_artifacts' 5 | 6 | module Jars 7 | class MavenFactory 8 | module AttachJars 9 | def attach_jars(spec, all_dependencies: false) 10 | @index ||= 0 11 | @done ||= [] 12 | 13 | deps = GemspecArtifacts.new(spec) 14 | deps.artifacts.each do |a| 15 | # for this gemspec we want to include all artifacts but 16 | # for all others we want to exclude provided and test artifacts 17 | next unless !@done.include?(a.key) && (all_dependencies || ((a.scope != 'provided') && (a.scope != 'test'))) 18 | 19 | # ruby dsl is not working reliably for classifier 20 | self["jars.#{@index}"] = a.to_coord_no_classifier 21 | if a.exclusions 22 | jndex = 0 23 | a.exclusions.each do |ex| 24 | self["jars.#{@index}.exclusions.#{jndex}"] = ex.to_s 25 | jndex += 1 26 | end 27 | end 28 | self["jars.#{@index}.scope"] = a.scope if a.scope 29 | self["jars.#{@index}.classifier"] = a.classifier if a.classifier 30 | @index += 1 31 | @done << a.key 32 | end 33 | end 34 | end 35 | 36 | attr_reader :debug, :verbose 37 | 38 | def initialize(options = nil, debug = Jars.debug?, verbose = Jars.verbose?) 39 | @options = (options || {}).dup 40 | @options.delete(:ignore_dependencies) 41 | @debug = debug 42 | @verbose = verbose 43 | @installed_maven = false 44 | end 45 | 46 | def maven_new(pom) 47 | lazy_load_maven 48 | maven = setup(Maven::Ruby::Maven.new) 49 | 50 | maven.extend AttachJars 51 | # TODO: copy pom to tmp dir in case it is not a real file 52 | maven.options['-f'] = pom 53 | maven 54 | end 55 | 56 | private 57 | 58 | def setup(maven) 59 | maven.verbose = @verbose 60 | maven.options['-X'] = nil if @debug 61 | if @verbose 62 | maven.options['-e'] = nil 63 | elsif !@debug 64 | maven.options['--quiet'] = nil 65 | end 66 | maven['verbose'] = (@debug || @verbose) == true 67 | 68 | maven.options['-s'] = Jars::MavenSettings.effective_settings if Jars.maven_settings 69 | 70 | maven['maven.repo.local'] = java.io.File.new(Jars.local_maven_repo).absolute_path.to_s 71 | 72 | maven 73 | end 74 | 75 | def lazy_load_maven 76 | add_gem_to_load_path('ruby-maven') 77 | add_gem_to_load_path('ruby-maven-libs') 78 | if @installed_maven 79 | puts 80 | puts 'using maven for the first time results in maven' 81 | puts 'downloading all its default plugin and can take time.' 82 | puts 'as those plugins get cached on disk and further execution' 83 | puts 'of maven is much faster then the first time.' 84 | puts 85 | end 86 | require 'maven/ruby/maven' 87 | end 88 | 89 | def find_spec_via_rubygems(name, req) 90 | require 'rubygems/dependency' 91 | dep = Gem::Dependency.new(name, req) 92 | dep.matching_specs(true).last 93 | end 94 | 95 | def add_gem_to_load_path(name) 96 | # if the gem is already activated => good 97 | return if Gem.loaded_specs[name] 98 | 99 | # just install gem if needed and add it to the load_path 100 | # and leave activated gems as they are 101 | req = requirement(name) 102 | unless (spec = find_spec_via_rubygems(name, req)) 103 | spec = install_gem(name, req) 104 | end 105 | raise "failed to resolve gem '#{name}' if you're using Bundler add it as a dependency" unless spec 106 | 107 | path = File.join(spec.full_gem_path, spec.require_path) 108 | $LOAD_PATH << path unless $LOAD_PATH.include?(path) 109 | end 110 | 111 | def requirement(name) 112 | jars = Gem.loaded_specs['jar-dependencies'] 113 | dep = jars&.dependencies&.detect { |d| d.name == name } 114 | dep.nil? ? Gem::Requirement.create('>0') : dep.requirement 115 | end 116 | 117 | def install_gem(name, req) 118 | @installed_maven = true 119 | puts "Installing gem '#{name}' . . ." 120 | require 'rubygems/dependency_installer' 121 | inst = Gem::DependencyInstaller.new(@options ||= {}) 122 | inst.install(name, req).first 123 | rescue => e 124 | if Jars.verbose? 125 | warn e.inspect 126 | warn e.backtrace.join("\n") 127 | end 128 | raise "there was an error installing '#{name} (#{req})' " \ 129 | "#{@options[:domain]}. please install it manually: #{e.inspect}" 130 | end 131 | end 132 | end 133 | -------------------------------------------------------------------------------- /lib/jars/maven_settings.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module Jars 4 | class MavenSettings 5 | LINE_SEPARATOR = ENV_JAVA['line.separator'] 6 | 7 | class << self 8 | def local_settings 9 | @_jars_maven_local_settings_ = nil unless instance_variable_defined?(:@_jars_maven_local_settings_) 10 | if @_jars_maven_local_settings_.nil? 11 | settings = Jars.absolute('settings.xml') 12 | @_jars_maven_local_settings_ = 13 | if settings && File.exist?(settings) 14 | settings 15 | else 16 | false 17 | end 18 | end 19 | @_jars_maven_local_settings_ || nil 20 | end 21 | 22 | def user_settings 23 | @_jars_maven_user_settings_ = nil unless instance_variable_defined?(:@_jars_maven_user_settings_) 24 | if @_jars_maven_user_settings_.nil? 25 | if (settings = Jars.absolute(Jars.to_prop(MAVEN_SETTINGS))) 26 | unless File.exist?(settings) 27 | Jars.warn { "configured ENV['#{MAVEN_SETTINGS}'] = '#{settings}' not found" } 28 | settings = false 29 | end 30 | else # use maven default (user) settings 31 | settings = File.join(Jars.user_home, '.m2', 'settings.xml') 32 | settings = false unless File.exist?(settings) 33 | end 34 | @_jars_maven_user_settings_ = settings 35 | end 36 | @_jars_maven_user_settings_ || nil 37 | end 38 | 39 | def effective_settings 40 | @_jars_effective_maven_settings_ = nil unless instance_variable_defined?(:@_jars_effective_maven_settings_) 41 | if @_jars_effective_maven_settings_.nil? 42 | begin 43 | require 'rubygems/request' 44 | 45 | http = Gem::Request.proxy_uri(Gem.configuration[:http_proxy] || Gem::Request.get_proxy_from_env('http')) 46 | https = Gem::Request.proxy_uri(Gem.configuration[:https_proxy] || Gem::Request.get_proxy_from_env('https')) 47 | rescue 48 | Jars.debug('ignore rubygems proxy configuration as rubygems is too old') 49 | end 50 | @_jars_effective_maven_settings_ = if http.nil? && https.nil? 51 | settings 52 | else 53 | setup_interpolated_settings(http, https) || settings 54 | end 55 | end 56 | @_jars_effective_maven_settings_ 57 | end 58 | 59 | def cleanup 60 | File.unlink(effective_settings) if effective_settings != settings 61 | ensure 62 | reset 63 | end 64 | 65 | def reset 66 | instance_variables.each { |var| instance_variable_set(var, nil) } 67 | end 68 | 69 | def settings 70 | @_jars_maven_settings_ = nil unless instance_variable_defined?(:@_jars_maven_settings_) 71 | local_settings || user_settings if @_jars_maven_settings_.nil? 72 | end 73 | 74 | def global_settings 75 | @_jars_maven_global_settings_ = nil unless instance_variable_defined?(:@_jars_maven_global_settings_) 76 | if @_jars_maven_global_settings_.nil? 77 | if (mvn_home = ENV['M2_HOME'] || ENV['MAVEN_HOME']) 78 | settings = File.join(mvn_home, 'conf/settings.xml') 79 | settings = false unless File.exist?(settings) 80 | else 81 | settings = false 82 | end 83 | @_jars_maven_global_settings_ = settings 84 | end 85 | @_jars_maven_global_settings_ || nil 86 | end 87 | 88 | private 89 | 90 | def setup_interpolated_settings(http, https) 91 | proxy = raw_proxy_settings_xml(http, https).gsub("\n", LINE_SEPARATOR) 92 | if settings.nil? 93 | raw = "#{LINE_SEPARATOR}#{proxy}" 94 | else 95 | raw = File.read(settings) 96 | if raw.include?('') 97 | Jars.warn("can not interpolated proxy info for #{settings}") 98 | return 99 | else 100 | raw.sub!('', "#{LINE_SEPARATOR}#{proxy}") 101 | end 102 | end 103 | tempfile = java.io.File.create_temp_file('settings', '.xml') 104 | tempfile.delete_on_exit 105 | File.write(tempfile.path, raw) 106 | tempfile.path 107 | end 108 | 109 | def raw_proxy_settings_xml(http, https) 110 | raw = File.read(File.join(File.dirname(__FILE__), 'settings.xml')) 111 | if http 112 | raw.sub!('__HTTP_ACTIVE__', 'true') 113 | raw.sub!('__HTTP_SERVER__', http.host) 114 | raw.sub!('__HTTP_PORT__', http.port.to_s) 115 | else 116 | raw.sub!('__HTTP_ACTIVE__', 'false') 117 | end 118 | if https 119 | raw.sub!('__HTTPS_ACTIVE__', 'true') 120 | raw.sub!('__HTTPS_SERVER__', https.host) 121 | raw.sub!('__HTTPS_PORT__', https.port.to_s) 122 | else 123 | raw.sub!('__HTTPS_ACTIVE__', 'false') 124 | end 125 | raw 126 | end 127 | end 128 | end 129 | end 130 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | # JRuby projects with jar dependencies 2 | 3 | 4 | ``` 5 | examples 6 | ├── gem-with-jar-dependencies 7 | ├── gem-with-java-extension 8 | │   ├── using-maven 9 | │   ├── using-rake-compiler 10 | │   └── using-ruby-maven 11 | ├── gem-with-java-extension-and-dependencies 12 | │   ├── using-maven 13 | │   ├── using-rake-compiler 14 | │   └── using-ruby-maven 15 | └── sinatra-app 16 | ├── having-gems-with-jar-dependencies 17 | └── having-jarfile-and-gems-with-jar-dependencies 18 | ``` 19 | 20 | to build the java extension you can do it with either proper maven, or 21 | with help of the ruby-maven gem or the rake-compiler gem. 22 | 23 | ## version ranges against a picked version 24 | 25 | jar-dependencies uses maven under the hood to resolve and install jar 26 | dependencies. maven discourages the use of version ranges and without 27 | version ranges there a deterministic version resolution, i.e. there is 28 | way to 29 | [resolve conflicts in maven](https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Transitive_Dependencies) 30 | (see section 'Dependency mediation'). 31 | 32 | so if you use version ranges like rubygems does it, then lock down the 33 | versions of jar dependencies is needed. for this use the command 34 | 35 | ``` 36 | lock_jars 37 | ``` 38 | 39 | from the jar-dependencies plugin. 40 | 41 | ## gem with jar dependencies 42 | 43 | see the project here: [gem with jar dependencies](https://github.com/mkristian/jar-dependencies/tree/master/examples/gem-with-jar-dependencies) 44 | 45 | you need to use bundler in this example. just declare the jar 46 | dependencies inside the gemspec, run 47 | 48 | ``` 49 | bundle install 50 | ``` 51 | 52 | and then you can use them with your ruby code. 53 | 54 | with lock down of the jar versions the setup is 55 | 56 | ``` 57 | bundle install 58 | lock_jars 59 | ``` 60 | 61 | ## gem with java extension 62 | 63 | use can use maven, ruby-maven or rake-compiler to build the 64 | extension. note that there is no jar-dependencies gem involved here. 65 | 66 | ### using maven 67 | 68 | see project here: 69 | [gem with java extension using maven](https://github.com/mkristian/jar-dependencies/tree/master/examples/gem-with-java-extension/using-maven) 70 | 71 | you need maven 3.9.x installed to get it working and the project needs 72 | to prepare maven to use the ruby DSL for maven. this is done by adding 73 | [](.mvn/extensions.xml) to your project. or use maven wrapper []() 74 | 75 | ``` 76 | bundle install 77 | mvn prepare-package 78 | ``` 79 | 80 | to setup your project. 81 | 82 | ### using ruby-maven 83 | 84 | see project here: 85 | [gem with java extension using ruby-maven](https://github.com/mkristian/jar-dependencies/tree/master/examples/gem-with-java-extension/using-ruby-maven) 86 | 87 | use the ruby-maven gem instead of system installed maven. much more ruby 88 | like, no need to have anything installed on the system beside jruby, i.e. 89 | 90 | ``` 91 | bundle install 92 | rake compile 93 | ``` 94 | 95 | to setup your project. 96 | 97 | ### using rake-compiler 98 | 99 | see project here: 100 | [gem with java extension using rake-compiler](https://github.com/mkristian/jar-dependencies/tree/master/examples/gem-with-java-extension/using-rake-compiler) 101 | 102 | just use the rake compiler inside the Rakefile, i.e. 103 | 104 | ``` 105 | bundle install 106 | rake compile 107 | ``` 108 | 109 | to setup your project. 110 | 111 | ## gem with java extension and jar dependencies 112 | 113 | this is more since you might need the jar dependencies and its 114 | transitive dependencies for compiling the gem extension. all these 115 | examples uses the jar dependencies declaration from the gemspec file. 116 | 117 | ### using maven 118 | 119 | see project here: 120 | [gem with java extension and jar dependencies using maven](https://github.com/mkristian/jar-dependencies/tree/master/examples/gem-with-java-extension-and-jar-dependencies/using-maven) 121 | 122 | maven just sets up the compile classpath for building the extension jar 123 | 124 | setup with locked jars 125 | 126 | ``` 127 | bundle install 128 | lock_jars 129 | mvn prepare-package 130 | ``` 131 | 132 | ### using ruby-maven 133 | 134 | see project here: 135 | [gem with java extension and jar dependencies using ruby-maven](https://github.com/mkristian/jar-dependencies/tree/master/examples/gem-with-java-extension-and-jar-dependencies/using-ruby-maven) 136 | 137 | like maven but using ruby-maven instrad. 138 | 139 | setup with locked jars 140 | 141 | ``` 142 | bundle install 143 | lock_jars 144 | rake compile 145 | ``` 146 | 147 | ### using rake-compiler 148 | 149 | see project here: 150 | [gem with java extension and jar dependencies using rake-compiler](https://github.com/mkristian/jar-dependencies/tree/master/examples/gem-with-java-extension-and-jar-dependencies/using-rake-compiler) 151 | 152 | jar-dependencies gems offers a simple way to pass on the classpath to rake-compiler. 153 | 154 | setup with locked jars 155 | 156 | ``` 157 | bundle install 158 | lock_jars 159 | rake compile 160 | ``` 161 | 162 | # summary 163 | 164 | using rake-compiler or ruby-maven is no difference for the user 165 | setting up the gem. 166 | 167 | maven is more to demostrate what is there and it allows to use a gem 168 | project as part of mutli-module maven build keeping the ruby project 169 | as ruby project but still integrate it nicely with maven. 170 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | set MAVEN_CMD_LINE_ARGS=%MAVEN_CONFIG% %* 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | 121 | set WRAPPER_JAR=""%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"" 122 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 123 | 124 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CMD_LINE_ARGS% 125 | if ERRORLEVEL 1 goto error 126 | goto end 127 | 128 | :error 129 | set ERROR_CODE=1 130 | 131 | :end 132 | @endlocal & set ERROR_CODE=%ERROR_CODE% 133 | 134 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 135 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 136 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 137 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 138 | :skipRcPost 139 | 140 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 141 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 142 | 143 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 144 | 145 | exit /B %ERROR_CODE% 146 | -------------------------------------------------------------------------------- /lib/jars/gemspec_artifacts.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module Jars 4 | class MavenVersion < String 5 | class << self 6 | def new(*args) 7 | if args.empty? || (args.size == 1 && args[0].nil?) 8 | nil 9 | else 10 | low, high = convert(args[0]) 11 | low, high = convert(args[1], low, high) if /[=~><]/.match?(args[1]) 12 | if low == high 13 | low 14 | else 15 | super "#{low || '[0'},#{high || ')'}" 16 | end 17 | end 18 | end 19 | 20 | private 21 | 22 | def convert(arg, low = nil, high = nil) 23 | if arg.include?('~>') 24 | val = arg.sub(/~>\s*/, '') 25 | last = val.include?('.') ? val.sub(/\.[0-9]*[a-z]+.*$/, '').sub(/\.[^.]+$/, '.99999') : '99999' 26 | ["[#{snapshot_version(val)}", "#{snapshot_version(last)}]"] 27 | elsif arg.include?('>=') 28 | val = arg.sub(/>=\s*/, '') 29 | ["[#{snapshot_version(val)}", (nil || high)] 30 | elsif arg.include?('<=') 31 | val = arg.sub(/<=\s*/, '') 32 | [(nil || low), "#{snapshot_version(val)}]"] 33 | # treat '!' the same way as '>' since maven can not describe such range 34 | elsif /[!>]/.match?(arg) 35 | val = arg.sub(/[!>]\s*/, '') 36 | ["(#{snapshot_version(val)}", (nil || high)] 37 | elsif arg.include?('<') 38 | val = arg.sub(/<\s*/, '') 39 | [(nil || low), "#{snapshot_version(val)})"] 40 | elsif arg.include?('=') 41 | val = arg.sub(/=\s*/, '') 42 | # for prereleased version pick the maven version (no version range) 43 | if /[a-z]|[A-Z]/.match?(val) 44 | [val, val] 45 | else 46 | ["[#{val}", "#{val}.0.0.0.0.1)"] 47 | end 48 | else 49 | # no conversion here, i.e. assume maven version 50 | [arg, arg] 51 | end 52 | end 53 | 54 | def snapshot_version(val) 55 | if val.match(/[a-z]|[A-Z]/) && !val.match(/-SNAPSHOT|[${}]/) 56 | "#{val}-SNAPSHOT" 57 | else 58 | val 59 | end 60 | end 61 | end 62 | end 63 | 64 | class GemspecArtifacts 65 | class Exclusion 66 | attr_reader :group_id, :artifact_id 67 | 68 | def initialize(line) 69 | @group_id, @artifact_id = line.gsub(/['"]/, '').strip.split(':') 70 | @artifact_id.strip! 71 | end 72 | 73 | def to_s 74 | "#{@group_id}:#{@artifact_id}" 75 | end 76 | end 77 | 78 | class Exclusions < Array 79 | def to_s 80 | "[#{join(', ')}]" 81 | end 82 | 83 | def initialize(line) 84 | super() 85 | line.gsub(/'"|^\s*\[|\]\s*$/, '').split(/,\s*/).each do |exclusion| 86 | self << Exclusion.new(exclusion) 87 | end 88 | freeze 89 | end 90 | end 91 | 92 | class Artifact 93 | attr_reader :type, :group_id, :artifact_id, :classifier, :version, :scope, :exclusions 94 | 95 | ALLOWED_TYPES = %w[jar pom].freeze 96 | 97 | def initialize(options, *args) 98 | @type, @group_id, @artifact_id, @classifier, @version, @exclusions = *args 99 | options.each do |k, v| 100 | instance_variable_set(:"@#{k}", v) 101 | end 102 | end 103 | 104 | def self.new(line) 105 | line = line.strip 106 | index = line.index(/\s/) 107 | return nil if index.nil? 108 | 109 | type = line[0..index].strip 110 | return nil unless ALLOWED_TYPES.member?(type) 111 | 112 | line = line[index..] 113 | line.gsub!(/['"]/, '') 114 | line.strip! 115 | 116 | options = {} 117 | line.sub!(/,\s*:exclusions\s*(:|=>)\s*(\[[^\]]+\])/) do 118 | options[:exclusions] = Exclusions.new(Regexp.last_match(2).strip) 119 | '' 120 | end 121 | line.sub!(/,\s*:([a-z]+)\s*(:|=>)\s*(:?[a-zA-Z0-9_]+)/) do 122 | options[Regexp.last_match(1).to_sym] = Regexp.last_match(3).sub(/^:/, '') 123 | '' 124 | end 125 | exclusions = nil 126 | line.sub!(/[,:]\s*\[(.+:.+,?\s*)+\]$/) do |a| 127 | exclusions = Exclusions.new(a[1..].strip) 128 | '' 129 | end 130 | 131 | line.strip! 132 | line.gsub!(/,\s*/, ':') 133 | 134 | if /[\[()\]]/.match?(line) 135 | index = line.index(/[\[(].+$/) 136 | version = line[index..].sub(/:/, ', ') 137 | line = line[0..index - 1].strip.sub(/:$/, '') 138 | else 139 | index = line.index(/:[^:]+$/) 140 | version = line[index + 1..] 141 | line = line[0..index - 1].strip 142 | end 143 | 144 | case line.count(':') 145 | when 2 146 | group_id, artifact_id, classifier = line.split(':') 147 | when 1 148 | group_id, artifact_id = line.split(':') 149 | classifier = nil 150 | else 151 | warn line 152 | return nil 153 | end 154 | super(options, type, group_id, artifact_id, classifier, version, exclusions) 155 | end 156 | 157 | def to_s 158 | args = [@group_id, @artifact_id] 159 | args << @classifier if @classifier 160 | args << @version 161 | args << @exclusions.to_s if @exclusions 162 | "#{@type} #{group_id}:#{args[1..].join(', ')}" 163 | end 164 | 165 | def to_gacv 166 | args = [@group_id, @artifact_id] 167 | args << @classifier if @classifier 168 | args << @version 169 | args.join(':') 170 | end 171 | 172 | def to_coord_no_classifier 173 | args = [@group_id, @artifact_id] 174 | args << @type 175 | args << MavenVersion.new(@version) 176 | args.join(':') 177 | end 178 | 179 | def to_coord 180 | args = [@group_id, @artifact_id] 181 | args << @classifier if @classifier 182 | args << @type 183 | args << MavenVersion.new(@version) 184 | args.join(':') 185 | end 186 | 187 | def key 188 | args = [@group_id, @artifact_id] 189 | args << @classifier if @classifier 190 | args.join(':') 191 | end 192 | end 193 | 194 | attr_reader :artifacts 195 | 196 | def initialize(spec) 197 | @artifacts = [] 198 | spec.requirements.each do |req| 199 | req.split("\n").each do |line| 200 | if (a = Artifact.new(line)) 201 | @artifacts << a 202 | end 203 | end 204 | end 205 | @artifacts.freeze 206 | end 207 | 208 | def [](index) 209 | @artifacts[index] 210 | end 211 | 212 | def each(&block) 213 | @artifacts.each(&block) 214 | end 215 | 216 | def size 217 | @artifacts.size 218 | end 219 | end 220 | end 221 | -------------------------------------------------------------------------------- /lib/jars/installer.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'jar_dependencies' 4 | require 'jars/maven_exec' 5 | 6 | module Jars 7 | class Installer 8 | class Dependency 9 | attr_reader :path, :file, :gav, :scope, :type, :coord 10 | 11 | def self.new(line) 12 | super if /:jar:|:pom:/.match?(line) 13 | end 14 | 15 | def setup_type(line) 16 | if line.index(':pom:') 17 | @type = :pom 18 | elsif line.index(':jar:') 19 | @type = :jar 20 | end 21 | end 22 | private :setup_type 23 | 24 | def setup_scope(line) 25 | @scope = 26 | case line 27 | when /:provided:/ 28 | :provided 29 | when /:test:/ 30 | :test 31 | else 32 | :runtime 33 | end 34 | end 35 | private :setup_scope 36 | 37 | REG = /:jar:|:pom:|:test:|:compile:|:runtime:|:provided:|:system:/.freeze 38 | EMPTY = '' 39 | def initialize(line) 40 | # remove ANSI escape sequences and module section (https://issues.apache.org/jira/browse/MDEP-974) 41 | line = line.gsub(/\e\[\d*m/, '') 42 | line = line.gsub(/ -- module.*/, '') 43 | 44 | setup_type(line) 45 | 46 | line.strip! 47 | 48 | @coord = line.sub(/:[^:]+:([A-Z]:\\)?[^:]+$/, EMPTY) 49 | first, second = @coord.split(/:#{type}:/) 50 | group_id, artifact_id = first.split(':') 51 | parts = group_id.split('.') 52 | parts << artifact_id 53 | parts << second.split(':')[-1] 54 | @file = line.slice(@coord.length, line.length).sub(REG, EMPTY).strip 55 | last = @file.reverse.index(%r{\\|/}) 56 | parts << line[-last..] 57 | @path = File.join(parts).strip 58 | 59 | setup_scope(line) 60 | 61 | @system = !line.index(':system:').nil? 62 | @gav = @coord.sub(REG, ':') 63 | end 64 | 65 | def system? 66 | @system 67 | end 68 | end 69 | 70 | def self.install_jars(write_require_file: false) 71 | new.install_jars(write_require_file: write_require_file) 72 | end 73 | 74 | def self.load_from_maven(file) 75 | result = [] 76 | File.read(file).each_line do |line| 77 | dep = Dependency.new(line) 78 | result << dep if dep && dep.scope == :runtime 79 | end 80 | result 81 | end 82 | 83 | def self.vendor_file(dir, dep) 84 | return unless !dep.system? && dep.type == :jar && dep.scope == :runtime 85 | 86 | vendored = File.join(dir, dep.path) 87 | FileUtils.mkdir_p(File.dirname(vendored)) 88 | FileUtils.cp(dep.file, vendored) 89 | end 90 | 91 | def self.print_require_jar(file, dep, fallback: false) 92 | return if dep.type != :jar || dep.scope != :runtime 93 | 94 | if dep.system? 95 | file&.puts("require '#{dep.file}'") 96 | elsif dep.scope == :runtime 97 | if fallback 98 | file&.puts(" require '#{dep.path}'") 99 | else 100 | file&.puts(" require_jar '#{dep.gav.gsub(':', "', '")}'") 101 | end 102 | end 103 | end 104 | 105 | COMMENT = '# this is a generated file, to avoid over-writing it just delete this comment' 106 | def self.needs_to_write?(require_filename) 107 | require_filename && (!File.exist?(require_filename) || File.read(require_filename).match(COMMENT)) 108 | end 109 | 110 | def self.write_require_jars(deps, require_filename) 111 | return unless needs_to_write?(require_filename) 112 | 113 | FileUtils.mkdir_p(File.dirname(require_filename)) 114 | File.open(require_filename, 'w') do |f| 115 | f.puts COMMENT 116 | f.puts 'begin' 117 | f.puts " require 'jar_dependencies'" 118 | f.puts 'rescue LoadError' 119 | deps.each do |dep| 120 | # do not use require_jar method 121 | print_require_jar(f, dep, fallback: true) 122 | end 123 | f.puts 'end' 124 | f.puts 125 | f.puts 'if defined? Jars' 126 | deps.each do |dep| 127 | print_require_jar(f, dep) 128 | end 129 | f.puts 'end' 130 | end 131 | end 132 | 133 | def self.vendor_jars(deps, dir) 134 | deps.each do |dep| 135 | vendor_file(dir, dep) 136 | end 137 | end 138 | 139 | def initialize(spec = nil) 140 | @mvn = MavenExec.new(spec) 141 | end 142 | 143 | def spec 144 | @mvn.spec 145 | end 146 | 147 | def vendor_jars(vendor_dir = nil, write_require_file: true) 148 | return unless jars? 149 | 150 | if Jars.to_prop(Jars::VENDOR) == 'false' 151 | vendor_dir = nil 152 | else 153 | vendor_dir ||= spec.require_path 154 | end 155 | do_install(vendor_dir, write_require_file) 156 | end 157 | 158 | def self.vendor_jars!(vendor_dir = nil) 159 | new.vendor_jars!(vendor_dir) 160 | end 161 | 162 | def vendor_jars!(vendor_dir = nil, write_require_file: true) 163 | vendor_dir ||= spec.require_path 164 | do_install(vendor_dir, write_require_file) 165 | end 166 | 167 | def install_jars(write_require_file: true) 168 | return unless jars? 169 | 170 | do_install(nil, write_require_file) 171 | end 172 | 173 | def ruby_maven_install_options=(options) 174 | @mvn.ruby_maven_install_options = options 175 | end 176 | 177 | def jars? 178 | # first look if there are any requirements in the spec 179 | # and then if gem depends on jar-dependencies for runtime. 180 | # only then install the jars declared in the requirements 181 | result = (spec = self.spec) && !spec.requirements.empty? && 182 | spec.dependencies.detect { |d| d.name == 'jar-dependencies' && d.type == :runtime } 183 | if result && spec.platform.to_s != 'java' 184 | Jars.warn "\njar dependencies found on non-java platform gem - do not install jars\n" 185 | false 186 | else 187 | result 188 | end 189 | end 190 | 191 | private 192 | 193 | def do_install(vendor_dir, write_require_file) 194 | if !spec.require_paths.include?(vendor_dir) && vendor_dir 195 | raise "vendor dir #{vendor_dir} not in require_paths of gemspec #{spec.require_paths}" 196 | end 197 | 198 | target_dir = File.join(@mvn.basedir, vendor_dir || spec.require_path) 199 | jars_file = File.join(target_dir, "#{spec.name}_jars.rb") 200 | 201 | # write out new jars_file it write_require_file is true or 202 | # check timestamps: 203 | # do not generate file if specfile is older then the generated file 204 | if !write_require_file && 205 | File.exist?(jars_file) && 206 | File.mtime(@mvn.specfile) < File.mtime(jars_file) 207 | # leave jars_file as is 208 | jars_file = nil 209 | end 210 | deps = install_dependencies 211 | self.class.write_require_jars(deps, jars_file) 212 | self.class.vendor_jars(deps, target_dir) if vendor_dir 213 | end 214 | 215 | def install_dependencies 216 | deps = File.join(@mvn.basedir, 'deps.lst') 217 | 218 | puts " jar dependencies for #{spec.spec_name} . . ." unless Jars.quiet? 219 | @mvn.resolve_dependencies_list(deps) 220 | 221 | self.class.load_from_maven(deps) 222 | ensure 223 | FileUtils.rm_f(deps) if deps 224 | end 225 | end 226 | end 227 | -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # 58 | # Look for the Apple JDKs first to preserve the existing behaviour, and then look 59 | # for the new JDKs provided by Oracle. 60 | # 61 | if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ] ; then 62 | # 63 | # Apple JDKs 64 | # 65 | export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home 66 | fi 67 | 68 | if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ] ; then 69 | # 70 | # Apple JDKs 71 | # 72 | export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home 73 | fi 74 | 75 | if [ -z "$JAVA_HOME" ] && [ -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ] ; then 76 | # 77 | # Oracle JDKs 78 | # 79 | export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home 80 | fi 81 | 82 | if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then 83 | # 84 | # Apple JDKs 85 | # 86 | export JAVA_HOME=`/usr/libexec/java_home` 87 | fi 88 | ;; 89 | esac 90 | 91 | if [ -z "$JAVA_HOME" ] ; then 92 | if [ -r /etc/gentoo-release ] ; then 93 | JAVA_HOME=`java-config --jre-home` 94 | fi 95 | fi 96 | 97 | if [ -z "$M2_HOME" ] ; then 98 | ## resolve links - $0 may be a link to maven's home 99 | PRG="$0" 100 | 101 | # need this for relative symlinks 102 | while [ -h "$PRG" ] ; do 103 | ls=`ls -ld "$PRG"` 104 | link=`expr "$ls" : '.*-> \(.*\)$'` 105 | if expr "$link" : '/.*' > /dev/null; then 106 | PRG="$link" 107 | else 108 | PRG="`dirname "$PRG"`/$link" 109 | fi 110 | done 111 | 112 | saveddir=`pwd` 113 | 114 | M2_HOME=`dirname "$PRG"`/.. 115 | 116 | # make it fully qualified 117 | M2_HOME=`cd "$M2_HOME" && pwd` 118 | 119 | cd "$saveddir" 120 | # echo Using m2 at $M2_HOME 121 | fi 122 | 123 | # For Cygwin, ensure paths are in UNIX format before anything is touched 124 | if $cygwin ; then 125 | [ -n "$M2_HOME" ] && 126 | M2_HOME=`cygpath --unix "$M2_HOME"` 127 | [ -n "$JAVA_HOME" ] && 128 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 129 | [ -n "$CLASSPATH" ] && 130 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 131 | fi 132 | 133 | # For Migwn, ensure paths are in UNIX format before anything is touched 134 | if $mingw ; then 135 | [ -n "$M2_HOME" ] && 136 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 137 | [ -n "$JAVA_HOME" ] && 138 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 139 | # TODO classpath? 140 | fi 141 | 142 | if [ -z "$JAVA_HOME" ]; then 143 | javaExecutable="`which javac`" 144 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 145 | # readlink(1) is not available as standard on Solaris 10. 146 | readLink=`which readlink` 147 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 148 | if $darwin ; then 149 | javaHome="`dirname \"$javaExecutable\"`" 150 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 151 | else 152 | javaExecutable="`readlink -f \"$javaExecutable\"`" 153 | fi 154 | javaHome="`dirname \"$javaExecutable\"`" 155 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 156 | JAVA_HOME="$javaHome" 157 | export JAVA_HOME 158 | fi 159 | fi 160 | fi 161 | 162 | if [ -z "$JAVACMD" ] ; then 163 | if [ -n "$JAVA_HOME" ] ; then 164 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 165 | # IBM's JDK on AIX uses strange locations for the executables 166 | JAVACMD="$JAVA_HOME/jre/sh/java" 167 | else 168 | JAVACMD="$JAVA_HOME/bin/java" 169 | fi 170 | else 171 | JAVACMD="`which java`" 172 | fi 173 | fi 174 | 175 | if [ ! -x "$JAVACMD" ] ; then 176 | echo "Error: JAVA_HOME is not defined correctly." >&2 177 | echo " We cannot execute $JAVACMD" >&2 178 | exit 1 179 | fi 180 | 181 | if [ -z "$JAVA_HOME" ] ; then 182 | echo "Warning: JAVA_HOME environment variable is not set." 183 | fi 184 | 185 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 186 | 187 | # For Cygwin, switch paths to Windows format before running java 188 | if $cygwin; then 189 | [ -n "$M2_HOME" ] && 190 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 191 | [ -n "$JAVA_HOME" ] && 192 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 193 | [ -n "$CLASSPATH" ] && 194 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 195 | fi 196 | 197 | # traverses directory structure from process work directory to filesystem root 198 | # first directory with .mvn subdirectory is considered project base directory 199 | find_maven_basedir() { 200 | local basedir=$(pwd) 201 | local wdir=$(pwd) 202 | while [ "$wdir" != '/' ] ; do 203 | if [ -d "$wdir"/.mvn ] ; then 204 | basedir=$wdir 205 | break 206 | fi 207 | wdir=$(cd "$wdir/.."; pwd) 208 | done 209 | echo "${basedir}" 210 | } 211 | 212 | # concatenates all lines of a file 213 | concat_lines() { 214 | if [ -f "$1" ]; then 215 | echo "$(tr -s '\n' ' ' < "$1")" 216 | fi 217 | } 218 | 219 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)} 220 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 221 | 222 | # Provide a "standardized" way to retrieve the CLI args that will 223 | # work with both Windows and non-Windows executions. 224 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 225 | export MAVEN_CMD_LINE_ARGS 226 | 227 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 228 | 229 | exec "$JAVACMD" \ 230 | $MAVEN_OPTS \ 231 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 232 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 233 | ${WRAPPER_LAUNCHER} $MAVEN_CMD_LINE_ARGS 234 | 235 | --------------------------------------------------------------------------------