diff --git a/.editorconfig b/.editorconfig index b17d4ea..d5ebc49 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,3 +7,5 @@ indent_style = space [*.{kt,kts}] indent_size = 4 ij_kotlin_imports_layout = *,java.**,javax.**,kotlin.**,^ +ij_kotlin_allow_trailing_comma = true +ij_kotlin_allow_trailing_comma_on_call_site = true diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index 7d0065f..cc5e65b 100644 --- a/.github/workflows/create_release.yml +++ b/.github/workflows/create_release.yml @@ -21,13 +21,12 @@ jobs: with: tag_name: ${{ github.ref }} body_file: ./RELEASE_NOTES.md - draft: false + publish: true - name: Notify Slack uses: chrimaeon/github-slack-action@v1 with: slack_token: ${{ secrets.SLACK_TOKEN }} channel: ${{ secrets.SLACK_CHANNEL }} - publish: true text: "${{ github.ref_name }} on ${{ github.repository }} released! :raised_hands:" blocks: | [ diff --git a/CHANGELOG.md b/CHANGELOG.md index 2dd248e..d6ebcaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog -## [Unreleased] +## Unreleased + ### Added ### Changed @@ -13,29 +14,30 @@ ### Security -## [4.6.0] -### Added -- Dark Mode for HTML report +## 4.6.1 ### Changed -- Sort libraries by name or maven coordinated on HTML report +- update AGP version +- update maven model library -### Deprecated +## 4.6.0 -### Removed +### Added +- Dark Mode for HTML report -### Fixed +### Changed +- Sort libraries by name or maven coordinated on HTML report -### Security +## 4.5.0 -## [4.5.0] ### Added - Better support for Android Variants ### Changed - Internal handling of the license mappings -## [4.4.0] +## 4.4.0 + ### Added - [SPDX License Identifier](https://spdx.org/licenses/) for various reports @@ -45,42 +47,47 @@ ### Fixed - CSV Reporter reports all licenses not only the first one -## [4.3.0] +## 4.3.0 + ### Changed - add maven coordinates to Library model - `version` is not part of the `mavenCoordinates` in the Library model - Improved Markdown reporter -## [4.2.0] +## 4.2.0 + ### Added - XSD Schema for the XML reporter ### Changed -- XML Schema changed - - `` is now attribute to `` +- - `` is now attribute to `` - `` is now a attribute to `` - `` has an `id` attribute now ### Fixed - HTML Reports includes all libraries again -## [4.1.0] +## 4.1.0 + ### Changed - Sort dependencies by name and version -## [4.0.0] +## 4.0.0 + ### Added - Kotlin Multiplatform support ### Changed - Extension property to set `enabled` and `destination` -## [3.3.0] +## 3.3.0 + ### Changed - Update Android Gradle plugin to version 7+ - Warning when license has no mapping for html reports -## [3.2.0] +## 3.2.0 + ### Added - set task outputs to report files - add DSL to configure reports @@ -88,7 +95,8 @@ ### Changed - use library to create CSV report -## [3.1.0] +## 3.1.0 + ### Changed - All public properties are now provided Properties - Use Kotlin Serialization instead of Moshi diff --git a/README.md b/README.md index 36d3916..c3732e8 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.6.0" + id("com.cmgapps.licenses") version "4.6.1" } ``` @@ -28,7 +28,7 @@ plugins { ```groovy plugins { - id 'com.cmgapps.licenses' version '4.6.0' + id 'com.cmgapps.licenses' version '4.6.1' } ``` @@ -46,7 +46,7 @@ buildscript { } } dependencies { - classpath("com.cmgapps:gradle-licenses-plugin:4.6.0") + classpath("com.cmgapps:gradle-licenses-plugin:4.6.1") } } @@ -65,7 +65,7 @@ buildscript { } } dependencies { - classpath 'com.cmgapps:gradle-licenses-plugin:4.6.0' + classpath 'com.cmgapps:gradle-licenses-plugin:4.6.1' } } diff --git a/build.gradle.kts b/build.gradle.kts index 28d7797..a2494b9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,10 @@ import com.cmgapps.gradle.logResults import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask import com.github.benmanes.gradle.versions.updates.gradle.GradleReleaseChannel -import kotlinx.kover.api.VerificationValueType.COVERED_LINES_PERCENTAGE +import kotlinx.kover.api.CounterType +import kotlinx.kover.api.DefaultJacocoEngine +import kotlinx.kover.api.KoverTaskExtension +import kotlinx.kover.api.VerificationValueType.COVERED_PERCENTAGE import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import java.util.Date import java.util.Properties @@ -17,12 +20,19 @@ plugins { `java-gradle-plugin` `maven-publish` signing + @Suppress("DSL_SCOPE_VIOLATION") alias(libs.plugins.kotlin.jvm) + @Suppress("DSL_SCOPE_VIOLATION") alias(libs.plugins.kotlin.serialization) + @Suppress("DSL_SCOPE_VIOLATION") alias(libs.plugins.versions) + @Suppress("DSL_SCOPE_VIOLATION") alias(libs.plugins.gradle.pluginPublish) + @Suppress("DSL_SCOPE_VIOLATION") alias(libs.plugins.jetbrains.dokka) + @Suppress("DSL_SCOPE_VIOLATION") alias(libs.plugins.jetbrains.changelog) + @Suppress("DSL_SCOPE_VIOLATION") alias(libs.plugins.kotlinx.kover) } @@ -46,6 +56,7 @@ idea { } java { + withSourcesJar() sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 } @@ -85,11 +96,6 @@ gradlePlugin { testSourceSets(functionalTestSourceSet) } -val sourcesJar by tasks.registering(Jar::class) { - archiveClassifier.set("sources") - from(sourceSets.main.get().allSource) -} - val javadocJar by tasks.registering(Jar::class) { archiveClassifier.set("javadoc") from(tasks.dokkaJavadoc) @@ -98,10 +104,6 @@ val javadocJar by tasks.registering(Jar::class) { publishing { publications { register("pluginMaven") { - // component registered by gradle-plugin plugin - artifact(sourcesJar.get()) - artifact(javadocJar.get()) - val pomArtifactId: String by pomProperties artifactId = pomArtifactId @@ -148,7 +150,9 @@ publishing { val credentials = Properties().apply { val credFile = projectDir.resolve("credentials.properties") if (credFile.exists()) { - load(credFile.inputStream()) + credFile.inputStream().use { + load(it) + } } } credentials { @@ -165,10 +169,21 @@ signing { changelog { version.set(versionName) + header.set(provider { version.get() }) } kover { - coverageEngine.set(kotlinx.kover.api.CoverageEngine.JACOCO) + engine.set(DefaultJacocoEngine) + verify { + rule { + name = "Minimal Line coverage" + bound { + minValue = 80 + counter = CounterType.LINE + valueType = COVERED_PERCENTAGE + } + } + } } tasks { @@ -176,6 +191,10 @@ tasks { group = "verification" testClassesDirs = functionalTestSourceSet.output.classesDirs classpath = functionalTestSourceSet.runtimeClasspath + + extensions.configure(KoverTaskExtension::class) { + isDisabled.set(true) + } } register("ktlintFormat") { @@ -217,8 +236,8 @@ tasks { "Built-Date" to Date(), "Built-JDK" to System.getProperty("java.version"), "Built-Gradle" to gradle.gradleVersion, - "Built-Kotlin" to libs.versions.kotlin - ) + "Built-Kotlin" to libs.versions.kotlin, + ), ) } } @@ -253,7 +272,7 @@ tasks { wrapper { distributionType = Wrapper.DistributionType.ALL - gradleVersion = "7.4.2" + gradleVersion = libs.versions.gradle.get() } val updateReadme by registering { @@ -280,16 +299,6 @@ tasks { patchChangelog { dependsOn(updateReadme) } - - koverVerify { - rule { - name = "Minimal Line coverage" - bound { - minValue = 80 - valueType = COVERED_LINES_PERCENTAGE - } - } - } } @Suppress("UnstableApiUsage") @@ -313,6 +322,7 @@ dependencies { testImplementation(libs.hamcrest) testImplementation(libs.kotlin.reflect) testImplementation(libs.mockito.kotlin) + testImplementation(libs.android.gradlePlugin) "functionalTestImplementation"(libs.jUnit) { exclude(group = "org.hamcrest") diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 1920514..6c79470 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,28 +1,29 @@ [versions] -kotlin = "1.7.0" +kotlin = "1.7.21" xmlunit = "2.9.0" +gradle = "7.5.1" [plugins] kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } -versions = "com.github.ben-manes.versions:0.42.0" -gradle-pluginPublish = "com.gradle.plugin-publish:0.21.0" -kotlinx-kover = "org.jetbrains.kotlinx.kover:0.5.1" -jetbrains-dokka = "org.jetbrains.dokka:1.6.21" -jetbrains-changelog = "org.jetbrains.changelog:1.3.1" +versions = "com.github.ben-manes.versions:0.43.0" +gradle-pluginPublish = "com.gradle.plugin-publish:1.1.0" +kotlinx-kover = "org.jetbrains.kotlinx.kover:0.6.1" +jetbrains-dokka = "org.jetbrains.dokka:1.7.20" +jetbrains-changelog = "org.jetbrains.changelog:2.0.0" [libraries] -android-gradlePlugin = "com.android.tools.build:gradle:7.2.1" +android-gradlePlugin = "com.android.tools.build:gradle:7.3.1" kotlin-multiplatformPlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } -kotlin-serialization = "org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.3" +kotlin-serialization = "org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1" kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" } kotlin-stdlib-jdk8 = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "kotlin" } apache-commonsCsv = "org.apache.commons:commons-csv:1.9.0" -maven-model = "org.apache.maven:maven-model:3.8.5" +maven-model = "org.apache.maven:maven-model:3.8.6" maven-artifact = "org.apache.maven:maven-artifact:3.8.6" -jUnit = "org.junit.jupiter:junit-jupiter:5.8.2" +jUnit = "org.junit.jupiter:junit-jupiter:5.9.1" hamcrest = "org.hamcrest:hamcrest:2.2" -ktlint = "com.pinterest:ktlint:0.45.2" +ktlint = "com.pinterest:ktlint:0.47.1" mockito-kotlin = "org.mockito.kotlin:mockito-kotlin:4.0.0" xmlunit-core = { module = "org.xmlunit:xmlunit-core", version.ref = "xmlunit" } xmlunit-matchers = { module = "org.xmlunit:xmlunit-matchers", version.ref = "xmlunit" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 92f06b5..8fad3f5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/pom.properties b/pom.properties index 9a04d28..f28aa0b 100644 --- a/pom.properties +++ b/pom.properties @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 # group=com.cmgapps -versionName=4.6.0 +versionName=4.6.1 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/LicensePluginAndroidShould.kt b/src/functionalTest/kotlin/com/cmgapps/license/LicensePluginAndroidShould.kt index 948b49e..e48e134 100644 --- a/src/functionalTest/kotlin/com/cmgapps/license/LicensePluginAndroidShould.kt +++ b/src/functionalTest/kotlin/com/cmgapps/license/LicensePluginAndroidShould.kt @@ -44,7 +44,7 @@ class LicensePluginAndroidShould { fun setUp() { val pluginClasspathResource = javaClass.classLoader.getResourceAsStream("plugin-under-test-metadata.properties") ?: throw IllegalStateException( - "Did not find plugin classpath resource, run `:pluginUnderTestMetadata` task." + "Did not find plugin classpath resource, run `:pluginUnderTestMetadata` task.", ) pluginClasspath = Properties().run { load(pluginClasspathResource) @@ -101,7 +101,7 @@ class LicensePluginAndroidShould { applicationId 'com.example' } } - """.trimIndent() + """.trimIndent(), ) val result = gradleRunner.withArguments(":$taskName").build() @@ -198,8 +198,8 @@ class LicensePluginAndroidShould { assertThat( File("$reportFolder/licenseDebugReport/licenses.txt").readText().trim(), `is`( - "Licenses\n" + "├─ Fake dependency name:1.0.0\n" + "│ ├─ License: Some license\n" + "│ └─ URL: http://website.tld/\n" + "└─ group:noname:1.0.0\n" + " ├─ License: Some license\n" + " └─ URL: http://website.tld/" - ) + "Licenses\n" + "├─ Fake dependency name:1.0.0\n" + "│ ├─ License: Some license\n" + "│ └─ URL: http://website.tld/\n" + "└─ group:noname:1.0.0\n" + " ├─ License: Some license\n" + " └─ URL: http://website.tld/", + ), ) } @@ -223,7 +223,7 @@ class LicensePluginAndroidShould { android { compileSdkVersion 28 } - """.trimIndent() + """.trimIndent(), ) val taskName = ":licenseDebugReport" @@ -252,7 +252,7 @@ class LicensePluginAndroidShould { android { compileSdkVersion 28 } - """.trimIndent() + """.trimIndent(), ) val taskName = ":licenseDebugReport" diff --git a/src/functionalTest/kotlin/com/cmgapps/license/LicensePluginJavaMultiProjectShould.kt b/src/functionalTest/kotlin/com/cmgapps/license/LicensePluginJavaMultiProjectShould.kt index 0bc0e4e..7eaaafc 100644 --- a/src/functionalTest/kotlin/com/cmgapps/license/LicensePluginJavaMultiProjectShould.kt +++ b/src/functionalTest/kotlin/com/cmgapps/license/LicensePluginJavaMultiProjectShould.kt @@ -36,13 +36,14 @@ class LicensePluginJavaMultiProjectShould { private lateinit var module1File: File private lateinit var module2File: File + private lateinit var module3File: File private lateinit var mavenRepoUrl: String private lateinit var gradleRunner: GradleRunner @BeforeEach fun setUp() { Files.createFile(Paths.get(testProjectDir.toString(), "settings.gradle")) - .toFile() + "include ':module1', ':module2'" + .toFile() + "include ':module1', ':module2', ':modules:submodule'" module1File = Paths.get(testProjectDir.toString(), "module1").toFile().run { mkdirs() Files.createFile(Paths.get(this.absolutePath, "build.gradle")).toFile() @@ -53,8 +54,13 @@ class LicensePluginJavaMultiProjectShould { Files.createFile(Paths.get(this.absolutePath, "build.gradle")).toFile() } + module3File = Paths.get(testProjectDir.toString(), "modules").resolve("submodule").toFile().run { + mkdirs() + Files.createFile(Paths.get(this.absolutePath, "build.gradle")).toFile() + } + mavenRepoUrl = - javaClass.getResource("/maven")?.toURI()?.toString() ?: error("""resource folder "\maven" not found!""") + javaClass.getResource("/maven")?.toURI()?.toString() ?: error("""resource folder "/maven" not found!""") gradleRunner = GradleRunner.create() .withProjectDir(testProjectDir.toFile()) .withArguments(":module1:licenseReport") @@ -72,7 +78,7 @@ class LicensePluginJavaMultiProjectShould { maven { url '$mavenRepoUrl' } } licenses { - additionalProjects ':module2' + additionalProjects ':module2', ':modules:submodule' reports { html.enabled = true } @@ -91,6 +97,18 @@ class LicensePluginJavaMultiProjectShould { } """.trimIndent() + module3File + """ + plugins { + id("java-library") + } + repositories { + maven { url '$mavenRepoUrl' } + } + dependencies { + implementation 'com.squareup.retrofit2:retrofit:2.3.0' + } + """.trimIndent() + gradleRunner.build() assertThat( @@ -112,9 +130,12 @@ class LicensePluginJavaMultiProjectShould { "" + "

Notice for packages:

" + "
  • Fake dependency name
" + + "
  • Retrofit
" +
+                    getFileContent("apache-2.0.txt") +
+                    "
" + "" + - "" - ) + "", + ), ) } @@ -176,8 +197,8 @@ class LicensePluginJavaMultiProjectShould { getFileContent("apache-2.0.txt") + "" + "" + - "" - ) + "", + ), ) } @@ -236,8 +257,8 @@ class LicensePluginJavaMultiProjectShould { "

Notice for packages:

" + "
  • Fake dependency name
" + "" + - "" - ) + "", + ), ) } } diff --git a/src/functionalTest/kotlin/com/cmgapps/license/LicensePluginJavaShould.kt b/src/functionalTest/kotlin/com/cmgapps/license/LicensePluginJavaShould.kt index 37b9121..e8553d6 100644 --- a/src/functionalTest/kotlin/com/cmgapps/license/LicensePluginJavaShould.kt +++ b/src/functionalTest/kotlin/com/cmgapps/license/LicensePluginJavaShould.kt @@ -60,7 +60,7 @@ class LicensePluginJavaShould { } @ParameterizedTest(name = "${ParameterizedTest.DISPLAY_NAME_PLACEHOLDER} - Gradle Version = {0}") - @ValueSource(strings = ["6.8", "6.9", "7.0", "7.1", "7.2", "7.3", "7.4"]) + @ValueSource(strings = ["6.8", "6.9", "7.0", "7.1", "7.2", "7.3", "7.4", "7.5"]) fun `apply Licenses plugin to various Gradle versions`(version: String) { val result = gradleRunner .withGradleVersion(version) @@ -93,7 +93,7 @@ class LicensePluginJavaShould { assertThat( result.output, - matchesPattern(Pattern.compile(".*Wrote HTML report to .*$reportFolder/licenses.html.*", Pattern.DOTALL)) + matchesPattern(Pattern.compile(".*Wrote HTML report to .*$reportFolder/licenses.html.*", Pattern.DOTALL)), ) assertThat( File("$reportFolder/licenses.html").readText().trim(), @@ -113,8 +113,8 @@ class LicensePluginJavaShould { "" + "

Notice for packages:

" + "" + - "" - ) + "", + ), ) } @@ -135,7 +135,7 @@ class LicensePluginJavaShould { assertThat( result.output, - matchesPattern(Pattern.compile(".*Wrote HTML report to .*$reportFolder/licenses.html.*", Pattern.DOTALL)) + matchesPattern(Pattern.compile(".*Wrote HTML report to .*$reportFolder/licenses.html.*", Pattern.DOTALL)), ) assertThat( File("$reportFolder/licenses.html").readText().trim(), @@ -161,8 +161,8 @@ class LicensePluginJavaShould { getFileContent("apache-2.0.txt") + "" + "" + - "" - ) + "", + ), ) } @@ -184,7 +184,7 @@ class LicensePluginJavaShould { assertThat( result.output, - matchesPattern(Pattern.compile(".*Wrote HTML report to .*$reportFolder/licenses.html.*", Pattern.DOTALL)) + matchesPattern(Pattern.compile(".*Wrote HTML report to .*$reportFolder/licenses.html.*", Pattern.DOTALL)), ) assertThat( File("$reportFolder/licenses.html").readText().trim(), @@ -211,8 +211,8 @@ class LicensePluginJavaShould { "http://website.tld/" + "" + "" + - "" - ) + "", + ), ) } @@ -234,7 +234,7 @@ class LicensePluginJavaShould { assertThat( result.output, - matchesPattern(Pattern.compile(".*Wrote HTML report to .*$reportFolder/licenses.html.*", Pattern.DOTALL)) + matchesPattern(Pattern.compile(".*Wrote HTML report to .*$reportFolder/licenses.html.*", Pattern.DOTALL)), ) assertThat( File("$reportFolder/licenses.html").readText().trim(), @@ -261,8 +261,8 @@ class LicensePluginJavaShould { "http://website.tld/" + "" + "" + - "" - ) + "", + ), ) } @@ -285,7 +285,7 @@ class LicensePluginJavaShould { assertThat( result.output, - matchesPattern(Pattern.compile(".*Wrote HTML report to .*$reportFolder/licenses.html.*", Pattern.DOTALL)) + matchesPattern(Pattern.compile(".*Wrote HTML report to .*$reportFolder/licenses.html.*", Pattern.DOTALL)), ) assertThat( File("$reportFolder/licenses.html").readText().trim(), @@ -307,8 +307,8 @@ class LicensePluginJavaShould { "http://website.tld/" + "" + "" + - "" - ) + "", + ), ) } @@ -330,7 +330,7 @@ class LicensePluginJavaShould { assertThat( result.output, - matchesPattern(Pattern.compile(".*Wrote TEXT report to .*$reportFolder/licenses.txt.*", Pattern.DOTALL)) + matchesPattern(Pattern.compile(".*Wrote TEXT report to .*$reportFolder/licenses.txt.*", Pattern.DOTALL)), ) assertThat( File("$reportFolder/licenses.txt").readText().trim(), @@ -338,8 +338,8 @@ class LicensePluginJavaShould { "Licenses\n" + "└─ group:noname:1.0.0\n" + " ├─ License: Some license\n" + - " └─ URL: http://website.tld/" - ) + " └─ URL: http://website.tld/", + ), ) } @@ -363,7 +363,7 @@ class LicensePluginJavaShould { assertThat( result.output, - matchesPattern(Pattern.compile(".*Wrote HTML report to .*$reportFolder/licenses.html.*", Pattern.DOTALL)) + matchesPattern(Pattern.compile(".*Wrote HTML report to .*$reportFolder/licenses.html.*", Pattern.DOTALL)), ) assertThat( File("$reportFolder/licenses.html").readText().trim(), @@ -383,8 +383,8 @@ class LicensePluginJavaShould { "http://website.tld/" + "" + "" + - "" - ) + "", + ), ) } @@ -407,7 +407,7 @@ class LicensePluginJavaShould { assertThat( result.output, - matchesPattern(Pattern.compile(".*Wrote CUSTOM report to .*$reportFolder/licenses.*", Pattern.DOTALL)) + matchesPattern(Pattern.compile(".*Wrote CUSTOM report to .*$reportFolder/licenses.*", Pattern.DOTALL)), ) assertThat(File("$reportFolder/licenses").readText().trim(), `is`("Fake dependency name")) } diff --git a/src/functionalTest/kotlin/com/cmgapps/license/LicensePluginMultiplatformShould.kt b/src/functionalTest/kotlin/com/cmgapps/license/LicensePluginMultiplatformShould.kt index 8897e38..0aa19b9 100644 --- a/src/functionalTest/kotlin/com/cmgapps/license/LicensePluginMultiplatformShould.kt +++ b/src/functionalTest/kotlin/com/cmgapps/license/LicensePluginMultiplatformShould.kt @@ -48,7 +48,7 @@ class LicensePluginMultiplatformShould { fun setUp() { val pluginClasspathResource = javaClass.classLoader.getResourceAsStream("plugin-under-test-metadata.properties") ?: throw IllegalStateException( - "Did not find plugin classpath resource, run `:pluginUnderTestMetadata` task." + "Did not find plugin classpath resource, run `:pluginUnderTestMetadata` task.", ) val pluginClasspath = Properties().run { load(pluginClasspathResource) @@ -92,7 +92,6 @@ class LicensePluginMultiplatformShould { @Test fun `apply plugin`() { - val taskName = "licenseMultiplatformReport" buildFile + """ @@ -109,7 +108,6 @@ class LicensePluginMultiplatformShould { @Test fun `generate overall licenses as TXT`() { - val taskName = "licenseMultiplatformReport" buildFile + """ @@ -155,8 +153,8 @@ class LicensePluginMultiplatformShould { assertThat( result.output, matchesPattern( - ".*Wrote TEXT report to .*$reportFolder/$taskName/licenses.txt.*".toPattern(Pattern.DOTALL) - ) + ".*Wrote TEXT report to .*$reportFolder/$taskName/licenses.txt.*".toPattern(Pattern.DOTALL), + ), ) assertThat( File("$reportFolder/$taskName/licenses.txt").readText().trim(), @@ -172,14 +170,13 @@ class LicensePluginMultiplatformShould { |│ └─ URL: http://www.apache.org/licenses/LICENSE-2.0.txt |└─ com.google.firebase:firebase-core:10.0.1 | └─ License: Undefined - """.trimMargin() - ) + """.trimMargin(), + ), ) } @Test fun `generate JVM licenses as TXT`() { - val taskName = "licenseMultiplatformJvmReport" buildFile + """ @@ -225,8 +222,8 @@ class LicensePluginMultiplatformShould { assertThat( result.output, matchesPattern( - ".*Wrote TEXT report to .*$reportFolder/$taskName/licenses.txt.*".toPattern(Pattern.DOTALL) - ) + ".*Wrote TEXT report to .*$reportFolder/$taskName/licenses.txt.*".toPattern(Pattern.DOTALL), + ), ) assertThat( File("$reportFolder/$taskName/licenses.txt").readText().trim(), @@ -239,14 +236,13 @@ class LicensePluginMultiplatformShould { |│ └─ URL: http://www.apache.org/licenses/LICENSE-2.0.txt |└─ com.google.firebase:firebase-core:10.0.1 | └─ License: Undefined - """.trimMargin() - ) + """.trimMargin(), + ), ) } @Test fun `generate native ios licenses`() { - val taskName = "licenseMultiplatformIosArm64Report" buildFile + """ @@ -281,8 +277,8 @@ class LicensePluginMultiplatformShould { assertThat( result.output, matchesPattern( - ".*Wrote TEXT report to .*$reportFolder/$taskName/licenses.txt.*".toPattern(Pattern.DOTALL) - ) + ".*Wrote TEXT report to .*$reportFolder/$taskName/licenses.txt.*".toPattern(Pattern.DOTALL), + ), ) assertThat( File("$reportFolder/$taskName/licenses.txt").readText().trim(), @@ -294,14 +290,13 @@ class LicensePluginMultiplatformShould { |│ └─ URL: http://website.tld/ |└─ com.google.firebase:firebase-core:10.0.1 | └─ License: Undefined - """.trimMargin() - ) + """.trimMargin(), + ), ) } @Test fun `generate custom target name`() { - val taskName = "licenseMultiplatformCustomReport" buildFile + """ @@ -336,8 +331,8 @@ class LicensePluginMultiplatformShould { assertThat( result.output, matchesPattern( - ".*Wrote TEXT report to .*$reportFolder/$taskName/licenses.txt.*".toPattern(Pattern.DOTALL) - ) + ".*Wrote TEXT report to .*$reportFolder/$taskName/licenses.txt.*".toPattern(Pattern.DOTALL), + ), ) assertThat( File("$reportFolder/$taskName/licenses.txt").readText().trim(), @@ -349,8 +344,8 @@ class LicensePluginMultiplatformShould { |│ └─ URL: http://website.tld/ |└─ com.google.firebase:firebase-core:10.0.1 | └─ License: Undefined - """.trimMargin() - ) + """.trimMargin(), + ), ) } } diff --git a/src/functionalTest/kotlin/com/cmgapps/license/XmlValidationShould.kt b/src/functionalTest/kotlin/com/cmgapps/license/XmlValidationShould.kt index 23b376b..2c635c5 100644 --- a/src/functionalTest/kotlin/com/cmgapps/license/XmlValidationShould.kt +++ b/src/functionalTest/kotlin/com/cmgapps/license/XmlValidationShould.kt @@ -60,7 +60,7 @@ class XmlValidationShould { assertThat( Input.fromFile("$reportFolder/licenses.xml"), - valid(Input.fromURL(URL("https://www.cmgapps.com/xsd/licenses.xsd"))) + valid(Input.fromURL(URL("https://www.cmgapps.com/xsd/licenses.xsd"))), ) } } diff --git a/src/main/kotlin/com/cmgapps/license/LicensesExtension.kt b/src/main/kotlin/com/cmgapps/license/LicensesExtension.kt index 1f69a7b..7ae728f 100644 --- a/src/main/kotlin/com/cmgapps/license/LicensesExtension.kt +++ b/src/main/kotlin/com/cmgapps/license/LicensesExtension.kt @@ -59,5 +59,5 @@ enum class OutputType { TEXT, MD, CSV, - CUSTOM + CUSTOM, } diff --git a/src/main/kotlin/com/cmgapps/license/LicensesPlugin.kt b/src/main/kotlin/com/cmgapps/license/LicensesPlugin.kt index b8d626c..1294e53 100644 --- a/src/main/kotlin/com/cmgapps/license/LicensesPlugin.kt +++ b/src/main/kotlin/com/cmgapps/license/LicensesPlugin.kt @@ -58,7 +58,7 @@ class LicensesPlugin : Plugin { "com.android.application", "com.android.library", "com.android.feature", - "com.android.dynamic-feature" + "com.android.dynamic-feature", ) @JvmStatic @@ -138,7 +138,7 @@ class LicensesPlugin : Plugin { project.tasks.register( "licenseMultiplatform${target.name.capitalize()}Report", KotlinMultiplatformTask::class.java, - configuration + configuration, ) } @@ -159,7 +159,7 @@ class LicensesPlugin : Plugin { project.tasks.register( "licenseMultiplatformReport", KotlinMultiplatformTask::class.java, - configuration + configuration, ) } diff --git a/src/main/kotlin/com/cmgapps/license/LicensesTask.kt b/src/main/kotlin/com/cmgapps/license/LicensesTask.kt index 532de6b..e837725 100644 --- a/src/main/kotlin/com/cmgapps/license/LicensesTask.kt +++ b/src/main/kotlin/com/cmgapps/license/LicensesTask.kt @@ -103,24 +103,25 @@ abstract class LicensesTask : DefaultTask() { project.configurations.remove(pomConfiguration) } + @OptIn(ExperimentalStdlibApi::class) protected open fun collectDependencies() { - val configurations = mutableSetOf() - - _allProjects.forEach { project -> - project.configurations.findByName("compile")?.let { - configurations.add(project.configurations.getByName(it.name)) - } + buildSet { + getAllProjects().forEach { project -> + project.configurations.findByName("compile")?.let { + add(project.configurations.getByName(it.name)) + } - project.configurations.findByName("api")?.let { - configurations.add(project.configurations.getByName(it.name)) - } + project.configurations.findByName("api")?.let { + add(project.configurations.getByName(it.name)) + } - project.configurations.findByName("implementation")?.let { - configurations.add(project.configurations.getByName(it.name)) + project.configurations.findByName("implementation")?.let { + add(project.configurations.getByName(it.name)) + } } + }.let { + addConfigurations(it) } - - addConfigurations(configurations) } protected fun addConfigurations(configurations: Set) { @@ -129,7 +130,7 @@ abstract class LicensesTask : DefaultTask() { "${dep.group}:${dep.name}:${dep.version}@pom" }.forEach { pom -> pomConfiguration.dependencies.add( - project.dependencies.add(POM_CONFIGURATION, pom) + project.dependencies.add(POM_CONFIGURATION, pom), ) } } @@ -137,7 +138,6 @@ abstract class LicensesTask : DefaultTask() { private fun generateLibraries(): List { return pomConfiguration.resolvedConfiguration.lenientConfiguration.artifacts.map { - val model = getPomModel(it.file) val licenses = model.findLicenses() @@ -153,7 +153,7 @@ abstract class LicensesTask : DefaultTask() { ), model.name, model.findDescription(), - licenses + licenses, ) } .sortedWith(Library.NameComparator()) @@ -198,11 +198,10 @@ abstract class LicensesTask : DefaultTask() { } private fun Parent.getModel(): Model { - val dependency = "$groupId:$artifactId:$version@pom" project.configurations.create(TEMP_POM_CONFIGURATION).dependencies.add( - project.dependencies.add(TEMP_POM_CONFIGURATION, dependency) + project.dependencies.add(TEMP_POM_CONFIGURATION, dependency), ) val pomFile = project.configurations.getByName(TEMP_POM_CONFIGURATION).incoming @@ -221,6 +220,7 @@ abstract class LicensesTask : DefaultTask() { } else { parent.getModel().findVersion() } + else -> null } @@ -253,19 +253,23 @@ abstract class LicensesTask : DefaultTask() { ReportType.CSV -> CsvReport(libraries) ReportType.CUSTOM -> { val customReport = reports.custom.action - if (customReport != null) + if (customReport != null) { CustomReport( libraries, - customReport + customReport, ) - else null + } else { + null + } } + ReportType.HTML -> HtmlReport( libraries, reports.html._stylesheet.orNull, reports.html.useDarkMode.get(), - logger + logger, ) + ReportType.JSON -> JsonReport(libraries) ReportType.MARKDOWN -> MarkdownReport(libraries, logger) ReportType.TEXT -> TextReport(libraries) @@ -282,7 +286,7 @@ abstract class LicensesTask : DefaultTask() { prepare() writeText(report.generate()) logger.lifecycle( - "Wrote ${this@writeFileReport.name.uppercase(Locale.US)} report to ${getClickableFileUrl(this)}." + "Wrote ${this@writeFileReport.name.uppercase(Locale.US)} report to ${getClickableFileUrl(this)}.", ) } } @@ -359,7 +363,7 @@ abstract class LicensesTask : DefaultTask() { markdown, text, xml, - custom + custom, ) private inner class LicenseReportDelegate(private val reportType: ReportType) : @@ -395,44 +399,39 @@ abstract class AndroidLicensesTask : LicensesTask() { @Internal lateinit var productFlavors: List + @OptIn(ExperimentalStdlibApi::class) override fun collectDependencies() { - super.collectDependencies() - val configurations = mutableSetOf() - - getAllProjects().forEach { project -> - project.configurations.find { it.name == "${buildType}Compile" }?.let { - configurations.add(it) - } - - project.configurations.find { it.name == "${buildType}Api" }?.let { - configurations.add(it) - } - - project.configurations.find { it.name == "${buildType}Implementation" }?.let { - configurations.add(it) - } - - productFlavors.forEach { flavor -> - // Works for productFlavors and productFlavors with dimensions - if (variant.capitalize().contains(flavor.capitalize())) { - project.configurations.find { it.name == "${flavor}Compile" }?.let { - configurations.add(it) - } - - project.configurations.find { it.name == "${flavor}Api" }?.let { - configurations.add(it) - } + buildSet { + getAllProjects().forEach { project -> + addAll(addConfiguration(project, buildType)) - project.configurations.find { it.name == "${flavor}Implementation" }?.let { - configurations.add(it) + productFlavors.forEach { flavor -> + // Works for productFlavors and productFlavors with dimensions + if (variant.capitalize().contains(flavor.capitalize())) { + addAll(addConfiguration(project, flavor)) } } } + }.let { + addConfigurations(it) } + } - addConfigurations(configurations) + @OptIn(ExperimentalStdlibApi::class) + private fun addConfiguration(project: Project, type: String) = buildSet { + project.configurations.find { it.name == "${type}Compile" }?.let { + add(it) + } + + project.configurations.find { it.name == "${type}Api" }?.let { + add(it) + } + + project.configurations.find { it.name == "${type}Implementation" }?.let { + add(it) + } } } diff --git a/src/main/kotlin/com/cmgapps/license/helper/LicensesHelper.kt b/src/main/kotlin/com/cmgapps/license/helper/LicensesHelper.kt index aa6f308..c8598d2 100644 --- a/src/main/kotlin/com/cmgapps/license/helper/LicensesHelper.kt +++ b/src/main/kotlin/com/cmgapps/license/helper/LicensesHelper.kt @@ -53,5 +53,5 @@ fun Logger.logLicenseWarning(license: License, libraries: List) = this. |used by ${libraries.joinToString { "'${it.mavenCoordinates}'" }} | |If it is a valid Open Source License, please report to https://github.com/chrimaeon/gradle-licenses-plugin/issues - """.trimMargin() + """.trimMargin(), ) diff --git a/src/main/kotlin/com/cmgapps/license/model/LicenseSerializer.kt b/src/main/kotlin/com/cmgapps/license/model/LicenseSerializer.kt index 9b385a3..98275f6 100644 --- a/src/main/kotlin/com/cmgapps/license/model/LicenseSerializer.kt +++ b/src/main/kotlin/com/cmgapps/license/model/LicenseSerializer.kt @@ -24,7 +24,7 @@ object LicenseSerializer : KSerializer { val surrogate = LicenseSurrogate( spdxLicenseIdentifier = value.id.spdxLicenseIdentifier, name = value.name, - url = value.url + url = value.url, ) encoder.encodeSerializableValue(LicenseSurrogate.serializer(), surrogate) @@ -35,7 +35,7 @@ object LicenseSerializer : KSerializer { return License( id = LicenseId.fromSpdxLicenseIdentifier(surrogate.spdxLicenseIdentifier), name = surrogate.name, - url = surrogate.url + url = surrogate.url, ) } } diff --git a/src/main/kotlin/com/cmgapps/license/model/Models.kt b/src/main/kotlin/com/cmgapps/license/model/Models.kt index 8dea78d..9561851 100644 --- a/src/main/kotlin/com/cmgapps/license/model/Models.kt +++ b/src/main/kotlin/com/cmgapps/license/model/Models.kt @@ -51,7 +51,8 @@ enum class LicenseId(val spdxLicenseIdentifier: String?) { LGPL_3("LGPL-3.0-only"), MIT("MIT"), MPL_2("MPL-2.0"), - UNKNOWN(null); + UNKNOWN(null), + ; companion object { @JvmStatic diff --git a/src/main/kotlin/com/cmgapps/license/reporter/CsvReport.kt b/src/main/kotlin/com/cmgapps/license/reporter/CsvReport.kt index 0a5e82b..4bb886a 100644 --- a/src/main/kotlin/com/cmgapps/license/reporter/CsvReport.kt +++ b/src/main/kotlin/com/cmgapps/license/reporter/CsvReport.kt @@ -24,7 +24,7 @@ internal class CsvReport(libraries: List) : Report(libraries) { library.description, license.id.spdxLicenseIdentifier, license.name, - license.url + license.url, ) } } diff --git a/src/main/kotlin/com/cmgapps/license/reporter/HtmlReport.kt b/src/main/kotlin/com/cmgapps/license/reporter/HtmlReport.kt index 9f202f3..1a1d152 100644 --- a/src/main/kotlin/com/cmgapps/license/reporter/HtmlReport.kt +++ b/src/main/kotlin/com/cmgapps/license/reporter/HtmlReport.kt @@ -18,7 +18,7 @@ internal class HtmlReport( libraries: List, private val css: TextResource?, private val useDarkMode: Boolean, - private val logger: Logger + private val logger: Logger, ) : Report(libraries) { companion object { diff --git a/src/main/kotlin/com/cmgapps/license/reporter/Report.kt b/src/main/kotlin/com/cmgapps/license/reporter/Report.kt index d6f099f..0e0a617 100644 --- a/src/main/kotlin/com/cmgapps/license/reporter/Report.kt +++ b/src/main/kotlin/com/cmgapps/license/reporter/Report.kt @@ -172,5 +172,5 @@ enum class ReportType(val extension: String) { MARKDOWN("md"), TEXT("txt"), XML("xml"), - CUSTOM("") + CUSTOM(""), } diff --git a/src/main/kotlin/com/cmgapps/license/reporter/XmlReport.kt b/src/main/kotlin/com/cmgapps/license/reporter/XmlReport.kt index 08e58a5..04babb8 100644 --- a/src/main/kotlin/com/cmgapps/license/reporter/XmlReport.kt +++ b/src/main/kotlin/com/cmgapps/license/reporter/XmlReport.kt @@ -13,7 +13,7 @@ internal class XmlReport(libraries: List) : R for (library in libraries) { library( id = library.mavenCoordinates.toString(), - version = library.mavenCoordinates.version.toString() + version = library.mavenCoordinates.version.toString(), ) { name { +(library.name ?: library.mavenCoordinates.toString()) diff --git a/src/test/kotlin/com/cmgapps/license/LicensesPluginShould.kt b/src/test/kotlin/com/cmgapps/license/LicensesPluginShould.kt new file mode 100644 index 0000000..52bb1ea --- /dev/null +++ b/src/test/kotlin/com/cmgapps/license/LicensesPluginShould.kt @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2019. Christian Grach + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package com.cmgapps.license + +import org.gradle.api.Project +import org.gradle.testfixtures.ProjectBuilder +import org.hamcrest.MatcherAssert.assertThat +import org.hamcrest.Matchers.`is` +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.io.TempDir +import java.io.File +import java.nio.file.Path + +class LicensesPluginShould { + + @TempDir + lateinit var testProjectDir: Path + + private lateinit var reportFolder: String + private lateinit var project: Project + + @BeforeEach + fun setUp() { + reportFolder = "$testProjectDir/build/reports/licenses/licensesReport" + project = ProjectBuilder.builder() + .withProjectDir(testProjectDir.toFile()) + .build() + val mavenRepoUrl = javaClass.getResource("/maven")!!.toURI().toString() + project.repositories.add( + project.repositories.maven { + it.setUrl(mavenRepoUrl) + }, + ) + } + + @Test + fun `handle java module`() { + project.plugins.apply("java") + project.dependencies.add("implementation", "group:name:1.0.0") + + LicensesPlugin().apply(project) + + val outputfile = File(reportFolder, "licenses.csv") + + project.extensions.configure(LicensesExtension::class.java) { + it.reports { + it.html.enabled = false + it.csv { + it.enabled = true + it.destination = outputfile + } + } + } + + project.tasks.withType(LicensesTask::class.java).getByName("licenseReport").licensesReport() + + assertThat( + outputfile.readText(), + `is`( + "Name,Version,MavenCoordinates,Description,SPDX-License-Identifier,License Name,License Url\r\n" + + "Fake dependency name,1.0.0,group:name:1.0.0,Fake dependency description,,Some license,http://website.tld/\r\n", + ), + ) + } +} diff --git a/src/test/kotlin/com/cmgapps/license/LicensesTaskShould.kt b/src/test/kotlin/com/cmgapps/license/LicensesTaskShould.kt index 9c6abb8..b2fc48a 100644 --- a/src/test/kotlin/com/cmgapps/license/LicensesTaskShould.kt +++ b/src/test/kotlin/com/cmgapps/license/LicensesTaskShould.kt @@ -34,15 +34,17 @@ class LicensesTaskShould { project.repositories.add( project.repositories.maven { it.setUrl(mavenRepoUrl) - } + }, ) + project.plugins.apply("java") + + project.configurations.create("api") project.configurations.create("compile") - project.dependencies.add("compile", "group:name:1.0.0") + project.dependencies.add("implementation", "group:name:1.0.0") } @Test fun `generate HTML Report`() { - val outputFile = File(reportFolder, "licenses.html") val task = project.tasks.create("licensesReport", LicensesTask::class.java) { task -> @@ -72,14 +74,13 @@ class LicensesTaskShould { "http://website.tld/" + "" + "" + - "" - ) + "", + ), ) } @Test fun `generate HTML Report wih custom CSS`() { - val outputFile = File(reportFolder, "licenses.html") val task = project.tasks.create("licensesReport", LicensesTask::class.java) { task -> @@ -110,14 +111,13 @@ class LicensesTaskShould { "http://website.tld/" + "" + "" + - "" - ) + "", + ), ) } @Test fun `generate JSON Report`() { - val outputFile = File(reportFolder, "licenses.json") val task = project.tasks.create("licensesReport", LicensesTask::class.java) { task -> @@ -150,14 +150,13 @@ class LicensesTaskShould { ] } ] - """.trimIndent() - ) + """.trimIndent(), + ), ) } @Test fun `generate XML Report`() { - val outputFile = File(reportFolder, "licenses.xml") val task = project.tasks.create("licensesReport", LicensesTask::class.java) { task -> @@ -191,8 +190,8 @@ class LicensesTaskShould { - """.trimIndent() - ) + """.trimIndent(), + ), ) } @@ -219,8 +218,8 @@ class LicensesTaskShould { http://website.tld/ ``` - """.trimIndent() - ) + """.trimIndent(), + ), ) } @@ -241,8 +240,8 @@ class LicensesTaskShould { "Licenses\n" + "└─ Fake dependency name:1.0.0\n" + " ├─ License: Some license\n" + - " └─ URL: http://website.tld/" - ) + " └─ URL: http://website.tld/", + ), ) } @@ -261,8 +260,8 @@ class LicensesTaskShould { outputFile.readText(), `is`( "Name,Version,MavenCoordinates,Description,SPDX-License-Identifier,License Name,License Url\r\n" + - "Fake dependency name,1.0.0,group:name:1.0.0,Fake dependency description,,Some license,http://website.tld/\r\n" - ) + "Fake dependency name,1.0.0,group:name:1.0.0,Fake dependency description,,Some license,http://website.tld/\r\n", + ), ) } @@ -315,8 +314,8 @@ class LicensesTaskShould { "http://website.tld/" + "" + "" + - "" - ) + "", + ), ) } @@ -348,7 +347,7 @@ class LicensesTaskShould { fun `sort libraries`() { val outputFile = File(reportFolder, "licenses.txt") - project.dependencies.add("compile", "group:another:2.0.0") + project.dependencies.add("api", "group:another:2.0.0") project.dependencies.add("compile", "group:other:1.0.0") val task = project.tasks.create("licensesReport", LicensesTask::class.java) { task -> task.reports { @@ -374,8 +373,93 @@ class LicensesTaskShould { "│ └─ URL: http://website.tld/\n" + "└─ Fake dependency other:1.0.0\n" + " ├─ License: Some license\n" + - " └─ URL: http://website.tld/" - ) + " └─ URL: http://website.tld/", + ), + ) + } + + @Test + fun `handle android project`() { + val outputFile = File(reportFolder, "licenses.txt") + + val task = project.tasks.create("licensesReport", AndroidLicensesTask::class.java) { task -> + task.buildType = "debug" + task.variant = "google" + task.productFlavors = listOf("google", "amazon") + task.reports { + it.html.enabled = false + it.csv { + it.enabled = true + it.destination = outputFile + } + } + } + + task.licensesReport() + + assertThat( + outputFile.readText(), + `is`( + "Name,Version,MavenCoordinates,Description,SPDX-License-Identifier,License Name,License Url\r\n" + + "Fake dependency name,1.0.0,group:name:1.0.0,Fake dependency description,,Some license,http://website.tld/\r\n", + ), + ) + } + + @Test + fun `handle multiplatform project`() { + val outputFile = File(reportFolder, "licenses.csv") + + val task = project.tasks.create("licensesReport", KotlinMultiplatformTask::class.java) { task -> + task.targetNames = listOf("jvm", "js") + task.reports { + it.html.enabled = false + it.csv { + it.enabled = true + it.destination = outputFile + } + } + } + + task.licensesReport() + + assertThat( + outputFile.readText(), + `is`( + "Name,Version,MavenCoordinates,Description,SPDX-License-Identifier,License Name,License Url\r\n" + + "Fake dependency name,1.0.0,group:name:1.0.0,Fake dependency description,,Some license,http://website.tld/\r\n", + ), + ) + } + + @Test + fun `handle parent version`() { + val outputFile = File(reportFolder, "licenses.csv") + + project.dependencies.add( + "implementation", + "group:has-parent:1.0.0", + ) + + val task = project.tasks.create("licensesReport", LicensesTask::class.java) { task -> + task.reports { + it.html.enabled = false + it.csv { + it.enabled = true + it.destination = outputFile + } + } + } + + task.licensesReport() + + assertThat( + outputFile.readText(), + `is`( + "Name,Version,MavenCoordinates,Description,SPDX-License-Identifier,License Name,License Url\r\n" + + "Fake dependency name,1.0.0,group:name:1.0.0,Fake dependency description,,Some license,http://website.tld/\r\n" + + "Has Parent,1.0.0,group:has-parent:1.0.0,,Apache-2.0,Apache 2.0,http://www.apache.org/licenses/LICENSE-2.0.txt\r\n", + ), ) } } diff --git a/src/test/kotlin/com/cmgapps/license/model/LibraryShould.kt b/src/test/kotlin/com/cmgapps/license/model/LibraryShould.kt index 088ee58..367adef 100644 --- a/src/test/kotlin/com/cmgapps/license/model/LibraryShould.kt +++ b/src/test/kotlin/com/cmgapps/license/model/LibraryShould.kt @@ -32,8 +32,8 @@ internal class LibraryShould { MavenCoordinates("lib.group", "my.artifact", ComparableVersion("1.0.0-alpha-4")), name = "Lib name", description = "description", - licenses = listOf(License(LicenseId.UNKNOWN, "License name", "https://domain.com")) - ) + licenses = listOf(License(LicenseId.UNKNOWN, "License name", "https://domain.com")), + ), ) assertThat( jsonString, @@ -53,8 +53,8 @@ internal class LibraryShould { "\"url\":\"https://domain.com\"" + "}" + "]" + - "}" - ) + "}", + ), ) } @@ -79,7 +79,7 @@ internal class LibraryShould { | } | ] |} - """.trimMargin() + """.trimMargin(), ) assertThat( lib, @@ -88,9 +88,9 @@ internal class LibraryShould { MavenCoordinates("lib.group", "my.artifact", ComparableVersion("1.0.0-alpha-4")), name = "Lib name", description = "description", - licenses = listOf(License(LicenseId.UNKNOWN, "License name", "https://domain.com")) - ) - ) + licenses = listOf(License(LicenseId.UNKNOWN, "License name", "https://domain.com")), + ), + ), ) } @@ -100,7 +100,7 @@ internal class LibraryShould { MavenCoordinates("lib.group", "my.artifact", ComparableVersion("1.0.0-alpha-4")), name = "Lib name", description = "description", - licenses = listOf(License(LicenseId.UNKNOWN, "License name", "https://domain.com")) + licenses = listOf(License(LicenseId.UNKNOWN, "License name", "https://domain.com")), ) assertThat(json.decodeFromString(json.encodeToString(lib)), `is`(lib)) } @@ -139,7 +139,7 @@ internal class LibraryShould { MavenCoordinates("groupA", "artifactA", ComparableVersion("1.0")), name = "A", description = "desc", - licenses = emptyList() + licenses = emptyList(), ), Library( MavenCoordinates("groupA", "artifactC", ComparableVersion("2.0")), @@ -151,7 +151,7 @@ internal class LibraryShould { MavenCoordinates("groupA", "artifactB", ComparableVersion("0.3-alpha4")), name = "A", description = null, - licenses = emptyList() + licenses = emptyList(), ), Library( MavenCoordinates("groupC", "artifactA", ComparableVersion("13")), @@ -161,9 +161,9 @@ internal class LibraryShould { License( LicenseId.UNKNOWN, "license", - "http://domain.tld" - ) - ) + "http://domain.tld", + ), + ), ), ).sortedWith(Library.NameComparator()) assertThat( @@ -179,13 +179,13 @@ internal class LibraryShould { MavenCoordinates("groupA", "artifactA", ComparableVersion("1.0")), name = "A", description = "desc", - licenses = emptyList() + licenses = emptyList(), ), Library( MavenCoordinates("groupA", "artifactB", ComparableVersion("0.3-alpha4")), name = "A", description = null, - licenses = emptyList() + licenses = emptyList(), ), Library( MavenCoordinates("groupB", "artifactA", ComparableVersion("1.0")), @@ -201,11 +201,11 @@ internal class LibraryShould { License( LicenseId.UNKNOWN, "license", - "http://domain.tld" - ) - ) + "http://domain.tld", + ), + ), ), - ) + ), ) } @@ -222,7 +222,7 @@ internal class LibraryShould { MavenCoordinates("groupA", "artifactA", ComparableVersion("1.0")), name = "A", description = "desc", - licenses = emptyList() + licenses = emptyList(), ), Library( MavenCoordinates("groupA", "artifactC", ComparableVersion("2.0")), @@ -240,7 +240,7 @@ internal class LibraryShould { MavenCoordinates("groupA", "artifactB", ComparableVersion("0.3-alpha4")), name = "A", description = null, - licenses = emptyList() + licenses = emptyList(), ), Library( MavenCoordinates("groupC", "artifactA", ComparableVersion("13")), @@ -250,9 +250,9 @@ internal class LibraryShould { License( LicenseId.UNKNOWN, "license", - "http://domain.tld" - ) - ) + "http://domain.tld", + ), + ), ), ).sortedWith(Library.MavenCoordinatesComparator()) assertThat( @@ -262,13 +262,13 @@ internal class LibraryShould { MavenCoordinates("groupA", "artifactA", ComparableVersion("1.0")), name = "A", description = "desc", - licenses = emptyList() + licenses = emptyList(), ), Library( MavenCoordinates("groupA", "artifactB", ComparableVersion("0.3-alpha4")), name = "A", description = null, - licenses = emptyList() + licenses = emptyList(), ), Library( MavenCoordinates("groupA", "artifactC", ComparableVersion("3.0.1")), @@ -296,11 +296,11 @@ internal class LibraryShould { License( LicenseId.UNKNOWN, "license", - "http://domain.tld" - ) - ) + "http://domain.tld", + ), + ), ), - ) + ), ) } } diff --git a/src/test/kotlin/com/cmgapps/license/model/LicenseIdShould.kt b/src/test/kotlin/com/cmgapps/license/model/LicenseIdShould.kt index 1c62a09..48951d2 100644 --- a/src/test/kotlin/com/cmgapps/license/model/LicenseIdShould.kt +++ b/src/test/kotlin/com/cmgapps/license/model/LicenseIdShould.kt @@ -46,8 +46,8 @@ class LicenseIdShould { "LGPL-3.0-only", "MIT", "MPL-2.0", - ) - ) + ), + ), ) } @@ -103,8 +103,8 @@ class LicenseIdShould { "lgpl-3.0.txt", "mit.txt", "mpl-2.0.txt", - ) - ) + ), + ), ) } diff --git a/src/test/kotlin/com/cmgapps/license/model/MavenCoordinatesShould.kt b/src/test/kotlin/com/cmgapps/license/model/MavenCoordinatesShould.kt index e78227a..b1a65ba 100644 --- a/src/test/kotlin/com/cmgapps/license/model/MavenCoordinatesShould.kt +++ b/src/test/kotlin/com/cmgapps/license/model/MavenCoordinatesShould.kt @@ -20,9 +20,9 @@ class MavenCoordinatesShould { MavenCoordinates( groupId = "groupId", artifactId = "artifactId", - version = ComparableVersion("1.0.0") + version = ComparableVersion("1.0.0"), ).toString(), - `is`("groupId:artifactId:1.0.0") + `is`("groupId:artifactId:1.0.0"), ) } @@ -32,9 +32,9 @@ class MavenCoordinatesShould { MavenCoordinates( groupId = "groupId", artifactId = "artifactId", - version = ComparableVersion("") + version = ComparableVersion(""), ).toString(), - `is`("groupId:artifactId") + `is`("groupId:artifactId"), ) } @@ -51,8 +51,8 @@ class MavenCoordinatesShould { groupId = "groupId", artifactId = "artifactId", version = ComparableVersion("2.0"), - ) - ) + ), + ), ) } } diff --git a/src/test/kotlin/com/cmgapps/license/reporter/CsvReportShould.kt b/src/test/kotlin/com/cmgapps/license/reporter/CsvReportShould.kt index cc21a10..607d2fa 100644 --- a/src/test/kotlin/com/cmgapps/license/reporter/CsvReportShould.kt +++ b/src/test/kotlin/com/cmgapps/license/reporter/CsvReportShould.kt @@ -27,9 +27,9 @@ class CsvReportShould { "Name,Version,MavenCoordinates,Description,SPDX-License-Identifier,License Name,License Url\r\n" + "Test lib 1,1.0,test.group:test.artifact:1.0,proper description,Apache-2.0,Apache 2.0,https://www.apache.org/licenses/LICENSE-2.0.txt\r\n" + "Test lib 1,1.0,test.group:test.artifact:1.0,proper description,MIT,MIT License,https://opensource.org/licenses/MIT\r\n" + - "Test lib 2,2.3.4,group.test2:artifact:2.3.4,descriptions of lib 2,Apache-2.0,\"The Apache Software License, Version 2.0\",https://www.apache.org/licenses/LICENSE-2.0.txt\r\n" + "Test lib 2,2.3.4,group.test2:artifact:2.3.4,descriptions of lib 2,Apache-2.0,\"The Apache Software License, Version 2.0\",https://www.apache.org/licenses/LICENSE-2.0.txt\r\n", - ) + ), ) } @@ -40,7 +40,8 @@ class CsvReportShould { Library( MavenCoordinates("groupC", "articfactA", ComparableVersion("version with a \n in it")), name = "Name with a , in it", - description = "description with \r in it", listOf(license) + description = "description with \r in it", + listOf(license), ) val result = CsvReport(listOf(library)).generate() @@ -48,8 +49,8 @@ class CsvReportShould { result, `is`( "Name,Version,MavenCoordinates,Description,SPDX-License-Identifier,License Name,License Url\r\n" + - "\"Name with a , in it\",\"version with a \n in it\",\"groupC:articfactA:version with a \n in it\",\"description with \r in it\",,\"License name with a \"\" in it\",just a plain url\r\n" - ) + "\"Name with a , in it\",\"version with a \n in it\",\"groupC:articfactA:version with a \n in it\",\"description with \r in it\",,\"License name with a \"\" in it\",just a plain url\r\n", + ), ) } } diff --git a/src/test/kotlin/com/cmgapps/license/reporter/HtmlReportShould.kt b/src/test/kotlin/com/cmgapps/license/reporter/HtmlReportShould.kt index 0e9fe65..407187e 100644 --- a/src/test/kotlin/com/cmgapps/license/reporter/HtmlReportShould.kt +++ b/src/test/kotlin/com/cmgapps/license/reporter/HtmlReportShould.kt @@ -31,7 +31,7 @@ class HtmlReportShould { testLibraries, null, false, - logger + logger, ).generate() assertThat( @@ -60,8 +60,8 @@ class HtmlReportShould { getFileContent("mit.txt") + "" + "" + - "" - ) + "", + ), ) } @@ -73,7 +73,7 @@ class HtmlReportShould { testLibraries, null, true, - logger + logger, ).generate() assertThat( @@ -107,8 +107,8 @@ class HtmlReportShould { getFileContent("mit.txt") + "" + "" + - "" - ) + "", + ), ) } @@ -123,13 +123,13 @@ class HtmlReportShould { name = "Lib with invalid license", description = null, licenses = listOf( - License(LicenseId.UNKNOWN, name = "foo", url = "https://www.license.foo") + License(LicenseId.UNKNOWN, name = "foo", url = "https://www.license.foo"), ), - ) + ), ), null, false, - logger + logger, ).generate() verify(logger).warn( @@ -138,7 +138,7 @@ class HtmlReportShould { |used by 'test.group:test.artifact:1.0' | |If it is a valid Open Source License, please report to https://github.com/chrimaeon/gradle-licenses-plugin/issues - """.trimMargin() + """.trimMargin(), ) } } diff --git a/src/test/kotlin/com/cmgapps/license/reporter/JsonReportShould.kt b/src/test/kotlin/com/cmgapps/license/reporter/JsonReportShould.kt index df51766..df4144b 100644 --- a/src/test/kotlin/com/cmgapps/license/reporter/JsonReportShould.kt +++ b/src/test/kotlin/com/cmgapps/license/reporter/JsonReportShould.kt @@ -59,8 +59,8 @@ class JsonReportShould { ] } ] - """.trimIndent() - ) + """.trimIndent(), + ), ) } } diff --git a/src/test/kotlin/com/cmgapps/license/reporter/MarkdownReportShould.kt b/src/test/kotlin/com/cmgapps/license/reporter/MarkdownReportShould.kt index 23504b8..ae7b15d 100644 --- a/src/test/kotlin/com/cmgapps/license/reporter/MarkdownReportShould.kt +++ b/src/test/kotlin/com/cmgapps/license/reporter/MarkdownReportShould.kt @@ -45,8 +45,8 @@ class MarkdownReportShould { |${getFileContent("mit.txt")} |``` | - """.trimMargin() - ) + """.trimMargin(), + ), ) } @@ -61,11 +61,11 @@ class MarkdownReportShould { name = "Lib with invalid license", description = null, licenses = listOf( - License(LicenseId.UNKNOWN, name = "foo", url = "http://www.license.foo") + License(LicenseId.UNKNOWN, name = "foo", url = "http://www.license.foo"), ), - ) + ), ), - logger + logger, ).generate() assertThat( result, @@ -79,8 +79,8 @@ class MarkdownReportShould { |http://www.license.foo |``` | - """.trimMargin() - ) + """.trimMargin(), + ), ) } @@ -95,11 +95,11 @@ class MarkdownReportShould { name = "Lib with invalid license", description = null, licenses = listOf( - License(LicenseId.UNKNOWN, name = "foo", url = "http://www.license.foo") + License(LicenseId.UNKNOWN, name = "foo", url = "http://www.license.foo"), ), - ) + ), ), - logger + logger, ).generate() verify(logger).warn( @@ -108,7 +108,7 @@ class MarkdownReportShould { |used by 'test.group:test.artifact:1.0' | |If it is a valid Open Source License, please report to https://github.com/chrimaeon/gradle-licenses-plugin/issues - """.trimMargin() + """.trimMargin(), ) } } diff --git a/src/test/kotlin/com/cmgapps/license/reporter/TextReportShould.kt b/src/test/kotlin/com/cmgapps/license/reporter/TextReportShould.kt index a73b924..82feaaa 100644 --- a/src/test/kotlin/com/cmgapps/license/reporter/TextReportShould.kt +++ b/src/test/kotlin/com/cmgapps/license/reporter/TextReportShould.kt @@ -35,8 +35,8 @@ class TextReportShould { ├─ License: The Apache Software License, Version 2.0 ├─ SPDX-License-Identifier: Apache-2.0 └─ URL: https://www.apache.org/licenses/LICENSE-2.0.txt - """.trimIndent() - ) + """.trimIndent(), + ), ) } @@ -48,15 +48,15 @@ class TextReportShould { MavenCoordinates("test.group", "test.artifact", ComparableVersion("1.0")), "Test lib 1", "proper description", - emptyList() + emptyList(), ), Library( MavenCoordinates("group.test2", "artifact", ComparableVersion("2.3.4")), "Test lib 2", "descriptions of lib 2", - emptyList() - ) - ) + emptyList(), + ), + ), ).generate() assertThat( report, @@ -67,8 +67,8 @@ class TextReportShould { │ └─ License: Undefined └─ Test lib 2:2.3.4 └─ License: Undefined - """.trimIndent() - ) + """.trimIndent(), + ), ) } } diff --git a/src/test/kotlin/com/cmgapps/license/reporter/XmlReportShould.kt b/src/test/kotlin/com/cmgapps/license/reporter/XmlReportShould.kt index 8bb7a8d..3bb46ad 100644 --- a/src/test/kotlin/com/cmgapps/license/reporter/XmlReportShould.kt +++ b/src/test/kotlin/com/cmgapps/license/reporter/XmlReportShould.kt @@ -59,8 +59,8 @@ class XmlReportShould { - """.trimIndent() - ) + """.trimIndent(), + ), ) } } diff --git a/src/test/kotlin/com/cmgapps/license/util/LibrariesHelper.kt b/src/test/kotlin/com/cmgapps/license/util/LibrariesHelper.kt index 87aabac..05174c1 100644 --- a/src/test/kotlin/com/cmgapps/license/util/LibrariesHelper.kt +++ b/src/test/kotlin/com/cmgapps/license/util/LibrariesHelper.kt @@ -42,5 +42,5 @@ internal val testLibraries = listOf( url = "https://www.apache.org/licenses/LICENSE-2.0.txt", ), ), - ) + ), ) diff --git a/src/test/resources/maven/group/has-parent/1.0.0/has-parent-1.0.0.pom b/src/test/resources/maven/group/has-parent/1.0.0/has-parent-1.0.0.pom new file mode 100644 index 0000000..a887aaf --- /dev/null +++ b/src/test/resources/maven/group/has-parent/1.0.0/has-parent-1.0.0.pom @@ -0,0 +1,15 @@ + + + + 4.0.0 + + + group + parent + 1.0.0 + ../pom.xml + + + has-parent + Has Parent + diff --git a/src/test/resources/maven/group/parent/1.0.0/parent-1.0.0.pom b/src/test/resources/maven/group/parent/1.0.0/parent-1.0.0.pom new file mode 100644 index 0000000..2fe6a37 --- /dev/null +++ b/src/test/resources/maven/group/parent/1.0.0/parent-1.0.0.pom @@ -0,0 +1,27 @@ + + + + 4.0.0 + + group + parent + 1.0.0 + pom + + Group (Parent) + + + has-parent + + + + + Apache 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + + +