Skip to content

Commit

Permalink
inject new jcef version
Browse files Browse the repository at this point in the history
  • Loading branch information
956237586 committed Oct 18, 2023
1 parent dbd4e14 commit 8524053
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ electronPackagerVersion=^15.1.0
gradleMkdocsPluginVersion=2.3.0
intellijPlatformVersion=213.6461.23
intellijMarkdownPluginVersion=213.5744.223
intellijJcefVersion=89.0.12-g2b76680-chromium-89.0.4389.90-api-1.6
intellijJcefVersion=104.4.26-g4180781-chromium-104.0.5112.102-api-1.10
istanbulInstrumenterLoaderVersion=3.0.1
javassistVersion=3.28.0-GA
javaWebSocketVersion=1.5.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ internal object IjInjector {
val isAgent: Boolean,
val markdownPanelClassName: String,
val isIdeAttached: Boolean,
)
){
val jcefTransformerInUse by lazy { isIdeAttached }
}

private fun parametersFromArgs(args: Map<String, String>): AgentParameters {

Expand All @@ -51,6 +53,7 @@ internal object IjInjector {
val parameters = parametersFromArgs(args)

// TODO: support same transformers in agent mode too to reach feature parity
// TODO JCEF & Markdown 不支持时,查看这里对应的类加载器
val transformers = listOf(
IjAwtTransformer,
IjLigaturesDisablerTransformer,
Expand All @@ -60,7 +63,6 @@ internal object IjInjector {
IjFastNodeCellRendererTransformer,
IjRestartDisablerTransformer,
)

ProjectorBatchTransformer(transformers).runTransformations(instrumentation, parameters)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,13 @@ internal object IjMdTransformer : IdeTransformerSetup<IjInjector.AgentParameters
}

override fun getClassLoader(parameters: IjInjector.AgentParameters): ClassLoader {
return markdownPlugin!!.pluginClassLoader!!
// return markdownPlugin!!.pluginClassLoader!!
try {
return markdownPlugin!!.pluginClassLoader!!
} catch (e: Exception) {
e.printStackTrace()
return super.getClassLoader(parameters)
}
}

private fun isPreviewCheckIsBrokenInHeadless(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ internal class ProjectorBatchTransformer(transformerSetups: List<IdeTransformerS
val groups = transformerSetups.groupBy { it.loadingState }.toMutableMap()

fun runForState(state: IdeState?): Boolean {
logger.info { "runForState state:$state" }
val transformers = groups[state] ?: return groups.isEmpty()
transformers.forEach { it.runTransformations(instrumentation, parameters, canRetransform) }
logResults(state)
Expand All @@ -56,16 +57,17 @@ internal class ProjectorBatchTransformer(transformerSetups: List<IdeTransformerS

runForState(null)

logger.info { "runTransformations registerStateListener start" }
if (!parameters.isIdeAttached) {
return
}

val requiredStates = groups.keys.filterNotNullTo(mutableSetOf())
registerStateListener("run transformations", IdeStateListener(requiredStates, ::runForState))
logger.info { "runTransformations registerStateListener end" }
}

private fun logResults(state: IdeState?) {
logResults("(State: ${state?.name ?: "Initial"})")
logResults("logResults State: ${state?.name ?: "Initial"})")
results.clear()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
package org.jetbrains.projector.util.loading

import com.intellij.ide.WindowsCommandLineProcessor
import org.jetbrains.projector.util.loading.state.IdeState
import org.jetbrains.projector.util.loading.state.whenOccurred
import java.lang.reflect.Method
Expand All @@ -49,7 +48,9 @@ public object ProjectorClassLoaderSetup {
prjClassLoader.forceLoadByProjectorClassLoader("org.jetbrains.projector.server.core.ij.md.ProjectorMarkdownPanel")

val onIdeClassloaderInstantiated = Runnable {
prjClassLoader.ideaClassLoader = WindowsCommandLineProcessor.ourMainRunnerClass.classLoader
// TODO 获取到真正的类加载器
//prjClassLoader.ideaClassLoader = WindowsCommandLineProcessor.ourMainRunnerClass.classLoader
//prjClassLoader.ideaClassLoader = AppMode::class.java.classLoader
ideaClassLoaderInitialized = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
package org.jetbrains.projector.util.loading.state

import com.intellij.diagnostic.LoadingState
import com.intellij.ide.WindowsCommandLineProcessor
import com.intellij.diagnostic.StartUpMeasurer
import org.jetbrains.projector.util.loading.ProjectorClassLoaderSetup
import org.jetbrains.projector.util.loading.UseProjectorLoader
import org.jetbrains.projector.util.loading.getOption
Expand Down Expand Up @@ -69,16 +69,18 @@ public enum class IdeState {
false -> false

true -> try {
WindowsCommandLineProcessor.ourMainRunnerClass
// TODO 更好的判断IDE是否启动起来 原 WindowsCommandLineProcessor.ourMainRunnerClass
StartUpMeasurer.isEnabled()
true
}
catch (t: Throwable) {
t.printStackTrace()
false
}
}

private val isIdeClassLoaderInstantiated: Boolean
get() = isIdeAttached && WindowsCommandLineProcessor.ourMainRunnerClass != null
get() = isIdeAttached

public val attachToIde: Boolean get() = getOption(ATTACH_TO_IDE_PROPERTY_NAME, "true").toBooleanStrict()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public fun registerStateListener(purpose: String?, listener: IdeStateListener) {
return
}

logger.info { "registerStateListener start" }

scope.launch { runLoopForListener(purpose, listener) }
}

Expand Down

0 comments on commit 8524053

Please sign in to comment.