mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-30 18:27:49 +08:00
workspace_model_usages.md: Add information about open LegacyBridgeJpsEntitySourceFactory API
This commit is contained in:
parent
6efc94f6ef
commit
5c22e6dce8
@ -43,6 +43,10 @@ An important part here is the entity source.
|
||||
To serialize an entity in project configuration files under the <path>.idea</path> folder, use
|
||||
[`JpsProjectFileEntitySource`](%gh-ic%/platform/workspace/jps/src/com/intellij/platform/workspace/jps/jpsEntitySources.kt).
|
||||
|
||||
<tabs>
|
||||
|
||||
<tab title="2024.3+">
|
||||
|
||||
```kotlin
|
||||
val workspaceModel = WorkspaceModel.getInstance(project)
|
||||
val moduleId = ModuleId(moduleName)
|
||||
@ -54,8 +58,32 @@ if (moduleId in workspaceModel.currentSnapshot) {
|
||||
val baseModuleDir = workspaceModel.getVirtualFileUrlManager()
|
||||
.getOrCreateFromUrl("file://foo/bar")
|
||||
val moduleEntitySource =
|
||||
LegacyBridgeJpsEntitySourceFactory.createEntitySourceForModule(
|
||||
project, baseModuleDir, null)
|
||||
LegacyBridgeJpsEntitySourceFactory.getInstance(project)
|
||||
.createEntitySourceForModule(baseModuleDir, null)
|
||||
WorkspaceModel.getInstance(project).update("Add new module") { builder ->
|
||||
val moduleEntity =
|
||||
ModuleEntity(moduleName, emptyList(), moduleEntitySource)
|
||||
builder.addEntity(moduleEntity)
|
||||
}
|
||||
```
|
||||
|
||||
</tab>
|
||||
|
||||
<tab title="2024.2">
|
||||
|
||||
```kotlin
|
||||
val workspaceModel = WorkspaceModel.getInstance(project)
|
||||
val moduleId = ModuleId(moduleName)
|
||||
if (moduleId in workspaceModel.currentSnapshot) {
|
||||
// Module with such `ModuleId` already exists
|
||||
...
|
||||
}
|
||||
|
||||
val baseModuleDir = workspaceModel.getVirtualFileUrlManager()
|
||||
.getOrCreateFromUrl("file://foo/bar")
|
||||
val moduleEntitySource =
|
||||
LegacyBridgeJpsEntitySourceFactory
|
||||
.createEntitySourceForModule(project, baseModuleDir, null)
|
||||
WorkspaceModel.getInstance(project).update("Add new module") { builder ->
|
||||
val moduleEntity =
|
||||
ModuleEntity(moduleName, emptyList(), moduleEntitySource)
|
||||
@ -64,12 +92,16 @@ WorkspaceModel.getInstance(project).update("Add new module") { builder ->
|
||||
```
|
||||
|
||||
<snippet id="LegacyBridgeJpsEntitySourceFactory-internal-note">
|
||||
> Note that `LegacyBridgeJpsEntitySourceFactory` is marked as internal in 2024.2.
|
||||
> It will be open API starting with 2024.3 and is allowed to use in plugins.
|
||||
> Note that [`LegacyBridgeJpsEntitySourceFactory`](%gh-ic%/platform/projectModel-impl/src/com/intellij/workspaceModel/ide/impl/LegacyBridgeJpsEntitySourceFactory.kt) is an internal API.
|
||||
> It is exceptionally allowed to use it in plugins.
|
||||
>
|
||||
{style="tip"}
|
||||
</snippet>
|
||||
|
||||
</tab>
|
||||
|
||||
</tabs>
|
||||
|
||||
### Add Library Dependency to Module
|
||||
|
||||
A project-level library is added as a dependency to the module.
|
||||
@ -121,6 +153,11 @@ Creating a new
|
||||
[`LibraryEntity`](%gh-ic%/platform/workspace/jps/src/com/intellij/platform/workspace/jps/entities/dependencies.kt),
|
||||
the legacy bridge will be created by the platform.
|
||||
|
||||
|
||||
<tabs>
|
||||
|
||||
<tab title="2024.3+">
|
||||
|
||||
```kotlin
|
||||
val currentSnapshot = WorkspaceModel.getInstance(project).currentSnapshot
|
||||
val libraryTableId = LibraryTableId.ProjectLibraryTableId
|
||||
@ -132,8 +169,35 @@ if (libraryId in currentSnapshot) {
|
||||
}
|
||||
|
||||
val libraryEntitySource =
|
||||
LegacyBridgeJpsEntitySourceFactory.createEntitySourceForProjectLibrary(
|
||||
project, null)
|
||||
LegacyBridgeJpsEntitySourceFactory.getInstance(project)
|
||||
.createEntitySourceForProjectLibrary(null)
|
||||
val libraryEntity = LibraryEntity(
|
||||
libraryName,
|
||||
libraryTableId, emptyList(),
|
||||
libraryEntitySource
|
||||
)
|
||||
WorkspaceModel.getInstance(project).update("Add new library") { builder ->
|
||||
builder.addEntity(libraryEntity)
|
||||
}
|
||||
```
|
||||
|
||||
</tab>
|
||||
|
||||
<tab title="2024.2">
|
||||
|
||||
```kotlin
|
||||
val currentSnapshot = WorkspaceModel.getInstance(project).currentSnapshot
|
||||
val libraryTableId = LibraryTableId.ProjectLibraryTableId
|
||||
|
||||
val libraryId = LibraryId(libraryName, libraryTableId)
|
||||
if (libraryId in currentSnapshot) {
|
||||
// Library with such `LibraryId` already exist
|
||||
...
|
||||
}
|
||||
|
||||
val libraryEntitySource =
|
||||
LegacyBridgeJpsEntitySourceFactory
|
||||
.createEntitySourceForProjectLibrary(project, null)
|
||||
val libraryEntity = LibraryEntity(
|
||||
libraryName,
|
||||
libraryTableId, emptyList(),
|
||||
@ -146,6 +210,10 @@ WorkspaceModel.getInstance(project).update("Add new library") { builder ->
|
||||
|
||||
<include from="workspace_model_usages.md" element-id="LegacyBridgeJpsEntitySourceFactory-internal-note"></include>
|
||||
|
||||
</tab>
|
||||
|
||||
</tabs>
|
||||
|
||||
### Searching for Library by Root Type and URL
|
||||
|
||||
```kotlin
|
||||
|
Loading…
x
Reference in New Issue
Block a user