Created
November 27, 2020 12:30
-
-
Save robin850/c6fcbf0378ca04e599e933e562bb6fbf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import de.flapdoodle.embed.mongo.Paths; | |
class CustomPackageResolver extends Paths { | |
public CustomPackageResolver(Command command) { | |
super(command); | |
} | |
@Override | |
public String getPath(Distribution distribution) { | |
String versionStr = getVersionPart(distribution.version()); | |
ArchiveType archiveType = getArchiveType(distribution); | |
String archiveTypeStr = getArchiveString(archiveType); | |
String platformStr = getPlatformString(distribution); | |
String osStr = getOsString(distribution); | |
if (distribution.platform() == Platform.Windows) { | |
versionStr = "2012plus-" + versionStr; | |
} else if (distribution.platform() == Platform.Linux) { | |
// Platform isn't distro-aware so imply Ubuntu by default on Linux. | |
versionStr = "ubuntu1804-" + versionStr; | |
} | |
return platformStr + "/mongodb-" + osStr + "-x86_64-" + versionStr + "." + archiveTypeStr; | |
} | |
private String getArchiveString(ArchiveType archiveType) { | |
switch (archiveType) { | |
case TGZ: | |
return "tgz"; | |
case ZIP: | |
return "zip"; | |
default: | |
throw new IllegalArgumentException("Unknown ArchiveType " + archiveType); | |
} | |
} | |
private String getOsString(Distribution distribution) { | |
switch (distribution.platform()) { | |
case Linux: | |
return "linux"; | |
case Windows: | |
return "win32"; | |
case OS_X: | |
return "macos"; | |
default: | |
throw new IllegalArgumentException("Unknown Platform " + distribution.platform()); | |
} | |
} | |
private String getPlatformString(Distribution distribution) { | |
switch (distribution.platform()) { | |
case Linux: | |
return "linux"; | |
case Windows: | |
return "win32"; | |
case OS_X: | |
return "osx"; | |
default: | |
throw new IllegalArgumentException("Unknown Platform " + distribution.platform()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment