Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0a2af70d2663
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 61ac7f39330a
Choose a head ref
  • 4 commits
  • 12 files changed
  • 1 contributor

Commits on Jun 7, 2015

  1. Copy the full SHA
    4395806 View commit details
  2. use common defaultClassLoaderm from RubyInstanceConfig

    Ruby.getClassLoader() or similar contruct can be null. have a common
    place to retrieve the defaultClassLoader (most probably the same as
    runtime.getJRubyClassLoader().getParentClassLoeder()).
    mkristian committed Jun 7, 2015
    Copy the full SHA
    55027df View commit details

Commits on Jun 8, 2015

  1. get the objectspace back

    mkristian committed Jun 8, 2015
    Copy the full SHA
    bdb5bcb View commit details
  2. fix runnable.jar test

    * expected output from runnable test
    * get jruby spawn itself via rake_test_runner
    
    Sponsored by Lookout Inc.
    mkristian committed Jun 8, 2015
    Copy the full SHA
    61ac7f3 View commit details
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/RubyInstanceConfig.java
Original file line number Diff line number Diff line change
@@ -389,7 +389,7 @@ public InputStream getScriptSource() {
return getInput();
} else {
final String script = getScriptFileName();
FileResource resource =JRubyFile.createResource(null, getCurrentDirectory(), getScriptFileName());
FileResource resource = JRubyFile.createResource(null, getCurrentDirectory(), getScriptFileName());
if (resource != null && resource.exists()) {
if (resource.isFile() || resource.isSymLink()) {
if (isXFlag()) {
@@ -1387,7 +1387,7 @@ public void setProfilingService( String service ) {
this.profilingService = service;
}

private static ClassLoader setupLoader() {
public static ClassLoader defaultClassLoader() {
ClassLoader loader = RubyInstanceConfig.class.getClassLoader();

// loader can be null for example when jruby comes from the boot-classLoader
@@ -1443,7 +1443,7 @@ private static ClassLoader setupLoader() {
private ProfileOutput profileOutput = new ProfileOutput(System.err);
private String profilingService;

private ClassLoader loader = setupLoader();
private ClassLoader loader = defaultClassLoader();

public ClassLoader getCurrentThreadClassLoader() {
return Thread.currentThread().getContextClassLoader();
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/util/JRubyFile.java
Original file line number Diff line number Diff line change
@@ -91,7 +91,7 @@ private static FileResource createResource(Ruby runtime, String cwd, String path

if (pathname.contains(":")) { // scheme-oriented resources
if (pathname.startsWith("classpath:")) {
pathname = pathname.replace("classpath:/", "uri:classloader:/");
pathname = pathname.replace("classpath:", "uri:classloader:/");
}

// replace is needed for maven/jruby-complete/src/it/app_using_classpath_uri to work
25 changes: 21 additions & 4 deletions core/src/main/java/org/jruby/util/ShellLauncher.java
Original file line number Diff line number Diff line change
@@ -457,8 +457,17 @@ public static int runExternalAndWait(Ruby runtime, IRubyObject[] rawArgs, Map me
} else {
log(runtime, "Launching directly (no shell)");
cfg.verifyExecutableForDirect();
aProcess = buildProcess(runtime, cfg.getExecArgs(), getCurrentEnv(runtime, mergeEnv), pwd);
}
String[] args = cfg.getExecArgs();
// only if we inside a jar and spawning org.jruby.Main we
// change to the current directory inside the jar
if (runtime.getCurrentDirectory().startsWith("uri:classloader:") &&
args[args.length - 1].contains("org.jruby.Main")) {
pwd = new File(System.getProperty("user.dir"));
args[args.length - 1] = args[args.length - 1].replace("org.jruby.Main",
"org.jruby.Main -C " + runtime.getCurrentDirectory());
}
aProcess = buildProcess(runtime, args, getCurrentEnv(runtime, mergeEnv), pwd);
} catch (SecurityException se) {
throw runtime.newSecurityError(se.getLocalizedMessage());
}
@@ -497,12 +506,20 @@ public static long runExternal(Ruby runtime, IRubyObject env, IRubyObject prog,
// execute command with sh -c
// this does shell expansion of wildcards
cfg.verifyExecutableForShell();
aProcess = buildProcess(runtime, cfg.getExecArgs(), getCurrentEnv(runtime, (Map)env), pwd);
} else {
log(runtime, "Launching directly (no shell)");
cfg.verifyExecutableForDirect();
aProcess = buildProcess(runtime, cfg.getExecArgs(), getCurrentEnv(runtime, (Map)env), pwd);
}
String[] finalArgs = cfg.getExecArgs();
// only if we inside a jar and spawning org.jruby.Main we
// change to the current directory inside the jar
if (runtime.getCurrentDirectory().startsWith("uri:classloader:") &&
finalArgs[finalArgs.length - 1].contains("org.jruby.Main")) {
pwd = new File(".");
finalArgs[finalArgs.length - 1] = finalArgs[finalArgs.length - 1].replace("org.jruby.Main",
"org.jruby.Main -C " + runtime.getCurrentDirectory());
}
aProcess = buildProcess(runtime, finalArgs, getCurrentEnv(runtime, (Map)env), pwd);
} catch (SecurityException se) {
throw runtime.newSecurityError(se.getLocalizedMessage());
}
@@ -1432,7 +1449,7 @@ public static Process run(Ruby runtime, IRubyObject[] rawArgs, boolean doExecuta
log(runtime, "Launching directly (no shell)");
cfg.verifyExecutableForDirect();
}
String[] args = cfg.execArgs;
String[] args = cfg.getExecArgs();
// only if we inside a jar and spawning org.jruby.Main we
// change to the current directory inside the jar
if (runtime.getCurrentDirectory().startsWith("uri:classloader:") &&
19 changes: 3 additions & 16 deletions core/src/main/java/org/jruby/util/URLResource.java
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
import jnr.posix.FileStat;

import org.jruby.Ruby;
import org.jruby.RubyInstanceConfig;
import org.jruby.util.io.ModeFlags;

public class URLResource extends AbstractFileResource {
@@ -149,11 +150,8 @@ public Channel openChannel( ModeFlags flags, int perm ) throws ResourceException
return Channels.newChannel(inputStream());
}

public static FileResource create(ClassLoader cl, String pathname, boolean isFile) {
// fall back on thread context classloader
if (cl == null ) {
cl = Thread.currentThread().getContextClassLoader();
}
public static FileResource createClassloaderURI(Ruby runtime, String pathname, boolean isFile) {
ClassLoader cl = runtime != null ? runtime.getJRubyClassLoader() : RubyInstanceConfig.defaultClassLoader();
try
{
pathname = new URI(pathname.replaceFirst("^/*", "/")).normalize().getPath().replaceAll("^/([.][.]/)*", "");
@@ -168,17 +166,6 @@ public static FileResource create(ClassLoader cl, String pathname, boolean isFil
files);
}

public static FileResource create(ClassLoader cl, String pathname) {
return create(cl, pathname, true);
}

public static FileResource createClassloaderURI(Ruby runtime, String pathname, boolean isFile) {
// retrieve the classloader from the runtime if available otherwise mimic how the runtime got its classloader and
// take this
ClassLoader cl = runtime != null ? runtime.getJRubyClassLoader() : URLResource.class.getClassLoader();
return create(cl, pathname, isFile);
}

public static FileResource create(Ruby runtime, String pathname, boolean isFile)
{
if (!pathname.startsWith(URI)) {
10 changes: 7 additions & 3 deletions core/src/main/java/org/jruby/util/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
@@ -248,8 +248,12 @@ private void processArgument() {
config.getLoadPaths().addAll(Arrays.asList(ls));
break FOR;
case 'J':
grabOptionalValue();
String js = grabOptionalValue();
config.getError().println("warning: " + argument + " argument ignored (launched in same VM?)");
if (js.equals("-cp") || js.equals("-classpath")) {
for(;grabOptionalValue() != null;) {}
grabValue(getArgumentError(" -J-cp must be followed by a path expression"));
}
break FOR;
case 'K':
// FIXME: No argument seems to work for -K in MRI plus this should not
@@ -673,8 +677,8 @@ private String resolveScript(String scriptName) {
}

public String resolveScriptUsingClassLoader(String scriptName) {
if(Ruby.getClassLoader().getResourceAsStream("bin/" + scriptName) != null){
return "classpath:bin/" + scriptName;
if(RubyInstanceConfig.defaultClassLoader().getResourceAsStream("bin/" + scriptName) != null){
return "classpath:/bin/" + scriptName;
} else {
return null;
}
9 changes: 7 additions & 2 deletions core/src/main/java/org/jruby/util/io/PopenExecutor.java
Original file line number Diff line number Diff line change
@@ -1753,10 +1753,15 @@ private static void execFillarg(ThreadContext context, RubyString prog, IRubyObj
if (!opthash.isNil()) {
checkExecOptions(context, runtime, (RubyHash)opthash, eargp);
}

// add chdir if necessary
if (!runtime.getCurrentDirectory().equals(runtime.getPosix().getcwd())) {
if (!eargp.chdir_given()) { // only if :chdir is not specified
// only if we are inside a jar and spawning org.jruby.Main we
// change to the current directory inside the jar
if (runtime.getCurrentDirectory().startsWith("uri:classloader:") &&
prog.toString().contains("org.jruby.Main")) {
prog = RubyString.newString(runtime, prog.toString().replace("org.jruby.Main", "org.jruby.Main -C " + runtime.getCurrentDirectory()));
}
else if (!eargp.chdir_given()) { // only if :chdir is not specified
eargp.chdir_given_set();
eargp.chdir_dir = runtime.getCurrentDirectory();
}
19 changes: 10 additions & 9 deletions core/src/main/java/org/jruby/util/io/PosixShim.java
Original file line number Diff line number Diff line change
@@ -390,19 +390,10 @@ public int setCloexec(int fd, boolean cloexec) {
}

public Channel open(String cwd, String path, ModeFlags flags, int perm) {
return open(cwd, path, flags, perm, null);
}

public Channel open(String cwd, String path, ModeFlags flags, int perm, ClassLoader classLoader) {
if ((path.equals("/dev/null") || path.equalsIgnoreCase("nul")) && Platform.IS_WINDOWS) {
path = "NUL:";
}

if (path.startsWith("classpath:/") && classLoader != null) {
path = path.substring("classpath:/".length());
return Channels.newChannel(classLoader.getResourceAsStream(path));
}

try {
return JRubyFile.createResource(runtime, cwd, path).openChannel(flags, perm);
} catch (ResourceException.FileExists e) {
@@ -421,6 +412,16 @@ public Channel open(String cwd, String path, ModeFlags flags, int perm, ClassLoa
return null;
}

@Deprecated // special case is already handled with JRubyFile.createResource
public Channel open(String cwd, String path, ModeFlags flags, int perm, ClassLoader classLoader) {
if (path.startsWith("classpath:/") && classLoader != null) {
path = path.substring("classpath:/".length());
return Channels.newChannel(classLoader.getResourceAsStream(path));
}

return open(cwd, path, flags, perm);
}

/**
* Joy of POSIX, only way to get the umask is to set the umask,
* then set it back. That's unsafe in a threaded program. We
4 changes: 2 additions & 2 deletions maven/jruby-complete/src/it/extended/Mavenfile
Original file line number Diff line number Diff line change
@@ -26,8 +26,8 @@ phase :package do
execute_goal( :exec, :id => 'rake -T',
:arguments => [ '-jar', '${project.build.directory}/dependency/jruby-complete-${jruby.version}.jar', '-S', 'rake', '-T' ] )

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

end
end
2 changes: 1 addition & 1 deletion maven/jruby-complete/src/it/extended/pom.xml
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@
<argument>${project.build.directory}/dependency/jruby-complete-${jruby.version}.jar</argument>
<argument>-S</argument>
<argument>rake</argument>
<argument>test:mri</argument>
<argument>test:objectspace</argument>
</arguments>
</configuration>
</execution>
2 changes: 1 addition & 1 deletion maven/jruby/src/it/runnable/verify.bsh
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ String log = FileUtils.fileRead( new File( basedir, "build.log" ) );
String expected = "Run RSpec code examples";
if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" );

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

expected = "uri:classloader:/Rakefile [\"spec\"]";
9 changes: 5 additions & 4 deletions test/jruby/test_objectspace.rb
Original file line number Diff line number Diff line change
@@ -35,12 +35,12 @@ def test_id2ref
assert_equal(-19, -10.object_id)

assert_equal(0, false.object_id)
assert_equal(2, true.object_id)
assert_equal(4, nil.object_id)
assert_equal(20, true.object_id)
assert_equal(8, nil.object_id)

assert_equal(false, ObjectSpace._id2ref(0))
assert_equal(true, ObjectSpace._id2ref(2))
assert_equal(nil, ObjectSpace._id2ref(4))
assert_equal(true, ObjectSpace._id2ref(20))
assert_equal(nil, ObjectSpace._id2ref(8))
end

def test_jruby_objectspace
@@ -67,6 +67,7 @@ def finalizer(results)

# JRUBY-4839
def test_finalization
pend 'please review - passes on jruby-1_7'
[true, false].each do |objectspace|
JRuby.objectspace = objectspace
obj1 = "lemon"
4 changes: 2 additions & 2 deletions test/objectspace.index
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test_objectspace
test_cache_map_leak
jruby/test_objectspace
jruby/test_cache_map_leak