Merge pull request #989 from GregMefford/patch-2

Fix `bin\logstash.bat deps` on Windows
This commit is contained in:
Jordan Sissel 2014-02-03 15:59:56 -08:00
commit 9eeb701cc6
3 changed files with 64 additions and 6 deletions

View file

@ -2,7 +2,7 @@
SETLOCAL
if NOT DEFINED JAVA_HOME goto err
if not defined JAVA_HOME goto missing_java_home
set SCRIPT_DIR=%~dp0
for %%I in ("%SCRIPT_DIR%..") do set LS_HOME=%%~dpfI
@ -46,18 +46,43 @@ REM The path to the heap dump location, note directory must exists and have enou
REM space for a full heap dump.
REM JAVA_OPTS=%JAVA_OPTS% -XX:HeapDumpPath=$LS_HOME/logs/heapdump.hprof
SET RUBYLIB=%LS_HOME%\lib
SET GEM_HOME=%LS_HOME%\vendor\bundle\jruby\1.9\
SET GEM_PATH=%GEM_HOME%
set RUBYLIB=%LS_HOME%\lib
set GEM_HOME=%LS_HOME%\vendor\bundle\jruby\1.9\
set GEM_PATH=%GEM_HOME%
"%JAVA_HOME%\bin\java" %JAVA_OPTS% %LS_JAVA_OPTS% -jar %LS_HOME%\vendor\jar\jruby-complete-%JRUBY_VERSION%.jar %LS_HOME%\lib\logstash\runner.rb %*
for %%I in ("%LS_HOME%\vendor\jar\jruby-complete-*.jar") do set JRUBY_JAR_FILE=%%I
if not defined JRUBY_JAR_FILE goto missing_jruby_jar
set RUBY_CMD="%JAVA_HOME%\bin\java" %JAVA_OPTS% %LS_JAVA_OPTS% -jar "%JRUBY_JAR_FILE%"
if "%*"=="deps" goto install_deps
goto run_logstash
:install_deps
if not exist "%LS_HOME%\logstash.gemspec" goto missing_gemspec
echo Installing gem dependencies. This will probably take a while the first time.
%RUBY_CMD% "%LS_HOME%\gembag.rb"
goto finally
:run_logstash
%RUBY_CMD% "%LS_HOME%\lib\logstash\runner.rb" %*
goto finally
:err
:missing_java_home
echo JAVA_HOME environment variable must be set!
pause
goto finally
:missing_jruby_jar
md "%LS_HOME%\vendor\jar\"
echo Please download the JRuby Complete .jar from http://jruby.org/download to %LS_HOME%\vendor\jar\ and re-run this command.
pause
goto finally
:missing_gemspec
echo Cannot install dependencies; missing logstash.gemspec. This 'deps' command only works from a logstash git clone.
pause
goto finally
:finally

View file

@ -10,6 +10,7 @@ ENV["GEM_PATH"] = ""
require "rubygems/specification"
require "rubygems/commands/install_command"
require "logstash/JRUBY-PR1448" if RUBY_PLATFORM == "java" && Gem.win_platform?
def install_gem(name, requirement, target)
puts "Fetching and installing gem: #{name} (#{requirement})"

View file

@ -0,0 +1,32 @@
# This patch fixes a problem that exists in JRuby prior to 1.7.11 where the
# ruby binary path used by rubygems is malformed on Windows, causing
# dependencies to not install cleanly when using `.\bin\logstash.bat deps`.
# This monkeypatch can probably be removed once it's unlikely that people
# are still using JRuby older than 1.7.11.
class << Gem
def ruby
ruby_path = original_ruby
ruby_path = "java -jar #{jar_path(ruby_path)}" if jarred_path?(ruby_path)
ruby_path
end
def jarred_path?(p)
p =~ /^file:/
end
# A jar path looks like this on non-Windows platforms:
# file:/path/to/file.jar!/path/within/jar/to/file.txt
# and like this on Windows:
# file:/C:/path/to/file.jar!/path/within/jar/to/file.txt
#
# This method returns:
# /path/to/file.jar
# or
# C:/path/to/file.jar
# as appropriate.
def jar_path(p)
path = p.sub(/^file:/, "").sub(/!.*/, "")
path = path.sub(/^\//, "") if win_platform? && path =~ /^\/[A-Za-z]:/
path
end
end