Skip to content

Commit 61ac7f3

Browse files
committed
fix runnable.jar test
* expected output from runnable test * get jruby spawn itself via rake_test_runner Sponsored by Lookout Inc.
1 parent bdb5bcb commit 61ac7f3

6 files changed

Lines changed: 37 additions & 11 deletions

File tree

core/src/main/java/org/jruby/util/ShellLauncher.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,17 @@ public static int runExternalAndWait(Ruby runtime, IRubyObject[] rawArgs, Map me
457457
} else {
458458
log(runtime, "Launching directly (no shell)");
459459
cfg.verifyExecutableForDirect();
460-
aProcess = buildProcess(runtime, cfg.getExecArgs(), getCurrentEnv(runtime, mergeEnv), pwd);
461460
}
461+
String[] args = cfg.getExecArgs();
462+
// only if we inside a jar and spawning org.jruby.Main we
463+
// change to the current directory inside the jar
464+
if (runtime.getCurrentDirectory().startsWith("uri:classloader:") &&
465+
args[args.length - 1].contains("org.jruby.Main")) {
466+
pwd = new File(System.getProperty("user.dir"));
467+
args[args.length - 1] = args[args.length - 1].replace("org.jruby.Main",
468+
"org.jruby.Main -C " + runtime.getCurrentDirectory());
469+
}
470+
aProcess = buildProcess(runtime, args, getCurrentEnv(runtime, mergeEnv), pwd);
462471
} catch (SecurityException se) {
463472
throw runtime.newSecurityError(se.getLocalizedMessage());
464473
}
@@ -497,12 +506,20 @@ public static long runExternal(Ruby runtime, IRubyObject env, IRubyObject prog,
497506
// execute command with sh -c
498507
// this does shell expansion of wildcards
499508
cfg.verifyExecutableForShell();
500-
aProcess = buildProcess(runtime, cfg.getExecArgs(), getCurrentEnv(runtime, (Map)env), pwd);
501509
} else {
502510
log(runtime, "Launching directly (no shell)");
503511
cfg.verifyExecutableForDirect();
504-
aProcess = buildProcess(runtime, cfg.getExecArgs(), getCurrentEnv(runtime, (Map)env), pwd);
505512
}
513+
String[] finalArgs = cfg.getExecArgs();
514+
// only if we inside a jar and spawning org.jruby.Main we
515+
// change to the current directory inside the jar
516+
if (runtime.getCurrentDirectory().startsWith("uri:classloader:") &&
517+
finalArgs[finalArgs.length - 1].contains("org.jruby.Main")) {
518+
pwd = new File(".");
519+
finalArgs[finalArgs.length - 1] = finalArgs[finalArgs.length - 1].replace("org.jruby.Main",
520+
"org.jruby.Main -C " + runtime.getCurrentDirectory());
521+
}
522+
aProcess = buildProcess(runtime, finalArgs, getCurrentEnv(runtime, (Map)env), pwd);
506523
} catch (SecurityException se) {
507524
throw runtime.newSecurityError(se.getLocalizedMessage());
508525
}
@@ -1432,7 +1449,7 @@ public static Process run(Ruby runtime, IRubyObject[] rawArgs, boolean doExecuta
14321449
log(runtime, "Launching directly (no shell)");
14331450
cfg.verifyExecutableForDirect();
14341451
}
1435-
String[] args = cfg.execArgs;
1452+
String[] args = cfg.getExecArgs();
14361453
// only if we inside a jar and spawning org.jruby.Main we
14371454
// change to the current directory inside the jar
14381455
if (runtime.getCurrentDirectory().startsWith("uri:classloader:") &&

core/src/main/java/org/jruby/util/cli/ArgumentProcessor.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,12 @@ private void processArgument() {
248248
config.getLoadPaths().addAll(Arrays.asList(ls));
249249
break FOR;
250250
case 'J':
251-
grabOptionalValue();
251+
String js = grabOptionalValue();
252252
config.getError().println("warning: " + argument + " argument ignored (launched in same VM?)");
253+
if (js.equals("-cp") || js.equals("-classpath")) {
254+
for(;grabOptionalValue() != null;) {}
255+
grabValue(getArgumentError(" -J-cp must be followed by a path expression"));
256+
}
253257
break FOR;
254258
case 'K':
255259
// FIXME: No argument seems to work for -K in MRI plus this should not

core/src/main/java/org/jruby/util/io/PopenExecutor.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,10 +1753,15 @@ private static void execFillarg(ThreadContext context, RubyString prog, IRubyObj
17531753
if (!opthash.isNil()) {
17541754
checkExecOptions(context, runtime, (RubyHash)opthash, eargp);
17551755
}
1756-
17571756
// add chdir if necessary
17581757
if (!runtime.getCurrentDirectory().equals(runtime.getPosix().getcwd())) {
1759-
if (!eargp.chdir_given()) { // only if :chdir is not specified
1758+
// only if we are inside a jar and spawning org.jruby.Main we
1759+
// change to the current directory inside the jar
1760+
if (runtime.getCurrentDirectory().startsWith("uri:classloader:") &&
1761+
prog.toString().contains("org.jruby.Main")) {
1762+
prog = RubyString.newString(runtime, prog.toString().replace("org.jruby.Main", "org.jruby.Main -C " + runtime.getCurrentDirectory()));
1763+
}
1764+
else if (!eargp.chdir_given()) { // only if :chdir is not specified
17601765
eargp.chdir_given_set();
17611766
eargp.chdir_dir = runtime.getCurrentDirectory();
17621767
}

maven/jruby-complete/src/it/extended/Mavenfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ phase :package do
2626
execute_goal( :exec, :id => 'rake -T',
2727
:arguments => [ '-jar', '${project.build.directory}/dependency/jruby-complete-${jruby.version}.jar', '-S', 'rake', '-T' ] )
2828

29-
execute_goal( :exec, :id => 'rake test:mri',
30-
:arguments => [ '-jar', '${project.build.directory}/dependency/jruby-complete-${jruby.version}.jar', '-S', 'rake', 'test:mri' ] )
29+
execute_goal( :exec, :id => 'rake test:objectspace',
30+
:arguments => [ '-jar', '${project.build.directory}/dependency/jruby-complete-${jruby.version}.jar', '-S', 'rake', 'test:objectspace' ] )
3131

3232
end
3333
end

maven/jruby-complete/src/it/extended/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
<argument>${project.build.directory}/dependency/jruby-complete-${jruby.version}.jar</argument>
6868
<argument>-S</argument>
6969
<argument>rake</argument>
70-
<argument>test:mri</argument>
70+
<argument>test:objectspace</argument>
7171
</arguments>
7272
</configuration>
7373
</execution>

maven/jruby/src/it/runnable/verify.bsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ String log = FileUtils.fileRead( new File( basedir, "build.log" ) );
66
String expected = "Run RSpec code examples";
77
if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" );
88

9-
expected = "uri:classloader:/Rakefile []";
9+
expected = "uri:classloader:/Rakefile [\"-T\"]";
1010
if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" );
1111

1212
expected = "uri:classloader:/Rakefile [\"spec\"]";

0 commit comments

Comments
 (0)