|
| 1 | +package org.gradle.profiler.ide |
| 2 | + |
| 3 | +import com.intellij.ide.starter.ide.IDETestContext |
| 4 | +import com.intellij.ide.starter.ide.IdeDistributionFactory |
| 5 | +import com.intellij.ide.starter.ide.IdeInstaller |
| 6 | +import com.intellij.ide.starter.ide.InstalledIde |
| 7 | +import com.intellij.ide.starter.ide.installer.ExistingIdeInstaller |
| 8 | +import com.intellij.ide.starter.ide.installer.IdeInstallerFile |
| 9 | +import com.intellij.ide.starter.models.IdeInfo |
| 10 | +import com.intellij.ide.starter.models.TestCase |
| 11 | +import com.intellij.ide.starter.path.GlobalPaths |
| 12 | +import com.intellij.ide.starter.process.exec.ProcessExecutor |
| 13 | +import com.intellij.ide.starter.project.LocalProjectInfo |
| 14 | +import com.intellij.ide.starter.runner.TestContainer |
| 15 | +import com.intellij.ide.starter.runner.TestContainerImpl |
| 16 | +import com.intellij.openapi.util.SystemInfo |
| 17 | +import com.intellij.openapi.util.io.FileUtil |
| 18 | +import java.nio.file.Path |
| 19 | +import java.nio.file.Paths |
| 20 | +import kotlin.io.path.div |
| 21 | +import kotlin.io.path.name |
| 22 | +import kotlin.time.Duration.Companion.minutes |
| 23 | + |
| 24 | +class RunIdeStarterImpl : RunIdeStarter { |
| 25 | + override fun newContext(projectLocation: String, ideLocation: String): RunIdeContext { |
| 26 | + val testVersion = "2023.2.3" |
| 27 | + val ideInfo = IdeInfo( |
| 28 | + productCode = "IC", |
| 29 | + version = "2023.2", |
| 30 | +// buildNumber = testVersion, |
| 31 | + executableFileName = "idea", |
| 32 | + fullName = "IntelliJ IDEA Community", |
| 33 | + platformPrefix = "idea", |
| 34 | + // getInstaller = { _ -> ExistingIdeInstaller(Paths.get(ideLocation)) } |
| 35 | + ) |
| 36 | + val testCase = TestCase( |
| 37 | + ideInfo, |
| 38 | + LocalProjectInfo(Paths.get(projectLocation)), |
| 39 | + ) |
| 40 | + val context = Starter.newContext("test", testCase) |
| 41 | + return RunIdeContextImpl(context) |
| 42 | + } |
| 43 | + |
| 44 | + class ExistingIdeInstaller(private val installedIdePath: Path) : IdeInstaller { |
| 45 | + override fun install(ideInfo: IdeInfo, includeRuntimeModuleRepository: Boolean): Pair<String, InstalledIde> { |
| 46 | + val ideInstaller = IdeInstallerFile(installedIdePath, "locally-installed-ide") |
| 47 | + val installDir = GlobalPaths.instance |
| 48 | + .getCacheDirectoryFor("builds") / "${ideInfo.productCode}-${ideInstaller.buildNumber}" |
| 49 | + installDir.toFile().deleteRecursively() |
| 50 | + val installedIde = installedIdePath.toFile() |
| 51 | + val destDir = installDir.resolve(installedIdePath.name).toFile() |
| 52 | + if (SystemInfo.isMac) { |
| 53 | + ProcessExecutor("copy app", null, 5.minutes, emptyMap(), listOf("ditto", installedIde.absolutePath, destDir.absolutePath)).start() |
| 54 | + } |
| 55 | + else { |
| 56 | + FileUtil.copyDir(installedIde, destDir) |
| 57 | + } |
| 58 | + return Pair( |
| 59 | + ideInstaller.buildNumber, |
| 60 | + IdeDistributionFactory.installIDE(installDir.toFile(), ideInfo.executableFileName) |
| 61 | + ) |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + private object Starter { |
| 66 | + private fun newTestContainer(): TestContainer<*> { |
| 67 | + return TestContainerImpl() |
| 68 | + } |
| 69 | + |
| 70 | + fun newContext(testName: String, testCase: TestCase<*>, preserveSystemDir: Boolean = false): IDETestContext = |
| 71 | + newTestContainer().initializeTestContext( |
| 72 | + testName = testName, |
| 73 | + testCase = testCase, |
| 74 | + preserveSystemDir = preserveSystemDir |
| 75 | + ) |
| 76 | + } |
| 77 | +} |
0 commit comments