Skip to content

Commit fc43f90

Browse files
committed
Stop report task from triggering a deprecation warning
Closes gh-400
1 parent 0d1b43d commit fc43f90

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

src/main/java/io/spring/gradle/dependencymanagement/internal/report/DependencyManagementReportRenderer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2022 the original author or authors.
2+
* Copyright 2014-2024 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.
@@ -41,12 +41,12 @@ class DependencyManagementReportRenderer {
4141
this.output = writer;
4242
}
4343

44-
void startProject(Project project) {
44+
void startProject(String path, String description, boolean root) {
4545
this.output.println();
4646
this.output.println("------------------------------------------------------------");
47-
String heading = (project.getRootProject().equals(project)) ? "Root project" : "Project " + project.getPath();
48-
if (project.getDescription() != null) {
49-
heading += " - " + project.getDescription();
47+
String heading = root ? "Root project" : ("Project " + path);
48+
if (description != null) {
49+
heading += " - " + description;
5050
}
5151
this.output.println(heading);
5252
this.output.println("------------------------------------------------------------");

src/main/java/io/spring/gradle/dependencymanagement/internal/report/DependencyManagementReportTask.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2022 the original author or authors.
2+
* Copyright 2014-2024 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.
@@ -23,6 +23,7 @@
2323

2424
import io.spring.gradle.dependencymanagement.internal.DependencyManagementContainer;
2525
import org.gradle.api.DefaultTask;
26+
import org.gradle.api.Project;
2627
import org.gradle.api.artifacts.Configuration;
2728
import org.gradle.api.tasks.TaskAction;
2829

@@ -37,6 +38,19 @@ public class DependencyManagementReportTask extends DefaultTask {
3738

3839
private DependencyManagementReportRenderer renderer = new DependencyManagementReportRenderer();
3940

41+
private final String projectPath;
42+
43+
private final String projectDescription;
44+
45+
private final boolean rootProject;
46+
47+
public DependencyManagementReportTask() {
48+
Project project = getProject();
49+
this.projectPath = project.getPath();
50+
this.projectDescription = project.getDescription();
51+
this.rootProject = project.getRootProject().equals(project);
52+
}
53+
4054
void setRenderer(DependencyManagementReportRenderer renderer) {
4155
this.renderer = renderer;
4256
}
@@ -54,7 +68,7 @@ public void setDependencyManagementContainer(DependencyManagementContainer depen
5468
*/
5569
@TaskAction
5670
public void report() {
57-
this.renderer.startProject(getProject());
71+
this.renderer.startProject(this.projectPath, this.projectDescription, this.rootProject);
5872
Map<String, String> globalManagedVersions = this.dependencyManagementContainer
5973
.getManagedVersionsForConfiguration(null);
6074
this.renderer.renderGlobalManagedVersions(globalManagedVersions);

src/test/java/io/spring/gradle/dependencymanagement/internal/report/DependencyManagementReportRendererTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2022 the original author or authors.
2+
* Copyright 2014-2024 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.
@@ -50,7 +50,7 @@ class DependencyManagementReportRendererTests {
5050
@Test
5151
void projectHeaderForRootProject() {
5252
Project rootProject = ProjectBuilder.builder().build();
53-
this.renderer.startProject(rootProject);
53+
this.renderer.startProject(rootProject.getPath(), rootProject.getDescription(), true);
5454
assertThat(outputLines()).containsExactly("", "------------------------------------------------------------",
5555
"Root project", "------------------------------------------------------------", "");
5656
}
@@ -61,7 +61,7 @@ void projectHeaderForSubproject() {
6161
.withParent(ProjectBuilder.builder().build())
6262
.withName("alpha")
6363
.build();
64-
this.renderer.startProject(subproject);
64+
this.renderer.startProject(subproject.getPath(), subproject.getDescription(), false);
6565
assertThat(outputLines()).containsExactly("", "------------------------------------------------------------",
6666
"Project :alpha", "------------------------------------------------------------", "");
6767
}
@@ -73,7 +73,7 @@ void projectHeaderForSubprojectWithDescription() {
7373
.withName("alpha")
7474
.build();
7575
subproject.setDescription("description of alpha project");
76-
this.renderer.startProject(subproject);
76+
this.renderer.startProject(subproject.getPath(), subproject.getDescription(), false);
7777
assertThat(outputLines()).containsExactly("", "------------------------------------------------------------",
7878
"Project :alpha - description of alpha project",
7979
"------------------------------------------------------------", "");

src/test/java/io/spring/gradle/dependencymanagement/internal/report/DependencyManagementReportTaskTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class DependencyManagementReportTaskTests {
5555
@SuppressWarnings("unchecked")
5656
void basicReport() {
5757
this.task.report();
58-
then(this.renderer).should().startProject(this.project);
58+
then(this.renderer).should().startProject(this.project.getPath(), this.project.getDescription(), true);
5959
then(this.renderer).should().renderGlobalManagedVersions(any(Map.class));
6060
then(this.renderer).shouldHaveNoMoreInteractions();
6161
}
@@ -66,7 +66,7 @@ void reportForProjectWithConfigurations() {
6666
Configuration configurationOne = this.project.getConfigurations().create("second");
6767
Configuration configurationTwo = this.project.getConfigurations().create("first");
6868
this.task.report();
69-
then(this.renderer).should().startProject(this.project);
69+
then(this.renderer).should().startProject(this.project.getPath(), this.project.getDescription(), true);
7070
then(this.renderer).should().renderGlobalManagedVersions(any(Map.class));
7171
then(this.renderer).should()
7272
.renderConfigurationManagedVersions(any(Map.class), eq(configurationTwo), any(Map.class));

0 commit comments

Comments
 (0)