diff --git a/components/net/sf/briar/plugins/file/RemovableDrivePluginFactory.java b/components/net/sf/briar/plugins/file/RemovableDrivePluginFactory.java index f42d322c7753e51a1f40e69ba57584e6c03b2d00..92850a4e03a89e22ad96fb1b6fb99e5b341d6e25 100644 --- a/components/net/sf/briar/plugins/file/RemovableDrivePluginFactory.java +++ b/components/net/sf/briar/plugins/file/RemovableDrivePluginFactory.java @@ -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, diff --git a/test/net/sf/briar/plugins/PluginManagerImplTest.java b/test/net/sf/briar/plugins/PluginManagerImplTest.java index 0a1b4693ff88dd152693fcdc11a458c67541c17d..276f16236a9019253c39538350a8d0dcf64c3822 100644 --- a/test/net/sf/briar/plugins/PluginManagerImplTest.java +++ b/test/net/sf/briar/plugins/PluginManagerImplTest.java @@ -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); } } diff --git a/test/net/sf/briar/plugins/file/UnixRemovableDriveMonitorTest.java b/test/net/sf/briar/plugins/file/UnixRemovableDriveMonitorTest.java index 1ed814d038dfb03eccebcb07ddac128616d96b44..c320968d0ed687067f30bd52f26d2afebe478192 100644 --- a/test/net/sf/briar/plugins/file/UnixRemovableDriveMonitorTest.java +++ b/test/net/sf/briar/plugins/file/UnixRemovableDriveMonitorTest.java @@ -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); diff --git a/util/net/sf/briar/util/OsUtils.java b/util/net/sf/briar/util/OsUtils.java index f8e8553da5ca15ee90872b8eb8a12a191b8b680d..dd32ad897fbf4314b446fe49c16ae8c63aa8dece 100644 --- a/util/net/sf/briar/util/OsUtils.java +++ b/util/net/sf/briar/util/OsUtils.java @@ -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; }