jruby-launcher 1.1.6-java → 1.1.7-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf1a6263145026e481e72cc8e449da659d0a51722966aee53bdd11d8073f17e6
4
- data.tar.gz: 2f7da6947f3d0f312a4c8ae147975ec40876c9031eecba25f20dca76ee3013bd
3
+ metadata.gz: 5b74c8761b44ded219baeb642d6506839943352037a337a972e37ad45c1e9e3d
4
+ data.tar.gz: 690574f72d73bc9d5cc182b65b82daafb1c4cadc6c253b88b6dc6a278c5330a7
5
5
  SHA512:
6
- metadata.gz: 753ade7fdfb6a7cf57b3d061c90f497eb503c78da696f9d98bfd2909ea4919516a196d5cbde9c625da94961aad84f4516bb03b949423377358e2087fc4666dbe
7
- data.tar.gz: 7c9fc6f159eac1cac4694d00b6442237c7620e04da9041a5b981ceb4fd5db397a9ae21d568bfd202af5861d83270030773dcc4f56db4f388279a9a6746a0abf4
6
+ metadata.gz: f7427b82e4e37b377f340024dcbcca67adeee3eb56543b8342b2a9054c8f5fc402d3c026ba968bb3061bbb8fe4c5bf131e341951de8b5cf91d5bd3f504b7464e
7
+ data.tar.gz: 71aa944a438acabb26441b2123f66510e70aed608d42d6db030bfa4924f7b914d25ec401ca5c15a5dd39fbac85bcbcdd92f1df077861e795a808506ed784d25d
@@ -60,6 +60,7 @@ const char *ArgParser::OPT_JRUBY_HOME = "-Djruby.home=";
60
60
  const char *ArgParser::OPT_JRUBY_COMMAND_NAME = "-Dsun.java.command=";
61
61
 
62
62
  const char *ArgParser::OPT_CMDLINE_CLASS_PATH = "-cp";
63
+ const char *ArgParser::OPT_CMDLINE_MODULE_PATH = "--module-path";
63
64
  const char *ArgParser::OPT_CLASS_PATH = "-Djava.class.path=";
64
65
  const char *ArgParser::OPT_BOOT_CLASS_PATH = "-Xbootclasspath/a:";
65
66
 
