Skip to content

Commit 446061d

Browse files
Resolved terminal exception for liberty:start action for lower intellij versions (#1393)
* Resolved terminal exception for liberty:start action * Corrected log error variable name * Removed unused import * Modified to adapt for specific intellij versions * Changed exception to specific list and log level to debug
1 parent 85af844 commit 446061d

File tree

1 file changed

+38
-14
lines changed

1 file changed

+38
-14
lines changed

src/main/java/io/openliberty/tools/intellij/util/LibertyProjectUtil.java

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import com.intellij.openapi.actionSystem.CommonDataKeys;
1313
import com.intellij.openapi.actionSystem.DataContext;
14+
import com.intellij.openapi.application.ApplicationInfo;
1415
import com.intellij.openapi.application.ApplicationManager;
1516
import com.intellij.openapi.diagnostic.Logger;
1617
import com.intellij.openapi.project.Project;
@@ -157,21 +158,22 @@ public static ShellTerminalWidget getTerminalWidget(Project project, LibertyModu
157158
TerminalToolWindowManager terminalToolWindowManager, ShellTerminalWidget widget) {
158159
// Set Terminal engine to CLASSIC
159160
if (widget == null && createWidget) {
160-
try {
161-
Class<?> optionsProviderClass = Class.forName("org.jetbrains.plugins.terminal.TerminalOptionsProvider");
162-
Object optionsProviderInstance = optionsProviderClass
163-
.getMethod("getInstance")
164-
.invoke(null);
165-
166-
Class<?> terminalEngineClass = Class.forName("org.jetbrains.plugins.terminal.TerminalEngine");
167-
Object classicEngine = Enum.valueOf((Class<Enum>) terminalEngineClass, "CLASSIC");
168-
Method setEngineMethod = optionsProviderClass
169-
.getMethod("setTerminalEngine", terminalEngineClass);
170-
setEngineMethod.invoke(optionsProviderInstance, classicEngine);
161+
if (shouldForceClassicTerminal()) {
162+
try {
163+
Class<?> optionsProviderClass = Class.forName("org.jetbrains.plugins.terminal.TerminalOptionsProvider");
164+
Object optionsProviderInstance = optionsProviderClass
165+
.getMethod("getInstance")
166+
.invoke(null);
171167

172-
} catch (ClassNotFoundException | NoSuchMethodException |
173-
IllegalAccessException | InvocationTargetException e) {
174-
LOGGER.error("Failed to set TerminalEngine to CLASSIC via reflection: " + e.getMessage());
168+
Class<?> terminalEngineClass = Class.forName("org.jetbrains.plugins.terminal.TerminalEngine");
169+
Object classicEngine = Enum.valueOf((Class<Enum>) terminalEngineClass, "CLASSIC");
170+
Method setEngineMethod = optionsProviderClass
171+
.getMethod("setTerminalEngine", terminalEngineClass);
172+
setEngineMethod.invoke(optionsProviderInstance, classicEngine);
173+
} catch (ClassNotFoundException | NoSuchMethodException |
174+
IllegalAccessException | InvocationTargetException e) {
175+
LOGGER.debug("Falling back to default terminal engine.", e);
176+
}
175177
}
176178

177179
// create a new terminal tab
@@ -184,6 +186,28 @@ public static ShellTerminalWidget getTerminalWidget(Project project, LibertyModu
184186
return widget;
185187
}
186188

189+
/**
190+
* Determines whether the IntelliJ terminal engine should be forced to "CLASSIC"
191+
* Return {@code true} for all IntelliJ versions starting with 2025.1.x,
192+
* except for the explicitly excluded versions: 2025.1, 2025.1.1, 2025.1.1.1
193+
* Return {@code false} for all other versions (e.g., 2024.x and 2025.2+)
194+
*
195+
* @return {@code true} if the IDE version requires forcing the "CLASSIC"
196+
* terminal engine; {@code false} otherwise.
197+
*/
198+
private static boolean shouldForceClassicTerminal() {
199+
ApplicationInfo appInfo = ApplicationInfo.getInstance();
200+
String fullVersion = appInfo.getFullVersion();
201+
202+
if (!fullVersion.startsWith("2025.1")) {
203+
return false;
204+
}
205+
206+
// Explicitly exclude safe builds
207+
Set<String> excluded = Set.of("2025.1", "2025.1.1", "2025.1.1.1");
208+
return !excluded.contains(fullVersion);
209+
}
210+
187211
public static void setFocusToWidget(Project project, ShellTerminalWidget widget) {
188212
TerminalToolWindowManager manager = TerminalToolWindowManager.getInstance(project);
189213
ToolWindow toolWindow = manager.getToolWindow();

0 commit comments

Comments
 (0)