Skip to content

Commit

Permalink
Update deps (#22)
Browse files Browse the repository at this point in the history
* Upgrade gradle to 8.8

* Update dependencies

* Use compileOnly to not force dependencies versions

* Update and apply ktlint

* Add ktlintCheck + detekt in PR workflow

* Reorder build.gradle.kts

* Update CI config
  • Loading branch information
pgreze authored Jun 27, 2024
1 parent 8f833c4 commit 5c7c931
Show file tree
Hide file tree
Showing 18 changed files with 385 additions and 327 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[*.{kt,kts}]
insert_final_newline = true
ktlint_code_style = ktlint_official
ktlint_standard_import-ordering = disabled
ktlint_standard_type-parameter-comment = disabled
ktlint_standard_multiline-expression-wrapping = disabled
14 changes: 14 additions & 0 deletions .github/actions/post-checkout/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Post checkout

description: Post checkout instructions.

runs:
using: "composite"
steps:
- name: Set up JDK 8
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 8

- uses: gradle/actions/setup-gradle@v3
42 changes: 12 additions & 30 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# https://help.github.com/en/actions/language-and-framework-guides/building-and-testing-java-with-gradle
# https://help.github.com/en/actions/language-and-framework-guides/publishing-java-packages-with-gradle

name: Build

on:
Expand All @@ -15,36 +12,21 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
# setup
- uses: actions/checkout@v2
- name: Set up JDK 8
uses: actions/setup-java@v1
with:
java-version: 8
# Cache
- name: Cache Gradle wrapper
uses: actions/cache@v1
with:
path: ~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('gradle/wrapper/*') }}
restore-keys: ${{ runner.os }}-gradle-${{ hashFiles('gradle/wrapper/*') }}
- name: Cache Gradle packages
uses: actions/cache@v1
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle.kts') }}
restore-keys: ${{ runner.os }}-gradle
# Build
- name: Build
- uses: actions/checkout@v4

- uses: ./.github/actions/post-checkout

- shell: bash
run: ./gradlew build dokkaHtml --continue

# https://github.com/marketplace/actions/publish-unit-test-results
- name: Publish Unit Test Results
# https://github.com/marketplace/actions/publish-unit-test-results
uses: EnricoMi/publish-unit-test-result-action@v1
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
files: build/test-results/**/*.xml
- name: Codecov
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: bash <(curl -s https://codecov.io/bash)

- uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
31 changes: 7 additions & 24 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# https://help.github.com/en/actions/language-and-framework-guides/building-and-testing-java-with-gradle
# https://help.github.com/en/actions/language-and-framework-guides/publishing-java-packages-with-gradle

name: Publish

on:
Expand All @@ -12,28 +9,13 @@ jobs:
publish:
runs-on: ubuntu-latest
steps:
# setup
- uses: actions/checkout@v2
- name: Set up JDK 8
uses: actions/setup-java@v1
with:
java-version: 8
# Cache
- name: Cache Gradle wrapper
uses: actions/cache@v1
with:
path: ~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('gradle/wrapper/*') }}
restore-keys: ${{ runner.os }}-gradle-${{ hashFiles('gradle/wrapper/*') }}
- name: Cache Gradle packages
uses: actions/cache@v1
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle.kts') }}
restore-keys: ${{ runner.os }}-gradle
# Build + Publish
- name: Build
- uses: actions/checkout@v4

- uses: ./.github/actions/post-checkout

- shell: bash
run: ./gradlew assemble dokkaHtml

- name: Publish to Maven Central
env:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
Expand All @@ -45,6 +27,7 @@ jobs:
export SIGNING_SECRET_KEY_RING_FILE=secret-key.gpg
echo $SIGNING_SECRET_KEY_RING_CONTENT | base64 -di > $SIGNING_SECRET_KEY_RING_FILE
./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository --max-workers 1
- name: Publish Dokka
uses: netlify/actions/cli@master
with:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies {
Or in your kotlin script:

```kotlin
@file:DependsOn("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
@file:DependsOn("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1")
@file:DependsOn("com.github.pgreze:kotlin-process:$kotlinProcessVersion")
```

Expand Down
37 changes: 23 additions & 14 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import de.fayard.refreshVersions.core.versionFor

plugins {
kotlin("jvm")
id("org.jetbrains.dokka")
Expand All @@ -9,14 +11,11 @@ plugins {
id("io.github.gradle-nexus.publish-plugin")
}

val myGroup = "com.github.pgreze"
.also { group = it }
val myGroup = "com.github.pgreze".also { group = it }
val myArtifactId = "kotlin-process"
val tagVersion = System.getenv("GITHUB_REF")?.split('/')?.last()
val myVersion = (tagVersion?.trimStart('v') ?: "WIP")
.also { version = it }
val myDescription = "Kotlin friendly way to run an external process"
.also { description = it }
val myVersion = (tagVersion?.trimStart('v') ?: "WIP").also { version = it }
val myDescription = "Kotlin friendly way to run an external process".also { description = it }
val githubUrl = "https://github.com/pgreze/$myArtifactId"

java {
Expand All @@ -36,10 +35,6 @@ tasks.test {
finalizedBy(tasks.jacocoTestReport)
}

configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
disabledRules.set(setOf("import-ordering"))
}

jacoco {
toolVersion = "0.8.7"
}
Expand All @@ -50,9 +45,21 @@ tasks.jacocoTestReport {
}
}

configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
version.set(versionFor("version.com.pinterest.ktlint..ktlint-cli"))
}

dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(KotlinX.coroutines.core)
setOf(
kotlin("stdlib-jdk8"),
KotlinX.coroutines.core,
).forEach { dependency ->
compileOnly(dependency)
testImplementation(dependency)
}

// To trigger refreshVersions updates
"ktlint"("com.pinterest.ktlint:ktlint-cli:_")

testImplementation("org.amshove.kluent:kluent:_")
testImplementation(platform(Testing.junit.bom))
Expand Down Expand Up @@ -119,13 +126,15 @@ publishing {
mapOf(
"signing.keyId" to "SIGNING_KEY_ID",
"signing.password" to "SIGNING_PASSWORD",
"signing.secretKeyRingFile" to "SIGNING_SECRET_KEY_RING_FILE"
"signing.secretKeyRingFile" to "SIGNING_SECRET_KEY_RING_FILE",
).forEach { (key, envName) ->
val value = propOrEnv(key, envName)
?.let {
if (key.contains("File")) {
rootProject.file(it).absolutePath
} else it
} else {
it
}
}
ext.set(key, value)
}
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
12 changes: 8 additions & 4 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,10 +80,10 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
Expand Down Expand Up @@ -143,12 +143,16 @@ fi
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down
1 change: 1 addition & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand Down
12 changes: 9 additions & 3 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
@file:Suppress("UnstableApiUsage")

rootProject.name = "kotlin-process"

@Suppress("UnstableApiUsage")
dependencyResolutionManagement.repositories {
mavenCentral()
}

rootProject.name = "kotlin-process"

plugins {
id("de.fayard.refreshVersions") version "0.40.2"
id("de.fayard.refreshVersions") version "0.60.5"
}

refreshVersions {
rejectVersionIf { candidate.stabilityLevel.isLessStableThan(current.stabilityLevel) }
}
33 changes: 20 additions & 13 deletions src/main/kotlin/com/github/pgreze/process/InputSource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ sealed class InputSource {
* Natively supported file redirection.
* @see ProcessBuilder.Redirect.from
*/
class FromFile(val file: File) : InputSource()
class FromFile(
val file: File,
) : InputSource()

/**
* Allows custom logic given the [Process.getInputStream] instance,
* auto-closed after [handler] completes.
*/
class FromStream(val handler: suspend (OutputStream) -> Unit) : InputSource()
class FromStream(
val handler: suspend (OutputStream) -> Unit,
) : InputSource()

/**
* Natively supported parent provided redirection.
Expand All @@ -30,22 +34,25 @@ sealed class InputSource {
fun fromString(
string: String,
charset: Charset = Charset.forName("UTF-8"),
): InputSource = FromStream {
it.write(string.toByteArray(charset))
}
): InputSource =
FromStream {
it.write(string.toByteArray(charset))
}

@JvmStatic
fun fromInputStream(
inputStream: InputStream,
bufferSize: Int = DEFAULT_BUFFER_SIZE,
): InputSource = FromStream { out ->
inputStream.use { it.copyTo(out, bufferSize) }
}
): InputSource =
FromStream { out ->
inputStream.use { it.copyTo(out, bufferSize) }
}
}
}

internal fun InputSource.toNative() = when (this) {
is InputSource.FromFile -> ProcessBuilder.Redirect.from(file)
is InputSource.FromStream -> ProcessBuilder.Redirect.PIPE
is InputSource.FromParent -> ProcessBuilder.Redirect.INHERIT
}
internal fun InputSource.toNative() =
when (this) {
is InputSource.FromFile -> ProcessBuilder.Redirect.from(file)
is InputSource.FromStream -> ProcessBuilder.Redirect.PIPE
is InputSource.FromParent -> ProcessBuilder.Redirect.INHERIT
}
Loading

0 comments on commit 5c7c931

Please sign in to comment.