jruby-launcher 1.0.19-java → 1.1.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/argnames.h +1 -0
  3. data/argparser.cpp +8 -0
  4. data/lib/jruby-launcher.rb +1 -1
  5. data/pkg/jruby-launcher-1.0.15-java/extconf.rb +7 -0
  6. data/pkg/jruby-launcher-1.0.15-java/lib/jruby-launcher.rb +3 -0
  7. data/pkg/jruby-launcher-1.0.15-java/lib/rubygems/defaults/jruby_native.rb +4 -0
  8. data/pkg/jruby-launcher-1.0.15-java/pkg/jruby-launcher-1.0.15-java/extconf.rb +7 -0
  9. data/pkg/jruby-launcher-1.0.15-java/pkg/jruby-launcher-1.0.15-java/lib/jruby-launcher.rb +3 -0
  10. data/pkg/jruby-launcher-1.0.15-java/pkg/jruby-launcher-1.0.15-java/lib/rubygems/defaults/jruby_native.rb +4 -0
  11. data/pkg/jruby-launcher-1.0.15-java/pkg/jruby-launcher-1.0.15-java/spec/launcher_spec.rb +258 -0
  12. data/pkg/jruby-launcher-1.0.15-java/pkg/jruby-launcher-1.0.15-java/spec/spec_helper.rb +81 -0
  13. data/pkg/jruby-launcher-1.0.15-java/spec/launcher_spec.rb +258 -0
  14. data/pkg/jruby-launcher-1.0.15-java/spec/spec_helper.rb +81 -0
  15. data/pkg/jruby-launcher-1.1.0-java/extconf.rb +7 -0
  16. data/pkg/jruby-launcher-1.1.0-java/lib/jruby-launcher.rb +3 -0
  17. data/pkg/jruby-launcher-1.1.0-java/lib/rubygems/defaults/jruby_native.rb +4 -0
  18. data/pkg/jruby-launcher-1.1.0-java/pkg/jruby-launcher-1.0.15-java/extconf.rb +7 -0
  19. data/pkg/jruby-launcher-1.1.0-java/pkg/jruby-launcher-1.0.15-java/lib/jruby-launcher.rb +3 -0
  20. data/pkg/jruby-launcher-1.1.0-java/pkg/jruby-launcher-1.0.15-java/lib/rubygems/defaults/jruby_native.rb +4 -0
  21. data/pkg/jruby-launcher-1.1.0-java/pkg/jruby-launcher-1.0.15-java/pkg/jruby-launcher-1.0.15-java/extconf.rb +7 -0
  22. data/pkg/jruby-launcher-1.1.0-java/pkg/jruby-launcher-1.0.15-java/pkg/jruby-launcher-1.0.15-java/lib/jruby-launcher.rb +3 -0
  23. data/pkg/jruby-launcher-1.1.0-java/pkg/jruby-launcher-1.0.15-java/pkg/jruby-launcher-1.0.15-java/lib/rubygems/defaults/jruby_native.rb +4 -0
  24. data/pkg/jruby-launcher-1.1.0-java/pkg/jruby-launcher-1.0.15-java/pkg/jruby-launcher-1.0.15-java/spec/launcher_spec.rb +258 -0
  25. data/pkg/jruby-launcher-1.1.0-java/pkg/jruby-launcher-1.0.15-java/pkg/jruby-launcher-1.0.15-java/spec/spec_helper.rb +81 -0
  26. data/pkg/jruby-launcher-1.1.0-java/pkg/jruby-launcher-1.0.15-java/spec/launcher_spec.rb +258 -0
  27. data/pkg/jruby-launcher-1.1.0-java/pkg/jruby-launcher-1.0.15-java/spec/spec_helper.rb +81 -0
  28. data/pkg/jruby-launcher-1.1.0-java/spec/launcher_spec.rb +258 -0
  29. data/pkg/jruby-launcher-1.1.0-java/spec/spec_helper.rb +81 -0
  30. data/version.h +1 -1
  31. metadata +49 -24
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4d24b0243283cbcc3c3bcd6426a90954db0d09ac
4
- data.tar.gz: 3b0d624082883167c321d028390bec604ffb2543
3
+ metadata.gz: 531b913ea1f42475a9dc006f1039c4365e5b085b
4
+ data.tar.gz: 6f72f81b77dd526626fc1f1393263b81ea4d1e12
5
5
  SHA512:
