Skip to content

Commit b8aed98

Browse files
committed
Avoid calling getProject() when checking configuration metadata
Closes gh-40546
1 parent fd88783 commit b8aed98

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

buildSrc/src/main/java/org/springframework/boot/build/context/properties/CheckAdditionalSpringConfigurationMetadata.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,12 @@
4848
*/
4949
public class CheckAdditionalSpringConfigurationMetadata extends SourceTask {
5050

51+
private final File projectDir;
52+
5153
private final RegularFileProperty reportLocation;
5254

5355
public CheckAdditionalSpringConfigurationMetadata() {
56+
this.projectDir = getProject().getProjectDir();
5457
this.reportLocation = getProject().getObjects().fileProperty();
5558
}
5659

@@ -82,7 +85,7 @@ private Report createReport() throws IOException, JsonParseException, JsonMappin
8285
ObjectMapper objectMapper = new ObjectMapper();
8386
Report report = new Report();
8487
for (File file : getSource().getFiles()) {
85-
Analysis analysis = report.analysis(getProject().getProjectDir().toPath().relativize(file.toPath()));
88+
Analysis analysis = report.analysis(this.projectDir.toPath().relativize(file.toPath()));
8689
Map<String, Object> json = objectMapper.readValue(file, Map.class);
8790
check("groups", json, analysis);
8891
check("properties", json, analysis);

buildSrc/src/main/java/org/springframework/boot/build/context/properties/CheckSpringConfigurationMetadata.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,14 @@ public class CheckSpringConfigurationMetadata extends DefaultTask {
4949

5050
private List<String> exclusions = new ArrayList<>();
5151

52+
private final File projectDir;
53+
5254
private final RegularFileProperty reportLocation;
5355

5456
private final RegularFileProperty metadataLocation;
5557

5658
public CheckSpringConfigurationMetadata() {
59+
this.projectDir = getProject().getProjectDir();
5760
this.metadataLocation = getProject().getObjects().fileProperty();
5861
this.reportLocation = getProject().getObjects().fileProperty();
5962
}
@@ -93,7 +96,7 @@ void check() throws JsonParseException, IOException {
9396
private Report createReport() throws IOException, JsonParseException, JsonMappingException {
9497
ObjectMapper objectMapper = new ObjectMapper();
9598
File file = this.metadataLocation.get().getAsFile();
96-
Report report = new Report(getProject().getProjectDir().toPath().relativize(file.toPath()));
99+
Report report = new Report(this.projectDir.toPath().relativize(file.toPath()));
97100
Map<String, Object> json = objectMapper.readValue(file, Map.class);
98101
List<Map<String, Object>> properties = (List<Map<String, Object>>) json.get("properties");
99102
for (Map<String, Object> property : properties) {

0 commit comments

Comments
 (0)