Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asodja/ide starter #545

Open
wants to merge 2 commits into
base: ide-provisioning-java17
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ spock = "2.1-groovy-3.0"

[libraries]
commonIo = "commons-io:commons-io:2.11.0"
ideStarter = "com.jetbrains.intellij.tools:ide-starter-squashed:233.13135.103"
ideStarter = "com.jetbrains.intellij.tools:ide-starter-squashed:233.14475.28"
toolingApi = "org.gradle:gradle-tooling-api:7.2"

spock-core = { module = "org.spockframework:spock-core", version.ref = "spock" }
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/org/gradle/profiler/studio/StudioGradleClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.gradle.profiler.InvocationSettings;
import org.gradle.profiler.client.protocol.ServerConnection;
import org.gradle.profiler.client.protocol.messages.*;
import org.gradle.profiler.ide.RunIde;
import org.gradle.profiler.instrument.GradleInstrumentation;
import org.gradle.profiler.result.BuildActionResult;
import org.gradle.profiler.studio.invoker.StudioBuildActionResult;
Expand Down Expand Up @@ -33,6 +34,9 @@

public class StudioGradleClient implements GradleClient {


private final InvocationSettings invocationSettings;

public enum CleanCacheMode {
BEFORE_SCENARIO,
BEFORE_BUILD,
Expand All @@ -43,6 +47,7 @@ public enum CleanCacheMode {
private static final Duration GRADLE_INVOCATION_STARTED_TIMEOUT = Duration.ofMillis(100);
private static final Duration GRADLE_INVOCATION_COMPLETED_TIMEOUT = Duration.ofMinutes(60);
private static final Duration SYNC_REQUEST_COMPLETED_TIMEOUT = Duration.ofMinutes(90);
private final StudioInstallDirSupplier studioInstallDirSupplier;

private final StudioProcessController processController;
private final StudioPluginInstaller studioPluginInstaller;
Expand All @@ -58,18 +63,24 @@ public StudioGradleClient(
) {
this.isFirstRun = true;
this.cleanCacheMode = cleanCacheMode;
Supplier<Path> studioInstallDirSupplier = new StudioInstallDirSupplier(invocationSettings, buildConfiguration);
this.studioInstallDirSupplier = new StudioInstallDirSupplier(invocationSettings, buildConfiguration);
Optional<File> studioSandboxDir = invocationSettings.getStudioSandboxDir();
this.sandbox = StudioSandboxCreator.createSandbox(studioSandboxDir.map(File::toPath).orElse(null));
Path protocolJar = GradleInstrumentation.unpackPlugin("client-protocol").toPath();
Path studioPlugin = GradleInstrumentation.unpackPlugin("studio-plugin").toPath();
this.studioPluginInstaller = new StudioPluginInstaller(sandbox.getPluginsDir());
studioPluginInstaller.installPlugin(Arrays.asList(studioPlugin, protocolJar));
this.invocationSettings = invocationSettings;
this.processController = new StudioProcessController(studioInstallDirSupplier, sandbox, invocationSettings, buildConfiguration);
this.executor = Executors.newSingleThreadExecutor();
}

public BuildActionResult sync(List<String> gradleArgs, List<String> jvmArgs) {
new RunIde().runIde(
invocationSettings.getProjectDir().getAbsolutePath(),
"2023.2.3",
studioInstallDirSupplier.get().toString()
);
if (shouldCleanCache()) {
processController.runAndWaitToStop((connections) -> {
System.out.println("* Cleaning Android Studio cache, this will require a restart...");
Expand Down
5 changes: 3 additions & 2 deletions subprojects/ide-provisioning/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
plugins {
id("profiler.embedded-library")
id("profiler.publication")
kotlin("jvm") version "1.9.22"
}

description = "IDE provisioning capabilities for Gradle profiler"

repositories { }

dependencies {
implementation(libs.ideStarter) {
exclude(group = "io.ktor")
exclude(group = "com.jetbrains.infra")
exclude(group = "com.jetbrains.intellij.remoteDev")
}
testImplementation(libs.bundles.testDependencies)
testImplementation(libs.commonIo)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.gradle.profiler.ide

import com.intellij.ide.starter.ide.IdeDistributionFactory
import com.intellij.ide.starter.ide.IdeInstaller
import com.intellij.ide.starter.ide.IdeProductProvider
import com.intellij.ide.starter.ide.InstalledIde
import com.intellij.ide.starter.models.IdeInfo
import com.intellij.ide.starter.models.TestCase
import com.intellij.ide.starter.project.LocalProjectInfo
import com.intellij.tools.ide.performanceTesting.commands.CommandChain
import com.intellij.tools.ide.performanceTesting.commands.exitApp
import com.intellij.tools.ide.performanceTesting.commands.importGradleProject
import com.intellij.tools.ide.performanceTesting.commands.waitForSmartMode
import java.nio.file.Path
import java.nio.file.Paths

class RunIde {

fun runIde(projectLocation: String, buildVersion: String, ideLocation: String) {
val testVersion = "2021.2.2"
val ideInfo = IdeInfo(
productCode = "IC",
version = "2023.2.3",
buildNumber = buildVersion,
executableFileName = "idea",
fullName = "IntelliJ IDEA Community",
platformPrefix = "idea",
getInstaller = { _ -> IdeLocalInstaller(Paths.get(ideLocation)) }
)
val testCase = TestCase(
ideInfo,
LocalProjectInfo(Paths.get(projectLocation)),
)
val context = Starter.newContext("test", testCase)
.applyVMOptionsPatch {
removeProfilerAgents()

}

context.runIDE(commands = CommandChain().importGradleProject().waitForSmartMode().importGradleProject())
println("Waiting for 10 seconds")
Thread.sleep(10_000)
context.runIDE(commands = CommandChain().importGradleProject().waitForSmartMode().exitApp())
}

class IdeLocalInstaller(private val installedLocation: Path) : IdeInstaller {
override fun install(ideInfo: IdeInfo, includeRuntimeModuleRepository: Boolean): Pair<String, InstalledIde> {
return ideInfo.buildNumber to IdeDistributionFactory.installIDE(installedLocation.toFile().parentFile, ideInfo.executableFileName)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.gradle.profiler.ide

import com.intellij.ide.starter.ide.IDETestContext
import com.intellij.ide.starter.models.TestCase
import com.intellij.ide.starter.runner.TestContainer
import com.intellij.ide.starter.runner.TestContainerImpl

object Starter {
fun newTestContainer(): TestContainer<*> {
return TestContainerImpl()
}

fun newContext(testName: String, testCase: TestCase<*>, preserveSystemDir: Boolean = false): IDETestContext =
newTestContainer().initializeTestContext(testName = testName, testCase = testCase, preserveSystemDir = preserveSystemDir)
}
Loading