diff --git a/src/main/java/org/gradle/profiler/studio/launcher/StudioLauncherProvider.java b/src/main/java/org/gradle/profiler/studio/launcher/StudioLauncherProvider.java index 154de7d0..92abf0fd 100644 --- a/src/main/java/org/gradle/profiler/studio/launcher/StudioLauncherProvider.java +++ b/src/main/java/org/gradle/profiler/studio/launcher/StudioLauncherProvider.java @@ -93,6 +93,7 @@ private List getAdditionalJvmArgs() { if (SHOULD_RUN_HEADLESS) { systemProperties.put("java.awt.headless", "true"); } + systemProperties.put("external.system.auto.import.disabled", "true"); systemProperties.forEach((k, v) -> jvmArgs.add(String.format("-D%s=%s", k, v))); return jvmArgs; } diff --git a/subprojects/studio-plugin/build.gradle.kts b/subprojects/studio-plugin/build.gradle.kts index fd759aef..5c65da89 100644 --- a/subprojects/studio-plugin/build.gradle.kts +++ b/subprojects/studio-plugin/build.gradle.kts @@ -43,6 +43,9 @@ java { tasks.test { useJUnitPlatform() + // Disable IntelliJ file system access check for tests: having this check enabled can fail + // CI builds since Gradle user home can be mounted, e.g. it can be located in the /mnt/tcagent1/.gradle + systemProperty("NO_FS_ROOTS_ACCESS_CHECK", "true") } intellij { diff --git a/subprojects/studio-plugin/src/main/java/org/gradle/profiler/studio/plugin/client/GradleProfilerClient.java b/subprojects/studio-plugin/src/main/java/org/gradle/profiler/studio/plugin/client/GradleProfilerClient.java index 86c2c61b..cbeae990 100644 --- a/subprojects/studio-plugin/src/main/java/org/gradle/profiler/studio/plugin/client/GradleProfilerClient.java +++ b/subprojects/studio-plugin/src/main/java/org/gradle/profiler/studio/plugin/client/GradleProfilerClient.java @@ -4,12 +4,17 @@ import com.intellij.ide.caches.CachesInvalidator; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; +import com.intellij.openapi.project.ProjectUtil; +import com.intellij.openapi.util.registry.Registry; +import com.intellij.openapi.vfs.VirtualFile; import org.gradle.profiler.client.protocol.Client; import org.gradle.profiler.client.protocol.messages.StudioCacheCleanupCompleted; import org.gradle.profiler.client.protocol.messages.StudioRequest; import org.gradle.profiler.client.protocol.messages.StudioSyncRequestCompleted; import org.gradle.profiler.studio.plugin.system.GradleSystemListener; import org.gradle.profiler.studio.plugin.system.GradleSyncResult; +import org.jetbrains.plugins.gradle.service.project.open.GradleProjectImportUtil; +import org.jetbrains.plugins.gradle.settings.GradleSettings; import java.time.Duration; import java.util.concurrent.TimeUnit; @@ -38,6 +43,7 @@ public GradleProfilerClient(Client client) { public StudioRequest listenForSyncRequests(Project project, GradleSystemListener gradleSystemListener) { StudioRequest request = receiveNextEvent(); waitOnPostStartupActivities(project); + maybeImportProject(project); while (shouldHandleNextEvent(request)) { handleGradleProfilerRequest(request, project, gradleSystemListener); request = receiveNextEvent(); @@ -45,6 +51,15 @@ public StudioRequest listenForSyncRequests(Project project, GradleSystemListener return request; } + private void maybeImportProject(Project project) { + GradleSettings gradleSettings = GradleSettings.getInstance(project); + if (gradleSettings.getLinkedProjectsSettings().isEmpty()) { + VirtualFile projectDir = ProjectUtil.guessProjectDir(project); + // We disabled auto import with 'external.system.auto.import.disabled=true', so we need to link and refresh the project manually + GradleProjectImportUtil.linkAndRefreshGradleProject(projectDir.getPath(), project); + } + } + private StudioRequest receiveNextEvent() { return client.receiveStudioRequest(Duration.ofDays(1)); } diff --git a/subprojects/studio-plugin/src/test/groovy/org/gradle/profiler/studio/plugin/StudioPluginIntegrationTest.groovy b/subprojects/studio-plugin/src/test/groovy/org/gradle/profiler/studio/plugin/StudioPluginIntegrationTest.groovy index e42afecb..df8e51b1 100644 --- a/subprojects/studio-plugin/src/test/groovy/org/gradle/profiler/studio/plugin/StudioPluginIntegrationTest.groovy +++ b/subprojects/studio-plugin/src/test/groovy/org/gradle/profiler/studio/plugin/StudioPluginIntegrationTest.groovy @@ -3,6 +3,7 @@ package org.gradle.profiler.studio.plugin import com.intellij.openapi.application.ApplicationInfo import com.intellij.openapi.application.PathManager import com.intellij.openapi.project.ProjectUtil +import com.intellij.openapi.util.registry.Registry import org.gradle.profiler.client.protocol.ServerConnection import org.gradle.profiler.client.protocol.messages.StudioRequest import org.gradle.profiler.client.protocol.messages.StudioSyncRequestCompleted @@ -18,6 +19,11 @@ import static org.gradle.profiler.client.protocol.messages.StudioSyncRequestComp class StudioPluginIntegrationTest extends StudioPluginSpecification { + def setup() { + // Our plugin expects auto-import is disabled + Registry.get("external.system.auto.import.disabled").setValue(true) + } + def "should successfully sync Gradle project"() { given: ServerConnection connection = server.waitForIncoming(Duration.ofSeconds(10))