Skip to content

Commit

Permalink
Stop report task from triggering a deprecation warning
Browse files Browse the repository at this point in the history
Closes gh-400
  • Loading branch information
wilkinsona committed Dec 16, 2024
1 parent 0d1b43d commit fc43f90
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2022 the original author or authors.
* Copyright 2014-2024 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.
Expand Down Expand Up @@ -41,12 +41,12 @@ class DependencyManagementReportRenderer {
this.output = writer;
}

void startProject(Project project) {
void startProject(String path, String description, boolean root) {
this.output.println();
this.output.println("------------------------------------------------------------");
String heading = (project.getRootProject().equals(project)) ? "Root project" : "Project " + project.getPath();
if (project.getDescription() != null) {
heading += " - " + project.getDescription();
String heading = root ? "Root project" : ("Project " + path);
if (description != null) {
heading += " - " + description;
}
this.output.println(heading);
this.output.println("------------------------------------------------------------");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2022 the original author or authors.
* Copyright 2014-2024 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.
Expand All @@ -23,6 +23,7 @@

import io.spring.gradle.dependencymanagement.internal.DependencyManagementContainer;
import org.gradle.api.DefaultTask;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.tasks.TaskAction;

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

private DependencyManagementReportRenderer renderer = new DependencyManagementReportRenderer();

private final String projectPath;

private final String projectDescription;

private final boolean rootProject;

public DependencyManagementReportTask() {
Project project = getProject();
this.projectPath = project.getPath();
this.projectDescription = project.getDescription();
this.rootProject = project.getRootProject().equals(project);
}

void setRenderer(DependencyManagementReportRenderer renderer) {
this.renderer = renderer;
}
Expand All @@ -54,7 +68,7 @@ public void setDependencyManagementContainer(DependencyManagementContainer depen
*/
@TaskAction
public void report() {
this.renderer.startProject(getProject());
this.renderer.startProject(this.projectPath, this.projectDescription, this.rootProject);
Map<String, String> globalManagedVersions = this.dependencyManagementContainer
.getManagedVersionsForConfiguration(null);
this.renderer.renderGlobalManagedVersions(globalManagedVersions);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2022 the original author or authors.
* Copyright 2014-2024 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.
Expand Down Expand Up @@ -50,7 +50,7 @@ class DependencyManagementReportRendererTests {
@Test
void projectHeaderForRootProject() {
Project rootProject = ProjectBuilder.builder().build();
this.renderer.startProject(rootProject);
this.renderer.startProject(rootProject.getPath(), rootProject.getDescription(), true);
assertThat(outputLines()).containsExactly("", "------------------------------------------------------------",
"Root project", "------------------------------------------------------------", "");
}
Expand All @@ -61,7 +61,7 @@ void projectHeaderForSubproject() {
.withParent(ProjectBuilder.builder().build())
.withName("alpha")
.build();
this.renderer.startProject(subproject);
this.renderer.startProject(subproject.getPath(), subproject.getDescription(), false);
assertThat(outputLines()).containsExactly("", "------------------------------------------------------------",
"Project :alpha", "------------------------------------------------------------", "");
}
Expand All @@ -73,7 +73,7 @@ void projectHeaderForSubprojectWithDescription() {
.withName("alpha")
.build();
subproject.setDescription("description of alpha project");
this.renderer.startProject(subproject);
this.renderer.startProject(subproject.getPath(), subproject.getDescription(), false);
assertThat(outputLines()).containsExactly("", "------------------------------------------------------------",
"Project :alpha - description of alpha project",
"------------------------------------------------------------", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class DependencyManagementReportTaskTests {
@SuppressWarnings("unchecked")
void basicReport() {
this.task.report();
then(this.renderer).should().startProject(this.project);
then(this.renderer).should().startProject(this.project.getPath(), this.project.getDescription(), true);
then(this.renderer).should().renderGlobalManagedVersions(any(Map.class));
then(this.renderer).shouldHaveNoMoreInteractions();
}
Expand All @@ -66,7 +66,7 @@ void reportForProjectWithConfigurations() {
Configuration configurationOne = this.project.getConfigurations().create("second");
Configuration configurationTwo = this.project.getConfigurations().create("first");
this.task.report();
then(this.renderer).should().startProject(this.project);
then(this.renderer).should().startProject(this.project.getPath(), this.project.getDescription(), true);
then(this.renderer).should().renderGlobalManagedVersions(any(Map.class));
then(this.renderer).should()
.renderConfigurationManagedVersions(any(Map.class), eq(configurationTwo), any(Map.class));
Expand Down

0 comments on commit fc43f90

Please sign in to comment.