Skip to content

Commit fd5bff8

Browse files
committed
Fetch the project information from neptune
1 parent b6c340f commit fd5bff8

File tree

5 files changed

+95
-38
lines changed

5 files changed

+95
-38
lines changed

src/main/kotlin/io/runescript/plugin/ide/execution/build/RsBuildInstance.kt

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import com.intellij.openapi.components.service
1515
import com.intellij.openapi.fileEditor.FileDocumentManager
1616
import com.intellij.openapi.module.Module
1717
import com.intellij.openapi.project.Project
18-
import com.intellij.openapi.projectRoots.JavaSdk
1918
import com.intellij.openapi.projectRoots.Sdk
2019
import com.intellij.openapi.wm.ToolWindow
20+
import io.runescript.plugin.ide.execution.createNeptuneJvmCommand
2121
import java.io.File
2222
import java.util.concurrent.CompletableFuture
2323
import java.util.concurrent.atomic.AtomicInteger
@@ -78,16 +78,6 @@ class RsBuildInstance(
7878
}
7979

8080
private fun createCommandLine(): GeneralCommandLine {
81-
val homeDirectory = neptuneHome
82-
val parameters = mutableListOf<String>()
83-
parameters += "-classpath"
84-
parameters += "$homeDirectory${File.separator}lib${File.separator}*"
85-
parameters += "me.filby.neptune.clientscript.compiler.ClientScriptCompilerApplicationKt"
86-
val path = JavaSdk.getInstance().getVMExecutablePath(javaSdk)
87-
return GeneralCommandLine()
88-
.withExePath(path)
89-
.withParameters(parameters)
90-
.withWorkDirectory(workDirectory)
91-
.withEnvironment(System.getenv())
81+
return createNeptuneJvmCommand(javaSdk, neptuneHome, workDirectory)
9282
}
9383
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package io.runescript.plugin.ide.execution
2+
3+
import com.intellij.execution.configurations.GeneralCommandLine
4+
import com.intellij.openapi.projectRoots.JavaSdk
5+
import com.intellij.openapi.projectRoots.Sdk
6+
import java.io.File
7+
8+
fun createNeptuneJvmCommand(
9+
javaSdk: Sdk,
10+
neptuneHome: File,
11+
workDirectory: String
12+
) = createNeptuneJvmCommand(JavaSdk.getInstance().getVMExecutablePath(javaSdk), neptuneHome, workDirectory)
13+
14+
fun createNeptuneJvmCommand(
15+
vmExecutablePath: String,
16+
neptuneHome: File,
17+
workDirectory: String
18+
) = GeneralCommandLine()
19+
.withExePath(vmExecutablePath)
20+
.withParameters(createNeptuneJvmArgs(neptuneHome.toString()))
21+
.withWorkDirectory(workDirectory)
22+
.withEnvironment(System.getenv())
23+
24+
private fun createNeptuneJvmArgs(
25+
homeDirectory: String
26+
): MutableList<String> {
27+
val args = mutableListOf<String>()
28+
args += "-classpath"
29+
args += "$homeDirectory${File.separator}lib${File.separator}*"
30+
args += "me.filby.neptune.clientscript.compiler.ClientScriptCompilerApplicationKt"
31+
return args
32+
}

src/main/kotlin/io/runescript/plugin/ide/neptune/NeptuneExecutionSettings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ package io.runescript.plugin.ide.neptune
33
import com.intellij.openapi.externalSystem.model.settings.ExternalSystemExecutionSettings
44

55
class NeptuneExecutionSettings(
6-
val jreHome: String,
6+
val jvmExecutablePath: String,
77
val neptuneSdkHome: String,
88
) : ExternalSystemExecutionSettings()

src/main/kotlin/io/runescript/plugin/ide/neptune/NeptuneManager.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import com.intellij.openapi.fileChooser.FileChooserDescriptor
1212
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory
1313
import com.intellij.openapi.options.Configurable
1414
import com.intellij.openapi.project.Project
15+
import com.intellij.openapi.projectRoots.JavaSdk
16+
import com.intellij.openapi.projectRoots.ProjectJdkTable
1517
import com.intellij.openapi.startup.StartupActivity
1618
import com.intellij.openapi.util.Pair
1719
import com.intellij.util.Function
@@ -40,11 +42,14 @@ class NeptuneManager :
4042
return Function { pair ->
4143
val project = pair.first
4244
val systemSettings = project.service<NeptuneSettings>()
43-
val settings = NeptuneExecutionSettings(
45+
val javaSdk = ProjectJdkTable.getInstance()
46+
.findJdk(systemSettings.launcherJre)
47+
?: error("Java SDK not found")
48+
val jvmExecutablePath = JavaSdk.getInstance().getVMExecutablePath(javaSdk)
49+
NeptuneExecutionSettings(
50+
jvmExecutablePath,
4451
systemSettings.neptuneHome,
45-
systemSettings.neptuneHome
4652
)
47-
settings
4853
}
4954
}
5055

src/main/kotlin/io/runescript/plugin/ide/neptune/NeptuneProjectResolver.kt

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.runescript.plugin.ide.neptune
22

