Skip to content

Commit

Permalink
Merge branch 'release/4.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
chrimaeon committed Oct 17, 2021
2 parents e9b60d9 + d4e0b6b commit 806457b
Show file tree
Hide file tree
Showing 24 changed files with 782 additions and 120 deletions.
4 changes: 3 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ executors:
username: chrimaeon
password: $DOCKERHUB_PASSWORD
environment:
TERM: "dumb"
JAVA_TOOL_OPTIONS: "-Xmx3g"
GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dorg.gradle.parallel=false -Dorg.gradle.workers.max=2 -Dkotlin.compiler.execution.strategy=in-process -Dkotlin.incremental=false"

Expand Down Expand Up @@ -40,6 +41,7 @@ commands:
jobs:
test:
executor: android-executor
resource_class: medium
steps:
- checkout
- restore_gradle_wrapper
Expand All @@ -49,7 +51,7 @@ jobs:
command: ./gradlew check
- run:
name: Generate and verify code coverage and
command: ./gradlew jacocoTestReport jacocoTestCoverageVerification
command: ./gradlew jacocoTestReport
- save_gradle_wrapper
- save_gradle_cache
- store_test_results:
Expand Down
17 changes: 14 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@

### Security

## [3.3.0]
## [4.0.0]
### Added

- Kotlin Multiplatform support

### Changed

- Update Android Gradle plugin to version 7+
- Warning when license has no mapping for html reports
- Extension property to set `enabled` and `destination`

### Deprecated

Expand All @@ -29,12 +30,22 @@

### Security

## [3.3.0]

### Changed

- Update Android Gradle plugin to version 7+
- Warning when license has no mapping for html reports

## [3.2.0]

### Added

- set task outputs to report files
- add DSL to configure reports

### Changed

- use library to create CSV report

