Skip to content

Commit

Permalink
Release 0.1.6 (#57)
Browse files Browse the repository at this point in the history
* libBuildType added for multiple variants

* test helper functions & minor tweaks

* remove skip function

* Use source extension functions

* minor tweaks

* Source extension functions

* remove kotlinx dep

* add okio module

* update test script to support multiple variants

* fix platform checks

* refactor TestHelper func

* wasm target file updated

* Add Okio & Ktor2 (#56)

* wasm target updated

* add ktor2

* add wasm target flag

* chore:build configurations fixed

* add ksoup-network-ktor2

* update publish scripts

* add okio doc

* assert message improved

* update target scripts

* add test clean flag

* update gradle props

* gradle enableCInteropCommonization

* fix jvm args

* runTests updated
  • Loading branch information
itboy87 authored Aug 31, 2024
1 parent 4b456a6 commit 33be625
Show file tree
Hide file tree
Showing 81 changed files with 1,740 additions and 282 deletions.
23 changes: 13 additions & 10 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@ on:
pull_request:
branches: [ "release", "develop" ]
paths-ignore: [ "**.md" ]
workflow_dispatch:

jobs:
build:
strategy:
matrix:
config: [
{ target: android, os: ubuntu-latest, tasks: testDebugUnitTest testReleaseUnitTest, continueOnError: false },
{ target: apple, os: macos-latest, tasks: iosX64Test iosSimulatorArm64Test macosX64Test macosArm64Test tvosX64Test tvosSimulatorArm64Test, continueOnError: false },
{ target: js, os: ubuntu-latest, tasks: jsTest wasmTest, continueOnError: false },
{ target: desktop, os: ubuntu-latest, tasks: jvmTest, continueOnError: false },
{ target: windows, os: windows-latest, tasks: mingwX64Test, continueOnError: false },
{ target: linux, os: windows-latest, tasks: linuxX64Test, continueOnError: false },
]
libBuildType: [ "korlibs", "kotlinx" ]
{ target: android, os: ubuntu-latest, tasks: testDebugUnitTest testReleaseUnitTest, continueOnError: false },
{ target: apple, os: macos-latest, tasks: iosX64Test iosSimulatorArm64Test macosX64Test macosArm64Test tvosX64Test tvosSimulatorArm64Test, continueOnError: false },
{ target: js, os: ubuntu-latest, tasks: jsTest wasmTest, continueOnError: false },
{ target: desktop, os: ubuntu-latest, tasks: jvmTest, continueOnError: false },
{ target: windows, os: windows-latest, tasks: mingwX64Test, continueOnError: false },
{ target: linux, os: windows-latest, tasks: linuxX64Test, continueOnError: false },
]
libBuildType: [ "korlibs", "kotlinx", "okio", "ktor2" ]
runs-on: ${{ matrix.config.os }}
name: Build ${{ matrix.config.target }} with libBuildType=${{ matrix.libBuildType }}
steps:
Expand All @@ -34,9 +35,11 @@ jobs:
- name: Setup gradle
uses: gradle/gradle-build-action@v2

- name: Test ${{ matrix.config.target }} targets with libBuildType=${{ matrix.libBuildType }}
- name: Run tests for ${{ matrix.libBuildType }} on ${{ matrix.config.target }}
continue-on-error: ${{ matrix.config.continueOnError }}
run: ./gradlew ${{ matrix.config.tasks }} -PlibBuildType=${{ matrix.libBuildType }} --info
run: |
chmod +x ./runTests.sh
./runTests.sh ${{ matrix.libBuildType }} ${{ matrix.config.tasks }}
working-directory: ${{ github.workspace }}

# deploy:
Expand Down
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Ksoup is adept at handling all varieties of HTML found in the wild.
### Ksoup is published on Maven Central
Include the dependency in `commonMain`. Latest version [![Maven Central](https://img.shields.io/maven-central/v/com.fleeksoft.ksoup/ksoup.svg)](https://central.sonatype.com/artifact/com.fleeksoft.ksoup/ksoup)

Ksoup published in three variants. Pick the one that suits your needs and start building!
Ksoup published in four variants. Pick the one that suits your needs and start building!
1. **This variant built with [kotlinx-io](https://github.com/Kotlin/kotlinx-io) and [Ktor 3.0.0-beta-2](https://github.com/ktorio/ktor)**
```kotlin
implementation("com.fleeksoft.ksoup:ksoup:<version>")
Expand All @@ -41,22 +41,30 @@ Ksoup published in three variants. Pick the one that suits your needs and start
implementation("com.fleeksoft.ksoup:ksoup-network:<version>")
```

2. **This variant built with [kotlinx-io](https://github.com/Kotlin/kotlinx-io) and [Ktor 2.3.12](https://github.com/ktorio/ktor)**
2. **This variant is built with [korlibs-io](https://github.com/korlibs/korlibs-io)**
```kotlin
implementation("com.fleeksoft.ksoup:ksoup-korlibs:<version>")

// Optional: Include only if you need to use network request functions such as
// Ksoup.parseGetRequest, Ksoup.parseSubmitRequest, and Ksoup.parsePostRequest
implementation("com.fleeksoft.ksoup:ksoup-network-korlibs:<version>")
```

3. **This variant built with [kotlinx-io](https://github.com/Kotlin/kotlinx-io) and [Ktor 2.3.12](https://github.com/ktorio/ktor)**
```kotlin
implementation("com.fleeksoft.ksoup:ksoup-ktor2:<version>")

// Optional: Include only if you need to use network request functions such as
// Ksoup.parseGetRequest, Ksoup.parseSubmitRequest, and Ksoup.parsePostRequest
implementation("com.fleeksoft.ksoup:ksoup-network-ktor2:<version>")
```

3. **This variant is built with [korlibs-io](https://github.com/korlibs/korlibs-io)**
4. **This variant built with [okio](https://github.com/square/okio) and [Ktor 2.3.12](https://github.com/ktorio/ktor)**
```kotlin
implementation("com.fleeksoft.ksoup:ksoup-korlibs:<version>")
implementation("com.fleeksoft.ksoup:ksoup-okio:<version>")

// Optional: Include only if you need to use network request functions such as
// Ksoup.parseGetRequest, Ksoup.parseSubmitRequest, and Ksoup.parsePostRequest
implementation("com.fleeksoft.ksoup:ksoup-network-korlibs:<version>")
implementation("com.fleeksoft.ksoup:ksoup-network-ktor2:<version>")
```

**NOTE:** Variants built with kotlinx do not support gzip files.
Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#Gradle
org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\="-Xmx2048M"
org.gradle.caching=true
org.gradle.jvmargs=-Xmx8192M -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\="-Xmx8192M"
#Kotlin
kotlin.code.style=official
#Android
android.useAndroidX=true
android.nonTransitiveRClass=true
kotlin.native.ignoreIncorrectDependencies=true

# dev, kotlinx, korlibs, okio
# dev will include all modules in project
libBuildType=korlibs
kotlin.mpp.enableCInteropCommonization=true
# dev, kotlinx, korlibs, okio, ktor2
# dev will include all modules in settings.gradle.kts but use kotlinx dep for engine
libBuildType=kotlinx
isWasmEnabled=false
6 changes: 6 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ compileSdk = "34"
minSdk = "21"
libraryVersion = "0.1.6-alpha1"
ktor = "3.0.0-beta-2"
ktor2 = "2.3.12"
coroutines = "1.8.1"
kotlinxDatetime = "0.6.1"
kotlinx-io = "0.5.3"
okio = "3.9.0"
codepoints = "0.9.0"
dokka = "1.9.20"

Expand All @@ -23,6 +25,8 @@ jsoup = "1.18.1"
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" }
ktor2-io = { module = "io.ktor:ktor-io", version.ref = "ktor2" }
ktor2-http = { module = "io.ktor:ktor-http", version.ref = "ktor2" }
ktor-io = { module = "io.ktor:ktor-io", version.ref = "ktor" }
ktor-http = { module = "io.ktor:ktor-http", version.ref = "ktor" }
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
Expand All @@ -39,6 +43,8 @@ korlibs-io = { module = "com.soywiz:korlibs-io", version.ref = "korlibs" }
korlibs-io-network-core = { module = "com.soywiz:korlibs-io-network-core", version.ref = "korlibs" }
stately-concurrent = { module = "co.touchlab:stately-concurrent-collections", version.ref = "stately-concurrent" }
jsoup = { module = "org.jsoup:jsoup", version.ref = "jsoup" }
okio = { module = "com.squareup.okio:okio", version.ref = "okio" }
okio-nodefilesystem = { module = "com.squareup.okio:okio-nodefilesystem", version.ref = "okio" }

[plugins]
androidLibrary = { id = "com.android.library", version.ref = "agp" }
Expand Down
2 changes: 2 additions & 0 deletions ksoup-engine-common/src/com/fleeksoft/ksoup/io/FileSource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ interface FileSource {
suspend fun toSourceReader(): SourceReader
fun getPath(): String
fun getFullName(): String

companion object
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.fleeksoft.ksoup.io

interface SourceReader {
public fun skip(count: Long)

public fun mark(readLimit: Long)

Expand All @@ -18,4 +17,6 @@ interface SourceReader {
public fun close()

public fun readAtMostTo(sink: KByteBuffer, byteCount: Int): Int

companion object
}
4 changes: 2 additions & 2 deletions ksoup-engine-korlibs/module.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
product:
type: lib
platforms: [jvm, js, wasm, android, linuxX64, linuxArm64, tvosArm64, tvosX64, tvosSimulatorArm64, macosX64, macosArm64, iosArm64, iosSimulatorArm64, iosX64, mingwX64]
platforms: [ jvm, js, wasm, android, linuxX64, linuxArm64, tvosArm64, tvosX64, tvosSimulatorArm64, macosX64, macosArm64, iosArm64, iosSimulatorArm64, iosX64, mingwX64 ]

apply: [ ../common.module-template.yaml ]

aliases:
- jvmAndAndroid: [jvm, android]
- jvmAndAndroid: [ jvm, android ]

dependencies:
- ../ksoup-engine-common
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ object KsoupEngineImpl : KsoupEngine {
}

override fun openSourceReader(content: String, charset: Charset?): SourceReader {
return SourceReaderImpl(charset?.toByteArray(content) ?: content.encodeToByteArray())
return SourceReader.from(charset?.toByteArray(content) ?: content.encodeToByteArray())
}

override fun openSourceReader(byteArray: ByteArray): SourceReader {
return SourceReaderImpl(byteArray)
return SourceReader.from(byteArray)
}

override fun getUtf8Charset(): Charset {
Expand All @@ -26,6 +26,6 @@ object KsoupEngineImpl : KsoupEngine {
}

override fun pathToFileSource(path: String): FileSource {
return FileSourceImpl(path)
return FileSource.from(path)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import korlibs.io.file.VfsFile
import korlibs.io.file.fullName
import korlibs.io.file.std.uniVfs

class FileSourceImpl : FileSource {
val file: VfsFile
internal class FileSourceImpl : FileSource {
private val file: VfsFile

constructor(file: VfsFile) {
this.file = file
Expand Down
14 changes: 14 additions & 0 deletions ksoup-engine-korlibs/src/com/fleeksoft/ksoup/io/SourceExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.fleeksoft.ksoup.io

import korlibs.io.file.VfsFile
import korlibs.io.stream.*


fun SourceReader.Companion.from(byteArray: ByteArray): SourceReader = SourceReaderImpl(byteArray)
fun SourceReader.Companion.from(syncStream: SyncStream): SourceReader = SourceReaderImpl(syncStream)
suspend fun SourceReader.Companion.from(asyncInputStream: AsyncInputStream): SourceReader =
SourceReaderImpl(asyncInputStream.toAsyncStream().toSyncOrNull() ?: asyncInputStream.readAll().openSync())


fun FileSource.Companion.from(file: VfsFile): FileSource = FileSourceImpl(file)
fun FileSource.Companion.from(filePath: String): FileSource = FileSourceImpl(filePath)
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import korlibs.io.stream.SyncInputStream
import korlibs.io.stream.markable
import korlibs.io.stream.openSync
import korlibs.memory.buildByteArray
import kotlin.math.min


class SourceReaderAsyncImpl : SourceReader {
internal class SourceReaderAsyncImpl : SourceReader {
private val stream: MarkableSyncInputStream
private val buffer: KByteBuffer = KByteBuffer(8192)
private var markBuffer: KByteBuffer? = null
Expand All @@ -20,17 +19,6 @@ class SourceReaderAsyncImpl : SourceReader {

constructor(bytes: ByteArray) : this(bytes.openSync())

override fun skip(count: Long) {
var skippedBuffer = 0
if (buffer().available() > 0) {
skippedBuffer = min(buffer().available(), count.toInt())
buffer().skip(skippedBuffer)
}
if (skippedBuffer < count) {
stream.skip(count.toInt() - skippedBuffer)
}
}

override fun mark(readLimit: Long) {
markBuffer = buffer.clone()
stream.mark(readLimit.toInt())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import korlibs.io.stream.readAll
import korlibs.io.stream.readBytes


class SourceReaderImpl : SourceReader {
internal class SourceReaderImpl : SourceReader {
private val syncStream: SyncStream

constructor(syncStream: SyncStream) {
Expand All @@ -15,10 +15,6 @@ class SourceReaderImpl : SourceReader {

constructor(bytes: ByteArray) : this(bytes.openSync())

override fun skip(count: Long) {
syncStream.skip(count.toInt())
}

override fun mark(readLimit: Long) {
syncStream.mark(readLimit.toInt())
}
Expand All @@ -35,10 +31,6 @@ class SourceReaderImpl : SourceReader {
return syncStream.read(bytes, offset, length)
}

/*override fun availableRead(): Long {
return syncStream.availableRead
}*/

override fun readAllBytes(): ByteArray {
return syncStream.readAll()
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.fleeksoft.ksoup.io

import korlibs.io.file.std.toVfs
import java.io.File
import java.io.InputStream

fun FileSource.Companion.from(file: File): FileSource = FileSource.from(file.toVfs())
fun SourceReader.Companion.from(inputStream: InputStream): SourceReader = SourceReader.from(inputStream.readAllBytes())
6 changes: 3 additions & 3 deletions ksoup-engine-kotlinx/module.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
product:
type: lib
platforms: [jvm, js, wasm, android, linuxX64, linuxArm64, tvosArm64, tvosX64, tvosSimulatorArm64, macosX64, macosArm64, iosArm64, iosSimulatorArm64, iosX64, mingwX64]
platforms: [ jvm, js, wasm, android, linuxX64, linuxArm64, tvosArm64, tvosX64, tvosSimulatorArm64, macosX64, macosArm64, iosArm64, iosSimulatorArm64, iosX64, mingwX64 ]

apply: [ ../common.module-template.yaml ]

aliases:
- jvmAndAndroid: [jvm, android]
- jvmAndAndroid: [ jvm, android ]

dependencies:
- ../ksoup-engine-common
- $libs.kotlinx.io
- $libs.kotlinx.io: exported
- $libs.ktor.io
- $libs.ktor.http
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ object KsoupEngineImpl : KsoupEngine {
}

override fun openSourceReader(content: String, charset: Charset?): SourceReader {
return SourceReaderImpl(charset?.toByteArray(content) ?: content.encodeToByteArray())
return SourceReader.from(charset?.toByteArray(content) ?: content.encodeToByteArray())
}

override fun openSourceReader(byteArray: ByteArray): SourceReader {
return SourceReaderImpl(byteArray)
return SourceReader.from(byteArray)
}

override fun getUtf8Charset(): Charset {
Expand All @@ -27,6 +27,6 @@ object KsoupEngineImpl : KsoupEngine {
}

override fun pathToFileSource(path: String): FileSource {
return FileSourceImpl(path)
return FileSource.from(path)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import kotlinx.io.files.Path
import kotlinx.io.files.SystemFileSystem

class FileSourceImpl : FileSource {
val path: Path
private val path: Path

private val sourceBuffered by lazy { buffered() }

Expand All @@ -17,7 +17,7 @@ class FileSourceImpl : FileSource {
this.path = Path(filePath)
}

override suspend fun toSourceReader(): SourceReader = SourceReaderImpl(sourceBuffered)
override suspend fun toSourceReader(): SourceReader = SourceReader.from(sourceBuffered)

private fun FileSourceImpl.buffered() = SystemFileSystem.source(path).buffered()

Expand Down
Loading

0 comments on commit 33be625

Please sign in to comment.