Skip to content

Commit e065ee7

Browse files
committed
Merge branch '2.1.x' into 2.2.x
Closes gh-20183
2 parents 7a11499 + c8907d4 commit e065ee7

File tree

4 files changed

+43
-77
lines changed

4 files changed

+43
-77
lines changed

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/buildinfo/BuildInfo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import org.gradle.api.Project;
2626
import org.gradle.api.Task;
2727
import org.gradle.api.internal.ConventionTask;
28-
import org.gradle.api.tasks.Input;
28+
import org.gradle.api.tasks.Nested;
2929
import org.gradle.api.tasks.OutputDirectory;
3030
import org.gradle.api.tasks.TaskAction;
3131
import org.gradle.api.tasks.TaskExecutionException;
@@ -89,7 +89,7 @@ public void setDestinationDir(File destinationDir) {
8989
* {@code build-info.properties} file.
9090
* @return the properties
9191
*/
92-
@Input
92+
@Nested
9393
public BuildInfoProperties getProperties() {
9494
return this.properties;
9595
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 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.
@@ -22,6 +22,9 @@
2222
import java.util.Map;
2323

2424
import org.gradle.api.Project;
25+
import org.gradle.api.provider.Property;
26+
import org.gradle.api.tasks.Input;
27+
import org.gradle.api.tasks.Optional;
2528

2629
/**
2730
* The properties that are written into the {@code build-info.properties} file.
@@ -32,123 +35,131 @@
3235
@SuppressWarnings("serial")
3336
public class BuildInfoProperties implements Serializable {
3437

35-
private final transient Project project;
38+
private final Property<String> group;
3639

37-
private String group;
40+
private final Property<String> artifact;
3841

39-
private String artifact;
42+
private final Property<String> version;
4043

41-
private String version;
44+
private final Property<String> name;
4245

43-
private String name;
44-
45-
private Instant time;
46+
private final Property<Instant> time;
4647

4748
private Map<String, Object> additionalProperties = new HashMap<>();
4849

4950
BuildInfoProperties(Project project) {
50-
this.project = project;
51-
this.time = Instant.now();
51+
this.time = project.getObjects().property(Instant.class);
52+
this.time.set(Instant.now());
53+
this.group = project.getObjects().property(String.class);
54+
this.group.set(project.provider(() -> project.getGroup().toString()));
55+
this.artifact = project.getObjects().property(String.class);
56+
this.version = project.getObjects().property(String.class);
57+
this.version.set(project.provider(() -> project.getVersion().toString()));
58+
this.name = project.getObjects().property(String.class);
59+
this.name.set(project.provider(() -> project.getName().toString()));
5260
}
5361

5462
/**
5563
* Returns the value used for the {@code build.group} property. Defaults to the
5664
* {@link Project#getGroup() Project's group}.
5765
* @return the group
5866
*/
67+
@Input
68+
@Optional
5969
public String getGroup() {
60-
if (this.group == null) {
61-
this.group = this.project.getGroup().toString();
62-
}
63-
return this.group;
70+
return this.group.getOrNull();
6471
}
6572

6673
/**
6774
* Sets the value used for the {@code build.group} property.
6875
* @param group the group name
6976
*/
7077
public void setGroup(String group) {
71-
this.group = group;
78+
this.group.set(group);
7279
}
7380

7481
/**
7582
* Returns the value used for the {@code build.artifact} property.
7683
* @return the artifact
7784
*/
85+
@Input
86+
@Optional
7887
public String getArtifact() {
79-
return this.artifact;
88+
return this.artifact.getOrNull();
8089
}
8190

8291
/**
8392
* Sets the value used for the {@code build.artifact} property.
8493
* @param artifact the artifact
8594
*/
8695
public void setArtifact(String artifact) {
87-
this.artifact = artifact;
96+
this.artifact.set(artifact);
8897
}
8998

9099
/**
91100
* Returns the value used for the {@code build.version} property. Defaults to the
92101
* {@link Project#getVersion() Project's version}.
93102
* @return the version
94103
*/
104+
@Input
105+
@Optional
95106
public String getVersion() {
96-
if (this.version == null) {
97-
this.version = this.project.getVersion().toString();
98-
}
99-
return this.version;
107+
return this.version.getOrNull();
100108
}
101109

102110
/**
103111
* Sets the value used for the {@code build.version} property.
104112
* @param version the version
105113
*/
106114
public void setVersion(String version) {
107-
this.version = version;
115+
this.version.set(version);
108116
}
109117

110118
/**
111119
* Returns the value used for the {@code build.name} property. Defaults to the
112120
* {@link Project#getDisplayName() Project's display name}.
113121
* @return the name
114122
*/
123+
@Input
124+
@Optional
115125
public String getName() {
116-
if (this.name == null) {
117-
this.name = this.project.getName();
118-
}
119-
return this.name;
126+
return this.name.getOrNull();
120127
}
121128

122129
/**
123130
* Sets the value used for the {@code build.name} property.
124131
* @param name the name
125132
*/
126133
public void setName(String name) {
127-
this.name = name;
134+
this.name.set(name);
128135
}
129136

130137
/**
131138
* Returns the value used for the {@code build.time} property. Defaults to
132139
* {@link Instant#now} when the {@code BuildInfoProperties} instance was created.
133140
* @return the time
134141
*/
142+
@Input
143+
@Optional
135144
public Instant getTime() {
136-
return this.time;
145+
return this.time.getOrNull();
137146
}
138147

139148
/**
140149
* Sets the value used for the {@code build.time} property.
141150
* @param time the build time
142151
*/
143152
public void setTime(Instant time) {
144-
this.time = time;
153+
this.time.set(time);
145154
}
146155

147156
/**
148157
* Returns the additional properties that will be included. When written, the name of
149158
* each additional property is prefixed with {@code build.}.
150159
* @return the additional properties
151160
*/
161+
@Input
162+
@Optional
152163
public Map<String, Object> getAdditional() {
153164
return this.additionalProperties;
154165
}
@@ -162,46 +173,4 @@ public void setAdditional(Map<String, Object> additionalProperties) {
162173
this.additionalProperties = additionalProperties;
163174
}
164175

165-
@Override
166-
public boolean equals(Object obj) {
167-
if (this == obj) {
168-
return true;
169-
}
170-
if (obj == null || getClass() != obj.getClass()) {
171-
return false;
172-
}
173-
BuildInfoProperties other = (BuildInfoProperties) obj;
174-
boolean result = true;
175-
result = result && nullSafeEquals(this.additionalProperties, other.additionalProperties);
176-
result = result && nullSafeEquals(this.artifact, other.artifact);
177-
result = result && nullSafeEquals(this.group, other.group);
178-
result = result && nullSafeEquals(this.name, other.name);
179-
result = result && nullSafeEquals(this.version, other.version);
180-
result = result && nullSafeEquals(this.time, other.time);
181-
return result;
182-
}
183-
184-
private boolean nullSafeEquals(Object o1, Object o2) {
185-
if (o1 == o2) {
186-
return true;
187-
}
188-
if (o1 == null || o2 == null) {
189-
return false;
190-
}
191-
return (o1.equals(o2));
192-
}
193-
194-
@Override
195-
public int hashCode() {
196-
final int prime = 31;
197-
int result = 1;
198-
result = prime * result + ((this.additionalProperties == null) ? 0 : this.additionalProperties.hashCode());
199-
result = prime * result + ((this.artifact == null) ? 0 : this.artifact.hashCode());
200-
result = prime * result + ((this.group == null) ? 0 : this.group.hashCode());
201-
result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
202-
result = prime * result + ((this.version == null) ? 0 : this.version.hashCode());
203-
result = prime * result + ((this.time == null) ? 0 : this.time.hashCode());
204-
return result;
205-
}
206-
207176
}

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void basicExecution() {
6464
assertThat(buildInfoProperties).containsEntry("build.group", "foo");
6565
assertThat(buildInfoProperties).containsEntry("build.additional", "foo");
6666
assertThat(buildInfoProperties).containsEntry("build.name", "foo");
67-
assertThat(buildInfoProperties).containsEntry("build.version", "1.0");
67+
assertThat(buildInfoProperties).containsEntry("build.version", "0.1.0");
6868
}
6969

7070
@TestTemplate

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoIntegrationTests.gradle

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ task buildInfo(type: org.springframework.boot.gradle.tasks.buildinfo.BuildInfo)
1414
artifact = property('buildInfoArtifact', 'foo')
1515
group = property('buildInfoGroup', 'foo')
1616
name = property('buildInfoName', 'foo')
17-
if (!project.hasProperty('projectVersion')) {
18-
version = property('buildInfoVersion', '1.0')
19-
}
2017
additional = ['additional': property('buildInfoAdditional', 'foo')]
2118
if (project.hasProperty('nullTime')) {
2219
time = null

0 commit comments

Comments
 (0)