Skip to content

Commit

Permalink
Replace classloader isolation strategy with process isolation strategy (
Browse files Browse the repository at this point in the history
cortinico#206)

* replace classloader isolation strategy with process isolation strategy to circumvent memory leaks in large projects

* add changelog entry with pull request reference
  • Loading branch information
simonhauck authored Oct 30, 2023
1 parent 2735bdd commit ed473b2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This file follows [Keepachangelog](https://keepachangelog.com/) format.
Please add your entries according to this format.

## Unreleased
- Replace class loader isolation with process isolation (#206)

## Version 0.14.0 *(2023-10-09)*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ import org.gradle.api.tasks.options.Option
import org.gradle.workers.WorkQueue
import org.gradle.workers.WorkerExecutor

/**
* ktfmt-gradle base Gradle tasks. Handles a coroutine scope and contains method to propertly
* process a single file with ktfmt
*/
/** ktfmt-gradle base Gradle tasks. Contains methods to properly process a single file with ktfmt */
@Suppress("LeakingThis")
abstract class KtfmtBaseTask
internal constructor(
Expand Down Expand Up @@ -65,7 +62,7 @@ internal constructor(
@TaskAction
internal fun taskAction() {
val workQueue =
workerExecutor.classLoaderIsolation { spec -> spec.classpath.from(ktfmtClasspath) }
workerExecutor.processIsolation { spec -> spec.classpath.from(ktfmtClasspath) }
execute(workQueue)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import org.intellij.lang.annotations.Language
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ValueSource

internal class KtfmtCheckTaskIntegrationTest {

Expand Down Expand Up @@ -196,6 +198,23 @@ internal class KtfmtCheckTaskIntegrationTest {
assertThat(result.output).contains("Valid formatting for:")
}

@ParameterizedTest
@ValueSource(ints = [10, 15, 30, 50, 100, 1000])
fun `check task can check the formatting of multiple files`(n: Int) {
repeat(n) { index ->
createTempFile(content = "val answer${index} = 42\n", fileName = "TestFile$index.kt")
}
val result =
GradleRunner.create()
.withProjectDir(tempDir)
.withPluginClasspath()
.withArguments("ktfmtCheckMain", "--info")
.forwardOutput()
.build()

assertThat(result.task(":ktfmtCheckMain")?.outcome).isEqualTo(SUCCESS)
}

private fun createTempFile(
@Language("kotlin") content: String,
fileName: String = "TestFile.kt",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import org.intellij.lang.annotations.Language
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ValueSource

internal class KtfmtFormatTaskIntegrationTest {

Expand Down Expand Up @@ -242,6 +244,23 @@ internal class KtfmtFormatTaskIntegrationTest {
assertThat(result.output).contains("[ktfmt] Successfully reformatted 1 files with Ktfmt")
}

@ParameterizedTest
@ValueSource(ints = [10, 15, 30, 50, 100, 1000])
fun `format task can format multiple files`(n: Int) {
repeat(n) { index ->
createTempFile(content = "val answer${index}=42\n", fileName = "TestFile$index.kt")
}
val result =
GradleRunner.create()
.withProjectDir(tempDir)
.withPluginClasspath()
.withArguments("ktfmtFormatMain", "--info")
.forwardOutput()
.build()

assertThat(result.task(":ktfmtFormatMain")?.outcome).isEqualTo(SUCCESS)
}

private fun createTempFile(
@Language("kotlin") content: String,
fileName: String = "TestFile.kt",
Expand Down

0 comments on commit ed473b2

Please sign in to comment.