Skip to content
Open
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
5 changes: 5 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ jobs:
- name: scip-kotlin-analysis tests
run: gradle :scip-kotlin-analysis:test --no-daemon

- name: scip-kotlin-analysis consumer smoke test
run: |
gradle --no-daemon :scip-shared:publishToMavenLocal :scip-kotlin-analysis:publishToMavenLocal
gradle --no-daemon -p examples/kotlin-analysis-consumer run

docker_test:
runs-on: ubuntu-latest
name: Docker CLI tests
Expand Down
16 changes: 16 additions & 0 deletions examples/kotlin-analysis-consumer/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
plugins {
kotlin("jvm") version "2.4.21"
application
}

val scipVersion = providers.gradleProperty("scipVersion").orElse("0.0.0-SNAPSHOT").get()

dependencies {
// Deliberately the only dependency: everything the indexer's public API needs
// must come from scip-kotlin-analysis's published metadata.
implementation("org.scip-code:scip-kotlin-analysis:$scipVersion")
}

application {
mainClass.set("MainKt")
}
13 changes: 13 additions & 0 deletions examples/kotlin-analysis-consumer/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// A standalone consumer of the published scip-kotlin-analysis artifact. It resolves
// the module only through its published metadata, as library users do, so it catches
// missing `api` dependencies and references to artifacts outside Maven Central.
//
// Run: gradle publishToMavenLocal && gradle -p examples/kotlin-analysis-consumer run
rootProject.name = "kotlin-analysis-consumer"

dependencyResolutionManagement {
repositories {
mavenLocal { content { includeGroup("org.scip-code") } }
mavenCentral()
}
}
38 changes: 38 additions & 0 deletions examples/kotlin-analysis-consumer/src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import java.nio.file.Files
import java.nio.file.Paths
import kotlin.io.path.writeText
import kotlin.system.exitProcess
import org.scip_code.scip.Document
import org.scip_code.scip_java.kotlin_analysis.KotlinAnalysisIndexer

fun main() {
val sourceroot = Files.createTempDirectory("kotlin-analysis-consumer").toRealPath()
val src = Files.createDirectories(sourceroot.resolve("src"))
src.resolve("Greeter.kt")
.writeText("package demo\n\nclass Greeter(val name: String) { fun greet() = \"Hi \$name\" }\n")
val stdlib = Paths.get(KotlinVersion::class.java.protectionDomain.codeSource.location.toURI())

val streamed = mutableListOf<Document>()
val documents: List<Document> =
KotlinAnalysisIndexer(
sourceroot = sourceroot,
targetroot = sourceroot.resolve("scip-targetroot"),
sourceRoots = listOf(src),
classpath = listOf(stdlib),
callback = { streamed += it },
)
.run()

val symbols = documents.flatMap { doc -> doc.occurrencesList.map { it.symbol } }
if (documents.map { it.relativePath } != listOf("src/Greeter.kt") ||
streamed != documents ||
"demo/Greeter#" !in symbols ||
"kotlin/String#" !in symbols
) {
System.err.println("Unexpected indexer output:\n$documents")
exitProcess(1)
}
println("Indexed ${documents.size} document with ${symbols.size} occurrences")
// The Analysis API leaves non-daemon threads behind; exit explicitly like scip-java.
exitProcess(0)
}
Loading