Skip to content

Commit

Permalink
Merge pull request #6 from ethauvin/feat/setup_kotlin_mp_jvm
Browse files Browse the repository at this point in the history
restructure project to Kotlin Multiplatform
  • Loading branch information
ethauvin authored Aug 4, 2023
2 parents c177d49 + 6d9023c commit 641ffad
Show file tree
Hide file tree
Showing 25 changed files with 417 additions and 274 deletions.
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ dependencies {
```

Instructions for using with Maven, Ivy, etc. can be found
on [Maven Central](https://maven-badges.herokuapp.com/maven-central/net.thauvin.erik/urlencoder).
on [Maven Central](https://maven-badges.herokuapp.com/maven-central/net.thauvin.erik/urlencoder-jvm).

## Standalone usage

Expand All @@ -85,34 +85,34 @@ Encode and decode URL components defensively.
### Running with Gradle

```shell
./gradlew run --args="-e 'a test &'" # -> a%20test%20%26
./gradlew run --args="%#okékÉȢ" # -> %25%23ok%C3%A9k%C3%89%C8%A2
./gradlew run --quiet --args="-e 'a test &'" # -> a%20test%20%26
./gradlew run --quiet --args="%#okékÉȢ" # -> %25%23ok%C3%A9k%C3%89%C8%A2

./gradlew run --args="-d 'a%20test%20%26'" # -> a test &
./gradlew run --quiet --args="-d 'a%20test%20%26'" # -> a test &
```

### Running with Java

First build the jar file:

```shell
./gradlew clean fatJar
./gradlew fatJar
```

Then run it:

```shell
java -jar lib/build/libs/urlencoder-*all.jar -e "a test &" # -> a%20test%20%26
java -jar lib/build/libs/urlencoder-*all.jar "%#okékÉȢ" # -> %25%23ok%C3%A9k%C3%89%C8%A2
java -jar urlencoder-app/build/libs/urlencoder-*all.jar -e "a test &" # -> a%20test%20%26
java -jar urlencoder-app/build/libs/urlencoder-*all.jar "%#okékÉȢ" # -> %25%23ok%C3%A9k%C3%89%C8%A2

java -jar lib/build/libs/urlencoder-*.all.jar -d "a%20test%20%26" # -> a test &
java -jar urlencoder-app/build/libs/urlencoder-*all.jar -d "a%20test%20%26" # -> a test &
```

## Why not simply use `java.net.URLEncoder`?

Apart for being quite inefficient, some URL components encoded with `URLEncoder.encode` might not be able to be properly decoded.

For example, a simply search query such as:
For example, a simple search query such as:

```kotlin
val u = URLEncoder.encode("foo +bar", StandardCharsets.UTF_8)
Expand All @@ -139,4 +139,3 @@ foo++bar
Unfortunately, decoding with [Uri.decode](https://developer.android.com/reference/android/net/Uri#decode(java.lang.String)) on Android, [decodeURI](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURI) in Javascript, etc. would yield the exact same result.

![URLEncoder](https://live.staticflickr.com/65535/52607534147_6197b42666_z.jpg)

58 changes: 0 additions & 58 deletions app/pom.xml

This file was deleted.

4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ group = "net.thauvin.erik"
version = "1.4.0-SNAPSHOT"

dependencies {
kover(projects.lib)
kover(projects.app)
kover(projects.urlencoderLib)
kover(projects.urlencoderApp)
}
11 changes: 11 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,14 @@ dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0")
implementation("org.jetbrains.kotlinx:kover-gradle-plugin:0.7.1")
}

dependencyLocking {
lockMode.set(LockMode.STRICT)
}

configurations {
// only lock compile & runtime to prevent error:
// Locking strict mode: Configuration ':buildSrc:testCompileClasspath' is locked but does not have lock state.
compileClasspath { resolutionStrategy.activateDependencyLocking() }
runtimeClasspath { resolutionStrategy.activateDependencyLocking() }
}
68 changes: 68 additions & 0 deletions buildSrc/gradle.lockfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# This is a Gradle generated file for dependency locking.
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.fasterxml.jackson.core:jackson-annotations:2.12.7=runtimeClasspath
com.fasterxml.jackson.core:jackson-core:2.12.7=runtimeClasspath
com.fasterxml.jackson.core:jackson-databind:2.12.7.1=runtimeClasspath
com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.12.7=runtimeClasspath
com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.12.7=runtimeClasspath
com.fasterxml.jackson.module:jackson-module-kotlin:2.12.7=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.12.7=runtimeClasspath
com.fasterxml.woodstox:woodstox-core:6.2.4=runtimeClasspath
com.github.ben-manes:gradle-versions-plugin:0.47.0=compileClasspath,runtimeClasspath
com.squareup.moshi:moshi-kotlin:1.12.0=runtimeClasspath
com.squareup.moshi:moshi:1.12.0=runtimeClasspath
com.squareup.okhttp3:okhttp:4.11.0=runtimeClasspath
com.squareup.okio:okio-jvm:3.2.0=runtimeClasspath
com.squareup.okio:okio:3.2.0=runtimeClasspath
com.thoughtworks.xstream:xstream:1.4.20=runtimeClasspath
io.github.x-stream:mxparser:1.2.2=runtimeClasspath
io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.23.0=compileClasspath,runtimeClasspath
jakarta.activation:jakarta.activation-api:1.2.1=runtimeClasspath
jakarta.xml.bind:jakarta.xml.bind-api:2.3.2=runtimeClasspath
org.codehaus.woodstox:stax2-api:4.2.1=runtimeClasspath
org.jetbrains.dokka:dokka-core:1.8.20=compileClasspath,runtimeClasspath
org.jetbrains.dokka:dokka-gradle-plugin:1.8.20=compileClasspath,runtimeClasspath
org.jetbrains.intellij.deps:trove4j:1.0.20200330=runtimeClasspath
org.jetbrains.kotlin:kotlin-android-extensions:1.9.0=runtimeClasspath
org.jetbrains.kotlin:kotlin-build-tools-api:1.9.0=runtimeClasspath
org.jetbrains.kotlin:kotlin-compiler-embeddable:1.9.0=runtimeClasspath
org.jetbrains.kotlin:kotlin-compiler-runner:1.9.0=runtimeClasspath
org.jetbrains.kotlin:kotlin-daemon-client:1.9.0=runtimeClasspath
org.jetbrains.kotlin:kotlin-daemon-embeddable:1.9.0=runtimeClasspath
org.jetbrains.kotlin:kotlin-gradle-plugin-annotations:1.9.0=compileClasspath,runtimeClasspath
org.jetbrains.kotlin:kotlin-gradle-plugin-api:1.9.0=compileClasspath,runtimeClasspath
org.jetbrains.kotlin:kotlin-gradle-plugin-idea-proto:1.9.0=runtimeClasspath
org.jetbrains.kotlin:kotlin-gradle-plugin-idea:1.9.0=runtimeClasspath
org.jetbrains.kotlin:kotlin-gradle-plugin-model:1.9.0=compileClasspath,runtimeClasspath
org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0=compileClasspath,runtimeClasspath
org.jetbrains.kotlin:kotlin-gradle-plugins-bom:1.9.0=compileClasspath,runtimeClasspath
org.jetbrains.kotlin:kotlin-klib-commonizer-api:1.9.0=runtimeClasspath
org.jetbrains.kotlin:kotlin-native-utils:1.9.0=compileClasspath,runtimeClasspath
org.jetbrains.kotlin:kotlin-project-model:1.9.0=compileClasspath,runtimeClasspath
org.jetbrains.kotlin:kotlin-reflect:1.8.20=compileClasspath,runtimeClasspath
org.jetbrains.kotlin:kotlin-scripting-common:1.9.0=runtimeClasspath
org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:1.9.0=runtimeClasspath
org.jetbrains.kotlin:kotlin-scripting-compiler-impl-embeddable:1.9.0=runtimeClasspath
org.jetbrains.kotlin:kotlin-scripting-jvm:1.9.0=runtimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-common:1.8.20=compileClasspath
org.jetbrains.kotlin:kotlin-stdlib-common:1.8.21=runtimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.20=compileClasspath
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.21=runtimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.20=compileClasspath
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.21=runtimeClasspath
org.jetbrains.kotlin:kotlin-stdlib:1.8.20=compileClasspath
org.jetbrains.kotlin:kotlin-stdlib:1.8.21=runtimeClasspath
org.jetbrains.kotlin:kotlin-tooling-core:1.9.0=compileClasspath,runtimeClasspath
org.jetbrains.kotlin:kotlin-util-io:1.9.0=compileClasspath,runtimeClasspath
org.jetbrains.kotlin:kotlin-util-klib:1.9.0=compileClasspath,runtimeClasspath
org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.3=runtimeClasspath
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.3=runtimeClasspath
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.3=runtimeClasspath
org.jetbrains.kotlinx:kover-gradle-plugin:0.7.1=compileClasspath,runtimeClasspath
org.jetbrains:annotations:13.0=compileClasspath,runtimeClasspath
org.jetbrains:markdown-jvm:0.3.1=compileClasspath,runtimeClasspath
org.jetbrains:markdown:0.3.1=compileClasspath,runtimeClasspath
org.jsoup:jsoup:1.15.3=runtimeClasspath
xmlpull:xmlpull:1.1.3.1=runtimeClasspath
empty=kotlinScriptDefExtensions
18 changes: 18 additions & 0 deletions buildSrc/src/main/kotlin/buildsrc/conventions/base.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,21 @@ tasks.withType<AbstractArchiveTask>().configureEach {
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
}

dependencyLocking {
lockMode.set(LockMode.STRICT)
lockAllConfigurations()
}

tasks.register("resolveAndLockAllDependencies") {
// https://docs.gradle.org/current/userguide/dependency_locking.html#ex-resolving-all-configurations
group = "dependencies"
notCompatibleWithConfigurationCache("Filters configurations at execution time")
val resolvableConfigurations = configurations.matching { it.isCanBeResolved }
doFirst {
require(gradle.startParameter.isWriteDependencyLocks) { "$path must be run from the command line with the `--write-locks` flag" }
}
doLast {
resolvableConfigurations.forEach { it.resolve() }
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ kotlin {

sourceSets.configureEach {
languageSettings {
// languageVersion =
// apiVersion =
// languageVersion =
// apiVersion =
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,21 @@ kotlin {
// ├── watchosX64
// └── watchosSimulatorArm64Main

targets {
linuxX64()
linuxX64()

mingwX64()
mingwX64()

macosX64()
macosArm64()
macosX64()
macosArm64()

// https://kotlinlang.org/docs/multiplatform-share-on-platforms.html#use-target-shortcuts
ios() // iosArm64, iosX64
watchos() // watchosArm32, watchosArm64, watchosX64
tvos() // tvosArm64, tvosX64
// https://kotlinlang.org/docs/multiplatform-share-on-platforms.html#use-target-shortcuts
ios() // iosArm64, iosX64
watchos() // watchosArm32, watchosArm64, watchosX64
tvos() // tvosArm64, tvosX64

iosSimulatorArm64()
tvosSimulatorArm64()
watchosSimulatorArm64()
}
iosSimulatorArm64()
tvosSimulatorArm64()
watchosSimulatorArm64()

@Suppress("UNUSED_VARIABLE")
sourceSets {
Expand Down Expand Up @@ -79,22 +77,22 @@ kotlin {
val iosMain by getting { dependsOn(nativeMain) }
val iosTest by getting { dependsOn(nativeTest) }

// val iosSimulatorArm64Main by getting { dependsOn(iosMain) }
// val iosSimulatorArm64Test by getting { dependsOn(iosTest) }

// // Apple - tvOS
// val tvosMain by getting { dependsOn(nativeMain) }
// val tvosTest by getting { dependsOn(nativeTest) }
//
// val tvosSimulatorArm64Main by getting { dependsOn(tvosMain) }
// val tvosSimulatorArm64Test by getting { dependsOn(tvosTest) }
//
// // Apple - watchOS
// val watchosMain by getting { dependsOn(nativeMain) }
// val watchosTest by getting { dependsOn(nativeTest) }
//
// val watchosSimulatorArm64Main by getting { dependsOn(watchosMain) }
// val watchosSimulatorArm64Test by getting { dependsOn(watchosTest) }
// val iosSimulatorArm64Main by getting { dependsOn(iosMain) }
// val iosSimulatorArm64Test by getting { dependsOn(iosTest) }

// // Apple - tvOS
// val tvosMain by getting { dependsOn(nativeMain) }
// val tvosTest by getting { dependsOn(nativeTest) }

// val tvosSimulatorArm64Main by getting { dependsOn(tvosMain) }
// val tvosSimulatorArm64Test by getting { dependsOn(tvosTest) }

// // Apple - watchOS
// val watchosMain by getting { dependsOn(nativeMain) }
// val watchosTest by getting { dependsOn(nativeTest) }

// val watchosSimulatorArm64Main by getting { dependsOn(watchosMain) }
// val watchosSimulatorArm64Test by getting { dependsOn(watchosTest) }

// val iosArm32Main by getting { dependsOn(desktopMain) }
// val iosArm32Test by getting { dependsOn(nativeTest) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ signing {
!isSnapshotVersion() || gradle.taskGraph.hasTask("publish")
})
}

tasks.withType<Sign>().configureEach {
val signingRequiredPredicate = provider { signing.isRequired }
onlyIf { signingRequiredPredicate.get() }
Expand All @@ -106,3 +107,9 @@ val javadocJar by tasks.registering(Jar::class) {
from(tasks.dokkaJavadoc)
archiveClassifier.set("javadoc")
}

publishing {
publications.withType<MavenPublication>().configureEach {
artifact(javadocJar)
}
}
9 changes: 9 additions & 0 deletions gradle.lockfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This is a Gradle generated file for dependency locking.
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
org.freemarker:freemarker:2.3.30=koverJvmReporter
org.jetbrains.intellij.deps:coverage-report:1.0.19=koverJvmReporter
org.jetbrains.intellij.deps:intellij-coverage-agent:1.0.721=koverJvmAgent,koverJvmReporter
org.jetbrains.intellij.deps:intellij-coverage-reporter:1.0.721=koverJvmReporter
org.jetbrains:annotations:16.0.2=koverJvmReporter
empty=koverExternalArtifacts
Loading

0 comments on commit 641ffad

Please sign in to comment.