mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-13 06:59:44 +07:00
Cleanup (minor optimization; typos; formatting)
(cherry picked from commit 6b29ba37fb1a74af33bbbf78fb4d353bb1f76a60) (cherry picked from commit 7e6df0a65da053bbc2aea9bdc08017565cfb5c8c) IJ-CR-155171 GitOrigin-RevId: c4bc63da9d5e7d0457376bfaa4380cde59ab54d1
This commit is contained in:
committed by
intellij-monorepo-bot
parent
9c2cf149ef
commit
daedb39b66
@@ -1,3 +1,4 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.notebooks.jupyter.core.jupyter
|
||||
|
||||
import com.intellij.ide.plugins.DynamicPluginListener
|
||||
@@ -31,4 +32,4 @@ class JupyterCorePluginListener : DynamicPluginListener {
|
||||
|
||||
const val JUPYTER_PLUGIN_ID = "intellij.jupyter"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.notebooks.jupyter.core.jupyter.preview
|
||||
|
||||
|
||||
import com.intellij.ide.plugins.cl.PluginAwareClassLoader
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.diagnostic.thisLogger
|
||||
import com.intellij.openapi.util.io.FileUtilRt
|
||||
import com.intellij.openapi.util.io.toCanonicalPath
|
||||
import com.intellij.util.PathUtil
|
||||
import io.netty.channel.ChannelHandlerContext
|
||||
import io.netty.handler.codec.http.EmptyHttpHeaders
|
||||
@@ -15,22 +13,19 @@ import io.netty.handler.codec.http.QueryStringDecoder
|
||||
import org.apache.http.client.utils.URIBuilder
|
||||
import org.jetbrains.ide.HttpRequestHandler
|
||||
import java.io.File
|
||||
import java.net.URI
|
||||
import java.net.URL
|
||||
import java.nio.file.Path
|
||||
|
||||
/**
|
||||
* "Web server" to serve Jupyter HTML
|
||||
*/
|
||||
abstract class JupyterCefHttpHandlerBase(private val absolutePathFiles: Collection<String> = emptyList()) : HttpRequestHandler() {
|
||||
|
||||
abstract class JupyterCefHttpHandlerBase(private val absolutePathFiles: Set<String>) : HttpRequestHandler() {
|
||||
companion object {
|
||||
private val allowedTypes = setOf("css", "js", "html", "svg", "woff", "woff2", "ttf")
|
||||
private const val JUPYTER_HTTP_URI = "jupyter"
|
||||
private const val PATH_PREFIX = "/$JUPYTER_HTTP_URI"
|
||||
private const val PATH_PREFIX = "/${JUPYTER_HTTP_URI}"
|
||||
|
||||
/**
|
||||
* Jupyter HTTP files can be accessed with this url
|
||||
* Jupyter HTTP files can be accessed with this URL
|
||||
*/
|
||||
fun getJupyterHttpUrl(): URIBuilder = getJupyterBaseUrl("http").addPathSegment(JUPYTER_HTTP_URI)
|
||||
|
||||
@@ -41,15 +36,15 @@ abstract class JupyterCefHttpHandlerBase(private val absolutePathFiles: Collecti
|
||||
|
||||
/**
|
||||
* Resources are in different folders when launched locally versus installation.
|
||||
* This method handles this difference. See .groovy build scripts
|
||||
* This method handles this difference; see build scripts.
|
||||
*/
|
||||
private fun getResource(javaClass: Class<*>, path: String): URL {
|
||||
// After optimizations in PluginClassLoader, classLoader.getResource return null in debug,
|
||||
// so we have additional logic with PluginClassLoader.pluginDescriptor. This is only for debugging purposes.
|
||||
var url = javaClass.classLoader.getResource(path)
|
||||
?: (javaClass.classLoader as? PluginAwareClassLoader)?.pluginDescriptor?.getPluginPath()?.let { Path.of(it.toCanonicalPath(), path) }?.toUri()?.toURL()
|
||||
?: (javaClass.classLoader as? PluginAwareClassLoader)?.pluginDescriptor?.getPluginPath()?.normalize()?.resolve(path)?.toUri()?.toURL()
|
||||
|
||||
// In remote dev, when we running remote-front via 'split (dev-build) run config, we have:
|
||||
// In remote dev, when we run remote-front via 'split (dev-build)' run config, we have:
|
||||
// (javaClass.classLoader as PluginClassLoader).getAllParents().mapNotNull{it as? PluginClassLoader}.map() { loader -> loader.pluginDescriptor.pluginPath }
|
||||
// = out/classes/production/intellij.jupyter.plugin.frontend or out/classes/production/intellij.notebooks.plugin
|
||||
// PathUtil.getJarPathForClass(javaClass) = out/classes/production/intellij.jupyter.core
|
||||
@@ -70,18 +65,14 @@ abstract class JupyterCefHttpHandlerBase(private val absolutePathFiles: Collecti
|
||||
}
|
||||
}
|
||||
|
||||
override fun isSupported(request: FullHttpRequest): Boolean {
|
||||
return super.isSupported(request) && request.uri().let { it.startsWith(PATH_PREFIX) || it in absolutePathFiles }
|
||||
}
|
||||
override fun isSupported(request: FullHttpRequest): Boolean =
|
||||
super.isSupported(request) && request.uri().let { it.startsWith(PATH_PREFIX) || it in absolutePathFiles }
|
||||
|
||||
override fun process(urlDecoder: QueryStringDecoder,
|
||||
request: FullHttpRequest,
|
||||
context: ChannelHandlerContext): Boolean {
|
||||
val str = request.uri()
|
||||
val fullUri = URI(str).path
|
||||
val uri = getFileFromUrl(fullUri) ?: return false
|
||||
override fun process(urlDecoder: QueryStringDecoder, request: FullHttpRequest, context: ChannelHandlerContext): Boolean {
|
||||
val fullPath = urlDecoder.path()
|
||||
val uri = getFileFromUrl(fullPath) ?: return false
|
||||
val readBytes = processInternalLibs(uri) ?: return false
|
||||
sendData(readBytes, "$appName/$uri", request, context.channel(), EmptyHttpHeaders.INSTANCE)
|
||||
sendData(readBytes, "${appName}/${uri}", request, context.channel(), EmptyHttpHeaders.INSTANCE)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -93,7 +84,7 @@ abstract class JupyterCefHttpHandlerBase(private val absolutePathFiles: Collecti
|
||||
return readFile(uri)
|
||||
}
|
||||
else {
|
||||
thisLogger().info("Extension not allowed: $extension")
|
||||
thisLogger().info("Extension not allowed: ${extension}")
|
||||
}
|
||||
return null
|
||||
}
|
||||
@@ -123,7 +114,7 @@ abstract class JupyterCefHttpHandlerBase(private val absolutePathFiles: Collecti
|
||||
if (file.contains("BASE_EXTENSION_PATH"))
|
||||
return null
|
||||
val appName = appName
|
||||
val resource = getResource(this::class.java, "$appName/$file")
|
||||
val resource = getResource(this::class.java, "${appName}/${file}")
|
||||
return resource.readBytes()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.notebooks.jupyter.core.lang
|
||||
|
||||
import com.intellij.lang.Language
|
||||
@@ -6,4 +7,4 @@ import com.intellij.lang.Language
|
||||
* General language for notebooks.
|
||||
* To share some of the common features for the notebooks, their language should use [NotebookLanguage] as base one.
|
||||
*/
|
||||
object NotebookLanguage: Language("Notebook")
|
||||
object NotebookLanguage: Language("Notebook")
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.jupyter.viewOnly
|
||||
|
||||
import com.intellij.notebooks.jupyter.core.jupyter.preview.JupyterCefHttpHandlerBase
|
||||
|
||||
class JupyterViewOnlyHandler : JupyterCefHttpHandlerBase(absolutePathFiles = listOf(
|
||||
"/ipywidgets.html",
|
||||
"/ipywidgets.css",
|
||||
"/ipywidgets.js")) {
|
||||
class JupyterViewOnlyHandler : JupyterCefHttpHandlerBase(
|
||||
absolutePathFiles = hashSetOf("/ipywidgets.html", "/ipywidgets.css", "/ipywidgets.js")
|
||||
) {
|
||||
override val appName: String = "jupyter-view-only"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user