Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop hard-coding BUNDLE_GEMFILE when running wars #444

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 1 addition & 28 deletions ext/WarMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ protected int launchJRuby(final URL[] jars) throws Exception {

invokeMethod(rubyInstanceConfig, "setUpdateNativeENVEnabled", new Class[] { Boolean.TYPE }, false);

final CharSequence execScriptEnvPre = executableScriptEnvPrefix();
final CharSequence execScriptEnvPre = "require File.expand_path('META-INF/init.rb')";

final String executablePath = locateExecutable(scriptingContainer, execScriptEnvPre);
if ( executablePath == null ) {
Expand All @@ -267,21 +267,6 @@ protected int launchJRuby(final URL[] jars) throws Exception {
return ( outcome instanceof Number ) ? ( (Number) outcome ).intValue() : 0;
}

@Deprecated
protected String locateExecutable(final Object scriptingContainer) throws Exception {
if ( executable == null ) {
throw new IllegalStateException("no executable");
}
final File exec = new File(extractRoot, executable);
if ( exec.exists() ) {
return exec.getAbsolutePath();
}
else {
final String script = locateExecutableScript(executable, executableScriptEnvPrefix());
return (String) invokeMethod(scriptingContainer, "runScriptlet", script);
}
}

protected String locateExecutable(final Object scriptingContainer, final CharSequence envPreScript)
throws Exception {
if ( executable == null ) {
Expand All @@ -297,18 +282,6 @@ protected String locateExecutable(final Object scriptingContainer, final CharSeq
}
}

protected CharSequence executableScriptEnvPrefix() {
final String gemsDir = new File(extractRoot, "gems").getAbsolutePath();
final String gemfile = new File(extractRoot, "Gemfile").getAbsolutePath();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main issue. Our project is using a custom gemfile (with BUNDLE_GEMFILE) and it's getting overridden here

debug("setting GEM_HOME to " + gemsDir);
debug("... and BUNDLE_GEMFILE to " + gemfile);

// ideally this would look up the config.override_gem_home setting
return "ENV['GEM_HOME'] = ENV['GEM_PATH'] = '"+ gemsDir +"' \n" +
"ENV['BUNDLE_GEMFILE'] ||= '"+ gemfile +"' \n" +
"require 'uri:classloader:/META-INF/init.rb'";
}

protected String locateExecutableScript(final String executable, final CharSequence envPreScript) {
return ( envPreScript == null ? "" : envPreScript + " \n" ) +
"begin\n" + // locate the executable within gemspecs :
Expand Down
2 changes: 1 addition & 1 deletion lib/warbler/templates/jar.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ ENV['GEM_HOME'] <%= config.override_gem_home ? '=' : '||=' %> File.expand_path(F
ENV['GEM_PATH'] = nil # RGs sets Gem.paths.path = Gem.default_path + [ GEM_HOME ]
<% end -%>
<% if config.bundler && config.bundler[:gemfile_path] -%>
ENV['BUNDLE_GEMFILE'] = File.expand_path(File.join('..', '..', '<%= config.bundler[:gemfile_path] %>'), __FILE__)
ENV['BUNDLE_GEMFILE'] ||= File.expand_path(File.join('..', '..', '<%= config.bundler[:gemfile_path] %>'), __FILE__)
<% end -%>
13 changes: 5 additions & 8 deletions lib/warbler/templates/war.erb
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
<% gem_operator = config.override_gem_home ? '=' : '||=' %>
if $servlet_context.nil?
ENV['GEM_HOME'] <%= config.override_gem_home ? '=' : '||=' %> File.expand_path(File.join('..', '..', '<%= config.gem_path %>'), __FILE__)
<% if config.override_gem_home -%>
<% # GEM_HOME/GEM_PATH are set as .war gets extracted (on java -jar ...)
# ... thus setting `ENV['GEM_PATH'] = nil` would cause a boot failure
-%>
<% end -%>
ENV['GEM_HOME'] <%= gem_operator %> File.expand_path(File.join('..', '..', '<%= config.gem_path %>'), __FILE__).sub('/WEB-INF/', '/')
ENV['GEM_PATH'] <%= gem_operator %> ENV['GEM_HOME']
<% if config.bundler && config.bundler[:gemfile_path] -%>
ENV['BUNDLE_GEMFILE'] ||= File.expand_path(File.join('..', '..', '<%= config.bundler[:gemfile_path] %>'), __FILE__)
ENV['BUNDLE_GEMFILE'] ||= File.expand_path(File.join('..', '..', '<%= config.bundler[:gemfile_path] %>'), __FILE__).sub('/WEB-INF/', '/')
<% end -%>
else
ENV['GEM_HOME'] <%= config.override_gem_home ? '=' : '||=' %> $servlet_context.getRealPath('<%= config.gem_path %>')
ENV['GEM_HOME'] <%= gem_operator %> $servlet_context.getRealPath('<%= config.gem_path %>')
<% if config.override_gem_home -%>
ENV['GEM_PATH'] = nil
<% end -%>
Expand Down
3 changes: 3 additions & 0 deletions spec/sample_bundler/Special-Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source "https://rubygems.org"

gem 'rake', '12.3.1'
13 changes: 13 additions & 0 deletions spec/sample_bundler/Special-Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
GEM
remote: https://rubygems.org/
specs:
rake (12.3.1)

PLATFORMS
java

DEPENDENCIES
rake (= 12.3.1)

BUNDLED WITH
1.16.4
5 changes: 5 additions & 0 deletions spec/sample_bundler/vendor/bundle/jruby/2.3.0/bin/rake
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ if ARGV.first
end
end

if Gem.respond_to?(:activate_bin_path)
load Gem.activate_bin_path('rake', 'rake', version)
else
gem "rake", version
load Gem.bin_path("rake", "rake", version)
end
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
*.bak
*.rbc
*.swp
*~
.#*
.DS_Store
.idea
.rbx
/.rdoc
/TAGS
/coverage
/html
/pkg
Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
= Source Repository

Rake is currently hosted at github. The github web page is
https://github.com/ruby/rake . The public git clone URL is

git://github.com/ruby/rake.git

= Running the Rake Test Suite

If you wish to run the unit and functional tests that come with Rake:

* +cd+ into the top project directory of rake.
* Install gem dependency using bundler:

bundle install # Install bundler, minitest and rdoc

* Type one of the following:

rake # If you have run rake's tests

= Issues and Bug Reports

Feel free to submit commits or feature requests. If you send a patch,
remember to update the corresponding unit tests. In fact, I prefer
new feature to be submitted in the form of new unit tests.

For other information, feel free to ask on the ruby-talk mailing list.

If you have found a bug in rake please try with the latest version of rake
before filing an issue. Also check History.rdoc for bug fixes that may have
addressed your issue.

When submitting pull requests please check the rake Travis-CI page for test
failures:

https://travis-ci.org/ruby/rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source "https://rubygems.org"

gemspec
Loading