From 387e622f9f50ef39072c24ae8270275f114430e1 Mon Sep 17 00:00:00 2001 From: Mikko Suniala Date: Sat, 11 Jan 2025 16:01:04 +0200 Subject: [PATCH 1/2] Add options to disable timestamp and counter in markdown report Disabling timestamp and counter output makes the report more diff friendly. --- .../render/InventoryMarkdownReportRenderer.groovy | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/groovy/com/github/jk1/license/render/InventoryMarkdownReportRenderer.groovy b/src/main/groovy/com/github/jk1/license/render/InventoryMarkdownReportRenderer.groovy index 7bd7b88..455b192 100644 --- a/src/main/groovy/com/github/jk1/license/render/InventoryMarkdownReportRenderer.groovy +++ b/src/main/groovy/com/github/jk1/license/render/InventoryMarkdownReportRenderer.groovy @@ -24,9 +24,14 @@ import com.github.jk1.license.PomData import com.github.jk1.license.ProjectData class InventoryMarkdownReportRenderer extends InventoryReportRenderer { + private Boolean includeTimestamp + private Boolean includeCounter - InventoryMarkdownReportRenderer(String fileName = 'licenses.md', String name = null, File overridesFile = null) { + InventoryMarkdownReportRenderer(String fileName = 'licenses.md', String name = null, File overridesFile = null, + Boolean includeTimestamp = true, Boolean includeCounter = true) { super(fileName, name, overridesFile) + this.includeTimestamp = includeTimestamp + this.includeCounter = includeCounter } @Override @@ -68,7 +73,7 @@ class InventoryMarkdownReportRenderer extends InventoryReportRenderer { output << "\n" output << "# ${name}\n" output << "## Dependency License Report\n" - output << "_${new Date().format('yyyy-MM-dd HH:mm:ss z')}_\n" + if (includeTimestamp) output << "_${new Date().format('yyyy-MM-dd HH:mm:ss z')}_\n" } protected void printDependency(ModuleData data) { @@ -109,7 +114,7 @@ class InventoryMarkdownReportRenderer extends InventoryReportRenderer { } protected void printDependencyMetaInformation(ModuleData data) { - output << "**${++counter}** " + if (includeCounter) output << "**${++counter}** " if (data.group) output << "**Group:** `$data.group` " if (data.name) output << "**Name:** `$data.name` " if (data.version) output << "**Version:** `$data.version` " @@ -154,7 +159,8 @@ class InventoryMarkdownReportRenderer extends InventoryReportRenderer { protected printImportedDependency(ImportedModuleData data) { output << "\n\n" - output << "${++counter}. **${data.name} v${data.version}**\n" + if (includeCounter) output << "${++counter}. " + output << "**${data.name} v${data.version}**\n" output << sectionLink("Project URL", data.projectUrl, data.projectUrl) output << sectionLink("License URL", data.license, data.licenseUrl) output << "\n\n" From 313c9e63bb2149f7d23f6aa3af7793bc90037ede Mon Sep 17 00:00:00 2001 From: Mikko Suniala Date: Sat, 11 Jan 2025 16:12:43 +0200 Subject: [PATCH 2/2] Add test case for omitting timestamp and counter in markdown report --- ...InventoryMarkdownReportRendererSpec.groovy | 9 +++ ...markdown_without_timestamp_and_counter.txt | 56 +++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 src/test/resources/com/github/jk1/license/render/InventoryMarkdownReportRendererSpec/check_the_correct_generation_of_markdown_without_timestamp_and_counter.txt diff --git a/src/test/groovy/com/github/jk1/license/render/InventoryMarkdownReportRendererSpec.groovy b/src/test/groovy/com/github/jk1/license/render/InventoryMarkdownReportRendererSpec.groovy index 400d87d..ee9b122 100644 --- a/src/test/groovy/com/github/jk1/license/render/InventoryMarkdownReportRendererSpec.groovy +++ b/src/test/groovy/com/github/jk1/license/render/InventoryMarkdownReportRendererSpec.groovy @@ -26,4 +26,13 @@ class InventoryMarkdownReportRendererSpec extends AbstractInventoryReportRendere def sanitizedOutput = outputFile.text.replaceAll("_[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} [A-Z0-9-]+_", "DATE") snapshotter.assertThat(sanitizedOutput).matchesSnapshot() } + + def "check the correct generation of markdown without timestamp and counter"() { + def renderer = new InventoryMarkdownReportRenderer(outputFile.name, "name", overrides, false, false) + when: + renderer.render(projectData) + then: + outputFile.exists() + snapshotter.assertThat(outputFile.text).matchesSnapshot() + } } diff --git a/src/test/resources/com/github/jk1/license/render/InventoryMarkdownReportRendererSpec/check_the_correct_generation_of_markdown_without_timestamp_and_counter.txt b/src/test/resources/com/github/jk1/license/render/InventoryMarkdownReportRendererSpec/check_the_correct_generation_of_markdown_without_timestamp_and_counter.txt new file mode 100644 index 0000000..aca1682 --- /dev/null +++ b/src/test/resources/com/github/jk1/license/render/InventoryMarkdownReportRendererSpec/check_the_correct_generation_of_markdown_without_timestamp_and_counter.txt @@ -0,0 +1,56 @@ + +# name +## Dependency License Report +## Apache License, Version 2.0 + +**Group:** `dummy-group` **Name:** `mod1` **Version:** `0.0.1` +> - **Manifest Project URL**: [http://dummy-mani-url](http://dummy-mani-url) +> - **Manifest License**: Apache 2.0 (Not Packaged) +> - **POM Project URL**: [http://dummy-pom-project-url](http://dummy-pom-project-url) +> - **POM License**: Apache License, Version 2.0 - [https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0) +> - **Embedded license files**: [apache2.license](apache2.license) + +**Group:** `dummy-group` **Name:** `mod2` **Version:** `0.0.1` +> - **Project URL**: [https://projecturl](https://projecturl) +> - **License URL**: [http://www.apache.org/licenses/LICENSE-2.0.txt](Apache License, Version 2.0) + +**Group:** `dummy-group` **Name:** `mod4` **Version:** `0.0.1` +> - **Manifest Project URL**: [http://dummy-mani-url](http://dummy-mani-url) +> - **Manifest License**: Apache 2.0 (Not Packaged) +> - **POM Project URL**: [http://dummy-pom-project-url](http://dummy-pom-project-url) +> - **POM License**: Apache License, Version 2.0 - [https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0) +> - **Embedded license files**: [apache2.license](apache2.license) + +## MIT License + +**Group:** `dummy-group` **Name:** `mod4` **Version:** `0.0.1` +> - **Manifest Project URL**: [http://dummy-mani-url](http://dummy-mani-url) +> - **Manifest License**: Apache 2.0 (Not Packaged) +> - **POM Project URL**: [http://dummy-pom-project-url](http://dummy-pom-project-url) +> - **POM License**: Apache License, Version 2.0 - [https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0) +> - **Embedded license files**: [apache2.license](apache2.license) + +## Unknown + +**Group:** `dummy-group` **Name:** `mod3` **Version:** `0.0.1` +> - **POM Project URL**: [http://dummy-pom-project-url](http://dummy-pom-project-url) +> - **POM License**: Unknown + +## bundle1 + + + + +**mod1 vsome-version** +> - **Project URL**: [some-projectUrl](some-projectUrl) +> - **License URL**: [apache-url](Apache 2) + + + + +**mod2 vsome-version** +> - **Project URL**: [some-projectUrl](some-projectUrl) +> - **License URL**: [apache-url](Apache 2) + + +