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
7 changes: 4 additions & 3 deletions gradle/elide.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ kotest = "5.5.4"
kotest-plugin = "0.8.18"
kotlin-compile-testing = "1.6.0"
kotlin-dataframe = "0.11.0"
kotlin-language = "2.0"
kotlin-language = "2.1"
kotlin-sdk = "2.2.0"
kotlinpoet = "2.2.0"
kotlinx-abiValidator = "0.17.0"
Expand Down Expand Up @@ -257,7 +257,7 @@ qodanaGradle = "2023.3.1"
r8 = "1.4.45"
react = "19.0.0"
reactivestreams = "1.0.4"
redacted-plugin = "1.9.0"
redacted-plugin = "1.14.1"
sarif4k = "0.6.0"
semver = "6.0.0"
shadow-plugin = "8.1.1"
Expand Down Expand Up @@ -871,7 +871,8 @@ plugin-nexusPublishing = { group = "io.github.gradle-nexus", name = "publish-plu
plugin-openrewrite = { group = "org.openrewrite", name = "plugin", version.ref = "openrewrite-plugin" }
plugin-proguard = { group = "com.guardsquare", name = "proguard-gradle", version.ref = "proguard" }
plugin-protobuf = { group = "com.google.protobuf", name = "protobuf-gradle-plugin", version.ref = "pluginProtobuf" }
plugin-redacted = { group = "dev.zacsweers.redacted", name = "redacted-compiler-plugin-gradle", version.ref = "redacted-plugin" }
plugin-redacted-core = { group = "dev.zacsweers.redacted", name = "redacted-compiler-plugin", version.ref = "redacted-plugin" }
plugin-redacted-gradle = { group = "dev.zacsweers.redacted", name = "redacted-compiler-plugin-gradle", version.ref = "redacted-plugin" }
plugin-reflekt = { group = "org.jetbrains.reflekt", name = "reflekt-plugin", version.ref = "kotlin-sdk" }
plugin-shadow = { group = "com.github.johnrengelman", name = "shadow", version.ref = "shadow-plugin" }
plugin-sigstore = { group = "dev.sigstore", name = "sigstore-gradle-sign-plugin", version.ref = "sigstore" }
Expand Down
6 changes: 6 additions & 0 deletions packages/base/api/base.api
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ public final class elide/AppEnvironment : java/lang/Enum {
public abstract interface annotation class elide/annotations/API : java/lang/annotation/Annotation {
}

public abstract interface annotation class elide/annotations/Cleartext : java/lang/annotation/Annotation {
}

public abstract interface annotation class elide/annotations/Eager : java/lang/annotation/Annotation {
}

Expand All @@ -21,6 +24,9 @@ public abstract interface annotation class elide/annotations/Generated : java/la
public abstract interface annotation class elide/annotations/Logic : java/lang/annotation/Annotation {
}

public abstract interface annotation class elide/annotations/Secret : java/lang/annotation/Annotation {
}

public abstract interface annotation class elide/annotations/base/Experimental : java/lang/annotation/Annotation {
}

Expand Down
1 change: 1 addition & 0 deletions packages/base/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ elide {
target = KotlinTarget.Default
atomicFu = true
explicitApi = true
kotlinVersionOverride = "2.0"
}

jvm {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2024 Elide Technologies, Inc.
*
* Licensed under the MIT license (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://opensource.org/license/mit/
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under the License.
*/
package elide.annotations

/**
* # Annotation: Cleartext
*
* Marks a value which holds a non-secret, within the context of a [Secret]; reverses redaction as a result. For example
* if a full data class is annotated [Secret], [Cleartext] will allow display of one or more individual properties.
*/
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.PROPERTY, AnnotationTarget.CLASS)
@MustBeDocumented
public annotation class Cleartext
27 changes: 27 additions & 0 deletions packages/base/src/commonMain/kotlin/elide/annotations/Secret.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2024 Elide Technologies, Inc.
*
* Licensed under the MIT license (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://opensource.org/license/mit/
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under the License.
*/
package elide.annotations

/**
* # Annotation: Secret
*
* Marks a value which holds some sort of secret or protected material; such material should be redacted from output as
* much as possible, and otherwise held with care.
*
* `Secret` can be applied to properties or classes; in each case, the data associated with the annotated value is
* withheld from generated output code such as `toString` (where supported).
*/
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.PROPERTY, AnnotationTarget.CLASS)
@MustBeDocumented
public annotation class Secret
1 change: 1 addition & 0 deletions packages/builder/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ dependencies {
implementation(libs.mordant.markdown)
implementation(libs.highlights)
implementation(libs.ktoml)
implementation(libs.plugin.redacted.core)
implementation(libs.kotlin.compiler.embedded)
implementation(libs.kotlin.serialization.embedded)
implementation(libs.kotlin.powerAssert.embedded)
Expand Down
1 change: 1 addition & 0 deletions packages/builder/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<CurrentIssues>
<ID>ForbiddenComment:JvmBuildConfigurator.kt$JvmBuildConfigurator$// @TODO: argument splitting by default</ID>
<ID>FunctionParameterNaming:Statics.kt$Statics$`in`: InputStream</ID>
<ID>LongMethod:JvmBuildConfigurator.kt$JvmBuildConfigurator$private fun ActionScope.kotlinc( name: String, resolver: MavenAetherResolver?, state: ElideBuildState, config: BuildConfigurator.BuildConfiguration, srcSet: SourceSet, additionalDeps: Classpath? = null, tests: Boolean = false, dependencies: List&lt;Task> = emptyList(), argsAmender: K2JVMCompilerArguments.() -> Unit = {}, )</ID>
<ID>ObjectPropertyNaming:Statics.kt$Statics$public val `in`: InputStream get() = delegatedInStream.value ?: System.`in`</ID>
<ID>UnusedParameter:NativeImageDriver.kt$NativeImageDriver$inputs: NativeImageInputs.Paths</ID>
<ID>UnusedParameter:NativeImageDriver.kt$NativeImageDriver$javaToolchainHome: Path</ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ internal class JvmBuildConfigurator : BuildConfigurator {
}

private fun jarNameFor(coordinate: String, version: String): String {
if (coordinate.startsWith("dev.elide")) {
return JvmLibraries.elideJarNameFor(coordinate, version)
}
return JvmLibraries.jarNameFor(coordinate, version)
}

Expand Down Expand Up @@ -424,6 +427,35 @@ internal class JvmBuildConfigurator : BuildConfigurator {

// kotlinx support is enabled by default; this includes kotlin's testing tools
val staticDeps = Classpath.empty().toMutable()

if (state.manifest.kotlin?.features?.autoClasspath != false) {
// add `dev.elide:elide-core`
staticDeps.add(
builtinKotlinJarPath(
state,
JvmLibraries.ELIDE_CORE,
JvmLibraries.ELIDE_VERSION,
)
)
// add `dev.elide:elide-base`
staticDeps.add(
builtinKotlinJarPath(
state,
JvmLibraries.ELIDE_BASE,
JvmLibraries.ELIDE_VERSION,
)
)
if (tests) {
// add `dev.elide:elide-test`
staticDeps.add(
builtinKotlinJarPath(
state,
JvmLibraries.ELIDE_TEST,
JvmLibraries.ELIDE_VERSION,
)
)
}
}
if (state.manifest.kotlin?.features?.kotlinx != false) {
if (state.manifest.kotlin?.features?.coroutines != false) {
// add `org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm`
Expand All @@ -435,7 +467,7 @@ internal class JvmBuildConfigurator : BuildConfigurator {
),
)
}
if (state.manifest.kotlin?.features?.serialization == true) {
if (state.manifest.kotlin?.features?.serialization != false) {
// add `org.jetbrains.kotlinx:kotlinx-serialization-core`
staticDeps.add(
builtinKotlinJarPath(
Expand Down Expand Up @@ -511,11 +543,14 @@ internal class JvmBuildConfigurator : BuildConfigurator {
// if additional deps are provided, add them to the classpath
additionalDeps?.let { add(it) }
}.toList().let {
Classpath.from(it.map { it.path })
Classpath.from(it.map { item -> item.path })
}

val kotlincOpts = state.manifest.kotlin?.compilerOptions ?: KotlinJvmCompilerOptions()
val args = Arguments.empty().toMutable().apply {
// @TODO eliminate this
add("-Xskip-prerelease-check")

// apply arguments
addAllStrings(kotlincOpts.collect().toList())
}.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,13 @@ public val kotlinc: Tool.CommandLineTool = Tool.describe(
// load services eagerly
debugLog("Building Kotlin compiler services")

buildList {
buildSet {
addAll(ServiceLoaderLite.loadImplementations(ComponentRegistrar::class.java, classLoader))
addAll(ServiceLoaderLite.loadImplementations(CompilerPluginRegistrar::class.java, classLoader))
add(org.jetbrains.kotlin.powerassert.PowerAssertCommandLineProcessor())
}.let {
add(dev.zacsweers.redacted.compiler.RedactedCommandLineProcessor())
add(dev.zacsweers.redacted.compiler.RedactedComponentRegistrar())
}.distinctBy { it::class }.let {
if (it.isEmpty()) {
error(
"No Kotlin compiler plugins found; this is an error."
Expand All @@ -376,9 +378,9 @@ public val kotlinc: Tool.CommandLineTool = Tool.describe(
it.forEach { svc ->
register(svc::class.java as Class<Any>, svc)
}
}.build().let {
}.build().let { services ->
debugLog("Registered $size Kotlin compiler plugins")
compilerServices = it
compilerServices = services
}
}
}
Expand Down
17 changes: 15 additions & 2 deletions packages/cli/src/projects/ktjvm/src/main/kotlin/sample/main.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
package sample

import com.google.common.base.Joiner
import elide.annotations.Secret
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json

fun render_greeting(): String {
@Serializable data class MyCoolData(
@Secret val name: String,
)

fun renderGreeting(): String {
return Joiner.on(" ").join("Hello", "World")
}

fun renderData(name: String = "World"): MyCoolData {
return MyCoolData(name = name)
}

fun main() {
println(render_greeting())
println(Json.encodeToString(renderData()))
println(renderData().toString())
println(renderGreeting())
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
package sample

import kotlinx.serialization.json.Json
import kotlin.test.*

class SampleTest {
@Test fun testGreeting() {
val greeting = render_greeting()
@Test fun `greeting is expected value`() {
val greeting = renderGreeting()
assertNotNull(greeting)
assertEquals("Hello World", greeting)
}

@Test fun `kotlinx serialization works`() {
val data = assertNotNull(renderData()).copy(name = "test")
val encoded = assertNotNull(Json.encodeToString(data))
assertTrue(encoded.isNotEmpty())
assertTrue("\"test\"" in encoded)
val decoded = assertNotNull(Json.decodeFromString<MyCoolData>(encoded))
assertEquals("test", decoded.name)
}

@Test fun `redaction works`() {
val data = assertNotNull(renderData()).copy(name = "test")
val stringForm = assertNotNull(data.toString())
assertFalse("test" in stringForm)
}
}
1 change: 1 addition & 0 deletions packages/core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ elide {
atomicFu = true
target = KotlinTarget.Default
explicitApi = true
kotlinVersionOverride = "2.0"
}

jvm {
Expand Down
1 change: 1 addition & 0 deletions packages/graalvm-kt/api/graalvm-kt.api
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public final class elide/runtime/gvm/kotlin/KotlinCompilerConfig$Companion {

public final class elide/runtime/gvm/kotlin/KotlinCompilerConfig$KotlinBuiltinPlugin : java/lang/Enum, elide/runtime/gvm/kotlin/KotlinCompilerConfig$KotlinPluginConfig {
public static final field POWER_ASSERT Lelide/runtime/gvm/kotlin/KotlinCompilerConfig$KotlinBuiltinPlugin;
public static final field REDACTED Lelide/runtime/gvm/kotlin/KotlinCompilerConfig$KotlinBuiltinPlugin;
public static final field SERIALIZATION Lelide/runtime/gvm/kotlin/KotlinCompilerConfig$KotlinBuiltinPlugin;
public synthetic fun <init> (Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public static fun getEntries ()Lkotlin/enums/EnumEntries;
Expand Down
31 changes: 27 additions & 4 deletions packages/graalvm-kt/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ dependencies {
implementation(libs.kotlin.compiler.embedded)
implementation(libs.kotlin.serialization.embedded)
implementation(libs.kotlin.powerAssert.embedded)
implementation(libs.plugin.redacted.core)
implementation(libs.kotlin.scripting.dependencies)
implementation(libs.kotlin.scripting.dependencies.maven) {
exclude(group = "com.google.inject", module = "guice")
Expand All @@ -138,6 +139,20 @@ dependencies {
api(files(embeddedKotlinRuntime))
compileOnly(libs.graalvm.svm)

// elide modules
embeddedKotlin(projects.packages.base) {
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk7")
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk8")
}
embeddedKotlin(projects.packages.core) {
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk7")
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk8")
}
embeddedKotlin(projects.packages.test) {
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk7")
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk8")
}

embeddedKotlin(libs.kotlin.stdlib)
embeddedKotlin(libs.kotlin.reflect)
embeddedKotlin(libs.kotlin.test.junit5)
Expand All @@ -157,6 +172,7 @@ dependencies {
embeddedKotlin(libs.ksp)
embeddedKotlin(libs.ksp.api)
embeddedKotlin(libs.ksp.cmdline)
embeddedKotlin(libs.plugin.redacted.core)
embeddedKotlin(mn.micronaut.inject.kotlin)
embeddedKotlin(libs.junit.jupiter.api)
embeddedKotlin(libs.junit.jupiter.params)
Expand Down Expand Up @@ -347,7 +363,7 @@ fun indexedDeps(cfg: Configuration): KotlinResourceIndex {
}

@OptIn(ExperimentalSerializationApi::class) val indexKotlinResources by tasks.registering {
dependsOn("prepKotlinResources")
enabled = false

indexedDeps(embeddedKotlin).plus(indexedDeps(embeddedJava)).let { index ->
kotlinResourceIndex.get().asFile.parentFile.mkdirs()
Expand Down Expand Up @@ -382,13 +398,15 @@ val prepKotlinResources by tasks.registering(Copy::class) {
}
destinationDir = intermediateResources.get().dir("lib").asFile
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
finalizedBy("indexKotlinResources")
// finalizedBy("indexKotlinResources")
}

val ktRuntimeTarget = "META-INF/elide/embedded/runtime/kt"
val ktRuntimeRoot = layout.projectDirectory.dir("src/main/resources/$ktRuntimeTarget")
val buildKotlinResourcesArchive by tasks.registering(Zip::class) {
dependsOn(prepKotlinResources, indexKotlinResources)
dependsOn(prepKotlinResources)
// dependsOn(indexKotlinResources)

archiveFileName = archiveName
destinationDirectory = intermediateResourcesZip.get().asFile.parentFile
from(intermediateResources.get().asFile)
Expand Down Expand Up @@ -435,7 +453,12 @@ val buildResourcesManifest by tasks.registering {
}

tasks.processResources {
dependsOn(prepKotlinResources, buildKotlinResourcesArchive, buildResourcesManifest, indexKotlinResources)
dependsOn(
prepKotlinResources,
buildKotlinResourcesArchive,
buildResourcesManifest,
// indexKotlinResources,
)

from(kotlinResourceIndex) {
into(ktRuntimeTarget)
Expand Down
Loading
Loading