@@ -5,7 +5,9 @@ import com.intellij.gradle.toolingExtension.modelAction.GradleModelFetchPhase
55import com.intellij.openapi.observable.operation.OperationExecutionStatus
66import com.intellij.openapi.progress.ProgressManager
77import com.intellij.openapi.util.Disposer
8+ import com.intellij.openapi.util.registry.Registry
89import com.intellij.openapi.util.use
10+ import com.intellij.platform.backend.workspace.workspaceModel
911import com.intellij.platform.testFramework.assertion.WorkspaceAssertions
1012import com.intellij.platform.testFramework.assertion.listenerAssertion.ListenerAssertion
1113import com.intellij.platform.workspace.storage.toBuilder
@@ -14,6 +16,7 @@ import org.jetbrains.plugins.gradle.importing.TestModelProvider
1416import org.jetbrains.plugins.gradle.importing.TestPhasedModel
1517import org.jetbrains.plugins.gradle.service.project.DefaultProjectResolverContext
1618import org.jetbrains.plugins.gradle.service.project.ProjectResolverContext
19+ import org.jetbrains.plugins.gradle.service.syncAction.GradleEntitySource
1720import org.jetbrains.plugins.gradle.service.syncAction.GradleSyncPhase
1821import org.jetbrains.plugins.gradle.service.syncAction.GradleSyncPhase.Dynamic.Companion.asSyncPhase
1922import org.jetbrains.plugins.gradle.util.entity.GradleTestBridgeEntitySource
@@ -208,6 +211,7 @@ class GradlePhasedSyncTest : GradlePhasedSyncTestCase() {
208211 true -> allDynamicPhases
209212 else -> completedDynamicPhases
210213 }
214+ is GradleSyncPhase .DataServices -> error(" Should not execute" )
211215 }
212216 WorkspaceAssertions .assertEntities(myProject, expectedEntities.map { GradleTestEntityId (it) }) {
213217 " Entities should be created for completed phases.\n " +
@@ -271,6 +275,7 @@ class GradlePhasedSyncTest : GradlePhasedSyncTestCase() {
271275 is GradleSyncPhase .Static -> completedStaticPhases
272276 is GradleSyncPhase .BaseScript -> completedBaseScriptPhases
273277 is GradleSyncPhase .Dynamic -> completedDynamicPhases
278+ is GradleSyncPhase .DataServices -> error(" Should not execute" )
274279 }
275280 WorkspaceAssertions .assertEntities(myProject, expectedEntities.map { GradleTestEntityId (it) }) {
276281 " Bridge entities should be created for completed phases.\n " +
@@ -298,9 +303,101 @@ class GradlePhasedSyncTest : GradlePhasedSyncTestCase() {
298303 " Requested phases = $allPhases "
299304 " Completed phases = $completedPhases "
300305 }
306+ val dataServicesEntities = myProject.workspaceModel.currentSnapshot.entitiesBySource {
307+ it is GradleEntitySource && it.phase == GradleSyncPhase .DATA_SERVICES_PHASE
308+ }
309+ Assertions .assertTrue(dataServicesEntities.toList().isEmpty()) {
310+ " There should be no entities with phase ${GradleSyncPhase .DATA_SERVICES_PHASE } "
311+ }
301312 }
302313 }
303314
315+ @Test
316+ fun `test bridge entity contribution on Gradle sync phase with bridge disabled` () {
317+ repeat(2 ) { index ->
318+ Disposer .newDisposable().use { disposable ->
319+ Registry .get(" gradle.phased.sync.bridge.disabled" ).setValue(true , disposable)
320+ val isSecondarySync = index == 1
321+
322+ val syncContributorAssertions = ListenerAssertion ()
323+ val syncPhaseCompletionAssertions = ListenerAssertion ()
324+
325+ val allPhases = DEFAULT_SYNC_PHASES
326+ val allStaticPhases = allPhases.filterIsInstance<GradleSyncPhase .Static >()
327+ val allDynamicPhases = allPhases.filterIsInstance<GradleSyncPhase .Dynamic >()
328+ val completedPhases = CopyOnWriteArrayList <GradleSyncPhase >()
329+
330+ for (phase in allPhases) {
331+ addSyncContributor(phase, disposable) { context, storage ->
332+ val builder = storage.toBuilder()
333+ syncContributorAssertions.trace {
334+ val entitySource = GradleTestEntitySource (context.projectPath, phase)
335+ builder addEntity GradleTestEntity (phase, entitySource)
336+ Assertions .assertTrue(completedPhases.add(phase)) {
337+ " The $phase should be completed only once."
338+ }
339+ }
340+ return @addSyncContributor builder.toSnapshot()
341+ }
342+ whenSyncPhaseCompleted(phase, disposable) { _ ->
343+ syncPhaseCompletionAssertions.trace {
344+ val completedStaticPhases = completedPhases.filterIsInstance<GradleSyncPhase .Static >()
345+ val completedBaseScriptPhases = completedPhases.filterIsInstance<GradleSyncPhase .BaseScript >()
346+ val completedDynamicPhases = completedPhases.filterIsInstance<GradleSyncPhase .Dynamic >()
347+ val expectedEntities = when (phase) {
348+ is GradleSyncPhase .Static -> when (isSecondarySync) {
349+ true -> completedStaticPhases + allDynamicPhases
350+ else -> completedStaticPhases
351+ }
352+ is GradleSyncPhase .BaseScript -> when (isSecondarySync) {
353+ true -> allStaticPhases + completedBaseScriptPhases + allDynamicPhases
354+ else -> completedBaseScriptPhases
355+ }
356+ is GradleSyncPhase .Dynamic -> when (isSecondarySync) {
357+ true -> allDynamicPhases
358+ else -> completedDynamicPhases
359+ }
360+ is GradleSyncPhase .DataServices -> error(" Should not execute" )
361+ }
362+ WorkspaceAssertions .assertEntities(myProject, expectedEntities.map { GradleTestEntityId (it) }) {
363+ " Entities should be created for completed phases.\n " +
364+ " Completed phases = $completedPhases \n "
365+ " isSecondarySync = $isSecondarySync "
366+ }
367+ }
368+ }
369+ }
370+
371+ initMultiModuleProject()
372+ importProject()
373+ assertMultiModuleProjectStructure()
374+
375+ syncContributorAssertions.assertListenerFailures()
376+ syncContributorAssertions.assertListenerState(allPhases.size) {
377+ " All requested sync phases should be handled."
378+ }
379+ syncPhaseCompletionAssertions.assertListenerFailures()
380+ syncPhaseCompletionAssertions.assertListenerState(allPhases.size) {
381+ " All requested sync phases should be completed."
382+ }
383+
384+ WorkspaceAssertions .assertEntities(myProject, allDynamicPhases.map { GradleTestEntityId (it) }) {
385+ " Entities should be created for completed phases.\n " +
386+ " Requested phases = $allPhases "
387+ " Completed phases = $completedPhases "
388+ }
389+
390+ val dataServicesEntities = myProject.workspaceModel.currentSnapshot.entitiesBySource {
391+ it is GradleEntitySource && it.phase == GradleSyncPhase .DATA_SERVICES_PHASE
392+ }
393+ Assertions .assertTrue(dataServicesEntities.toList().isNotEmpty()) {
394+ " There should be at least one entity with phase ${GradleSyncPhase .DATA_SERVICES_PHASE } "
395+ }
396+ }
397+ }
398+ }
399+
400+
304401 @Test
305402 fun `test phased Gradle sync for custom static phase without model provider` () {
306403 `test phased Gradle sync for custom phase without model provider`(
0 commit comments