Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.0.2"
".": "0.0.3"
}
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 5
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cas-parser%2Fcas-parser-b7fdba3d3f97c7debc22c7ca30b828bce81bcd64648df8c94029b27a3321ebb9.yml
openapi_spec_hash: 03f1315f1d32ada42445ca920f047dff
config_hash: 0e1291f316b20497ad29b59a231a8680
config_hash: cb5d75abef6264b5d86448caf7295afa
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## 0.0.3 (2025-08-22)

Full Changelog: [v0.0.2...v0.0.3](https://github.com/CASParser/cas-parser-java/compare/v0.0.2...v0.0.3)

### Chores

* **ci:** reduce log noise ([b66b3f9](https://github.com/CASParser/cas-parser-java/commit/b66b3f9da67d09730f90fc863a3aa05bd54d1b14))
* **client:** refactor closing / shutdown ([a96f2f2](https://github.com/CASParser/cas-parser-java/commit/a96f2f22d6b5e36631fd79ad19e71b45c33a1402))
* **internal:** fix multipart tests ([c564310](https://github.com/CASParser/cas-parser-java/commit/c56431084f5366b0b5887619ca0e1e4c44fe6e6c))
* **internal:** support running formatters directly ([aec2ce4](https://github.com/CASParser/cas-parser-java/commit/aec2ce4f099cfebef00d9357a1c1cc8280caa83b))

## 0.0.2 (2025-08-18)

Full Changelog: [v0.0.1...v0.0.2](https://github.com/CASParser/cas-parser-java/compare/v0.0.1...v0.0.2)
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<!-- x-release-please-start-version -->

[![Maven Central](https://img.shields.io/maven-central/v/com.cas_parser.api/cas-parser-java)](https://central.sonatype.com/artifact/com.cas_parser.api/cas-parser-java/0.0.2)
[![javadoc](https://javadoc.io/badge2/com.cas_parser.api/cas-parser-java/0.0.2/javadoc.svg)](https://javadoc.io/doc/com.cas_parser.api/cas-parser-java/0.0.2)
[![Maven Central](https://img.shields.io/maven-central/v/com.cas_parser.api/cas-parser-java)](https://central.sonatype.com/artifact/com.cas_parser.api/cas-parser-java/0.0.3)
[![javadoc](https://javadoc.io/badge2/com.cas_parser.api/cas-parser-java/0.0.3/javadoc.svg)](https://javadoc.io/doc/com.cas_parser.api/cas-parser-java/0.0.3)

<!-- x-release-please-end -->

Expand All @@ -13,7 +13,7 @@ It is generated with [Stainless](https://www.stainless.com/).

<!-- x-release-please-start-version -->

The REST API documentation can be found on [docs.casparser.in](https://docs.casparser.in/reference). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.cas_parser.api/cas-parser-java/0.0.2).
The REST API documentation can be found on [docs.casparser.in](https://docs.casparser.in/reference). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.cas_parser.api/cas-parser-java/0.0.3).

<!-- x-release-please-end -->

Expand All @@ -24,7 +24,7 @@ The REST API documentation can be found on [docs.casparser.in](https://docs.casp
### Gradle

```kotlin
implementation("com.cas_parser.api:cas-parser-java:0.0.2")
implementation("com.cas_parser.api:cas-parser-java:0.0.3")
```

### Maven
Expand All @@ -33,7 +33,7 @@ implementation("com.cas_parser.api:cas-parser-java:0.0.2")
<dependency>
<groupId>com.cas_parser.api</groupId>
<artifactId>cas-parser-java</artifactId>
<version>0.0.2</version>
<version>0.0.3</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repositories {

allprojects {
group = "com.cas_parser.api"
version = "0.0.2" // x-release-please-version
version = "0.0.3" // x-release-please-version
}

subprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class CasParserClientAsyncImpl(private val clientOptions: ClientOptions) : CasPa

override fun casGenerator(): CasGeneratorServiceAsync = casGenerator

override fun close() = clientOptions.httpClient.close()
override fun close() = clientOptions.close()

class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) :
CasParserClientAsync.WithRawResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class CasParserClientImpl(private val clientOptions: ClientOptions) : CasParserC

override fun casGenerator(): CasGeneratorService = casGenerator

override fun close() = clientOptions.httpClient.close()
override fun close() = clientOptions.close()

class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) :
CasParserClient.WithRawResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ private constructor(
* The HTTP client to use in the SDK.
*
* Use the one published in `cas-parser-java-client-okhttp` or implement your own.
*
* This class takes ownership of the client and closes it when closed.
*/
@get:JvmName("httpClient") val httpClient: HttpClient,
/**
Expand Down Expand Up @@ -157,6 +159,8 @@ private constructor(
* The HTTP client to use in the SDK.
*
* Use the one published in `cas-parser-java-client-okhttp` or implement your own.
*
* This class takes ownership of the client and closes it when closed.
*/
fun httpClient(httpClient: HttpClient) = apply {
this.httpClient = PhantomReachableClosingHttpClient(httpClient)
Expand Down Expand Up @@ -404,4 +408,18 @@ private constructor(
)
}
}

/**
* Closes these client options, relinquishing any underlying resources.
*
* This is purposefully not inherited from [AutoCloseable] because the client options are
* long-lived and usually should not be synchronously closed via try-with-resources.
*
* It's also usually not necessary to call this method at all. the default client automatically
* releases threads and connections if they remain idle, but if you are writing an application
* that needs to aggressively release unused resources, then you may call this method.
*/
fun close() {
httpClient.close()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.cas_parser.api.core

import java.util.concurrent.Callable
import java.util.concurrent.ExecutorService
import java.util.concurrent.Future
import java.util.concurrent.TimeUnit

/**
* A delegating wrapper around an [ExecutorService] that shuts it down once it's only phantom
* reachable.
*
* This class ensures the [ExecutorService] is shut down even if the user forgets to do it.
*/
internal class PhantomReachableExecutorService(private val executorService: ExecutorService) :
ExecutorService {
init {
closeWhenPhantomReachable(this) { executorService.shutdown() }
}

override fun execute(command: Runnable) = executorService.execute(command)

override fun shutdown() = executorService.shutdown()

override fun shutdownNow(): MutableList<Runnable> = executorService.shutdownNow()

override fun isShutdown(): Boolean = executorService.isShutdown

override fun isTerminated(): Boolean = executorService.isTerminated

override fun awaitTermination(timeout: Long, unit: TimeUnit): Boolean =
executorService.awaitTermination(timeout, unit)

override fun <T : Any?> submit(task: Callable<T>): Future<T> = executorService.submit(task)

override fun <T : Any?> submit(task: Runnable, result: T): Future<T> =
executorService.submit(task, result)

override fun submit(task: Runnable): Future<*> = executorService.submit(task)

override fun <T : Any?> invokeAll(
tasks: MutableCollection<out Callable<T>>
): MutableList<Future<T>> = executorService.invokeAll(tasks)

override fun <T : Any?> invokeAll(
tasks: MutableCollection<out Callable<T>>,
timeout: Long,
unit: TimeUnit,
): MutableList<Future<T>> = executorService.invokeAll(tasks, timeout, unit)

override fun <T : Any?> invokeAny(tasks: MutableCollection<out Callable<T>>): T =
executorService.invokeAny(tasks)

override fun <T : Any?> invokeAny(
tasks: MutableCollection<out Callable<T>>,
timeout: Long,
unit: TimeUnit,
): T = executorService.invokeAny(tasks, timeout, unit)
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,6 @@ internal class CasParserCamsKfintechParamsTest {

val body = params._body()

assertThat(body.filterValues { !it.value.isNull() })
.usingRecursiveComparison()
// TODO(AssertJ): Replace this and the `mapValues` below with:
// https://github.com/assertj/assertj/issues/3165
.withEqualsForType(
{ a, b -> a.readBytes() contentEquals b.readBytes() },
InputStream::class.java,
)
.isEqualTo(
mapOf().mapValues { (_, field) ->
field.map { (it as? ByteArray)?.inputStream() ?: it }
}
)
assertThat(body.filterValues { !it.value.isNull() }).isEmpty()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,6 @@ internal class CasParserCdslParamsTest {

val body = params._body()

assertThat(body.filterValues { !it.value.isNull() })
.usingRecursiveComparison()
// TODO(AssertJ): Replace this and the `mapValues` below with:
// https://github.com/assertj/assertj/issues/3165
.withEqualsForType(
{ a, b -> a.readBytes() contentEquals b.readBytes() },
InputStream::class.java,
)
.isEqualTo(
mapOf().mapValues { (_, field) ->
field.map { (it as? ByteArray)?.inputStream() ?: it }
}
)
assertThat(body.filterValues { !it.value.isNull() }).isEmpty()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,6 @@ internal class CasParserNsdlParamsTest {

val body = params._body()

assertThat(body.filterValues { !it.value.isNull() })
.usingRecursiveComparison()
// TODO(AssertJ): Replace this and the `mapValues` below with:
// https://github.com/assertj/assertj/issues/3165
.withEqualsForType(
{ a, b -> a.readBytes() contentEquals b.readBytes() },
InputStream::class.java,
)
.isEqualTo(
mapOf().mapValues { (_, field) ->
field.map { (it as? ByteArray)?.inputStream() ?: it }
}
)
assertThat(body.filterValues { !it.value.isNull() }).isEmpty()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,6 @@ internal class CasParserSmartParseParamsTest {

val body = params._body()

assertThat(body.filterValues { !it.value.isNull() })
.usingRecursiveComparison()
// TODO(AssertJ): Replace this and the `mapValues` below with:
// https://github.com/assertj/assertj/issues/3165
.withEqualsForType(
{ a, b -> a.readBytes() contentEquals b.readBytes() },
InputStream::class.java,
)
.isEqualTo(
mapOf().mapValues { (_, field) ->
field.map { (it as? ByteArray)?.inputStream() ?: it }
}
)
assertThat(body.filterValues { !it.value.isNull() }).isEmpty()
}
}
2 changes: 0 additions & 2 deletions cas-parser-java-proguard-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ val proguardJar by tasks.registering(proguard.gradle.ProGuardTask::class) {
outjars(proguardJarPath)
printmapping("${layout.buildDirectory.get()}/proguard-mapping.txt")

dontwarn()

val javaHome = System.getProperty("java.home")
if (System.getProperty("java.version").startsWith("1.")) {
// Before Java 9, the runtime classes were packaged in a single jar file.
Expand Down
1 change: 1 addition & 0 deletions cas-parser-java-proguard-test/test.pro
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
-keep class org.junit.** { *; }

# Many warnings don't apply for our testing purposes.
-dontnote
-dontwarn
17 changes: 15 additions & 2 deletions scripts/format
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,18 @@ set -e

cd "$(dirname "$0")/.."

echo "==> Running formatters"
./gradlew format
if command -v ktfmt &> /dev/null; then
echo "==> Running ktfmt"
./scripts/kotlin-format
else
echo "==> Running gradlew formatKotlin"
./gradlew formatKotlin
fi

if command -v palantir-java-format &> /dev/null; then
echo "==> Running palantir-java-format"
./scripts/java-format
else
echo "==> Running gradlew formatJava"
./gradlew formatJava
fi
7 changes: 7 additions & 0 deletions scripts/java-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -e

cd "$(dirname "$0")/.."

find . -name "*.java" -not -path "./buildSrc/build/*" -print0 | xargs -0 -r palantir-java-format --palantir --replace "$@"
7 changes: 7 additions & 0 deletions scripts/kotlin-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -e

cd "$(dirname "$0")/.."

find . -name "*.kt" -not -path "./buildSrc/build/*" -print0 | xargs -0 -r ktfmt --kotlinlang-style "$@"
17 changes: 16 additions & 1 deletion scripts/lint
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,19 @@ set -e
cd "$(dirname "$0")/.."

echo "==> Running lints"
./gradlew lint

if command -v ktfmt &> /dev/null; then
echo "==> Checking ktfmt"
./scripts/kotlin-format --dry-run --set-exit-if-changed
else
echo "==> Running gradlew lintKotlin"
./gradlew lintKotlin
fi

if command -v palantir-java-format &> /dev/null; then
echo "==> Checking palantir-java-format"
./scripts/java-format --dry-run --set-exit-if-changed
else
echo "==> Running gradlew lintJava"
./gradlew lintJava
fi
Loading