Skip to content

Commit

Permalink
Merge pull request #24 from fleeksoft/develop
Browse files Browse the repository at this point in the history
Release 0.1.2
  • Loading branch information
itboy87 authored Dec 24, 2023
2 parents 7983b95 + 5a25f64 commit 80515b6
Show file tree
Hide file tree
Showing 36 changed files with 278 additions and 257 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ jobs:
strategy:
matrix:
config: [
{ target: android, os: ubuntu-latest, tasks: testDebugUnitTest, continueOnError: false },
{ target: apple, os: macos-latest, tasks: iosX64Test iosSimulatorArm64Test, continueOnError: false },
{ target: android, os: ubuntu-latest, tasks: testDebugUnitTest testReleaseUnitTest, continueOnError: false },
{ target: apple, os: macos-latest, tasks: iosX64Test iosSimulatorArm64Test macosX64Test macosArm64Test tvosX64Test tvosSimulatorArm64Test watchosX64Test watchosSimulatorArm64Test, continueOnError: false },
{ target: nodejs, os: ubuntu-latest, tasks: jsNodeTest, continueOnError: false },
{ target: desktop, os: ubuntu-latest, tasks: jvmTest, continueOnError: false },
{ target: windows, os: windows-latest, tasks: mingwX64Test, continueOnError: false },
]
runs-on: ${{ matrix.config.os }}
name: Build ${{ matrix.config.target }}
Expand All @@ -36,7 +37,7 @@ jobs:

- name: Test ${{ matrix.config.target }} targets
continue-on-error: ${{ matrix.config.continueOnError }}
run: ./gradlew ${{ matrix.config.tasks }}
run: ./gradlew ${{ matrix.config.tasks }} --info
working-directory: ${{ github.workspace }}

release:
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

**Ksoup** is a Kotlin Multiplatform library for working with real-world HTML and XML. It's a port of the renowned Java library, **jsoup**, and offers an easy-to-use API for URL fetching, data parsing, extraction, and manipulation using DOM and CSS selectors.

