1
1
package io.runescript.plugin.ide.neptune
2
2
3
+ import com.google.gson.Gson
4
+ import com.google.gson.annotations.SerializedName
3
5
import com.intellij.openapi.externalSystem.importing.ProjectResolverPolicy
4
6
import com.intellij.openapi.externalSystem.model.DataNode
5
7
import com.intellij.openapi.externalSystem.model.ProjectKeys
@@ -10,6 +12,7 @@ import com.intellij.openapi.externalSystem.model.project.ProjectData
10
12
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId
11
13
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener
12
14
import com.intellij.openapi.externalSystem.service.project.ExternalSystemProjectResolver
15
+ import io.runescript.plugin.ide.execution.createNeptuneJvmCommand
13
16
import io.runescript.plugin.ide.projectWizard.RsModuleType
14
17
import org.slf4j.LoggerFactory
15
18
import java.io.File
@@ -26,24 +29,14 @@ class NeptuneProjectResolver : ExternalSystemProjectResolver<NeptuneExecutionSet
26
29
resolverPolicy : ProjectResolverPolicy ? ,
27
30
listener : ExternalSystemTaskNotificationListener
28
31
): 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" }
38
33
39
34
val projectRoot = File (projectPath)
40
35
check(projectRoot.isDirectory)
41
36
42
- val neptuneData = extractNeptuneProjectMetadata(projectRoot)
37
+ val neptuneData = extractNeptuneProjectMetadata(settings, projectRoot) ? : return null
43
38
val projectName = neptuneData.name
44
39
45
- log.info(" Extracted project name: {}" , projectName)
46
-
47
40
val projectData = ProjectData (
48
41
Neptune .SYSTEM_ID ,
49
42
projectName,
@@ -53,11 +46,16 @@ class NeptuneProjectResolver : ExternalSystemProjectResolver<NeptuneExecutionSet
53
46
val projectNode = DataNode (ProjectKeys .PROJECT , projectData, null )
54
47
val moduleNode = projectNode.createModuleNode(projectName, projectRoot.absolutePath)
55
48
49
+ val outputPath = neptuneData.writers?.binary?.outputPath
50
+ var excludedPaths = neptuneData.excludePaths
51
+ if (outputPath != null ) {
52
+ excludedPaths = excludedPaths + outputPath
53
+ }
56
54
moduleNode.createContentRootNode(
57
55
projectRoot.absolutePath,
58
- listOf ( " src " ) ,
59
- listOf ( " symbols " ) ,
60
- listOf ( " pack " )
56
+ neptuneData.sourcePaths ,
57
+ neptuneData.symbolPaths ,
58
+ excludedPaths,
61
59
)
62
60
63
61
return projectNode
@@ -102,20 +100,52 @@ class NeptuneProjectResolver : ExternalSystemProjectResolver<NeptuneExecutionSet
102
100
return false
103
101
}
104
102
105
- private fun extractNeptuneProjectMetadata (projectRoot : File ): NeptuneProjectData {
103
+ private fun extractNeptuneProjectMetadata (
104
+ settings : NeptuneExecutionSettings ,
105
+ projectRoot : File
106
+ ): NeptuneProjectData ? {
106
107
val neptuneFile = projectRoot.resolve(" neptune.toml" )
107
108
check(neptuneFile.exists())
108
109
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" )
110
119
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 " )
114
123
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
+ }
116
132
}
117
133
118
134
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 ? ,
120
147
)
148
+ data class ClientScriptWriterConfig (val binary : BinaryFileWriterConfig ? = null )
149
+ data class BinaryFileWriterConfig (val outputPath : String )
150
+
121
151
}
0 commit comments