## [3.1.0]
Expand Down
57 changes: 38 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Gradle Licenses Plugin [![CircleCI](https://circleci.com/gh/chrimaeon/gradle-licenses-plugin.svg?style=svg)](https://circleci.com/gh/chrimaeon/gradle-licenses-plugin)

[![License](https://img.shields.io/badge/license-Apache%202.0-brightgreen.svg?style=for-the-badge)](http://www.apache.org/licenses/LICENSE-2.0)
[![MavenCentral](https://img.shields.io/maven-central/v/com.cmgapps/gradle-licenses-plugin?style=for-the-badge)](https://repo1.maven.org/maven2/com/cmgapps/gradle-licenses-plugin/)
[![gradlePluginPortal](https://img.shields.io/maven-metadata/v/https/plugins.gradle.org/m2/com/cmgapps/licenses/com.cmgapps.licenses.gradle.plugin/maven-metadata.xml.svg?label=Gradle%20Plugin%20Portal&style=for-the-badge)](https://plugins.gradle.org/plugin/com.cmgapps.licenses)
[![Gradle Plugin](https://img.shields.io/badge/Gradle-6.8%2B-%2302303A.svg?style=for-the-badge&logo=Gradle)](https://gradle.org/)
[![MavenCentral](https://img.shields.io/maven-central/v/com.cmgapps/gradle-licenses-plugin?style=for-the-badge&logo=Apache%20Maven)](https://repo1.maven.org/maven2/com/cmgapps/gradle-licenses-plugin/)
[![gradlePluginPortal](https://img.shields.io/maven-metadata/v/https/plugins.gradle.org/m2/com/cmgapps/licenses/com.cmgapps.licenses.gradle.plugin/maven-metadata.xml.svg?label=Gradle%20Plugin%20Portal&style=for-the-badge&logo=Gradle)](https://plugins.gradle.org/plugin/com.cmgapps.licenses)

This Gradle plugin provides tasks to generate a file with the licenses used from the project's dependencies.

Expand All @@ -12,46 +13,56 @@ Using the plugins DSL

```groovy
plugins {
id "com.cmgapps.licenses" version "3.3.0"
id "com.cmgapps.licenses" version "4.0.0"
}
```

Using legacy plugin application
Using legacy plugin application

```groovy
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("com.cmgapps:gradle-licenses-plugin:3.3.0")
classpath("com.cmgapps:gradle-licenses-plugin:4.0.0")
}
}
apply(plugin: "com.cmgapps.licenses")
```

### Tasks

Applying the plugin will create tasks to generate the license report

For `"java"` and `"java-library"`
* `licenseReport`

* `licenseReport`

For `"com.android.application"`, `"com.android.library"`, `"com.android.feature"` and `"com.android.dynamic-feature"`

* `license<variant>Report`

For `"org.jetbrains.kotlin.multiplatform"`

* `licenseMultiplatformReport` collects licenses from all targets
* `licenseMultiplatform<target>Report` collects licenses from `common` and the specified `<target>`

### Configuration

#### Output Format

Example:
```groovy

```kotlin
licenses {
reports {
html.enabled.set(false) // html is enabled by default
html.enabled = false // html is enabled by default
xml {
enabled.set(true)
destination.set(file("$buildDir/reports/licenses.xml"))
enabled = true
destination = file("$buildDir/reports/licenses.xml")
}
}
}
Expand All @@ -60,27 +71,35 @@ licenses {
The plugin can output different formats.

* `HTML`
generates a formatted HTML website
generates a formatted HTML website
* Styling

For an HTML report you can define custom stylesheet using a [TextResource]:
```groovy
For an HTML report you can define custom stylesheet using a `File` or `String`:
```kotlin
licenses {
reports {
html.stylesheet = resources.text.fromString("body {background: #FAFAFA}")
html.stylesheet("body {background: #FAFAFA}")
}
}
```
or
```kotlin
licenses {
reports {
html.stylesheet(file("$projectDir/styles/licenses.css"))
}
}
```
* `JSON`
generates a Json file
generates a Json file
* `XML`
generates a valid XML version 1.0 file
generates a valid XML version 1.0 file
* `Text`
generates a plain text report file
generates a plain text report file
* `Mardown`
generates a Markdown file
generates a Markdown file
* `Custom`
add your own reporter as a lambda function
add your own reporter as a lambda function
```groovy
licenses {
custom {
Expand Down
18 changes: 11 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import com.cmgapps.gradle.logResults
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.util.Date
Expand Down Expand Up @@ -187,6 +188,10 @@ changelog {
version.set(versionName)
}

jacoco {
toolVersion = Deps.jacocoAgentVersion
}

tasks {
val setupJacocoRuntime by registering(WriteProperties::class) {
outputFile =
Expand Down Expand Up @@ -216,10 +221,6 @@ tasks {
dependsOn(functionalTest, ktlint)
}

jacoco {
toolVersion = Deps.jacocoAgentVersion
}

val jacocoExecData = fileTree("$buildDir/jacoco").include("*.exec")

jacocoTestReport {
Expand All @@ -228,6 +229,7 @@ tasks {
}

jacocoTestCoverageVerification {
inputs.dir(buildDir.resolve("jacoco"))
executionData(jacocoExecData)
violationRules {
rule {
Expand All @@ -245,6 +247,8 @@ tasks {
mapOf(
"Implementation-Title" to pomName,
"Implementation-Version" to versionName,
"Implementation-Vendor" to "CMG Mobile Apps",
"Created-By" to """${System.getProperty("java.version")} (${System.getProperty("java.vendor")})""",
"Built-By" to System.getProperty("user.name"),
"Built-Date" to Date(),
"Built-JDK" to System.getProperty("java.version"),
Expand All @@ -267,9 +271,7 @@ tasks {

withType<Test> {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
}
afterTest(KotlinClosure2(logger::logResults))
}

withType<KotlinCompile> {
Expand Down Expand Up @@ -315,6 +317,7 @@ tasks {

dependencies {
compileOnly(Deps.androidGradlePlugin)
compileOnly(Deps.kotlinMultiplatformPlugin)

val kotlinReflect = kotlin("reflect", Deps.kotlinVersion)
// Necessary to bump a transitive dependency.
Expand All @@ -336,6 +339,7 @@ dependencies {
testImplementation(Deps.mockitoKotlin)

"functionalTestImplementation"(Deps.androidGradlePlugin)
"functionalTestImplementation"(Deps.kotlinMultiplatformPlugin)
"functionalTestImplementation"(gradleTestKit())
"functionalTestImplementation"(kotlinReflect)

Expand Down
6 changes: 6 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ plugins {
`kotlin-dsl`
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
freeCompilerArgs = freeCompilerArgs + "-Xopt-in=kotlin.RequiresOptIn"
}
}

repositories {
mavenCentral()
}
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/Deps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ object Deps {
}

const val androidGradlePlugin = "com.android.tools.build:gradle:7.0.2"
const val kotlinMultiplatformPlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
const val apacheCommonsCsv = "org.apache.commons:commons-csv:1.9.0"
const val mavenModel = "org.apache.maven:maven-model:3.8.3"
const val jUnit = "org.junit.jupiter:junit-jupiter:5.8.1"
Expand Down
71 changes: 71 additions & 0 deletions buildSrc/src/main/kotlin/com/cmgapps/gradle/TestResultMapper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2021. Christian Grach <christian.grach@cmgapps.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.cmgapps.gradle

import org.gradle.api.logging.Logger
import org.gradle.api.tasks.testing.TestDescriptor
import org.gradle.api.tasks.testing.TestResult
import org.gradle.api.tasks.testing.TestResult.ResultType

const val CSI = "\u001B["
const val ANSI_RED = "31"
const val ANSI_GREEN = "32"
const val ANSI_YELLOW = "33"
const val ANSI_BOLD = "1"

fun Logger.logResults(desc: TestDescriptor, result: TestResult) {
val message = "{} > {} {}" + if (result.exception != null) "\n>\t{}\n" else "\n"

@OptIn(ExperimentalStdlibApi::class)
val params = buildList<String> {
add(desc.className?.substringAfterLast('.') ?: "")
add(desc.displayName)
add(getFormattedResult(result))
result.exception?.let {
add(it.message?.replace("\n", "\n>\t") ?: "")
}
}.toTypedArray()

if (result.resultType == ResultType.FAILURE) {
this.error(message, *params)
} else {
this.lifecycle(message, *params)
}
}

private fun getFormattedResult(result: TestResult): String {
return buildString {
val isAnsiColorTerm = System.getenv("TERM")?.toLowerCase()?.contains("color") ?: false
val (color, text) = when (result.resultType) {
ResultType.SUCCESS -> ANSI_GREEN to "PASSED"
ResultType.FAILURE -> ANSI_RED to "FAILED"
ResultType.SKIPPED -> ANSI_YELLOW to "SKIPPED"
null -> ANSI_YELLOW to "NO RESULT"
}
if (isAnsiColorTerm) {
append(CSI)
append(color)
append(";${ANSI_BOLD}m")
}
append(text)

if (isAnsiColorTerm) {
append(CSI)
append("0m")
}
}
}
9 changes: 5 additions & 4 deletions example/groovy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ repositories {
licenses {
reports {
csv {
enabled.set(true)
destination.set(layout.buildDirectory.file("html-report/customdir.html"))
enabled = true
destination = file("$buildDir/csv-report/customdir.csv")
}
json.enabled.set(true)
json.enabled = true

custom {
enabled.set(true)
enabled = true
destination = file("$buildDir/reports/licenses/licenses.txt")
generate { list -> list.collect { it.name }.join(', ') }
}
}
Expand Down
9 changes: 5 additions & 4 deletions example/kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ repositories {
licenses {
reports {
csv {
enabled.set(true)
destination.set(buildDir.resolve("csv-report").resolve("customdir.csv"))
enabled = true
destination = buildDir.resolve("csv-report").resolve("customdir.csv")
}
json.enabled.set(true)
json.enabled = true

custom {
enabled.set(true)
enabled = true
destination = buildDir.resolve("reports").resolve("licenses.txt")
generate { list -> list.map { it.name }.joinToString() }
}
}
Expand Down
Loading

0 comments on commit 806457b

Please sign in to comment.