20
20
package org .elasticsearch .gradle ;
21
21
22
22
import org .elasticsearch .gradle .docker .DockerSupportService ;
23
+ import org .gradle .api .Action ;
23
24
import org .gradle .api .Buildable ;
24
25
import org .gradle .api .artifacts .Configuration ;
25
26
import org .gradle .api .model .ObjectFactory ;
31
32
import java .util .Collections ;
32
33
import java .util .Iterator ;
33
34
import java .util .Locale ;
34
- import java .util .Optional ;
35
- import java .util .function .Function ;
36
35
37
36
public class ElasticsearchDistribution implements Buildable , Iterable <File > {
38
37
@@ -105,7 +104,7 @@ public String toString() {
105
104
private final Property <Boolean > bundledJdk ;
106
105
private final Property <Boolean > failIfUnavailable ;
107
106
private final Configuration extracted ;
108
- private Function < ElasticsearchDistribution , ElasticsearchDistribution > distributionFinalizer ;
107
+ private Action < ElasticsearchDistribution > distributionFinalizer ;
109
108
private boolean froozen = false ;
110
109
111
110
ElasticsearchDistribution (
@@ -114,7 +113,7 @@ public String toString() {
114
113
Provider <DockerSupportService > dockerSupport ,
115
114
Configuration fileConfiguration ,
116
115
Configuration extractedConfiguration ,
117
- Function < ElasticsearchDistribution , ElasticsearchDistribution > distributionFinalizer
116
+ Action < ElasticsearchDistribution > distributionFinalizer
118
117
) {
119
118
this .name = name ;
120
119
this .dockerSupport = dockerSupport ;
@@ -210,7 +209,7 @@ public String toString() {
210
209
public ElasticsearchDistribution maybeFreeze () {
211
210
if (!froozen ) {
212
211
finalizeValues ();
213
- distributionFinalizer .apply (this );
212
+ distributionFinalizer .execute (this );
214
213
froozen = true ;
215
214
}
216
215
return this ;
@@ -238,26 +237,16 @@ public Configuration getExtracted() {
238
237
239
238
@ Override
240
239
public TaskDependency getBuildDependencies () {
241
- Optional <TaskDependency > dockerBuildDependencies = dockerBuildDependencies ();
242
- return dockerBuildDependencies .orElseGet (() -> {
240
+ if (skippingDockerDistributionBuild ()) {
241
+ return task -> Collections .emptySet ();
242
+ } else {
243
243
maybeFreeze ();
244
244
return getType ().shouldExtract () ? extracted .getBuildDependencies () : configuration .getBuildDependencies ();
245
- });
246
- }
247
-
248
- public TaskDependency getArchiveBuildDependencies () {
249
- Optional <TaskDependency > dockerBuildDependencies = dockerBuildDependencies ();
250
- return dockerBuildDependencies .orElseGet (() -> {
251
- maybeFreeze ();
252
- return configuration .getBuildDependencies ();
253
- });
245
+ }
254
246
}
255
247
256
- private Optional <TaskDependency > dockerBuildDependencies () {
257
- // For non-required Docker distributions, skip building the distribution is Docker is unavailable
258
- return (isDocker () && getFailIfUnavailable () == false && dockerSupport .get ().getDockerAvailability ().isAvailable == false )
259
- ? Optional .of (task -> Collections .emptySet ())
260
- : Optional .empty ();
248
+ private boolean skippingDockerDistributionBuild () {
249
+ return isDocker () && getFailIfUnavailable () == false && dockerSupport .get ().getDockerAvailability ().isAvailable == false ;
261
250
}
262
251
263
252
@ Override
@@ -329,4 +318,9 @@ void finalizeValues() {
329
318
flavor .finalizeValue ();
330
319
bundledJdk .finalizeValue ();
331
320
}
321
+
322
+ public Configuration getArchive () {
323
+ maybeFreeze ();
324
+ return configuration ;
325
+ }
332
326
}
0 commit comments