Skip to content

draft: publishing mql-engines as an npm package for index suggestions experiment INTELLIJ-295 #190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ FAKE_BROWSER_OUTPUT

/.idea/artifacts
/.intellijPlatform
/kotlin-js-store
5 changes: 4 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import java.net.URL
group = "com.mongodb"
// This should be bumped when releasing a new version using the versionBump task:
// ./gradlew versionBump -Pmode={major,minor,patch}
version = "0.0.1"
version = "0.0.4"

plugins {
base
id("com.github.ben-manes.versions")
id("jacoco-report-aggregation")
id("org.jetbrains.changelog")
id("org.jetbrains.qodana")

id("org.jetbrains.compose") version("1.7.3") apply(false)
id("org.jetbrains.kotlin.plugin.compose") version("2.0.21") apply(false)
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import org.gradle.accessors.dm.LibrariesForLibs
import org.jlleitschuh.gradle.ktlint.KtlintExtension
import org.jlleitschuh.gradle.ktlint.reporter.ReporterType
import java.io.ByteArrayOutputStream
import java.io.File

plugins {
id("jacoco")
id("org.jlleitschuh.gradle.ktlint")
}

version = rootProject.version
val libs = the<LibrariesForLibs>()

tasks {
withType<JacocoReport> {
reports {
xml.required = true
csv.required = false
html.outputLocation = layout.buildDirectory.dir("reports/jacocoHtml")
}

executionData(
files(withType(Test::class.java)).filter { it.name.endsWith(".exec") && it.exists() }
)
}

register("checkSpecUpdates") {
group = "verification"
description = "Fails if a Kotlin file changed but no specification file was updated"

doLast {
val rootDir = "${rootDir.absolutePath}"
val baseDir = "${project.projectDir.path}"
val specsDir = "$baseDir/src/docs/"

if (!File(specsDir).exists()) {
logger.lifecycle("Skipping checkSpecUpdates: $specsDir does not exist.")
return@doLast
} else {
logger.lifecycle("Verifying specifications.")
}

val outputStream = ByteArrayOutputStream()
exec {
workingDir = project.rootDir
standardOutput = outputStream
commandLine("git", "diff", "--name-only", "origin/main")
}

val changedFiles = outputStream.toString().trim().lines().map { "$rootDir/$it" }

logger.quiet("List of changed files:")
changedFiles.forEach { file ->
logger.quiet(file)
}

val codeChanged =
changedFiles.any { it.startsWith("$baseDir/src/main/kotlin/") && it.endsWith(".kt") }
val specChanged = changedFiles.any { it.startsWith(specsDir) }

if (codeChanged && !specChanged) {
logger.error("The specification is not up to date with the latest code changes.")
logger.error("Please update the relevant files in $specsDir or add the 'skip-spec-check' label to the PR.")
throw GradleException()
}
}
}
}

configure<KtlintExtension> {
version.set(libs.versions.ktlint.tool)
verbose.set(true)
outputToConsole.set(true)
ignoreFailures.set(false)
enableExperimentalRules.set(true)

reporters {
reporter(ReporterType.PLAIN)
reporter(ReporterType.CHECKSTYLE)
}

filter {
exclude("**/generated/**")
include("**/kotlin/**")
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import org.gradle.accessors.dm.LibrariesForLibs
import org.jlleitschuh.gradle.ktlint.KtlintExtension
import org.jlleitschuh.gradle.ktlint.reporter.ReporterType
import java.io.ByteArrayOutputStream

plugins {
id("java")
kotlin("jvm")
id("jacoco")
id("org.jlleitschuh.gradle.ktlint")
id("com.mongodb.intellij.base-module")
kotlin("multiplatform")
}

repositories {
Expand All @@ -17,116 +12,94 @@ repositories {

val libs = the<LibrariesForLibs>()

dependencies {
compileOnly(libs.kotlin.stdlib)
compileOnly(libs.kotlin.coroutines.core)
compileOnly(libs.kotlin.reflect)
testImplementation(libs.testing.jupiter.engine)
testImplementation(libs.testing.jupiter.params)
testImplementation(libs.testing.jupiter.vintage.engine)
testImplementation(libs.testing.mockito.core)
testImplementation(libs.testing.mockito.kotlin)
testImplementation(libs.kotlin.coroutines.test)
testImplementation(libs.testing.testContainers.core)
testImplementation(libs.testing.testContainers.jupiter)
testImplementation(libs.testing.testContainers.mongodb)
}

tasks {
withType<JavaCompile> {
sourceCompatibility = libs.versions.java.target.get()
targetCompatibility = libs.versions.java.target.get()
kotlin {
jvm {
val main by compilations.getting
}

withType<Test> {
useJUnitPlatform()

extensions.configure(JacocoTaskExtension::class) {
isJmx = true
includes = listOf("com.mongodb.*")
isIncludeNoLocationClasses = true
js(IR) {
moduleName = project.name
version = project.version

generateTypeScriptDefinitions()
browser {
testTask {
useKarma {
useFirefox()
}
}
}

jacoco {
toolVersion = libs.versions.jacoco.get()
isScanForTestClasses = true
nodejs {
testTask {
useMocha()
}
}

jvmArgs(
listOf(
"--add-opens=java.base/java.lang=ALL-UNNAMED"
)
)
binaries.library()
}

withType<JacocoReport> {
reports {
xml.required = true
csv.required = false
html.outputLocation = layout.buildDirectory.dir("reports/jacocoHtml")
sourceSets {
val commonMain by getting {
dependencies {
compileOnly(libs.kotlin.stdlib)
compileOnly(libs.kotlin.coroutines.core)
compileOnly(libs.kotlin.reflect)
implementation(libs.kotlin.collections)
}
}

executionData(
files(withType(Test::class.java)).filter { it.name.endsWith(".exec") && it.exists() }
)
}
}

configure<KtlintExtension> {
version.set(libs.versions.ktlint.tool)
verbose.set(true)
outputToConsole.set(true)
ignoreFailures.set(false)
enableExperimentalRules.set(true)

reporters {
reporter(ReporterType.PLAIN)
reporter(ReporterType.CHECKSTYLE)
}

filter {
exclude("**/generated/**")
include("**/kotlin/**")
}
}
val commonTest by getting {
dependencies {
implementation(libs.testing.kotlin.test)
implementation(libs.testing.kotlin.coroutines)
}
}

tasks.register("checkSpecUpdates") {
group = "verification"
description = "Fails if a Kotlin file changed but no specification file was updated"
val jvmMain by getting

doLast {
val rootDir = "${rootDir.absolutePath}"
val baseDir = "${project.projectDir.path}"
val specsDir = "$baseDir/src/docs/"
val jvmTest by getting {
dependencies {
implementation(libs.testing.jupiter.engine)
implementation(libs.testing.jupiter.params)
implementation(libs.testing.jupiter.vintage.engine)

if (!File(specsDir).exists()) {
logger.lifecycle("Skipping checkSpecUpdates: $specsDir does not exist.")
return@doLast
} else {
logger.lifecycle("Verifying specifications.")
implementation(libs.testing.mockito.core)
implementation(libs.testing.mockito.kotlin)
implementation(libs.testing.kotlin.coroutines)
}
}

val outputStream = ByteArrayOutputStream()
exec {
workingDir = project.rootDir
standardOutput = outputStream
commandLine("git", "diff", "--name-only", "origin/main")
val jsMain by getting {
dependencies {
implementation(libs.kotlin.stdlib)
implementation(libs.kotlin.coroutines.core)
}
}

val changedFiles = outputStream.toString().trim().lines().map { "$rootDir/$it" }
val jsTest by getting
}
}

logger.quiet("List of changed files:")
changedFiles.forEach { file ->
logger.quiet(file)
}
tasks {
withType<Test> {
useJUnitPlatform()

val codeChanged = changedFiles.any { it.startsWith("$baseDir/src/main/kotlin/") && it.endsWith(".kt") }
val specChanged = changedFiles.any { it.startsWith(specsDir) }
extensions.configure(JacocoTaskExtension::class) {
isJmx = true
includes = listOf("com.mongodb.*")
isIncludeNoLocationClasses = true
}

if (codeChanged && !specChanged) {
logger.error("The specification is not up to date with the latest code changes.")
logger.error("Please update the relevant files in $specsDir or add the 'skip-spec-check' label to the PR.")
throw GradleException()
jacoco {
toolVersion = libs.versions.jacoco.get()
isScanForTestClasses = true
}

jvmArgs(
listOf(
"--add-opens=java.base/java.lang=ALL-UNNAMED"
)
)
}
}
Loading