Skip to content

Commit

Permalink
Allow Gradle task property to be set with String or enum value
Browse files Browse the repository at this point in the history
  • Loading branch information
scottfrederick committed Oct 20, 2022
1 parent c53c8c8 commit b78b22b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public abstract class BootBuildImage extends DefaultTask {

private static final String BUILDPACK_JVM_VERSION_KEY = "BP_JVM_VERSION";

private final Property<PullPolicy> pullPolicy;

private final String projectName;

private final CacheSpec buildCache;
Expand All @@ -94,6 +96,7 @@ public BootBuildImage() {
this.buildCache = getProject().getObjects().newInstance(CacheSpec.class);
this.launchCache = getProject().getObjects().newInstance(CacheSpec.class);
this.docker = getProject().getObjects().newInstance(DockerSpec.class);
this.pullPolicy = getProject().getObjects().property(PullPolicy.class);
}

/**
Expand Down Expand Up @@ -175,7 +178,17 @@ public BootBuildImage() {
@Input
@Optional
@Option(option = "pullPolicy", description = "The image pull policy")
public abstract Property<String> getPullPolicy();
public Property<PullPolicy> getPullPolicy() {
return this.pullPolicy;
}

/**
* Sets image pull policy that will be used when building the image.
* @param pullPolicy the pull policy to use
*/
public void setPullPolicy(String pullPolicy) {
getPullPolicy().set(PullPolicy.valueOf(pullPolicy));
}

/**
* Whether the built image should be pushed to a registry.
Expand Down Expand Up @@ -342,7 +355,7 @@ private BuildRequest customizeCreator(BuildRequest request) {
}

private BuildRequest customizePullPolicy(BuildRequest request) {
PullPolicy pullPolicy = getPullPolicy().map(PullPolicy::valueOf).getOrNull();
PullPolicy pullPolicy = getPullPolicy().getOrNull();
if (pullPolicy != null) {
request = request.withPullPolicy(pullPolicy);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ void whenUsingDefaultConfigurationThenRequestHasAlwaysPullPolicy() {

@Test
void whenPullPolicyIsConfiguredThenRequestHasPullPolicy() {
this.buildImage.getPullPolicy().set(PullPolicy.NEVER.toString());
this.buildImage.getPullPolicy().set(PullPolicy.NEVER);
assertThat(this.buildImage.createRequest().getPullPolicy()).isEqualTo(PullPolicy.NEVER);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.springframework.boot.buildpack.platform.build.PullPolicy;

plugins {
id 'java'
id 'org.springframework.boot' version '{version}'
Expand All @@ -12,4 +14,5 @@ targetCompatibility = '1.8'

bootBuildImage {
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
pullPolicy = PullPolicy.ALWAYS
}

0 comments on commit b78b22b

Please sign in to comment.