1
1
/*
2
- * Copyright 2012-2020 the original author or authors.
2
+ * Copyright 2012-2021 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
17
17
package org .springframework .boot .buildpack .platform .build ;
18
18
19
19
import java .io .File ;
20
+ import java .util .Arrays ;
20
21
import java .util .Collections ;
21
22
import java .util .LinkedHashMap ;
23
+ import java .util .List ;
22
24
import java .util .Map ;
23
25
import java .util .function .Function ;
24
26
@@ -61,6 +63,8 @@ public class BuildRequest {
61
63
62
64
private final boolean publish ;
63
65
66
+ private final List <BuildpackReference > buildpacks ;
67
+
64
68
BuildRequest (ImageReference name , Function <Owner , TarArchive > applicationContent ) {
65
69
Assert .notNull (name , "Name must not be null" );
66
70
Assert .notNull (applicationContent , "ApplicationContent must not be null" );
@@ -74,11 +78,12 @@ public class BuildRequest {
74
78
this .pullPolicy = PullPolicy .ALWAYS ;
75
79
this .publish = false ;
76
80
this .creator = Creator .withVersion ("" );
81
+ this .buildpacks = Collections .emptyList ();
77
82
}
78
83
79
84
BuildRequest (ImageReference name , Function <Owner , TarArchive > applicationContent , ImageReference builder ,
80
85
ImageReference runImage , Creator creator , Map <String , String > env , boolean cleanCache ,
81
- boolean verboseLogging , PullPolicy pullPolicy , boolean publish ) {
86
+ boolean verboseLogging , PullPolicy pullPolicy , boolean publish , List < BuildpackReference > buildpacks ) {
82
87
this .name = name ;
83
88
this .applicationContent = applicationContent ;
84
89
this .builder = builder ;
@@ -89,6 +94,7 @@ public class BuildRequest {
89
94
this .verboseLogging = verboseLogging ;
90
95
this .pullPolicy = pullPolicy ;
91
96
this .publish = publish ;
97
+ this .buildpacks = buildpacks ;
92
98
}
93
99
94
100
/**
@@ -99,7 +105,8 @@ public class BuildRequest {
99
105
public BuildRequest withBuilder (ImageReference builder ) {
100
106
Assert .notNull (builder , "Builder must not be null" );
101
107
return new BuildRequest (this .name , this .applicationContent , builder .inTaggedOrDigestForm (), this .runImage ,
102
- this .creator , this .env , this .cleanCache , this .verboseLogging , this .pullPolicy , this .publish );
108
+ this .creator , this .env , this .cleanCache , this .verboseLogging , this .pullPolicy , this .publish ,
109
+ this .buildpacks );
103
110
}
104
111
105
112
/**
@@ -109,7 +116,8 @@ public BuildRequest withBuilder(ImageReference builder) {
109
116
*/
110
117
public BuildRequest withRunImage (ImageReference runImageName ) {
111
118
return new BuildRequest (this .name , this .applicationContent , this .builder , runImageName .inTaggedOrDigestForm (),
112
- this .creator , this .env , this .cleanCache , this .verboseLogging , this .pullPolicy , this .publish );
119
+ this .creator , this .env , this .cleanCache , this .verboseLogging , this .pullPolicy , this .publish ,
120
+ this .buildpacks );
113
121
}
114
122
115
123
/**
@@ -120,7 +128,7 @@ public BuildRequest withRunImage(ImageReference runImageName) {
120
128
public BuildRequest withCreator (Creator creator ) {
121
129
Assert .notNull (creator , "Creator must not be null" );
122
130
return new BuildRequest (this .name , this .applicationContent , this .builder , this .runImage , creator , this .env ,
123
- this .cleanCache , this .verboseLogging , this .pullPolicy , this .publish );
131
+ this .cleanCache , this .verboseLogging , this .pullPolicy , this .publish , this . buildpacks );
124
132
}
125
133
126
134
/**
@@ -135,7 +143,8 @@ public BuildRequest withEnv(String name, String value) {
135
143
Map <String , String > env = new LinkedHashMap <>(this .env );
136
144
env .put (name , value );
137
145
return new BuildRequest (this .name , this .applicationContent , this .builder , this .runImage , this .creator ,
138
- Collections .unmodifiableMap (env ), this .cleanCache , this .verboseLogging , this .pullPolicy , this .publish );
146
+ Collections .unmodifiableMap (env ), this .cleanCache , this .verboseLogging , this .pullPolicy , this .publish ,
147
+ this .buildpacks );
139
148
}
140
149
141
150
/**
@@ -149,7 +158,7 @@ public BuildRequest withEnv(Map<String, String> env) {
149
158
updatedEnv .putAll (env );
150
159
return new BuildRequest (this .name , this .applicationContent , this .builder , this .runImage , this .creator ,
151
160
Collections .unmodifiableMap (updatedEnv ), this .cleanCache , this .verboseLogging , this .pullPolicy ,
152
- this .publish );
161
+ this .publish , this . buildpacks );
153
162
}
154
163
155
164
/**
@@ -159,7 +168,7 @@ public BuildRequest withEnv(Map<String, String> env) {
159
168
*/
160
169
public BuildRequest withCleanCache (boolean cleanCache ) {
161
170
return new BuildRequest (this .name , this .applicationContent , this .builder , this .runImage , this .creator , this .env ,
162
- cleanCache , this .verboseLogging , this .pullPolicy , this .publish );
171
+ cleanCache , this .verboseLogging , this .pullPolicy , this .publish , this . buildpacks );
163
172
}
164
173
165
174
/**
@@ -169,7 +178,7 @@ public BuildRequest withCleanCache(boolean cleanCache) {
169
178
*/
170
179
public BuildRequest withVerboseLogging (boolean verboseLogging ) {
171
180
return new BuildRequest (this .name , this .applicationContent , this .builder , this .runImage , this .creator , this .env ,
172
- this .cleanCache , verboseLogging , this .pullPolicy , this .publish );
181
+ this .cleanCache , verboseLogging , this .pullPolicy , this .publish , this . buildpacks );
173
182
}
174
183
175
184
/**
@@ -179,7 +188,7 @@ public BuildRequest withVerboseLogging(boolean verboseLogging) {
179
188
*/
180
189
public BuildRequest withPullPolicy (PullPolicy pullPolicy ) {
181
190
return new BuildRequest (this .name , this .applicationContent , this .builder , this .runImage , this .creator , this .env ,
182
- this .cleanCache , this .verboseLogging , pullPolicy , this .publish );
191
+ this .cleanCache , this .verboseLogging , pullPolicy , this .publish , this . buildpacks );
183
192
}
184
193
185
194
/**
@@ -189,7 +198,28 @@ public BuildRequest withPullPolicy(PullPolicy pullPolicy) {
189
198
*/
190
199
public BuildRequest withPublish (boolean publish ) {
191
200
return new BuildRequest (this .name , this .applicationContent , this .builder , this .runImage , this .creator , this .env ,
192
- this .cleanCache , this .verboseLogging , this .pullPolicy , publish );
201
+ this .cleanCache , this .verboseLogging , this .pullPolicy , publish , this .buildpacks );
202
+ }
203
+
204
+ /**
205
+ * Return a new {@link BuildRequest} with an updated buildpacks setting.
206
+ * @param buildpacks a collection of buildpacks to use when building the image
207
+ * @return an updated build request
208
+ */
209
+ public BuildRequest withBuildpacks (BuildpackReference ... buildpacks ) {
210
+ Assert .notEmpty (buildpacks , "Buildpacks must not be empty" );
211
+ return withBuildpacks (Arrays .asList (buildpacks ));
212
+ }
213
+
214
+ /**
215
+ * Return a new {@link BuildRequest} with an updated buildpacks setting.
216
+ * @param buildpacks a collection of buildpacks to use when building the image
217
+ * @return an updated build request
218
+ */
219
+ public BuildRequest withBuildpacks (List <BuildpackReference > buildpacks ) {
220
+ Assert .notNull (buildpacks , "Buildpacks must not be null" );
221
+ return new BuildRequest (this .name , this .applicationContent , this .builder , this .runImage , this .creator , this .env ,
222
+ this .cleanCache , this .verboseLogging , this .pullPolicy , this .publish , buildpacks );
193
223
}
194
224
195
225
/**
@@ -275,6 +305,14 @@ public PullPolicy getPullPolicy() {
275
305
return this .pullPolicy ;
276
306
}
277
307
308
+ /**
309
+ * Return the collection of buildpacks to use when building the image, if provided.
310
+ * @return the collection of buildpacks
311
+ */
312
+ public List <BuildpackReference > getBuildpacks () {
313
+ return this .buildpacks ;
314
+ }
315
+
278
316
/**
279
317
* Factory method to create a new {@link BuildRequest} from a JAR file.
280
318
* @param jarFile the source jar file
0 commit comments