From 427282e114b03dd6e8f7df6110cfa9d94f13503f Mon Sep 17 00:00:00 2001 From: Jared Burrows Date: Thu, 11 Feb 2021 16:48:42 -0500 Subject: [PATCH] move to sonatype maven central --- .github/workflows/build.yml | 10 +- README.md | 26 +-- build.gradle | 57 +++++-- gradle.properties | 4 +- gradle/compile.gradle | 43 ----- gradle/dependencies.gradle | 4 +- gradle/publish.gradle | 161 ++++++------------ gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle | 7 +- .../jaredsburrows/license/LicensePlugin.kt | 9 +- .../license/LicenseReportTask.kt | 37 ++-- .../license/internal/report/CsvReport.kt | 21 +-- .../license/internal/report/HtmlReport.kt | 7 +- .../license/internal/report/JsonReport.kt | 2 +- .../license/internal/report/Report.kt | 2 +- .../license/LicensePluginAndroidSpec.groovy | 15 +- .../license/LicensePluginJavaSpec.groovy | 6 +- 17 files changed, 192 insertions(+), 221 deletions(-) delete mode 100644 gradle/compile.gradle diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1456f11f..8cb75b6c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -39,7 +39,7 @@ jobs: java-version: ${{ matrix.java-version }} - name: Run Build - run: ./gradlew clean ktlintCheck build jar docsJar sourcesJar testsJar reportsZip generatePomFileForMavenPublication -s --scan + run: ./gradlew clean ktlintCheck build jar docsJar sourcesJar testsJar reportsZip publishMavenPublicationToMavenLocal -s - name: Upload Artifacts uses: actions/upload-artifact@v2 @@ -74,9 +74,7 @@ jobs: java-version: 1.8 - name: Publish - run: ./gradlew clean artifactoryPublish -s --scan + run: ./gradlew clean publishMavenPublicationToMavenRepository -s env: - BINTRAY_API_KEY: ${{ secrets.BINTRAY_API_KEY }} - BINTRAY_USERNAME: ${{ secrets.BINTRAY_USERNAME }} - GRADLE_KEY: ${{ secrets.GRADLE_KEY }} - GRADLE_SECRET: ${{ secrets.GRADLE_SECRET }} + SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} diff --git a/README.md b/README.md index 84dc360e..8a3a408a 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Also, for Android projects the license HTML file will be copied to `/sr ```groovy buildscript { repositories { - jcenter() + mavenCentral() google() } @@ -30,13 +30,13 @@ buildscript { apply plugin: 'com.android.application' // or 'java-library' apply plugin: 'com.jaredsburrows.license' ``` -Release versions are available in the [JFrog Bintray repository](https://jcenter.bintray.com/com/jaredsburrows/gradle-license-plugin/). +Release versions are available in the [Sonatype's release repository](https://repo1.maven.org/maven2/com/jaredsburrows/gradle-license-plugin/). **Snapshot:** ```groovy buildscript { repositories { - maven { url 'https://oss.jfrog.org/artifactory/oss-snapshot-local/' } + maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } google() } @@ -48,7 +48,7 @@ buildscript { apply plugin: 'com.android.application' // or 'java-library' apply plugin: 'com.jaredsburrows.license' ``` -Snapshot versions are available in the [JFrog Artifactory repository](https://oss.jfrog.org/artifactory/libs-snapshot/com/jaredsburrows/gradle-license-plugin/). +Snapshot versions are available in the [Sonatype's snapshots repository](https://oss.sonatype.org/content/repositories/snapshots/com/jaredsburrows/gradle-license-plugin/). ## Tasks @@ -89,27 +89,27 @@ Design,null,26.1.0,null,null,null,The Apache Software License,http://www.apache.
Copyright © 20xx The original author or authors
- -
No license found
-
+ +
No license found
+

  • Android GIF Drawable Library (1.2.3)
    Copyright © 20xx Karol Wrótniak
  • - -
    mit.txt here
    -
    + +
    mit.txt here
    +

  • Design (26.1.0)
    Copyright © 20xx The original author or authors
  • - -
    apache-2.0.txt here
    -
    + +
    apache-2.0.txt here
    +

    diff --git a/build.gradle b/build.gradle index 8806db34..c86f8be8 100644 --- a/build.gradle +++ b/build.gradle @@ -1,18 +1,17 @@ plugins { - id 'com.jfrog.artifactory' version '4.24.16' - id 'com.jfrog.bintray' version '1.8.5' - id 'com.github.ben-manes.versions' version '0.39.0' - id 'com.gradle.plugin-publish' version '0.15.0' id 'org.jetbrains.kotlin.jvm' version '1.5.30' - id 'org.jetbrains.dokka' version '0.10.1' + id 'org.jetbrains.dokka' version '1.5.0' + id 'com.gradle.plugin-publish' version '0.15.0' id 'org.jlleitschuh.gradle.ktlint' version '10.2.0' - id 'java-gradle-plugin' + id 'com.github.ben-manes.versions' version '0.39.0' id 'groovy' + id 'java-gradle-plugin' id 'maven-publish' + id 'signing' } repositories { - jcenter() + mavenCentral() google() } @@ -50,7 +49,7 @@ task createClasspathManifest() { } } -configurations.all { +configurations.configureEach { resolutionStrategy { eachDependency { details -> if (details.requested.group == 'org.jetbrains.kotlin') { @@ -61,7 +60,6 @@ configurations.all { } dependencies { - implementation localGroovy() implementation deps.kotlin.stdlib.jdk implementation deps.kotlinx.html implementation deps.gson @@ -75,11 +73,48 @@ dependencies { testImplementation deps.commons.csv } -apply from: 'gradle/compile.gradle' apply from: 'gradle/publish.gradle' -tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { +tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { kotlinOptions { jvmTarget = rootProject.versions.java } } + +tasks.withType(JavaCompile).configureEach { + sourceCompatibility = rootProject.versions.java + targetCompatibility = rootProject.versions.java + + // Show all warnings except boot classpath + configure(options) { + compilerArgs << '-Xlint:all' // Turn on all warnings + compilerArgs << '-Werror' // Turn warnings into errors + encoding = 'utf-8' + } +} + +tasks.withType(GroovyCompile).configureEach { + sourceCompatibility = rootProject.versions.java + targetCompatibility = rootProject.versions.java + + // Show all warnings except boot classpath + configure(options) { + compilerArgs << '-Xlint:all' // Turn on all warnings + compilerArgs << '-Werror' // Turn warnings into errors + encoding = 'utf-8' + } +} + +tasks.withType(Test).configureEach { + useJUnitPlatform() + + // Turn on logging for all tests, filter to show failures/skips only + testLogging { + exceptionFormat 'full' + showCauses true + showExceptions true + showStackTraces true + events 'failed', 'skipped' + } +} + diff --git a/gradle.properties b/gradle.properties index 3d3ff230..01be06ef 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,9 +1,10 @@ GROUP=com.jaredsburrows +POM_ARTIFACT_ID=gradle-license-plugin VERSION_NAME=0.8.91-SNAPSHOT POM_NAME=Gradle License Plugin -POM_ARTIFACT_ID=gradle-license-plugin POM_DESCRIPTION=Gradle plugin that provides a task to generate a HTML license report of your project. +POM_INCEPTION_YEAR=2016 POM_PACKAGING=jar POM_URL=https://github.com/jaredsburrows/gradle-license-plugin @@ -22,6 +23,5 @@ POM_DEVELOPER_ID=jaredsburrows POM_DEVELOPER_NAME=Jared Burrows POM_DEVELOPER_EMAIL=jaredsburrows@gmail.com -BINTRAY_GITHUB_REPO=jaredsburrows/gradle-license-plugin PLUGIN_NAME=com.jaredsburrows.license PLUGIN_NAME_CLASS=com.jaredsburrows.license.LicensePlugin diff --git a/gradle/compile.gradle b/gradle/compile.gradle deleted file mode 100644 index e849df6d..00000000 --- a/gradle/compile.gradle +++ /dev/null @@ -1,43 +0,0 @@ -tasks.withType(JavaCompile) { - sourceCompatibility = rootProject.versions.java - targetCompatibility = rootProject.versions.java - - // Show all warnings except boot classpath - configure(options) { - compilerArgs << '-Xlint:all' // Turn on all warnings - compilerArgs << '-Werror' // Turn warnings into errors - encoding = 'utf-8' - } -} - -tasks.withType(GroovyCompile) { - sourceCompatibility = rootProject.versions.java - targetCompatibility = rootProject.versions.java - - // Show all warnings except boot classpath - configure(options) { - compilerArgs << '-Xlint:all' // Turn on all warnings - compilerArgs << '-Werror' // Turn warnings into errors - encoding = 'utf-8' - } -} - -tasks.withType(Test) { - // Turn on logging for all tests, filter to show failures/skips only - testLogging { - exceptionFormat 'full' - showCauses true - showExceptions true - showStackTraces true - events 'failed', 'skipped' - } -} - -tasks.withType(Groovydoc) { - docTitle = '${project.name} ${project.version}' - header = project.name - link('http://docs.oracle.com/javase/8/docs/api/', - 'http://docs.oracle.com/javaee/7/api/', - 'http://groovy.codehaus.org/gapi/') - exclude "**/*Spec.java" -} diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index 1b5d42bf..9b4fe4c6 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -13,7 +13,7 @@ ext.deps = [ ], ], 'kotlinx': [ - 'html': 'org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.2', + 'html': 'org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.3', ], 'gson' : 'com.google.code.gson:gson:2.8.8', 'android': [ @@ -23,7 +23,7 @@ ext.deps = [ ] ] ], - 'spock' : 'org.spockframework:spock-core:1.3-groovy-2.5', + 'spock' : 'org.spockframework:spock-junit4:2.0-groovy-3.0', 'xmlunit': [ 'matchers': 'org.xmlunit:xmlunit-matchers:2.8.2', ], diff --git a/gradle/publish.gradle b/gradle/publish.gradle index 7a142b19..c1ff1c68 100644 --- a/gradle/publish.gradle +++ b/gradle/publish.gradle @@ -1,42 +1,12 @@ -def pomConfig = { - resolveStrategy = Closure.DELEGATE_FIRST - name POM_ARTIFACT_ID - description POM_DESCRIPTION - url POM_URL - - issueManagement { - system POM_ISSUE_SYSTEM - url POM_ISSUE_URL - } - - scm { - url POM_SCM_URL - connection POM_SCM_CONNECTION - developerConnection POM_SCM_DEV_CONNECTION - } - - licenses { - license { - name POM_LICENCE_NAME - url POM_LICENCE_URL - distribution POM_LICENCE_DIST - } - } - - developers { - developer { - id POM_DEVELOPER_ID - name POM_DEVELOPER_NAME - email POM_DEVELOPER_EMAIL - } - } +def isReleaseBuild() { + return !VERSION_NAME.contains('SNAPSHOT') } -task docsJar(type: Jar, dependsOn: dokka) { +task docsJar(type: Jar, dependsOn: dokkaHtml) { group = 'Publications' description = 'Create jar of documentation.' archiveClassifier = 'docs' - from dokka.outputDirectory + from dokkaJavadoc.outputDirectory } task sourcesJar(type: Jar, dependsOn: classes) { @@ -60,10 +30,22 @@ task reportsZip(type: Zip, dependsOn: check) { from reporting.baseDir } -// Local published to ~/.m2 - mavenLocal() publishing { repositories { mavenLocal() + + maven { + credentials { + username project.properties['SONATYPE_USERNAME'] ?: System.getenv('SONATYPE_USERNAME') + password project.properties['SONATYPE_PASSWORD'] ?: System.getenv('SONATYPE_PASSWORD') + } + + if (isReleaseBuild()) { + url 'https://oss.sonatype.org/service/local/staging/deploy/maven2/' + } else { + url 'https://oss.sonatype.org/content/repositories/snapshots/' + } + } } publications { @@ -78,76 +60,48 @@ publishing { artifactId POM_ARTIFACT_ID version VERSION_NAME - pom.withXml { - // Add parent POM information - asNode().children().first() + pomConfig + pom { + name = POM_ARTIFACT_ID + packaging = POM_PACKAGING + description = POM_DESCRIPTION + url = POM_URL + inceptionYear = POM_INCEPTION_YEAR + + licenses { + license { + name = POM_LICENCE_NAME + url = POM_LICENCE_URL + distribution = POM_LICENCE_DIST + } + } + + developers { + developer { + id = POM_DEVELOPER_ID + name = POM_DEVELOPER_NAME + email = POM_DEVELOPER_EMAIL + } + } + + scm { + url = POM_SCM_URL + connection = POM_SCM_CONNECTION + developerConnection = POM_SCM_DEV_CONNECTION + } + + issueManagement { + system = POM_ISSUE_SYSTEM + url = POM_ISSUE_URL + } } } } } -publish.dependsOn jar, docsJar, sourcesJar, testsJar, reportsZip -publish.dependsOn 'generatePomFileForMavenPublication' - -// Snapshots published to JFrog Artifactory repository -artifactory { - contextUrl = 'https://oss.jfrog.org' - - publish { - repository { - repoKey = 'oss-snapshot-local' - username = project.properties['BINTRAY_USERNAME'] ?: System.getenv('BINTRAY_USERNAME') - password = project.properties['BINTRAY_API_KEY'] ?: System.getenv('BINTRAY_API_KEY') - } - - defaults { - publications 'maven' - } - } - resolve { - repository { - repoKey = 'libs-release' - } - } -} -artifactoryPublish.dependsOn jar, docsJar, sourcesJar, testsJar, reportsZip -artifactoryPublish.dependsOn 'generatePomFileForMavenPublication' - -// Publishes to JFrog Bintray's JCenter repository -bintray { - user = project.properties['BINTRAY_USERNAME'] ?: System.getenv('BINTRAY_USERNAME') - key = project.properties['BINTRAY_API_KEY'] ?: System.getenv('BINTRAY_API_KEY') - publications = ['maven'] - publish = true - - pkg { - repo = 'maven' - name = POM_ARTIFACT_ID - desc = POM_DESCRIPTION - websiteUrl = POM_URL - issueTrackerUrl = POM_ISSUE_URL - vcsUrl = POM_URL - labels = ['gradle', 'plugin', 'license'] - githubRepo = BINTRAY_GITHUB_REPO - githubReleaseNotesFile = 'README.md' - - version { - name = VERSION_NAME - desc = POM_DESCRIPTION - released = new Date() - vcsTag = VERSION_NAME - - mavenCentralSync { - sync = false - user = project.properties['SONATYPE_USERNAME'] ?: System.getenv('SONATYPE_USERNAME') - password = project.properties['SONATYPE_PASSWORD'] ?: System.getenv('SONATYPE_PASSWORD') - close = '1' - } - } - } +signing { + required { isReleaseBuild() && gradle.taskGraph.hasTask("release") } + sign publishing.publications.maven } -bintrayUpload.dependsOn jar, docsJar, sourcesJar, testsJar, reportsZip -bintrayUpload.dependsOn 'generatePomFileForMavenPublication' // Publishes to Gradle plugins repository gradlePlugin { @@ -162,7 +116,6 @@ pluginBundle { website = POM_URL vcsUrl = POM_URL description = POM_DESCRIPTION - tags = bintray.pkg.labels plugins { licensePlugin { @@ -170,11 +123,9 @@ pluginBundle { } } } -publishPlugins.dependsOn jar, docsJar, sourcesJar, testsJar, reportsZip -publishPlugins.dependsOn 'generatePomFileForMavenPublication' -// Publish to both Bintray and Gradle repositories -task release(dependsOn: [bintrayUpload, publishPlugins]) { +// Publish to both Maven Central and Gradle repositories +task release(dependsOn: [publishMavenPublicationToMavenRepository, publishPlugins]) { group = 'Publishing' - description = 'Publish to JFrog Jcenter\'s Brintray and Gradle Plugins Repositories.' + description = 'Publish to Maven Central and Gradle Plugins Repositories.' } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4d9ca164..ffed3a25 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-6.7.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle b/settings.gradle index 679552f8..40b4ab5c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,12 +1,13 @@ plugins { - id "com.gradle.enterprise" version "3.4.1" + id "com.gradle.enterprise" version "3.6.4" } -rootProject.name = 'gradle-license-plugin' - gradleEnterprise { buildScan { termsOfServiceUrl = "https://gradle.com/terms-of-service" termsOfServiceAgree = "yes" + publishAlways() } } + +rootProject.name = 'gradle-license-plugin' diff --git a/src/main/kotlin/com/jaredsburrows/license/LicensePlugin.kt b/src/main/kotlin/com/jaredsburrows/license/LicensePlugin.kt index 0ed44580..393ffcf9 100644 --- a/src/main/kotlin/com/jaredsburrows/license/LicensePlugin.kt +++ b/src/main/kotlin/com/jaredsburrows/license/LicensePlugin.kt @@ -14,6 +14,7 @@ import org.gradle.api.Project import org.gradle.api.plugins.ExtensionContainer import org.gradle.api.plugins.JavaPlugin import java.io.File +import java.util.Locale import kotlin.reflect.KClass /** A [Plugin] which grabs the POM.xml files from maven dependencies. */ @@ -73,7 +74,13 @@ class LicensePlugin : Plugin { ) { // Configure tasks for all variants variants?.all { variant -> - val name = variant.name.capitalize() + val name = variant.name.replaceFirstChar { + if (it.isLowerCase()) { + it.titlecase(Locale.getDefault()) + } else { + it.toString() + } + } val taskName = "license${name}Report" val path = "${project.buildDir}/reports/licenses/$taskName".replace('/', File.separatorChar) diff --git a/src/main/kotlin/com/jaredsburrows/license/LicenseReportTask.kt b/src/main/kotlin/com/jaredsburrows/license/LicenseReportTask.kt index 61443970..11418026 100644 --- a/src/main/kotlin/com/jaredsburrows/license/LicenseReportTask.kt +++ b/src/main/kotlin/com/jaredsburrows/license/LicenseReportTask.kt @@ -26,6 +26,7 @@ import org.gradle.api.tasks.TaskAction import java.io.File import java.net.URI import java.net.URL +import java.util.Locale import java.util.UUID /** A [Task] that creates HTML and JSON reports of the current projects dependencies. */ @@ -208,7 +209,7 @@ open class LicenseReportTask : DefaultTask() { // tasks can't be final } // Sort POM information by name - projects.sortBy { it.name.toLowerCase() } + projects.sortBy { it.name.lowercase(Locale.getDefault()) } } /** Setup configurations to collect dependencies. */ @@ -270,7 +271,10 @@ open class LicenseReportTask : DefaultTask() { // tasks can't be final } // Log output directory for user - logger.log(LogLevel.LIFECYCLE, "Wrote CSV report to ${ConsoleRenderer().asClickableFileUrl(csvFile)}.") + logger.log( + LogLevel.LIFECYCLE, + "Wrote CSV report to ${ConsoleRenderer().asClickableFileUrl(csvFile)}." + ) } private fun copyCsvReport() { @@ -291,7 +295,10 @@ open class LicenseReportTask : DefaultTask() { // tasks can't be final } // Log output directory for user - logger.log(LogLevel.LIFECYCLE, "Copied CSV report to ${ConsoleRenderer().asClickableFileUrl(licenseFile)}.") + logger.log( + LogLevel.LIFECYCLE, + "Copied CSV report to ${ConsoleRenderer().asClickableFileUrl(licenseFile)}." + ) } } @@ -311,7 +318,10 @@ open class LicenseReportTask : DefaultTask() { // tasks can't be final } // Log output directory for user - logger.log(LogLevel.LIFECYCLE, "Wrote HTML report to ${ConsoleRenderer().asClickableFileUrl(htmlFile)}.") + logger.log( + LogLevel.LIFECYCLE, + "Wrote HTML report to ${ConsoleRenderer().asClickableFileUrl(htmlFile)}." + ) } private fun copyHtmlReport() { @@ -332,7 +342,10 @@ open class LicenseReportTask : DefaultTask() { // tasks can't be final } // Log output directory for user - logger.log(LogLevel.LIFECYCLE, "Copied HTML report to ${ConsoleRenderer().asClickableFileUrl(licenseFile)}.") + logger.log( + LogLevel.LIFECYCLE, + "Copied HTML report to ${ConsoleRenderer().asClickableFileUrl(licenseFile)}." + ) } } @@ -351,7 +364,10 @@ open class LicenseReportTask : DefaultTask() { // tasks can't be final } // Log output directory for user - logger.log(LogLevel.LIFECYCLE, "Wrote JSON report to ${ConsoleRenderer().asClickableFileUrl(jsonFile)}.") + logger.log( + LogLevel.LIFECYCLE, + "Wrote JSON report to ${ConsoleRenderer().asClickableFileUrl(jsonFile)}." + ) } private fun copyJsonReport() { @@ -372,7 +388,10 @@ open class LicenseReportTask : DefaultTask() { // tasks can't be final } // Log output directory for user - logger.log(LogLevel.LIFECYCLE, "Copied JSON report to ${ConsoleRenderer().asClickableFileUrl(licenseFile)}.") + logger.log( + LogLevel.LIFECYCLE, + "Copied JSON report to ${ConsoleRenderer().asClickableFileUrl(licenseFile)}." + ) } } @@ -448,9 +467,7 @@ open class LicenseReportTask : DefaultTask() { // tasks can't be final } private fun getName(node: Node): String { - return if (node.getAt("name").text().isNotEmpty()) { - node.getAt("name").text() - } else { + return node.getAt("name").text().ifEmpty { node.getAt("artifactId").text() }.trim() } diff --git a/src/main/kotlin/com/jaredsburrows/license/internal/report/CsvReport.kt b/src/main/kotlin/com/jaredsburrows/license/internal/report/CsvReport.kt index 46b2be97..aa29fba7 100644 --- a/src/main/kotlin/com/jaredsburrows/license/internal/report/CsvReport.kt +++ b/src/main/kotlin/com/jaredsburrows/license/internal/report/CsvReport.kt @@ -14,11 +14,11 @@ class CsvReport(private val projects: List) : Report { override fun report(): String = if (projects.isEmpty()) emptyReport() else fullReport() override fun fullReport(): String { - val projectInfoList = arrayListOf() + val projectInfoList = mutableListOf() projectInfoList.add(COLUMNS) projects.map { project -> - val projectInfo = arrayListOf().apply { + val projectInfo = mutableListOf().apply { // Project Name addCsvString(project.name) @@ -58,32 +58,33 @@ class CsvReport(private val projects: List) : Report { override fun emptyReport(): String = EMPTY_CSV /** Convert list of elements to comma separated list. */ - private fun ArrayList.toCsv(): String = this.joinToString(separator = ",") + private fun MutableList.toCsv(): String = this.joinToString(separator = ",") /** Add elements to Csv. */ - private fun ArrayList.addCsvString(element: String): Boolean { + private fun MutableList.addCsvString(element: String): Boolean { return this.add(element.valueOrNull()) } /** Add List of elements to Csv as comma separated list with quotes. */ - private fun ArrayList.addCsvList( + private fun MutableList.addCsvList( elements: List, transform: ((T) -> CharSequence)? = null ): Boolean { return when { elements.isEmpty() -> this.add(null) else -> { - val blah = elements.joinToString(separator = ",", transform = transform) + val element = elements.joinToString(separator = ",", transform = transform) when (elements.size) { - 1 -> this.add(blah) - else -> this.add("\"${blah}\"") + 1 -> this.add(element) + else -> this.add("\"${element}\"") } } } } - companion object { - private const val COLUMNS = "project,description,version,developers,url,year,licenses,license urls,dependency" + private companion object { + private const val COLUMNS = + "project,description,version,developers,url,year,licenses,license urls,dependency" private const val EMPTY_CSV = "" } } diff --git a/src/main/kotlin/com/jaredsburrows/license/internal/report/HtmlReport.kt b/src/main/kotlin/com/jaredsburrows/license/internal/report/HtmlReport.kt index 423c8a9f..1dd59c7e 100644 --- a/src/main/kotlin/com/jaredsburrows/license/internal/report/HtmlReport.kt +++ b/src/main/kotlin/com/jaredsburrows/license/internal/report/HtmlReport.kt @@ -99,7 +99,7 @@ class HtmlReport(private val projects: List) : Report { +project.name +" (${project.version})" } - val copyrightYear = if (project.year.isEmpty()) DEFAULT_YEAR else project.year + val copyrightYear = project.year.ifEmpty { DEFAULT_YEAR } dl { if (project.developers.isNotEmpty()) { project.developers.forEach { developer -> @@ -223,8 +223,9 @@ class HtmlReport(private val projects: List) : Report { consumer ).visit(block) - companion object { - const val CSS_STYLE = "body { font-family: sans-serif } pre { background-color: #eeeeee; padding: 1em; white-space: pre-wrap; display: inline-block }" + private companion object { + const val CSS_STYLE = + "body { font-family: sans-serif } pre { background-color: #eeeeee; padding: 1em; white-space: pre-wrap; display: inline-block }" const val OPEN_SOURCE_LIBRARIES = "Open source licenses" const val NO_LIBRARIES = "None" const val NO_LICENSE = "No license found" diff --git a/src/main/kotlin/com/jaredsburrows/license/internal/report/JsonReport.kt b/src/main/kotlin/com/jaredsburrows/license/internal/report/JsonReport.kt index e2b9b08b..083dbee7 100644 --- a/src/main/kotlin/com/jaredsburrows/license/internal/report/JsonReport.kt +++ b/src/main/kotlin/com/jaredsburrows/license/internal/report/JsonReport.kt @@ -43,7 +43,7 @@ class JsonReport(private val projects: List) : Report { override fun emptyReport(): String = EMPTY_JSON - companion object { + private companion object { private const val PROJECT = "project" private const val DESCRIPTION = "description" private const val VERSION = "version" diff --git a/src/main/kotlin/com/jaredsburrows/license/internal/report/Report.kt b/src/main/kotlin/com/jaredsburrows/license/internal/report/Report.kt index 898aaf26..043125d8 100644 --- a/src/main/kotlin/com/jaredsburrows/license/internal/report/Report.kt +++ b/src/main/kotlin/com/jaredsburrows/license/internal/report/Report.kt @@ -14,5 +14,5 @@ interface Report { /** Return the empty report if no open source licenses are found. */ fun emptyReport(): String - fun String.valueOrNull(): String? = if (this.isNotEmpty()) this else null + fun String.valueOrNull(): String? = this.ifEmpty { null } } diff --git a/src/test/groovy/com/jaredsburrows/license/LicensePluginAndroidSpec.groovy b/src/test/groovy/com/jaredsburrows/license/LicensePluginAndroidSpec.groovy index ae85f85c..44f23668 100644 --- a/src/test/groovy/com/jaredsburrows/license/LicensePluginAndroidSpec.groovy +++ b/src/test/groovy/com/jaredsburrows/license/LicensePluginAndroidSpec.groovy @@ -46,7 +46,7 @@ final class LicensePluginAndroidSpec extends Specification { """ buildscript { repositories { - jcenter() + mavenCentral() google() } @@ -84,13 +84,16 @@ final class LicensePluginAndroidSpec extends Specification { where: [gradleVersion, agpVersion] << [ [ - '5.6.4', - '6.1.1' + '7.0.2', + '7.1.1', + '7.2' ], [ - '3.5.0', - '3.6.0', - '4.0.0' + '3.5.4', + '3.6.4', + '4.0.2', + '4.1.3', + '4.2.2' ] ].combinations() } diff --git a/src/test/groovy/com/jaredsburrows/license/LicensePluginJavaSpec.groovy b/src/test/groovy/com/jaredsburrows/license/LicensePluginJavaSpec.groovy index 59f64a86..f66820a9 100644 --- a/src/test/groovy/com/jaredsburrows/license/LicensePluginJavaSpec.groovy +++ b/src/test/groovy/com/jaredsburrows/license/LicensePluginJavaSpec.groovy @@ -51,9 +51,9 @@ final class LicensePluginJavaSpec extends Specification { where: gradleVersion << [ - '5.4.1', - '5.6.4', - '6.1.1' + '7.0.2', + '7.1.1', + '7.2' ] }