Skip to content

Commit 1519bcf

Browse files
committed
Polish "Add support for additional Homebrew home on macOS"
See gh-49721
1 parent 2d4c235 commit 1519bcf

4 files changed

Lines changed: 13 additions & 14 deletions

File tree

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,15 @@ private Process start(ProcessBuilder processBuilder) throws IOException {
9696
if (!Platform.isMac()) {
9797
throw ex;
9898
}
99-
String executable = processBuilder.command().get(0);
99+
List<String> originalCommand = List.copyOf(processBuilder.command());
100+
String executable = originalCommand.get(0);
100101
for (String binDirectory : MAC_OS_BIN_DIRECTORIES) {
102+
List<String> command = new ArrayList<>(originalCommand);
103+
command.set(0, binDirectory + executable);
101104
try {
102-
List<String> command = new ArrayList<>(processBuilder.command());
103-
if (executable.startsWith(binDirectory)) {
104-
continue;
105-
}
106-
command.set(0, binDirectory + executable);
107105
return processBuilder.command(command).start();
108106
}
109107
catch (Exception suppressed) {
110-
// Suppresses the exception and rethrows the original exception
111108
ex.addSuppressed(suppressed);
112109
}
113110
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,11 @@ void getWhenExecutableDoesNotExistErrorThrowsException() {
106106
.satisfies((ex) -> {
107107
if (Platform.isMac()) {
108108
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));
109+
assertThat(ex.getSuppressed()).satisfiesExactlyInAnyOrder(
110+
(suppressed) -> assertThat(suppressed)
111+
.hasMessageContaining("/opt/homebrew/bin/" + executable),
112+
(suppressed) -> assertThat(suppressed)
113+
.hasMessageContaining("/usr/local/bin/" + executable));
113114
}
114115
});
115116
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private Process startProcess(String[] command) {
114114
String path = processBuilder.environment().get("PATH");
115115
if (MAC_OS && path != null) {
116116
for (String binDirectory : MAC_OS_BIN_DIRECTORIES) {
117-
if (path.contains(binDirectory) || command[0].startsWith(binDirectory + "/")) {
117+
if (path.contains(binDirectory) || command[0].startsWith("/")) {
118118
continue;
119119
}
120120
String[] localCommand = command.clone();

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private void check(String[] command) {
7878
String path = processBuilder.environment().get("PATH");
7979
if (MAC_OS && path != null) {
8080
for (String binDirectory : MAC_OS_BIN_DIRECTORIES) {
81-
if (path.contains(binDirectory) || command[0].startsWith(binDirectory + "/")) {
81+
if (path.contains(binDirectory) || command[0].startsWith("/")) {
8282
continue;
8383
}
8484
String[] localCommand = command.clone();
@@ -87,7 +87,8 @@ private void check(String[] command) {
8787
check(new ProcessBuilder(localCommand));
8888
return;
8989
}
90-
catch (Exception ignored) {
90+
catch (Exception suppressed) {
91+
ex.addSuppressed(suppressed);
9192
}
9293
}
9394
}

0 commit comments

Comments
 (0)