Skip to content
Snippets Groups Projects
Commit 214b274e authored by akwizgran's avatar akwizgran
Browse files

Removable drive monitor for OS X 10.4 (JNotify requires at least 10.5).

parent b2226067
No related branches found
No related tags found
No related merge requests found
......@@ -18,9 +18,14 @@ public class RemovableDrivePluginFactory implements BatchPluginFactory {
if(OsUtils.isLinux()) {
finder = new LinuxRemovableDriveFinder();
monitor = new LinuxRemovableDriveMonitor();
} else if(OsUtils.isMac()) {
} else if(OsUtils.isMacLeopardOrNewer()) {
finder = new MacRemovableDriveFinder();
monitor = new MacRemovableDriveMonitor();
} else if(OsUtils.isMac()) {
// JNotify requires OS X 10.5 or newer, so we have to poll
finder = new MacRemovableDriveFinder();
monitor = new PollingRemovableDriveMonitor(finder,
POLLING_INTERVAL);
} else if(OsUtils.isWindows()) {
finder = new WindowsRemovableDriveFinder();
monitor = new PollingRemovableDriveMonitor(finder,
......
......@@ -41,9 +41,12 @@ public class PluginManagerImplTest extends TestCase {
Poller poller = new PollerImpl();
PluginManagerImpl p = new PluginManagerImpl(db, executor, poller,
dispatcher, uiCallback);
// The Bluetooth plugin will not start without a Bluetooth device, so
// we expect two plugins to be started
assertEquals(2, p.startPlugins());
assertEquals(2, p.stopPlugins());
// We expect either 2 or 3 plugins to be started, depending on whether
// the test machine has a Bluetooth device
int started = p.startPlugins();
int stopped = p.stopPlugins();
assertEquals(started, stopped);
assertTrue(started >= 2);
assertTrue(started <= 3);
}
}
......@@ -9,6 +9,7 @@ import java.util.concurrent.TimeUnit;
import junit.framework.TestCase;
import net.sf.briar.TestUtils;
import net.sf.briar.plugins.file.RemovableDriveMonitor.Callback;
import net.sf.briar.util.OsUtils;
import org.junit.After;
import org.junit.Before;
......@@ -25,6 +26,10 @@ public class UnixRemovableDriveMonitorTest extends TestCase {
@Test
public void testNonexistentDir() throws Exception {
if(!OsUtils.isLinux() || OsUtils.isMacLeopardOrNewer()) {
System.err.println("Warning: Skipping test");
return;
}
File doesNotExist = new File(testDir, "doesNotExist");
RemovableDriveMonitor monitor = createMonitor(doesNotExist);
monitor.start(null);
......@@ -33,6 +38,10 @@ public class UnixRemovableDriveMonitorTest extends TestCase {
@Test
public void testOneCallbackPerFile() throws Exception {
if(!OsUtils.isLinux() || OsUtils.isMacLeopardOrNewer()) {
System.err.println("Warning: Skipping test");
return;
}
// Create a callback that will wait for two files before stopping
final List<File> detected = new ArrayList<File>();
final CountDownLatch latch = new CountDownLatch(2);
......
......@@ -3,6 +3,7 @@ package net.sf.briar.util;
public class OsUtils {
private static final String os = System.getProperty("os.name");
private static final String version = System.getProperty("os.version");
public static boolean isWindows() {
return os.indexOf("Windows") != -1;
......@@ -12,6 +13,19 @@ public class OsUtils {
return os.indexOf("Mac OS") != -1;
}
public static boolean isMacLeopardOrNewer() {
if(!isMac() || version == null) return false;
try {
String[] v = version.split("\\.");
if(v.length != 3) return false;
int major = Integer.parseInt(v[0]);
int minor = Integer.parseInt(v[1]);
return major >= 10 && minor >= 5;
} catch(NumberFormatException e) {
return false;
}
}
public static boolean isLinux() {
return os.indexOf("Linux") != -1;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment