Docker App in bootdash without actuator -> no automatic live hover

See: https://github.com/spring-projects/sts4/issues/716
This commit is contained in:
Kris De Volder
2022-07-26 15:50:16 -07:00
parent 35f4cc8292
commit 392d953bd9
32 changed files with 308 additions and 188 deletions

View File

@@ -10,6 +10,7 @@
*******************************************************************************/
package org.springframework.ide.eclipse.boot.dash.api;
import org.springframework.ide.eclipse.boot.dash.model.ClasspathPropertyTester;
import org.springframework.ide.eclipse.boot.dash.model.remote.RefreshStateTracker;
/**
@@ -28,4 +29,5 @@ public interface AppContext {
RefreshStateTracker getRefreshTracker();
boolean projectHasDevtoolsDependency();
<T extends App> T getParent(Class<T> expectedType);
boolean projectHasClasspathProperty(ClasspathPropertyTester tester);
}

View File

@@ -0,0 +1,7 @@
package org.springframework.ide.eclipse.boot.dash.api;
import org.springframework.ide.eclipse.boot.dash.model.ClasspathPropertyTester;
public interface ClasspathBearing extends App {
boolean hasClasspathProperty(ClasspathPropertyTester tester);
}

View File

@@ -1,10 +1,11 @@
package org.springframework.ide.eclipse.boot.dash.api;
public interface DevtoolsConnectable {
import org.springframework.ide.eclipse.boot.dash.model.ClasspathPropertyTester;
public interface DevtoolsConnectable extends ClasspathBearing {
String getDevtoolsSecret();
boolean hasDevtoolsDependency();
default TemporalBoolean isDevtoolsConnectable() {
return TemporalBoolean.now(hasDevtoolsDependency() && getDevtoolsSecret()!=null);
return TemporalBoolean.now(hasClasspathProperty(ClasspathPropertyTester.HAS_DEVTOOLS) && getDevtoolsSecret()!=null);
}
}

View File

@@ -36,6 +36,7 @@ import org.springframework.ide.eclipse.boot.dash.model.AbstractLaunchConfigurati
import org.springframework.ide.eclipse.boot.dash.model.BootDashElement;
import org.springframework.ide.eclipse.boot.dash.model.BootDashModel;
import org.springframework.ide.eclipse.boot.dash.model.ButtonModel;
import org.springframework.ide.eclipse.boot.dash.model.ClasspathPropertyTester;
import org.springframework.ide.eclipse.boot.dash.model.RefreshState;
import org.springframework.ide.eclipse.boot.dash.model.RunState;
import org.springframework.ide.eclipse.boot.dash.model.TagUtils;
@@ -407,7 +408,7 @@ public class BootDashLabels implements Disposable {
styledLabel = new StyledString("- " + "Fetching runstate from JMX", stylers.italicColoured(muted));
}
} else if (column==DEVTOOLS) {
if (element.hasDevtoolsDependency()) {
if (element.hasClasspathProperty(ClasspathPropertyTester.HAS_DEVTOOLS)) {
Color grey = colorGrey();
Color green = colorGreen();
Color color = element.isDevtoolsGreenColor() ? green : grey;

View File

@@ -118,6 +118,8 @@ public interface BootDashElement extends App, Taggable {
Object getParent();
BootDashColumn[] getColumns();
boolean projectHasDevtoolsDependency();
boolean projectHasClasspathProperty(ClasspathPropertyTester tester);
String getUrl();
@@ -136,5 +138,5 @@ public interface BootDashElement extends App, Taggable {
default String getProtocol() { return "http"; }
default boolean isDevtoolsGreenColor() { return projectHasDevtoolsDependency(); }
default RefreshState getRefreshState() { return RefreshState.READY; }
default boolean hasDevtoolsDependency() { return projectHasDevtoolsDependency(); }
default boolean hasClasspathProperty(ClasspathPropertyTester tester) { return projectHasClasspathProperty(tester); }
}

View File

@@ -0,0 +1,39 @@
package org.springframework.ide.eclipse.boot.dash.model;
import org.eclipse.jdt.core.IClasspathEntry;
import org.springframework.ide.eclipse.boot.core.BootPropertyTester;
import com.google.common.base.Predicate;
public interface ClasspathPropertyTester {
String getId();
boolean test(IClasspathEntry[] classpath);
static final ClasspathPropertyTester HAS_DEVTOOLS = anyElement("HAS_DEVTOOLS", BootPropertyTester::isDevtoolsJar);
static final ClasspathPropertyTester HAS_ACTUATORS = anyElement("HAS_ACTUATORS", BootPropertyTester::isActuatorJar);
static ClasspathPropertyTester anyElement(String id, Predicate<IClasspathEntry> entryTester) {
return new ClasspathPropertyTester() {
@Override
public boolean test(IClasspathEntry[] classpath) {
for (IClasspathEntry e : classpath) {
if (entryTester.test(e)) {
return true;
}
}
return false;
}
@Override
public String getId() {
return id;
}
@Override
public String toString() {
return "ClasspathPropertyTester("+id+")";
}
};
}
}

View File

@@ -11,9 +11,13 @@
package org.springframework.ide.eclipse.boot.dash.model;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import org.eclipse.core.resources.IProject;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.springframework.ide.eclipse.beans.ui.live.model.TypeLookup;
@@ -32,6 +36,7 @@ import org.springsource.ide.eclipse.commons.livexp.core.LiveExpression;
import org.springsource.ide.eclipse.commons.livexp.core.LiveSets;
import org.springsource.ide.eclipse.commons.livexp.core.ObservableSet;
import org.springsource.ide.eclipse.commons.livexp.core.ValueListener;
import org.springsource.ide.eclipse.commons.livexp.util.Log;
import com.google.common.collect.ImmutableSet;
@@ -166,33 +171,58 @@ public abstract class WrappingBootDashElement<T> extends AbstractDisposable impl
}
}
private LiveExpression<Boolean> hasDevtools = null;
private Map<ClasspathPropertyTester, LiveExpression<Boolean>> classpathProperties = new HashMap<>();
@Override
public boolean projectHasClasspathProperty(ClasspathPropertyTester tester) {
LiveExpression<Boolean> exp;
synchronized (classpathProperties) {
exp = classpathProperties.computeIfAbsent(tester, t -> {
LiveExpression<Boolean> propertyExp = new LiveExpression<Boolean>(false) {
@Override
protected Boolean compute() {
IProject p = getProject();
try {
if (p!=null && p.isAccessible()) {
IJavaProject jp = JavaCore.create(p);
if (jp.exists()) {
IClasspathEntry[] classpath = jp.getResolvedClasspath(true);
if (classpath!=null) {
return tester.test(classpath);
}
}
}
} catch (Exception e) {
Log.log(e);
}
//Reaching here means we couldn't apply the tester, e.g. because classpath not (yet) available.
return false;
}
};
propertyExp.refresh();
ClasspathListenerManager classpathListener = new ClasspathListenerManager(new ClasspathListener() {
public void classpathChanged(IJavaProject jp) {
if (jp.getProject().equals(getProject())) {
propertyExp.refresh();
}
}
});
this.dependsOn(propertyExp);
this.addDisposableChild(classpathListener);
this.addDisposableChild(propertyExp);
return propertyExp;
});
}
return exp.getValue();
}
@Override
public final boolean projectHasDevtoolsDependency() {
if (hasDevtools==null) {
hasDevtools = new LiveExpression<Boolean>(false) {
@Override
protected Boolean compute() {
boolean val = BootPropertyTester.hasDevtools(getProject());
return val;
}
};
hasDevtools.refresh();
ClasspathListenerManager classpathListener = new ClasspathListenerManager(new ClasspathListener() {
public void classpathChanged(IJavaProject jp) {
if (jp.getProject().equals(getProject())) {
hasDevtools.refresh();
}
}
});
this.dependsOn(hasDevtools);
this.addDisposableChild(classpathListener);
this.addDisposableChild(hasDevtools);
}
return hasDevtools.getValue();
return projectHasClasspathProperty(ClasspathPropertyTester.HAS_DEVTOOLS);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
protected void dependsOn(LiveExpression<?> liveProperty) {
liveProperty.addListener(new ValueListener() {

View File

@@ -15,7 +15,6 @@ import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicInteger;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.Assert;
@@ -34,6 +33,7 @@ import org.springframework.ide.eclipse.boot.dash.api.ActualInstanceCount;
import org.springframework.ide.eclipse.boot.dash.api.App;
import org.springframework.ide.eclipse.boot.dash.api.AppConsole;
import org.springframework.ide.eclipse.boot.dash.api.AppContext;
import org.springframework.ide.eclipse.boot.dash.api.ClasspathBearing;
import org.springframework.ide.eclipse.boot.dash.api.DebuggableApp;
import org.springframework.ide.eclipse.boot.dash.api.Deletable;
import org.springframework.ide.eclipse.boot.dash.api.DesiredInstanceCount;
@@ -54,6 +54,7 @@ import org.springframework.ide.eclipse.boot.dash.liveprocess.LiveDataCapableElem
import org.springframework.ide.eclipse.boot.dash.liveprocess.LiveDataConnectionManagementActions.ExecuteCommandAction;
import org.springframework.ide.eclipse.boot.dash.livexp.DisposingFactory;
import org.springframework.ide.eclipse.boot.dash.model.BootDashElement;
import org.springframework.ide.eclipse.boot.dash.model.ClasspathPropertyTester;
import org.springframework.ide.eclipse.boot.dash.model.BootDashModel.ElementStateListener;
import org.springframework.ide.eclipse.boot.dash.model.Failable;
import org.springframework.ide.eclipse.boot.dash.model.MissingLiveInfoMessages;
@@ -876,15 +877,6 @@ public class GenericRemoteAppElement extends WrappingBootDashElement<String> imp
return null;
}
@Override
public boolean hasDevtoolsDependency() {
App data = getAppData();
if (data instanceof DevtoolsConnectable) {
return ((DevtoolsConnectable) data).hasDevtoolsDependency();
}
return super.hasDevtoolsDependency();
}
@Override
public boolean isDevtoolsGreenColor() {
App data = getAppData();
@@ -907,6 +899,15 @@ public class GenericRemoteAppElement extends WrappingBootDashElement<String> imp
return selfMatch || childMatch(action);
}
@Override
public boolean hasClasspathProperty(ClasspathPropertyTester tester) {
App data = getAppData();
if (data instanceof ClasspathBearing) {
return ((ClasspathBearing) data).hasClasspathProperty(tester);
}
return projectHasClasspathProperty(tester);
}
private boolean childMatch(ExecuteCommandAction action) {
for (BootDashElement child : this.getChildren().getValues()) {
if (

View File

@@ -15,6 +15,7 @@ import org.springframework.ide.eclipse.boot.dash.model.BootDashElement;
import org.springframework.ide.eclipse.boot.dash.model.BootDashModel;
import org.springframework.ide.eclipse.boot.dash.model.BootDashModel.ElementStateListener;
import org.springframework.ide.eclipse.boot.dash.model.BootDashViewModel;
import org.springframework.ide.eclipse.boot.dash.model.ClasspathPropertyTester;
import org.springsource.ide.eclipse.commons.boot.ls.remoteapps.RemoteBootAppsDataHolder.Contributor;
import org.springsource.ide.eclipse.commons.boot.ls.remoteapps.RemoteBootAppsDataHolder.RemoteAppData;
import org.springsource.ide.eclipse.commons.livexp.core.AsyncLiveExpression.AsyncMode;
@@ -75,6 +76,7 @@ public class GenericRemoteAppElementDataContributor implements Contributor, Elem
data.setUrlScheme("http");
data.setPort(""+child.getLivePort());
data.setKeepChecking(false);
data.setManualConnect(!child.hasClasspathProperty(ClasspathPropertyTester.HAS_ACTUATORS));
data.setProcessId(child.getAppData().getName());
data.setProcessName(child.getConsoleDisplayName());
allApps.add(data);

View File

@@ -25,6 +25,7 @@ import org.eclipse.debug.core.Launch;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.jdt.launching.JavaRuntime;
import org.springframework.ide.eclipse.boot.dash.model.ClasspathPropertyTester;
import org.springframework.ide.eclipse.boot.util.RetryUtil;
import org.springsource.ide.eclipse.commons.livexp.util.Log;
@@ -53,7 +54,7 @@ public class RemoteJavaLaunchUtil {
public synchronized static void synchronizeWith(GenericRemoteAppElement app) {
if (isDebuggable(app)) {
ILaunch l = ensureDebuggerAttached(app);
if (app.hasDevtoolsDependency()) {
if (app.hasClasspathProperty(ClasspathPropertyTester.HAS_DEVTOOLS)) {
l.setAttribute(DISABLE_HCR_LAUNCH_ATTRIBUTE, "true");
}
if (l!=null) {