From b6745498407606eca7b32e5f05600f92a7db7102 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Sat, 12 Jun 2021 13:30:54 -0700 Subject: [PATCH] Cleanup. --- .github/workflows/gradle.yml | 32 +++++++++++++--- build.gradle.kts | 38 +++++++++---------- examples/build.gradle.kts | 6 +-- .../net/thauvin/erik/akismet/Akismet.kt | 18 ++++----- .../thauvin/erik/akismet/AkismetComment.kt | 11 +++--- 5 files changed, 61 insertions(+), 44 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 43f7c1c..523faab 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -5,39 +5,59 @@ on: [push, pull_request, workflow_dispatch] jobs: build: runs-on: ubuntu-latest + + env: + GRADLE_OPTS: "-Dorg.gradle.jvmargs=-XX:MaxMetaspaceSize=512m" + SONAR_JDK: "11" + + strategy: + matrix: + java-version: [ 1.8, 11, 15 ] + steps: - uses: actions/checkout@v2 with: fetch-depth: 0 - - name: Set up JDK 11 + + - name: Set up JDK ${{ matrix.java-version }} uses: actions/setup-java@v1 with: - java-version: 11 + java-version: ${{ matrix.java-version }} + - name: Grant execute permission for gradlew run: chmod +x gradlew + - name: Cache SonarCloud packages + if: matrix.java-version == env.SONAR_JDK uses: actions/cache@v1 with: path: ~/.sonar/cache key: ${{ runner.os }}-sonar restore-keys: ${{ runner.os }}-sonar + - name: Cache Gradle packages uses: actions/cache@v2 with: path: | ~/.gradle/caches ~/.gradle/wrapper - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + key: ${{ runner.os }}-gradle-${{ matrix.java-version }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} restore-keys: | - ${{ runner.os }}-gradle- + ${{ runner.os }}-gradle-${{ matrix.java-version }}- + - name: Test with Gradle env: - CI_NAME: "GitHub CI" AKISMET_BLOG: ${{ secrets.AKISMET_BLOG }} AKISMET_API_KEY: ${{ secrets.AKISMET_API_KEY }} + run: ./gradlew build check --stacktrace + + - name: SonarCloud + if: success() && matrix.java-version == env.SONAR_JDK + env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: ./gradlew check sonarqube + run: ./gradlew sonarqube + - name: Cleanup Gradle Cache run: | rm -f ~/.gradle/caches/modules-2/modules-2.lock diff --git a/build.gradle.kts b/build.gradle.kts index 65649e3..e6df14e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,18 +4,18 @@ import org.gradle.api.tasks.testing.logging.TestExceptionFormat import org.gradle.api.tasks.testing.logging.TestLogEvent plugins { - jacoco - java - `maven-publish` - signing - id("com.github.ben-manes.versions") version "0.38.0" + id("com.github.ben-manes.versions") version "0.39.0" id("io.gitlab.arturbosch.detekt") version "1.17.1" + id("jacoco") + id("java") + id("maven-publish") id("net.thauvin.erik.gradle.semver") version "1.0.4" id("org.jetbrains.dokka") version "1.4.32" - id("org.jetbrains.kotlin.jvm") version "1.5.0" - id("org.jetbrains.kotlin.kapt") version "1.5.0" - id("org.jetbrains.kotlin.plugin.serialization") version "1.5.0" - id("org.sonarqube") version "3.2.0" + id("org.sonarqube") version "3.3" + id("signing") + kotlin("jvm") version "1.5.10" + kotlin("kapt") version "1.5.10" + kotlin("plugin.serialization") version "1.5.10" } group = "net.thauvin.erik" @@ -30,12 +30,10 @@ var semverProcessor = "net.thauvin.erik:semver:1.2.0" val publicationName = "mavenJava" -object VersionInfo { - const val okhttp = "4.9.1" +object Versions { + const val OKHTTP = "4.9.1" } -val versions: VersionInfo by extra { VersionInfo } - repositories { mavenCentral() maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") } @@ -49,12 +47,12 @@ dependencies { implementation("javax.servlet:javax.servlet-api:4.0.1") - implementation("com.squareup.okhttp3:okhttp:${versions.okhttp}") - implementation("com.squareup.okhttp3:logging-interceptor:${versions.okhttp}") + implementation("com.squareup.okhttp3:okhttp:${Versions.OKHTTP}") + implementation("com.squareup.okhttp3:logging-interceptor:${Versions.OKHTTP}") implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.1") - testImplementation("org.mockito:mockito-core:3.10.0") + testImplementation("org.mockito:mockito-core:3.11.1") testImplementation("org.testng:testng:7.4.0") } @@ -177,10 +175,10 @@ tasks { register("deploy") { description = "Copies all needed files to the $deployDir directory." group = PublishingPlugin.PUBLISH_TASK_GROUP - dependsOn("build", "jar") + dependsOn(build, jar) outputs.dir(deployDir) inputs.files(copyToDeploy) - mustRunAfter("clean") + mustRunAfter(clean) } val gitIsDirty by registering(Exec::class) { @@ -201,11 +199,11 @@ tasks { register("release") { description = "Publishes version ${project.version} to local repository." group = PublishingPlugin.PUBLISH_TASK_GROUP - dependsOn("wrapper", "deploy", "gitTag", "publishToMavenLocal") + dependsOn(wrapper, "deploy", gitTag, publishToMavenLocal) } "sonarqube" { - dependsOn("jacocoTestReport") + dependsOn(jacocoTestReport) } } diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts index a975d8c..47f9ebb 100644 --- a/examples/build.gradle.kts +++ b/examples/build.gradle.kts @@ -1,7 +1,7 @@ plugins { - id("org.jetbrains.kotlin.jvm") version "1.5.0" - id("com.github.ben-manes.versions") version "0.38.0" - application + id("application") + id("com.github.ben-manes.versions") version "0.39.0" + kotlin("jvm") version "1.5.10" } // ./gradlew run runJava diff --git a/src/main/kotlin/net/thauvin/erik/akismet/Akismet.kt b/src/main/kotlin/net/thauvin/erik/akismet/Akismet.kt index d24b5ee..3aaff45 100644 --- a/src/main/kotlin/net/thauvin/erik/akismet/Akismet.kt +++ b/src/main/kotlin/net/thauvin/erik/akismet/Akismet.kt @@ -52,13 +52,13 @@ import java.util.logging.Logger /** * Provides access to the [Akismet API](https://akismet.com/development/api/). * - * @constructor Creates new instance using the provided [Akismet](https://www.askimet.com/) API key. + * @constructor Creates a new instance using the provided [Akismet](https://www.askimet.com/) API key. */ @Version(properties = "version.properties", type = "kt") open class Akismet(apiKey: String) { companion object { /** - * (Re)Create a [comment][AkismetComment] from a JSON string. + * (Re)Creates a [comment][AkismetComment] from a JSON string. * * @see [AkismetComment.toString] */ @@ -68,7 +68,7 @@ open class Akismet(apiKey: String) { } /** - * Convert a date to a UTC timestamp. (ISO 8601) + * Converts a date to a UTC timestamp. (ISO 8601) * * @see [AkismetComment.dateGmt] * @see [AkismetComment.postModifiedGmt] @@ -81,7 +81,7 @@ open class Akismet(apiKey: String) { } /** - * Convert a locale date/time to a UTC timestamp. (ISO 8601) + * Converts a locale date/time to a UTC timestamp. (ISO 8601) * * @see [AkismetComment.dateGmt] * @see [AkismetComment.postModifiedGmt] @@ -125,7 +125,7 @@ open class Akismet(apiKey: String) { var appUserAgent = "" /** - * Check if the API Key has been verified + * Set to `true` if the API Key has been verified. * * @see [Akismet.verifyKey] */ @@ -173,7 +173,7 @@ open class Akismet(apiKey: String) { private set /** - * Set to true if Akismet has determined that the last [checked comment][checkComment] is blatant spam, and you + * Set to `true` if Akismet has determined that the last [checked comment][checkComment] is blatant spam, and you * can safely discard it without saving it in any spam queue. * * See the [Akismet API](https://akismet.com/development/api/#comment-check) for more details. @@ -226,7 +226,7 @@ open class Akismet(apiKey: String) { } /** - * Create a new instance using an [Akismet](https://www.askimet.com/) API key and URL registered with Akismet. + * Creates a new instance using an [Akismet](https://www.askimet.com/) API key and URL registered with Akismet. */ constructor(apiKey: String, blog: String) : this(apiKey) { this.blog = blog @@ -318,7 +318,7 @@ open class Akismet(apiKey: String) { } /** - * Execute a call to an Akismet REST API method. + * Executes a call to an Akismet REST API method. * * @param apiUrl The Akismet API URL endpoint. (e.g. https://rest.akismet.com/1.1/verify-key) * @param formBody The HTTP POST form body containing the request parameters to be submitted. @@ -371,7 +371,7 @@ open class Akismet(apiKey: String) { } /** - * Reset the [debugHelp], [errorMessage], [httpStatusCode], [isDiscard], [isVerifiedKey], [proTip], and + * Resets the [debugHelp], [errorMessage], [httpStatusCode], [isDiscard], [isVerifiedKey], [proTip], and * [response] properties. */ fun reset() { diff --git a/src/main/kotlin/net/thauvin/erik/akismet/AkismetComment.kt b/src/main/kotlin/net/thauvin/erik/akismet/AkismetComment.kt index 969a9a2..30c2353 100644 --- a/src/main/kotlin/net/thauvin/erik/akismet/AkismetComment.kt +++ b/src/main/kotlin/net/thauvin/erik/akismet/AkismetComment.kt @@ -36,7 +36,6 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import javax.servlet.http.HttpServletRequest -import kotlin.collections.HashMap import kotlin.collections.Map import kotlin.collections.emptyMap import kotlin.collections.iterator @@ -53,7 +52,7 @@ private fun String?.ifNull() = this ?: "" * * See the [Akismet API](https://akismet.com/development/api/#comment-check) for more details. * - * @constructor Create an Akismet comment instance. + * @constructor Creates a new [AskimetComment] instance. * * See the [Akismet API](https://akismet.com/development/api/#comment-check) for more details. * @@ -233,7 +232,7 @@ open class AkismetComment(val userIp: String, val userAgent: String) { var serverEnv: Map = emptyMap() /** - * Create an Akismet comment extracting the [userIp], [userAgent], [referrer] and [serverEnv] environment variables + * Creates a new instance extracting the [userIp], [userAgent], [referrer] and [serverEnv] environment variables * from a Servlet request. * * See the @@ -242,8 +241,8 @@ open class AkismetComment(val userIp: String, val userAgent: String) { * @see [serverEnv] */ constructor(request: HttpServletRequest) : this( - request.remoteAddr, - request.getHeader("User-Agent").ifNull() + request.remoteAddr, + request.getHeader("User-Agent").ifNull() ) { referrer = request.getHeader("referer").ifNull() serverEnv = buildServerEnv(request) @@ -325,7 +324,7 @@ open class AkismetComment(val userIp: String, val userAgent: String) { } private fun buildServerEnv(request: HttpServletRequest): Map { - val params = HashMap() + val params = mutableMapOf() params["REMOTE_ADDR"] = request.remoteAddr params["REQUEST_URI"] = request.requestURI