mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
(IJPL-157828) What's New: provide a resource lookup override mechanism
#IJPL-157828 Fixed GitOrigin-RevId: 6e7da6c9daf5c68c9bc42384f2b2ce51632c6120
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a01e2c2c9f
commit
ff1a51e79f
@@ -1,6 +1,7 @@
|
||||
<idea-plugin package="com.intellij.platform.whatsNew">
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<backgroundPostStartupActivity implementation="com.intellij.platform.whatsNew.WhatsNewShowOnStartCheckService" order="last"/>
|
||||
<applicationService serviceImplementation="com.intellij.platform.whatsNew.WhatsNewInVisionContentProvider" />
|
||||
<statistics.counterUsagesCollector implementationClass="com.intellij.platform.whatsNew.reaction.ReactionCollector"/>
|
||||
<statistics.counterUsagesCollector implementationClass="com.intellij.platform.whatsNew.reaction.LegacyReactionCollector"/>
|
||||
<statistics.counterUsagesCollector implementationClass="com.intellij.platform.whatsNew.collectors.LegacyRiderWhatsNewCounterUsagesCollector"/>
|
||||
|
||||
@@ -35,8 +35,8 @@ internal sealed class WhatsNewContent {
|
||||
get() = CommonDataKeys.PROJECT.getData(this)
|
||||
|
||||
suspend fun getWhatsNewContent(): WhatsNewContent? {
|
||||
return if (WhatsNewInVisionContentProvider.isAvailable()) {
|
||||
WhatsNewVisionContent(WhatsNewInVisionContentProvider.getContent().entities.first())
|
||||
return if (WhatsNewInVisionContentProvider.getInstance().isAvailable()) {
|
||||
WhatsNewVisionContent(WhatsNewInVisionContentProvider.getInstance().getContent().entities.first())
|
||||
} else {
|
||||
ExternalProductResourceUrls.getInstance().whatIsNewPageUrl?.toDecodedForm()?.let { WhatsNewUrlContent(it) }
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ package com.intellij.platform.whatsNew
|
||||
|
||||
import com.intellij.openapi.application.ApplicationInfo
|
||||
import com.intellij.openapi.application.ApplicationNamesInfo
|
||||
import com.intellij.openapi.components.serviceAsync
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
@@ -18,7 +19,12 @@ import kotlin.io.path.Path
|
||||
import kotlin.io.path.inputStream
|
||||
import kotlin.io.path.isRegularFile
|
||||
|
||||
internal object WhatsNewInVisionContentProvider {
|
||||
open class WhatsNewInVisionContentProvider {
|
||||
|
||||
companion object {
|
||||
suspend fun getInstance(): WhatsNewInVisionContentProvider = serviceAsync()
|
||||
}
|
||||
|
||||
suspend fun isAvailable(): Boolean {
|
||||
return content.checkAvailability()
|
||||
}
|
||||
@@ -42,7 +48,7 @@ internal object WhatsNewInVisionContentProvider {
|
||||
@Serializable
|
||||
internal data class PublicVar(val value: String, val description: String)
|
||||
|
||||
private fun getResourceName(): String {
|
||||
protected fun getResourceName(): String {
|
||||
val fileName = "vision.json"
|
||||
val appName = ApplicationNamesInfo.getInstance().productName.lowercase()
|
||||
val isEap = ApplicationInfo.getInstance().isEAP
|
||||
@@ -56,11 +62,14 @@ internal object WhatsNewInVisionContentProvider {
|
||||
}"
|
||||
}
|
||||
|
||||
protected open fun getResource(): ContentSource =
|
||||
ResourceContentSource(WhatsNewInVisionContentProvider::class.java.classLoader, getResourceName())
|
||||
|
||||
private val content: ContentSource by lazy {
|
||||
System.getProperty(PROPERTY_WHATS_NEW_VISION_JSON)?.let { testResourcePath ->
|
||||
logger.info("What's New test mode engaged: loading resource from \"$testResourcePath\".")
|
||||
PathContentSource(Path(testResourcePath))
|
||||
} ?: ResourceContentSource(WhatsNewInVisionContentProvider::class.java.classLoader, getResourceName())
|
||||
} ?: getResource()
|
||||
}
|
||||
|
||||
private val json = Json { ignoreUnknownKeys = true }
|
||||
@@ -75,7 +84,7 @@ private const val PROPERTY_WHATS_NEW_VISION_JSON = "intellij.whats.new.vision.js
|
||||
|
||||
private val logger = logger<WhatsNewInVisionContentProvider>()
|
||||
|
||||
private interface ContentSource {
|
||||
interface ContentSource {
|
||||
suspend fun openStream(): InputStream?
|
||||
suspend fun checkAvailability(): Boolean
|
||||
}
|
||||
@@ -87,7 +96,7 @@ private class PathContentSource(private val path: Path) : ContentSource {
|
||||
path.isRegularFile()
|
||||
}
|
||||
}
|
||||
private class ResourceContentSource(private val classLoader: ClassLoader, private val resourceName: String) : ContentSource {
|
||||
class ResourceContentSource(private val classLoader: ClassLoader, private val resourceName: String) : ContentSource {
|
||||
override suspend fun openStream(): InputStream? = withContext(Dispatchers.IO) {
|
||||
classLoader.getResourceAsStream(resourceName)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user