@ -1,5 +1,5 @@
/ *
* Copyright 2012 - 202 1 the original author or authors .
* Copyright 2012 - 202 3 the original author or authors .
*
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -17,6 +17,8 @@
package org.springframework.boot.buildpack.platform.build ;
import java.io.File ;
import java.time.Instant ;
import java.time.format.DateTimeParseException ;
import java.util.Arrays ;
import java.util.Collections ;
import java.util.LinkedHashMap ;
@ -79,6 +81,8 @@ public class BuildRequest {
private final Cache launchCache ;
private final Instant createdDate ;
BuildRequest ( ImageReference name , Function < Owner , TarArchive > applicationContent ) {
Assert . notNull ( name , "Name must not be null" ) ;
Assert . notNull ( applicationContent , "ApplicationContent must not be null" ) ;
@ -98,12 +102,14 @@ public class BuildRequest {
this . tags = Collections . emptyList ( ) ;
this . buildCache = null ;
this . launchCache = null ;
this . createdDate = null ;
}
BuildRequest ( ImageReference name , Function < Owner , TarArchive > applicationContent , ImageReference builder ,
ImageReference runImage , Creator creator , Map < String , String > env , boolean cleanCache ,
boolean verboseLogging , PullPolicy pullPolicy , boolean publish , List < BuildpackReference > buildpacks ,
List < Binding > bindings , String network , List < ImageReference > tags , Cache buildCache , Cache launchCache ) {
List < Binding > bindings , String network , List < ImageReference > tags , Cache buildCache , Cache launchCache ,
Instant createdDate ) {
this . name = name ;
this . applicationContent = applicationContent ;
this . builder = builder ;
@ -120,6 +126,7 @@ public class BuildRequest {
this . tags = tags ;
this . buildCache = buildCache ;
this . launchCache = launchCache ;
this . createdDate = createdDate ;
}
/ * *
@ -131,7 +138,8 @@ public class BuildRequest {
Assert . notNull ( builder , "Builder must not be null" ) ;
return new BuildRequest ( this . name , this . applicationContent , builder . inTaggedOrDigestForm ( ) , this . runImage ,
this . creator , this . env , this . cleanCache , this . verboseLogging , this . pullPolicy , this . publish ,
this . buildpacks , this . bindings , this . network , this . tags , this . buildCache , this . launchCache ) ;
this . buildpacks , this . bindings , this . network , this . tags , this . buildCache , this . launchCache ,
this . createdDate ) ;
}
/ * *
@ -142,7 +150,8 @@ public class BuildRequest {
public BuildRequest withRunImage ( ImageReference runImageName ) {
return new BuildRequest ( this . name , this . applicationContent , this . builder , runImageName . inTaggedOrDigestForm ( ) ,
this . creator , this . env , this . cleanCache , this . verboseLogging , this . pullPolicy , this . publish ,
this . buildpacks , this . bindings , this . network , this . tags , this . buildCache , this . launchCache ) ;
this . buildpacks , this . bindings , this . network , this . tags , this . buildCache , this . launchCache ,
this . createdDate ) ;
}
/ * *
@ -154,7 +163,7 @@ public class BuildRequest {
Assert . notNull ( creator , "Creator must not be null" ) ;
return new BuildRequest ( this . name , this . applicationContent , this . builder , this . runImage , creator , this . env ,
this . cleanCache , this . verboseLogging , this . pullPolicy , this . publish , this . buildpacks , this . bindings ,
this . network , this . tags , this . buildCache , this . launchCache );
this . network , this . tags , this . buildCache , this . launchCache , this . createdDate );
}
/ * *
@ -170,7 +179,8 @@ public class BuildRequest {
env . put ( name , value ) ;
return new BuildRequest ( this . name , this . applicationContent , this . builder , this . runImage , this . creator ,
Collections . unmodifiableMap ( env ) , this . cleanCache , this . verboseLogging , this . pullPolicy , this . publish ,
this . buildpacks , this . bindings , this . network , this . tags , this . buildCache , this . launchCache ) ;
this . buildpacks , this . bindings , this . network , this . tags , this . buildCache , this . launchCache ,
this . createdDate ) ;
}
/ * *
@ -185,7 +195,7 @@ public class BuildRequest {
return new BuildRequest ( this . name , this . applicationContent , this . builder , this . runImage , this . creator ,
Collections . unmodifiableMap ( updatedEnv ) , this . cleanCache , this . verboseLogging , this . pullPolicy ,
this . publish , this . buildpacks , this . bindings , this . network , this . tags , this . buildCache ,
this . launchCache );
this . launchCache , this . createdDate );
}
/ * *
@ -196,7 +206,7 @@ public class BuildRequest {
public BuildRequest withCleanCache ( boolean cleanCache ) {
return new BuildRequest ( this . name , this . applicationContent , this . builder , this . runImage , this . creator , this . env ,
cleanCache , this . verboseLogging , this . pullPolicy , this . publish , this . buildpacks , this . bindings ,
this . network , this . tags , this . buildCache , this . launchCache );
this . network , this . tags , this . buildCache , this . launchCache , this . createdDate );
}
/ * *
@ -207,7 +217,7 @@ public class BuildRequest {
public BuildRequest withVerboseLogging ( boolean verboseLogging ) {
return new BuildRequest ( this . name , this . applicationContent , this . builder , this . runImage , this . creator , this . env ,
this . cleanCache , verboseLogging , this . pullPolicy , this . publish , this . buildpacks , this . bindings ,
this . network , this . tags , this . buildCache , this . launchCache );
this . network , this . tags , this . buildCache , this . launchCache , this . createdDate );
}
/ * *
@ -218,7 +228,7 @@ public class BuildRequest {
public BuildRequest withPullPolicy ( PullPolicy pullPolicy ) {
return new BuildRequest ( this . name , this . applicationContent , this . builder , this . runImage , this . creator , this . env ,
this . cleanCache , this . verboseLogging , pullPolicy , this . publish , this . buildpacks , this . bindings ,
this . network , this . tags , this . buildCache , this . launchCache );
this . network , this . tags , this . buildCache , this . launchCache , this . createdDate );
}
/ * *
@ -229,7 +239,7 @@ public class BuildRequest {
public BuildRequest withPublish ( boolean publish ) {
return new BuildRequest ( this . name , this . applicationContent , this . builder , this . runImage , this . creator , this . env ,
this . cleanCache , this . verboseLogging , this . pullPolicy , publish , this . buildpacks , this . bindings ,
this . network , this . tags , this . buildCache , this . launchCache );
this . network , this . tags , this . buildCache , this . launchCache , this . createdDate );
}
/ * *
@ -253,7 +263,7 @@ public class BuildRequest {
Assert . notNull ( buildpacks , "Buildpacks must not be null" ) ;
return new BuildRequest ( this . name , this . applicationContent , this . builder , this . runImage , this . creator , this . env ,
this . cleanCache , this . verboseLogging , this . pullPolicy , this . publish , buildpacks , this . bindings ,
this . network , this . tags , this . buildCache , this . launchCache );
this . network , this . tags , this . buildCache , this . launchCache , this . createdDate );
}
/ * *
@ -277,7 +287,7 @@ public class BuildRequest {
Assert . notNull ( bindings , "Bindings must not be null" ) ;
return new BuildRequest ( this . name , this . applicationContent , this . builder , this . runImage , this . creator , this . env ,
this . cleanCache , this . verboseLogging , this . pullPolicy , this . publish , this . buildpacks , bindings ,
this . network , this . tags , this . buildCache , this . launchCache );
this . network , this . tags , this . buildCache , this . launchCache , this . createdDate );
}
/ * *
@ -289,7 +299,7 @@ public class BuildRequest {
public BuildRequest withNetwork ( String network ) {
return new BuildRequest ( this . name , this . applicationContent , this . builder , this . runImage , this . creator , this . env ,
this . cleanCache , this . verboseLogging , this . pullPolicy , this . publish , this . buildpacks , this . bindings ,
network , this . tags , this . buildCache , this . launchCache );
network , this . tags , this . buildCache , this . launchCache , this . createdDate );
}
/ * *
@ -311,7 +321,7 @@ public class BuildRequest {
Assert . notNull ( tags , "Tags must not be null" ) ;
return new BuildRequest ( this . name , this . applicationContent , this . builder , this . runImage , this . creator , this . env ,
this . cleanCache , this . verboseLogging , this . pullPolicy , this . publish , this . buildpacks , this . bindings ,
this . network , tags , this . buildCache , this . launchCache );
this . network , tags , this . buildCache , this . launchCache , this . createdDate );
}
/ * *
@ -323,7 +333,7 @@ public class BuildRequest {
Assert . notNull ( buildCache , "BuildCache must not be null" ) ;
return new BuildRequest ( this . name , this . applicationContent , this . builder , this . runImage , this . creator , this . env ,
this . cleanCache , this . verboseLogging , this . pullPolicy , this . publish , this . buildpacks , this . bindings ,
this . network , this . tags , buildCache , this . launchCache );
this . network , this . tags , buildCache , this . launchCache , this . createdDate );
}
/ * *
@ -335,7 +345,31 @@ public class BuildRequest {
Assert . notNull ( launchCache , "LaunchCache must not be null" ) ;
return new BuildRequest ( this . name , this . applicationContent , this . builder , this . runImage , this . creator , this . env ,
this . cleanCache , this . verboseLogging , this . pullPolicy , this . publish , this . buildpacks , this . bindings ,
this . network , this . tags , this . buildCache , launchCache ) ;
this . network , this . tags , this . buildCache , launchCache , this . createdDate ) ;
}
/ * *
* Return a new { @link BuildRequest } with an updated created date .
* @param createdDate the created date
* @return an updated build request
* /
public BuildRequest withCreatedDate ( String createdDate ) {
Assert . notNull ( createdDate , "CreatedDate must not be null" ) ;
return new BuildRequest ( this . name , this . applicationContent , this . builder , this . runImage , this . creator , this . env ,
this . cleanCache , this . verboseLogging , this . pullPolicy , this . publish , this . buildpacks , this . bindings ,
this . network , this . tags , this . buildCache , this . launchCache , parseCreatedDate ( createdDate ) ) ;
}
private Instant parseCreatedDate ( String createdDate ) {
if ( "now" . equalsIgnoreCase ( createdDate ) ) {
return Instant . now ( ) ;
}
try {
return Instant . parse ( createdDate ) ;
}
catch ( DateTimeParseException ex ) {
throw new IllegalArgumentException ( "Error parsing '" + createdDate + "' as an image created date" , ex ) ;
}
}
/ * *
@ -471,6 +505,14 @@ public class BuildRequest {
return this . launchCache ;
}
/ * *
* Return the custom created date that should be used by the lifecycle .
* @return the created date
* /
public Instant getCreatedDate ( ) {
return this . createdDate ;
}
/ * *
* Factory method to create a new { @link BuildRequest } from a JAR file .
* @param jarFile the source jar file