-
Notifications
You must be signed in to change notification settings - Fork 88
Feature/look in path #175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Feature/look in path #175
Changes from 1 commit
195d9af
ab078a6
a12076d
35ab870
252a88e
0a61921
d39fb31
19791dd
a734f16
fa10060
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,8 +15,7 @@ | |
| */ | ||
| package com.palantir.docker.compose.execution; | ||
|
|
||
| import static java.util.Collections.singletonList; | ||
|
|
||
| import com.google.common.collect.ImmutableList; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
|
|
@@ -28,13 +27,20 @@ | |
| @Value.Immutable | ||
| public abstract class DockerCommandLocator { | ||
|
|
||
| private static final List<String> MAC_SEARCH_LOCATIONS = ImmutableList.of("/usr/local/bin", "/usr/bin"); | ||
|
|
||
| protected abstract String command(); | ||
|
|
||
| @Value.Default | ||
| protected boolean isWindows() { | ||
| return SystemUtils.IS_OS_WINDOWS; | ||
| } | ||
|
|
||
| @Value.Default | ||
| protected List<String> macSearchLocations() { | ||
| return MAC_SEARCH_LOCATIONS; | ||
| } | ||
|
|
||
| @Value.Derived | ||
| protected String executableName() { | ||
| if (isWindows()) { | ||
|
|
@@ -46,22 +52,17 @@ protected String executableName() { | |
| @Nullable | ||
| protected abstract String locationOverride(); | ||
|
|
||
| @Value.Derived | ||
| protected List<Path> searchLocations() { | ||
| if (locationOverride() == null) { | ||
| return DockerCommandLocations.pathLocations(); | ||
| } | ||
| return singletonList(Paths.get(locationOverride())); | ||
| } | ||
|
|
||
| public String getLocation() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously DOCKER_COMPOSE_LOCATION would be the path to the binary, e.g. You could remove the It might even be worth moving |
||
| return searchLocations() | ||
| if (locationOverride() != null) { | ||
| return locationOverride(); | ||
| } | ||
| return macSearchLocations() | ||
| .stream() | ||
| .map(p -> p.resolve(executableName())) | ||
| .map(p -> Paths.get(p, executableName())) | ||
| .filter(Files::exists) | ||
| .findFirst() | ||
| .map(Path::toString) | ||
| .orElseThrow(() -> new IllegalStateException("Could not find " + command() + " in " + searchLocations())); | ||
| .orElse(executableName()); | ||
| } | ||
|
|
||
| public static ImmutableDockerCommandLocator.Builder forCommand(String command) { | ||
|
|
||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
returning a constant to represent a default where the constant is framed as a question is somewhat misleading (I still don't know what the default is)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default is to allow it to be overriden in tests, otherwise it should behave as a constant.
Would "useWindowsExecutableNaming" have been easier to understand?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isWindowsis fine, but I'm starting to think that making it a default doesn't really make any sense. Whoever creates this builder will know at the time what environment they're in, and it feels odd to be like "I'm not going to specify if I'm running on windows because defaults"Unless of course this is for backcompat and it's used in client code then nevermind.