@@ -462,6 +463,8 @@ void ArgParser::prepareOptions() {
462
463
 
463
464
  setupMaxHeapAndStack(userOptions);
464
465
 
466
+ useModulesIfPresent();
467
+
465
468
  constructBootClassPath();
466
469
  constructClassPath();
467
470
 
@@ -481,8 +484,12 @@ void ArgParser::prepareOptions() {
481
484
  option += cmdName;
482
485
  javaOptions.push_back(option);
483
486
 
484
- // When launching a separate process, use '-cp' which expands embedded wildcards
485
- if (separateProcess) {
487
+ if (useModulePath) {
488
+ // When modules are present, use module path
489
+ javaOptions.push_back(OPT_CMDLINE_MODULE_PATH);
490
+ javaOptions.push_back(classPath);
491
+ } else if (separateProcess) {
492
+ // When launching a separate process, use '-cp' which expands embedded wildcards
486
493
  javaOptions.push_back(OPT_CMDLINE_CLASS_PATH);
487
494
  javaOptions.push_back(classPath);
488
495
  } else {
@@ -515,6 +522,18 @@ void ArgParser::setupMaxHeapAndStack(list<string> userOptions) {
515
522
  }
516
523
  }
517
524
 
525
+ void ArgParser::useModulesIfPresent() {
526
+ logMsg("useModulesIfPresent()");
527
+
528
+ if (jdkhome.empty()) {
529
+ logMsg("Unable to detect JPMS modules as JAVA_HOME is not specified");
530
+ } else if (access((jdkhome + "/jmods").c_str(), R_OK) == 0) {
531
+ logMsg("JPMS jmods dir detected, using module flags");
532
+ noBootClassPath = 1;
533
+ useModulePath = 1;
534
+ }
535
+ }
536
+
518
537
  void ArgParser::constructBootClassPath() {
519
538
  logMsg("constructBootClassPath()");
520
539
  addedToBootCP.clear();
@@ -20,6 +20,7 @@ protected:
20
20
  static const char *OPT_JRUBY_COMMAND_NAME;
21
21
 
22
22
  static const char *OPT_CMDLINE_CLASS_PATH;
23
+ static const char *OPT_CMDLINE_MODULE_PATH;
23
24
  static const char *OPT_CLASS_PATH;
24
25
  static const char *OPT_BOOT_CLASS_PATH;
25
26
 
@@ -52,12 +53,14 @@ protected:
52
53
  void addJarsToClassPathFrom(const char *dir);
53
54
  void addOptionsToCommandLine(std::list<std::string> & commandLine);
54
55
  bool endsWith(const std::string &string, const std::string &end);
56
+ void useModulesIfPresent();
55
57
 
56
58
  protected:
57
59
  bool separateProcess;
58
60
  bool nailgunClient;
59
61
  bool noBootClassPath;
60
62
  bool printCommandLine;
63
+ bool useModulePath;
61
64
  std::string platformDir;
62
65
  std::string bootclass;
63
66
  std::string jdkhome;
@@ -1,3 +1,3 @@
1
1
  module JRubyLauncher
2
- VERSION = "1.1.6"
2
+ VERSION = "1.1.7"
3
3
  end
@@ -0,0 +1,5 @@
1
+ mf = File.read('Makefile')
2
+ mf = mf.gsub(/^BINDIR\s*=.*$/, "BINDIR = #{RbConfig::CONFIG['bindir']}")
3
+ mf = mf.gsub(/^PREFIX\s*=.*$/, "PREFIX = #{File.dirname(RbConfig::CONFIG['libdir'])}")
4
+ puts mf
5
+ File.open('Makefile', 'wb') {|f| f << mf}
@@ -0,0 +1,3 @@
1
+ module JRubyLauncher
2
+ VERSION = "1.1.6.pre"
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,5 @@
1
+ mf = File.read('Makefile')
2
+ mf = mf.gsub(/^BINDIR\s*=.*$/, "BINDIR = #{RbConfig::CONFIG['bindir']}")
3
+ mf = mf.gsub(/^PREFIX\s*=.*$/, "PREFIX = #{File.dirname(RbConfig::CONFIG['libdir'])}")
4
+ puts mf
5
+ File.open('Makefile', 'wb') {|f| f << mf}
@@ -0,0 +1,3 @@
1
+ module JRubyLauncher
2
+ VERSION = "1.1.6.pre"
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.select {|l| l =~ /JRuby Launcher usage/}.should_not be_empty
16
+ args.should include("-X")
17
+ args = jruby_launcher_args("-X 2>&1")
18
+ args.detect {|l| l =~ /JRuby Launcher usage/}.should_not be_empty
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 allow max heap to be overridden" do
98
+ jruby_launcher_args("-J-Xmx256m").should include("-Xmx256m")
99
+ end
100
+
101
+ it "should default to 2048k max stack" do
102
+ jruby_launcher_args("").should include("-Xss2048k")
103
+ end
104
+
105
+ it "should allow max stack to be overridden" do
106
+ jruby_launcher_args("-J-Xss512k").should include("-Xss512k")
107
+ end
108
+
109
+ it "should add the contents of the CLASSPATH environment variable" do
110
+ with_environment "CLASSPATH" => "some.jar" do
111
+ classpath_arg(jruby_launcher_args("")).should =~ /some.jar/
112
+ end
113
+ end
114
+
115
+ it "should add the classpath elements in proper order" do
116
+ s = File::PATH_SEPARATOR
117
+ with_environment "CLASSPATH" => "some-env.jar" do
118
+ args = jruby_launcher_args("-Xcp:a some-other.jar -Xcp:p some.jar")
119
+ classpath_arg(args).should =~ /some.jar.*#{s}some-env.jar#{s}some-other.jar/
120
+ end
121
+ end
122
+
123
+ it "should use the --server compiler" do
124
+ jruby_launcher_args("--server").should include("-server")
125
+ end
126
+
127
+ it "should use the --client compiler" do
128
+ jruby_launcher_args("--client").should include("-client")
129
+ end
130
+
131
+ it "should set the JMX settings when --manage is present" do
132
+ jruby_launcher_args("--manage").should include("-Dcom.sun.management.jmxremote", "-Djruby.management.enabled=true")
133
+ end
134
+
135
+ it "should set the headless flag when --headless is present" do
136
+ jruby_launcher_args("--headless").should include("-Djava.awt.headless=true")
137
+ end
138
+
139
+ it "should pass -Xprof when --sample is present" do
140
+ jruby_launcher_args("--sample").should include("-Xprof")
141
+ end
142
+
143
+ it "should stop argument processing when a -- is seen" do
144
+ jruby_launcher_args("-- -Xhelp -Xtrace --headless").should include("-Xhelp", "-Xtrace", "--headless")
145
+ end
146
+
147
+ # JRUBY-4151
148
+ it "should properly handle single quotes" do
149
+ jruby_launcher_args("-e 'ABC DEF'").should include("ABC DEF")
150
+ end
151
+
152
+ # JRUBY-4581
153
+ it "should prepend JRUBY_OPTS to the start of the argument list to process" do
154
+ with_environment "JRUBY_OPTS" => "--server -J-Dsome.key=val -rubygems" do
155
+ jruby_launcher_args("-e 'ABC DEF'").should include("-server", "-Dsome.key=val", "-rubygems", "-e", "ABC DEF")
156
+ end
157
+ end
158
+
159
+ # JRUBY-4611
160
+ it "stops argument processing on first non-option argument" do
161
+ jruby_launcher_args("foo.rb --sample")[-2..-1].should == ["foo.rb", "--sample"]
162
+ end
163
+
164
+ # JRUBY-4608
165
+ if RbConfig::CONFIG['target_os'] =~ /darwin/i
166
+ it "includes file.encoding=UTF-8 on Mac if JAVA_ENCODING is not set" do
167
+ jruby_launcher_args("-e true").should include("-Dfile.encoding=UTF-8")
168
+ with_environment "JAVA_ENCODING" => "MacRoman" do
169
+ jruby_launcher_args("-e true").should_not include("-Dfile.encoding=UTF-8")
170
+ end
171
+ end
172
+ end
173
+
174
+ it "does not crash on empty args" do
175
+ jruby_launcher_args("-e ''").should include("-e")
176
+ jruby_launcher("-Xtrace '' 2>&1").should =~ /-Xtrace/
177
+ jruby_launcher("-Xjdkhome '' 2>&1").should =~ /-Xjdkhome/
178
+ end
179
+
180
+ # JRUBY-4706
181
+ it "should put JRuby on regular classpath when -Xnobootclasspath is used" do
182
+ args = jruby_launcher_args("-e true")
183
+ args.grep(/Xbootclasspath/).should_not be_empty
184
+ args = jruby_launcher_args("-Xnobootclasspath -e true")
185
+ args.grep(/Xbootclasspath/).should be_empty
186
+ end
187
+
188
+ it "should put JRuby on regular classpath when VERIFY_JRUBY is set" do
189
+ with_environment "VERIFY_JRUBY" => "true" do
190
+ args = jruby_launcher_args("-e true")
191
+ args.grep(/Xbootclasspath/).should be_empty
192
+ end
193
+ end
194
+
195
+ # JRUBY-4709
196
+ it "should include a bare : or ; at the end of the classpath, to include PWD in the path" do
197
+ classpath_arg(jruby_launcher_args("-Xnobootclasspath -e true")).should =~
198
+ if windows?
199
+ /;$/
200
+ else
201
+ /:$/
202
+ end
203
+ end
204
+
205
+ # JRUBY-6016
206
+ it "should honor JAVA_MEM" do
207
+ with_environment "JAVA_MEM" => "-Xmx768m" do
208
+ jruby_launcher_args("").should include("-Xmx768m")
209
+ end
210
+ end
211
+
212
+ it "should honor JAVA_STACK" do
213
+ with_environment "JAVA_STACK" => "-Xss3072k" do
214
+ jruby_launcher_args("").should include("-Xss3072k")
215
+ end
216
+ end
217
+
218
+ it "should honor JRUBY_HOME" do
219
+ with_environment "JRUBY_HOME" => "/tmp" do
220
+ jruby_launcher_args("").should include("-Djruby.home=/tmp")
221
+ end
222
+ end
223
+
224
+ context "JRUBY_HOME set and JRUBY_HOME/lib/jruby.jar exists" do
225
+ let(:jruby_home) do
226
+ require 'tempfile'
227
+ t = Tempfile.new("jruby_home")
228
+ t.path.tap { t.close! }
229
+ end
230
+
231
+ before do
232
+ FileUtils.mkdir_p(File.join(jruby_home, "lib"))
233
+ FileUtils.touch(File.join(jruby_home, "lib", "jruby.jar"))
234
+ end
235
+ after { FileUtils.rm_rf jruby_home }
236
+
237
+ it "should add jruby.jar to the bootclasspath" do
238
+ with_environment "JRUBY_HOME" => jruby_home do
239
+ jruby_launcher_args("").should include("-Xbootclasspath/a:#{jruby_home}/lib/jruby.jar")
240
+ end
241
+ end
242
+ end
243
+
244
+ it "should place user-supplied options after default options" do
245
+ args = jruby_launcher_args("-J-Djruby.home=/tmp")
246
+ home_args = args.select {|x| x =~ /^-Djruby\.home/ }
247
+ home_args.length.should == 2
248
+ home_args.last.should == "-Djruby.home=/tmp"
249
+ end
250
+
251
+ it "should print the version" do
252
+ jruby_launcher("-Xversion 2>&1").should =~ /Launcher Version #{JRubyLauncher::VERSION}/
253
+ end
254
+
255
+ it "should not crash on format-strings" do
256
+ jruby_launcher_args("-e %s%s%s%s%s 2>&1").should include('-e', '%s%s%s%s%s')
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.select {|l| l =~ /JRuby Launcher usage/}.should_not be_empty
16
+ args.should include("-X")
17
+ args = jruby_launcher_args("-X 2>&1")
18
+ args.detect {|l| l =~ /JRuby Launcher usage/}.should_not be_empty
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 allow max heap to be overridden" do
98
+ jruby_launcher_args("-J-Xmx256m").should include("-Xmx256m")
99
+ end
100
+
101
+ it "should default to 2048k max stack" do
102
+ jruby_launcher_args("").should include("-Xss2048k")
103
+ end
104
+
105
+ it "should allow max stack to be overridden" do
106
+ jruby_launcher_args("-J-Xss512k").should include("-Xss512k")
107
+ end
108
+
109
+ it "should add the contents of the CLASSPATH environment variable" do
110
+ with_environment "CLASSPATH" => "some.jar" do
111
+ classpath_arg(jruby_launcher_args("")).should =~ /some.jar/
112
+ end
113
+ end
114
+
115
+ it "should add the classpath elements in proper order" do
116
+ s = File::PATH_SEPARATOR
117
+ with_environment "CLASSPATH" => "some-env.jar" do
118
+ args = jruby_launcher_args("-Xcp:a some-other.jar -Xcp:p some.jar")
119
+ classpath_arg(args).should =~ /some.jar.*#{s}some-env.jar#{s}some-other.jar/
120
+ end
121
+ end
122
+
123
+ it "should use the --server compiler" do
124
+ jruby_launcher_args("--server").should include("-server")
125
+ end
126
+
127
+ it "should use the --client compiler" do
128
+ jruby_launcher_args("--client").should include("-client")
129
+ end
130
+
131
+ it "should set the JMX settings when --manage is present" do
132
+ jruby_launcher_args("--manage").should include("-Dcom.sun.management.jmxremote", "-Djruby.management.enabled=true")
133
+ end
134
+
135
+ it "should set the headless flag when --headless is present" do
136
+ jruby_launcher_args("--headless").should include("-Djava.awt.headless=true")
137
+ end
138
+
139
+ it "should pass -Xprof when --sample is present" do
140
+ jruby_launcher_args("--sample").should include("-Xprof")
141
+ end
142
+
143
+ it "should stop argument processing when a -- is seen" do
144
+ jruby_launcher_args("-- -Xhelp -Xtrace --headless").should include("-Xhelp", "-Xtrace", "--headless")
145
+ end
146
+
147
+ # JRUBY-4151
148
+ it "should properly handle single quotes" do
149
+ jruby_launcher_args("-e 'ABC DEF'").should include("ABC DEF")
150
+ end
151
+
152
+ # JRUBY-4581
153
+ it "should prepend JRUBY_OPTS to the start of the argument list to process" do
154
+ with_environment "JRUBY_OPTS" => "--server -J-Dsome.key=val -rubygems" do
155
+ jruby_launcher_args("-e 'ABC DEF'").should include("-server", "-Dsome.key=val", "-rubygems", "-e", "ABC DEF")
156
+ end
157
+ end
158
+
159
+ # JRUBY-4611
160
+ it "stops argument processing on first non-option argument" do
161
+ jruby_launcher_args("foo.rb --sample")[-2..-1].should == ["foo.rb", "--sample"]
162
+ end
163
+
164
+ # JRUBY-4608
165
+ if RbConfig::CONFIG['target_os'] =~ /darwin/i
166
+ it "includes file.encoding=UTF-8 on Mac if JAVA_ENCODING is not set" do
167
+ jruby_launcher_args("-e true").should include("-Dfile.encoding=UTF-8")
168
+ with_environment "JAVA_ENCODING" => "MacRoman" do
169
+ jruby_launcher_args("-e true").should_not include("-Dfile.encoding=UTF-8")
170
+ end
171
+ end
172
+ end
173
+
174
+ it "does not crash on empty args" do
175
+ jruby_launcher_args("-e ''").should include("-e")
176
+ jruby_launcher("-Xtrace '' 2>&1").should =~ /-Xtrace/
177
+ jruby_launcher("-Xjdkhome '' 2>&1").should =~ /-Xjdkhome/
178
+ end
179
+
180
+ # JRUBY-4706
181
+ it "should put JRuby on regular classpath when -Xnobootclasspath is used" do
182
+ args = jruby_launcher_args("-e true")
183
+ args.grep(/Xbootclasspath/).should_not be_empty
184
+ args = jruby_launcher_args("-Xnobootclasspath -e true")
185
+ args.grep(/Xbootclasspath/).should be_empty
186
+ end
187
+
188
+ it "should put JRuby on regular classpath when VERIFY_JRUBY is set" do
189
+ with_environment "VERIFY_JRUBY" => "true" do
190
+ args = jruby_launcher_args("-e true")
191
+ args.grep(/Xbootclasspath/).should be_empty
192
+ end
193
+ end
194
+
195
+ # JRUBY-4709
196
+ it "should include a bare : or ; at the end of the classpath, to include PWD in the path" do
197
+ classpath_arg(jruby_launcher_args("-Xnobootclasspath -e true")).should =~
198
+ if windows?
199
+ /;$/
200
+ else
201
+ /:$/
202
+ end
203
+ end
204
+
205
+ # JRUBY-6016
206
+ it "should honor JAVA_MEM" do
207
+ with_environment "JAVA_MEM" => "-Xmx768m" do
208
+ jruby_launcher_args("").should include("-Xmx768m")
209
+ end
210
+ end
211
+
212
+ it "should honor JAVA_STACK" do
213
+ with_environment "JAVA_STACK" => "-Xss3072k" do
214
+ jruby_launcher_args("").should include("-Xss3072k")
215
+ end
216
+ end
217
+
218
+ it "should honor JRUBY_HOME" do
219
+ with_environment "JRUBY_HOME" => "/tmp" do
220
+ jruby_launcher_args("").should include("-Djruby.home=/tmp")
221
+ end
222
+ end
223
+
224
+ context "JRUBY_HOME set and JRUBY_HOME/lib/jruby.jar exists" do
225
+ let(:jruby_home) do
226
+ require 'tempfile'
227
+ t = Tempfile.new("jruby_home")
228
+ t.path.tap { t.close! }
229
+ end
230
+
231
+ before do
232
+ FileUtils.mkdir_p(File.join(jruby_home, "lib"))
233
+ FileUtils.touch(File.join(jruby_home, "lib", "jruby.jar"))
234
+ end
235
+ after { FileUtils.rm_rf jruby_home }
236
+
237
+ it "should add jruby.jar to the bootclasspath" do
238
+ with_environment "JRUBY_HOME" => jruby_home do
239
+ jruby_launcher_args("").should include("-Xbootclasspath/a:#{jruby_home}/lib/jruby.jar")
240
+ end
241
+ end
242
+ end
243
+
244
+ it "should place user-supplied options after default options" do
245
+ args = jruby_launcher_args("-J-Djruby.home=/tmp")
246
+ home_args = args.select {|x| x =~ /^-Djruby\.home/ }
247
+ home_args.length.should == 2
248
+ home_args.last.should == "-Djruby.home=/tmp"
249
+ end
250
+
251
+ it "should print the version" do
252
+ jruby_launcher("-Xversion 2>&1").should =~ /Launcher Version #{JRubyLauncher::VERSION}/
253
+ end
254
+
255
+ it "should not crash on format-strings" do
256
+ jruby_launcher_args("-e %s%s%s%s%s 2>&1").should include('-e', '%s%s%s%s%s')
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,5 @@
1
+ mf = File.read('Makefile')
2
+ mf = mf.gsub(/^BINDIR\s*=.*$/, "BINDIR = #{RbConfig::CONFIG['bindir']}")
3
+ mf = mf.gsub(/^PREFIX\s*=.*$/, "PREFIX = #{File.dirname(RbConfig::CONFIG['libdir'])}")
4
+ puts mf
5
+ File.open('Makefile', 'wb') {|f| f << mf}
@@ -0,0 +1,3 @@
1
+ module JRubyLauncher
2
+ VERSION = "1.1.6.pre"
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.select {|l| l =~ /JRuby Launcher usage/}.should_not be_empty
16
+ args.should include("-X")
17
+ args = jruby_launcher_args("-X 2>&1")
18
+ args.detect {|l| l =~ /JRuby Launcher usage/}.should_not be_empty
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 allow max heap to be overridden" do
98
+ jruby_launcher_args("-J-Xmx256m").should include("-Xmx256m")
99
+ end
100
+
101
+ it "should default to 2048k max stack" do
102
+ jruby_launcher_args("").should include("-Xss2048k")
103
+ end
104
+
105
+ it "should allow max stack to be overridden" do
106
+ jruby_launcher_args("-J-Xss512k").should include("-Xss512k")
107
+ end
108
+
109
+ it "should add the contents of the CLASSPATH environment variable" do
110
+ with_environment "CLASSPATH" => "some.jar" do
111
+ classpath_arg(jruby_launcher_args("")).should =~ /some.jar/
112
+ end
113
+ end
114
+
115
+ it "should add the classpath elements in proper order" do
116
+ s = File::PATH_SEPARATOR
117
+ with_environment "CLASSPATH" => "some-env.jar" do
118
+ args = jruby_launcher_args("-Xcp:a some-other.jar -Xcp:p some.jar")
119
+ classpath_arg(args).should =~ /some.jar.*#{s}some-env.jar#{s}some-other.jar/
120
+ end
121
+ end
122
+
123
+ it "should use the --server compiler" do
124
+ jruby_launcher_args("--server").should include("-server")
125
+ end
126
+
127
+ it "should use the --client compiler" do
128
+ jruby_launcher_args("--client").should include("-client")
129
+ end
130
+
131
+ it "should set the JMX settings when --manage is present" do
132
+ jruby_launcher_args("--manage").should include("-Dcom.sun.management.jmxremote", "-Djruby.management.enabled=true")
133
+ end
134
+
135
+ it "should set the headless flag when --headless is present" do
136
+ jruby_launcher_args("--headless").should include("-Djava.awt.headless=true")
137
+ end
138
+
139
+ it "should pass -Xprof when --sample is present" do
140
+ jruby_launcher_args("--sample").should include("-Xprof")
141
+ end
142
+
143
+ it "should stop argument processing when a -- is seen" do
144
+ jruby_launcher_args("-- -Xhelp -Xtrace --headless").should include("-Xhelp", "-Xtrace", "--headless")
145
+ end
146
+
147
+ # JRUBY-4151
148
+ it "should properly handle single quotes" do
149
+ jruby_launcher_args("-e 'ABC DEF'").should include("ABC DEF")
150
+ end
151
+
152
+ # JRUBY-4581
153
+ it "should prepend JRUBY_OPTS to the start of the argument list to process" do
154
+ with_environment "JRUBY_OPTS" => "--server -J-Dsome.key=val -rubygems" do
155
+ jruby_launcher_args("-e 'ABC DEF'").should include("-server", "-Dsome.key=val", "-rubygems", "-e", "ABC DEF")
156
+ end
157
+ end
158
+
159
+ # JRUBY-4611
160
+ it "stops argument processing on first non-option argument" do
161
+ jruby_launcher_args("foo.rb --sample")[-2..-1].should == ["foo.rb", "--sample"]
162
+ end
163
+
164
+ # JRUBY-4608
165
+ if RbConfig::CONFIG['target_os'] =~ /darwin/i
166
+ it "includes file.encoding=UTF-8 on Mac if JAVA_ENCODING is not set" do
167
+ jruby_launcher_args("-e true").should include("-Dfile.encoding=UTF-8")
168
+ with_environment "JAVA_ENCODING" => "MacRoman" do
169
+ jruby_launcher_args("-e true").should_not include("-Dfile.encoding=UTF-8")
170
+ end
171
+ end
172
+ end
173
+
174
+ it "does not crash on empty args" do
175
+ jruby_launcher_args("-e ''").should include("-e")
176
+ jruby_launcher("-Xtrace '' 2>&1").should =~ /-Xtrace/
177
+ jruby_launcher("-Xjdkhome '' 2>&1").should =~ /-Xjdkhome/
178
+ end
179
+
180
+ # JRUBY-4706
181
+ it "should put JRuby on regular classpath when -Xnobootclasspath is used" do
182
+ args = jruby_launcher_args("-e true")
183
+ args.grep(/Xbootclasspath/).should_not be_empty
184
+ args = jruby_launcher_args("-Xnobootclasspath -e true")
185
+ args.grep(/Xbootclasspath/).should be_empty
186
+ end
187
+
188
+ it "should put JRuby on regular classpath when VERIFY_JRUBY is set" do
189
+ with_environment "VERIFY_JRUBY" => "true" do
190
+ args = jruby_launcher_args("-e true")
191
+ args.grep(/Xbootclasspath/).should be_empty
192
+ end
193
+ end
194
+
195
+ # JRUBY-4709
196
+ it "should include a bare : or ; at the end of the classpath, to include PWD in the path" do
197
+ classpath_arg(jruby_launcher_args("-Xnobootclasspath -e true")).should =~
198
+ if windows?
199
+ /;$/
200
+ else
201
+ /:$/
202
+ end
203
+ end
204
+
205
+ # JRUBY-6016
206
+ it "should honor JAVA_MEM" do
207
+ with_environment "JAVA_MEM" => "-Xmx768m" do
208
+ jruby_launcher_args("").should include("-Xmx768m")
209
+ end
210
+ end
211
+
212
+ it "should honor JAVA_STACK" do
213
+ with_environment "JAVA_STACK" => "-Xss3072k" do
214
+ jruby_launcher_args("").should include("-Xss3072k")
215
+ end
216
+ end
217
+
218
+ it "should honor JRUBY_HOME" do
219
+ with_environment "JRUBY_HOME" => "/tmp" do
220
+ jruby_launcher_args("").should include("-Djruby.home=/tmp")
221
+ end
222
+ end
223
+
224
+ context "JRUBY_HOME set and JRUBY_HOME/lib/jruby.jar exists" do
225
+ let(:jruby_home) do
226
+ require 'tempfile'
227
+ t = Tempfile.new("jruby_home")
228
+ t.path.tap { t.close! }
229
+ end
230
+
231
+ before do
232
+ FileUtils.mkdir_p(File.join(jruby_home, "lib"))
233
+ FileUtils.touch(File.join(jruby_home, "lib", "jruby.jar"))
234
+ end
235
+ after { FileUtils.rm_rf jruby_home }
236
+
237
+ it "should add jruby.jar to the bootclasspath" do
238
+ with_environment "JRUBY_HOME" => jruby_home do
239
+ jruby_launcher_args("").should include("-Xbootclasspath/a:#{jruby_home}/lib/jruby.jar")
240
+ end
241
+ end
242
+ end
243
+
244
+ it "should place user-supplied options after default options" do
245
+ args = jruby_launcher_args("-J-Djruby.home=/tmp")
246
+ home_args = args.select {|x| x =~ /^-Djruby\.home/ }
247
+ home_args.length.should == 2
248
+ home_args.last.should == "-Djruby.home=/tmp"
249
+ end
250
+
251
+ it "should print the version" do
252
+ jruby_launcher("-Xversion 2>&1").should =~ /Launcher Version #{JRubyLauncher::VERSION}/
253
+ end
254
+
255
+ it "should not crash on format-strings" do
256
+ jruby_launcher_args("-e %s%s%s%s%s 2>&1").should include('-e', '%s%s%s%s%s')
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
@@ -138,8 +138,6 @@ bool PlatformLauncher::start(char* argv[], int argc, DWORD *retCode, const char*
138
138
  }
139
139
  }
140
140
 
141
- prepareOptions();
142
-
143
141
  string java("");
144
142
 
145
143
  if (getenv("JAVACMD") != NULL) {
@@ -159,6 +157,8 @@ bool PlatformLauncher::start(char* argv[], int argc, DWORD *retCode, const char*
159
157
  java = jdkhome + "\\bin\\java";
160
158
  }
161
159
 
160
+ prepareOptions();
161
+
162
162
  if (printCommandLine) {
163
163
  list<string> commandLine;
164
164
  commandLine.push_back(java);
@@ -94,10 +94,6 @@ describe "JRuby native launcher" do
94
94
  jruby_launcher_args("-Xproperties").should include("--properties")
95
95
  end
96
96
 
97
- it "should default to 500m max heap" do
98
- jruby_launcher_args("").should include("-Xmx500m")
99
- end
100
-
101
97
  it "should allow max heap to be overridden" do
102
98
  jruby_launcher_args("-J-Xmx256m").should include("-Xmx256m")
103
99
  end
@@ -42,8 +42,6 @@ int UnixLauncher::run(int argc, char* argv[], char* envp[]) {
42
42
  return nailgunClientMain(progArgs.size(), (char**)nailArgv, envp);
43
43
  }
44
44
 
45
- prepareOptions();
46
-
47
45
  string java("");
48
46
 
49
47
  if (getenv("JAVACMD") != NULL) {
@@ -53,6 +51,7 @@ int UnixLauncher::run(int argc, char* argv[], char* envp[]) {
53
51
  java = jdkhome + "/bin/java";
54
52
  } else if (getenv("JAVA_HOME") != NULL) {
55
53
  string java_home = string(getenv("JAVA_HOME"));
54
+ jdkhome = java_home;
56
55
  java_home = trimTrailingBackslashes(java_home);
57
56
  java = java_home + "/bin/java";
58
57
  } else {
@@ -65,6 +64,8 @@ int UnixLauncher::run(int argc, char* argv[], char* envp[]) {
65
64
  return 255;
66
65
  }
67
66
 
67
+ prepareOptions();
68
+
68
69
  list<string> commandLine;
69
70
  commandLine.push_back(java);
70
71
  addOptionsToCommandLine(commandLine);
data/version.h CHANGED
@@ -6,6 +6,6 @@
6
6
  #ifndef _VERSION_H_
7
7
  #define _VERSION_H_
8
8
 
9
- #define JRUBY_LAUNCHER_VERSION "1.1.6"
9
+ #define JRUBY_LAUNCHER_VERSION "1.1.7"
10
10
 
11
11
  #endif // ! _VERSION_H_
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jruby-launcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.1.7
5
5
  platform: java
6
6
  authors:
7
7
  - Nick Sieger
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-09-19 00:00:00.000000000 Z
12
+ date: 2018-11-14 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Builds and installs a native launcher for JRuby on your system
15
15
  email:
@@ -39,6 +39,21 @@ files:
39
39
  - lib/rubygems/defaults/jruby_native.rb
40
40
  - nbexecloader.h
41
41
  - ng.c
42
+ - pkg/jruby-launcher-1.1.5-java/extconf.rb
43
+ - pkg/jruby-launcher-1.1.5-java/lib/jruby-launcher.rb
44
+ - pkg/jruby-launcher-1.1.5-java/lib/rubygems/defaults/jruby_native.rb
45
+ - pkg/jruby-launcher-1.1.5-java/pkg/jruby-launcher-1.1.5.pre-java/extconf.rb
46
+ - pkg/jruby-launcher-1.1.5-java/pkg/jruby-launcher-1.1.5.pre-java/lib/jruby-launcher.rb
47
+ - pkg/jruby-launcher-1.1.5-java/pkg/jruby-launcher-1.1.5.pre-java/lib/rubygems/defaults/jruby_native.rb
48
+ - pkg/jruby-launcher-1.1.5-java/pkg/jruby-launcher-1.1.5.pre-java/spec/launcher_spec.rb
49
+ - pkg/jruby-launcher-1.1.5-java/pkg/jruby-launcher-1.1.5.pre-java/spec/spec_helper.rb
50
+ - pkg/jruby-launcher-1.1.5-java/spec/launcher_spec.rb
51
+ - pkg/jruby-launcher-1.1.5-java/spec/spec_helper.rb
52
+ - pkg/jruby-launcher-1.1.5.pre-java/extconf.rb
53
+ - pkg/jruby-launcher-1.1.5.pre-java/lib/jruby-launcher.rb
54
+ - pkg/jruby-launcher-1.1.5.pre-java/lib/rubygems/defaults/jruby_native.rb
55
+ - pkg/jruby-launcher-1.1.5.pre-java/spec/launcher_spec.rb
56
+ - pkg/jruby-launcher-1.1.5.pre-java/spec/spec_helper.rb
42
57
  - platformlauncher.cpp
43
58
  - platformlauncher.h
44
59
  - rb_w32_cmdvector.h