[![Kotlin](https://img.shields.io/badge/Kotlin-1.9.21-blue.svg?style=flat&logo=kotlin)](https://kotlinlang.org)
[![Kotlin](https://img.shields.io/badge/Kotlin-1.9.22-blue.svg?style=flat&logo=kotlin)](https://kotlinlang.org)
[![Maven Central](https://img.shields.io/maven-central/v/com.fleeksoft.ksoup/ksoup.svg)](https://mvnrepository.com/artifact/com.fleeksoft.ksoup)

![badge-android](http://img.shields.io/badge/platform-android-6EDB8D.svg?style=flat)
Expand Down Expand Up @@ -86,8 +86,9 @@ To report any issues, visit our [GitHub issues](https://github.com/fleeksoft/kso
| iOS | Alpha | Does not support few charsets. |
| Linux | Experimental | Does not support gzip files and few charsets. |
| JS | Alpha | Does not support few charsets. |
| Native MacOS | Coming Soon | |
| Native Windows | Coming Soon | |
| Native MacOS | Alpha | |
| Native Windows | Experimental | Does not support gzip file. |
| Wasm | Coming Soon | |



Expand Down
9 changes: 5 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[versions]
agp = "8.1.3"
kotlin = "1.9.21"
agp = "8.2.0"
kotlin = "1.9.22"
compileSdk = "34"
minSdk = "21"
libraryVersion = "0.1.1"
libraryVersion = "0.1.2"
ktor = "2.3.7"
coroutines = "1.7.3"
okio = "3.6.0"
okio = "3.7.0"
kotlinxDatetime = "0.5.0"
kotlinx-io = "0.3.0"
codepoints = "0.6.1"
Expand All @@ -22,6 +22,7 @@ ktor-client-darwin = { module = "io.ktor:ktor-client-darwin", version.ref = "kto
ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" }
ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" }
ktor-client-js = { module = "io.ktor:ktor-client-js", version.ref = "ktor" }
ktor-client-win = { module = "io.ktor:ktor-client-winhttp", version.ref = "ktor" }
okio = { module = "com.squareup.okio:okio", version.ref = "okio" }
okio-nodefilesystem = { module = "com.squareup.okio:okio-nodefilesystem", version.ref = "okio" }
kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinxDatetime" }
Expand Down
23 changes: 21 additions & 2 deletions ksoup-network/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
id("signing")
}

group = "com.fleeksoft.ksoup.network"
group = "com.fleeksoft.ksoup"
version = libs.versions.libraryVersion.get()

kotlin {
Expand All @@ -23,6 +23,11 @@ kotlin {
linuxX64()
linuxArm64()

macosX64()
macosArm64()

mingwX64()

androidTarget {
compilations.all {
kotlinOptions {
Expand All @@ -35,6 +40,14 @@ kotlin {
iosX64(),
iosArm64(),
iosSimulatorArm64(),
macosX64(),
macosArm64(),
tvosX64(),
tvosArm64(),
tvosSimulatorArm64(),
watchosX64(),
watchosArm64(),
watchosSimulatorArm64(),
).forEach {
it.binaries.framework {
baseName = "ksoup-network"
Expand Down Expand Up @@ -72,7 +85,7 @@ kotlin {
}
}

iosMain {
appleMain {
dependsOn(nonJsMain)
dependencies {
implementation(libs.ktor.client.darwin)
Expand All @@ -89,6 +102,12 @@ kotlin {
jsMain.dependencies {
implementation(libs.ktor.client.js)
}

mingwMain {
dependencies {
implementation(libs.ktor.client.win)
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
package com.fleeksoft.ksoup.network

import io.ktor.client.HttpClient
import io.ktor.client.plugins.*
import io.ktor.client.plugins.observer.*
import io.ktor.client.*
import io.ktor.client.request.*
import io.ktor.client.request.forms.submitForm
import io.ktor.client.statement.HttpResponse
import io.ktor.http.parameters
import io.ktor.utils.io.core.*
import io.ktor.client.request.forms.*
import io.ktor.client.statement.*
import io.ktor.http.*

internal class NetworkHelper(private val client: HttpClient) {
companion object {
val instance: NetworkHelper =
NetworkHelper(
HttpClient(provideHttpClientEngine()) {
this.followRedirects = true
/*this.ResponseObserver {
println("headers => ${it.headers}")
}*/
},
)
}
Expand Down

This file was deleted.

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

import io.ktor.client.engine.*
import io.ktor.client.engine.winhttp.*

internal actual fun provideHttpClientEngine(): HttpClientEngine {
return WinHttp.create()
}
21 changes: 16 additions & 5 deletions ksoup/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ kotlin {
linuxX64()
linuxArm64()

mingwX64()

androidTarget {
compilations.all {
kotlinOptions {
Expand All @@ -37,6 +39,14 @@ kotlin {
iosX64(),
iosArm64(),
iosSimulatorArm64(),
macosX64(),
macosArm64(),
tvosX64(),
tvosArm64(),
tvosSimulatorArm64(),
watchosX64(),
watchosArm64(),
watchosSimulatorArm64(),
).forEach {
it.binaries.framework {
baseName = "ksoup"
Expand Down Expand Up @@ -70,7 +80,7 @@ kotlin {
androidMain.dependencies {
}

iosMain.dependencies {
appleMain.dependencies {
}

jsMain.dependencies {
Expand Down Expand Up @@ -178,8 +188,8 @@ signing {
project.tasks.withType(AbstractPublishToMaven::class.java).configureEach {
dependsOn(project.tasks.withType(Sign::class.java))
}

val generateRootPathSource: Task by tasks.creating {
val isGithubActions: Boolean = System.getenv("GITHUB_ACTIONS")?.toBoolean() == true
val generateBuildConfigFile: Task by tasks.creating {
group = "build setup"
val file = layout.buildDirectory.file("$rootPath/BuildConfig.kt")
outputs.file(file)
Expand All @@ -191,14 +201,15 @@ val generateRootPathSource: Task by tasks.creating {
object BuildConfig {
const val PROJECT_ROOT: String = "${rootProject.rootDir.absolutePath.replace("\\", "\\\\")}"
const val isGithubActions: Boolean = $isGithubActions
}
""".trimIndent()
file.get().asFile.writeText(content)
}
}

tasks.all {
if (name != "generateRootPathSource" && !name.contains("publish", ignoreCase = true)) {
dependsOn("generateRootPathSource")
if (name != generateBuildConfigFile.name && !name.contains("publish", ignoreCase = true)) {
dependsOn(generateBuildConfigFile.name)
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package com.fleeksoft.ksoup

import okio.Buffer
import okio.BufferedSource
import okio.FileSystem
import okio.Path
import okio.buffer
import okio.*

internal actual fun readGzipFile(file: Path): BufferedSource {
// TODO: optimize for BufferedSource without reading all bytes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,23 @@
@file:OptIn(ExperimentalForeignApi::class, ExperimentalForeignApi::class)
@file:OptIn(ExperimentalForeignApi::class, ExperimentalNativeApi::class)

package com.fleeksoft.ksoup

import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.addressOf
import kotlinx.cinterop.alloc
import kotlinx.cinterop.allocArray
import kotlinx.cinterop.memScoped
import kotlinx.cinterop.ptr
import kotlinx.cinterop.reinterpret
import kotlinx.cinterop.usePinned
import kotlinx.cinterop.*
import platform.darwin.ByteVar
import platform.posix.memcpy
import platform.zlib.MAX_WBITS
import platform.zlib.Z_NO_FLUSH
import platform.zlib.Z_OK
import platform.zlib.Z_STREAM_END
import platform.zlib.inflate
import platform.zlib.inflateEnd
import platform.zlib.inflateInit2
import platform.zlib.z_stream
import platform.zlib.*
import kotlin.experimental.ExperimentalNativeApi

internal fun decompressGzip(input: ByteArray): ByteArray {
val inputSize = input.size.toULong()
val inputSize = input.size

memScoped {
val inputPtr = allocArray<ByteVar>(inputSize.toInt())
input.usePinned { pinned ->
memcpy(inputPtr, pinned.addressOf(0), inputSize)
val inputPtr = allocArray<ByteVar>(inputSize)
for (i in 0 until inputSize) {
inputPtr[i] = input.getUByteAt(i)
}
/*input.usePinned { pinned ->
memcpy(inputPtr, pinned.addressOf(0), inputSize.toULong())
}*/

val strm = alloc<z_stream>()
strm.next_in = inputPtr
Expand Down
13 changes: 11 additions & 2 deletions ksoup/src/commonMain/kotlin/com/fleeksoft/ksoup/Platform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ internal expect fun readGzipFile(file: Path): BufferedSource
internal expect fun readFile(file: Path): BufferedSource

// js don't support ?i
// TODO: may be check this for js only and replace it
internal fun jsSupportedRegex(regex: String): Regex {
return if (regex.contains("(?i)")) {
return if (Platform.current == PlatformType.JS && regex.contains("(?i)")) {
Regex(regex.replace("(?i)", ""), RegexOption.IGNORE_CASE)
} else {
Regex(regex)
Expand All @@ -23,8 +22,18 @@ public enum class PlatformType {
IOS,
LINUX,
JS,
MAC,
WINDOWS,
}

public expect object Platform {
public val current: PlatformType
}

public fun Platform.isApple(): Boolean = this.current == PlatformType.IOS || this.current == PlatformType.MAC

public fun Platform.isWindows(): Boolean = this.current == PlatformType.WINDOWS

public fun Platform.isJvmOrAndroid(): Boolean = this.current == PlatformType.JVM || this.current == PlatformType.ANDROID

public fun Platform.isJvm(): Boolean = this.current == PlatformType.JVM
Loading

0 comments on commit 80515b6

Please sign in to comment.