mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-23 16:19:54 +01:00
Removable drive monitor for OS X 10.4 (JNotify requires at least 10.5).
This commit is contained in:
@@ -18,9 +18,14 @@ public class RemovableDrivePluginFactory implements BatchPluginFactory {
|
|||||||
if(OsUtils.isLinux()) {
|
if(OsUtils.isLinux()) {
|
||||||
finder = new LinuxRemovableDriveFinder();
|
finder = new LinuxRemovableDriveFinder();
|
||||||
monitor = new LinuxRemovableDriveMonitor();
|
monitor = new LinuxRemovableDriveMonitor();
|
||||||
} else if(OsUtils.isMac()) {
|
} else if(OsUtils.isMacLeopardOrNewer()) {
|
||||||
finder = new MacRemovableDriveFinder();
|
finder = new MacRemovableDriveFinder();
|
||||||
monitor = new MacRemovableDriveMonitor();
|
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()) {
|
} else if(OsUtils.isWindows()) {
|
||||||
finder = new WindowsRemovableDriveFinder();
|
finder = new WindowsRemovableDriveFinder();
|
||||||
monitor = new PollingRemovableDriveMonitor(finder,
|
monitor = new PollingRemovableDriveMonitor(finder,
|
||||||
|
|||||||
@@ -41,9 +41,12 @@ public class PluginManagerImplTest extends TestCase {
|
|||||||
Poller poller = new PollerImpl();
|
Poller poller = new PollerImpl();
|
||||||
PluginManagerImpl p = new PluginManagerImpl(db, executor, poller,
|
PluginManagerImpl p = new PluginManagerImpl(db, executor, poller,
|
||||||
dispatcher, uiCallback);
|
dispatcher, uiCallback);
|
||||||
// The Bluetooth plugin will not start without a Bluetooth device, so
|
// We expect either 2 or 3 plugins to be started, depending on whether
|
||||||
// we expect two plugins to be started
|
// the test machine has a Bluetooth device
|
||||||
assertEquals(2, p.startPlugins());
|
int started = p.startPlugins();
|
||||||
assertEquals(2, p.stopPlugins());
|
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 junit.framework.TestCase;
|
||||||
import net.sf.briar.TestUtils;
|
import net.sf.briar.TestUtils;
|
||||||
import net.sf.briar.plugins.file.RemovableDriveMonitor.Callback;
|
import net.sf.briar.plugins.file.RemovableDriveMonitor.Callback;
|
||||||
|
import net.sf.briar.util.OsUtils;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -25,6 +26,10 @@ public class UnixRemovableDriveMonitorTest extends TestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNonexistentDir() throws Exception {
|
public void testNonexistentDir() throws Exception {
|
||||||
|
if(!OsUtils.isLinux() || OsUtils.isMacLeopardOrNewer()) {
|
||||||
|
System.err.println("Warning: Skipping test");
|
||||||
|
return;
|
||||||
|
}
|
||||||
File doesNotExist = new File(testDir, "doesNotExist");
|
File doesNotExist = new File(testDir, "doesNotExist");
|
||||||
RemovableDriveMonitor monitor = createMonitor(doesNotExist);
|
RemovableDriveMonitor monitor = createMonitor(doesNotExist);
|
||||||
monitor.start(null);
|
monitor.start(null);
|
||||||
@@ -33,6 +38,10 @@ public class UnixRemovableDriveMonitorTest extends TestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOneCallbackPerFile() throws Exception {
|
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
|
// Create a callback that will wait for two files before stopping
|
||||||
final List<File> detected = new ArrayList<File>();
|
final List<File> detected = new ArrayList<File>();
|
||||||
final CountDownLatch latch = new CountDownLatch(2);
|
final CountDownLatch latch = new CountDownLatch(2);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package net.sf.briar.util;
|
|||||||
public class OsUtils {
|
public class OsUtils {
|
||||||
|
|
||||||
private static final String os = System.getProperty("os.name");
|
private static final String os = System.getProperty("os.name");
|
||||||
|
private static final String version = System.getProperty("os.version");
|
||||||
|
|
||||||
public static boolean isWindows() {
|
public static boolean isWindows() {
|
||||||
return os.indexOf("Windows") != -1;
|
return os.indexOf("Windows") != -1;
|
||||||
@@ -12,6 +13,19 @@ public class OsUtils {
|
|||||||
return os.indexOf("Mac OS") != -1;
|
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() {
|
public static boolean isLinux() {
|
||||||
return os.indexOf("Linux") != -1;
|
return os.indexOf("Linux") != -1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user