Skip to content

Commit 0f56151

Browse files
committed
Revert command/executable name extraction from macOS fallback changes
- Remove the helper methods introduced for extracting command/executable names and keep this change focused on adding /opt/homebrew/bin as an additional macOS fallback path
1 parent a5f5d60 commit 0f56151

4 files changed

Lines changed: 16 additions & 32 deletions

File tree

buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/configuration/CredentialHelper.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,29 +96,25 @@ private Process start(ProcessBuilder processBuilder) throws IOException {
9696
if (!Platform.isMac()) {
9797
throw ex;
9898
}
99-
String executableName = getExecutableName(processBuilder.command().get(0));
99+
String executable = processBuilder.command().get(0);
100100
for (String binDirectory : MAC_OS_BIN_DIRECTORIES) {
101101
try {
102102
List<String> command = new ArrayList<>(processBuilder.command());
103-
if (command.get(0).startsWith(binDirectory)) {
103+
if (executable.startsWith(binDirectory)) {
104104
continue;
105105
}
106-
command.set(0, binDirectory + executableName);
106+
command.set(0, binDirectory + executable);
107107
return processBuilder.command(command).start();
108108
}
109109
catch (Exception suppressed) {
110+
// Suppresses the exception and rethrows the original exception
110111
ex.addSuppressed(suppressed);
111112
}
112113
}
113114
throw ex;
114115
}
115116
}
116117

117-
private String getExecutableName(String executable) {
118-
int lastSlash = executable.lastIndexOf('/');
119-
return (lastSlash != -1) ? executable.substring(lastSlash + 1) : executable;
120-
}
121-
122118
private static boolean isCredentialsNotFoundError(String message) {
123119
return CREDENTIAL_NOT_FOUND_MESSAGES.contains(message.trim());
124120
}

buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/configuration/CredentialHelperTests.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,16 @@ void getWhenUnknownErrorThrowsException() {
102102
void getWhenExecutableDoesNotExistErrorThrowsException() {
103103
String executable = "docker-credential-%s".formatted(UUID.randomUUID().toString());
104104
assertThatIOException().isThrownBy(() -> new CredentialHelper(executable).get("invalid.example.com"))
105-
.withMessageContaining(executable)
106-
.satisfies((ex) -> {
107-
if (Platform.isMac()) {
108-
assertThat(ex.getMessage()).doesNotContain("/usr/local/bin/");
109-
assertThat(ex.getSuppressed()).anySatisfy(
110-
(suppressed) -> assertThat(suppressed).hasMessageContaining("/opt/homebrew/bin/" + executable));
111-
assertThat(ex.getSuppressed()).anySatisfy(
112-
(suppressed) -> assertThat(suppressed).hasMessageContaining("/usr/local/bin/" + executable));
113-
}
114-
});
105+
.withMessageContaining(executable)
106+
.satisfies((ex) -> {
107+
if (Platform.isMac()) {
108+
assertThat(ex.getMessage()).doesNotContain("/usr/local/bin/");
109+
assertThat(ex.getSuppressed()).anySatisfy((suppressed) -> assertThat(suppressed)
110+
.hasMessageContaining("/opt/homebrew/bin/" + executable));
111+
assertThat(ex.getSuppressed()).anySatisfy((suppressed) -> assertThat(suppressed)
112+
.hasMessageContaining("/usr/local/bin/" + executable));
113+
}
114+
});
115115
}
116116

117117
}

core/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/ProcessRunner.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,12 @@ private Process startProcess(String[] command) {
113113
catch (IOException ex) {
114114
String path = processBuilder.environment().get("PATH");
115115
if (MAC_OS && path != null) {
116-
String commandName = getCommandName(command[0]);
117116
for (String binDirectory : MAC_OS_BIN_DIRECTORIES) {
118117
if (path.contains(binDirectory) || command[0].startsWith(binDirectory + "/")) {
119118
continue;
120119
}
121120
String[] localCommand = command.clone();
122-
localCommand[0] = binDirectory + "/" + commandName;
121+
localCommand[0] = binDirectory + "/" + command[0];
123122
ProcessBuilder localProcessBuilder = new ProcessBuilder(localCommand);
124123
localProcessBuilder.directory(this.workingDirectory);
125124
try {
@@ -134,11 +133,6 @@ private Process startProcess(String[] command) {
134133
}
135134
}
136135

137-
private String getCommandName(String command) {
138-
int lastSlash = command.lastIndexOf('/');
139-
return (lastSlash != -1) ? command.substring(lastSlash + 1) : command;
140-
}
141-
142136
private int waitForProcess(Process process) {
143137
try {
144138
return process.waitFor();

test-support/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/process/DisabledIfProcessUnavailableCondition.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,12 @@ private void check(String[] command) {
7777
catch (Exception ex) {
7878
String path = processBuilder.environment().get("PATH");
7979
if (MAC_OS && path != null) {
80-
String commandName = getCommandName(command[0]);
8180
for (String binDirectory : MAC_OS_BIN_DIRECTORIES) {
8281
if (path.contains(binDirectory) || command[0].startsWith(binDirectory + "/")) {
8382
continue;
8483
}
8584
String[] localCommand = command.clone();
86-
localCommand[0] = binDirectory + "/" + commandName;
85+
localCommand[0] = binDirectory + "/" + command[0];
8786
try {
8887
check(new ProcessBuilder(localCommand));
8988
return;
@@ -104,9 +103,4 @@ private void check(ProcessBuilder processBuilder) throws Exception {
104103
process.destroy();
105104
}
106105

107-
private String getCommandName(String command) {
108-
int lastSlash = command.lastIndexOf('/');
109-
return (lastSlash != -1) ? command.substring(lastSlash + 1) : command;
110-
}
111-
112106
}

0 commit comments

Comments
 (0)