Skip to content

Commit d6c72eb

Browse files
committed
Capture Docker Compose version information in a custom value
Closes gh-80
1 parent 54acfdb commit d6c72eb

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

src/main/java/io/spring/ge/conventions/gradle/BuildScanConventions.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public void execute(BuildScanConfiguration buildScan) {
6565
tagBuildScan(buildScan, ci);
6666
buildScan.background(this::addGitMetadata);
6767
buildScan.background(this::addDockerMetadata);
68+
buildScan.background(this::addDockerComposeMetadata);
6869
addCiMetadata(buildScan, ci);
6970
buildScan.getUploadInBackground().set(ci == null);
7071
buildScan.capture((settings) -> settings.getFileFingerprints().set(true));
@@ -127,6 +128,11 @@ private void addDockerMetadata(BuildScanConfiguration buildScan) {
127128
run("docker", "--version").standardOut((dockerVersion) -> buildScan.value("Docker", dockerVersion));
128129
}
129130

131+
private void addDockerComposeMetadata(BuildScanConfiguration buildScan) {
132+
run("docker", "compose", "version")
133+
.standardOut((dockerComposeVersion) -> buildScan.value("Docker Compose", dockerComposeVersion));
134+
}
135+
130136
private void addCiMetadata(BuildScanConfiguration buildScan, ContinuousIntegration ci) {
131137
if (ci == null) {
132138
return;

src/main/java/io/spring/ge/conventions/gradle/ProcessOperationsProcessRunner.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2021 the original author or authors.
2+
* Copyright 2020-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
2020
import java.util.function.Consumer;
2121

2222
import org.gradle.api.internal.ProcessOperations;
23+
import org.gradle.process.ExecResult;
2324
import org.gradle.process.ExecSpec;
2425

2526
/**
@@ -38,7 +39,7 @@ class ProcessOperationsProcessRunner implements ProcessRunner {
3839
@Override
3940
public void run(Consumer<ProcessSpec> configurer) {
4041
try {
41-
this.processOperations.exec((spec) -> configurer.accept(new ExecSpecProcessSpec(spec)));
42+
ExecResult exec = this.processOperations.exec((spec) -> configurer.accept(new ExecSpecProcessSpec(spec)));
4243
}
4344
catch (Exception ex) {
4445
throw new RunFailedException(ex);

src/main/java/io/spring/ge/conventions/gradle/ProcessRunner.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2021 the original author or authors.
2+
* Copyright 2020-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -55,6 +55,10 @@ interface ProcessSpec {
5555

5656
class RunFailedException extends RuntimeException {
5757

58+
RunFailedException() {
59+
60+
}
61+
5862
RunFailedException(Exception cause) {
5963
super(cause);
6064
}

src/test/java/io/spring/ge/conventions/gradle/BuildScanConventionsTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,24 @@ void whenDockerIsNotAvailableThenConventionsCanBeAppliedWithoutFailure() {
290290
assertThat(this.buildScan.values).doesNotContainKey("Docker");
291291
}
292292

293+
@Test
294+
void buildScanHasDockerComposeCustomValue() {
295+
this.processRunner.commandLineOutput.put(Arrays.asList("docker", "compose", "version"),
296+
"Docker Compose version v2.17.2");
297+
new BuildScanConventions(this.develocity, this.processRunner).execute(this.buildScan);
298+
assertThat(this.buildScan.values).containsEntry("Docker Compose", "Docker Compose version v2.17.2");
299+
}
300+
301+
@Test
302+
void whenDockerComposeIsNotAvailableThenConventionsCanBeAppliedWithoutFailure() {
303+
this.processRunner.failures.put(Arrays.asList("docker", "compose", "version"),
304+
new RuntimeException("docker compose is not available"));
305+
new BuildScanConventions(this.develocity, this.processRunner).execute(this.buildScan);
306+
assertThatNoException()
307+
.isThrownBy(() -> new BuildScanConventions(this.develocity, this.processRunner).execute(this.buildScan));
308+
assertThat(this.buildScan.values).doesNotContainKey("Docker Compose");
309+
}
310+
293311
@Test
294312
void whenBuildingLocallyThenBackgroundUploadIsEnabled() {
295313
new BuildScanConventions(this.develocity, this.processRunner, Collections.emptyMap()).execute(this.buildScan);

0 commit comments

Comments
 (0)