6
- metadata.gz: 63267ed5dccbf6cb9d5262e5ee65485c71f222dfcb12fb338bb91f1ce0e885206c7d178ed31a2bee147f477935162083817d873beaa9eece03ddeb13f5b05eb8
7
- data.tar.gz: 3750401b00836c9b7094e6a55fe6e399dd77583d7b5c25e106fe88cb7b77d26a598953c7d2e48285aa58436bec267af0825eb1c5f3c0f49eb845672c6215bc3a
6
+ metadata.gz: cc30de7517bd9967f18b721282d8ae7de28990bce42bfe225c05e9c3666ecbb6ab5b91b80b1f6135016e7691d27efcbd0f71324606262a579d1b5b345145b8b1
7
+ data.tar.gz: 98c3516919093b049cab51e646d0d9fe18f5e8c5e09140b2f0760f374c14f648fc7906a787d4ce987d87d9dc43cce7e064009568848bba6f9fb9f301b38c9d1b
data/argnames.h CHANGED
@@ -24,6 +24,7 @@
24
24
  /* Below are standard JRuby args handled by the launcher. */
25
25
  #define ARG_NAME_SERVER "--server"
26
26
  #define ARG_NAME_CLIENT "--client"
27
+ #define ARG_NAME_DEV "--dev"
27
28
  #define ARG_NAME_SAMPLE "--sample"
28
29
  #define ARG_NAME_MANAGE "--manage"
29
30
  #define ARG_NAME_HEADLESS "--headless"
