Skip to content

Commit

Permalink
Merge branch 'release/4.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
chrimaeon committed Jun 18, 2022
2 parents f381fd2 + fa98c11 commit 2e57bbf
Show file tree
Hide file tree
Showing 12 changed files with 190 additions and 21 deletions.
1 change: 1 addition & 0 deletions .github/workflows/create_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
[
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
- develop
- 'release/**'
- 'hotfix/**'
pull_request:

jobs:
build-and-test:
Expand Down
13 changes: 10 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,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

Expand All @@ -28,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
Expand Down
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
```
</details>
Expand All @@ -28,7 +28,7 @@ plugins {

```groovy
plugins {
id 'com.cmgapps.licenses' version '4.5.0'
id 'com.cmgapps.licenses' version '4.6.0'
}
```
</details>
Expand All @@ -46,7 +46,7 @@ buildscript {
}
}
dependencies {
classpath("com.cmgapps:gradle-licenses-plugin:4.5.0")
classpath("com.cmgapps:gradle-licenses-plugin:4.6.0")
}
}

Expand All @@ -65,7 +65,7 @@ buildscript {
}
}
dependencies {
classpath 'com.cmgapps:gradle-licenses-plugin:4.5.0'
classpath 'com.cmgapps:gradle-licenses-plugin:4.6.0'
}
}
Expand Down Expand Up @@ -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 `<meta name="color-scheme" content="dark light">` and a custom css theme.

It can be disabled via
```kotlin
licenses {
reports {
html.useDarkMode.set(false)
}
}
```
* `JSON`
generates a JSON file
* `XML`
Expand Down
2 changes: 1 addition & 1 deletion pom.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# SPDX-License-Identifier: Apache-2.0
#
group=com.cmgapps
versionName=4.5.0
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ class LicensePluginJavaMultiProjectShould {
"<html lang=\"en\">" +
"<head>" +
"<meta charset=\"UTF-8\">" +
"<style>body{font-family:sans-serif;background-color:#eee}pre,.license{background-color:#ddd;padding:1em}pre{white-space:pre-wrap}</style>" +
"<meta name=\"color-scheme\" content=\"dark light\">" +
"<style>" +
"body{font-family:sans-serif;background-color:#eee}" +
"pre,.license{background-color:#ddd;padding:1em}pre{white-space:pre-wrap}" +
"@media(prefers-color-scheme: dark){body{background-color: #303030}pre,.license {background-color: #242424}}" +
"</style>" +
"<title>Open source licenses</title>" +
"</head>" +
"<body>" +
Expand Down Expand Up @@ -156,7 +161,12 @@ class LicensePluginJavaMultiProjectShould {
"<html lang=\"en\">" +
"<head>" +
"<meta charset=\"UTF-8\">" +
"<style>body{font-family:sans-serif;background-color:#eee}pre,.license{background-color:#ddd;padding:1em}pre{white-space:pre-wrap}</style>" +
"<meta name=\"color-scheme\" content=\"dark light\">" +
"<style>" +
"body{font-family:sans-serif;background-color:#eee}" +
"pre,.license{background-color:#ddd;padding:1em}pre{white-space:pre-wrap}" +
"@media(prefers-color-scheme: dark){body{background-color: #303030}pre,.license {background-color: #242424}}" +
"</style>" +
"<title>Open source licenses</title>" +
"</head>" +
"<body>" +
Expand Down Expand Up @@ -214,7 +224,12 @@ class LicensePluginJavaMultiProjectShould {
"<html lang=\"en\">" +
"<head>" +
"<meta charset=\"UTF-8\">" +
"<style>body{font-family:sans-serif;background-color:#eee}pre,.license{background-color:#ddd;padding:1em}pre{white-space:pre-wrap}</style>" +
"<meta name=\"color-scheme\" content=\"dark light\">" +
"<style>" +
"body{font-family:sans-serif;background-color:#eee}" +
"pre,.license{background-color:#ddd;padding:1em}pre{white-space:pre-wrap}" +
"@media(prefers-color-scheme: dark){body{background-color: #303030}pre,.license {background-color: #242424}}" +
"</style>" +
"<title>Open source licenses</title>" +
"</head>" +
"<body>" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ class LicensePluginJavaShould {
"<html lang=\"en\">" +
"<head>" +
"<meta charset=\"UTF-8\">" +
"<style>body{font-family:sans-serif;background-color:#eee}pre,.license{background-color:#ddd;padding:1em}pre{white-space:pre-wrap}</style>" +
"<meta name=\"color-scheme\" content=\"dark light\">" +
"<style>" +
"body{font-family:sans-serif;background-color:#eee}" +
"pre,.license{background-color:#ddd;padding:1em}pre{white-space:pre-wrap}" +
"@media(prefers-color-scheme: dark){body{background-color: #303030}pre,.license {background-color: #242424}}" +
"</style>" +
"<title>Open source licenses</title>" +
"</head>" +
"<body>" +
Expand Down Expand Up @@ -139,7 +144,12 @@ class LicensePluginJavaShould {
"<html lang=\"en\">" +
"<head>" +
"<meta charset=\"UTF-8\">" +
"<style>body{font-family:sans-serif;background-color:#eee}pre,.license{background-color:#ddd;padding:1em}pre{white-space:pre-wrap}</style>" +
"<meta name=\"color-scheme\" content=\"dark light\">" +
"<style>" +
"body{font-family:sans-serif;background-color:#eee}" +
"pre,.license{background-color:#ddd;padding:1em}pre{white-space:pre-wrap}" +
"@media(prefers-color-scheme: dark){body{background-color: #303030}pre,.license {background-color: #242424}}" +
"</style>" +
"<title>Open source licenses</title>" +
"</head>" +
"<body>" +
Expand Down Expand Up @@ -183,7 +193,12 @@ class LicensePluginJavaShould {
"<html lang=\"en\">" +
"<head>" +
"<meta charset=\"UTF-8\">" +
"<style>body{font-family:sans-serif;background-color:#eee}pre,.license{background-color:#ddd;padding:1em}pre{white-space:pre-wrap}</style>" +
"<meta name=\"color-scheme\" content=\"dark light\">" +
"<style>" +
"body{font-family:sans-serif;background-color:#eee}" +
"pre,.license{background-color:#ddd;padding:1em}pre{white-space:pre-wrap}" +
"@media(prefers-color-scheme: dark){body{background-color: #303030}pre,.license {background-color: #242424}}" +
"</style>" +
"<title>Open source licenses</title>" +
"</head>" +
"<body>" +
Expand Down Expand Up @@ -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`(
"<!DOCTYPE html>" +
"<html lang=\"en\">" +
"<head>" +
"<meta charset=\"UTF-8\">" +
"<meta name=\"color-scheme\" content=\"dark light\">" +
"<style>" +
"body{font-family:sans-serif;background-color:#eee}" +
"pre,.license{background-color:#ddd;padding:1em}pre{white-space:pre-wrap}" +
"@media(prefers-color-scheme: dark){body{background-color: #303030}pre,.license {background-color: #242424}}" +
"</style>" +
"<title>Open source licenses</title>" +
"</head>" +
"<body>" +
"<h3>Notice for packages:</h3>" +
"<ul>" +
"<li>group:noname</li>" +
"</ul>" +
"<div class=\"license\">" +
"<p>Some license</p>" +
"<a href=\"http://website.tld/\">http://website.tld/</a>" +
"</div>" +
"</body>" +
"</html>"
)
)
}

