Commit c8021806 authored by Andy Wilkinson's avatar Andy Wilkinson

Use sorted properties to make build info output repeatable

Closes gh-14494
parent 6de14f71
......@@ -22,12 +22,15 @@ import java.io.IOException;
import java.util.Properties;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.InvalidRunnerConfigurationException;
import org.gradle.testkit.runner.TaskOutcome;
import org.gradle.testkit.runner.UnexpectedBuildFailure;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.gradle.junit.GradleCompatibilityExtension;
import org.springframework.boot.gradle.testkit.GradleBuild;
import org.springframework.boot.loader.tools.FileUtils;
import static org.assertj.core.api.Assertions.assertThat;
......@@ -92,6 +95,22 @@ public class BuildInfoIntegrationTests {
assertThat(result.task(":buildInfo").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
}
@TestTemplate
public void reproducibleOutputWithFixedTime() throws InvalidRunnerConfigurationException,
UnexpectedBuildFailure, IOException, InterruptedException {
assertThat(this.gradleBuild.build("buildInfo", "-PnullTime").task(":buildInfo")
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
File buildInfoProperties = new File(this.gradleBuild.getProjectDir(),
"build/build-info.properties");
String firstHash = FileUtils.sha1Hash(buildInfoProperties);
assertThat(buildInfoProperties.delete()).isTrue();
Thread.sleep(1500);
assertThat(this.gradleBuild.build("buildInfo", "-PnullTime")
.task(":buildInfo").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
String secondHash = FileUtils.sha1Hash(buildInfoProperties);
assertThat(firstHash).isEqualTo(secondHash);
}
private Properties buildInfoProperties() {
File file = new File(this.gradleBuild.getProjectDir(),
"build/build-info.properties");
......
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
......@@ -24,6 +24,8 @@ import java.time.format.DateTimeFormatter;
import java.util.Map;
import java.util.Properties;
import org.springframework.core.CollectionFactory;
/**
* A {@code BuildPropertiesWriter} writes the {@code build-info.properties} for
* consumption by the Actuator.
......@@ -68,7 +70,7 @@ public final class BuildPropertiesWriter {
}
protected Properties createBuildInfo(ProjectDetails project) {
Properties properties = new Properties();
Properties properties = CollectionFactory.createSortedProperties(true);
properties.put("build.group", project.getGroup());
properties.put("build.artifact", project.getArtifact());
properties.put("build.name", project.getName());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment