From d9860d9879197aef9caa66675bc48f3b345b4580 Mon Sep 17 00:00:00 2001 From: Christian Grach Date: Mon, 13 Jun 2022 18:20:15 +0200 Subject: [PATCH 1/6] trigger action on PR --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6ae16a5..e613af3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,6 +7,7 @@ on: - develop - 'release/**' - 'hotfix/**' + pull_request: jobs: build-and-test: From 63b078c0726db9990709226fa571db5993be43c5 Mon Sep 17 00:00:00 2001 From: Christian Grach Date: Mon, 13 Jun 2022 18:20:28 +0200 Subject: [PATCH 2/6] add publish release --- .github/workflows/create_release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index d769c4d..7d0065f 100644 --- a/.github/workflows/create_release.yml +++ b/.github/workflows/create_release.yml @@ -27,6 +27,7 @@ jobs: with: slack_token: ${{ secrets.SLACK_TOKEN }} channel: ${{ secrets.SLACK_CHANNEL }} + publish: true text: "${{ github.ref_name }} on ${{ github.repository }} released! :raised_hands:" blocks: | [ From 6f21608de9e7ce10cfc180c0039068184a474173 Mon Sep 17 00:00:00 2001 From: Christian Grach Date: Tue, 14 Jun 2022 11:48:09 +0200 Subject: [PATCH 3/6] sort licenses by name or maven coordinate --- CHANGELOG.md | 1 + .../kotlin/com/cmgapps/license/reporter/HtmlReport.kt | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b389b9..3d6b6e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Added ### Changed +- Sort libraries by name or maven coordinated on HTML report ### Deprecated diff --git a/src/main/kotlin/com/cmgapps/license/reporter/HtmlReport.kt b/src/main/kotlin/com/cmgapps/license/reporter/HtmlReport.kt index 467fcd2..d4ed605 100644 --- a/src/main/kotlin/com/cmgapps/license/reporter/HtmlReport.kt +++ b/src/main/kotlin/com/cmgapps/license/reporter/HtmlReport.kt @@ -48,11 +48,12 @@ internal class HtmlReport( libraries.toLicensesMap().forEach { (license, libraries) -> ul { - libraries.asSequence().sortedBy { it.name }.forEach { library -> - li { - +(library.name ?: library.mavenCoordinates.identifierWithoutVersion) + libraries.asSequence().sortedBy { it.name ?: it.mavenCoordinates.identifierWithoutVersion } + .forEach { library -> + li { + +(library.name ?: library.mavenCoordinates.identifierWithoutVersion) + } } - } } when (license.id) { From 7048b6b51c612437afbd25c98634b5dc0d68ba4d Mon Sep 17 00:00:00 2001 From: Christian Grach Date: Sat, 18 Jun 2022 14:08:05 +0200 Subject: [PATCH 4/6] add dark mode for html report --- CHANGELOG.md | 1 + README.md | 11 +++ pom.properties | 2 +- .../LicensePluginJavaMultiProjectShould.kt | 21 +++++- .../license/LicensePluginJavaShould.kt | 73 ++++++++++++++++++- .../com/cmgapps/license/LicensesTask.kt | 1 + .../cmgapps/license/reporter/HtmlReport.kt | 8 +- .../com/cmgapps/license/reporter/Report.kt | 5 +- .../com/cmgapps/license/LicensesTaskShould.kt | 9 ++- .../license/reporter/HtmlReportShould.kt | 49 +++++++++++++ 10 files changed, 170 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d6b6e6..068dd02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [Unreleased] ### Added +- dark mode for HTML report ### Changed - Sort libraries by name or maven coordinated on HTML report diff --git a/README.md b/README.md index 38b6940..1b653aa 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,17 @@ The plugin can output different formats. } } ``` + + * On the default CSS style Dark Mode for supported browsers is also enabled by default. It adds a `` and a custom css theme. + + It can be disabled via + ```kotlin + licenses { + reports { + html.useDarkMode.set(false) + } + } + ``` * `JSON` generates a JSON file * `XML` diff --git a/pom.properties b/pom.properties index 53a3638..4edb251 100644 --- a/pom.properties +++ b/pom.properties @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 # group=com.cmgapps -versionName=4.5.0 +versionName=4.6.0-SNAPSHOT pomName=Gradle Licenses Plugin pomArtifactId=gradle-licenses-plugin pomDescription=Gradle plugin that provides a task to generate a license report for the dependencies used in your project Java/Kotlin project. diff --git a/src/functionalTest/kotlin/com/cmgapps/license/LicensePluginJavaMultiProjectShould.kt b/src/functionalTest/kotlin/com/cmgapps/license/LicensePluginJavaMultiProjectShould.kt index 87e46f4..0bc0e4e 100644 --- a/src/functionalTest/kotlin/com/cmgapps/license/LicensePluginJavaMultiProjectShould.kt +++ b/src/functionalTest/kotlin/com/cmgapps/license/LicensePluginJavaMultiProjectShould.kt @@ -101,7 +101,12 @@ class LicensePluginJavaMultiProjectShould { "" + "" + "" + - "" + + "" + + "" + "Open source licenses" + "" + "" + @@ -156,7 +161,12 @@ class LicensePluginJavaMultiProjectShould { "" + "" + "" + - "" + + "" + + "" + "Open source licenses" + "" + "" + @@ -214,7 +224,12 @@ class LicensePluginJavaMultiProjectShould { "" + "" + "" + - "" + + "" + + "" + "Open source licenses" + "" + "" + diff --git a/src/functionalTest/kotlin/com/cmgapps/license/LicensePluginJavaShould.kt b/src/functionalTest/kotlin/com/cmgapps/license/LicensePluginJavaShould.kt index 915715f..37b9121 100644 --- a/src/functionalTest/kotlin/com/cmgapps/license/LicensePluginJavaShould.kt +++ b/src/functionalTest/kotlin/com/cmgapps/license/LicensePluginJavaShould.kt @@ -102,7 +102,12 @@ class LicensePluginJavaShould { "" + "" + "" + - "" + + "" + + "" + "Open source licenses" + "" + "" + @@ -139,7 +144,12 @@ class LicensePluginJavaShould { "" + "" + "" + - "" + + "" + + "" + "Open source licenses" + "" + "" + @@ -183,7 +193,12 @@ class LicensePluginJavaShould { "" + "" + "" + - "" + + "" + + "" + "Open source licenses" + "" + "" + @@ -217,6 +232,57 @@ class LicensePluginJavaShould { val result = gradleRunner.build() + assertThat( + result.output, + matchesPattern(Pattern.compile(".*Wrote HTML report to .*$reportFolder/licenses.html.*", Pattern.DOTALL)) + ) + assertThat( + File("$reportFolder/licenses.html").readText().trim(), + `is`( + "" + + "" + + "" + + "" + + "" + + "" + + "Open source licenses" + + "" + + "" + + "

Notice for packages:

" + + "
    " + + "
  • group:noname
  • " + + "
" + + "
" + + "

Some license

" + + "http://website.tld/" + + "
" + + "" + + "" + ) + ) + } + + @Test + fun `generate Html report with no dark theme`() { + buildFile + """ + licenses { + reports { + html.enabled = true + html.useDarkMode.set(false) + } + } + + dependencies { + implementation 'group:noname:1.0.0' + } + """.trimIndent() + + val result = gradleRunner.build() + assertThat( result.output, matchesPattern(Pattern.compile(".*Wrote HTML report to .*$reportFolder/licenses.html.*", Pattern.DOTALL)) @@ -284,6 +350,7 @@ class LicensePluginJavaShould { reports { html.enabled = true html.stylesheet("body{}") + html.useDarkMode.set(false) } } diff --git a/src/main/kotlin/com/cmgapps/license/LicensesTask.kt b/src/main/kotlin/com/cmgapps/license/LicensesTask.kt index 04a9e32..532de6b 100644 --- a/src/main/kotlin/com/cmgapps/license/LicensesTask.kt +++ b/src/main/kotlin/com/cmgapps/license/LicensesTask.kt @@ -263,6 +263,7 @@ abstract class LicensesTask : DefaultTask() { ReportType.HTML -> HtmlReport( libraries, reports.html._stylesheet.orNull, + reports.html.useDarkMode.get(), logger ) ReportType.JSON -> JsonReport(libraries) diff --git a/src/main/kotlin/com/cmgapps/license/reporter/HtmlReport.kt b/src/main/kotlin/com/cmgapps/license/reporter/HtmlReport.kt index d4ed605..9f202f3 100644 --- a/src/main/kotlin/com/cmgapps/license/reporter/HtmlReport.kt +++ b/src/main/kotlin/com/cmgapps/license/reporter/HtmlReport.kt @@ -17,12 +17,15 @@ import org.gradle.api.resources.TextResource internal class HtmlReport( libraries: List, private val css: TextResource?, + private val useDarkMode: Boolean, private val logger: Logger ) : Report(libraries) { companion object { private const val DEFAULT_PRE_CSS = "pre,.license{background-color:#ddd;padding:1em}pre{white-space:pre-wrap}" private const val DEFAULT_BODY_CSS = "body{font-family:sans-serif;background-color:#eee}" + private const val NIGHT_MODE_CSS = + "@media(prefers-color-scheme: dark){body{background-color: #303030}pre,.license {background-color: #242424}}" private const val DEFAULT_CSS = "$DEFAULT_BODY_CSS$DEFAULT_PRE_CSS" private const val OPEN_SOURCE_LIBRARIES = "Open source licenses" @@ -33,8 +36,11 @@ internal class HtmlReport( return html { head { meta(mapOf("charset" to "UTF-8")) + if (useDarkMode) { + meta(mapOf("name" to "color-scheme", "content" to "dark light")) + } style { - +(css?.asString() ?: DEFAULT_CSS) + +(css?.asString() ?: (DEFAULT_CSS + if (useDarkMode) NIGHT_MODE_CSS else "")) } title { +OPEN_SOURCE_LIBRARIES diff --git a/src/main/kotlin/com/cmgapps/license/reporter/Report.kt b/src/main/kotlin/com/cmgapps/license/reporter/Report.kt index 016b1e1..d6f099f 100644 --- a/src/main/kotlin/com/cmgapps/license/reporter/Report.kt +++ b/src/main/kotlin/com/cmgapps/license/reporter/Report.kt @@ -72,7 +72,7 @@ open class LicensesReport(internal val type: ReportType, task: Task, internal va class CustomizableHtmlReport(type: ReportType, task: Task, project: Project) : LicensesReport(type, task, project) { - internal var _stylesheet: Property = task.project.objects.property(TextResource::class.java) + internal val _stylesheet: Property = task.project.objects.property(TextResource::class.java) @Input fun stylesheet(css: String) { @@ -84,6 +84,9 @@ class CustomizableHtmlReport(type: ReportType, task: Task, project: Project) : L _stylesheet.set(project.resources.text.fromFile(css)) } + @Input + val useDarkMode: Property = task.project.objects.property(Boolean::class.java).convention(true) + override fun configure( config: (Action)?, configHtml: (Action)?, diff --git a/src/test/kotlin/com/cmgapps/license/LicensesTaskShould.kt b/src/test/kotlin/com/cmgapps/license/LicensesTaskShould.kt index 736c305..9c6abb8 100644 --- a/src/test/kotlin/com/cmgapps/license/LicensesTaskShould.kt +++ b/src/test/kotlin/com/cmgapps/license/LicensesTaskShould.kt @@ -48,6 +48,7 @@ class LicensesTaskShould { val task = project.tasks.create("licensesReport", LicensesTask::class.java) { task -> task.reports { it.html.enabled = true + it.html.useDarkMode.set(false) } } @@ -85,6 +86,7 @@ class LicensesTaskShould { task.reports { it.html.enabled = true it.html.stylesheet("body{}") + it.html.useDarkMode.set(false) } } @@ -297,7 +299,12 @@ class LicensesTaskShould { "" + "" + "" + - "" + + "" + + "" + "Open source licenses" + "" + "" + diff --git a/src/test/kotlin/com/cmgapps/license/reporter/HtmlReportShould.kt b/src/test/kotlin/com/cmgapps/license/reporter/HtmlReportShould.kt index 8fc20c2..0e9fe65 100644 --- a/src/test/kotlin/com/cmgapps/license/reporter/HtmlReportShould.kt +++ b/src/test/kotlin/com/cmgapps/license/reporter/HtmlReportShould.kt @@ -30,6 +30,7 @@ class HtmlReportShould { val result = HtmlReport( testLibraries, null, + false, logger ).generate() @@ -64,6 +65,53 @@ class HtmlReportShould { ) } + @Test + fun `generate HTML report with dark mode`() { + val logger: Logger = Logging.getLogger("TestLogger") + + val result = HtmlReport( + testLibraries, + null, + true, + logger + ).generate() + + assertThat( + result, + `is`( + "" + + "" + + "" + + "" + + "" + + "" + + "Open source licenses" + + "" + + "" + + "

Notice for packages:

" + + "
    " + + "
  • Test lib 1
  • " + + "
  • Test lib 2
  • " + + "
" + + "
" +
+                    getFileContent("apache-2.0.txt") +
+                    "
" + + "
    " + + "
  • Test lib 1
  • " + + "
" + + "
" +
+                    getFileContent("mit.txt") +
+                    "
" + + "" + + "" + ) + ) + } + @Test fun `report library without matching license`() { val logger = mock() @@ -80,6 +128,7 @@ class HtmlReportShould { ) ), null, + false, logger ).generate() From 14bc40512753810758796a03b3249f927135bd5c Mon Sep 17 00:00:00 2001 From: Christian Grach Date: Sat, 18 Jun 2022 14:17:48 +0200 Subject: [PATCH 5/6] bump version number --- pom.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.properties b/pom.properties index 4edb251..9a04d28 100644 --- a/pom.properties +++ b/pom.properties @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 # group=com.cmgapps -versionName=4.6.0-SNAPSHOT +versionName=4.6.0 pomName=Gradle Licenses Plugin pomArtifactId=gradle-licenses-plugin pomDescription=Gradle plugin that provides a task to generate a license report for the dependencies used in your project Java/Kotlin project. From fa98c11cfde8821ea8805dd8110fa5d0c79b8e52 Mon Sep 17 00:00:00 2001 From: Christian Grach Date: Sat, 18 Jun 2022 14:18:43 +0200 Subject: [PATCH 6/6] patch changelog --- CHANGELOG.md | 15 ++++++++++----- README.md | 8 ++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 068dd02..2dd248e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,8 @@ ## [Unreleased] ### Added -- dark mode for HTML report ### Changed -- Sort libraries by name or maven coordinated on HTML report ### Deprecated @@ -15,12 +13,12 @@ ### Security -## [4.5.0] +## [4.6.0] ### Added -- Better support for Android Variants +- Dark Mode for HTML report ### Changed -- Internal handling of the license mappings +- Sort libraries by name or maven coordinated on HTML report ### Deprecated @@ -30,6 +28,13 @@ ### Security +## [4.5.0] +### Added +- Better support for Android Variants + +### Changed +- Internal handling of the license mappings + ## [4.4.0] ### Added - [SPDX License Identifier](https://spdx.org/licenses/) for various reports diff --git a/README.md b/README.md index 1b653aa..36d3916 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ This Gradle plugin provides tasks to generate a file with the licenses used from ```kotlin plugins { - id("com.cmgapps.licenses") version "4.5.0" + id("com.cmgapps.licenses") version "4.6.0" } ``` @@ -28,7 +28,7 @@ plugins { ```groovy plugins { - id 'com.cmgapps.licenses' version '4.5.0' + id 'com.cmgapps.licenses' version '4.6.0' } ``` @@ -46,7 +46,7 @@ buildscript { } } dependencies { - classpath("com.cmgapps:gradle-licenses-plugin:4.5.0") + classpath("com.cmgapps:gradle-licenses-plugin:4.6.0") } } @@ -65,7 +65,7 @@ buildscript { } } dependencies { - classpath 'com.cmgapps:gradle-licenses-plugin:4.5.0' + classpath 'com.cmgapps:gradle-licenses-plugin:4.6.0' } }