Consider time in BuildInfo up-to-date checks and allow it to be set
Closes gh-12111 Closes gh-12266
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 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.
|
||||
@@ -69,48 +69,19 @@ public class BuildInfoIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void upToDateWhenExecutedTwice() {
|
||||
public void notUpToDateWhenExecutedTwiceAsTimeChanges() {
|
||||
assertThat(this.gradleBuild.build("buildInfo").task(":buildInfo").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("buildInfo").task(":buildInfo").getOutcome())
|
||||
.isEqualTo(TaskOutcome.UP_TO_DATE);
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notUpToDateWhenDestinationDirChanges() {
|
||||
notUpToDateWithChangeToProperty("buildInfoDestinationDir");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notUpToDateWhenProjectArtifactChanges() {
|
||||
notUpToDateWithChangeToProperty("buildInfoArtifact");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notUpToDateWhenProjectGroupChanges() {
|
||||
notUpToDateWithChangeToProperty("buildInfoGroup");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notUpToDateWhenProjectVersionChanges() {
|
||||
notUpToDateWithChangeToProperty("buildInfoVersion");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notUpToDateWhenProjectNameChanges() {
|
||||
notUpToDateWithChangeToProperty("buildInfoName");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notUpToDateWhenAdditionalPropertyChanges() {
|
||||
notUpToDateWithChangeToProperty("buildInfoAdditional");
|
||||
}
|
||||
|
||||
private void notUpToDateWithChangeToProperty(String name) {
|
||||
assertThat(this.gradleBuild.build("buildInfo", "--stacktrace").task(":buildInfo")
|
||||
public void upToDateWhenExecutedTwiceWithFixedTime() {
|
||||
assertThat(this.gradleBuild.build("buildInfo", "-PnullTime").task(":buildInfo")
|
||||
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("buildInfo", "-P" + name + "=changed")
|
||||
.task(":buildInfo").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("buildInfo", "-PnullTime").task(":buildInfo")
|
||||
.getOutcome()).isEqualTo(TaskOutcome.UP_TO_DATE);
|
||||
}
|
||||
|
||||
private Properties buildInfoProperties() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 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.
|
||||
@@ -19,6 +19,8 @@ package org.springframework.boot.gradle.tasks.buildinfo;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
@@ -91,6 +93,29 @@ public class BuildInfoTests {
|
||||
assertThat(buildInfoProperties(task)).containsEntry("build.version", "2.3.4");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void timeIsSetInProperties() {
|
||||
BuildInfo task = createTask(createProject("test"));
|
||||
assertThat(buildInfoProperties(task)).containsEntry("build.time",
|
||||
DateTimeFormatter.ISO_INSTANT.format(task.getProperties().getTime()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void timeCanBeRemovedFromProperties() {
|
||||
BuildInfo task = createTask(createProject("test"));
|
||||
task.getProperties().setTime(null);
|
||||
assertThat(buildInfoProperties(task)).doesNotContainKey("build.time");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void timeCanBeCustomizedInProperties() {
|
||||
Instant now = Instant.now();
|
||||
BuildInfo task = createTask(createProject("test"));
|
||||
task.getProperties().setTime(now);
|
||||
assertThat(buildInfoProperties(task)).containsEntry("build.time",
|
||||
DateTimeFormatter.ISO_INSTANT.format(now));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void additionalPropertiesAreReflectedInProperties() {
|
||||
BuildInfo task = createTask(createProject("test"));
|
||||
|
||||
Reference in New Issue
Block a user