-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
small api changes regarding servlet creation, added mounting capabili…
…ties
- Loading branch information
1 parent
27ae93b
commit a1c8105
Showing
16 changed files
with
470 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/org/cryptomator/frontend/webdav/mount/FallbackMounter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.cryptomator.frontend.webdav.mount; | ||
|
||
import java.net.URI; | ||
import java.util.Map; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
@Singleton | ||
class FallbackMounter implements MounterStrategy { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(FallbackMounter.class); | ||
|
||
@Inject | ||
FallbackMounter() { | ||
} | ||
|
||
@Override | ||
public Mount mount(URI uri, Map<MountParam, String> mountParams) throws CommandFailedException { | ||
LOG.warn("Attempted to mount {}, but no applicable strategy has been found for your system. Try using the URI with a WebDAV client of your choice.", uri); | ||
throw new CommandFailedException("No mounting strategy found."); | ||
} | ||
|
||
@Override | ||
public boolean isApplicable() { | ||
return false; | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/org/cryptomator/frontend/webdav/mount/LinuxGvfsMounter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.cryptomator.frontend.webdav.mount; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.util.Map; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
|
||
import org.apache.commons.lang3.SystemUtils; | ||
|
||
@Singleton | ||
class LinuxGvfsMounter implements MounterStrategy { | ||
|
||
@Inject | ||
LinuxGvfsMounter() { | ||
} | ||
|
||
@Override | ||
public boolean isApplicable() { | ||
if (!SystemUtils.IS_OS_LINUX) { | ||
return false; | ||
} | ||
|
||
// check if gvfs is installed: | ||
assert SystemUtils.IS_OS_LINUX; | ||
try { | ||
ProcessBuilder checkDependencies = new ProcessBuilder("which", "gvfs-mount", "xdg-open"); | ||
Process checkDependenciesProcess = checkDependencies.start(); | ||
ProcessUtil.assertExitValue(checkDependenciesProcess, 0); | ||
return true; | ||
} catch (CommandFailedException | IOException e) { | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public Mount mount(URI uri, Map<MountParam, String> mountParams) throws CommandFailedException { | ||
// TODO Auto-generated method stub | ||
throw new CommandFailedException("not yet implemented."); | ||
} | ||
|
||
} |
90 changes: 90 additions & 0 deletions
90
src/main/java/org/cryptomator/frontend/webdav/mount/MacAppleScriptMounter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package org.cryptomator.frontend.webdav.mount; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Map; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.commons.lang3.SystemUtils; | ||
|
||
@Singleton | ||
class MacAppleScriptMounter implements MounterStrategy { | ||
|
||
@Inject | ||
MacAppleScriptMounter() { | ||
} | ||
|
||
@Override | ||
public boolean isApplicable() { | ||
return SystemUtils.IS_OS_MAC_OSX && // since macOS 10.10+ | ||
!SystemUtils.IS_OS_MAC_OSX_MAVERICKS && // 10.9 | ||
!SystemUtils.IS_OS_MAC_OSX_MOUNTAIN_LION; // 10.8; older version not supported by Java 8 | ||
} | ||
|
||
@Override | ||
public Mount mount(URI uri, Map<MountParam, String> mountParams) throws CommandFailedException { | ||
try { | ||
String mountAppleScript = String.format("mount volume \"%s\"", uri.toString()); | ||
ProcessBuilder mount = new ProcessBuilder("/usr/bin/osascript", "-e", mountAppleScript); | ||
Process mountProcess = mount.start(); | ||
String stdout = ProcessUtil.toString(mountProcess.getInputStream(), StandardCharsets.UTF_8); | ||
ProcessUtil.waitFor(mountProcess, 1, TimeUnit.SECONDS); | ||
ProcessUtil.assertExitValue(mountProcess, 0); | ||
String volumeIdentifier = StringUtils.trim(StringUtils.removeStart(stdout, "file ")); | ||
String waitAppleScript1 = String.format("tell application \"Finder\" to repeat while not (\"%s\" exists)", volumeIdentifier); | ||
String waitAppleScript2 = "delay 0.1"; | ||
String waitAppleScript3 = "end repeat"; | ||
ProcessBuilder wait = new ProcessBuilder("/usr/bin/osascript", "-e", waitAppleScript1, "-e", waitAppleScript2, "-e", waitAppleScript3); | ||
Process waitProcess = wait.start(); | ||
ProcessUtil.waitFor(waitProcess, 5, TimeUnit.SECONDS); | ||
ProcessUtil.assertExitValue(waitProcess, 0); | ||
return new MountImpl(volumeIdentifier); | ||
} catch (IOException e) { | ||
throw new CommandFailedException(e); | ||
} | ||
} | ||
|
||
private static class MountImpl implements Mount { | ||
|
||
private final ProcessBuilder revealCommand; | ||
private final ProcessBuilder unmountCommand; | ||
|
||
private MountImpl(String volumeIdentifier) { | ||
String openAppleScript = String.format("tell application \"Finder\" to open \"%s\"", volumeIdentifier); | ||
String activateAppleScript = String.format("tell application \"Finder\" to activate \"%s\"", volumeIdentifier); | ||
String ejectAppleScript = String.format("tell application \"Finder\" to if \"%s\" exists then eject \"%s\"", volumeIdentifier, volumeIdentifier); | ||
|
||
this.revealCommand = new ProcessBuilder("/usr/bin/osascript", "-e", openAppleScript, "-e", activateAppleScript); | ||
this.unmountCommand = new ProcessBuilder("/usr/bin/osascript", "-e", ejectAppleScript); | ||
} | ||
|
||
@Override | ||
public void unmount() throws CommandFailedException { | ||
try { | ||
Process proc = unmountCommand.start(); | ||
ProcessUtil.waitFor(proc, 1, TimeUnit.SECONDS); | ||
ProcessUtil.assertExitValue(proc, 0); | ||
} catch (IOException e) { | ||
throw new CommandFailedException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void reveal() throws CommandFailedException { | ||
try { | ||
Process proc = revealCommand.start(); | ||
ProcessUtil.waitFor(proc, 2, TimeUnit.SECONDS); | ||
ProcessUtil.assertExitValue(proc, 0); | ||
} catch (IOException e) { | ||
throw new CommandFailedException(e); | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/org/cryptomator/frontend/webdav/mount/MacShellScriptMounter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.cryptomator.frontend.webdav.mount; | ||
|
||
import java.net.URI; | ||
import java.util.Map; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
|
||
import org.apache.commons.lang3.SystemUtils; | ||
|
||
@Singleton | ||
class MacShellScriptMounter implements MounterStrategy { | ||
|
||
@Inject | ||
MacShellScriptMounter() { | ||
} | ||
|
||
@Override | ||
public boolean isApplicable() { | ||
return SystemUtils.IS_OS_MAC_OSX_MAVERICKS || SystemUtils.IS_OS_MAC_OSX_MOUNTAIN_LION; | ||
} | ||
|
||
@Override | ||
public Mount mount(URI uri, Map<MountParam, String> mountParams) throws CommandFailedException { | ||
// TODO Auto-generated method stub | ||
throw new CommandFailedException("not yet implemented."); | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/org/cryptomator/frontend/webdav/mount/Mounter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.cryptomator.frontend.webdav.mount; | ||
|
||
import java.net.URI; | ||
import java.util.Map; | ||
|
||
public interface Mounter { | ||
|
||
/** | ||
* Tries to mount a given webdav share. | ||
* | ||
* @param uri URI of the webdav share | ||
* @param mountParams additional mount parameters, that might be needed by certain OS-specific mount commands. | ||
* @return a {@link Mount} representing the mounted share | ||
* @throws CommandFailedException if the mount operation fails | ||
* @throws IllegalArgumentException if mountParams is missing expected options | ||
*/ | ||
Mount mount(URI uri, Map<MountParam, String> mountParams) throws CommandFailedException; | ||
|
||
public enum MountParam { | ||
MOUNT_NAME, WIN_DRIVE_LETTER, PREFERRED_GVFS_SCHEME; | ||
} | ||
|
||
/** | ||
* Represents a single mounted volume and allows certain interactions with it. | ||
*/ | ||
public interface Mount { | ||
void unmount() throws CommandFailedException; | ||
|
||
void reveal() throws CommandFailedException; | ||
} | ||
|
||
public class CommandFailedException extends Exception { | ||
|
||
public CommandFailedException(String message) { | ||
super(message); | ||
} | ||
|
||
public CommandFailedException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.