Fix IJPL-217529: What's New: find the first existing resource, not just first

GitOrigin-RevId: 674ec77a51aec24eaf1aed21f3371f26174e803d
This commit is contained in:
Ivan Migalev
2025-11-08 19:11:35 +00:00
committed by intellij-monorepo-bot
parent 44816cafd8
commit 06f954ad70
5 changed files with 37 additions and 2 deletions
+7
View File
@@ -16,6 +16,12 @@ resourcegroup(
strip_prefix = "resources"
)
resourcegroup(
name = "whatsNew_test_resources",
srcs = glob(["testResources/**/*"]),
strip_prefix = "testResources"
)
jvm_library(
name = "whatsNew",
module_name = "intellij.platform.whatsNew",
@@ -48,6 +54,7 @@ jvm_library(
name = "whatsNew_test_lib",
visibility = ["//visibility:public"],
srcs = glob(["testSrc/**/*.kt", "testSrc/**/*.java", "testSrc/**/*.form"], allow_empty = True),
resources = [":whatsNew_test_resources"],
kotlinc_opts = ":custom_whatsNew",
associates = [":whatsNew"],
deps = [
@@ -27,6 +27,7 @@
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/testSrc" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/testResources" type="java-test-resource" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
@@ -133,9 +133,9 @@ class ResourceContentSource(private val classLoader: ClassLoader, private val re
constructor(classLoader: ClassLoader, resourceName: String) : this(classLoader, listOf(resourceName))
override suspend fun openStream(): InputStream? = withContext(Dispatchers.IO) {
resourceNames.asSequence().map {
resourceNames.firstNotNullOfOrNull {
classLoader.getResourceAsStream(it)
}.firstOrNull()
}
}
override suspend fun checkAvailability(): Boolean = withContext(Dispatchers.IO) {
resourceNames.any { classLoader.getResource(it) != null }
@@ -0,0 +1,26 @@
// 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.platform.whatsNew
import com.intellij.testFramework.junit5.TestApplication
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
@TestApplication
class WhatsNewVisionContentProviderTest {
// IJPL-217529
@Test
fun testLegacyResourceNaming() {
val provider = object : WhatsNewInVisionContentProvider() {
fun extractResourceNames() = getVisionJsonResourceNames()
}
val resourceNames = provider.extractResourceNames()
val contentSource = ResourceContentSource(this::class.java.classLoader, resourceNames)
runBlocking {
Assertions.assertTrue(contentSource.checkAvailability(), "Resource availability check failed")
Assertions.assertTrue(contentSource.openStream() != null, "Resource stream opening failed")
}
}
}