@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))
Expand Down Expand Up @@ -284,6 +350,7 @@ class LicensePluginJavaShould {
reports {
html.enabled = true
html.stylesheet("body{}")
html.useDarkMode.set(false)
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/com/cmgapps/license/LicensesTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 12 additions & 5 deletions src/main/kotlin/com/cmgapps/license/reporter/HtmlReport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ import org.gradle.api.resources.TextResource
internal class HtmlReport(
libraries: List<Library>,
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"

Expand All @@ -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
Expand All @@ -48,11 +54,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) {
Expand Down
5 changes: 4 additions & 1 deletion src/main/kotlin/com/cmgapps/license/reporter/Report.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<TextResource?> = task.project.objects.property(TextResource::class.java)
internal val _stylesheet: Property<TextResource?> = task.project.objects.property(TextResource::class.java)

@Input
fun stylesheet(css: String) {
Expand All @@ -84,6 +84,9 @@ class CustomizableHtmlReport(type: ReportType, task: Task, project: Project) : L
_stylesheet.set(project.resources.text.fromFile(css))
}

@Input
val useDarkMode: Property<Boolean> = task.project.objects.property(Boolean::class.java).convention(true)

override fun configure(
config: (Action<in LicensesReport>)?,
configHtml: (Action<in CustomizableHtmlReport>)?,
Expand Down
9 changes: 8 additions & 1 deletion src/test/kotlin/com/cmgapps/license/LicensesTaskShould.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -85,6 +86,7 @@ class LicensesTaskShould {
task.reports {
it.html.enabled = true
it.html.stylesheet("body{}")
it.html.useDarkMode.set(false)
}
}

Expand Down Expand Up @@ -297,7 +299,12 @@ class LicensesTaskShould {
"<html lang=\"en\">" +
"<head>" +
"<meta charset=\"UTF-8\">" +
"<style>body{font-family:sans-serif;background-color:#eee}pre,.license{background-color:#ddd;padding:1em}pre{white-space:pre-wrap}</style>" +
"<meta name=\"color-scheme\" content=\"dark light\">" +
"<style>" +
"body{font-family:sans-serif;background-color:#eee}" +
"pre,.license{background-color:#ddd;padding:1em}pre{white-space:pre-wrap}" +
"@media(prefers-color-scheme: dark){body{background-color: #303030}pre,.license {background-color: #242424}}" +
"</style>" +
"<title>Open source licenses</title>" +
"</head>" +
"<body>" +
Expand Down
Loading

0 comments on commit 2e57bbf

Please sign in to comment.