From 7ec8bc14cd49718b6f18d6d7cd0eaadcad8d959b Mon Sep 17 00:00:00 2001 From: aboyko Date: Tue, 4 Jun 2024 18:05:13 -0400 Subject: [PATCH] Adopt Boot Launch to the latest Java launch changes --- .../boot/launch/BootDependenciesTab.java | 43 +++++++++++++++++++ .../BootLaunchConfigurationTabGroup.java | 12 ++++-- 2 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 eclipse-extensions/org.springframework.ide.eclipse.boot.launch/src/org/springframework/ide/eclipse/boot/launch/BootDependenciesTab.java diff --git a/eclipse-extensions/org.springframework.ide.eclipse.boot.launch/src/org/springframework/ide/eclipse/boot/launch/BootDependenciesTab.java b/eclipse-extensions/org.springframework.ide.eclipse.boot.launch/src/org/springframework/ide/eclipse/boot/launch/BootDependenciesTab.java new file mode 100644 index 000000000..077c52ab0 --- /dev/null +++ b/eclipse-extensions/org.springframework.ide.eclipse.boot.launch/src/org/springframework/ide/eclipse/boot/launch/BootDependenciesTab.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2024 Broadcom, 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 + * https://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Broadcom, Inc. - initial API and implementation + *******************************************************************************/ +package org.springframework.ide.eclipse.boot.launch; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.jdt.debug.ui.launchConfigurations.JavaDependenciesTab; +import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; +import org.springframework.ide.eclipse.boot.core.SpringBootCore; +import org.springsource.ide.eclipse.commons.livexp.util.Log; + +public class BootDependenciesTab extends JavaDependenciesTab { + + @Override + public void initializeFrom(ILaunchConfiguration conf) { + //See bug: https://github.com/spring-projects/spring-ide/issues/222 + // If user did not create boot launch config via boot dash and tries to immediately edit classpath + // an incorrect default classpath will be computed because of the missing classpath provider. + // So make sure the classpath provider is present. + IProject project = BootLaunchConfigurationDelegate.getProject(conf); + try { + if (project!=null && project.hasNature(SpringBootCore.M2E_NATURE) && !conf.hasAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER)) { + ILaunchConfigurationWorkingCopy wc = conf.getWorkingCopy(); + BootLaunchConfigurationDelegate.enableMavenClasspathProviders(wc); + conf = wc; + } + } catch (CoreException e) { + Log.log(e); + } + super.initializeFrom(conf); + } + +} diff --git a/eclipse-extensions/org.springframework.ide.eclipse.boot.launch/src/org/springframework/ide/eclipse/boot/launch/BootLaunchConfigurationTabGroup.java b/eclipse-extensions/org.springframework.ide.eclipse.boot.launch/src/org/springframework/ide/eclipse/boot/launch/BootLaunchConfigurationTabGroup.java index aa2784134..f7e789bd8 100644 --- a/eclipse-extensions/org.springframework.ide.eclipse.boot.launch/src/org/springframework/ide/eclipse/boot/launch/BootLaunchConfigurationTabGroup.java +++ b/eclipse-extensions/org.springframework.ide.eclipse.boot.launch/src/org/springframework/ide/eclipse/boot/launch/BootLaunchConfigurationTabGroup.java @@ -11,16 +11,19 @@ package org.springframework.ide.eclipse.boot.launch; +import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup; import org.eclipse.debug.ui.CommonTab; +import org.eclipse.debug.ui.DebugUITools; import org.eclipse.debug.ui.EnvironmentTab; import org.eclipse.debug.ui.ILaunchConfigurationDialog; import org.eclipse.debug.ui.ILaunchConfigurationTab; import org.eclipse.debug.ui.ILaunchConfigurationTabGroup; +import org.eclipse.debug.ui.PrototypeTab; import org.eclipse.debug.ui.sourcelookup.SourceLookupTab; import org.eclipse.jdt.debug.ui.launchConfigurations.JavaArgumentsTab; -import org.eclipse.jdt.debug.ui.launchConfigurations.JavaClasspathTab; import org.eclipse.jdt.debug.ui.launchConfigurations.JavaJRETab; +import org.eclipse.jdt.launching.JavaRuntime; public class BootLaunchConfigurationTabGroup extends AbstractLaunchConfigurationTabGroup { @@ -28,14 +31,17 @@ public class BootLaunchConfigurationTabGroup extends AbstractLaunchConfiguration * @see ILaunchConfigurationTabGroup#createTabs(ILaunchConfigurationDialog, String) */ public void createTabs(ILaunchConfigurationDialog dialog, String mode) { + ILaunchConfiguration configuration = DebugUITools.getLaunchConfiguration(dialog); + boolean isModularConfiguration = configuration != null && JavaRuntime.isModularConfiguration(configuration); ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] { new BootMainTab(), new JavaArgumentsTab(), new JavaJRETab(), - new BootClasspathTab(), + isModularConfiguration ? new BootDependenciesTab() : new BootClasspathTab(), new SourceLookupTab(), new EnvironmentTab(), - new CommonTab() + new CommonTab(), + new PrototypeTab() }; setTabs(tabs); }