This commit is contained in:
Erik C. Thauvin 2021-06-12 13:30:54 -07:00
parent 3ce2bac9c7
commit b674549840
5 changed files with 61 additions and 44 deletions

View file

@ -5,39 +5,59 @@ on: [push, pull_request, workflow_dispatch]
jobs: jobs:
build: build:
runs-on: ubuntu-latest 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: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Set up JDK 11
- name: Set up JDK ${{ matrix.java-version }}
uses: actions/setup-java@v1 uses: actions/setup-java@v1
with: with:
java-version: 11 java-version: ${{ matrix.java-version }}
- name: Grant execute permission for gradlew - name: Grant execute permission for gradlew
run: chmod +x gradlew run: chmod +x gradlew
- name: Cache SonarCloud packages - name: Cache SonarCloud packages
if: matrix.java-version == env.SONAR_JDK
uses: actions/cache@v1 uses: actions/cache@v1
with: with:
path: ~/.sonar/cache path: ~/.sonar/cache
key: ${{ runner.os }}-sonar key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar restore-keys: ${{ runner.os }}-sonar
- name: Cache Gradle packages - name: Cache Gradle packages
uses: actions/cache@v2 uses: actions/cache@v2
with: with:
path: | path: |
~/.gradle/caches ~/.gradle/caches
~/.gradle/wrapper ~/.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: | restore-keys: |
${{ runner.os }}-gradle- ${{ runner.os }}-gradle-${{ matrix.java-version }}-
- name: Test with Gradle - name: Test with Gradle
env: env:
CI_NAME: "GitHub CI"
AKISMET_BLOG: ${{ secrets.AKISMET_BLOG }} AKISMET_BLOG: ${{ secrets.AKISMET_BLOG }}
AKISMET_API_KEY: ${{ secrets.AKISMET_API_KEY }} 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 }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./gradlew check sonarqube run: ./gradlew sonarqube
- name: Cleanup Gradle Cache - name: Cleanup Gradle Cache
run: | run: |
rm -f ~/.gradle/caches/modules-2/modules-2.lock rm -f ~/.gradle/caches/modules-2/modules-2.lock

View file

