Skip to content

Commit 066a39a

Browse files
committed
refactor: better windows support
1 parent 6cb92d2 commit 066a39a

File tree

5 files changed

+41
-29
lines changed

5 files changed

+41
-29
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ platformVersion = 2025.1.1
1616

1717
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
1818
# Example: platformPlugins = com.jetbrains.php:203.4449.22, org.intellij.scala:2023.3.27@EAP
19-
platformPlugins=com.jetbrains.php:251.23774.318,com.jetbrains.hackathon.indices.viewer:1.30,com.github.xepozz.php_opcodes_language:2025.0.9
19+
platformPlugins=com.jetbrains.php:251.23774.318,com.jetbrains.hackathon.indices.viewer:1.30,com.github.xepozz.php_opcodes_language:2025.0.10
2020
# Example: platformBundledPlugins = com.intellij.java
2121
platformBundledPlugins=
2222

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.github.xepozz.php_dump
2+
3+
import com.intellij.execution.process.ProcessAdapter
4+
import com.intellij.execution.process.ProcessEvent
5+
import com.intellij.execution.process.ProcessOutputTypes
6+
import com.intellij.openapi.util.Key
7+
8+
9+
class SeparateStringBufferProcessAdapter(val stderr: StringBuilder?, val stdout: StringBuilder?) : ProcessAdapter() {
10+
override fun onTextAvailable(event: ProcessEvent, outputType: Key<*>) {
11+
when (outputType) {
12+
ProcessOutputTypes.STDERR -> stderr?.append(event.text)
13+
ProcessOutputTypes.STDOUT -> stdout?.append(event.text)
14+
}
15+
}
16+
}

src/main/kotlin/com/github/xepozz/php_dump/command/PhpCommandExecutor.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.intellij.execution.process.KillableColoredProcessHandler
66
import com.intellij.execution.process.ProcessAdapter
77
import com.intellij.execution.process.ProcessEvent
88
import com.intellij.execution.process.ProcessHandler
9+
import com.intellij.openapi.diagnostic.thisLogger
910
import com.intellij.openapi.project.Project
1011
import com.intellij.openapi.util.text.StringUtil
1112
import com.jetbrains.php.config.PhpProjectConfigurationFacade
@@ -22,8 +23,6 @@ object PhpCommandExecutor {
2223
processListener: ProcessAdapter,
2324
processArguments: List<String> = emptyList()
2425
) {
25-
println("run php command $file, $phpSnippet")
26-
2726
val arguments = buildList {
2827
addAll(processArguments)
2928
add("-r")
@@ -66,7 +65,7 @@ object PhpCommandExecutor {
6665
.withRedirectErrorStream(false)
6766
.apply { addParameters(arguments) }
6867

69-
println("cmd: ${command.commandLineString}")
68+
thisLogger().info("cmd: ${command.commandLineString}")
7069
processHandler = manager.getRemoteProcessHandler(
7170
project,
7271
data,
@@ -75,7 +74,7 @@ object PhpCommandExecutor {
7574
*phpCommandSettings.additionalMappings
7675
)
7776
} else {
78-
println("cmd: ${command.commandLineString}")
77+
thisLogger().info("cmd: ${command.commandLineString}")
7978
processHandler = KillableColoredProcessHandler.Silent(command)
8079
processHandler.setShouldKillProcessSoftly(false)
8180
processHandler.setShouldDestroyProcessRecursively(true)

src/main/kotlin/com/github/xepozz/php_dump/services/OpcacheSettingsTreeDumperService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class OpcacheSettingsTreeDumperService(var project: Project) : DumperServiceInte
5151
phpSnippet,
5252
project,
5353
StringBufferProcessAdapter(output),
54-
listOf("-dopcache.enable_cli=1"),
54+
("-d opcache.enable_cli=1".split(" ")),
5555
)
5656

5757
val jsonString = output.toString()
Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,62 @@
11
package com.github.xepozz.php_dump.services
22

3-
import com.github.xepozz.php_dump.StringBufferProcessAdapter
3+
import com.github.xepozz.php_dump.SeparateStringBufferProcessAdapter
44
import com.github.xepozz.php_dump.command.PathMapper
55
import com.github.xepozz.php_dump.command.PhpCommandExecutor
66
import com.github.xepozz.php_dump.configuration.PhpDumpSettingsService
77
import com.intellij.execution.configurations.GeneralCommandLine
88
import com.intellij.openapi.components.Service
99
import com.intellij.openapi.project.Project
10-
import com.jetbrains.php.config.PhpProjectConfigurationFacade
11-
import com.jetbrains.php.config.interpreters.PhpInterpretersManagerImpl
1210
import kotlinx.coroutines.Dispatchers
1311
import kotlinx.coroutines.withContext
1412

1513
@Service(Service.Level.PROJECT)
1614
class OpcodesDumperService(var project: Project) : DumperServiceInterface {
1715
val state = PhpDumpSettingsService.getInstance(project)
18-
val interpreter = PhpProjectConfigurationFacade.getInstance(project).interpreter
19-
?: PhpInterpretersManagerImpl.getInstance(project).interpreters.firstOrNull()
2016

21-
override suspend fun dump(file: String): Any? {
22-
val interpreterPath = interpreter?.pathToPhpExecutable ?: return null
17+
override suspend fun dump(file: String): Any {
2318
val debugLevel = state.debugLevel.value
2419
val preloadFile = state.preloadFile
2520

2621
val localFile = PathMapper.map(project, file)
2722
val command = GeneralCommandLine(buildList {
28-
add(interpreterPath)
2923
add("-l")
30-
add("-ddisplay_errors=0")
31-
add("-derror_reporting=0")
24+
addAll("-d display_errors=0".split(" "))
25+
addAll("-d error_reporting=0".split(" "))
3226

33-
add("-dopcache.enable_cli=1")
34-
add("-dopcache.save_comments=1")
35-
add("-dopcache.opt_debug_level=${debugLevel}")
27+
addAll("-d opcache.enable_cli=1".split(" "))
28+
addAll("-d opcache.save_comments=1".split(" "))
29+
addAll("-d opcache.opt_debug_level=${debugLevel}".split(" "))
3630
if (preloadFile != null) {
37-
add("-dopcache.preload=${preloadFile}")
31+
addAll("-d opcache.preload=${preloadFile}".split(" "))
3832
}
39-
40-
add("1>/dev/null")
4133
add(localFile)
4234
}).commandLineString
4335

4436
// language=injectablephp
4537
val phpSnippet = $$"""
46-
opcache_compile_file($argv[1]);
47-
passthru('$$command');
38+
opcache_compile_file($argv[1]); passthru(PHP_BINARY . ' $$command');
4839
""".trimIndent()
4940

41+
// println("command: $command")
42+
// println("phpSnippet: $phpSnippet")
5043
return withContext(Dispatchers.IO) {
51-
val output = StringBuilder()
44+
val opcodes = StringBuilder()
45+
val errors = StringBuilder()
5246

5347
PhpCommandExecutor.execute(
5448
localFile,
5549
phpSnippet,
5650
project,
57-
StringBufferProcessAdapter(output),
58-
listOf("-dopcache.enable_cli=1"),
51+
SeparateStringBufferProcessAdapter(stderr = opcodes, stdout = errors),
52+
("-d opcache.enable_cli=1".split(" ")),
5953
)
6054

61-
62-
output.toString()
55+
if (opcodes.isEmpty()) {
56+
errors.toString()
57+
} else {
58+
opcodes.toString()
59+
}
6360
}
6461
}
6562
}

0 commit comments

Comments
 (0)