Skip to content

Commit 76d269d

Browse files
chore(internal): codegen related update
1 parent b42e5bb commit 76d269d

File tree

444 files changed

+13811
-3519
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

444 files changed

+13811
-3519
lines changed

.github/workflows/ci.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,31 @@ jobs:
3636

3737
- name: Run lints
3838
run: ./scripts/lint
39+
40+
build:
41+
timeout-minutes: 15
42+
name: build
43+
runs-on: ${{ github.repository == 'stainless-sdks/orb-java' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
44+
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork
45+
46+
steps:
47+
- uses: actions/checkout@v4
48+
49+
- name: Set up Java
50+
uses: actions/setup-java@v4
51+
with:
52+
distribution: temurin
53+
java-version: |
54+
8
55+
21
56+
cache: gradle
57+
58+
- name: Set up Gradle
59+
uses: gradle/actions/setup-gradle@v4
60+
61+
- name: Build SDK
62+
run: ./scripts/build
63+
3964
test:
4065
timeout-minutes: 15
4166
name: test

.github/workflows/publish-sonatype.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
export -- GPG_SIGNING_KEY_ID
3434
printenv -- GPG_SIGNING_KEY | gpg --batch --passphrase-fd 3 --import 3<<< "$GPG_SIGNING_PASSWORD"
3535
GPG_SIGNING_KEY_ID="$(gpg --with-colons --list-keys | awk -F : -- '/^pub:/ { getline; print "0x" substr($10, length($10) - 7) }')"
36-
./gradlew publishAndReleaseToMavenCentral -Dorg.gradle.jvmargs="-Xmx8g" --stacktrace -PmavenCentralUsername="$SONATYPE_USERNAME" -PmavenCentralPassword="$SONATYPE_PASSWORD" --no-configuration-cache
36+
./gradlew publishAndReleaseToMavenCentral --stacktrace -PmavenCentralUsername="$SONATYPE_USERNAME" -PmavenCentralPassword="$SONATYPE_PASSWORD" --no-configuration-cache
3737
env:
3838
SONATYPE_USERNAME: ${{ secrets.ORB_SONATYPE_USERNAME || secrets.SONATYPE_USERNAME }}
3939
SONATYPE_PASSWORD: ${{ secrets.ORB_SONATYPE_PASSWORD || secrets.SONATYPE_PASSWORD }}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
.gradle
33
.idea
44
.kotlin
5-
build
5+
build/
66
codegen.log
77
kls_database.db

build.gradle.kts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,15 @@ allprojects {
22
group = "com.withorb.api"
33
version = "1.9.0" // x-release-please-version
44
}
5+
6+
subprojects {
7+
// These are populated with dependencies by `buildSrc` scripts.
8+
tasks.register("format") {
9+
group = "Verification"
10+
description = "Formats all source files."
11+
}
12+
tasks.register("lint") {
13+
group = "Verification"
14+
description = "Verifies all source files are formatted."
15+
}
16+
}

buildSrc/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ repositories {
1010
}
1111

1212
dependencies {
13-
implementation("com.diffplug.spotless:spotless-plugin-gradle:7.0.2")
1413
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.20")
1514
implementation("com.vanniktech:gradle-maven-publish-plugin:0.28.0")
1615
}

buildSrc/src/main/kotlin/orb.java.gradle.kts

Lines changed: 83 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,13 @@
1-
import com.diffplug.gradle.spotless.SpotlessExtension
21
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
32

43
plugins {
54
`java-library`
6-
id("com.diffplug.spotless")
75
}
86

97
repositories {
108
mavenCentral()
119
}
1210

13-
configure<SpotlessExtension> {
14-
java {
15-
importOrder()
16-
removeUnusedImports()
17-
palantirJavaFormat()
18-
toggleOffOn()
19-
}
20-
}
21-
2211
java {
2312
toolchain {
2413
languageVersion.set(JavaLanguageVersion.of(21))
@@ -53,3 +42,86 @@ tasks.withType<Test>().configureEach {
5342
exceptionFormat = TestExceptionFormat.FULL
5443
}
5544
}
45+
46+
val palantir by configurations.creating
47+
dependencies {
48+
palantir("com.palantir.javaformat:palantir-java-format:2.73.0")
49+
}
50+
51+
fun registerPalantir(
52+
name: String,
53+
description: String,
54+
) {
55+
val javaName = "${name}Java"
56+
tasks.register<JavaExec>(javaName) {
57+
group = "Verification"
58+
this.description = description
59+
60+
classpath = palantir
61+
mainClass = "com.palantir.javaformat.java.Main"
62+
63+
// Avoid an `IllegalAccessError` on Java 9+.
64+
jvmArgs(
65+
"--add-exports", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
66+
"--add-exports", "jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
67+
"--add-exports", "jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
68+
"--add-exports", "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
69+
"--add-exports", "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
70+
)
71+
72+
// Use paths relative to the current module.
73+
val argumentFile =
74+
project.layout.buildDirectory.file("palantir-$name-args.txt").get().asFile
75+
val lastRunTimeFile =
76+
project.layout.buildDirectory.file("palantir-$name-last-run.txt").get().asFile
77+
78+
// Read the time when this task was last executed for this module (if ever).
79+
val lastRunTime = lastRunTimeFile.takeIf { it.exists() }?.readText()?.toLongOrNull() ?: 0L
80+
81+
// Use a `fileTree` relative to the module's source directory.
82+
val javaFiles = project.fileTree("src") { include("**/*.java") }
83+
84+
// Determine if any files need to be formatted or linted and continue only if there is at least
85+
// one file.
86+
onlyIf { javaFiles.any { it.lastModified() > lastRunTime } }
87+
88+
inputs.files(javaFiles)
89+
90+
doFirst {
91+
// Create the argument file and set the preferred formatting style.
92+
argumentFile.parentFile.mkdirs()
93+
argumentFile.writeText("--palantir\n")
94+
95+
if (name == "lint") {
96+
// For lint, do a dry run, so no files are modified. Set the exit code to 1 (instead of
97+
// the default 0) if any files need to be formatted, indicating that linting has failed.
98+
argumentFile.appendText("--dry-run\n")
99+
argumentFile.appendText("--set-exit-if-changed\n")
100+
} else {
101+
// `--dry-run` and `--replace` (for in-place formatting) are mutually exclusive.
102+
argumentFile.appendText("--replace\n")
103+
}
104+
105+
// Write the modified files to the argument file.
106+
javaFiles.filter { it.lastModified() > lastRunTime }
107+
.forEach { argumentFile.appendText("${it.absolutePath}\n") }
108+
}
109+
110+
doLast {
111+
// Record the last execution time for later up-to-date checking.
112+
lastRunTimeFile.writeText(System.currentTimeMillis().toString())
113+
}
114+
115+
// Pass the argument file using the @ symbol
116+
args = listOf("@${argumentFile.absolutePath}")
117+
118+
outputs.upToDateWhen { javaFiles.none { it.lastModified() > lastRunTime } }
119+
}
120+
121+
tasks.named(name) {
122+
dependsOn(tasks.named(javaName))
123+
}
124+
}
125+
126+
registerPalantir(name = "format", description = "Formats all Java source files.")
127+
registerPalantir(name = "lint", description = "Verifies all Java source files are formatted.")

buildSrc/src/main/kotlin/orb.kotlin.gradle.kts

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import com.diffplug.gradle.spotless.SpotlessExtension
21
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
32
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
43

@@ -7,6 +6,10 @@ plugins {
76
kotlin("jvm")
87
}
98

9+
repositories {
10+
mavenCentral()
11+
}
12+
1013
kotlin {
1114
jvmToolchain {
1215
languageVersion.set(JavaLanguageVersion.of(21))
@@ -27,14 +30,77 @@ kotlin {
2730
}
2831
}
2932

30-
configure<SpotlessExtension> {
31-
kotlin {
32-
ktfmt().kotlinlangStyle()
33-
toggleOffOn()
34-
}
35-
}
36-
3733
tasks.withType<Test>().configureEach {
3834
systemProperty("junit.jupiter.execution.parallel.enabled", true)
3935
systemProperty("junit.jupiter.execution.parallel.mode.default", "concurrent")
4036
}
37+
38+
val ktfmt by configurations.creating
39+
dependencies {
40+
ktfmt("com.facebook:ktfmt:0.56")
41+
}
42+
43+
fun registerKtfmt(
44+
name: String,
45+
description: String,
46+
) {
47+
val kotlinName = "${name}Kotlin"
48+
tasks.register<JavaExec>(kotlinName) {
49+
group = "Verification"
50+
this.description = description
51+
52+
classpath = ktfmt
53+
mainClass = "com.facebook.ktfmt.cli.Main"
54+
55+
// Use paths relative to the current module.
56+
val argumentFile = project.layout.buildDirectory.file("ktfmt-$name-args.txt").get().asFile
57+
val lastRunTimeFile =
58+
project.layout.buildDirectory.file("ktfmt-$name-last-run.txt").get().asFile
59+
60+
// Read the time when this task was last executed for this module (if ever).
61+
val lastRunTime = lastRunTimeFile.takeIf { it.exists() }?.readText()?.toLongOrNull() ?: 0L
62+
63+
// Use a `fileTree` relative to the module's source directory.
64+
val kotlinFiles = project.fileTree("src") { include("**/*.kt") }
65+
66+
// Determine if any files need to be formatted or linted and continue only if there is at least
67+
// one file (otherwise Ktfmt will fail).
68+
onlyIf { kotlinFiles.any { it.lastModified() > lastRunTime } }
69+
70+
inputs.files(kotlinFiles)
71+
72+
doFirst {
73+
// Create the argument file and set the preferred formatting style.
74+
argumentFile.parentFile.mkdirs()
75+
argumentFile.writeText("--kotlinlang-style\n")
76+
77+
if (name == "lint") {
78+
// For lint, do a dry run, so no files are modified. Set the exit code to 1 (instead of
79+
// the default 0) if any files need to be formatted, indicating that linting has failed.
80+
argumentFile.appendText("--dry-run\n")
81+
argumentFile.appendText("--set-exit-if-changed\n")
82+
}
83+
84+
// Write the modified files to the argument file.
85+
kotlinFiles.filter { it.lastModified() > lastRunTime }
86+
.forEach { argumentFile.appendText("${it.absolutePath}\n") }
87+
}
88+
89+
doLast {
90+
// Record the last execution time for later up-to-date checking.
91+
lastRunTimeFile.writeText(System.currentTimeMillis().toString())
92+
}
93+
94+
// Pass the argument file using the @ symbol
95+
args = listOf("@${argumentFile.absolutePath}")
96+
97+
outputs.upToDateWhen { kotlinFiles.none { it.lastModified() > lastRunTime } }
98+
}
99+
100+
tasks.named(name) {
101+
dependsOn(tasks.named(kotlinName))
102+
}
103+
}
104+
105+
registerKtfmt(name = "format", description = "Formats all Kotlin source files.")
106+
registerKtfmt(name = "lint", description = "Verifies all Kotlin source files are formatted.")

gradle.properties

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ org.gradle.parallel=true
44
org.gradle.daemon=false
55
# These options improve our compilation and test performance. They are inherited by the Kotlin daemon.
66
org.gradle.jvmargs=\
7-
-Xms1g \
8-
-Xmx4g \
7+
-Xms2g \
8+
-Xmx8g \
99
-XX:+UseParallelGC \
1010
-XX:InitialCodeCacheSize=256m \
1111
-XX:ReservedCodeCacheSize=1G \
12-
-XX:MetaspaceSize=256m \
12+
-XX:MetaspaceSize=512m \
13+
-XX:MaxMetaspaceSize=2G \
1314
-XX:TieredStopAtLevel=1 \
1415
-XX:GCTimeRatio=4 \
1516
-XX:CICompilerCount=4 \

orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClient.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ class OrbOkHttpClient private constructor() {
126126
* The executor to use for running [AsyncStreamResponse.Handler] callbacks.
127127
*
128128
* Defaults to a dedicated cached thread pool.
129+
*
130+
* This class takes ownership of the executor and shuts it down, if possible, when closed.
129131
*/
130132
fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply {
131133
clientOptions.streamHandlerExecutor(streamHandlerExecutor)

orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClientAsync.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ class OrbOkHttpClientAsync private constructor() {
126126
* The executor to use for running [AsyncStreamResponse.Handler] callbacks.
127127
*
128128
* Defaults to a dedicated cached thread pool.
129+
*
130+
* This class takes ownership of the executor and shuts it down, if possible, when closed.
129131
*/
130132
fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply {
131133
clientOptions.streamHandlerExecutor(streamHandlerExecutor)

0 commit comments

Comments
 (0)