diff --git a/src/main/java/io/spring/gradle/dependencymanagement/internal/report/DependencyManagementReportRenderer.java b/src/main/java/io/spring/gradle/dependencymanagement/internal/report/DependencyManagementReportRenderer.java index d0f11d7..b8a1575 100644 --- a/src/main/java/io/spring/gradle/dependencymanagement/internal/report/DependencyManagementReportRenderer.java +++ b/src/main/java/io/spring/gradle/dependencymanagement/internal/report/DependencyManagementReportRenderer.java @@ -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. @@ -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("------------------------------------------------------------"); diff --git a/src/main/java/io/spring/gradle/dependencymanagement/internal/report/DependencyManagementReportTask.java b/src/main/java/io/spring/gradle/dependencymanagement/internal/report/DependencyManagementReportTask.java index 5c30aaf..3728646 100644 --- a/src/main/java/io/spring/gradle/dependencymanagement/internal/report/DependencyManagementReportTask.java +++ b/src/main/java/io/spring/gradle/dependencymanagement/internal/report/DependencyManagementReportTask.java @@ -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. @@ -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; @@ -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; } @@ -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 globalManagedVersions = this.dependencyManagementContainer .getManagedVersionsForConfiguration(null); this.renderer.renderGlobalManagedVersions(globalManagedVersions); diff --git a/src/test/java/io/spring/gradle/dependencymanagement/internal/report/DependencyManagementReportRendererTests.java b/src/test/java/io/spring/gradle/dependencymanagement/internal/report/DependencyManagementReportRendererTests.java index 111cdad..abb4d6f 100644 --- a/src/test/java/io/spring/gradle/dependencymanagement/internal/report/DependencyManagementReportRendererTests.java +++ b/src/test/java/io/spring/gradle/dependencymanagement/internal/report/DependencyManagementReportRendererTests.java @@ -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. @@ -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", "------------------------------------------------------------", ""); } @@ -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", "------------------------------------------------------------", ""); } @@ -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", "------------------------------------------------------------", ""); diff --git a/src/test/java/io/spring/gradle/dependencymanagement/internal/report/DependencyManagementReportTaskTests.java b/src/test/java/io/spring/gradle/dependencymanagement/internal/report/DependencyManagementReportTaskTests.java index 861e925..850d8cb 100644 --- a/src/test/java/io/spring/gradle/dependencymanagement/internal/report/DependencyManagementReportTaskTests.java +++ b/src/test/java/io/spring/gradle/dependencymanagement/internal/report/DependencyManagementReportTaskTests.java @@ -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(); } @@ -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));