Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.1.8 #81

Merged
merged 35 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
746f29f
add sonatype config
itboy87 Sep 3, 2024
b171f04
add micro amper gradle code
itboy87 Sep 3, 2024
783b78d
clean and minor tweak deps
itboy87 Sep 3, 2024
9a23bf6
tweak and refactor code
itboy87 Sep 3, 2024
23acc28
use SourceReader extension for network
itboy87 Sep 3, 2024
fdbe14d
update for micro amper
itboy87 Sep 3, 2024
0bf6a77
update wasm test
itboy87 Sep 3, 2024
f7cda1a
kotlin (2.0.20), agp (8.5.2) version bump
itboy87 Sep 3, 2024
dfcecff
publish script updated
itboy87 Sep 3, 2024
29f2ea4
test script updated
itboy87 Sep 3, 2024
86b1720
deploy update for publish script
itboy87 Sep 3, 2024
7c59357
fix test
itboy87 Sep 3, 2024
7283574
fix target for linux
itboy87 Sep 3, 2024
fe58ca0
fix script for windows
itboy87 Sep 4, 2024
61fd497
fix to use bash
itboy87 Sep 4, 2024
3af9c6a
charset support flag updated
itboy87 Sep 4, 2024
b7389ae
update kotlin version to 2.0.20
itboy87 Sep 4, 2024
f8d39e5
add common publish
itboy87 Sep 4, 2024
db0bc42
Merge remote-tracking branch 'origin/release' into develop
itboy87 Sep 9, 2024
53a7155
fix ktor2
itboy87 Sep 11, 2024
db3dae2
add dev build type
itboy87 Sep 11, 2024
fd223e7
Replace stately-concurrent-collections with stately-concurrency
itboy87 Sep 11, 2024
6f59027
Parse in quirksmode if no doctype html
itboy87 Sep 11, 2024
77c05be
For `has()` queries, always test children
itboy87 Sep 11, 2024
1af5450
Use a SoftPool of ElementIterators vs a single ThreadLocal
itboy87 Sep 11, 2024
a77b0c7
bump library version to 0.1.7 and ktor3 to 3.0.0-rc-1
itboy87 Sep 11, 2024
18dffa0
ktor3 to 3.0.0-rc-1
itboy87 Sep 11, 2024
6cf3b52
Fixes #65 (#73)
itboy87 Sep 11, 2024
c658745
Implement KMP CodePoint and remove external dependency (#75)
itboy87 Sep 12, 2024
f25b3c1
add ksoup-lite variant (#77)
itboy87 Sep 14, 2024
e8542c3
fix clock millis
itboy87 Sep 16, 2024
380b098
fix scripts for ksoup-lite
itboy87 Sep 17, 2024
c6365d9
bump library version to 0.1.8
itboy87 Sep 17, 2024
0f7be3c
add ksoup-lite
itboy87 Sep 17, 2024
c046ac5
Merge remote-tracking branch 'origin/release' into develop
itboy87 Sep 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jobs:
matrix:
buildType:
- "common"
- "lite"
- "kotlinx"
- "korlibs"
- "ktor2"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
{ target: windows, os: windows-latest, tasks: mingwX64Test, continueOnError: false },
{ target: linux, os: ubuntu-latest, tasks: linuxX64Test, continueOnError: false },
]
libBuildType: [ "korlibs", "kotlinx", "okio", "ktor2" ]
libBuildType: [ "lite", "korlibs", "kotlinx", "okio", "ktor2" ]
runs-on: ${{ matrix.config.os }}
name: Build ${{ matrix.config.target }} with libBuildType=${{ matrix.libBuildType }}
steps:
Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ Ksoup is adept at handling all varieties of HTML found in the wild.
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 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-rc-1](https://github.com/ktorio/ktor)**
1. **This variant is built without any external IO or Network dependencies. Use this if you want to parse HTML from a string.**
```kotlin
implementation("com.fleeksoft.ksoup:ksoup-lite:<version>")
```
2. **This variant built with [kotlinx-io](https://github.com/Kotlin/kotlinx-io) and [Ktor 3.0.0-rc-1](https://github.com/ktorio/ktor)**
```kotlin
implementation("com.fleeksoft.ksoup:ksoup:<version>")

Expand All @@ -41,7 +45,7 @@ Ksoup published in four variants. Pick the one that suits your needs and start b
implementation("com.fleeksoft.ksoup:ksoup-network:<version>")
```

2. **This variant is built with [korlibs-io](https://github.com/korlibs/korlibs-io)**
3. **This variant is built with [korlibs-io](https://github.com/korlibs/korlibs-io)**
```kotlin
implementation("com.fleeksoft.ksoup:ksoup-korlibs:<version>")

Expand All @@ -50,15 +54,15 @@ Ksoup published in four variants. Pick the one that suits your needs and start b
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)**
4. **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>")
```
4. **This variant built with [okio](https://github.com/square/okio) and [Ktor 2.3.12](https://github.com/ktorio/ktor)**
5. **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-okio:<version>")

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ android.nonTransitiveRClass=true
kotlin.native.ignoreIncorrectDependencies=true
kotlin.mpp.enableCInteropCommonization=true
kotlin.mpp.applyDefaultHierarchyTemplate=false
# dev, common, kotlinx, korlibs, okio, ktor2
# dev, common, lite, kotlinx, korlibs, okio, ktor2
# dev will include all modules in settings.gradle.kts but use kotlinx dep for engine
libBuildType=okio
libBuildType=lite


SONATYPE_HOST=CENTRAL_PORTAL
Expand Down
4 changes: 1 addition & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ agp = "8.5.2"
kotlin = "2.0.20"
compileSdk = "34"
minSdk = "21"
libraryVersion = "0.1.7"
libraryVersion = "0.1.8"
ktor = "3.0.0-rc-1"
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"

#korlibs = "999.0.0.999" # 999.0.0.999 is local version
Expand Down Expand Up @@ -43,7 +42,6 @@ ktor-client-js = { module = "io.ktor:ktor-client-js", version.ref = "ktor" }
ktor-client-win = { module = "io.ktor:ktor-client-winhttp", version.ref = "ktor" }
kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinxDatetime" }
kotlinx-io = { module = "org.jetbrains.kotlinx:kotlinx-io-core", version.ref = "kotlinx-io" }
codepoints = { module = "de.cketti.unicode:kotlin-codepoints-deluxe", version.ref = "codepoints" }
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-concurrency = { module = "co.touchlab:stately-concurrency", version.ref = "stately" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@ package com.fleeksoft.ksoup.engine

import com.fleeksoft.ksoup.io.Charset
import com.fleeksoft.ksoup.io.FileSource
import com.fleeksoft.ksoup.io.SourceReader

interface KsoupEngine {
fun urlResolveOrNull(base: String, relUrl: String): String?

fun openSourceReader(content: String, charset: Charset? = null): SourceReader

fun openSourceReader(byteArray: ByteArray): SourceReader

fun getUtf8Charset(): Charset

Expand Down
2 changes: 2 additions & 0 deletions ksoup-engine-common/src/com/fleeksoft/ksoup/io/Charset.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ interface Charset {

fun decode(stringBuilder: StringBuilder, byteArray: ByteArray, start: Int, end: Int): Int
fun toByteArray(value: String): ByteArray

fun onlyUtf8(): Boolean = false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.fleeksoft.ksoup.io

internal class SourceReaderByteArray(bytes: ByteArray) : SourceReader {
private var source: ByteArray = bytes
private var currentPosition: Int = 0
private var markedPosition: Int? = null
private var isClosed: Boolean = false

override fun mark(readLimit: Long) {
markedPosition = currentPosition
}

override fun reset() {
isClosed = false
markedPosition?.let {
currentPosition = it
markedPosition = null
}
}


override fun readBytes(count: Int): ByteArray {
val byteArray = ByteArray(count)
var i = 0
while (exhausted().not() && i < count) {
byteArray[i] = source[currentPosition++]
i++
}
return if (i == 0) {
byteArrayOf()
} else if (i != count) {
byteArray.sliceArray(0 until i)
} else {
byteArray
}
}

override fun read(bytes: ByteArray, offset: Int, length: Int): Int {
var i = offset
while (exhausted().not() && i < length) {
bytes[i] = source[currentPosition++]
i++
}
return i
}

override fun readAllBytes(): ByteArray {
return readBytes(source.size - currentPosition)
}

override fun exhausted(): Boolean {
return currentPosition >= source.size
}

override fun close() {
// on reset we need bytes again
// source = ByteArray(0)
// currentPosition = 0
// markedPosition = null
isClosed = true
}

override fun readAtMostTo(sink: KByteBuffer, byteCount: Int): Int {
val bytes = readBytes(byteCount)
sink.writeBytes(bytes, bytes.size)
return bytes.size
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.fleeksoft.ksoup.io

fun SourceReader.Companion.from(byteArray: ByteArray): SourceReader = SourceReaderByteArray(byteArray)
6 changes: 3 additions & 3 deletions ksoup-engine-korlibs/src/com/fleeksoft/ksoup/EngineExt.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.fleeksoft.ksoup

import com.fleeksoft.ksoup.engine.KsoupEngineImpl
import com.fleeksoft.ksoup.io.SourceReader
import com.fleeksoft.ksoup.io.from
import korlibs.io.compression.deflate.GZIP
import korlibs.io.compression.uncompress
import korlibs.io.file.VfsFile
Expand All @@ -16,8 +16,8 @@ suspend fun VfsFile.openStream(): SourceReader {
val zipped =
(byteArray.size == 2 && byteArray[0].toInt() == 31 && byteArray[1].toInt() == -117) // gzip magic bytes 31(0x1f), -117(0x1f)
if (zipped) {
return KsoupEngineImpl.openSourceReader(this.readAsSyncStream().readAll().uncompress(GZIP))
return SourceReader.from(this.readAsSyncStream().readAll().uncompress(GZIP))
}
}
return KsoupEngineImpl.openSourceReader(this.readAll())
return SourceReader.from(this.readAll())
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,8 @@ package com.fleeksoft.ksoup.engine

import com.fleeksoft.ksoup.io.*
import korlibs.io.lang.Charsets
import korlibs.io.net.URL

object KsoupEngineImpl : KsoupEngine {
override fun urlResolveOrNull(base: String, relUrl: String): String? {
return URL.resolveOrNull(base = base, access = relUrl)
}

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

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

override fun getUtf8Charset(): Charset {
return CharsetImpl(Charsets.UTF8)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ 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())
Expand Down
3 changes: 1 addition & 2 deletions ksoup-engine-kotlinx/module.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ aliases:
dependencies:
- ../ksoup-engine-common
- $libs.kotlinx.io: exported
- $libs.ktor.io
- $libs.ktor.http
- $libs.ktor.io
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@ import io.ktor.utils.io.charsets.*

object KsoupEngineImpl : KsoupEngine {

override fun urlResolveOrNull(base: String, relUrl: String): String? {
return URLUtil.urlResolveOrNull(base = base, relUrl = relUrl)
}

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

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

override fun getUtf8Charset(): Charset {
return CharsetImpl(Charsets.UTF_8)
}
Expand Down
Loading
Loading