@ -4,18 +4,18 @@ import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent import org.gradle.api.tasks.testing.logging.TestLogEvent
plugins { plugins {
jacoco id("com.github.ben-manes.versions") version "0.39.0"
java
`maven-publish`
signing
id("com.github.ben-manes.versions") version "0.38.0"
id("io.gitlab.arturbosch.detekt") version "1.17.1" 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("net.thauvin.erik.gradle.semver") version "1.0.4"
id("org.jetbrains.dokka") version "1.4.32" id("org.jetbrains.dokka") version "1.4.32"
id("org.jetbrains.kotlin.jvm") version "1.5.0" id("org.sonarqube") version "3.3"
id("org.jetbrains.kotlin.kapt") version "1.5.0" id("signing")
id("org.jetbrains.kotlin.plugin.serialization") version "1.5.0" kotlin("jvm") version "1.5.10"
id("org.sonarqube") version "3.2.0" kotlin("kapt") version "1.5.10"
kotlin("plugin.serialization") version "1.5.10"
} }
group = "net.thauvin.erik" group = "net.thauvin.erik"
@ -30,12 +30,10 @@ var semverProcessor = "net.thauvin.erik:semver:1.2.0"
val publicationName = "mavenJava" val publicationName = "mavenJava"
object VersionInfo { object Versions {
const val okhttp = "4.9.1" const val OKHTTP = "4.9.1"
} }
val versions: VersionInfo by extra { VersionInfo }
repositories { repositories {
mavenCentral() mavenCentral()
maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") } 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("javax.servlet:javax.servlet-api:4.0.1")
implementation("com.squareup.okhttp3:okhttp:${versions.okhttp}") implementation("com.squareup.okhttp3:okhttp:${Versions.OKHTTP}")
implementation("com.squareup.okhttp3:logging-interceptor:${versions.okhttp}") implementation("com.squareup.okhttp3:logging-interceptor:${Versions.OKHTTP}")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.1") 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") testImplementation("org.testng:testng:7.4.0")
} }
@ -177,10 +175,10 @@ tasks {
register("deploy") { register("deploy") {
description = "Copies all needed files to the $deployDir directory." description = "Copies all needed files to the $deployDir directory."
group = PublishingPlugin.PUBLISH_TASK_GROUP group = PublishingPlugin.PUBLISH_TASK_GROUP
dependsOn("build", "jar") dependsOn(build, jar)
outputs.dir(deployDir) outputs.dir(deployDir)
inputs.files(copyToDeploy) inputs.files(copyToDeploy)
mustRunAfter("clean") mustRunAfter(clean)
} }
val gitIsDirty by registering(Exec::class) { val gitIsDirty by registering(Exec::class) {
@ -201,11 +199,11 @@ tasks {
register("release") { register("release") {
description = "Publishes version ${project.version} to local repository." description = "Publishes version ${project.version} to local repository."
group = PublishingPlugin.PUBLISH_TASK_GROUP group = PublishingPlugin.PUBLISH_TASK_GROUP
dependsOn("wrapper", "deploy", "gitTag", "publishToMavenLocal") dependsOn(wrapper, "deploy", gitTag, publishToMavenLocal)
} }
"sonarqube" { "sonarqube" {
dependsOn("jacocoTestReport") dependsOn(jacocoTestReport)
} }
} }

View file

@ -1,7 +1,7 @@
plugins { plugins {
id("org.jetbrains.kotlin.jvm") version "1.5.0" id("application")
id("com.github.ben-manes.versions") version "0.38.0" id("com.github.ben-manes.versions") version "0.39.0"
application kotlin("jvm") version "1.5.10"
} }
// ./gradlew run runJava // ./gradlew run runJava

View file

@ -52,13 +52,13 @@ import java.util.logging.Logger
/** /**
* Provides access to the [Akismet API](https://akismet.com/development/api/). * 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") @Version(properties = "version.properties", type = "kt")
open class Akismet(apiKey: String) { open class Akismet(apiKey: String) {
companion object { companion object {
/** /**
* (Re)Create a [comment][AkismetComment] from a JSON string. * (Re)Creates a [comment][AkismetComment] from a JSON string.
* *
* @see [AkismetComment.toString] * @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.dateGmt]
* @see [AkismetComment.postModifiedGmt] * @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.dateGmt]
* @see [AkismetComment.postModifiedGmt] * @see [AkismetComment.postModifiedGmt]
@ -125,7 +125,7 @@ open class Akismet(apiKey: String) {
var appUserAgent = "" var appUserAgent = ""
/** /**
* Check if the API Key has been verified * Set to `true` if the API Key has been verified.
* *
* @see [Akismet.verifyKey] * @see [Akismet.verifyKey]
*/ */
@ -173,7 +173,7 @@ open class Akismet(apiKey: String) {
private set 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. * 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. * 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) { constructor(apiKey: String, blog: String) : this(apiKey) {
this.blog = blog 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 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. * @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. * [response] properties.
*/ */
fun reset() { fun reset() {

View file

@ -36,7 +36,6 @@ import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import javax.servlet.http.HttpServletRequest import javax.servlet.http.HttpServletRequest
import kotlin.collections.HashMap
import kotlin.collections.Map import kotlin.collections.Map
import kotlin.collections.emptyMap import kotlin.collections.emptyMap
import kotlin.collections.iterator 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. * 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. * 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<String, String> = emptyMap() var serverEnv: Map<String, String> = 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. * from a Servlet request.
* *
* See the * See the
@ -242,8 +241,8 @@ open class AkismetComment(val userIp: String, val userAgent: String) {
* @see [serverEnv] * @see [serverEnv]
*/ */
constructor(request: HttpServletRequest) : this( constructor(request: HttpServletRequest) : this(
request.remoteAddr, request.remoteAddr,
request.getHeader("User-Agent").ifNull() request.getHeader("User-Agent").ifNull()
) { ) {
referrer = request.getHeader("referer").ifNull() referrer = request.getHeader("referer").ifNull()
serverEnv = buildServerEnv(request) serverEnv = buildServerEnv(request)
@ -325,7 +324,7 @@ open class AkismetComment(val userIp: String, val userAgent: String) {
} }
private fun buildServerEnv(request: HttpServletRequest): Map<String, String> { private fun buildServerEnv(request: HttpServletRequest): Map<String, String> {
val params = HashMap<String, String>() val params = mutableMapOf<String, String>()
params["REMOTE_ADDR"] = request.remoteAddr params["REMOTE_ADDR"] = request.remoteAddr
params["REQUEST_URI"] = request.requestURI params["REQUEST_URI"] = request.requestURI