Skip to content

Commit 641b621

Browse files
committed
Pause gradle sync
1 parent 5c51d08 commit 641b621

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

components/ide/jetbrains/backend-plugin/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pluginVersion=0.0.1
22
gitpodVersion=dev
33
# Supported environments: stable, latest (via https://github.com/stevesaliman/gradle-properties-plugin)
4-
environmentName=latest
4+
environmentName=stable
55
# IntelliJ Platform Artifacts Repositories
66
# -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html
77
pluginGroup=io.gitpod.jetbrains
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright (c) 2024 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License.AGPL.txt in the project root for license information.
4+
5+
package io.gitpod.jetbrains.remote.listeners
6+
7+
import com.intellij.openapi.diagnostic.thisLogger
8+
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId
9+
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener
10+
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListenerAdapter
11+
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskType
12+
import com.intellij.openapi.progress.ProgressIndicator
13+
import com.intellij.openapi.progress.ProgressManager
14+
import com.intellij.openapi.progress.Task
15+
import kotlinx.coroutines.delay
16+
import java.util.concurrent.CompletableFuture
17+
import java.util.concurrent.TimeUnit
18+
19+
class GradleSyncListener : ExternalSystemTaskNotificationListener {
20+
override fun onStart(id: ExternalSystemTaskId, workingDir: String?) {
21+
thisLogger().warn("===========hwen.onStart.1 ${id.projectSystemId} ${id.type} ${workingDir}")
22+
if (id.projectSystemId.toString() != "GRADLE" || id.type != ExternalSystemTaskType.RESOLVE_PROJECT) {
23+
return
24+
}
25+
thisLogger().warn("===========hwen.onStart.2 gradle")
26+
27+
Thread.sleep(30000L)
28+
thisLogger().warn("===========hwen.onStart.3")
29+
30+
// 使用后台任务执行延迟
31+
ProgressManager.getInstance().run(
32+
object : Task.Backgroundable(null, "Waiting before Gradle sync", true) {
33+
override fun run(indicator: ProgressIndicator) {
34+
try {
35+
indicator.isIndeterminate = false
36+
37+
for (i in 1..10) {
38+
if (indicator.isCanceled) {
39+
thisLogger().warn("===========hwen.4 Delay was cancelled by user")
40+
return
41+
}
42+
43+
indicator.fraction = i / 10.0
44+
indicator.text = "Waiting ${10 - i} seconds before Gradle sync..."
45+
46+
CompletableFuture.delayedExecutor(1, TimeUnit.SECONDS)
47+
.execute {}.run { }
48+
}
49+
50+
thisLogger().warn("===========hwen.5 Delay completed, continuing with sync")
51+
} catch (e: Exception) {
52+
thisLogger().error("===========hwen.6 Error during delay", e)
53+
}
54+
}
55+
56+
override fun onCancel() {
57+
thisLogger().warn("==============hwen.7 Delay was cancelled")
58+
super.onCancel()
59+
}
60+
}
61+
)
62+
}
63+
}

components/ide/jetbrains/backend-plugin/src/main/resources/META-INF/plugin.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
<applicationService serviceInterface="io.gitpod.jetbrains.remote.GitpodIgnoredPortsForNotificationService"
5555
serviceImplementation="io.gitpod.jetbrains.remote.internal.GitpodIgnoredPortsForNotificationServiceImpl"
5656
preload="true"/>
57+
58+
<externalSystemTaskNotificationListener
59+
implementation="io.gitpod.jetbrains.remote.listeners.GradleSyncListener"/>
5760
</extensions>
5861

5962
<actions>

0 commit comments

Comments
 (0)