11/*
2- * Copyright 2012-2020 the original author or authors.
2+ * Copyright 2012-2021 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.
1717package org .springframework .boot .buildpack .platform .build ;
1818
1919import java .io .File ;
20+ import java .util .Arrays ;
2021import java .util .Collections ;
2122import java .util .LinkedHashMap ;
23+ import java .util .List ;
2224import java .util .Map ;
2325import java .util .function .Function ;
2426
@@ -61,6 +63,8 @@ public class BuildRequest {
6163
6264 private final boolean publish ;
6365
66+ private final List <BuildpackReference > buildpacks ;
67+
6468 BuildRequest (ImageReference name , Function <Owner , TarArchive > applicationContent ) {
6569 Assert .notNull (name , "Name must not be null" );
6670 Assert .notNull (applicationContent , "ApplicationContent must not be null" );
@@ -74,11 +78,12 @@ public class BuildRequest {
7478 this .pullPolicy = PullPolicy .ALWAYS ;
7579 this .publish = false ;
7680 this .creator = Creator .withVersion ("" );
81+ this .buildpacks = Collections .emptyList ();
7782 }
7883
7984 BuildRequest (ImageReference name , Function <Owner , TarArchive > applicationContent , ImageReference builder ,
8085 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 ) {
8287 this .name = name ;
8388 this .applicationContent = applicationContent ;
8489 this .builder = builder ;
@@ -89,6 +94,7 @@ public class BuildRequest {
8994 this .verboseLogging = verboseLogging ;
9095 this .pullPolicy = pullPolicy ;
9196 this .publish = publish ;
97+ this .buildpacks = buildpacks ;
9298 }
9399
94100 /**
@@ -99,7 +105,8 @@ public class BuildRequest {
99105 public BuildRequest withBuilder (ImageReference builder ) {
100106 Assert .notNull (builder , "Builder must not be null" );
101107 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 );
103110 }
104111
105112 /**
@@ -109,7 +116,8 @@ public BuildRequest withBuilder(ImageReference builder) {
109116 */
110117 public BuildRequest withRunImage (ImageReference runImageName ) {
111118 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 );
113121 }
114122
115123 /**
@@ -120,7 +128,7 @@ public BuildRequest withRunImage(ImageReference runImageName) {
120128 public BuildRequest withCreator (Creator creator ) {
121129 Assert .notNull (creator , "Creator must not be null" );
122130 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 );
124132 }
125133
126134 /**
@@ -135,7 +143,8 @@ public BuildRequest withEnv(String name, String value) {
135143 Map <String , String > env = new LinkedHashMap <>(this .env );
136144 env .put (name , value );
137145 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 );
139148 }
140149
141150 /**
@@ -149,7 +158,7 @@ public BuildRequest withEnv(Map<String, String> env) {
149158 updatedEnv .putAll (env );
150159 return new BuildRequest (this .name , this .applicationContent , this .builder , this .runImage , this .creator ,
151160 Collections .unmodifiableMap (updatedEnv ), this .cleanCache , this .verboseLogging , this .pullPolicy ,
152- this .publish );
161+ this .publish , this . buildpacks );
153162 }
154163
155164 /**
@@ -159,7 +168,7 @@ public BuildRequest withEnv(Map<String, String> env) {
159168 */
160169 public BuildRequest withCleanCache (boolean cleanCache ) {
161170 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 );
163172 }
164173
165174 /**
@@ -169,7 +178,7 @@ public BuildRequest withCleanCache(boolean cleanCache) {
169178 */
170179 public BuildRequest withVerboseLogging (boolean verboseLogging ) {
171180 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 );
173182 }
174183
175184 /**
@@ -179,7 +188,7 @@ public BuildRequest withVerboseLogging(boolean verboseLogging) {
179188 */
180189 public BuildRequest withPullPolicy (PullPolicy pullPolicy ) {
181190 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 );
183192 }
184193
185194 /**
@@ -189,7 +198,28 @@ public BuildRequest withPullPolicy(PullPolicy pullPolicy) {
189198 */
190199 public BuildRequest withPublish (boolean publish ) {
191200 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 );
193223 }
194224
195225 /**
@@ -275,6 +305,14 @@ public PullPolicy getPullPolicy() {
275305 return this .pullPolicy ;
276306 }
277307
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+
278316 /**
279317 * Factory method to create a new {@link BuildRequest} from a JAR file.
280318 * @param jarFile the source jar file
0 commit comments