mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
[plugins] IJPL-221014 Cloud plugins are not suggested anymore
(cherry picked from commit ca5217748f4c6cee5c3576ee29bf0b3cf5c00aae) IJ-CR-184444 GitOrigin-RevId: c8c48d7dd673141c148288c96ed36cb8e3d00f2d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
4adb08116d
commit
7fef480f21
@@ -6,8 +6,8 @@ import com.intellij.ide.plugins.DependencyCollector
|
||||
import com.intellij.ide.plugins.DependencyInformation
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.IntellijInternalApi
|
||||
import com.intellij.openapi.util.SystemInfo
|
||||
import com.intellij.util.EnvironmentUtil
|
||||
import com.intellij.util.system.OS
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import java.nio.file.FileSystems
|
||||
import java.nio.file.Files
|
||||
@@ -16,8 +16,6 @@ import java.nio.file.Path
|
||||
import kotlin.io.path.isExecutable
|
||||
import kotlin.io.path.isRegularFile
|
||||
|
||||
@ApiStatus.Internal
|
||||
@IntellijInternalApi
|
||||
internal class EnvironmentDependencyCollector : DependencyCollector {
|
||||
private val ALLOWED_EXECUTABLES: List<String> = listOf(
|
||||
"docker",
|
||||
@@ -45,7 +43,11 @@ internal class EnvironmentDependencyCollector : DependencyCollector {
|
||||
object EnvironmentScanner {
|
||||
fun getPathNames(): List<Path> {
|
||||
val fs = FileSystems.getDefault()
|
||||
val pathNames = EnvironmentUtil.getEnvironmentMap()["PATH"]?.split(fs.separator)
|
||||
|
||||
@Suppress("IO_FILE_USAGE")
|
||||
val pathDelimiter = java.io.File.pathSeparatorChar
|
||||
|
||||
val pathNames = EnvironmentUtil.getEnvironmentMap()["PATH"]?.split(pathDelimiter)
|
||||
?.mapNotNull {
|
||||
try {
|
||||
fs.getPath(it)
|
||||
@@ -59,7 +61,7 @@ object EnvironmentScanner {
|
||||
}
|
||||
|
||||
fun hasToolInLocalPath(pathNames: List<Path>, executableWithoutExt: String): Boolean {
|
||||
val baseNames = if (SystemInfo.isWindows) {
|
||||
val baseNames = if (OS.CURRENT == OS.Windows) {
|
||||
sequenceOf(".bat", ".cmd", ".com", ".exe")
|
||||
.map { exeSuffix -> executableWithoutExt + exeSuffix }
|
||||
}
|
||||
@@ -72,7 +74,6 @@ object EnvironmentScanner {
|
||||
baseNames.map { basename -> pathEntry.resolve(basename) }
|
||||
}
|
||||
.filter(Path::isRegularFile)
|
||||
.filter(Path::isExecutable)
|
||||
.any()
|
||||
.any(Path::isExecutable)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.ide.plugins.advertiser
|
||||
|
||||
import com.intellij.openapi.updateSettings.impl.pluginsAdvertisement.EnvironmentScanner
|
||||
import com.intellij.util.EnvironmentUtil
|
||||
import com.intellij.util.EnvironmentUtil.getSystemEnv
|
||||
import com.intellij.util.system.OS
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import kotlin.io.path.name
|
||||
|
||||
class EnvironmentScannerTest {
|
||||
@After
|
||||
fun cleanup() {
|
||||
EnvironmentUtil.setEnvironmentLoader(CompletableDeferred(getSystemEnv()))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNames() {
|
||||
val names = listOf(
|
||||
"docker",
|
||||
"git",
|
||||
"terraform"
|
||||
)
|
||||
|
||||
val tmpDir = Files.createTempDirectory("mock-path")
|
||||
val executableFiles = names.map { Files.createFile(tmpDir.resolve(makeExeName(it))) }
|
||||
|
||||
EnvironmentUtil.setEnvironmentLoader(CompletableDeferred(getSystemEnv() + mapOf(
|
||||
"PATH" to executableFiles.joinToString(File.pathSeparator)
|
||||
)))
|
||||
|
||||
val pathNames = EnvironmentScanner.getPathNames()
|
||||
|
||||
assertTrue("PATH is not empty", pathNames.isNotEmpty())
|
||||
assertTrue("PATH contains example names", pathNames.map { it.name }.containsAll(names))
|
||||
|
||||
assertTrue("PATH names do not have File.pathSeparatorChar symbols",
|
||||
pathNames.none { it.toString().contains(File.pathSeparatorChar) })
|
||||
assertTrue("PATH names exist on disk",
|
||||
pathNames.all { Files.exists(it) })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testExecutable() {
|
||||
val tmpDir = Files.createTempDirectory("mock-path")
|
||||
|
||||
val executableFile = Files.createFile(tmpDir.resolve(makeExeName("docker")))
|
||||
executableFile.toFile().setExecutable(true)
|
||||
|
||||
assertTrue("Executable files are present in PATH",
|
||||
EnvironmentScanner.hasToolInLocalPath(listOf(tmpDir), "docker"))
|
||||
|
||||
val nonExecutableFile = Files.createFile(tmpDir.resolve(makeExeName("podman")))
|
||||
nonExecutableFile.toFile().setExecutable(false)
|
||||
|
||||
assertFalse("Non-executable files are not present in PATH",
|
||||
EnvironmentScanner.hasToolInLocalPath(listOf(tmpDir), "podman"))
|
||||
}
|
||||
|
||||
private fun makeExeName(baseName: String): String {
|
||||
return baseName + (if (OS.CURRENT == OS.Windows) ".exe" else "")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user