Skip to content

Commit 60b4e0d

Browse files
committed
Minor polishing
1 parent 78e5fab commit 60b4e0d

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

buildSrc/src/main/java/org/elasticsearch/gradle/ElasticsearchDistribution.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.Collections;
3232
import java.util.Iterator;
3333
import java.util.Locale;
34+
import java.util.Optional;
3435
import java.util.function.Function;
3536

3637
public class ElasticsearchDistribution implements Buildable, Iterable<File> {
@@ -205,7 +206,7 @@ public String toString() {
205206
* if not executed before, this
206207
* freezes the distribution configuration and
207208
* runs distribution finalizer logic.
208-
* */
209+
*/
209210
public ElasticsearchDistribution maybeFreeze() {
210211
if (!froozen) {
211212
finalizeValues();
@@ -237,25 +238,31 @@ public Configuration getExtracted() {
237238

238239
@Override
239240
public TaskDependency getBuildDependencies() {
240-
// For non-required Docker distributions, skip building the distribution is Docker is unavailable
241-
if (isDocker() && getFailIfUnavailable() == false && dockerSupport.get().getDockerAvailability().isAvailable == false) {
242-
return task -> Collections.emptySet();
243-
}
244-
maybeFreeze();
245-
return getType().shouldExtract() ? extracted.getBuildDependencies() : configuration.getBuildDependencies();
241+
Optional<TaskDependency> dockerBuildDependencies = dockerBuildDependencies();
242+
return dockerBuildDependencies.orElseGet(() -> {
243+
maybeFreeze();
244+
return getType().shouldExtract() ? extracted.getBuildDependencies() : configuration.getBuildDependencies();
245+
});
246246
}
247247

248248
public TaskDependency getArchiveBuildDependencies() {
249+
Optional<TaskDependency> dockerBuildDependencies = dockerBuildDependencies();
250+
return dockerBuildDependencies.orElseGet(() -> {
251+
maybeFreeze();
252+
return configuration.getBuildDependencies();
253+
});
254+
}
255+
256+
private Optional<TaskDependency> dockerBuildDependencies() {
249257
// For non-required Docker distributions, skip building the distribution is Docker is unavailable
250-
if (isDocker() && getFailIfUnavailable() == false && dockerSupport.get().getDockerAvailability().isAvailable == false) {
251-
return task -> Collections.emptySet();
252-
}
253-
maybeFreeze();
254-
return configuration.getBuildDependencies();
258+
return (isDocker() && getFailIfUnavailable() == false && dockerSupport.get().getDockerAvailability().isAvailable == false)
259+
? Optional.of(task -> Collections.emptySet())
260+
: Optional.empty();
255261
}
256262

257263
@Override
258264
public Iterator<File> iterator() {
265+
maybeFreeze();
259266
return getType().shouldExtract() ? extracted.iterator() : configuration.iterator();
260267
}
261268

0 commit comments

Comments
 (0)