diff --git a/platform/bootstrap/src/com/intellij/platform/bootstrap/ModuleBasedProductLoadingStrategy.kt b/platform/bootstrap/src/com/intellij/platform/bootstrap/ModuleBasedProductLoadingStrategy.kt index 115356991888..e6f0da9d82cc 100644 --- a/platform/bootstrap/src/com/intellij/platform/bootstrap/ModuleBasedProductLoadingStrategy.kt +++ b/platform/bootstrap/src/com/intellij/platform/bootstrap/ModuleBasedProductLoadingStrategy.kt @@ -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") } diff --git a/platform/runtime/product/api-dump-experimental.txt b/platform/runtime/product/api-dump-experimental.txt index 10ae79035bc0..7f6e93fe826a 100644 --- a/platform/runtime/product/api-dump-experimental.txt +++ b/platform/runtime/product/api-dump-experimental.txt @@ -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 diff --git a/platform/runtime/product/src/ProductMode.java b/platform/runtime/product/src/ProductMode.java index 208e13a6cbff..5e7cecb2046a 100644 --- a/platform/runtime/product/src/ProductMode.java +++ b/platform/runtime/product/src/ProductMode.java @@ -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; + } + } } diff --git a/platform/runtime/product/src/impl/ProductModeLoadingRules.java b/platform/runtime/product/src/impl/ProductModeLoadingRules.java index a64c7fc22fea..a56a72524e4d 100644 --- a/platform/runtime/product/src/impl/ProductModeLoadingRules.java +++ b/platform/runtime/product/src/impl/ProductModeLoadingRules.java @@ -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); } } diff --git a/tools/devLauncher/src/IntellijDevLauncher.kt b/tools/devLauncher/src/IntellijDevLauncher.kt index 90093dabee1e..c5685a69801e 100644 --- a/tools/devLauncher/src/IntellijDevLauncher.kt +++ b/tools/devLauncher/src/IntellijDevLauncher.kt @@ -58,7 +58,7 @@ fun main(args: Array) { 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") }