[platform] API refactoring: convert enum ProductMode to a regular class (IJPL-182310)

External plugins may start using this class after IJPL-182310 is implemented. It's better not to allow external plugins to use a switch/when statement without an 'else' branch for this type because we may add new variants in the future, and such changes shouldn't break clients.

GitOrigin-RevId: 9a6cc2dd25cc7b63e6248d894de14d267e46b641
This commit is contained in:
Nikolay Chashnikov
2025-09-24 09:37:29 +00:00
committed by intellij-monorepo-bot
parent bbd11fb346
commit 5eaca49911
5 changed files with 33 additions and 18 deletions
@@ -31,7 +31,7 @@ import kotlin.io.path.extension
internal class ModuleBasedProductLoadingStrategy(internal val moduleRepository: RuntimeModuleRepository) : ProductLoadingStrategy() {
private val currentMode by lazy {
val currentModeId = System.getProperty(PLATFORM_PRODUCT_MODE_PROPERTY, ProductMode.MONOLITH.id)
val currentMode = ProductMode.entries.find { it.id == currentModeId }
val currentMode = ProductMode.findById(currentModeId)
if (currentMode == null) {
error("Unknown mode '$currentModeId' specified in '$PLATFORM_PRODUCT_MODE_PROPERTY' system property")
}
@@ -4,14 +4,11 @@
*:com.intellij.platform.runtime.product.PluginModuleGroup
- com.intellij.platform.runtime.product.RuntimeModuleGroup
- a:getMainModule():com.intellij.platform.runtime.repository.RuntimeModuleDescriptor
*e:com.intellij.platform.runtime.product.ProductMode
- java.lang.Enum
*f:com.intellij.platform.runtime.product.ProductMode
- sf:BACKEND:com.intellij.platform.runtime.product.ProductMode
- sf:FRONTEND:com.intellij.platform.runtime.product.ProductMode
- sf:MONOLITH:com.intellij.platform.runtime.product.ProductMode
- getId():java.lang.String
- s:valueOf(java.lang.String):com.intellij.platform.runtime.product.ProductMode
- s:values():com.intellij.platform.runtime.product.ProductMode[]
*:com.intellij.platform.runtime.product.ProductModules
- a:getBundledPluginModuleGroups():java.util.List
- a:getMainModuleGroup():com.intellij.platform.runtime.product.RuntimeModuleGroup
+17 -5
View File
@@ -1,36 +1,48 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.platform.runtime.product;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Describes a mode in which a product may be started.
* TODO: reuse inside {@link com.intellij.idea.AppMode}?
*/
public enum ProductMode {
public final class ProductMode {
/**
* Indicates that this process performs all necessary tasks to provide smart features itself. This is the default mode for all IDEs.
*/
MONOLITH("monolith"),
public static final ProductMode MONOLITH = new ProductMode("monolith");
/**
* Indicates that this process doesn't perform heavy tasks like code analysis, and takes necessary information from another process.
* Currently, this is used by JetBrains Client process connected to a remote development host or CodeWithMe session.
*/
FRONTEND("frontend"),
public static final ProductMode FRONTEND = new ProductMode("frontend");
/**
* Indicates that this process doesn't perform heavy tasks like code analysis and takes necessary information from another process.
* Currently, this is used by an IDE running as a remote development host.
*/
BACKEND("backend");
public static final ProductMode BACKEND = new ProductMode("backend");
private final String myId;
ProductMode(@NotNull @NonNls String id) {
private ProductMode(@NotNull @NonNls String id) {
myId = id;
}
public @NotNull @NonNls String getId() {
return myId;
}
@ApiStatus.Internal
public static @Nullable ProductMode findById(@NotNull @NonNls String id) {
switch (id) {
case "monolith": return MONOLITH;
case "frontend": return FRONTEND;
case "backend": return BACKEND;
default: return null;
}
}
}
@@ -6,6 +6,8 @@ import com.intellij.platform.runtime.repository.RuntimeModuleId;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import static com.intellij.platform.runtime.product.ProductMode.*;
/**
* This class is used to determine whether a module should be loaded based on the current {@link ProductMode}.
* Currently, this is determined by the presence of specific modules in dependencies. We can change this and require to specify modes
@@ -20,14 +22,18 @@ public final class ProductModeLoadingRules {
* Returns the module which presence in the dependencies indicates that a module isn't compatible with the given {@code mode}.
*/
public static @NotNull RuntimeModuleId getIncompatibleRootModule(@NotNull ProductMode mode) {
switch (mode) {
case FRONTEND: return RuntimeModuleId.module("intellij.platform.backend");
case MONOLITH: return RuntimeModuleId.module("intellij.platform.frontend.split");
if (mode.equals(FRONTEND)) {
return RuntimeModuleId.module("intellij.platform.backend");
}
else if (mode.equals(MONOLITH)) {
//currently we use the same modules in 'backend' and 'monolith' modes, in the future we may disable some UI-only modules in 'backend' mode
case BACKEND: return RuntimeModuleId.module("intellij.platform.frontend.split");
return RuntimeModuleId.module("intellij.platform.frontend.split");
}
else if (mode.equals(BACKEND)) {
return RuntimeModuleId.module("intellij.platform.frontend.split");
}
else {
throw new AssertionError("Unexpected value: " + mode);
}
throw new AssertionError(mode);
}
}
+1 -1
View File
@@ -58,7 +58,7 @@ fun main(args: Array<String>) {
private fun loadProductModules(moduleRepository: RuntimeModuleRepository, projectHome: Path): ProductModules {
val currentModeId = System.getProperty(PLATFORM_PRODUCT_MODE_PROPERTY, ProductMode.MONOLITH.id)
val currentMode = ProductMode.entries.find { it.id == currentModeId }
val currentMode = ProductMode.findById(currentModeId)
if (currentMode == null) {
reportError("Unknown mode '$currentModeId' specified in '$PLATFORM_PRODUCT_MODE_PROPERTY' system property")
}