Skip to content

Commit

Permalink
Make temp dir available to users
Browse files Browse the repository at this point in the history
  • Loading branch information
hollingsworthd committed Nov 24, 2015
1 parent 6dfca5a commit 46f1c48
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/com/machinepublishers/jbrowserdriver/JBrowserDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package com.machinepublishers.jbrowserdriver;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -105,6 +106,13 @@ public void init() {
context.init(this);
}

/**
* @return Temporary directory where generated runtime files are saved.
*/
public File temporaryDir() {
return JavaFx.tmpDir(context.settingsId.get());
}

/**
* Reset the state of the browser. More efficient than quitting the
* browser and creating a new instance.
Expand Down
9 changes: 9 additions & 0 deletions src/com/machinepublishers/jbrowserdriver/JavaFx.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/
package com.machinepublishers.jbrowserdriver;

import java.io.File;
import java.rmi.RemoteException;

import com.machinepublishers.browser.Browser.Fatal;
Expand Down Expand Up @@ -61,4 +62,12 @@ static void close(long settingsId) {
throw new Fatal(e);
}
}

static File tmpDir(long settingsId) {
try {
return instance.tmpDir(settingsId);
} catch (RemoteException e) {
throw new Fatal(e);
}
}
}
3 changes: 3 additions & 0 deletions src/com/machinepublishers/jbrowserdriver/JavaFxRemote.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.machinepublishers.jbrowserdriver;

import java.io.File;
import java.rmi.Remote;
import java.rmi.RemoteException;

Expand All @@ -10,4 +11,6 @@ public interface JavaFxRemote extends Remote {
JavaFxObjectRemote getStatic(String type, Long id) throws RemoteException;

void close(long settingsId) throws RemoteException;

File tmpDir(long settingsId) throws RemoteException;
}
10 changes: 10 additions & 0 deletions src/com/machinepublishers/jbrowserdriver/JavaFxServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ public void close(long settingsId) {
}
}

public File tmpDir(long settingsId) {
synchronized (lock) {
ClassLoader classLoader = classLoaders.get(settingsId);
if (classLoader != null && classLoader instanceof JavaFxClassLoader) {
return ((JavaFxClassLoader) classLoader).myTmpDir;
}
}
return null;
}

private static ClassLoader newClassLoader(long settingsId) {
try {
final ClassLoader classLoader;
Expand Down

0 comments on commit 46f1c48

Please sign in to comment.