forked from ozimov/embedded-redis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kstyrc#29 from kstyrc/os_detection_fix
Os detection fix + ability to override redis exec per os/arch
- Loading branch information
Showing
12 changed files
with
319 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package redis.embedded; | ||
|
||
import com.google.common.base.Preconditions; | ||
import com.google.common.collect.Maps; | ||
import redis.embedded.util.Architecture; | ||
import redis.embedded.util.JarUtil; | ||
import redis.embedded.util.OS; | ||
import redis.embedded.util.OsArchitecture; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
public class RedisExecProvider { | ||
|
||
private final Map<OsArchitecture, String> executables = Maps.newHashMap(); | ||
|
||
public static RedisExecProvider defaultProvider() { | ||
return new RedisExecProvider(); | ||
} | ||
|
||
private RedisExecProvider() { | ||
initExecutables(); | ||
} | ||
|
||
private void initExecutables() { | ||
executables.put(OsArchitecture.WINDOWS_x86, "redis-server.exe"); | ||
executables.put(OsArchitecture.WINDOWS_x86_64, "redis-server-64.exe"); | ||
|
||
executables.put(OsArchitecture.UNIX_x86, "redis-server"); | ||
executables.put(OsArchitecture.UNIX_x86_64, "redis-server"); | ||
|
||
executables.put(OsArchitecture.MAC_OS_X_x86, "redis-server.app"); | ||
executables.put(OsArchitecture.MAC_OS_X_x86_64, "redis-server.app"); | ||
} | ||
|
||
public RedisExecProvider override(OS os, String executable) { | ||
Preconditions.checkNotNull(executable); | ||
for (Architecture arch : Architecture.values()) { | ||
override(os, arch, executable); | ||
} | ||
return this; | ||
} | ||
|
||
public RedisExecProvider override(OS os, Architecture arch, String executable) { | ||
Preconditions.checkNotNull(executable); | ||
executables.put(new OsArchitecture(os, arch), executable); | ||
return this; | ||
} | ||
|
||
public File get() throws IOException { | ||
OsArchitecture osArch = OsArchitecture.detect(); | ||
String executablePath = executables.get(osArch); | ||
return fileExists(executablePath) ? | ||
new File(executablePath) : | ||
JarUtil.extractExecutableFromJar(executablePath); | ||
|
||
} | ||
|
||
private boolean fileExists(String executablePath) { | ||
return new File(executablePath).exists(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
11 changes: 11 additions & 0 deletions
11
src/main/java/redis/embedded/exceptions/OsDetectionException.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,11 @@ | ||
package redis.embedded.exceptions; | ||
|
||
public class OsDetectionException extends RuntimeException { | ||
public OsDetectionException(String message) { | ||
super(message); | ||
} | ||
|
||
public OsDetectionException(Throwable cause) { | ||
super(cause); | ||
} | ||
} |
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,6 @@ | ||
package redis.embedded.util; | ||
|
||
public enum Architecture { | ||
x86, | ||
x86_64 | ||
} |
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,7 @@ | ||
package redis.embedded.util; | ||
|
||
public enum OS { | ||
WINDOWS, | ||
UNIX, | ||
MAC_OS_X | ||
} |
Oops, something went wrong.