Skip to content

Instantly share code, notes, and snippets.

@robin850
Created November 27, 2020 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robin850/c6fcbf0378ca04e599e933e562bb6fbf to your computer and use it in GitHub Desktop.
Save robin850/c6fcbf0378ca04e599e933e562bb6fbf to your computer and use it in GitHub Desktop.
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