Skip to content

Commit

Permalink
[workspace model tests] AT-427 Downloading public installers even on …
Browse files Browse the repository at this point in the history
…dev build server

GitOrigin-RevId: 77a44356c4e42dbea24566c52729114408a85496
  • Loading branch information
Nikita-Kudrin authored and intellij-monorepo-bot committed Oct 2, 2023
1 parent 3549f79 commit b3fe73f
Show file tree
Hide file tree
Showing 19 changed files with 90 additions and 77 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.intellij.ide.starter.community

import com.intellij.ide.starter.ide.IdeDownloader
import com.intellij.ide.starter.ide.installer.IdeInstaller
import com.intellij.ide.starter.ide.installer.IdeInstallerFile
import com.intellij.ide.starter.models.IdeInfo
import com.intellij.ide.starter.utils.HttpClient
import com.intellij.ide.starter.utils.logOutput
import java.nio.file.Path
import kotlin.io.path.exists

object IdeByLinkDownloader : IdeDownloader {
override fun downloadIdeInstaller(ideInfo: IdeInfo, installerDirectory: Path): IdeInstaller {
override fun downloadIdeInstaller(ideInfo: IdeInfo, installerDirectory: Path): IdeInstallerFile {
requireNotNull(ideInfo.downloadURI) { "Download URI should not be null for $ideInfo" }

val installerFile = installerDirectory.resolve("${ideInfo.installerFilePrefix}-${ideInfo.buildNumber}${ideInfo.installerFileExt}")
Expand All @@ -20,6 +20,6 @@ object IdeByLinkDownloader : IdeDownloader {
}
else logOutput("Installer file $installerFile already exists. Skipping download.")

return IdeInstaller(installerFile, ideInfo.buildNumber)
return IdeInstallerFile(installerFile, ideInfo.buildNumber)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.intellij.ide.starter.community

import com.intellij.ide.starter.community.model.ReleaseInfo
import com.intellij.ide.starter.ide.IdeDownloader
import com.intellij.ide.starter.ide.installer.IdeInstaller
import com.intellij.ide.starter.ide.installer.IdeInstallerFile
import com.intellij.ide.starter.models.IdeInfo
import com.intellij.ide.starter.system.OsType
import com.intellij.ide.starter.system.SystemInfo
Expand Down Expand Up @@ -36,7 +36,7 @@ object PublicIdeDownloader : IdeDownloader {
throw NoSuchElementException("Couldn't find specified release by parameters $filteringParams")
}

override fun downloadIdeInstaller(ideInfo: IdeInfo, installerDirectory: Path): IdeInstaller {
override fun downloadIdeInstaller(ideInfo: IdeInfo, installerDirectory: Path): IdeInstallerFile {
val params = ProductInfoRequestParameters(type = ideInfo.productCode,
snapshot = ideInfo.buildType,
buildNumber = ideInfo.buildNumber,
Expand Down Expand Up @@ -64,6 +64,6 @@ object PublicIdeDownloader : IdeDownloader {
}
else logOutput("Installer file $installerFile already exists. Skipping download.")

return IdeInstaller(installerFile, possibleBuild.build)
return IdeInstallerFile(installerFile, possibleBuild.build)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import com.intellij.ide.starter.frameworks.Framework
import com.intellij.ide.starter.ide.CodeInjector
import com.intellij.ide.starter.ide.IDETestContext
import com.intellij.ide.starter.ide.IdeDownloader
import com.intellij.ide.starter.ide.IdeInstallator
import com.intellij.ide.starter.ide.installer.IdeInstallerFactory
import com.intellij.ide.starter.models.IdeInfo
import com.intellij.ide.starter.models.IdeProduct
import com.intellij.ide.starter.models.IdeProductImp
import com.intellij.ide.starter.path.GlobalPaths
Expand Down Expand Up @@ -49,7 +47,7 @@ var di = DI {
bindSingleton<CodeInjector> { CodeBuilderHost() }
bindFactory { testContext: IDETestContext -> PluginConfigurator(testContext) }
bindSingleton<IdeDownloader> { PublicIdeDownloader }
bindFactory<IdeInfo, IdeInstallator> { ideInfo -> IdeInstallerFactory().createInstaller(ideInfo) }
bindSingleton<IdeInstallerFactory> { IdeInstallerFactory() }

// you can extend DI with frameworks, specific to IDE language stack
bindArgSet<IDETestContext, Framework>()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
package com.intellij.ide.starter.ide

import java.nio.file.Path
import kotlin.io.path.isRegularFile
import kotlin.io.path.readText

abstract class IdeDistribution {
abstract fun installIde(unpackDir: Path, executableFileName: String): InstalledIde

companion object {
/** @return Product code and build number */
fun readProductCodeAndBuildNumberFromBuildTxt(buildTxtPath: Path): Pair<String, String> {
require(buildTxtPath.isRegularFile()) { "Cannot find build.txt file" }

val (productCode, build) = buildTxtPath.readText().trim().split("-", limit = 2)
return Pair(productCode, build)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.intellij.ide.starter.ide

import com.intellij.ide.starter.ide.installer.IdeInstaller
import com.intellij.ide.starter.ide.installer.IdeInstallerFile
import com.intellij.ide.starter.models.IdeInfo
import java.nio.file.Path

interface IdeDownloader {
fun downloadIdeInstaller(ideInfo: IdeInfo, installerDirectory: Path): IdeInstaller
fun downloadIdeInstaller(ideInfo: IdeInfo, installerDirectory: Path): IdeInstallerFile
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.intellij.ide.starter.ide

import com.intellij.ide.starter.di.di
import com.intellij.ide.starter.models.IdeInfo
import org.kodein.di.direct
import org.kodein.di.instance

interface IdeInstaller {
val downloader: IdeDownloader
get() = di.direct.instance<IdeDownloader>()

/**
* @return <Build Number, InstalledIde>
*/
fun install(ideInfo: IdeInfo): Pair<String, InstalledIde>
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ interface InstalledIde {

fun resolveAndDownloadTheSameJDK(): Path

fun isMajorVersionAtLeast(v: Int) = build.substringBefore(".").toIntOrNull()?.let { it >= v } ?: true
/** Check the major version of the build number.
* Eg: 232.9921.47 => 232
**/
fun isMajorBuildVersionAtLeast(v: Int) = build.substringBefore(".").toIntOrNull()?.let { it >= v } ?: true
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ class LinuxIdeDistribution : IdeDistribution() {
require(SystemInfo.isLinux) { "Can only run on Linux, docker is possible, please PR" }

val appHome = (unpackDir.toFile().listFiles()?.singleOrNull { it.isDirectory }?.toPath() ?: unpackDir).toAbsolutePath()

val buildTxtPath = appHome.resolve("build.txt")
require(buildTxtPath.isRegularFile()) { "Cannot find build.txt file in $appHome" }
val (productCode, build) = buildTxtPath.readText().trim().split("-", limit = 2)
val (productCode, build) = readProductCodeAndBuildNumberFromBuildTxt(appHome.resolve("build.txt"))

val binDir = appHome / "bin"
val allBinFiles = binDir.listDirectoryEntries()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import java.nio.file.Path
import kotlin.io.path.div
import kotlin.io.path.isDirectory
import kotlin.io.path.isRegularFile
import kotlin.io.path.readText

class MacOsIdeDistribution : IdeDistribution() {

Expand Down Expand Up @@ -53,10 +52,7 @@ class MacOsIdeDistribution : IdeDistribution() {
val executablePath = appHome / "MacOS" / executableName
require(executablePath.isRegularFile()) { "Cannot find macOS IDE executable file in $executablePath" }

val buildTxtPath = appHome / "Resources" / "build.txt"
require(buildTxtPath.isRegularFile()) { "Cannot find macOS IDE vmoptions file in $executablePath" }

val (productCode, build) = buildTxtPath.readText().trim().split("-", limit = 2)
val (productCode, build) = readProductCodeAndBuildNumberFromBuildTxt(appHome / "Resources" / "build.txt")

return object : InstalledIde {
override val bundledPluginsDir = appHome / "plugins"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import com.intellij.ide.starter.system.OsType
import com.intellij.ide.starter.utils.JvmUtils
import com.intellij.ide.starter.utils.logOutput
import java.nio.file.Path
import kotlin.io.path.*
import kotlin.io.path.div
import kotlin.io.path.isDirectory
import kotlin.io.path.listDirectoryEntries

class WindowsIdeDistribution : IdeDistribution() {
override fun installIde(unpackDir: Path, executableFileName: String): InstalledIde {
val buildTxtPath = unpackDir.resolve("build.txt")
require(buildTxtPath.isRegularFile()) { "Cannot find WindowsOS IDE vmoptions file in $unpackDir" }
val (productCode, build) = buildTxtPath.readText().trim().split("-", limit = 2)
val (productCode, build) = readProductCodeAndBuildNumberFromBuildTxt(unpackDir.resolve("build.txt"))

val binDir = unpackDir / "bin"

Expand All @@ -24,7 +24,7 @@ class WindowsIdeDistribution : IdeDistribution() {
return object : InstalledIde {
override val bundledPluginsDir = unpackDir.resolve("plugins")

private val vmOptionsFinal: VMOptions =VMOptions(
private val vmOptionsFinal: VMOptions = VMOptions(
ide = this,
data = emptyList(),
env = emptyMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.intellij.ide.starter.ide.installer
import com.intellij.ide.starter.di.di
import com.intellij.ide.starter.ide.IdeArchiveExtractor
import com.intellij.ide.starter.ide.IdeDistributionFactory
import com.intellij.ide.starter.ide.IdeInstallator
import com.intellij.ide.starter.ide.IdeInstaller
import com.intellij.ide.starter.ide.InstalledIde
import com.intellij.ide.starter.models.IdeInfo
import com.intellij.ide.starter.path.GlobalPaths
Expand All @@ -14,7 +14,7 @@ import java.io.File
import java.nio.file.Path
import kotlin.io.path.div

class AndroidInstaller : IdeInstallator {
class AndroidInstaller : IdeInstaller {

/**
* Resolve platform specific android studio installer and return paths
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
package com.intellij.ide.starter.ide.installer

import com.intellij.ide.starter.di.di
import com.intellij.ide.starter.ide.IdeDistributionFactory
import com.intellij.ide.starter.ide.IdeInstallator
import com.intellij.ide.starter.ide.IdeInstaller
import com.intellij.ide.starter.ide.InstalledIde
import com.intellij.ide.starter.models.IdeInfo
import com.intellij.ide.starter.path.GlobalPaths
import org.apache.commons.io.FileUtils
import org.kodein.di.direct
import org.kodein.di.instance
import java.nio.file.Path
import kotlin.io.path.div

/**
* Use existing installed IDE instead of downloading one.
* Set it as:
* `bindFactory<IdeInfo, IdeInstallator>(overrides = true) { _ -> ExistingIdeInstallator(Paths.get(pathToInstalledIDE)) }`
* `bindSingleton<IdeInstallerFactory>(overrides = true) {
* object : IdeInstallerFactory() {
* override fun createInstaller(ideInfo: IdeInfo, downloader: IdeDownloader): IdeInstaller {
* return ExistingIdeInstaller(Paths.get(pathToInstalledIDE))
* }
* }
* }`
*/
class ExistingIdeInstallator(private val installedIdePath: Path) : IdeInstallator {
class ExistingIdeInstaller(private val installedIdePath: Path) : IdeInstaller {
override fun install(ideInfo: IdeInfo): Pair<String, InstalledIde> {
val ideInstaller = IdeInstaller(installedIdePath, "locally-installed-ide")
val ideInstaller = IdeInstallerFile(installedIdePath, "locally-installed-ide")
val installDir = GlobalPaths.instance
.getCacheDirectoryFor("builds") / "${ideInfo.productCode}-${ideInstaller.buildNumber}"
installDir.toFile().deleteRecursively()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package com.intellij.ide.starter.ide.installer

import com.intellij.ide.starter.ide.IdeInstallator
import com.intellij.ide.starter.di.di
import com.intellij.ide.starter.ide.IdeDownloader
import com.intellij.ide.starter.ide.IdeInstaller
import com.intellij.ide.starter.ide.IdeProductProvider
import com.intellij.ide.starter.models.IdeInfo
import org.kodein.di.direct
import org.kodein.di.instance

open class IdeInstallerFactory {
open fun createInstaller(ideInfo: IdeInfo): IdeInstallator {
open fun createInstaller(ideInfo: IdeInfo, downloader: IdeDownloader = di.direct.instance<IdeDownloader>()): IdeInstaller {
return if (ideInfo.productCode == IdeProductProvider.AI.productCode)
AndroidInstaller()
else
SimpleInstaller()
StandardInstaller(downloader)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package com.intellij.ide.starter.ide.installer

import java.nio.file.Path

open class IdeInstaller(val installerFile: Path, val buildNumber: String) {
open class IdeInstallerFile(val installerFile: Path, val buildNumber: String) {
companion object
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package com.intellij.ide.starter.ide.installer

import com.intellij.ide.starter.ide.IdeArchiveExtractor
import com.intellij.ide.starter.ide.IdeDistributionFactory
import com.intellij.ide.starter.ide.IdeInstallator
import com.intellij.ide.starter.ide.InstalledIde
import com.intellij.ide.starter.di.di
import com.intellij.ide.starter.ide.*
import com.intellij.ide.starter.models.IdeInfo
import com.intellij.ide.starter.path.GlobalPaths
import com.intellij.ide.starter.utils.logOutput
import org.kodein.di.direct
import org.kodein.di.instance
import kotlin.io.path.createDirectories
import kotlin.io.path.div

class SimpleInstaller : IdeInstallator {
/** Prebuilt installer, distributed via archive (.tar.gz, .exe, .dmg) */
class StandardInstaller(override val downloader: IdeDownloader = di.direct.instance<IdeDownloader>()) : IdeInstaller {

override fun install(ideInfo: IdeInfo): Pair<String, InstalledIde> {
val installersDirectory = (GlobalPaths.instance.installersDirectory / ideInfo.productCode).createDirectories()

//Download
val ideInstaller = ideInfo.download(installersDirectory)
val ideInstaller = downloader.downloadIdeInstaller(ideInfo, installersDirectory)
val installDir = GlobalPaths.instance.getCacheDirectoryFor("builds") / "${ideInfo.productCode}-${ideInstaller.buildNumber}"

if (ideInstaller.buildNumber == "SNAPSHOT") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ package com.intellij.ide.starter.models

import com.intellij.ide.starter.community.model.BuildType
import com.intellij.ide.starter.di.di
import com.intellij.ide.starter.ide.IdeDownloader
import com.intellij.ide.starter.ide.installer.IdeInstaller
import com.intellij.ide.starter.ide.IdeInstaller
import com.intellij.ide.starter.ide.installer.IdeInstallerFactory
import com.intellij.ide.starter.system.SystemInfo
import org.kodein.di.direct
import org.kodein.di.instance
import java.net.URI
import java.nio.file.Path

data class IdeInfo(
/**
Expand Down Expand Up @@ -37,13 +36,8 @@ data class IdeInfo(

val fullName: String,

private val downloader: IdeDownloader = di.direct.instance<IdeDownloader>()
val getInstaller: (IdeInfo) -> IdeInstaller = { di.direct.instance<IdeInstallerFactory>().createInstaller(it) }
) {

fun download(installerDirectory: Path): IdeInstaller {
return downloader.downloadIdeInstaller(this, installerDirectory)
}

companion object

val installerFilePrefix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.intellij.ide.starter.models
import com.intellij.ide.starter.community.PublicIdeDownloader
import com.intellij.ide.starter.community.model.BuildType
import com.intellij.ide.starter.ide.IdeProductProvider
import com.intellij.ide.starter.ide.installer.StandardInstaller
import com.intellij.ide.starter.project.GitProjectInfo
import com.intellij.ide.starter.project.LocalProjectInfo
import com.intellij.ide.starter.project.ProjectInfoSpec
Expand Down Expand Up @@ -43,20 +44,22 @@ data class TestCase<T : ProjectInfoSpec>(
buildNumber: String? = null,
version: String? = null
): TestCase<T> {
return copy(ideInfo = ideInfo.copy(
buildType = buildType?.type ?: "",
downloader = PublicIdeDownloader,
buildNumber = buildNumber ?: "",
version = version ?: ""
))
return copy(
ideInfo = ideInfo.copy(
buildType = buildType?.type ?: "",
buildNumber = buildNumber ?: "",
version = version ?: ""
).run { this.copy(getInstaller = { StandardInstaller(PublicIdeDownloader) }) }
)
}

fun useRC(): TestCase<T> = copyWithPublicIdeDownloaderAndUpdatedInfo(buildType = BuildType.RC)

fun useEAP(): TestCase<T> = copyWithPublicIdeDownloaderAndUpdatedInfo(buildType = BuildType.EAP)

/** E.g: "222.3244.1" */
private fun useEAP(buildNumber: String = ""): TestCase<T> = copyWithPublicIdeDownloaderAndUpdatedInfo(BuildType.EAP, buildNumber = buildNumber)
private fun useEAP(buildNumber: String = ""): TestCase<T> = copyWithPublicIdeDownloaderAndUpdatedInfo(BuildType.EAP,
buildNumber = buildNumber)

fun useRelease(): TestCase<T> = copyWithPublicIdeDownloaderAndUpdatedInfo(buildType = BuildType.RELEASE)

Expand Down
Loading

0 comments on commit b3fe73f

Please sign in to comment.