Skip to content

Commit

Permalink
Merge pull request #544 from gradle/asodja/better-headless-2023.2
Browse files Browse the repository at this point in the history
Improve initial sync handling in headless mode
  • Loading branch information
asodja authored Mar 12, 2024
2 parents 2b4653e + 83dacfc commit c5b6e32
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ private List<String> 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;
}
Expand Down
3 changes: 3 additions & 0 deletions subprojects/studio-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -38,13 +43,23 @@ 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();
}
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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down

0 comments on commit c5b6e32

Please sign in to comment.