Respect actuator on classpath. Launch config attr for auto-connect
This commit is contained in:
@@ -327,11 +327,5 @@
|
||||
class="org.springframework.ide.eclipse.boot.dash.remoteapps.RemoteAppsFromBootDash">
|
||||
</injection>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.core.runtime.preferences">
|
||||
<initializer
|
||||
class="org.springframework.ide.eclipse.boot.dash.prefs.PrefsInitializer">
|
||||
</initializer>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package org.springframework.ide.eclipse.boot.dash;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -21,13 +22,14 @@ import org.eclipse.debug.core.DebugPlugin;
|
||||
import org.eclipse.debug.core.ILaunch;
|
||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||
import org.eclipse.debug.core.model.IProcess;
|
||||
import org.eclipse.jdt.core.IJavaProject;
|
||||
import org.eclipse.jdt.core.JavaCore;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.jface.resource.ImageRegistry;
|
||||
import org.eclipse.jface.util.IPropertyChangeListener;
|
||||
import org.eclipse.jface.util.PropertyChangeEvent;
|
||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.ServiceReference;
|
||||
import org.springframework.ide.eclipse.boot.core.BootPropertyTester;
|
||||
import org.springframework.ide.eclipse.boot.dash.di.SimpleDIContext;
|
||||
import org.springframework.ide.eclipse.boot.dash.liveprocess.CommandInfo;
|
||||
import org.springframework.ide.eclipse.boot.dash.liveprocess.LiveProcessCommandsExecutor;
|
||||
@@ -104,7 +106,7 @@ public class BootDashActivator extends AbstractUIPlugin {
|
||||
super.start(context);
|
||||
plugin = this;
|
||||
new M2ELogbackCustomizer().schedule();
|
||||
connectToLaunchedBootApps();
|
||||
listenToLaunchedBootApps();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -114,6 +116,7 @@ public class BootDashActivator extends AbstractUIPlugin {
|
||||
* BundleContext)
|
||||
*/
|
||||
public void stop(BundleContext context) throws Exception {
|
||||
stopListeningToLaunchedBootApps();
|
||||
plugin = null;
|
||||
super.stop(context);
|
||||
if (model!=null) {
|
||||
@@ -195,60 +198,56 @@ public class BootDashActivator extends AbstractUIPlugin {
|
||||
|
||||
@Override
|
||||
public void stateChanged(ILaunchConfiguration owner) {
|
||||
if (BootLaunchConfigurationDelegate.getEnableJmx(owner)) {
|
||||
LocalBootDashModel localModel = (LocalBootDashModel) getModel().getSectionByTargetId(RunTargets.LOCAL.getId());
|
||||
LaunchConfRunStateTracker tracker = localModel.getLaunchConfRunStateTracker();
|
||||
RunState state = tracker.getState(owner);
|
||||
if (state == RunState.RUNNING || state == RunState.DEBUGGING) {
|
||||
for (ILaunch l : DebugPlugin.getDefault().getLaunchManager().getLaunches()) {
|
||||
if (l.getLaunchConfiguration() == owner) {
|
||||
for (IProcess p : l.getProcesses()) {
|
||||
String pid = p.getAttribute(IProcess.ATTR_PROCESS_ID);
|
||||
if (pid != null) {
|
||||
List<Server> servers = LiveProcessCommandsExecutor.getDefault()
|
||||
.getLanguageServers();
|
||||
if (BootLaunchConfigurationDelegate.getEnableJmx(owner) && BootLaunchConfigurationDelegate.getAutoConnect(owner)) {
|
||||
IJavaProject project = JavaCore.create(BootLaunchConfigurationDelegate.getProject(owner));
|
||||
try {
|
||||
if (project != null && Arrays.stream(project.getResolvedClasspath(true)).anyMatch(BootPropertyTester::isActuatorJar)) {
|
||||
LocalBootDashModel localModel = (LocalBootDashModel) getModel().getSectionByTargetId(RunTargets.LOCAL.getId());
|
||||
LaunchConfRunStateTracker tracker = localModel.getLaunchConfRunStateTracker();
|
||||
RunState state = tracker.getState(owner);
|
||||
if (state == RunState.RUNNING || state == RunState.DEBUGGING) {
|
||||
for (ILaunch l : DebugPlugin.getDefault().getLaunchManager().getLaunches()) {
|
||||
if (l.getLaunchConfiguration() == owner) {
|
||||
for (IProcess p : l.getProcesses()) {
|
||||
String pid = p.getAttribute(IProcess.ATTR_PROCESS_ID);
|
||||
if (pid != null) {
|
||||
List<Server> servers = LiveProcessCommandsExecutor.getDefault()
|
||||
.getLanguageServers();
|
||||
|
||||
CommandInfo cmd = new CommandInfo("sts/livedata/connect",
|
||||
Map.of("processKey", pid));
|
||||
CommandInfo cmd = new CommandInfo("sts/livedata/connect",
|
||||
Map.of("processKey", pid));
|
||||
|
||||
// The delay seems to be necessary for the moment. Although the process is created VM attach API may not work at early stages of the process run.
|
||||
// "VirtualMachine.list()" call may not list the newly created process which means the process is gone and triggers disconnect.
|
||||
// If lifecycle management is enabled the ready state seem to be a great indicator of a boot process fully started.
|
||||
// TODO: explore health endpoint perhaps instead of ready state under Admin endpoint.
|
||||
Flux.fromIterable(servers).flatMap(s -> Mono.delay(Duration.ofMillis(500)).then(s.executeCommand(cmd))).subscribe();
|
||||
// The delay seems to be necessary for the moment. Although the process is created VM attach API may not work at early stages of the process run.
|
||||
// "VirtualMachine.list()" call may not list the newly created process which means the process is gone and triggers disconnect.
|
||||
// If lifecycle management is enabled the ready state seem to be a great indicator of a boot process fully started.
|
||||
// TODO: explore health endpoint perhaps instead of ready state under Admin endpoint.
|
||||
Flux.fromIterable(servers).flatMap(s -> Mono.delay(Duration.ofMillis(500)).then(s.executeCommand(cmd))).subscribe();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
getLog().error("Failed to connect to Boot app", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private void connectToLaunchedBootApps() {
|
||||
updateRunStateListening();
|
||||
|
||||
getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() {
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent event) {
|
||||
if (PREF_LIVE_INFORMATION_AUTO_CONNECT.equals(event.getProperty())) {
|
||||
updateRunStateListening();
|
||||
}
|
||||
}
|
||||
});
|
||||
private void listenToLaunchedBootApps() {
|
||||
LocalBootDashModel localModel = (LocalBootDashModel) getModel().getSectionByTargetId(RunTargets.LOCAL.getId());
|
||||
LaunchConfRunStateTracker tracker = localModel.getLaunchConfRunStateTracker();
|
||||
tracker.addListener(RUN_STATE_LISTENER);
|
||||
|
||||
}
|
||||
|
||||
private void updateRunStateListening() {
|
||||
private void stopListeningToLaunchedBootApps() {
|
||||
LocalBootDashModel localModel = (LocalBootDashModel) getModel().getSectionByTargetId(RunTargets.LOCAL.getId());
|
||||
LaunchConfRunStateTracker tracker = localModel.getLaunchConfRunStateTracker();
|
||||
if (getPreferenceStore().getBoolean(PREF_LIVE_INFORMATION_AUTO_CONNECT)) {
|
||||
tracker.addListener(RUN_STATE_LISTENER);
|
||||
} else {
|
||||
tracker.removeListener(RUN_STATE_LISTENER);
|
||||
}
|
||||
tracker.removeListener(RUN_STATE_LISTENER);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ public class BootDashPrefsPage extends FieldEditorPreferencePage implements IWor
|
||||
@Override
|
||||
protected void createFieldEditors() {
|
||||
Composite parent = getFieldEditorParent();
|
||||
addField(new BooleanFieldEditor(BootDashActivator.PREF_LIVE_INFORMATION_AUTO_CONNECT, "Auto Connect to launched Boot app to show Live Information", parent));
|
||||
for (RunTargetType rtt : BootDashActivator.getDefault().getModel().getRunTargetTypes()) {
|
||||
if (rtt.supportsDeletion()) {
|
||||
addField(new BooleanFieldEditor(DeleteElementsAction.PREF_SKIP_CONFIRM_DELETE(rtt), "Skip Delete Element Confirmation ("+rtt.getName()+")", parent));
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2022 VMware, 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:
|
||||
* VMware, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.eclipse.boot.dash.prefs;
|
||||
|
||||
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.springframework.ide.eclipse.boot.dash.BootDashActivator;
|
||||
|
||||
public class PrefsInitializer extends AbstractPreferenceInitializer {
|
||||
|
||||
public PrefsInitializer() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeDefaultPreferences() {
|
||||
IPreferenceStore preferenceStore = BootDashActivator.getDefault().getPreferenceStore();
|
||||
preferenceStore.setDefault(BootDashActivator.PREF_LIVE_INFORMATION_AUTO_CONNECT, true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -134,6 +134,9 @@ public class BootLaunchConfigurationDelegate extends AbstractBootLaunchConfigura
|
||||
|
||||
public static final String SPRING_PROJECT_NAME_ATTRIBUTE = "spring.boot.project.name";
|
||||
|
||||
public static final String AUTO_CONNECT = "spring.boot.auto-connect";
|
||||
public static final boolean DEFAULT_AUTO_CONNECT = true;
|
||||
|
||||
// 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
|
||||
@@ -363,6 +366,7 @@ public class BootLaunchConfigurationDelegate extends AbstractBootLaunchConfigura
|
||||
setMainType(wc, mainType);
|
||||
}
|
||||
setEnableJMX(wc, DEFAULT_ENABLE_JMX);
|
||||
setAutoConnect(wc, false);
|
||||
setEnableLiveBeanSupport(wc, DEFAULT_ENABLE_LIVE_BEAN_SUPPORT());
|
||||
setEnableLifeCycle(wc, DEFAULT_ENABLE_LIFE_CYCLE);
|
||||
setTerminationTimeout(wc,""+DEFAULT_TERMINATION_TIMEOUT);
|
||||
@@ -442,6 +446,19 @@ public class BootLaunchConfigurationDelegate extends AbstractBootLaunchConfigura
|
||||
return "";
|
||||
}
|
||||
|
||||
public static boolean getAutoConnect(ILaunchConfiguration conf) {
|
||||
try {
|
||||
return conf.getAttribute(AUTO_CONNECT, DEFAULT_AUTO_CONNECT);
|
||||
} catch (CoreException e) {
|
||||
Log.log(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void setAutoConnect(ILaunchConfigurationWorkingCopy conf, boolean autoConnect) {
|
||||
conf.setAttribute(AUTO_CONNECT, autoConnect);
|
||||
}
|
||||
|
||||
public static void setEnableLiveBeanSupport(ILaunchConfigurationWorkingCopy conf, boolean value) {
|
||||
conf.setAttribute(ENABLE_LIVE_BEAN_SUPPORT, value);
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ public class BootLaunchUIModel {
|
||||
public final LaunchTabSelectionModel<Boolean> enableDebug;
|
||||
public final EnableJmxFeaturesModel enableJmx;
|
||||
public final LaunchTabSelectionModel<Boolean> hideFromDash;
|
||||
public final LaunchTabSelectionModel<Boolean> autoConnect;
|
||||
public final LaunchTabSelectionModel<Boolean> ansiConsoleOutput;
|
||||
public final LaunchTabSelectionModel<Boolean> fastStartup;
|
||||
public final LaunchTabSelectionModel<Boolean> useThinWrapper;
|
||||
@@ -82,6 +83,7 @@ public class BootLaunchUIModel {
|
||||
enableDebug = CheckboxLaunchTabModel.create(ENABLE_DEBUG_OUTPUT, DEFAULT_ENABLE_DEBUG_OUTPUT);
|
||||
enableJmx = new EnableJmxFeaturesModel();
|
||||
hideFromDash = CheckboxLaunchTabModel.create(HIDE_FROM_BOOT_DASH, DEFAULT_HIDE_FROM_BOOT_DASH);
|
||||
autoConnect = CheckboxLaunchTabModel.create(AUTO_CONNECT, DEFAULT_AUTO_CONNECT);
|
||||
ansiConsoleOutput = CheckboxLaunchTabModel.create(ANSI_CONSOLE_OUTPUT, BootLaunchConfigurationDelegate.supportsAnsiConsoleOutput());
|
||||
fastStartup = CheckboxLaunchTabModel.create(FAST_STARTUP, BootActivator.getDefault().getPreferenceStore()
|
||||
.getBoolean(BootPreferences.PREF_BOOT_FAST_STARTUP_DEFAULT));
|
||||
|
||||
@@ -54,6 +54,7 @@ public class BootMainTab extends LaunchConfigurationTabWithSections implements I
|
||||
jvmArgsSections.add(new EnableDebugSection(this, model.enableDebug));
|
||||
jvmArgsSections.add(new HideFromBootDashSection(this, model.hideFromDash));
|
||||
jvmArgsSections.add(new FastStartupLaunchTabSection(this, model.fastStartup));
|
||||
jvmArgsSections.add(new DelegatingLaunchConfigurationTabSection(this, model.autoConnect, new CheckboxSection(this, model.autoConnect, "Auto-connect to fetch Live Data")));
|
||||
/*
|
||||
* Show UI for enabling/disabling ANSI console output only if
|
||||
* IDE supports ANSI console output
|
||||
|
||||
Reference in New Issue
Block a user