Skip to content

Commit

Permalink
Usage of explicitApi() (#96)
Browse files Browse the repository at this point in the history
Usage of explicitApi() as recommended for libraries.

Resolves #95.
  • Loading branch information
StefanOltmann authored May 4, 2024
1 parent d3dac70 commit b5aff2e
Show file tree
Hide file tree
Showing 345 changed files with 3,597 additions and 2,983 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/.idea/deploymentTargetDropDown.xml
/.idea/gradle.xml
/.idea/jarRepositories.xml
/.idea/kim.iml
/.idea/kotlinScripting.xml
/.idea/kotlinc.xml
/.idea/libraries/
Expand All @@ -23,5 +24,4 @@
/.idea/workspace.xml
/build/
/local.properties
/.idea/kim.iml
/src/commonTest/resources/com/ashampoo/kim/testdata/full/*.html
1,018 changes: 793 additions & 225 deletions .idea/inspectionProfiles/Project_Default.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ of Ashampoo Photo Organizer, which, in turn, is driven by user community feedbac
## Installation

```
implementation("com.ashampoo:kim:0.17.7")
implementation("com.ashampoo:kim:0.18")
```

For the targets `wasmJs` & `js` you also need to specify this:
Expand Down
15 changes: 9 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ repositories {
mavenCentral()
}

val productName = "Ashampoo Kim"
val productName: String = "Ashampoo Kim"

val ktorVersion: String = "2.3.10"
val xmpCoreVersion: String = "1.2.2"
val xmpCoreVersion: String = "1.3.0"
val dateTimeVersion: String = "0.5.0"
val testRessourcesVersion: String = "0.4.0"
val kotlinxIoVersion: String = "0.3.3"
Expand Down Expand Up @@ -115,6 +115,8 @@ dependencies {

kotlin {

explicitApi()

androidTarget {

compilations.all {
Expand Down Expand Up @@ -333,6 +335,7 @@ kotlin {
macosArm64Test.dependsOn(this)
}

@Suppress("UnusedPrivateMember", "UNUSED_VARIABLE") // False positive
val jsMain by sourceSets.getting {

dependsOn(commonMain)
Expand Down Expand Up @@ -360,7 +363,7 @@ kotlin {
}

// region Writing version.txt for GitHub Actions
val writeVersion = tasks.register("writeVersion") {
val writeVersion: TaskProvider<Task> = tasks.register("writeVersion") {
doLast {
File("build/version.txt").writeText(project.version.toString())
}
Expand Down Expand Up @@ -404,7 +407,7 @@ ext["signing.secretKeyRingFile"] = "secring.pgp"
ext["ossrhUsername"] = System.getenv("OSSRH_USERNAME")
ext["ossrhPassword"] = System.getenv("OSSRH_PASSWORD")

val javadocJar by tasks.registering(Jar::class) {
val javadocJar: TaskProvider<Jar> by tasks.registering(Jar::class) {
archiveClassifier.set("javadoc")
}

Expand Down Expand Up @@ -485,7 +488,7 @@ afterEvaluate {
}
}

fun getExtraString(name: String) = ext[name]?.toString()
fun getExtraString(name: String): String? = ext[name]?.toString()

publishing {
publications {
Expand Down Expand Up @@ -515,7 +518,7 @@ publishing {
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
}
}

Expand Down
2 changes: 1 addition & 1 deletion detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ style:
RedundantHigherOrderMapUsage:
active: true
RedundantVisibilityModifierRule:
active: true
active: false # explicitApi
ReturnCount:
active: false # results in bad style
max: 2
Expand Down
2 changes: 1 addition & 1 deletion examples/kim-java-sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repositories {
}

dependencies {
implementation 'com.ashampoo:kim:0.17.7'
implementation 'com.ashampoo:kim:0.18'
}

// Needed to make it work for the Gradle java plugin
Expand Down
2 changes: 1 addition & 1 deletion examples/kim-java-sample/src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import com.ashampoo.kim.Kim;
import com.ashampoo.kim.jvm.KimJvm;
import com.ashampoo.kim.format.ImageMetadata;
import com.ashampoo.kim.input.ByteReader;
import com.ashampoo.kim.input.JvmInputStreamByteReader;
import com.ashampoo.kim.jvm.KimJvm;
import com.ashampoo.kim.model.MetadataUpdate;
import com.ashampoo.kim.output.ByteArrayByteWriter;

Expand Down
2 changes: 1 addition & 1 deletion examples/kim-kotlin-jvm-sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ repositories {
}

dependencies {
implementation("com.ashampoo:kim:0.17.7")
implementation("com.ashampoo:kim:0.18")
}
1 change: 0 additions & 1 deletion examples/kim-kotlin-jvm-sample/src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import com.ashampoo.kim.input.JvmInputStreamByteReader
import com.ashampoo.kim.input.KotlinIoSourceByteReader
import com.ashampoo.kim.input.use
import com.ashampoo.kim.jvm.readMetadata
import com.ashampoo.kim.kotlinx.KimKotlinx
import com.ashampoo.kim.model.MetadataUpdate
import com.ashampoo.kim.output.ByteArrayByteWriter
import com.ashampoo.kim.output.OutputStreamByteWriter
Expand Down
14 changes: 7 additions & 7 deletions src/androidMain/kotlin/com/ashampoo/kim/android/KimAndroid.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ import java.io.InputStream
/**
* Extra object to have a nicer API for Java projects
*/
object KimAndroid {
public object KimAndroid {

@JvmStatic
@Throws(ImageReadException::class)
fun readMetadata(inputStream: InputStream, length: Long): ImageMetadata? =
public fun readMetadata(inputStream: InputStream, length: Long): ImageMetadata? =
Kim.readMetadata(AndroidInputStreamByteReader(inputStream, length))

@JvmStatic
@Throws(ImageReadException::class)
fun readMetadata(path: String): ImageMetadata? =
public fun readMetadata(path: String): ImageMetadata? =
readMetadata(File(path))

@JvmStatic
@Throws(ImageReadException::class)
fun readMetadata(file: File): ImageMetadata? {
public fun readMetadata(file: File): ImageMetadata? {

check(file.exists()) { "File does not exist: $file" }

Expand All @@ -48,13 +48,13 @@ object KimAndroid {
}

@Throws(ImageReadException::class)
fun Kim.readMetadata(inputStream: InputStream, length: Long): ImageMetadata? =
public fun Kim.readMetadata(inputStream: InputStream, length: Long): ImageMetadata? =
KimAndroid.readMetadata(inputStream, length)

@Throws(ImageReadException::class)
fun Kim.readMetadata(path: String): ImageMetadata? =
public fun Kim.readMetadata(path: String): ImageMetadata? =
KimAndroid.readMetadata(path)

@Throws(ImageReadException::class)
fun Kim.readMetadata(file: File): ImageMetadata? =
public fun Kim.readMetadata(file: File): ImageMetadata? =
KimAndroid.readMetadata(file)
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import java.util.zip.Inflater

private const val ZLIB_BUFFER_SIZE: Int = 1024

actual fun compress(input: String): ByteArray {
internal actual fun compress(input: String): ByteArray {

val deflater = Deflater()
val inputBytes = input.toByteArray()
Expand All @@ -45,7 +45,7 @@ actual fun compress(input: String): ByteArray {
return outputStream.toByteArray()
}

actual fun decompress(byteArray: ByteArray): String {
internal actual fun decompress(byteArray: ByteArray): String {

val inflater = Inflater()
val outputStream = ByteArrayOutputStream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import java.io.InputStream
* Provides way to read from Android ContentReolver that
* should work on all versions.
*/
open class AndroidInputStreamByteReader(
public open class AndroidInputStreamByteReader(
private val inputStream: InputStream,
override val contentLength: Long
) : ByteReader {
Expand Down Expand Up @@ -54,6 +54,6 @@ open class AndroidInputStreamByteReader(
buffer.slice(startIndex = 0, count = count)
}

override fun close() =
override fun close(): Unit =
inputStream.close()
}
10 changes: 5 additions & 5 deletions src/appleMain/kotlin/com/ashampoo/kim/apple/KimApple.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ import platform.posix.memcpy
/**
* Extra object to be aligned with the other modules.
*/
object KimApple {
public object KimApple {

@Throws(ImageReadException::class)
fun readMetadata(data: NSData): ImageMetadata? =
public fun readMetadata(data: NSData): ImageMetadata? =
Kim.readMetadata(ByteArrayByteReader(convertDataToByteArray(data)))

@Throws(ImageReadException::class)
fun readMetadata(path: String): ImageMetadata? {
public fun readMetadata(path: String): ImageMetadata? {

val fileBytes = readFileAsByteArray(path) ?: return null

Expand All @@ -45,11 +45,11 @@ object KimApple {
}

@Throws(ImageReadException::class)
fun Kim.readMetadata(data: NSData): ImageMetadata? =
public fun Kim.readMetadata(data: NSData): ImageMetadata? =
KimApple.readMetadata(data)

@Throws(ImageReadException::class)
fun Kim.readMetadata(path: String): ImageMetadata? =
public fun Kim.readMetadata(path: String): ImageMetadata? =
KimApple.readMetadata(path)

@OptIn(ExperimentalForeignApi::class)
Expand Down
20 changes: 10 additions & 10 deletions src/commonMain/kotlin/com/ashampoo/kim/Kim.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ import com.ashampoo.kim.model.MetadataUpdate
import com.ashampoo.kim.output.ByteArrayByteWriter
import com.ashampoo.kim.output.ByteWriter

object Kim {
public object Kim {

var underUnitTesting: Boolean = false
internal var underUnitTesting: Boolean = false

@kotlin.jvm.JvmStatic
@Throws(ImageReadException::class)
fun readMetadata(bytes: ByteArray): ImageMetadata? =
public fun readMetadata(bytes: ByteArray): ImageMetadata? =
if (bytes.isEmpty())
null
else
readMetadata(ByteArrayByteReader(bytes))

@kotlin.jvm.JvmStatic
@Throws(ImageReadException::class)
fun readMetadata(
public fun readMetadata(
byteReader: ByteReader
): ImageMetadata? = tryWithImageReadException {

Expand Down Expand Up @@ -93,7 +93,7 @@ object Kim {
*/
@kotlin.jvm.JvmStatic
@Throws(ImageReadException::class)
fun extractMetadataBytes(
public fun extractMetadataBytes(
byteReader: ByteReader
): Pair<ImageFormat?, ByteArray> = tryWithImageReadException {

Expand All @@ -116,7 +116,7 @@ object Kim {

@kotlin.jvm.JvmStatic
@Throws(ImageReadException::class)
fun extractPreviewImage(
public fun extractPreviewImage(
byteReader: ByteReader
): ByteArray? = tryWithImageReadException {

Expand Down Expand Up @@ -166,7 +166,7 @@ object Kim {
*/
@kotlin.jvm.JvmStatic
@Throws(ImageWriteException::class)
fun update(
public fun update(
bytes: ByteArray,
update: MetadataUpdate
): ByteArray = tryWithImageWriteException {
Expand All @@ -192,11 +192,11 @@ object Kim {
*/
@kotlin.jvm.JvmStatic
@Throws(ImageWriteException::class)
fun update(
public fun update(
byteReader: ByteReader,
byteWriter: ByteWriter,
update: MetadataUpdate
) = tryWithImageWriteException {
): Unit = tryWithImageWriteException {

val headerBytes = byteReader.readBytes(ImageFormat.REQUIRED_HEADER_BYTE_COUNT_FOR_DETECTION)

Expand All @@ -216,7 +216,7 @@ object Kim {

@kotlin.jvm.JvmStatic
@Throws(ImageWriteException::class)
fun updateThumbnail(
public fun updateThumbnail(
bytes: ByteArray,
thumbnailBytes: ByteArray
): ByteArray = tryWithImageWriteException {
Expand Down
Loading

0 comments on commit b5aff2e

Please sign in to comment.