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 65c5183 commit 35c00d5
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion core/src/main/java/org/jruby/util/JRubyClassLoader.java
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@
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.security.ProtectionDomain;
@@ -74,10 +75,26 @@ public class JRubyClassLoader extends URLClassLoader implements ClassDefiningCla

private Runnable unloader;

private File tempdir;

public JRubyClassLoader(ClassLoader parent) {
super(new URL[0], 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;
}

public void addURLNoIndex(URL url) {
// if we have such embedded jar within a jar, we copy it to temp file and use the
// the temp file with the super URLClassLoader
@@ -86,7 +103,7 @@ public void addURLNoIndex(URL url) {
OutputStream out = null;
try
{
File f = File.createTempFile( "jruby", ".jar");
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 35c00d5

Please sign in to comment.