data/argparser.cpp CHANGED
@@ -127,6 +127,8 @@ bool ArgParser::initPlatformDir() {
127
127
  bool found = false;
128
128
  char path[PATH_MAX] = "";
129
129
 
130
+ logMsg("Version: " JRUBY_LAUNCHER_VERSION);
131
+
130
132
  if (getenv("JRUBY_HOME") != NULL) {
131
133
  logMsg("initPlatformDir: using JRUBY_HOME environment variable");
132
134
  char sep[2] = { FILE_SEP, NULL };
@@ -316,6 +318,12 @@ bool ArgParser::parseArgs(int argc, char *argv[]) {
316
318
  } else if (it->compare(ARG_NAME_SERVER) == 0
317
319
  || it->compare(ARG_NAME_CLIENT) == 0) {
318
320
  javaOptions.push_back(it->substr(1)); // to JVMLauncher, -server instead of --server
321
+ } else if (it->compare(ARG_NAME_DEV) == 0) {
322
+ javaOptions.push_back("-XX:+TieredCompilation");
323
+ javaOptions.push_back("-XX:TieredStopAtLevel=1");
324
+ javaOptions.push_back("-Djruby.compile.mode=OFF");
325
+ javaOptions.push_back("-Djruby.compile.invokedynamic=false");
326
+ progArgs.push_back(*it); // allow JRuby to process it too
319
327
  } else if (it->compare(ARG_NAME_SAMPLE) == 0) {
320
328
  javaOptions.push_back("-Xprof");
321
329
  } else if (it->compare(ARG_NAME_MANAGE) == 0) {
@@ -1,3 +1,3 @@
1
1
  module JRubyLauncher
2
- VERSION = "1.0.19"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -0,0 +1,7 @@
1
+ require 'rbconfig'
2
+
3
+ mf = File.read('Makefile')
4
+ mf = mf.gsub(/^BINDIR\s*=.*$/, "BINDIR = #{Config::CONFIG['bindir']}")
5
+ mf = mf.gsub(/^PREFIX\s*=.*$/, "PREFIX = #{File.dirname(Config::CONFIG['libdir'])}")
6
+ puts mf
7
+ File.open('Makefile', 'wb') {|f| f << mf}
@@ -0,0 +1,3 @@
1
+ module JRubyLauncher
2
+ VERSION = "1.0.15"
3
+ end
@@ -0,0 +1,4 @@
1
+ class Gem::ConfigFile
2
+ PLATFORM_DEFAULTS['install'] = '--no-rdoc --no-ri'
3
+ PLATFORM_DEFAULTS['update'] = '--no-rdoc --no-ri'
4
+ end
@@ -0,0 +1,7 @@
1
+ require 'rbconfig'
2
+
3
+ mf = File.read('Makefile')
4
+ mf = mf.gsub(/^BINDIR\s*=.*$/, "BINDIR = #{Config::CONFIG['bindir']}")
5
+ mf = mf.gsub(/^PREFIX\s*=.*$/, "PREFIX = #{File.dirname(Config::CONFIG['libdir'])}")
6
+ puts mf
7
+ File.open('Makefile', 'wb') {|f| f << mf}
@@ -0,0 +1,3 @@
1
+ module JRubyLauncher
2
+ VERSION = "1.0.15"
3
+ end
@@ -0,0 +1,4 @@
1
+ class Gem::ConfigFile
2
+ PLATFORM_DEFAULTS['install'] = '--no-rdoc --no-ri'
3
+ PLATFORM_DEFAULTS['update'] = '--no-rdoc --no-ri'
4
+ end
@@ -0,0 +1,258 @@
1
+ require File.expand_path('../spec_helper.rb', __FILE__)
2
+ load File.expand_path('../../lib/jruby-launcher.rb', __FILE__)
3
+
4
+ describe "JRuby native launcher" do
5
+ it "should run org.jruby.Main" do
6
+ jruby_launcher_args("").last.should == "org/jruby/Main"
7
+ end
8
+
9
+ it "should pass unrecognized arguments to JRuby" do
10
+ jruby_launcher_args("-J-Dsome.option -v --help")[-3..-1].should == ["org/jruby/Main", "-v", "--help"]
11
+ end
12
+
13
+ it "should print help message" do
14
+ args = jruby_launcher_args("-Xhelp 2>&1")
15
+ args.detect{|l| l =~ /JRuby Launcher usage/}.should be_true
16
+ args.should include("-X")
17
+ args = jruby_launcher_args("-X 2>&1")
18
+ args.detect{|l| l =~ /JRuby Launcher usage/}.should be_true
19
+ args.should include("-X")
20
+ end
21
+
22
+ it "should use $JAVACMD when JAVACMD is specified" do
23
+ with_environment "JAVACMD" => File.join("jato") do
24
+ if windows?
25
+ jruby_launcher_args("-v 2>&1").join.should =~ %r{jato}
26
+ else
27
+ jruby_launcher_args("-v").first.should == File.join("jato")
28
+ end
29
+ end
30
+ end
31
+
32
+ it "should use $JAVA_HOME/bin/java when JAVA_HOME is specified" do
33
+ with_environment "JAVA_HOME" => File.join("some", "java", "home") do
34
+ if windows?
35
+ jruby_launcher_args("-v 2>&1").join.should =~ %r{some/java/home}
36
+ else
37
+ jruby_launcher_args("-v").first.should == File.join("some", "java", "home", "bin", "java")
38
+ end
39
+ end
40
+ end
41
+
42
+ it "should use -Xjdkhome argument above JAVA_HOME" do
43
+ with_environment "JAVA_HOME" => File.join("env", "java", "home") do
44
+ if windows?
45
+ jruby_launcher_args("-Xjdkhome some/java/home 2>&1").join.should =~ %r{some/java/home}
46
+ else
47
+ jruby_launcher_args("-Xjdkhome some/java/home").first.should == File.join("some", "java", "home", "bin", "java")
48
+ end
49
+ end
50
+ end
51
+
52
+ it "should drop the backslashes at the end of JAVA_HOME" do
53
+ with_environment "JAVA_HOME" => File.join("some", "java", "home\\\\") do
54
+ if windows?
55
+ jruby_launcher_args("").join.should =~ %r{some/java/home}
56
+ else
57
+ jruby_launcher_args("").first.should == File.join("some", "java", "home", "bin", "java")
58
+ end
59
+ end
60
+ end
61
+
62
+ it "should complain about a missing log argument" do
63
+ jruby_launcher("-Xtrace 2>&1").should =~ /Argument is missing for "-Xtrace"/
64
+ jruby_launcher("-Xtrace -- 2>&1").should =~ /Argument is missing for "-Xtrace"/
65
+ end
66
+
67
+ it "should complain about a missing jdkhome argument" do
68
+ jruby_launcher("-Xjdkhome 2>&1").should =~ /Argument is missing/
69
+ jruby_launcher("-Xjdkhome -- 2>&1").should =~ /Argument is missing/
70
+ end
71
+
72
+ it "should complain about a missing classpath append argument" do
73
+ jruby_launcher("-Xcp:a 2>&1").should =~ /Argument is missing/
74
+ jruby_launcher("-Xcp:a -- 2>&1").should =~ /Argument is missing/
75
+ end
76
+
77
+ it "should run nailgun server with --ng-server option" do
78
+ jruby_launcher_args("--ng-server").last.should == "com/martiansoftware/nailgun/NGServer"
79
+ end
80
+
81
+ it "should run nailgun client with --ng option" do
82
+ jruby_launcher_args('--ng -e "puts 1"').should == ["org.jruby.util.NailMain", "-e", "puts 1"]
83
+ end
84
+
85
+ it "should handle -J JVM options" do
86
+ jruby_launcher_args("-J-Darg1=value1 -J-Darg2=value2").should include("-Darg1=value1", "-Darg2=value2")
87
+ end
88
+
89
+ it "should pass -Xprop.erty=value as -J-Djruby.prop.erty=value" do
90
+ jruby_launcher_args("-Xprop.erty=value").should include("-Djruby.prop.erty=value")
91
+ end
92
+
93
+ it "should pass -Xproperties as --properties" do
94
+ jruby_launcher_args("-Xproperties").should include("--properties")
95
+ end
96
+
97
+ it "should default to 500m max heap" do
98
+ jruby_launcher_args("").should include("-Xmx500m", "-Djruby.memory.max=500m")
99
+ end
100
+
101
+ it "should allow max heap to be overridden" do
102
+ jruby_launcher_args("-J-Xmx256m").should include("-Xmx256m", "-Djruby.memory.max=256m")
103
+ end
104
+
105
+ it "should default to 2048k max stack" do
106
+ jruby_launcher_args("").should include("-Xss2048k", "-Djruby.stack.max=2048k")
107
+ end
108
+
109
+ it "should allow max stack to be overridden" do
110
+ jruby_launcher_args("-J-Xss512k").should include("-Xss512k", "-Djruby.stack.max=512k")
111
+ end
112
+
113
+ it "should add the contents of the CLASSPATH environment variable" do
114
+ with_environment "CLASSPATH" => "some.jar" do
115
+ classpath_arg(jruby_launcher_args("")).should =~ /some.jar/
116
+ end
117
+ end
118
+
119
+ it "should add the classpath elements in proper order" do
120
+ s = File::PATH_SEPARATOR
121
+ with_environment "CLASSPATH" => "some-env.jar" do
122
+ args = jruby_launcher_args("-Xcp:a some-other.jar -Xcp:p some.jar")
123
+ classpath_arg(args).should =~ /some.jar.*#{s}some-env.jar#{s}some-other.jar/
124
+ end
125
+ end
126
+
127
+ it "should use the --server compiler" do
128
+ jruby_launcher_args("--server").should include("-server")
129
+ end
130
+
131
+ it "should use the --client compiler" do
132
+ jruby_launcher_args("--client").should include("-client")
133
+ end
134
+
135
+ it "should set the JMX settings when --manage is present" do
136
+ jruby_launcher_args("--manage").should include("-Dcom.sun.management.jmxremote", "-Djruby.management.enabled=true")
137
+ end
138
+
139
+ it "should set the headless flag when --headless is present" do
140
+ jruby_launcher_args("--headless").should include("-Djava.awt.headless=true")
141
+ end
142
+
143
+ it "should pass -Xprof when --sample is present" do
144
+ jruby_launcher_args("--sample").should include("-Xprof")
145
+ end
146
+
147
+ it "should stop argument processing when a -- is seen" do
148
+ jruby_launcher_args("-- -Xhelp -Xtrace --headless").should include("-Xhelp", "-Xtrace", "--headless")
149
+ end
150
+
151
+ # JRUBY-4151
152
+ it "should properly handle single quotes" do
153
+ jruby_launcher_args("-e 'ABC DEF'").should include("ABC DEF")
154
+ end
155
+
156
+ # JRUBY-4581
157
+ it "should prepend JRUBY_OPTS to the start of the argument list to process" do
158
+ with_environment "JRUBY_OPTS" => "--server -J-Dsome.key=val -rubygems" do
159
+ jruby_launcher_args("-e 'ABC DEF'").should include("-server", "-Dsome.key=val", "-rubygems", "-e", "ABC DEF")
160
+ end
161
+ end
162
+
163
+ # JRUBY-4611
164
+ it "stops argument processing on first non-option argument" do
165
+ jruby_launcher_args("foo.rb --sample")[-2..-1].should == ["foo.rb", "--sample"]
166
+ end
167
+
168
+ # JRUBY-4608
169
+ if RbConfig::CONFIG['target_os'] =~ /darwin/i
170
+ it "includes file.encoding=UTF-8 on Mac if JAVA_ENCODING is not set" do
171
+ jruby_launcher_args("-e true").should include("-Dfile.encoding=UTF-8")
172
+ with_environment "JAVA_ENCODING" => "MacRoman" do
173
+ jruby_launcher_args("-e true").should_not include("-Dfile.encoding=UTF-8")
174
+ end
175
+ end
176
+ end
177
+
178
+ it "does not crash on empty args" do
179
+ jruby_launcher_args("-e ''").should include("-e")
180
+ jruby_launcher("-Xtrace '' 2>&1").should =~ /-Xtrace/
181
+ jruby_launcher("-Xjdkhome '' 2>&1").should =~ /-Xjdkhome/
182
+ end
183
+
184
+ # JRUBY-4706
185
+ it "should put JRuby on regular classpath when -Xnobootclasspath is used" do
186
+ args = jruby_launcher_args("-e true")
187
+ args.grep(/Xbootclasspath/).should_not be_empty
188
+ args = jruby_launcher_args("-Xnobootclasspath -e true")
189
+ args.grep(/Xbootclasspath/).should be_empty
190
+ end
191
+
192
+ it "should put JRuby on regular classpath when VERIFY_JRUBY is set" do
193
+ with_environment "VERIFY_JRUBY" => "true" do
194
+ args = jruby_launcher_args("-e true")
195
+ args.grep(/Xbootclasspath/).should be_empty
196
+ end
197
+ end
198
+
199
+ # JRUBY-4709
200
+ it "should include a bare : or ; at the end of the classpath, to include PWD in the path" do
201
+ classpath_arg(jruby_launcher_args("-Xnobootclasspath -e true")).should =~
202
+ if windows?
203
+ /;$/
204
+ else
205
+ /:$/
206
+ end
207
+ end
208
+
209
+ # JRUBY-6016
210
+ it "should honor JAVA_MEM" do
211
+ with_environment "JAVA_MEM" => "-Xmx768m" do
212
+ jruby_launcher_args("").should include("-Xmx768m", "-Djruby.memory.max=768m")
213
+ end
214
+ end
215
+
216
+ it "should honor JAVA_STACK" do
217
+ with_environment "JAVA_STACK" => "-Xss3072k" do
218
+ jruby_launcher_args("").should include("-Xss3072k", "-Djruby.stack.max=3072k")
219
+ end
220
+ end
221
+
222
+ it "should honor JRUBY_HOME" do
223
+ with_environment "JRUBY_HOME" => "/tmp" do
224
+ jruby_launcher_args("").should include("-Djruby.home=/tmp")
225
+ end
226
+ end
227
+
228
+ context "JRUBY_HOME set and JRUBY_HOME/lib/jruby.jar exists" do
229
+ let(:jruby_home) do
230
+ require 'tempfile'
231
+ t = Tempfile.new("jruby_home")
232
+ t.path.tap { t.close! }
233
+ end
234
+
235
+ before do
236
+ FileUtils.mkdir_p(File.join(jruby_home, "lib"))
237
+ FileUtils.touch(File.join(jruby_home, "lib", "jruby.jar"))
238
+ end
239
+ after { FileUtils.rm_rf jruby_home }
240
+
241
+ it "should add jruby.jar to the bootclasspath" do
242
+ with_environment "JRUBY_HOME" => jruby_home do
243
+ jruby_launcher_args("").should include("-Xbootclasspath/a:#{jruby_home}/lib/jruby.jar")
244
+ end
245
+ end
246
+ end
247
+
248
+ it "should place user-supplied options after default options" do
249
+ args = jruby_launcher_args("-J-Djruby.home=/tmp")
250
+ home_args = args.select {|x| x =~ /^-Djruby\.home/ }
251
+ home_args.length.should == 2
252
+ home_args.last.should == "-Djruby.home=/tmp"
253
+ end
254
+
255
+ it "should print the version" do
256
+ jruby_launcher("-Xversion 2>&1").should =~ /Launcher Version #{JRubyLauncher::VERSION}/
257
+ end
258
+ end
@@ -0,0 +1,81 @@
1
+ require 'rspec'
2
+ require 'rbconfig'
3
+ require 'fileutils'
4
+
5
+ if defined?(JRUBY_VERSION)
6
+ require 'jruby'
7
+ JRuby.runtime.instance_config.run_ruby_in_process = false
8
+ end
9
+
10
+ module JRubyLauncherHelper
11
+ JRUBY_EXE = ''
12
+ WINDOWS = RbConfig::CONFIG['target_os'] =~ /mswin/
13
+
14
+ def self.check_executable_built
15
+ exe = File.expand_path("../../jruby", __FILE__) + RbConfig::CONFIG['EXEEXT']
16
+ unless File.executable?(exe)
17
+ raise "Error: launcher executable not built; type `make' before continuing."
18
+ end
19
+ top = File.dirname(exe)
20
+ name = File.basename(exe)
21
+ home = File.join(top, "build/home")
22
+ FileUtils.mkdir_p(File.join(home, "bin"))
23
+ FileUtils.cp(exe, File.join(home, "bin"))
24
+ if JRubyLauncherHelper::WINDOWS
25
+ FileUtils.cp(exe.sub(/exe/, 'dll'), File.join(home, "bin"))
26
+ end
27
+ FileUtils.mkdir_p(File.join(home, "lib"))
28
+ FileUtils.touch(File.join(home, "lib/jruby.jar"))
29
+ JRUBY_EXE.concat File.join(home, "bin", name)
30
+ end
31
+
32
+ def jruby_launcher(args)
33
+ `#{JRUBY_EXE} #{args}`
34
+ end
35
+
36
+ def jruby_launcher_args(args)
37
+ jruby_launcher("-Xcommand #{args}").split("\n")
38
+ end
39
+
40
+ def last_exit_code
41
+ $?.exitstatus
42
+ end
43
+
44
+ def windows?
45
+ WINDOWS
46
+ end
47
+
48
+ def classpath_arg(args)
49
+ index = args.index("-cp")
50
+ index.should > 0
51
+ args[index + 1]
52
+ end
53
+
54
+ def with_environment(pairs = {})
55
+ prev_env = {}
56
+ pairs.each_pair do |k,v|
57
+ prev_env[k] = ENV[k] if ENV.has_key?(k)
58
+ ENV[k] = v
59
+ end
60
+ begin
61
+ yield
62
+ ensure
63
+ pairs.keys.each {|k| ENV.delete(k)}
64
+ ENV.update(prev_env)
65
+ end
66
+ end
67
+ end
68
+
69
+ RSpec.configure do |config|
70
+ config.before(:all) do
71
+ JRubyLauncherHelper.check_executable_built
72
+ # clear environment for better control
73
+ ENV.delete("JAVA_HOME")
74
+ ENV.delete("JRUBY_HOME")
75
+ ENV.delete("JAVA_OPTS")
76
+ ENV.delete("JRUBY_OPTS")
77
+ ENV.delete("CLASSPATH")
78
+ ENV.delete("JAVA_ENCODING")
79
+ end
80
+ config.include(JRubyLauncherHelper)
81
+ end
@@ -0,0 +1,258 @@
1
+ require File.expand_path('../spec_helper.rb', __FILE__)
2
+ load File.expand_path('../../lib/jruby-launcher.rb', __FILE__)
3
+
4
+ describe "JRuby native launcher" do
5
+ it "should run org.jruby.Main" do
6
+ jruby_launcher_args("").last.should == "org/jruby/Main"
7
+ end
8
+
9
+ it "should pass unrecognized arguments to JRuby" do
10
+ jruby_launcher_args("-J-Dsome.option -v --help")[-3..-1].should == ["org/jruby/Main", "-v", "--help"]
11
+ end
12
+
13
+ it "should print help message" do
14
+ args = jruby_launcher_args("-Xhelp 2>&1")
15
+ args.detect{|l| l =~ /JRuby Launcher usage/}.should be_true
16
+ args.should include("-X")
17
+ args = jruby_launcher_args("-X 2>&1")
18
+ args.detect{|l| l =~ /JRuby Launcher usage/}.should be_true
19
+ args.should include("-X")
20
+ end
21
+
22
+ it "should use $JAVACMD when JAVACMD is specified" do
23
+ with_environment "JAVACMD" => File.join("jato") do
24
+ if windows?
25
+ jruby_launcher_args("-v 2>&1").join.should =~ %r{jato}
26
+ else
27
+ jruby_launcher_args("-v").first.should == File.join("jato")
28
+ end
29
+ end
30
+ end
31
+
32
+ it "should use $JAVA_HOME/bin/java when JAVA_HOME is specified" do
33
+ with_environment "JAVA_HOME" => File.join("some", "java", "home") do
34
+ if windows?
35
+ jruby_launcher_args("-v 2>&1").join.should =~ %r{some/java/home}
36
+ else
37
+ jruby_launcher_args("-v").first.should == File.join("some", "java", "home", "bin", "java")
38
+ end
39
+ end
40
+ end
41
+
42
+ it "should use -Xjdkhome argument above JAVA_HOME" do
43
+ with_environment "JAVA_HOME" => File.join("env", "java", "home") do
44
+ if windows?
45
+ jruby_launcher_args("-Xjdkhome some/java/home 2>&1").join.should =~ %r{some/java/home}
46
+ else
47
+ jruby_launcher_args("-Xjdkhome some/java/home").first.should == File.join("some", "java", "home", "bin", "java")
48
+ end
49
+ end
50
+ end
51
+
52
+ it "should drop the backslashes at the end of JAVA_HOME" do
53
+ with_environment "JAVA_HOME" => File.join("some", "java", "home\\\\") do
54
+ if windows?
55
+ jruby_launcher_args("").join.should =~ %r{some/java/home}
56
+ else
57
+ jruby_launcher_args("").first.should == File.join("some", "java", "home", "bin", "java")
58
+ end
59
+ end
60
+ end
61
+
62
+ it "should complain about a missing log argument" do
63
+ jruby_launcher("-Xtrace 2>&1").should =~ /Argument is missing for "-Xtrace"/
64
+ jruby_launcher("-Xtrace -- 2>&1").should =~ /Argument is missing for "-Xtrace"/
65
+ end
66
+
67
+ it "should complain about a missing jdkhome argument" do
68
+ jruby_launcher("-Xjdkhome 2>&1").should =~ /Argument is missing/
69
+ jruby_launcher("-Xjdkhome -- 2>&1").should =~ /Argument is missing/
70
+ end
71
+
72
+ it "should complain about a missing classpath append argument" do
73
+ jruby_launcher("-Xcp:a 2>&1").should =~ /Argument is missing/
74
+ jruby_launcher("-Xcp:a -- 2>&1").should =~ /Argument is missing/
75
+ end
76
+
77
+ it "should run nailgun server with --ng-server option" do
78
+ jruby_launcher_args("--ng-server").last.should == "com/martiansoftware/nailgun/NGServer"
79
+ end
80
+
81
+ it "should run nailgun client with --ng option" do
82
+ jruby_launcher_args('--ng -e "puts 1"').should == ["org.jruby.util.NailMain", "-e", "puts 1"]
83
+ end
84
+
85
+ it "should handle -J JVM options" do
86
+ jruby_launcher_args("-J-Darg1=value1 -J-Darg2=value2").should include("-Darg1=value1", "-Darg2=value2")
87
+ end
88
+
89
+ it "should pass -Xprop.erty=value as -J-Djruby.prop.erty=value" do
90
+ jruby_launcher_args("-Xprop.erty=value").should include("-Djruby.prop.erty=value")
91
+ end
92
+
93
+ it "should pass -Xproperties as --properties" do
94
+ jruby_launcher_args("-Xproperties").should include("--properties")
95
+ end
96
+
97
+ it "should default to 500m max heap" do
98
+ jruby_launcher_args("").should include("-Xmx500m", "-Djruby.memory.max=500m")
99
+ end
100
+
101
+ it "should allow max heap to be overridden" do
102
+ jruby_launcher_args("-J-Xmx256m").should include("-Xmx256m", "-Djruby.memory.max=256m")
103
+ end
104
+
105
+ it "should default to 2048k max stack" do
106
+ jruby_launcher_args("").should include("-Xss2048k", "-Djruby.stack.max=2048k")
107
+ end
108
+
109
+ it "should allow max stack to be overridden" do
110
+ jruby_launcher_args("-J-Xss512k").should include("-Xss512k", "-Djruby.stack.max=512k")
111
+ end
112
+
113
+ it "should add the contents of the CLASSPATH environment variable" do
114
+ with_environment "CLASSPATH" => "some.jar" do
115
+ classpath_arg(jruby_launcher_args("")).should =~ /some.jar/
116
+ end
117
+ end
118
+
119
+ it "should add the classpath elements in proper order" do
120
+ s = File::PATH_SEPARATOR
121
+ with_environment "CLASSPATH" => "some-env.jar" do
122
+ args = jruby_launcher_args("-Xcp:a some-other.jar -Xcp:p some.jar")
123
+ classpath_arg(args).should =~ /some.jar.*#{s}some-env.jar#{s}some-other.jar/
124
+ end
125
+ end
126
+
127
+ it "should use the --server compiler" do
128
+ jruby_launcher_args("--server").should include("-server")
129
+ end
130
+
131
+ it "should use the --client compiler" do
132
+ jruby_launcher_args("--client").should include("-client")
133
+ end
134
+
135
+ it "should set the JMX settings when --manage is present" do
136
+ jruby_launcher_args("--manage").should include("-Dcom.sun.management.jmxremote", "-Djruby.management.enabled=true")
137
+ end
138
+
139
+ it "should set the headless flag when --headless is present" do
140
+ jruby_launcher_args("--headless").should include("-Djava.awt.headless=true")
141
+ end
142
+
143
+ it "should pass -Xprof when --sample is present" do
144
+ jruby_launcher_args("--sample").should include("-Xprof")
145
+ end
146
+
147
+ it "should stop argument processing when a -- is seen" do
148
+ jruby_launcher_args("-- -Xhelp -Xtrace --headless").should include("-Xhelp", "-Xtrace", "--headless")
149
+ end
150
+
151
+ # JRUBY-4151
152
+ it "should properly handle single quotes" do
153
+ jruby_launcher_args("-e 'ABC DEF'").should include("ABC DEF")
154
+ end
155
+
156
+ # JRUBY-4581
157
+ it "should prepend JRUBY_OPTS to the start of the argument list to process" do
158
+ with_environment "JRUBY_OPTS" => "--server -J-Dsome.key=val -rubygems" do
159
+ jruby_launcher_args("-e 'ABC DEF'").should include("-server", "-Dsome.key=val", "-rubygems", "-e", "ABC DEF")
160
+ end
161
+ end
162
+
163
+ # JRUBY-4611
164
+ it "stops argument processing on first non-option argument" do
165
+ jruby_launcher_args("foo.rb --sample")[-2..-1].should == ["foo.rb", "--sample"]
166
+ end
167
+
168
+ # JRUBY-4608
169
+ if RbConfig::CONFIG['target_os'] =~ /darwin/i
170
+ it "includes file.encoding=UTF-8 on Mac if JAVA_ENCODING is not set" do
171
+ jruby_launcher_args("-e true").should include("-Dfile.encoding=UTF-8")
172
+ with_environment "JAVA_ENCODING" => "MacRoman" do
173
+ jruby_launcher_args("-e true").should_not include("-Dfile.encoding=UTF-8")
174
+ end
175
+ end
176
+ end
177
+
178
+ it "does not crash on empty args" do
179
+ jruby_launcher_args("-e ''").should include("-e")
180
+ jruby_launcher("-Xtrace '' 2>&1").should =~ /-Xtrace/
181
+ jruby_launcher("-Xjdkhome '' 2>&1").should =~ /-Xjdkhome/
182
+ end
183
+
184
+ # JRUBY-4706
185
+ it "should put JRuby on regular classpath when -Xnobootclasspath is used" do
186
+ args = jruby_launcher_args("-e true")
187
+ args.grep(/Xbootclasspath/).should_not be_empty
188
+ args = jruby_launcher_args("-Xnobootclasspath -e true")
189
+ args.grep(/Xbootclasspath/).should be_empty
190
+ end
191
+
192
+ it "should put JRuby on regular classpath when VERIFY_JRUBY is set" do
193
+ with_environment "VERIFY_JRUBY" => "true" do
194
+ args = jruby_launcher_args("-e true")
195
+ args.grep(/Xbootclasspath/).should be_empty
196
+ end
197
+ end
198
+
199
+ # JRUBY-4709
200
+ it "should include a bare : or ; at the end of the classpath, to include PWD in the path" do
201
+ classpath_arg(jruby_launcher_args("-Xnobootclasspath -e true")).should =~
202
+ if windows?
203
+ /;$/
204
+ else
205
+ /:$/
206
+ end
207
+ end
208
+
209
+ # JRUBY-6016
210
+ it "should honor JAVA_MEM" do
211
+ with_environment "JAVA_MEM" => "-Xmx768m" do
212
+ jruby_launcher_args("").should include("-Xmx768m", "-Djruby.memory.max=768m")
213
+ end
214
+ end
215
+
216
+ it "should honor JAVA_STACK" do
217
+ with_environment "JAVA_STACK" => "-Xss3072k" do
218
+ jruby_launcher_args("").should include("-Xss3072k", "-Djruby.stack.max=3072k")
219
+ end
220
+ end
221
+
222
+ it "should honor JRUBY_HOME" do
223
+ with_environment "JRUBY_HOME" => "/tmp" do
224
+ jruby_launcher_args("").should include("-Djruby.home=/tmp")
225
+ end
226
+ end
227
+
228
+ context "JRUBY_HOME set and JRUBY_HOME/lib/jruby.jar exists" do
229
+ let(:jruby_home) do
230
+ require 'tempfile'
231
+ t = Tempfile.new("jruby_home")
232
+ t.path.tap { t.close! }
233
+ end
234
+
235
+ before do
236
+ FileUtils.mkdir_p(File.join(jruby_home, "lib"))
237
+ FileUtils.touch(File.join(jruby_home, "lib", "jruby.jar"))
238
+ end
239
+ after { FileUtils.rm_rf jruby_home }
240
+
241
+ it "should add jruby.jar to the bootclasspath" do
242
+ with_environment "JRUBY_HOME" => jruby_home do
243
+ jruby_launcher_args("").should include("-Xbootclasspath/a:#{jruby_home}/lib/jruby.jar")
244
+ end
245
+ end
246
+ end
247
+
248
+ it "should place user-supplied options after default options" do
249
+ args = jruby_launcher_args("-J-Djruby.home=/tmp")
250
+ home_args = args.select {|x| x =~ /^-Djruby\.home/ }
251
+ home_args.length.should == 2
252
+ home_args.last.should == "-Djruby.home=/tmp"
253
+ end
254
+
255
+ it "should print the version" do
256
+ jruby_launcher("-Xversion 2>&1").should =~ /Launcher Version #{JRubyLauncher::VERSION}/
257
+ end
258
+ end