@@ -7,6 +7,7 @@ import com.intellij.openapi.projectRoots.JavaSdk
7
7
import com.intellij.openapi.projectRoots.impl.JavaHomeFinder
8
8
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl
9
9
import com.intellij.openapi.roots.OrderRootType
10
+ import com.intellij.openapi.util.io.FileUtilRt
10
11
import com.intellij.platform.eel.provider.getEelDescriptor
11
12
import com.intellij.platform.workspace.jps.entities.*
12
13
import com.intellij.platform.workspace.jps.entities.LibraryTableId.ProjectLibraryTableId
@@ -30,6 +31,7 @@ import org.jetbrains.jps.model.module.JpsModuleSourceDependency
30
31
import org.jetbrains.jps.model.module.JpsSdkDependency
31
32
import org.jetbrains.jps.model.serialization.*
32
33
import org.jetbrains.jps.model.serialization.impl.JpsPathVariablesConfigurationImpl
34
+ import org.jetbrains.jps.util.JpsPathUtil
33
35
import org.jetbrains.kotlin.config.isHmpp
34
36
import org.jetbrains.kotlin.idea.facet.KotlinFacetType
35
37
import org.jetbrains.kotlin.idea.workspaceModel.KotlinSettingsEntity
@@ -72,18 +74,19 @@ object JpsWorkspaceImporter : WorkspaceImporter {
72
74
name = library.name,
73
75
tableId = ProjectLibraryTableId ,
74
76
roots = buildList {
75
- library.getPaths(JpsOrderRootType .COMPILED ).mapNotNullTo(this ) {
76
- if (! it.exists()) {
77
- onUnresolvedDependency(it.toString())
77
+ library.getRootUrls(JpsOrderRootType .COMPILED ).mapNotNullTo(this ) { url ->
78
+ val fileUrl = virtualFileUrlManager.getOrCreateFromUrl(url)
79
+ if (! Path .of(JpsPathUtil .urlToPath(url)).exists()) {
80
+ onUnresolvedDependency(url)
78
81
return @mapNotNull null
79
82
}
80
83
LibraryRoot (
81
- it.toIntellijUri(virtualFileUrlManager) ,
84
+ fileUrl ,
82
85
LibraryRootTypeId .COMPILED
83
86
)
84
87
}
85
- library.getPaths (JpsOrderRootType .SOURCES ).mapTo(this ) {
86
- LibraryRoot (it.toIntellijUri(virtualFileUrlManager ), LibraryRootTypeId .SOURCES )
88
+ library.getRootUrls (JpsOrderRootType .SOURCES ).mapTo(this ) { url ->
89
+ LibraryRoot (virtualFileUrlManager.getOrCreateFromUrl(url ), LibraryRootTypeId .SOURCES )
87
90
}
88
91
},
89
92
entitySource = entitySource
@@ -208,12 +211,20 @@ object JpsWorkspaceImporter : WorkspaceImporter {
208
211
val builder = SdkEntity (
209
212
name = library.name,
210
213
type = library.type.toSdkType(),
211
- roots = library.getRootUrls(JpsOrderRootType .COMPILED ).mapNotNull {
212
- val url = if (it.startsWith(" jrt://" )) it.replace(" !/" , " !/modules/" ) else it
213
- SdkRoot (
214
- virtualFileUrlManager.getOrCreateFromUrl(url),
215
- SdkRootTypeId (OrderRootType .CLASSES .customName),
216
- )
214
+ roots = buildList {
215
+ library.getRootUrls(JpsOrderRootType .COMPILED ).mapNotNullTo(this ) { url ->
216
+ val url = url.run { if (startsWith(" jrt://" )) replace(" !/" , " !/modules/" ) else this }
217
+ SdkRoot (
218
+ virtualFileUrlManager.getOrCreateFromUrl(url),
219
+ SdkRootTypeId (OrderRootType .CLASSES .customName),
220
+ )
221
+ }
222
+ library.getRootUrls(JpsOrderRootType .SOURCES ).mapNotNullTo(this ) { url ->
223
+ SdkRoot (
224
+ virtualFileUrlManager.getOrCreateFromUrl(url),
225
+ SdkRootTypeId (OrderRootType .SOURCES .customName),
226
+ )
227
+ }
217
228
},
218
229
additionalData = " " ,
219
230
entitySource = entitySource
@@ -257,16 +268,29 @@ private fun detectJavaSdks(
257
268
suggestedName != null && sdkName.contains(suggestedName, ignoreCase = true )
258
269
} ? : detectedSdks.maxBy { it.versionInfo?.version?.feature ? : 0 }
259
270
LOG .info(" Detected SDK [$sdkName ]: ${sdk.path} " )
271
+ val classRoots = JavaSdkImpl .findClasses(Path .of(sdk.path), false )
272
+ .map { (it.replace(" !/" , " !/modules/" )) }
260
273
SdkEntity (
261
274
name = sdkName,
262
275
type = JavaSdk .getInstance().name,
263
- roots = JavaSdkImpl .findClasses( Path .of(sdk.path), false ).map { (it.replace( " !/ " , " !/modules/ " )) }
264
- .map {
276
+ roots = buildList {
277
+ classRoots.mapTo( this ) {
265
278
SdkRoot (
266
279
virtualFileUrlManager.getOrCreateFromUrl(it),
267
280
SdkRootTypeId (OrderRootType .CLASSES .customName),
268
281
)
269
- },
282
+ }
283
+ val srcZip = Path .of(sdk.path, " lib" , " src.zip" )
284
+ if (srcZip.exists()) {
285
+ val prefix = " jar://${FileUtilRt .toSystemIndependentName(srcZip.toString())} !/"
286
+ classRoots.mapTo(this ) {
287
+ SdkRoot (
288
+ virtualFileUrlManager.getOrCreateFromUrl(" $prefix${it.substringAfterLast(" /" )} " ),
289
+ SdkRootTypeId (OrderRootType .SOURCES .customName),
290
+ )
291
+ }
292
+ }
293
+ },
270
294
additionalData = " " ,
271
295
entitySource = entitySource
272
296
)
0 commit comments