3+
import com.google.gson.Gson
4+
import com.google.gson.annotations.SerializedName
35
import com.intellij.openapi.externalSystem.importing.ProjectResolverPolicy
46
import com.intellij.openapi.externalSystem.model.DataNode
57
import com.intellij.openapi.externalSystem.model.ProjectKeys
@@ -10,6 +12,7 @@ import com.intellij.openapi.externalSystem.model.project.ProjectData
1012
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId
1113
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener
1214
import com.intellij.openapi.externalSystem.service.project.ExternalSystemProjectResolver
15+
import io.runescript.plugin.ide.execution.createNeptuneJvmCommand
1316
import io.runescript.plugin.ide.projectWizard.RsModuleType
1417
import org.slf4j.LoggerFactory
1518
import java.io.File
@@ -26,24 +29,14 @@ class NeptuneProjectResolver : ExternalSystemProjectResolver<NeptuneExecutionSet
2629
resolverPolicy: ProjectResolverPolicy?,
2730
listener: ExternalSystemTaskNotificationListener
2831
): DataNode<ProjectData>? {
29-
30-
if (settings == null) {
31-
check(false) { "NeptuneExecutionSettings is null" }
32-
return null
33-
}
34-
35-
log.info("JVM Arguments: ${settings.jvmArguments.toTypedArray().contentToString()}")
36-
log.info("Environment Variables: ${settings.env.toMap().entries.joinToString(", ") { "${it.key}=${it.value}" }}")
37-
log.info("Execution Name: ${settings.arguments}")
32+
check(settings != null) { "Neptune settings must not be null" }
3833

3934
val projectRoot = File(projectPath)
4035
check(projectRoot.isDirectory)
4136

42-
val neptuneData = extractNeptuneProjectMetadata(projectRoot)
37+
val neptuneData = extractNeptuneProjectMetadata(settings, projectRoot) ?: return null
4338
val projectName = neptuneData.name
4439

45-
log.info("Extracted project name: {}", projectName)
46-
4740
val projectData = ProjectData(
4841
Neptune.SYSTEM_ID,
4942
projectName,
@@ -53,11 +46,16 @@ class NeptuneProjectResolver : ExternalSystemProjectResolver<NeptuneExecutionSet
5346
val projectNode = DataNode(ProjectKeys.PROJECT, projectData, null)
5447
val moduleNode = projectNode.createModuleNode(projectName, projectRoot.absolutePath)
5548

49+
val outputPath = neptuneData.writers?.binary?.outputPath
50+
var excludedPaths = neptuneData.excludePaths
51+
if (outputPath != null) {
52+
excludedPaths = excludedPaths + outputPath
53+
}
5654
moduleNode.createContentRootNode(
5755
projectRoot.absolutePath,
58-
listOf("src"),
59-
listOf("symbols"),
60-
listOf("pack")
56+
neptuneData.sourcePaths,
57+
neptuneData.symbolPaths,
58+
excludedPaths,
6159
)
6260

6361
return projectNode
@@ -102,20 +100,52 @@ class NeptuneProjectResolver : ExternalSystemProjectResolver<NeptuneExecutionSet
102100
return false
103101
}
104102

105-
private fun extractNeptuneProjectMetadata(projectRoot: File): NeptuneProjectData {
103+
private fun extractNeptuneProjectMetadata(
104+
settings: NeptuneExecutionSettings,
105+
projectRoot: File
106+
): NeptuneProjectData? {
106107
val neptuneFile = projectRoot.resolve("neptune.toml")
107108
check(neptuneFile.exists())
108109

109-
val fileText = neptuneFile.readText()
110+
val commandLine = createNeptuneJvmCommand(
111+
settings.jvmExecutablePath,
112+
File(settings.neptuneSdkHome),
113+
projectRoot.absolutePath
114+
)
115+
commandLine.addParameter("--config-path")
116+
commandLine.addParameter(neptuneFile.absolutePath)
117+
118+
commandLine.addParameter("--print")
110119

111-
val regex = Regex("name\\s*=\\s*['\"](.*)['\"]")
112-
val match = regex.find(fileText)
113-
val projectName = match?.groupValues?.get(1) ?: projectRoot.name
120+
// Turn off logging.
121+
commandLine.addParameter("--log-level")
122+
commandLine.addParameter("off")
114123

115-
return NeptuneProjectData(projectName)
124+
val process = commandLine.createProcess()
125+
val output = process.inputStream.bufferedReader().readText()
126+
try {
127+
return Gson().fromJson(output, NeptuneProjectData::class.java)
128+
} catch (e: Throwable) {
129+
log.error("Failed to parse Neptune project data", e)
130+
return null
131+
}
116132
}
117133

118134
private data class NeptuneProjectData(
119-
val name: String
135+
@SerializedName("name")
136+
val name: String,
137+
@SerializedName("sourcePaths")
138+
val sourcePaths: List<String>,
139+
@SerializedName("symbolPaths")
140+
val symbolPaths: List<String>,
141+
@SerializedName("libraryPaths")
142+
val libraryPaths: List<String>,
143+
@SerializedName("excludePaths")
144+
val excludePaths: List<String>,
145+
@SerializedName("writers")
146+
val writers: ClientScriptWriterConfig?,
120147
)
148+
data class ClientScriptWriterConfig(val binary: BinaryFileWriterConfig? = null)
149+
data class BinaryFileWriterConfig(val outputPath: String)
150+
121151
}

0 commit comments

Comments
 (0)