dependencies downloader: provide TeamCityHelper.persistentCachePath

GitOrigin-RevId: fafb76b7e08f1dc61271531943b599d5eea75d56
This commit is contained in:
Leonid Shalupov
2024-10-12 17:02:22 +02:00
committed by intellij-monorepo-bot
parent 7255f628e1
commit 2a10f32737
2 changed files with 12 additions and 28 deletions

View File

@@ -13,10 +13,7 @@ import org.jetbrains.intellij.build.dependencies.BuildDependenciesUtil.extractTa
import org.jetbrains.intellij.build.dependencies.BuildDependenciesUtil.extractTarGz
import org.jetbrains.intellij.build.dependencies.BuildDependenciesUtil.extractZip
import org.jetbrains.intellij.build.dependencies.BuildDependenciesUtil.listDirectory
import org.jetbrains.intellij.build.dependencies.TeamCityHelper.isUnderTeamCity
import org.jetbrains.intellij.build.dependencies.TeamCityHelper.systemProperties
import org.jetbrains.intellij.build.downloadFileToCacheLocationSync
import java.io.IOException
import java.io.PrintWriter
import java.io.StringWriter
import java.math.BigInteger
@@ -25,12 +22,7 @@ import java.nio.ByteBuffer
import java.nio.ByteOrder
import java.nio.channels.FileChannel
import java.nio.charset.StandardCharsets
import java.nio.file.FileVisitResult
import java.nio.file.Files
import java.nio.file.LinkOption
import java.nio.file.Path
import java.nio.file.Paths
import java.nio.file.SimpleFileVisitor
import java.nio.file.*
import java.nio.file.attribute.BasicFileAttributes
import java.nio.file.attribute.FileTime
import java.time.Instant
@@ -91,14 +83,9 @@ object BuildDependenciesDownloader {
return Files.createDirectories(communityRoot.communityRoot.resolve("build/download"))
}
@Throws(IOException::class)
private fun getDownloadCachePath(communityRoot: BuildDependenciesCommunityRoot): Path {
val path: Path = if (isUnderTeamCity) {
val persistentCachePath = systemProperties["agent.persistent.cache"]
check(!persistentCachePath.isNullOrBlank()) {
"'agent.persistent.cache' system property is required under TeamCity"
}
Paths.get(persistentCachePath)
val path: Path = if (TeamCityHelper.isUnderTeamCity) {
TeamCityHelper.persistentCachePath ?: error ("'agent.persistent.cache' system property is required under TeamCity")
}
else {
getProjectLocalDownloadCache(communityRoot)
@@ -258,7 +245,7 @@ options:${getExtractOptionsShortString(options)}
// run only once per process
return
}
if (isUnderTeamCity) {
if (TeamCityHelper.isUnderTeamCity) {
// Cleanup on TeamCity is handled by TeamCity
return
}

View File

@@ -1,12 +1,10 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.intellij.build.dependencies
import com.google.common.base.Suppliers
import org.jetbrains.annotations.ApiStatus
import org.jetbrains.intellij.build.dependencies.BuildDependenciesUtil.loadPropertiesFile
import java.nio.file.Files
import java.nio.file.Path
import java.util.function.Supplier
@ApiStatus.Internal
object TeamCityHelper {
@@ -24,18 +22,17 @@ object TeamCityHelper {
if (value.isNullOrEmpty()) {
throw RuntimeException("TeamCity system property " + name + "was not found while running under TeamCity")
}
val file = Path.of(value)
if (!Files.isDirectory(file)) {
throw RuntimeException("TeamCity system property $name contains non existent directory: $file")
}
return file
}
val systemProperties: Map<String, String>
get() = systemPropertiesValue.get()
val allProperties: Map<String, String>
get() = allPropertiesValue.get()
val persistentCachePath: Path?
get() = systemProperties["agent.persistent.cache"]?.let { Path.of(it) }
val tempDirectory: Path?
get() {
@@ -49,9 +46,9 @@ object TeamCityHelper {
return Path.of(tempPath)
}
private val systemPropertiesValue: Supplier<Map<String, String>> = Suppliers.memoize {
val systemProperties: Map<String, String> by lazy {
if (!isUnderTeamCity) {
return@memoize HashMap<String, String>()
return@lazy emptyMap<String, String>()
}
val systemPropertiesEnvName = "TEAMCITY_BUILD_PROPERTIES_FILE"
val systemPropertiesFile = System.getenv(systemPropertiesEnvName)
@@ -65,9 +62,9 @@ object TeamCityHelper {
loadPropertiesFile(file)
}
private val allPropertiesValue: Supplier<Map<String, String>> = Suppliers.memoize {
val allProperties: Map<String, String> by lazy {
if (!isUnderTeamCity) {
return@memoize HashMap<String, String>()
return@lazy HashMap<String, String>()
}
val propertyName = "teamcity.configuration.properties.file"
val value = systemProperties[propertyName]