From 652a774d8b1984a102767b018e7a8ad39831c8d1 Mon Sep 17 00:00:00 2001 From: Nieraj Singh Date: Tue, 6 Sep 2022 03:49:29 -0700 Subject: [PATCH] GH-823: Enable ANSI support Eclipse 4.25 now includes ANSI support. Enable ANSI support in boot launch config based on whether Eclipse ANSI preference is set --- .../BootLaunchConfigurationDelegate.java | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/eclipse-extensions/org.springframework.ide.eclipse.boot.launch/src/org/springframework/ide/eclipse/boot/launch/BootLaunchConfigurationDelegate.java b/eclipse-extensions/org.springframework.ide.eclipse.boot.launch/src/org/springframework/ide/eclipse/boot/launch/BootLaunchConfigurationDelegate.java index c7c0ed9b0..cd8682cfa 100644 --- a/eclipse-extensions/org.springframework.ide.eclipse.boot.launch/src/org/springframework/ide/eclipse/boot/launch/BootLaunchConfigurationDelegate.java +++ b/eclipse-extensions/org.springframework.ide.eclipse.boot.launch/src/org/springframework/ide/eclipse/boot/launch/BootLaunchConfigurationDelegate.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015, 2020 Pivotal Software, Inc. + * Copyright (c) 2015, 2022 Pivotal Software, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -43,6 +43,8 @@ import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; import org.eclipse.jdt.launching.IRuntimeClasspathEntry; import org.eclipse.jdt.launching.JavaRuntime; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.ui.console.ConsolePlugin; import org.osgi.framework.Bundle; import org.springframework.ide.eclipse.boot.core.BootActivator; import org.springframework.ide.eclipse.boot.core.BootPreferences; @@ -132,6 +134,12 @@ public class BootLaunchConfigurationDelegate extends AbstractBootLaunchConfigura public static final String SPRING_PROJECT_NAME_ATTRIBUTE = "spring.boot.project.name"; + // Preference for Eclipse ANSI Console support. + // See org.eclipse.ui.internal.console.ansi.preferences.AnsiConsolePreferenceConstants + // Because this class is only available in Eclipse 4.25 and higher, we cannot add a + // direct reference to this type for backward compatibility + public static final String PREF_ANSI_CONSOLE_ENABLED = "ANSI_support_enabled"; + private ProfileHistory profileHistory = new ProfileHistory(); /** @@ -542,11 +550,29 @@ public class BootLaunchConfigurationDelegate extends AbstractBootLaunchConfigura return BootLaunchConfigurationDelegate.DEFAULT_TERMINATION_TIMEOUT; } - public static boolean supportsAnsiConsoleOutput() { + /** + * This is for STS based on Eclipse 4.24 and older. + * + * @return true if "Legacy" ANSI plugin is available. + */ + private static boolean isLegacyAnsiPluginInstalled() { Bundle bundle = Platform.getBundle("net.mihai-nita.ansicon.plugin"); return bundle != null && bundle.getState() != Bundle.UNINSTALLED; } + public static boolean supportsAnsiConsoleOutput() { + return isPlatformAnsiSupportEnabled() || isLegacyAnsiPluginInstalled(); + } + + /** + * + * @return true if ANSI plugin support in Eclipse platform is enabled. This applies for Eclipse 4.25 and higher + */ + private static boolean isPlatformAnsiSupportEnabled() { + IPreferenceStore prefStore = ConsolePlugin.getDefault().getPreferenceStore(); + return prefStore.getBoolean(PREF_ANSI_CONSOLE_ENABLED); + } + public static boolean getEnableAnsiConsoleOutput(ILaunchConfiguration conf) { boolean defaultValue = supportsAnsiConsoleOutput(); try {