Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,19 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.openapi.util.CheckedDisposable
import com.intellij.openapi.vfs.VfsUtil
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import org.gradle.tooling.CancellationTokenSource
import org.gradle.tooling.GradleConnector
import org.jetbrains.plugins.gradle.service.execution.GradleExecutionHelper
import org.jetbrains.plugins.gradle.settings.GradleExecutionSettings
import org.jetbrains.plugins.gradle.util.GradleConstants
import java.io.File
import java.util.concurrent.Executors

@Service(Service.Level.PROJECT)
class ApolloCodegenService(
private val project: Project,
private val coroutineScope: CoroutineScope,
) : Disposable {
private var documentChangesDisposable: CheckedDisposable? = null
private var fileEditorChangesDisposable: CheckedDisposable? = null
Expand All @@ -53,8 +55,6 @@ class ApolloCodegenService(

private var gradleCodegenCancellation: CancellationTokenSource? = null

private val gradleExecutorService = Executors.newSingleThreadExecutor()

init {
logd("project=${project.name}")
startOrStopCodegenObservers()
Expand Down Expand Up @@ -181,10 +181,9 @@ class ApolloCodegenService(

val modules = ModuleManager.getInstance(project).modules
val rootProjectPath = project.getGradleRootPath() ?: return
val executionSettings =
ExternalSystemApiUtil.getExecutionSettings<GradleExecutionSettings>(project, rootProjectPath, GradleConstants.SYSTEM_ID)

gradleExecutorService.submit {
coroutineScope.launch {
val executionSettings =
ExternalSystemApiUtil.getExecutionSettings<GradleExecutionSettings>(project, rootProjectPath, GradleConstants.SYSTEM_ID)
val gradleExecutionHelper = GradleExecutionHelper()
gradleExecutionHelper.execute(rootProjectPath, executionSettings) { connection ->
gradleCodegenCancellation = GradleConnector.newCancellationTokenSource()
Expand Down Expand Up @@ -257,6 +256,5 @@ class ApolloCodegenService(
override fun dispose() {
logd("project=${project.name}")
stopContinuousGradleCodegen()
gradleExecutorService.shutdown()
}
}
Loading