/
_jrubyvmopts.bat
178 lines (144 loc) · 4.16 KB
/
_jrubyvmopts.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
@echo off
set _MEM=-Xmx500m
if not defined JAVA_MEM goto memOptDone
set _MEM=%JAVA_MEM%
:memOptDone
set _STK=-Xss1024k
if not defined JAVA_STACK goto stackOptDone
set _STK=%JAVA_STACK%
:stackOptDone
set _VM_OPTS=
set _RUBY_OPTS=
set _DFLT_VM_OPTS=%JAVA_OPTS%
set _JAVA_VM=-client
set _JAVA_CLASS=org.jruby.Main
set _JRUBY_BOOTCP_OPTS=-Xbootclasspath/a:"%JRUBY_CP%"
set SAFE_JAVA_HOME=%JAVA_HOME:(=^^(%
set SAFE_JAVA_HOME=%SAFE_JAVA_HOME:)=^^)%
if not exist "%SAFE_JAVA_HOME%\bin\java.exe" goto noJavaHome
goto okJavaHome
:noJavaHome
echo The JAVA_HOME environment variable is not defined correctly.
echo Please set JAVA_HOME to the path to your JDK installation.
set JRUBY_BAT_ERROR=1
goto :EOF
:okJavaHome
rem
rem Can you believe I'm rewriting batch arg processing in batch files because batch
rem file arg processing sucks so bad? Can you believe this is even possible?
rem http://support.microsoft.com/kb/71247
rem Escape any quotes. Use _S for ', _D for ", _P for |,
rem and _U to escape _ itself. We have to escape _ itself, otherwise file names
rem with _S and _D will be converted to to wrong ones, when we un-escape.
rem See JRUBY-2821.
set _ARGS=%*
if not defined _ARGS goto vmoptsDone
set _ARGS=%_ARGS:_=_U%
set _ARGS=%_ARGS:'=_S%
set _ARGS=%_ARGS:|=_P%
set _ARGS=%_ARGS:"=_D%
rem prequote all args for 'for' statement
set _ARGS="%_ARGS%"
:vmoptsLoop
rem split args by spaces into first and rest
for /f "tokens=1,*" %%i in (%_ARGS%) do call :getarg "%%i" "%%j"
goto procarg
:getarg
rem remove quotes around first arg
for %%i in (%1) do set _CMP=%%~i
rem set the rest args (note, they're all quoted and ready to go)
set _ARGS=%2
rem return to line 18
goto :EOF
:procarg
if ["%_CMP%"] == [""] goto vmoptsDone
REM NOTE: If you'd like to use a parameter with underscore in its name,
REM NOTE: use the quoted value: --do_stuff -> --do_Ustuff
if ["%_CMP%"] == ["--server"] (
set _JAVA_VM=-server
goto :vmoptsNext
)
if ["%_CMP%"] == ["--client"] (
set _JAVA_VM=-client
goto :vmoptsNext
)
if ["%_CMP%"] == ["--jdb"] (
set _STARTJAVA=%SAFE_JAVA_HOME%\bin\jdb
goto :vmoptsNext
)
if ["%_CMP%"] == ["--sample"] (
set _CMP=-J-Xprof
goto :jvmarg
)
if ["%_CMP%"] == ["--manage"] (
set _CMP=-J-Dcom.sun.management.jmxremote
goto :jvmarg
)
if ["%_CMP%"] == ["--1.9"] (
set _CMP=-J-Djruby.compat.version=RUBY1_9
goto :jvmarg
)
if ["%_CMP%"] == ["--1.8"] (
set _CMP=-J-Djruby.compat.version=RUBY1_8
goto :jvmarg
)
if ["%_CMP%"] == ["--ng-server"] (
set _JAVA_CLASS=com.martiansoftware.nailgun.NGServer
set _JAVA_VM=-server
rem Nailgun server fails if -Xbootclasspath is used, so we remove it here.
rem In com.martiansoftware.nailgun.AliasManager's constructor,
rem getResourceAsStream("com/martiansoftware/nailgun/builtins/builtins.properties")
rem returns null, which is not handled, crashing the server. Removing
rem -Xbootclasspath for some reason fixes the getResourceAsStream() call.
set _JRUBY_BOOTCP_OPTS=
goto :vmoptsNext
)
if ["%_CMP%"] == ["--ng"] (
set _NAILGUN_CLIENT=true
goto :vmoptsNext
)
rem now unescape _D, _S and _Q
set _CMP=%_CMP:_D="%
set _CMP=%_CMP:_S='%
set _CMP=%_CMP:_U=_%
set _CMP1=%_CMP:~0,1%
set _CMP2=%_CMP:~0,2%
rem detect first character is a quote; skip directly to rubyarg
rem this avoids a batch syntax error
if "%_CMP1:"=\\%" == "\\" goto rubyarg
rem removing quote avoids a batch syntax error
if "%_CMP2:"=\\%" == "-J" goto jvmarg
:rubyarg
set _RUBY_OPTS=%_RUBY_OPTS% %_CMP%
goto vmoptsNext
:jvmarg
set _VAL=%_CMP:~2%
if "%_VAL:~0,4%" == "-Xmx" (
set _MEM=%_VAL%
goto vmoptsNext
)
if "%_VAL:~0,4%" == "-Xss" (
set _STK=%_VAL%
goto vmoptsNext
)
rem Make sure the older way to specify server VM
rem is still supported.
if ["%_VAL%"] == ["-server"] (
set _JAVA_VM=-server
goto vmoptsNext
)
set _VM_OPTS=%_VM_OPTS% %_VAL%
:vmoptsNext
set _CMP=
goto vmoptsLoop
:vmoptsDone
set _RUBY_OPTS=%_RUBY_OPTS:_P=|%
set _VM_OPTS=%_VM_OPTS% %_JAVA_VM% %_MEM% %_STK% %_DFLT_VM_OPTS%
set _DFLT_VM_OPTS=
set _MEM=
set _STK=
set _ARGS=
set _VAL=
set _CMP=
set _CMP1=
set _JAVA_VM=