Skip to content

Commit

Permalink
put all the temporary jar created by the JRubyClassLoader into on dir…
Browse files Browse the repository at this point in the history
…ectory

these temporary jars get cleaned up after the jvm exits BUT on hard kill
the jars do not get cleaned. creating a directory 'jruby-${PID}' might help
to clean up easier.

Sponsored by Lookout Inc.
mkristian committed Sep 29, 2015
1 parent 94ae555 commit 28f6507
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion core/src/main/java/org/jruby/util/JRubyClassLoader.java
Original file line number Diff line number Diff line change
@@ -35,8 +35,10 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.management.ManagementFactory;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;

import org.jruby.util.log.Logger;
import org.jruby.util.log.LoggerFactory;
@@ -60,10 +62,26 @@ public class JRubyClassLoader extends ClassDefiningJRubyClassLoader {

private Runnable unloader;

private File tempdir;

public JRubyClassLoader(ClassLoader parent) {
super(parent);
}

private File getTempDir() {
if (tempdir == null) {
String processName = ManagementFactory.getRuntimeMXBean().getName();
long pid = Long.parseLong(processName.split("@")[0]);
File dir = new File(System.getProperty("java.io.tmpdir"), "jruby-" + pid);
if (dir.mkdirs()) {
dir.deleteOnExit();
}
;
tempdir = dir;
}
return tempdir;
}

// Change visibility so others can see it
@Override
public void addURL(URL url) {
@@ -74,7 +92,7 @@ public void addURL(URL url) {
OutputStream out = null;
try
{
File f = File.createTempFile( "jruby", new File(url.getFile()).getName());
File f = File.createTempFile("jruby", new File(url.getFile()).getName(), getTempDir());
f.deleteOnExit();
out = new BufferedOutputStream( new FileOutputStream( f ) );
in = new BufferedInputStream( url.openStream() );

0 comments on commit 28f6507

Please sign in to comment.