From 633381f0145623d589b35f2dd110234ba090e284 Mon Sep 17 00:00:00 2001 From: BoykoAlex Date: Thu, 28 Sep 2017 19:11:33 -0400 Subject: [PATCH] [PT-#150812522] Beans tab for Boot Dash --- .../.classpath | 7 + .../.project | 28 +++ .../.settings/org.eclipse.jdt.core.prefs | 7 + .../META-INF/MANIFEST.MF | 22 +++ .../build.properties | 4 + .../icons}/bean_obj.gif | Bin .../icons}/beanref_obj.gif | Bin .../icons}/config_obj.gif | Bin .../pom.xml | 68 +++++++ .../beans/ui/live/LiveBeansUiPlugin.java | 64 +++++++ .../actions/AbstractOpenResourceAction.java | 60 ++++++ .../ui/live}/actions/OpenBeanClassAction.java | 27 +-- .../actions/OpenBeanDefinitionAction.java | 65 +++++++ .../model/AbstractLiveBeansModelElement.java | 18 +- .../beans/ui/live}/model/LiveBean.java | 49 +++-- .../live}/model/LiveBeanPropertySource.java | 17 +- .../ui/live}/model/LiveBeanRelation.java | 19 +- .../ui/live}/model/LiveBeansContext.java | 17 +- .../beans/ui/live/model/LiveBeansGroup.java | 62 ++++++ .../ui/live}/model/LiveBeansJsonParser.java | 45 ++--- .../beans/ui/live}/model/LiveBeansModel.java | 43 +++-- .../live}/model/LiveBeansModelCollection.java | 17 +- .../ui/live}/model/LiveBeansResource.java | 17 +- .../beans/ui/live/model}/TypeLookup.java | 19 +- .../beans/ui/live/model/TypeLookupImpl.java | 88 +++++++++ ...AbstractLiveBeansTreeContentProvider.java} | 50 ++--- .../ContextGroupedBeansContentProvider.java | 36 ++++ .../ui/live/tree}/InnerBeansViewerFilter.java | 21 ++- .../tree}/LiveBeansTreeLabelProvider.java | 33 ++-- .../ResourceGroupedBeansContentProvider.java | 36 ++++ .../eclipse/beans/ui/live/utils/JdtUtils.java | 107 +++++++++++ .../.classpath | 2 +- .../.settings/org.eclipse.jdt.core.prefs | 6 +- .../META-INF/MANIFEST.MF | 5 +- .../beans/ui/livegraph/LiveGraphUIImages.java | 8 +- .../actions/AbstractOpenResourceAction.java | 120 ------------ .../actions/ConnectToApplicationAction.java | 16 +- .../ui/livegraph/actions/LoadModelAction.java | 16 +- ....java => OpenXmlBeanDefinitionAction.java} | 64 +++---- .../actions/RefreshApplicationAction.java | 16 +- .../actions/ToggleViewModeAction.java | 17 +- .../ui/livegraph/model/LiveBeansGroup.java | 47 ----- .../model/LiveBeansModelGenerator.java | 21 ++- .../ui/livegraph/model/LiveBeansSession.java | 60 +++--- .../views/LiveBeansGraphContentProvider.java | 18 +- .../views/LiveBeansGraphLabelProvider.java | 16 +- .../livegraph/views/LiveBeansGraphView.java | 50 +++-- .../boot/dash/test/AllBootDashTests.java | 6 +- .../boot/dash/test/BootDashModelTest.java | 6 +- .../boot/dash/test/JLRMethodParserTest.java | 2 +- .../ActuatorClientTest.java | 14 +- .../dash/test/actuator/ActuatorDataTest.java | 98 ++++++++++ .../RequestMappingAsserts.java | 4 +- .../test/actuator/beans-sample-diff1.json | 25 +++ .../boot/dash/test/actuator/beans-sample.json | 25 +++ .../{requestmappings => actuator}/sample.json | 0 .../sample2.json | 0 .../META-INF/MANIFEST.MF | 5 +- .../plugin.xml | 20 ++ .../dash/cloudfoundry/CloudDashElement.java | 31 ++- ...stractLaunchConfigurationsDashElement.java | 34 +++- .../boot/dash/model/BootDashElement.java | 10 +- .../dash/model/WrappingBootDashElement.java | 21 +-- .../AbstractRequestMapping.java | 11 +- .../ActuatorClient.java | 22 ++- .../JLRMethodParser.java | 6 +- .../JMXActuatorClient.java | 37 +++- .../RequestMapping.java | 4 +- .../RestActuatorClient.java | 12 +- .../views/AbstractBootDashElementsAction.java | 8 +- .../views/RequestMappingLabelProvider.java | 4 +- .../dash/views/RequestMappingsSection.java | 4 +- .../RestartWithRemoteDevClientAction.java | 8 +- .../AbstractBdePropertiesSection.java | 10 +- .../properties/BeansPropertiesSection.java | 177 ++++++++++++++++++ .../RequestMappingPropertiesSection.java | 14 +- ...RequestMappingContentProposalProvider.java | 4 +- .../META-INF/MANIFEST.MF | 3 +- .../livebean/OpenLiveBeansGraphAction.java | 10 +- pom.xml | 1 + 80 files changed, 1573 insertions(+), 591 deletions(-) create mode 100644 plugins/org.springframework.ide.eclipse.beans.ui.live/.classpath create mode 100644 plugins/org.springframework.ide.eclipse.beans.ui.live/.project create mode 100644 plugins/org.springframework.ide.eclipse.beans.ui.live/.settings/org.eclipse.jdt.core.prefs create mode 100644 plugins/org.springframework.ide.eclipse.beans.ui.live/META-INF/MANIFEST.MF create mode 100644 plugins/org.springframework.ide.eclipse.beans.ui.live/build.properties rename plugins/{org.springframework.ide.eclipse.beans.ui.livegraph/icons/full/obj16 => org.springframework.ide.eclipse.beans.ui.live/icons}/bean_obj.gif (100%) rename plugins/{org.springframework.ide.eclipse.beans.ui.livegraph/icons/full/obj16 => org.springframework.ide.eclipse.beans.ui.live/icons}/beanref_obj.gif (100%) rename plugins/{org.springframework.ide.eclipse.beans.ui.livegraph/icons/full/obj16 => org.springframework.ide.eclipse.beans.ui.live/icons}/config_obj.gif (100%) create mode 100644 plugins/org.springframework.ide.eclipse.beans.ui.live/pom.xml create mode 100644 plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/LiveBeansUiPlugin.java create mode 100644 plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/actions/AbstractOpenResourceAction.java rename plugins/{org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph => org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live}/actions/OpenBeanClassAction.java (73%) create mode 100644 plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/actions/OpenBeanDefinitionAction.java rename plugins/{org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph => org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live}/model/AbstractLiveBeansModelElement.java (64%) rename plugins/{org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph => org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live}/model/LiveBean.java (66%) rename plugins/{org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph => org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live}/model/LiveBeanPropertySource.java (79%) rename plugins/{org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph => org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live}/model/LiveBeanRelation.java (69%) rename plugins/{org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph => org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live}/model/LiveBeansContext.java (72%) create mode 100644 plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansGroup.java rename plugins/{org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph => org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live}/model/LiveBeansJsonParser.java (78%) rename plugins/{org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph => org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live}/model/LiveBeansModel.java (57%) rename plugins/{org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph => org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live}/model/LiveBeansModelCollection.java (65%) rename plugins/{org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph => org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live}/model/LiveBeansResource.java (72%) rename plugins/{org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/requestmappings => org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model}/TypeLookup.java (66%) create mode 100644 plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/TypeLookupImpl.java rename plugins/{org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/views/LiveBeansTreeContentProvider.java => org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree/AbstractLiveBeansTreeContentProvider.java} (51%) create mode 100644 plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree/ContextGroupedBeansContentProvider.java rename plugins/{org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/views => org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree}/InnerBeansViewerFilter.java (54%) rename plugins/{org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/views => org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree}/LiveBeansTreeLabelProvider.java (57%) create mode 100644 plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree/ResourceGroupedBeansContentProvider.java create mode 100644 plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/utils/JdtUtils.java delete mode 100644 plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/AbstractOpenResourceAction.java rename plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/{OpenBeanDefinitionAction.java => OpenXmlBeanDefinitionAction.java} (69%) delete mode 100644 plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeansGroup.java rename plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/{requestmappings => actuator}/ActuatorClientTest.java (90%) create mode 100644 plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/actuator/ActuatorDataTest.java rename plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/{requestmappings => actuator}/RequestMappingAsserts.java (86%) create mode 100644 plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/actuator/beans-sample-diff1.json create mode 100644 plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/actuator/beans-sample.json rename plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/{requestmappings => actuator}/sample.json (100%) rename plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/{requestmappings => actuator}/sample2.json (100%) rename plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/{requestmappings => actuator}/AbstractRequestMapping.java (87%) rename plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/{requestmappings => actuator}/ActuatorClient.java (88%) rename plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/{requestmappings => actuator}/JLRMethodParser.java (95%) rename plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/{requestmappings => actuator}/JMXActuatorClient.java (73%) rename plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/{requestmappings => actuator}/RequestMapping.java (88%) rename plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/{requestmappings => actuator}/RestActuatorClient.java (82%) create mode 100644 plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/views/properties/BeansPropertiesSection.java diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.live/.classpath b/plugins/org.springframework.ide.eclipse.beans.ui.live/.classpath new file mode 100644 index 0000000000..eca7bdba8f --- /dev/null +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.live/.project b/plugins/org.springframework.ide.eclipse.beans.ui.live/.project new file mode 100644 index 0000000000..cbbc2d3cbb --- /dev/null +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/.project @@ -0,0 +1,28 @@ + + + org.springframework.ide.eclipse.beans.ui.live + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.live/.settings/org.eclipse.jdt.core.prefs b/plugins/org.springframework.ide.eclipse.beans.ui.live/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..0c68a61dca --- /dev/null +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.live/META-INF/MANIFEST.MF b/plugins/org.springframework.ide.eclipse.beans.ui.live/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..dfe57b2fbf --- /dev/null +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/META-INF/MANIFEST.MF @@ -0,0 +1,22 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Live Beans Tree +Bundle-SymbolicName: org.springframework.ide.eclipse.beans.ui.live;singleton:=true +Bundle-Version: 3.9.1.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: org.springframework.ide.eclipse.beans.ui.live, + org.springframework.ide.eclipse.beans.ui.live.actions, + org.springframework.ide.eclipse.beans.ui.live.model, + org.springframework.ide.eclipse.beans.ui.live.tree +Require-Bundle: org.eclipse.core.runtime, + org.eclipse.ui.views, + org.json, + org.eclipse.core.resources, + org.apache.commons.lang, + org.eclipse.jface, + org.eclipse.ui.workbench, + org.eclipse.jdt.core, + org.springsource.ide.eclipse.commons.ui +Bundle-ActivationPolicy: lazy +Bundle-Vendor: Spring IDE Developers +Bundle-Activator: org.springframework.ide.eclipse.beans.ui.live.LiveBeansUiPlugin diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.live/build.properties b/plugins/org.springframework.ide.eclipse.beans.ui.live/build.properties new file mode 100644 index 0000000000..34d2e4d2da --- /dev/null +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/icons/full/obj16/bean_obj.gif b/plugins/org.springframework.ide.eclipse.beans.ui.live/icons/bean_obj.gif similarity index 100% rename from plugins/org.springframework.ide.eclipse.beans.ui.livegraph/icons/full/obj16/bean_obj.gif rename to plugins/org.springframework.ide.eclipse.beans.ui.live/icons/bean_obj.gif diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/icons/full/obj16/beanref_obj.gif b/plugins/org.springframework.ide.eclipse.beans.ui.live/icons/beanref_obj.gif similarity index 100% rename from plugins/org.springframework.ide.eclipse.beans.ui.livegraph/icons/full/obj16/beanref_obj.gif rename to plugins/org.springframework.ide.eclipse.beans.ui.live/icons/beanref_obj.gif diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/icons/full/obj16/config_obj.gif b/plugins/org.springframework.ide.eclipse.beans.ui.live/icons/config_obj.gif similarity index 100% rename from plugins/org.springframework.ide.eclipse.beans.ui.livegraph/icons/full/obj16/config_obj.gif rename to plugins/org.springframework.ide.eclipse.beans.ui.live/icons/config_obj.gif diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.live/pom.xml b/plugins/org.springframework.ide.eclipse.beans.ui.live/pom.xml new file mode 100644 index 0000000000..fe68844c01 --- /dev/null +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/pom.xml @@ -0,0 +1,68 @@ + + + 4.0.0 + + org.springframework.ide.eclipse + org.springframework.ide.eclipse.parent + 3.9.1-SNAPSHOT + ../../pom.xml + + org.springframework.ide.eclipse + org.springframework.ide.eclipse.beans.ui.live + + eclipse-plugin + + + + + + org.eclipse.tycho + target-platform-configuration + ${tycho-version} + + p2 + ignore + + + + + org.eclipse.tycho + tycho-compiler-plugin + ${tycho-version} + + + + org.eclipse.tycho + tycho-source-plugin + ${tycho-version} + + + plugin-source + generate-sources + + plugin-source + + + + + + + org.eclipse.tycho + tycho-p2-plugin + ${tycho-version} + + + second-generate-p2-metadata + + p2-metadata + + verify + + + + + + + diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/LiveBeansUiPlugin.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/LiveBeansUiPlugin.java new file mode 100644 index 0000000000..5254fcfe20 --- /dev/null +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/LiveBeansUiPlugin.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Pivotal, Inc. - initial API and implementation + *******************************************************************************/ +package org.springframework.ide.eclipse.beans.ui.live; + +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * Live Beans plugin + * + * @author Alex Boyko + * + */ +public class LiveBeansUiPlugin extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.springframework.ide.eclipse.beans.ui.live"; //$NON-NLS-1$ + + private static final String ICON_PATH_PREFIX = "icons/"; + private static final String NAME_PREFIX = PLUGIN_ID + '.'; + private static final int NAME_PREFIX_LENGTH = NAME_PREFIX.length(); + + public static final String IMG_OBJS_BEAN = NAME_PREFIX + "bean_obj.gif"; + public static final String IMG_OBJS_BEAN_REF = NAME_PREFIX + "beanref_obj.gif"; + public static final String IMG_OBJS_CONFIG = NAME_PREFIX + "config_obj.gif"; + + private static LiveBeansUiPlugin plugin; + + + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + @Override + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + public static LiveBeansUiPlugin getDefault() { + return plugin; + } + + @Override + protected void initializeImageRegistry(ImageRegistry reg) { + super.initializeImageRegistry(reg); + reg.put(IMG_OBJS_BEAN, imageDescriptorFromPlugin(PLUGIN_ID, ICON_PATH_PREFIX + IMG_OBJS_BEAN.substring(NAME_PREFIX_LENGTH))); + reg.put(IMG_OBJS_BEAN_REF, imageDescriptorFromPlugin(PLUGIN_ID, ICON_PATH_PREFIX + IMG_OBJS_BEAN_REF.substring(NAME_PREFIX_LENGTH))); + reg.put(IMG_OBJS_CONFIG, imageDescriptorFromPlugin(PLUGIN_ID, ICON_PATH_PREFIX + IMG_OBJS_CONFIG.substring(NAME_PREFIX_LENGTH))); + } + + +} diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/actions/AbstractOpenResourceAction.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/actions/AbstractOpenResourceAction.java new file mode 100644 index 0000000000..aa266b7e1c --- /dev/null +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/actions/AbstractOpenResourceAction.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2013, 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Pivotal, Inc. - initial API and implementation + *******************************************************************************/ +package org.springframework.ide.eclipse.beans.ui.live.actions; + +import org.eclipse.jdt.core.IType; +import org.eclipse.ui.actions.BaseSelectionListenerAction; +import org.springframework.ide.eclipse.beans.ui.live.model.TypeLookup; +import org.springsource.ide.eclipse.commons.ui.SpringUIUtils; + +/** + * @author Leo Dos Santos + * @author Alex Boyko + */ +public abstract class AbstractOpenResourceAction extends BaseSelectionListenerAction { + + protected AbstractOpenResourceAction(String text) { + super(text); + } + + protected String extractClassName(String resourcePath) { + int index = resourcePath.lastIndexOf("/WEB-INF/classes/"); + int length = "/WEB-INF/classes/".length(); + if (index >= 0) { + resourcePath = resourcePath.substring(index + length); + } + resourcePath = resourcePath.substring(0, resourcePath.lastIndexOf(".class")); + resourcePath = resourcePath.replaceAll("\\\\|\\/", "."); //Tolerate both '/' and '\'. + return resourcePath; + } + + protected String extractResourcePath(String resourceStr) { + // Extract the resource path out of the descriptive text + int indexStart = resourceStr.indexOf("["); + int indexEnd = resourceStr.indexOf("]"); + if (indexStart > -1 && indexEnd > -1 && indexStart < indexEnd) { + resourceStr = resourceStr.substring(indexStart + 1, indexEnd); + } + return resourceStr; + } + + protected boolean hasTypeInProject(TypeLookup workspaceContext, String className) { + return workspaceContext.findType(className) != null; + } + + protected void openInEditor(TypeLookup workspaceContext, String className) { + IType type = workspaceContext.findType(className); + if (type != null) { + SpringUIUtils.openInEditor(type); + } + } + +} diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/OpenBeanClassAction.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/actions/OpenBeanClassAction.java similarity index 73% rename from plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/OpenBeanClassAction.java rename to plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/actions/OpenBeanClassAction.java index 0fa7cb083c..a0eed500c4 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/OpenBeanClassAction.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/actions/OpenBeanClassAction.java @@ -1,30 +1,31 @@ /******************************************************************************* - * Copyright (c) 2012 - 2013 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 - * http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2012, 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: - * VMware, Inc. - initial API and implementation + * Contributors: + * Pivotal, Inc. - initial API and implementation *******************************************************************************/ -package org.springframework.ide.eclipse.beans.ui.livegraph.actions; +package org.springframework.ide.eclipse.beans.ui.live.actions; import java.util.List; import org.eclipse.jface.viewers.IStructuredSelection; -import org.springframework.ide.eclipse.beans.ui.livegraph.model.LiveBean; -import org.springframework.ide.eclipse.beans.ui.livegraph.model.LiveBeansSession; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBean; +import org.springframework.ide.eclipse.beans.ui.live.model.TypeLookup; /** * @author Leo Dos Santos + * @author Alex Boyko */ public class OpenBeanClassAction extends AbstractOpenResourceAction { public OpenBeanClassAction() { super("Open Bean Class"); } - + @Override public void run() { IStructuredSelection selection = getStructuredSelection(); @@ -32,7 +33,7 @@ public void run() { for (Object obj : elements) { if (obj instanceof LiveBean) { LiveBean bean = (LiveBean) obj; - LiveBeansSession appName = bean.getSession(); + TypeLookup appName = bean.getTypeLookup(); String beanClass = bean.getBeanType(); if (appName != null) { if (beanClass != null && beanClass.trim().length() > 0) { @@ -72,7 +73,7 @@ protected boolean updateSelection(IStructuredSelection selection) { return true; } else { - return hasTypeInProject(bean.getSession(), bean.getId()); + return hasTypeInProject(bean.getTypeLookup(), bean.getId()); } } } diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/actions/OpenBeanDefinitionAction.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/actions/OpenBeanDefinitionAction.java new file mode 100644 index 0000000000..8d847ac3e4 --- /dev/null +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/actions/OpenBeanDefinitionAction.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2012, 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Pivotal, Inc. - initial API and implementation + *******************************************************************************/ +package org.springframework.ide.eclipse.beans.ui.live.actions; + +import java.util.List; + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBean; +import org.springframework.ide.eclipse.beans.ui.live.model.TypeLookup; + +/** + * @author Leo Dos Santos + * @author Alex Boyko + */ +public class OpenBeanDefinitionAction extends AbstractOpenResourceAction { + + public OpenBeanDefinitionAction() { + super("Open Bean Definition File"); + } + + @Override + public void run() { + IStructuredSelection selection = getStructuredSelection(); + List elements = selection.toList(); + for (Object obj : elements) { + if (obj instanceof LiveBean) { + LiveBean bean = (LiveBean) obj; + TypeLookup session = bean.getTypeLookup(); + String resource = bean.getResource(); + if (resource != null && resource.trim().length() > 0 && !resource.equalsIgnoreCase("null")) { + String resourcePath = extractResourcePath(resource); + if (resourcePath.endsWith(".class")) { + openInEditor(session, extractClassName(resourcePath)); + } + } + } + } + } + + @Override + protected boolean updateSelection(IStructuredSelection selection) { + if (!selection.isEmpty()) { + List elements = selection.toList(); + for (Object obj : elements) { + if (obj instanceof LiveBean) { + LiveBean bean = (LiveBean) obj; + String resource = bean.getResource(); + if (resource != null && resource.trim().length() > 0 && !resource.equalsIgnoreCase("null")) { + return true; + } + } + } + } + return false; + } + +} diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/AbstractLiveBeansModelElement.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/AbstractLiveBeansModelElement.java similarity index 64% rename from plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/AbstractLiveBeansModelElement.java rename to plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/AbstractLiveBeansModelElement.java index 486d3d282a..6d816381d6 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/AbstractLiveBeansModelElement.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/AbstractLiveBeansModelElement.java @@ -1,14 +1,14 @@ /******************************************************************************* - * Copyright (c) 2012 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 - * http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2012, 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: - * VMware, Inc. - initial API and implementation + * Contributors: + * Pivotal, Inc. - initial API and implementation *******************************************************************************/ -package org.springframework.ide.eclipse.beans.ui.livegraph.model; +package org.springframework.ide.eclipse.beans.ui.live.model; import java.util.HashMap; import java.util.Map; @@ -18,6 +18,7 @@ /** * @author Leo Dos Santos + * @author Alex Boyko */ public abstract class AbstractLiveBeansModelElement implements IAdaptable { @@ -31,6 +32,7 @@ public void addAttribute(String key, String value) { attributes.put(key, value); } + @SuppressWarnings({ "unchecked", "rawtypes" }) public Object getAdapter(Class adapter) { if (adapter == IPropertySource.class) { return new LiveBeanPropertySource(this); diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBean.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBean.java similarity index 66% rename from plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBean.java rename to plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBean.java index 7afa56e481..c5b3d52b10 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBean.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBean.java @@ -1,22 +1,23 @@ /******************************************************************************* - * Copyright (c) 2012 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 - * http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2012, 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: - * VMware, Inc. - initial API and implementation + * Contributors: + * Pivotal, Inc. - initial API and implementation *******************************************************************************/ -package org.springframework.ide.eclipse.beans.ui.livegraph.model; +package org.springframework.ide.eclipse.beans.ui.live.model; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Set; import org.apache.commons.lang.StringUtils; /** * @author Leo Dos Santos + * @author Alex Boyko */ public class LiveBean extends AbstractLiveBeansModelElement { @@ -32,7 +33,7 @@ public class LiveBean extends AbstractLiveBeansModelElement { public static final String ATTR_APPLICATION = "application name"; - private final LiveBeansSession session; + private final TypeLookup typeLookup; private final String beanId; @@ -44,17 +45,17 @@ public class LiveBean extends AbstractLiveBeansModelElement { private final boolean innerBean; - public LiveBean(LiveBeansSession session, String id) { + public LiveBean(TypeLookup session, String id) { this(session, id, false); } - public LiveBean(LiveBeansSession session, String id, boolean innerBean) { + public LiveBean(TypeLookup typeLookup, String id, boolean innerBean) { super(); - this.session = session; + this.typeLookup = typeLookup; this.beanId = id; this.innerBean = innerBean; - dependencies = new HashSet(); - injectedInto = new HashSet(); + dependencies = new LinkedHashSet(); + injectedInto = new LinkedHashSet(); attributes.put(ATTR_BEAN, id); } @@ -116,8 +117,22 @@ public boolean isInnerBean() { return innerBean; } - public LiveBeansSession getSession() { - return session; + public TypeLookup getTypeLookup() { + return typeLookup; } + @Override + public boolean equals(Object obj) { + if (obj instanceof LiveBean) { + LiveBean other = (LiveBean) obj; + return this.attributes.equals(other.attributes); + } + return super.equals(obj); + } + + @Override + public int hashCode() { + return beanId == null ? super.hashCode() : beanId.hashCode(); + } + } diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeanPropertySource.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeanPropertySource.java similarity index 79% rename from plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeanPropertySource.java rename to plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeanPropertySource.java index 1f6cf48db4..e18e687c0e 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeanPropertySource.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeanPropertySource.java @@ -1,14 +1,14 @@ /******************************************************************************* - * Copyright (c) 2012 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 - * http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2012, 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: - * VMware, Inc. - initial API and implementation + * Contributors: + * Pivotal, Inc. - initial API and implementation *******************************************************************************/ -package org.springframework.ide.eclipse.beans.ui.livegraph.model; +package org.springframework.ide.eclipse.beans.ui.live.model; import java.util.ArrayList; import java.util.List; @@ -21,6 +21,7 @@ /** * @author Leo Dos Santos + * @author Alex Boyko */ public class LiveBeanPropertySource implements IPropertySource { diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeanRelation.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeanRelation.java similarity index 69% rename from plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeanRelation.java rename to plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeanRelation.java index 8e75551605..f56468a824 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeanRelation.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeanRelation.java @@ -1,25 +1,24 @@ /******************************************************************************* - * Copyright (c) 2012 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 - * http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2012, 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: - * VMware, Inc. - initial API and implementation + * Contributors: + * Pivotal, Inc. - initial API and implementation *******************************************************************************/ -package org.springframework.ide.eclipse.beans.ui.livegraph.model; +package org.springframework.ide.eclipse.beans.ui.live.model; import java.util.Map; -import org.springframework.ide.eclipse.beans.ui.livegraph.views.LiveBeansTreeContentProvider; - /** * A wrapper around a {@link LiveBean} used by the * {@link LiveBeansTreeContentProvider} for displaying bean relationships * without nesting. * * @author Leo Dos Santos + * @author Alex Boyko */ public class LiveBeanRelation extends AbstractLiveBeansModelElement { diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeansContext.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansContext.java similarity index 72% rename from plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeansContext.java rename to plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansContext.java index 178479bb1b..b68ff9a726 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeansContext.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansContext.java @@ -1,17 +1,18 @@ /******************************************************************************* - * Copyright (c) 2012 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 - * http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2012, 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: - * VMware, Inc. - initial API and implementation + * Contributors: + * Pivotal, Inc. - initial API and implementation *******************************************************************************/ -package org.springframework.ide.eclipse.beans.ui.livegraph.model; +package org.springframework.ide.eclipse.beans.ui.live.model; /** * @author Leo Dos Santos + * @author Alex Boyko */ public class LiveBeansContext extends LiveBeansGroup { diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansGroup.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansGroup.java new file mode 100644 index 0000000000..5b2a8b8dcf --- /dev/null +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansGroup.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2012, 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Pivotal, Inc. - initial API and implementation + *******************************************************************************/ +package org.springframework.ide.eclipse.beans.ui.live.model; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +/** + * @author Leo Dos Santos + * @author Alex Boyko + */ +public class LiveBeansGroup extends AbstractLiveBeansModelElement { + + private final String label; + + private final List beans; + + public LiveBeansGroup(String label) { + super(); + this.label = label; + beans = new ArrayList(); + } + + public void addBean(LiveBean bean) { + beans.add(bean); + } + + public List getBeans() { + return beans; + } + + public String getDisplayName() { + return getLabel(); + } + + public String getLabel() { + return label; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof LiveBeansGroup) { + LiveBeansGroup other = (LiveBeansGroup) obj; + return Objects.equals(label, other.label) + && Objects.equals(attributes, other.attributes) + && Objects.equals(beans, other.beans); + } + return super.equals(obj); + } + + + +} diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeansJsonParser.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansJsonParser.java similarity index 78% rename from plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeansJsonParser.java rename to plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansJsonParser.java index 419587fb81..3469030802 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeansJsonParser.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansJsonParser.java @@ -1,16 +1,16 @@ /******************************************************************************* - * Copyright (c) 2012 - 2013 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 - * http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2012, 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: - * VMware, Inc. - initial API and implementation + * Contributors: + * Pivotal, Inc. - initial API and implementation *******************************************************************************/ -package org.springframework.ide.eclipse.beans.ui.livegraph.model; +package org.springframework.ide.eclipse.beans.ui.live.model; -import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; import org.json.JSONArray; @@ -19,10 +19,11 @@ /** * @author Leo Dos Santos + * @author Alex Boyko */ public class LiveBeansJsonParser { - private final LiveBeansSession session; + private final TypeLookup typeLookup; private final String jsonInput; @@ -32,9 +33,9 @@ public class LiveBeansJsonParser { private Map resourceMap; - public LiveBeansJsonParser(LiveBeansSession session, String jsonInput) { + public LiveBeansJsonParser(TypeLookup typeLookup, String jsonInput) { this.jsonInput = jsonInput; - this.session = session; + this.typeLookup = typeLookup; } private void groupByResource() { @@ -53,9 +54,9 @@ private void groupByResource() { } public LiveBeansModel parse() throws JSONException { - beansMap = new HashMap(); - contextMap = new HashMap(); - resourceMap = new HashMap(); + beansMap = new LinkedHashMap(); + contextMap = new LinkedHashMap(); + resourceMap = new LinkedHashMap(); // JSON structure is an array of context descriptions, each containing // an array of beans @@ -64,7 +65,7 @@ public LiveBeansModel parse() throws JSONException { populateContextDependencies(contextsArray); groupByResource(); - LiveBeansModel model = new LiveBeansModel(session); + LiveBeansModel model = new LiveBeansModel(typeLookup); model.addBeans(beansMap.values()); model.addContexts(contextMap.values()); model.addResources(resourceMap.values()); @@ -76,7 +77,7 @@ private void parseBeans(LiveBeansContext context, JSONArray beansArray) throws J for (int i = 0; i < beansArray.length(); i++) { JSONObject beanJson = beansArray.getJSONObject(i); if (beanJson != null && beanJson.has(LiveBean.ATTR_BEAN)) { - LiveBean bean = new LiveBean(session, beanJson.getString(LiveBean.ATTR_BEAN)); + LiveBean bean = new LiveBean(typeLookup, beanJson.getString(LiveBean.ATTR_BEAN)); bean.addAttribute(LiveBeansContext.ATTR_CONTEXT, context.getLabel()); if (beanJson.has(LiveBean.ATTR_SCOPE)) { bean.addAttribute(LiveBean.ATTR_SCOPE, beanJson.getString(LiveBean.ATTR_SCOPE)); @@ -87,8 +88,8 @@ private void parseBeans(LiveBeansContext context, JSONArray beansArray) throws J if (beanJson.has(LiveBean.ATTR_RESOURCE)) { bean.addAttribute(LiveBean.ATTR_RESOURCE, beanJson.getString(LiveBean.ATTR_RESOURCE)); } - if (session.getApplicationName() != null) { - bean.addAttribute(LiveBean.ATTR_APPLICATION, session.getApplicationName()); + if (typeLookup.getApplicationName() != null) { + bean.addAttribute(LiveBean.ATTR_APPLICATION, typeLookup.getApplicationName()); } context.addBean(bean); beansMap.put(bean.getId(), bean); @@ -126,9 +127,9 @@ private void populateBeanDependencies(JSONArray beansArray) throws JSONException bean.addDependency(dependencyBean); } else { - LiveBean dependentBean = new LiveBean(session, dependency, true); - if (session.getApplicationName() != null) { - dependentBean.addAttribute(LiveBean.ATTR_APPLICATION, session.getApplicationName()); + LiveBean dependentBean = new LiveBean(typeLookup, dependency, true); + if (typeLookup.getApplicationName() != null) { + dependentBean.addAttribute(LiveBean.ATTR_APPLICATION, typeLookup.getApplicationName()); } bean.addDependency(dependentBean); } diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeansModel.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansModel.java similarity index 57% rename from plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeansModel.java rename to plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansModel.java index 05e17fe2ec..0d8720e393 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeansModel.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansModel.java @@ -1,23 +1,25 @@ /******************************************************************************* - * Copyright (c) 2012 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 - * http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2012, 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: - * VMware, Inc. - initial API and implementation + * Contributors: + * Pivotal, Inc. - initial API and implementation *******************************************************************************/ -package org.springframework.ide.eclipse.beans.ui.livegraph.model; +package org.springframework.ide.eclipse.beans.ui.live.model; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Objects; /** * A model of a running Spring application to be graphed in the Live Beans Graph * * @author Leo Dos Santos + * @author Alex Boyko */ public class LiveBeansModel implements Comparable { @@ -27,13 +29,13 @@ public class LiveBeansModel implements Comparable { private final List resources; - private final LiveBeansSession session; + private final TypeLookup typeLookup; - public LiveBeansModel(LiveBeansSession session) { + public LiveBeansModel(TypeLookup typeLookup) { this.beans = new ArrayList(); this.contexts = new ArrayList(); this.resources = new ArrayList(); - this.session = session; + this.typeLookup = typeLookup; } public void addBeans(Collection beansToAdd) { @@ -53,8 +55,8 @@ public int compareTo(LiveBeansModel o) { } public String getApplicationName() { - if (session != null) { - return session.getApplicationName(); + if (typeLookup != null) { + return typeLookup.getApplicationName(); } return ""; } @@ -71,8 +73,19 @@ public List getBeansByResource() { return resources; } - public LiveBeansSession getSession() { - return session; + public TypeLookup getWorkspaceContext() { + return typeLookup; } + @Override + public boolean equals(Object obj) { + if (obj instanceof LiveBeansModel) { + LiveBeansModel other = (LiveBeansModel) obj; + // Should be enough to compare contexts only since this is close to raw JSON data + return contexts.equals(other.contexts) && Objects.equals(typeLookup, other.typeLookup); + } + return super.equals(obj); + } + + } diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeansModelCollection.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansModelCollection.java similarity index 65% rename from plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeansModelCollection.java rename to plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansModelCollection.java index 78fb6835ff..c908c0dec3 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeansModelCollection.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansModelCollection.java @@ -1,20 +1,21 @@ /******************************************************************************* - * Copyright (c) 2012 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 - * http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2012, 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: - * VMware, Inc. - initial API and implementation + * Contributors: + * Pivotal, Inc. - initial API and implementation *******************************************************************************/ -package org.springframework.ide.eclipse.beans.ui.livegraph.model; +package org.springframework.ide.eclipse.beans.ui.live.model; import java.util.Set; import java.util.TreeSet; /** * @author Leo Dos Santos + * @author Alex Boyko */ public class LiveBeansModelCollection { diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeansResource.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansResource.java similarity index 72% rename from plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeansResource.java rename to plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansResource.java index 369381f5d9..47845c3f12 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeansResource.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansResource.java @@ -1,17 +1,18 @@ /******************************************************************************* - * Copyright (c) 2012 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 - * http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2012, 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: - * VMware, Inc. - initial API and implementation + * Contributors: + * Pivotal, Inc. - initial API and implementation *******************************************************************************/ -package org.springframework.ide.eclipse.beans.ui.livegraph.model; +package org.springframework.ide.eclipse.beans.ui.live.model; /** * @author Leo Dos Santos + * @author Alex Boyko */ public class LiveBeansResource extends LiveBeansGroup { diff --git a/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/requestmappings/TypeLookup.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/TypeLookup.java similarity index 66% rename from plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/requestmappings/TypeLookup.java rename to plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/TypeLookup.java index cd64980ba2..ff620acf6a 100644 --- a/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/requestmappings/TypeLookup.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/TypeLookup.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015 Pivotal, Inc. + * Copyright (c) 2012, 2017 Pivotal, 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 @@ -8,16 +8,23 @@ * Contributors: * Pivotal, Inc. - initial API and implementation *******************************************************************************/ -package org.springframework.ide.eclipse.boot.dash.model.requestmappings; +package org.springframework.ide.eclipse.beans.ui.live.model; +import org.eclipse.core.resources.IProject; import org.eclipse.jdt.core.IType; /** - * Represents a context in which it is possible to find Java types. Typcially - * this context is some IJavaProject (or something that is linked to one, like a BDE) - * - * @author Kris De Volder + * @author Leo Dos Santos + * @author Alex Boyko */ public interface TypeLookup { + + public String getApplicationName(); + + public IProject getProject(); + IType findType(String fqName); + + IProject[] relatedProjects(); + } diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/TypeLookupImpl.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/TypeLookupImpl.java new file mode 100644 index 0000000000..3af4a89450 --- /dev/null +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/TypeLookupImpl.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2012, 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Pivotal, Inc. - initial API and implementation + *******************************************************************************/ +package org.springframework.ide.eclipse.beans.ui.live.model; + +import java.util.Objects; + +import org.eclipse.core.resources.IProject; +import org.eclipse.jdt.core.IType; +import org.springframework.ide.eclipse.beans.ui.live.utils.JdtUtils; + +/** + * Type Lookup implementation + * + * @author Alex Boyko + * + */ +public class TypeLookupImpl implements TypeLookup { + + private final String appName; + + private final IProject project; + + public TypeLookupImpl(String appName, IProject project) { + this.appName = appName; + this.project = project; + } + + public String getApplicationName() { + return appName; + } + + public IProject getProject() { + return project; + } + + protected String cleanClassName(String className) { + String cleanClassName = className; + if (className != null) { + int ix = className.indexOf('$'); + if (ix > 0) { + cleanClassName = className.substring(0, ix); + } + else { + ix = className.indexOf('#'); + if (ix > 0) { + cleanClassName = className.substring(0, ix); + } + } + } + return cleanClassName; + } + + @Override + public IType findType(String fqName) { + IProject[] projects = relatedProjects(); + for (IProject project : projects) { + IType type = JdtUtils.getJavaType(project, cleanClassName(fqName)); + if (type != null) { + return type; + } + } + return null; + } + + @Override + public IProject[] relatedProjects() { + return new IProject[] { project }; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof TypeLookupImpl) { + TypeLookupImpl other = (TypeLookupImpl) obj; + return Objects.equals(appName, other.appName) && Objects.equals(project, other.project); + } + return super.equals(obj); + } + + +} diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/views/LiveBeansTreeContentProvider.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree/AbstractLiveBeansTreeContentProvider.java similarity index 51% rename from plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/views/LiveBeansTreeContentProvider.java rename to plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree/AbstractLiveBeansTreeContentProvider.java index ef219c7ba6..901bc74fa4 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/views/LiveBeansTreeContentProvider.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree/AbstractLiveBeansTreeContentProvider.java @@ -1,40 +1,33 @@ /******************************************************************************* - * Copyright (c) 2012 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 - * http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2012, 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: - * VMware, Inc. - initial API and implementation + * Contributors: + * Pivotal, Inc. - initial API and implementation *******************************************************************************/ -package org.springframework.ide.eclipse.beans.ui.livegraph.views; +package org.springframework.ide.eclipse.beans.ui.live.tree; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Set; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.Viewer; -import org.springframework.ide.eclipse.beans.ui.livegraph.model.LiveBean; -import org.springframework.ide.eclipse.beans.ui.livegraph.model.LiveBeanRelation; -import org.springframework.ide.eclipse.beans.ui.livegraph.model.LiveBeansGroup; -import org.springframework.ide.eclipse.beans.ui.livegraph.model.LiveBeansModel; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBean; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeanRelation; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeansGroup; /** * A content provider for the Live Beans tree display * * @author Leo Dos Santos + * @author Alex Boyko */ -public class LiveBeansTreeContentProvider implements ITreeContentProvider { - - private final LiveBeansGraphView view; - - public LiveBeansTreeContentProvider(LiveBeansGraphView view) { - this.view = view; - } +public abstract class AbstractLiveBeansTreeContentProvider implements ITreeContentProvider { public void dispose() { - // TODO Auto-generated method stub } @@ -44,7 +37,7 @@ public Object[] getChildren(Object parentElement) { return group.getBeans().toArray(); } else if (parentElement instanceof LiveBean) { - Set children = new HashSet(); + Set children = new LinkedHashSet(); LiveBean bean = (LiveBean) parentElement; Set dependencies = bean.getDependencies(); for (LiveBean child : dependencies) { @@ -59,19 +52,6 @@ else if (parentElement instanceof LiveBean) { return null; } - public Object[] getElements(Object inputElement) { - if (inputElement instanceof LiveBeansModel) { - LiveBeansModel model = (LiveBeansModel) inputElement; - if (view.getGroupByMode() == LiveBeansGraphView.GROUP_BY_RESOURCE) { - return model.getBeansByResource().toArray(); - } - else if (view.getGroupByMode() == LiveBeansGraphView.GROUP_BY_CONTEXT) { - return model.getBeansByContext().toArray(); - } - } - return null; - } - public Object getParent(Object element) { // TODO Auto-generated method stub return null; diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree/ContextGroupedBeansContentProvider.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree/ContextGroupedBeansContentProvider.java new file mode 100644 index 0000000000..3ece60a9bd --- /dev/null +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree/ContextGroupedBeansContentProvider.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2012, 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Pivotal, Inc. - initial API and implementation + *******************************************************************************/ +package org.springframework.ide.eclipse.beans.ui.live.tree; + +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeansModel; + +/** + * Beans grouped by contexts + * + * @author Alex Boyko + * + */ +public final class ContextGroupedBeansContentProvider extends AbstractLiveBeansTreeContentProvider { + + public static final ContextGroupedBeansContentProvider INSTANCE = new ContextGroupedBeansContentProvider(); + + private ContextGroupedBeansContentProvider() {} + + @Override + public Object[] getElements(Object inputElement) { + if (inputElement instanceof LiveBeansModel) { + LiveBeansModel model = (LiveBeansModel) inputElement; + return model.getBeansByContext().toArray(); + } + return new Object[0]; + } + +} diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/views/InnerBeansViewerFilter.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree/InnerBeansViewerFilter.java similarity index 54% rename from plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/views/InnerBeansViewerFilter.java rename to plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree/InnerBeansViewerFilter.java index 854eca7619..9f6b0203a2 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/views/InnerBeansViewerFilter.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree/InnerBeansViewerFilter.java @@ -1,22 +1,23 @@ /******************************************************************************* - * Copyright (c) 2012 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 - * http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2012, 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: - * VMware, Inc. - initial API and implementation + * Contributors: + * Pivotal, Inc. - initial API and implementation *******************************************************************************/ -package org.springframework.ide.eclipse.beans.ui.livegraph.views; +package org.springframework.ide.eclipse.beans.ui.live.tree; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerFilter; -import org.springframework.ide.eclipse.beans.ui.livegraph.model.LiveBean; -import org.springframework.ide.eclipse.beans.ui.livegraph.model.LiveBeanRelation; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBean; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeanRelation; /** * @author Leo Dos Santos + * @author Alex Boyko */ public class InnerBeansViewerFilter extends ViewerFilter { diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/views/LiveBeansTreeLabelProvider.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree/LiveBeansTreeLabelProvider.java similarity index 57% rename from plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/views/LiveBeansTreeLabelProvider.java rename to plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree/LiveBeansTreeLabelProvider.java index 229c9ec265..5c747dba81 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/views/LiveBeansTreeLabelProvider.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree/LiveBeansTreeLabelProvider.java @@ -1,28 +1,31 @@ /******************************************************************************* - * Copyright (c) 2012, 2016 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 - * http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2012, 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: - * VMware, Inc. - initial API and implementation + * Contributors: + * Pivotal, Inc. - initial API and implementation *******************************************************************************/ -package org.springframework.ide.eclipse.beans.ui.livegraph.views; +package org.springframework.ide.eclipse.beans.ui.live.tree; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.swt.graphics.Image; -import org.springframework.ide.eclipse.beans.ui.livegraph.LiveGraphUIImages; -import org.springframework.ide.eclipse.beans.ui.livegraph.model.LiveBean; -import org.springframework.ide.eclipse.beans.ui.livegraph.model.LiveBeanRelation; -import org.springframework.ide.eclipse.beans.ui.livegraph.model.LiveBeansGroup; +import org.springframework.ide.eclipse.beans.ui.live.LiveBeansUiPlugin; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBean; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeanRelation; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeansGroup; /** * A label provider for the Live Beans tree display * * @author Leo Dos Santos + * @author Alex Boyko */ public class LiveBeansTreeLabelProvider extends LabelProvider { + + public static final LiveBeansTreeLabelProvider INSTANCE = new LiveBeansTreeLabelProvider(); // public void decorate(Object element, IDecoration decoration) { // if (element instanceof LiveBean) { @@ -38,14 +41,14 @@ public class LiveBeansTreeLabelProvider extends LabelProvider { @Override public Image getImage(Object element) { if (element instanceof LiveBean) { - return LiveGraphUIImages.getImage(LiveGraphUIImages.IMG_OBJS_BEAN); + return LiveBeansUiPlugin.getDefault().getImageRegistry().get(LiveBeansUiPlugin.IMG_OBJS_BEAN); } else if (element instanceof LiveBeansGroup) { - return LiveGraphUIImages.getImage(LiveGraphUIImages.IMG_OBJS_CONFIG); + return LiveBeansUiPlugin.getDefault().getImageRegistry().get(LiveBeansUiPlugin.IMG_OBJS_CONFIG); } else if (element instanceof LiveBeanRelation) { // TODO: incoming/outgoing arrow images??? - return LiveGraphUIImages.getImage(LiveGraphUIImages.IMG_OBJS_BEAN); + return LiveBeansUiPlugin.getDefault().getImageRegistry().get(LiveBeansUiPlugin.IMG_OBJS_BEAN_REF); } return super.getImage(element); } diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree/ResourceGroupedBeansContentProvider.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree/ResourceGroupedBeansContentProvider.java new file mode 100644 index 0000000000..c82815577e --- /dev/null +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree/ResourceGroupedBeansContentProvider.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2012, 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Pivotal, Inc. - initial API and implementation + *******************************************************************************/ +package org.springframework.ide.eclipse.beans.ui.live.tree; + +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeansModel; + +/** + * Content provider for beans grouped by resources + * + * @author Alex Boyko + * + */ +public final class ResourceGroupedBeansContentProvider extends AbstractLiveBeansTreeContentProvider { + + public static final ResourceGroupedBeansContentProvider INSTANCE = new ResourceGroupedBeansContentProvider(); + + private ResourceGroupedBeansContentProvider() {} + + @Override + public Object[] getElements(Object inputElement) { + if (inputElement instanceof LiveBeansModel) { + LiveBeansModel model = (LiveBeansModel) inputElement; + return model.getBeansByResource().toArray(); + } + return new Object[0]; + } + +} diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/utils/JdtUtils.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/utils/JdtUtils.java new file mode 100644 index 0000000000..29b88d1b95 --- /dev/null +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/utils/JdtUtils.java @@ -0,0 +1,107 @@ +/******************************************************************************* + * Copyright (c) 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Pivotal, Inc. - initial API and implementation + *******************************************************************************/ +package org.springframework.ide.eclipse.beans.ui.live.utils; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Status; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.JavaCore; +import org.springframework.ide.eclipse.beans.ui.live.LiveBeansUiPlugin; + +/** + * JDT Utilities (subset taken from Spring-IDE core to minimize dependencies) + * + * @author Alex Boyko + * + */ +public class JdtUtils { + + /** + * Returns the corresponding Java project or null a for given + * project. + * + * @param project + * the project the Java project is requested for + * @return the requested Java project or null if the Java project + * is not defined or the project is not accessible + */ + public static IJavaProject getJavaProject(IProject project) { + if (project.isAccessible()) { + try { + if (project.hasNature(JavaCore.NATURE_ID)) { + return (IJavaProject) project.getNature(JavaCore.NATURE_ID); + } + } catch (CoreException e) { + LiveBeansUiPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, LiveBeansUiPlugin.PLUGIN_ID, + "Error getting Java project for project '" + project.getName() + "'", e)); + } + } + return null; + } + + /** + * Returns the corresponding Java type for given full-qualified class name. + * + * @param project + * the JDT project the class belongs to + * @param className + * the full qualified class name of the requested Java type + * @return the requested Java type or null if the class is not defined or the + * project is not accessible + */ + public static IType getJavaType(IProject project, String className) { + IJavaProject javaProject = JdtUtils.getJavaProject(project); + if (className != null) { + // For inner classes replace '$' by '.' + int pos = className.lastIndexOf('$'); + if (pos > 0) { + className = className.replace('$', '.'); + } + try { + IType type = null; + // First look for the type in the Java project + if (javaProject != null) { + // TODO CD not sure why we need + type = javaProject.findType(className, new NullProgressMonitor()); + // type = javaProject.findType(className); + if (type != null) { + return type; + } + } + + // Then look for the type in the referenced Java projects + for (IProject refProject : project.getReferencedProjects()) { + IJavaProject refJavaProject = JdtUtils.getJavaProject(refProject); + if (refJavaProject != null) { + type = refJavaProject.findType(className); + if (type != null) { + return type; + } + } + } + + // fall back and try to locate the class using AJDT + // TODO: uncomment this call + // return getAjdtType(project, className); + } catch (CoreException e) { + LiveBeansUiPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, LiveBeansUiPlugin.PLUGIN_ID, + "Error getting Java type '" + className + "'", e)); + } + } + + return null; + } + +} diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/.classpath b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/.classpath index 098194ca4b..eca7bdba8f 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/.classpath +++ b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/.classpath @@ -1,6 +1,6 @@ - + diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/.settings/org.eclipse.jdt.core.prefs b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/.settings/org.eclipse.jdt.core.prefs index 220bc53163..3e5a4cef4d 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/.settings/org.eclipse.jdt.core.prefs +++ b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/.settings/org.eclipse.jdt.core.prefs @@ -1,7 +1,7 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 -org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.autoboxing=ignore @@ -58,7 +58,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=di org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.source=1.7 +org.eclipse.jdt.core.compiler.source=1.8 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/META-INF/MANIFEST.MF b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/META-INF/MANIFEST.MF index aed973cb5d..2154983749 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/META-INF/MANIFEST.MF +++ b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/META-INF/MANIFEST.MF @@ -17,9 +17,10 @@ Require-Bundle: org.eclipse.ui, org.eclipse.wst.server.core, org.eclipse.jst.server.core, org.eclipse.jst.ws, - org.eclipse.wst.common.modulecore + org.eclipse.wst.common.modulecore, + org.springframework.ide.eclipse.beans.ui.live Bundle-ActivationPolicy: lazy -Bundle-RequiredExecutionEnvironment: JavaSE-1.7 +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-Vendor: Spring IDE Developers Bundle-ClassPath: . Export-Package: org.springframework.ide.eclipse.beans.ui.livegraph, diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/LiveGraphUIImages.java b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/LiveGraphUIImages.java index fd2dbbaf1f..6f9c159ba7 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/LiveGraphUIImages.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/LiveGraphUIImages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016 Spring IDE Developers + * Copyright (c) 2016, 2017 Spring IDE Developers * 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,19 +43,13 @@ public class LiveGraphUIImages { /* * Available cached Images in the Spring Beans UI plugin image registry. */ - public static final String IMG_OBJS_BEAN = NAME_PREFIX + "bean_obj.gif"; - public static final String IMG_OBJS_BEAN_REF = NAME_PREFIX + "beanref_obj.gif"; - public static final String IMG_OBJS_CONFIG = NAME_PREFIX + "config_obj.gif"; public static final String IMG_OBJS_COLLECTION = NAME_PREFIX + "collection_obj.gif"; public static final String IMG_OBJS_REFRESH = NAME_PREFIX + "refresh_obj.gif"; // Use IPath and toOSString to build the names to ensure they have the slashes correct private final static String OBJECT = "obj16/"; //basic colors - size 16x16 - public static final ImageDescriptor DESC_OBJS_BEAN_REF = createManaged(OBJECT, IMG_OBJS_BEAN_REF); public static final ImageDescriptor DESC_OBJS_COLLECTION = createManaged(OBJECT, IMG_OBJS_COLLECTION); - public static final ImageDescriptor DESC_OBJS_BEAN = createManaged(OBJECT, IMG_OBJS_BEAN); - public static final ImageDescriptor DESC_OBJS_CONFIG = createManaged(OBJECT, IMG_OBJS_CONFIG); public static final ImageDescriptor REFRESH = createManaged(OBJECT, IMG_OBJS_REFRESH); /* diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/AbstractOpenResourceAction.java b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/AbstractOpenResourceAction.java deleted file mode 100644 index 8211a318c2..0000000000 --- a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/AbstractOpenResourceAction.java +++ /dev/null @@ -1,120 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VMware, Inc. - initial API and implementation - *******************************************************************************/ -package org.springframework.ide.eclipse.beans.ui.livegraph.actions; - -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.jdt.core.IType; -import org.eclipse.jst.server.core.IWebModule; -import org.eclipse.ui.actions.BaseSelectionListenerAction; -import org.eclipse.wst.server.core.IModule; -import org.eclipse.wst.server.core.ServerUtil; -import org.springframework.ide.eclipse.beans.ui.livegraph.model.LiveBeansSession; -import org.springsource.ide.eclipse.commons.core.JdtUtils; -import org.springsource.ide.eclipse.commons.ui.SpringUIUtils; - -/** - * @author Leo Dos Santos - */ -public abstract class AbstractOpenResourceAction extends BaseSelectionListenerAction { - - protected AbstractOpenResourceAction(String text) { - super(text); - } - - protected String cleanClassName(String className) { - String cleanClassName = className; - if (className != null) { - int ix = className.indexOf('$'); - if (ix > 0) { - cleanClassName = className.substring(0, ix); - } - else { - ix = className.indexOf('#'); - if (ix > 0) { - cleanClassName = className.substring(0, ix); - } - } - } - return cleanClassName; - } - - protected String extractClassName(String resourcePath) { - int index = resourcePath.lastIndexOf("/WEB-INF/classes/"); - int length = "/WEB-INF/classes/".length(); - if (index >= 0) { - resourcePath = resourcePath.substring(index + length); - } - resourcePath = resourcePath.substring(0, resourcePath.lastIndexOf(".class")); - resourcePath = resourcePath.replaceAll("\\\\|\\/", "."); //Tolerate both '/' and '\'. - return resourcePath; - } - - protected String extractResourcePath(String resourceStr) { - // Extract the resource path out of the descriptive text - int indexStart = resourceStr.indexOf("["); - int indexEnd = resourceStr.indexOf("]"); - if (indexStart > -1 && indexEnd > -1 && indexStart < indexEnd) { - resourceStr = resourceStr.substring(indexStart + 1, indexEnd); - } - return resourceStr; - } - - protected IProject[] findProjects(LiveBeansSession session) { - Set projects = new HashSet(); - - IProject p = session.getProject(); - if (p!=null) { - projects.add(p); - } - - String appName = session.getApplicationName(); - if (appName!=null && !"".equals(appName)) { - IModule[] modules = ServerUtil.getModules("jst.web"); - for (IModule module : modules) { - Object obj = module.loadAdapter(IWebModule.class, new NullProgressMonitor()); - if (obj instanceof IWebModule) { - IWebModule webModule = (IWebModule) obj; - if (appName.equals(webModule.getContextRoot())) { - projects.add(module.getProject()); - } - } - } - } - return projects.toArray(new IProject[projects.size()]); - } - - protected boolean hasTypeInProject(LiveBeansSession session, String className) { - IProject[] projects = findProjects(session); - for (IProject project : projects) { - IType type = JdtUtils.getJavaType(project, cleanClassName(className)); - if (type != null) { - return true; - } - } - return false; - } - - protected void openInEditor(LiveBeansSession session, String className) { - IProject[] projects = findProjects(session); - for (IProject project : projects) { - IType type = JdtUtils.getJavaType(project, cleanClassName(className)); - if (type != null) { - SpringUIUtils.openInEditor(type); - break; - } - } - } - -} diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/ConnectToApplicationAction.java b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/ConnectToApplicationAction.java index bc1c4158a5..f651ce34f4 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/ConnectToApplicationAction.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/ConnectToApplicationAction.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2012 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 - * http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2012, 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: - * VMware, Inc. - initial API and implementation + * Contributors: + * Pivotal, Inc. - initial API and implementation *******************************************************************************/ package org.springframework.ide.eclipse.beans.ui.livegraph.actions; @@ -16,8 +16,8 @@ import org.eclipse.jface.action.Action; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.dialogs.IDialogConstants; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeansModel; import org.springframework.ide.eclipse.beans.ui.livegraph.LiveGraphUiPlugin; -import org.springframework.ide.eclipse.beans.ui.livegraph.model.LiveBeansModel; import org.springframework.ide.eclipse.beans.ui.livegraph.model.LiveBeansModelGenerator; import org.springframework.ide.eclipse.beans.ui.livegraph.views.LiveBeansGraphView; import org.springsource.ide.eclipse.commons.core.StatusHandler; diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/LoadModelAction.java b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/LoadModelAction.java index 2098fd8552..b06f92e26d 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/LoadModelAction.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/LoadModelAction.java @@ -1,17 +1,17 @@ /******************************************************************************* - * Copyright (c) 2012 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 - * http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2012, 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: - * VMware, Inc. - initial API and implementation + * Contributors: + * Pivotal, Inc. - initial API and implementation *******************************************************************************/ package org.springframework.ide.eclipse.beans.ui.livegraph.actions; import org.eclipse.jface.action.Action; -import org.springframework.ide.eclipse.beans.ui.livegraph.model.LiveBeansModel; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeansModel; import org.springframework.ide.eclipse.beans.ui.livegraph.views.LiveBeansGraphView; /** diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/OpenBeanDefinitionAction.java b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/OpenXmlBeanDefinitionAction.java similarity index 69% rename from plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/OpenBeanDefinitionAction.java rename to plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/OpenXmlBeanDefinitionAction.java index 4888807d5a..06caa13e60 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/OpenBeanDefinitionAction.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/OpenXmlBeanDefinitionAction.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2012 - 2013 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 - * http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: - * VMware, Inc. - initial API and implementation + * Contributors: + * Pivotal, Inc. - initial API and implementation *******************************************************************************/ package org.springframework.ide.eclipse.beans.ui.livegraph.actions; @@ -26,25 +26,29 @@ import org.eclipse.core.runtime.Status; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jst.ws.internal.common.ResourceUtils; +import org.springframework.ide.eclipse.beans.ui.live.actions.OpenBeanDefinitionAction; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBean; +import org.springframework.ide.eclipse.beans.ui.live.model.TypeLookup; import org.springframework.ide.eclipse.beans.ui.livegraph.LiveGraphUiPlugin; -import org.springframework.ide.eclipse.beans.ui.livegraph.model.LiveBean; -import org.springframework.ide.eclipse.beans.ui.livegraph.model.LiveBeansSession; import org.springsource.ide.eclipse.commons.core.StatusHandler; import org.springsource.ide.eclipse.commons.ui.SpringUIUtils; /** - * @author Leo Dos Santos + * Legacy action to open XML bean resource + * + * @author Alex Boyko + * */ @SuppressWarnings("restriction") -public class OpenBeanDefinitionAction extends AbstractOpenResourceAction { - - public OpenBeanDefinitionAction() { - super("Open Bean Definition File"); +public class OpenXmlBeanDefinitionAction extends OpenBeanDefinitionAction { + + public OpenXmlBeanDefinitionAction() { + super(); } - private void openXmlFiles(List contexts, LiveBeansSession session) { + private void openXmlFiles(List contexts, TypeLookup workspaceContext) { try { - IProject[] projects = findProjects(session); + IProject[] projects = workspaceContext.relatedProjects(); for (IProject project : projects) { IPath[] paths = ResourceUtils.getAllJavaSourceLocations(project); if (paths.length > 0) { @@ -70,12 +74,12 @@ private void openXmlFiles(List contexts, LiveBeansSession session) { public void run() { IStructuredSelection selection = getStructuredSelection(); List elements = selection.toList(); - LiveBeansSession session = null; + TypeLookup session = null; final List contexts = new ArrayList(); for (Object obj : elements) { if (obj instanceof LiveBean) { LiveBean bean = (LiveBean) obj; - session = bean.getSession(); + session = bean.getTypeLookup(); String resource = bean.getResource(); if (resource != null && resource.trim().length() > 0 && !resource.equalsIgnoreCase("null")) { String resourcePath = extractResourcePath(resource); @@ -89,9 +93,6 @@ public void run() { contexts.add(resourcePath); } } - else if (resourcePath.endsWith(".class")) { - openInEditor(session, extractClassName(resourcePath)); - } } } } @@ -100,23 +101,9 @@ else if (resourcePath.endsWith(".class")) { // Find the XML files in the workspace and open them openXmlFiles(contexts, session); } - } - - @Override - protected boolean updateSelection(IStructuredSelection selection) { - if (!selection.isEmpty()) { - List elements = selection.toList(); - for (Object obj : elements) { - if (obj instanceof LiveBean) { - LiveBean bean = (LiveBean) obj; - String resource = bean.getResource(); - if (resource != null && resource.trim().length() > 0 && !resource.equalsIgnoreCase("null")) { - return true; - } - } - } - } - return false; + + // Open Java classes + super.run(); } private class ResourceProxyVisitor implements IResourceProxyVisitor { @@ -141,4 +128,5 @@ public boolean visit(IResourceProxy proxy) throws CoreException { } + } diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/RefreshApplicationAction.java b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/RefreshApplicationAction.java index 7fe757c356..11159ddfa2 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/RefreshApplicationAction.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/RefreshApplicationAction.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2012, 2016 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 - * http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2012, 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: - * VMware, Inc. - initial API and implementation + * Contributors: + * Pivotal, Inc. - initial API and implementation *******************************************************************************/ package org.springframework.ide.eclipse.beans.ui.livegraph.actions; @@ -14,9 +14,9 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.jface.action.Action; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeansModel; import org.springframework.ide.eclipse.beans.ui.livegraph.LiveGraphUIImages; import org.springframework.ide.eclipse.beans.ui.livegraph.LiveGraphUiPlugin; -import org.springframework.ide.eclipse.beans.ui.livegraph.model.LiveBeansModel; import org.springframework.ide.eclipse.beans.ui.livegraph.model.LiveBeansModelGenerator; import org.springframework.ide.eclipse.beans.ui.livegraph.views.LiveBeansGraphView; import org.springsource.ide.eclipse.commons.core.StatusHandler; diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/ToggleViewModeAction.java b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/ToggleViewModeAction.java index 0995b98875..dac7d26a26 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/ToggleViewModeAction.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/ToggleViewModeAction.java @@ -1,16 +1,17 @@ /******************************************************************************* - * Copyright (c) 2012, 2016 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 - * http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2012, 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: - * VMware, Inc. - initial API and implementation + * Contributors: + * Pivotal, Inc. - initial API and implementation *******************************************************************************/ package org.springframework.ide.eclipse.beans.ui.livegraph.actions; import org.eclipse.jface.action.Action; +import org.springframework.ide.eclipse.beans.ui.live.LiveBeansUiPlugin; import org.springframework.ide.eclipse.beans.ui.livegraph.LiveGraphUIImages; import org.springframework.ide.eclipse.beans.ui.livegraph.views.LiveBeansGraphView; @@ -27,7 +28,7 @@ public ToggleViewModeAction(LiveBeansGraphView view, int mode) { super("", AS_RADIO_BUTTON); if (mode == LiveBeansGraphView.DISPLAY_MODE_GRAPH) { setText("Graph View"); - setImageDescriptor(LiveGraphUIImages.DESC_OBJS_BEAN_REF); + setImageDescriptor(LiveBeansUiPlugin.getDefault().getImageRegistry().getDescriptor(LiveBeansUiPlugin.IMG_OBJS_BEAN_REF)); } else if (mode == LiveBeansGraphView.DISPLAY_MODE_TREE) { setText("Tree View"); diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeansGroup.java b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeansGroup.java deleted file mode 100644 index 8c95e7e54f..0000000000 --- a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeansGroup.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VMware, Inc. - initial API and implementation - *******************************************************************************/ -package org.springframework.ide.eclipse.beans.ui.livegraph.model; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author Leo Dos Santos - */ -public class LiveBeansGroup extends AbstractLiveBeansModelElement { - - private final String label; - - private final List beans; - - public LiveBeansGroup(String label) { - super(); - this.label = label; - beans = new ArrayList(); - } - - public void addBean(LiveBean bean) { - beans.add(bean); - } - - public List getBeans() { - return beans; - } - - public String getDisplayName() { - return getLabel(); - } - - public String getLabel() { - return label; - } - -} diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeansModelGenerator.java b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeansModelGenerator.java index 4c9653f436..3ebd370aed 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeansModelGenerator.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeansModelGenerator.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2012 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 - * http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2012, 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: - * VMware, Inc. - initial API and implementation + * Contributors: + * Pivotal, Inc. - initial API and implementation *******************************************************************************/ package org.springframework.ide.eclipse.beans.ui.livegraph.model; @@ -34,6 +34,9 @@ import org.eclipse.core.runtime.jobs.Job; import org.json.JSONException; import org.springframework.context.support.LiveBeansViewMBean; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeansJsonParser; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeansModel; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeansModelCollection; import org.springframework.ide.eclipse.beans.ui.livegraph.LiveGraphUiPlugin; import org.springsource.ide.eclipse.commons.core.StatusHandler; @@ -211,8 +214,8 @@ private static LiveBeansModel generateModel(LiveBeansViewMBean mbean, LiveBeansS * @throws CoreException */ public static LiveBeansModel refreshModel(LiveBeansModel originalModel) throws CoreException { - LiveBeansSession session = originalModel.getSession(); - if (session != null) { + if (originalModel.getWorkspaceContext() instanceof LiveBeansSession) { + LiveBeansSession session = (LiveBeansSession) originalModel.getWorkspaceContext(); LiveBeansModel model = connectToModel(session.getServiceUrl(), session.getUsername(), session.getPassword(), session.getApplicationName(), session.getProject()); if (model != null) { diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeansSession.java b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeansSession.java index 0dcd04b2d2..6e3a3dd4e9 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeansSession.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/model/LiveBeansSession.java @@ -1,21 +1,32 @@ /******************************************************************************* - * Copyright (c) 2012 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 - * http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: - * VMware, Inc. - initial API and implementation + * Contributors: + * Pivotal, Inc. - initial API and implementation *******************************************************************************/ package org.springframework.ide.eclipse.beans.ui.livegraph.model; +import java.util.ArrayList; +import java.util.Arrays; + import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jst.server.core.IWebModule; +import org.eclipse.wst.server.core.IModule; +import org.eclipse.wst.server.core.ServerUtil; +import org.springframework.ide.eclipse.beans.ui.live.model.TypeLookupImpl; /** - * @author Leo Dos Santos + * Live Beans Session implementation + * + * @author Alex Boyko + * */ -public class LiveBeansSession { +public class LiveBeansSession extends TypeLookupImpl { private final String serviceUrl; @@ -23,20 +34,11 @@ public class LiveBeansSession { private final String password; - private final String appName; - - private final IProject project; - public LiveBeansSession(String serviceUrl, String username, String password, String appName, IProject project) { + super(appName, project); this.serviceUrl = serviceUrl; this.username = username; this.password = password; - this.appName = appName; - this.project = project; - } - - public String getApplicationName() { - return appName; } public String getPassword() { @@ -51,8 +53,24 @@ public String getUsername() { return username; } - public IProject getProject() { - return project; + @Override + public IProject[] relatedProjects() { + ArrayList projects = new ArrayList<>(); + projects.addAll(Arrays.asList(super.relatedProjects())); + String appName = getApplicationName(); + if (appName != null && !"".equals(appName)) { + IModule[] modules = ServerUtil.getModules("jst.web"); + for (IModule module : modules) { + Object obj = module.loadAdapter(IWebModule.class, new NullProgressMonitor()); + if (obj instanceof IWebModule) { + IWebModule webModule = (IWebModule) obj; + if (appName.equals(webModule.getContextRoot())) { + projects.add(module.getProject()); + } + } + } + } + return projects.toArray(new IProject[projects.size()]); } } diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/views/LiveBeansGraphContentProvider.java b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/views/LiveBeansGraphContentProvider.java index c6b1fb89b4..7d54931d8e 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/views/LiveBeansGraphContentProvider.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/views/LiveBeansGraphContentProvider.java @@ -1,19 +1,19 @@ /******************************************************************************* - * Copyright (c) 2012 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 - * http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2012, 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: - * VMware, Inc. - initial API and implementation + * Contributors: + * Pivotal, Inc. - initial API and implementation *******************************************************************************/ package org.springframework.ide.eclipse.beans.ui.livegraph.views; import org.eclipse.jface.viewers.Viewer; import org.eclipse.zest.core.viewers.IGraphEntityContentProvider; -import org.springframework.ide.eclipse.beans.ui.livegraph.model.LiveBean; -import org.springframework.ide.eclipse.beans.ui.livegraph.model.LiveBeansModel; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBean; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeansModel; /** * A content provider for the Live Beans Graph diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/views/LiveBeansGraphLabelProvider.java b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/views/LiveBeansGraphLabelProvider.java index f3cce4f388..f7946abe8e 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/views/LiveBeansGraphLabelProvider.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/views/LiveBeansGraphLabelProvider.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2012 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 - * http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2012, 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: - * VMware, Inc. - initial API and implementation + * Contributors: + * Pivotal, Inc. - initial API and implementation *******************************************************************************/ package org.springframework.ide.eclipse.beans.ui.livegraph.views; @@ -16,7 +16,7 @@ import org.eclipse.zest.core.viewers.ISelfStyleProvider; import org.eclipse.zest.core.widgets.GraphConnection; import org.eclipse.zest.core.widgets.GraphNode; -import org.springframework.ide.eclipse.beans.ui.livegraph.model.LiveBean; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBean; /** * A label provider for the Live Beans Graph diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/views/LiveBeansGraphView.java b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/views/LiveBeansGraphView.java index 0061b39361..4399159562 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/views/LiveBeansGraphView.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/views/LiveBeansGraphView.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2012 - 2013 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 - * http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2012, 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: - * VMware, Inc. - initial API and implementation + * Contributors: + * Pivotal, Inc. - initial API and implementation *******************************************************************************/ package org.springframework.ide.eclipse.beans.ui.livegraph.views; @@ -24,6 +24,7 @@ import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerSorter; @@ -36,17 +37,21 @@ import org.eclipse.zest.core.viewers.GraphViewer; import org.eclipse.zest.core.widgets.ZestStyles; import org.eclipse.zest.layouts.LayoutStyles; +import org.springframework.ide.eclipse.beans.ui.live.actions.OpenBeanClassAction; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeansModel; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeansModelCollection; +import org.springframework.ide.eclipse.beans.ui.live.tree.ContextGroupedBeansContentProvider; +import org.springframework.ide.eclipse.beans.ui.live.tree.InnerBeansViewerFilter; +import org.springframework.ide.eclipse.beans.ui.live.tree.LiveBeansTreeLabelProvider; +import org.springframework.ide.eclipse.beans.ui.live.tree.ResourceGroupedBeansContentProvider; import org.springframework.ide.eclipse.beans.ui.livegraph.LiveGraphUiPlugin; import org.springframework.ide.eclipse.beans.ui.livegraph.actions.ConnectToApplicationAction; import org.springframework.ide.eclipse.beans.ui.livegraph.actions.FilterInnerBeansAction; import org.springframework.ide.eclipse.beans.ui.livegraph.actions.LoadModelAction; -import org.springframework.ide.eclipse.beans.ui.livegraph.actions.OpenBeanClassAction; -import org.springframework.ide.eclipse.beans.ui.livegraph.actions.OpenBeanDefinitionAction; +import org.springframework.ide.eclipse.beans.ui.livegraph.actions.OpenXmlBeanDefinitionAction; import org.springframework.ide.eclipse.beans.ui.livegraph.actions.RefreshApplicationAction; import org.springframework.ide.eclipse.beans.ui.livegraph.actions.ToggleGroupByAction; import org.springframework.ide.eclipse.beans.ui.livegraph.actions.ToggleViewModeAction; -import org.springframework.ide.eclipse.beans.ui.livegraph.model.LiveBeansModel; -import org.springframework.ide.eclipse.beans.ui.livegraph.model.LiveBeansModelCollection; /** * A simple view to host our graph @@ -146,11 +151,20 @@ public void createPartControl(Composite parent) { setGroupByMode(prefStore.getInt(PREF_GROUP_MODE)); setFilterInnerBeans(prefStore.getBoolean(PREF_FILTER_INNER_BEANS)); } + + private ITreeContentProvider getTreeContentProvider() { + if (getGroupByMode() == GROUP_BY_CONTEXT) { + return ContextGroupedBeansContentProvider.INSTANCE; + } else if (getGroupByMode() == GROUP_BY_RESOURCE) { + return ResourceGroupedBeansContentProvider.INSTANCE; + } + return null; + } private void createTreeViewer() { treeViewer = new TreeViewer(pagebook, SWT.NONE); - treeViewer.setContentProvider(new LiveBeansTreeContentProvider(this)); - treeViewer.setLabelProvider(new LiveBeansTreeLabelProvider()); + treeViewer.setContentProvider(getTreeContentProvider()); + treeViewer.setLabelProvider(LiveBeansTreeLabelProvider.INSTANCE); treeViewer.setSorter(new ViewerSorter()); treeViewer.addDoubleClickListener(new IDoubleClickListener() { @@ -249,10 +263,10 @@ private void hookToolBar() { private boolean isViewerVisible(Viewer viewer) { return viewer != null && !viewer.getControl().isDisposed() && viewer.getControl().isVisible(); } - + private void makeActions() { openBeanClassAction = new OpenBeanClassAction(); - openBeanDefAction = new OpenBeanDefinitionAction(); + openBeanDefAction = new OpenXmlBeanDefinitionAction(); connectApplicationAction = new ConnectToApplicationAction(this); displayModeActions = new ToggleViewModeAction[] { new ToggleViewModeAction(this, DISPLAY_MODE_GRAPH), new ToggleViewModeAction(this, DISPLAY_MODE_TREE) }; @@ -287,9 +301,9 @@ else if (isViewerVisible(treeViewer)) { public void setGroupByMode(int mode) { activeGroupByMode = mode; - if (isViewerVisible(treeViewer)) { - treeViewer.refresh(); - } +// if (isViewerVisible(treeViewer)) { + treeViewer.setContentProvider(getTreeContentProvider()); +// } for (ToggleGroupByAction action : groupByActions) { action.setChecked(mode == action.getGroupByMode()); } diff --git a/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/AllBootDashTests.java b/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/AllBootDashTests.java index 0ff355bc71..40be0913a5 100644 --- a/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/AllBootDashTests.java +++ b/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/AllBootDashTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015, 2016 Pivotal, Inc. + * Copyright (c) 2015, 2017 Pivotal, 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 @@ -13,7 +13,8 @@ import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; -import org.springframework.ide.eclipse.boot.dash.test.requestmappings.ActuatorClientTest; +import org.springframework.ide.eclipse.boot.dash.test.actuator.ActuatorClientTest; +import org.springframework.ide.eclipse.boot.dash.test.actuator.ActuatorDataTest; import org.springframework.ide.eclipse.boot.dash.test.yaml.AppNameReconcilerTest; import org.springframework.ide.eclipse.boot.dash.test.yaml.CFRouteTests; import org.springframework.ide.eclipse.boot.dash.test.yaml.DeploymentProperties2YamlTest; @@ -44,6 +45,7 @@ AbstractLaunchConfigurationsDashElementTest.class, BootDashElementTagsTests.class, ActuatorClientTest.class, + ActuatorDataTest.class, ToggleFiltersModelTest.class, //Medium length (less than 30 seconds): diff --git a/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/BootDashModelTest.java b/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/BootDashModelTest.java index b08eebfc0a..8402203891 100644 --- a/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/BootDashModelTest.java +++ b/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/BootDashModelTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015, 2016 Pivotal, Inc. + * Copyright (c) 2015, 2017 Pivotal, 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 @@ -30,7 +30,7 @@ import static org.mockito.Mockito.when; import static org.springframework.ide.eclipse.boot.dash.test.BootDashViewModelHarness.assertLabelContains; import static org.springframework.ide.eclipse.boot.dash.test.BootDashViewModelHarness.getLabel; -import static org.springframework.ide.eclipse.boot.dash.test.requestmappings.RequestMappingAsserts.assertRequestMappingWithPath; +import static org.springframework.ide.eclipse.boot.dash.test.actuator.RequestMappingAsserts.assertRequestMappingWithPath; import static org.springframework.ide.eclipse.boot.test.BootProjectTestHarness.bootVersionAtLeast; import static org.springframework.ide.eclipse.boot.test.BootProjectTestHarness.setPackage; import static org.springframework.ide.eclipse.boot.test.BootProjectTestHarness.withStarters; @@ -97,8 +97,8 @@ import org.springframework.ide.eclipse.boot.dash.model.RunState; import org.springframework.ide.eclipse.boot.dash.model.ToggleFiltersModel; import org.springframework.ide.eclipse.boot.dash.model.ToggleFiltersModel.FilterChoice; +import org.springframework.ide.eclipse.boot.dash.model.actuator.RequestMapping; import org.springframework.ide.eclipse.boot.dash.model.UserInteractions; -import org.springframework.ide.eclipse.boot.dash.model.requestmappings.RequestMapping; import org.springframework.ide.eclipse.boot.dash.model.runtargettypes.RunTargetTypes; import org.springframework.ide.eclipse.boot.dash.util.CollectionUtils; import org.springframework.ide.eclipse.boot.dash.views.BootDashLabels; diff --git a/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/JLRMethodParserTest.java b/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/JLRMethodParserTest.java index 2185a22689..2a9a94567b 100644 --- a/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/JLRMethodParserTest.java +++ b/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/JLRMethodParserTest.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.springframework.ide.eclipse.boot.dash.test; -import org.springframework.ide.eclipse.boot.dash.model.requestmappings.JLRMethodParser; +import org.springframework.ide.eclipse.boot.dash.model.actuator.JLRMethodParser; import junit.framework.TestCase; diff --git a/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/requestmappings/ActuatorClientTest.java b/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/actuator/ActuatorClientTest.java similarity index 90% rename from plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/requestmappings/ActuatorClientTest.java rename to plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/actuator/ActuatorClientTest.java index dc8aa6f957..26d9a5b529 100644 --- a/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/requestmappings/ActuatorClientTest.java +++ b/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/actuator/ActuatorClientTest.java @@ -8,13 +8,13 @@ * Contributors: * Pivotal, Inc. - initial API and implementation *******************************************************************************/ -package org.springframework.ide.eclipse.boot.dash.test.requestmappings; +package org.springframework.ide.eclipse.boot.dash.test.actuator; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.springframework.ide.eclipse.boot.dash.test.requestmappings.RequestMappingAsserts.assertRequestMappingWithPath; +import static org.springframework.ide.eclipse.boot.dash.test.actuator.RequestMappingAsserts.assertRequestMappingWithPath; import java.io.InputStream; import java.net.URI; @@ -26,9 +26,9 @@ import org.eclipse.jdt.core.IType; import org.junit.Test; -import org.springframework.ide.eclipse.boot.dash.model.requestmappings.RequestMapping; -import org.springframework.ide.eclipse.boot.dash.model.requestmappings.RestActuatorClient; -import org.springframework.ide.eclipse.boot.dash.model.requestmappings.TypeLookup; +import org.springframework.ide.eclipse.beans.ui.live.model.TypeLookup; +import org.springframework.ide.eclipse.boot.dash.model.actuator.RequestMapping; +import org.springframework.ide.eclipse.boot.dash.model.actuator.RestActuatorClient; import org.springsource.ide.eclipse.commons.frameworks.core.util.IOUtil; @@ -152,8 +152,8 @@ protected Client restClientThrowing(Throwable exeption) throws Exception { ////////////////////////////////////////////////////////////////// - private String getContents(String resourcePath) throws Exception { - InputStream input = this.getClass().getResourceAsStream(resourcePath); + public static String getContents(String resourcePath) throws Exception { + InputStream input = ActuatorClientTest.class.getResourceAsStream(resourcePath); String s = IOUtil.toString(input); System.out.println(s); return s; diff --git a/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/actuator/ActuatorDataTest.java b/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/actuator/ActuatorDataTest.java new file mode 100644 index 0000000000..0f0ccaa444 --- /dev/null +++ b/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/actuator/ActuatorDataTest.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2015 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Pivotal, Inc. - initial API and implementation + *******************************************************************************/ +package org.springframework.ide.eclipse.boot.dash.test.actuator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +import org.junit.Test; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBean; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeansGroup; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeansModel; +import org.springframework.ide.eclipse.beans.ui.live.model.TypeLookup; +import org.springframework.ide.eclipse.boot.dash.model.actuator.ActuatorClient; + +/** + * Tests data obtained from the Actuator + * + * @author Alex Boyko + * + */ +public class ActuatorDataTest { + + static class TestActuatorClient extends ActuatorClient { + + private String beansJson = ""; + private String requestMappingsJson = ""; + + public TestActuatorClient(TypeLookup workspaceConext) { + super(workspaceConext); + } + + public TestActuatorClient beansJson(String json) { + this.beansJson = json; + return this; + } + + public TestActuatorClient requestMappingJson(String json) { + this.requestMappingsJson = json; + return this; + } + + @Override + protected String getRequestMappingData() throws Exception { + return requestMappingsJson; + } + + @Override + protected String getBeansData() throws Exception { + return beansJson; + } + + } + + @Test public void testModelEquality() throws Exception { + TestActuatorClient client = new TestActuatorClient(null).beansJson(ActuatorClientTest.getContents("beans-sample.json")); + LiveBeansModel liveBeans = client.getBeans(); + assertEquals(liveBeans, client.getBeans()); + } + + @Test public void testModelIneuality_1() throws Exception { + TestActuatorClient client = new TestActuatorClient(null).beansJson(ActuatorClientTest.getContents("beans-sample.json")); + TestActuatorClient otherClient = new TestActuatorClient(null).beansJson(ActuatorClientTest.getContents("beans-sample-diff1.json")); + assertNotEquals(client.getBeans(), otherClient.getBeans()); + } + + @Test public void testModelContent() throws Exception { + TestActuatorClient client = new TestActuatorClient(null).beansJson(ActuatorClientTest.getContents("beans-sample.json")); + LiveBeansModel liveBeans = client.getBeans(); + assertEquals(1, liveBeans.getBeansByContext().size()); + LiveBeansGroup context = liveBeans.getBeansByContext().get(0); + assertEquals(2, context.getBeans().size()); + assertEquals(2, liveBeans.getBeans().size()); + assertEquals(2, liveBeans.getBeansByResource().size()); + + assertEquals(context.getBeans(), liveBeans.getBeans()); + + LiveBean bean1 = liveBeans.getBeans().get(0); + assertEquals( + "org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$Jackson2ObjectMapperBuilderCustomizerConfiguration$StandardJackson2ObjectMapperBuilderCustomizer", + bean1.getBeanType()); + assertEquals("standardJacksonObjectMapperBuilderCustomizer", bean1.getId()); + + LiveBean bean2 = liveBeans.getBeans().get(1); + assertEquals( + "org.springframework.boot.autoconfigure.jackson.JacksonProperties", + bean2.getBeanType()); + assertEquals("spring.jackson-org.springframework.boot.autoconfigure.jackson.JacksonProperties", bean2.getId()); + } + +} diff --git a/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/requestmappings/RequestMappingAsserts.java b/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/actuator/RequestMappingAsserts.java similarity index 86% rename from plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/requestmappings/RequestMappingAsserts.java rename to plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/actuator/RequestMappingAsserts.java index 5bdbed3f9f..197e3f9472 100644 --- a/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/requestmappings/RequestMappingAsserts.java +++ b/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/actuator/RequestMappingAsserts.java @@ -8,13 +8,13 @@ * Contributors: * Pivotal, Inc. - initial API and implementation *******************************************************************************/ -package org.springframework.ide.eclipse.boot.dash.test.requestmappings; +package org.springframework.ide.eclipse.boot.dash.test.actuator; import static org.junit.Assert.fail; import java.util.List; -import org.springframework.ide.eclipse.boot.dash.model.requestmappings.RequestMapping; +import org.springframework.ide.eclipse.boot.dash.model.actuator.RequestMapping; public class RequestMappingAsserts { diff --git a/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/actuator/beans-sample-diff1.json b/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/actuator/beans-sample-diff1.json new file mode 100644 index 0000000000..cbc63d9073 --- /dev/null +++ b/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/actuator/beans-sample-diff1.json @@ -0,0 +1,25 @@ +[{ + "parent": null, + "beans": [ + { + "aliases": [], + "resource": "class path resource [org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration$Jackson2ObjectMapperBuilderCustomizerConfiguration1.class]", + "scope": "singleton", + "type": "org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$Jackson2ObjectMapperBuilderCustomizerConfiguration$StandardJackson2ObjectMapperBuilderCustomizer", + "bean": "standardJacksonObjectMapperBuilderCustomizer", + "dependencies": [ + "org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@4b9e255", + "spring.jackson-org.springframework.boot.autoconfigure.jackson.JacksonProperties" + ] + }, + { + "aliases": [], + "resource": "null", + "scope": "singleton", + "type": "org.springframework.boot.autoconfigure.jackson.JacksonProperties", + "bean": "spring.jackson-org.springframework.boot.autoconfigure.jackson.JacksonProperties", + "dependencies": [] + } + ], + "context": "application:9999" +}] diff --git a/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/actuator/beans-sample.json b/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/actuator/beans-sample.json new file mode 100644 index 0000000000..787869197a --- /dev/null +++ b/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/actuator/beans-sample.json @@ -0,0 +1,25 @@ +[{ + "parent": null, + "beans": [ + { + "aliases": [], + "resource": "class path resource [org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration$Jackson2ObjectMapperBuilderCustomizerConfiguration.class]", + "scope": "singleton", + "type": "org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$Jackson2ObjectMapperBuilderCustomizerConfiguration$StandardJackson2ObjectMapperBuilderCustomizer", + "bean": "standardJacksonObjectMapperBuilderCustomizer", + "dependencies": [ + "org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@4b9e255", + "spring.jackson-org.springframework.boot.autoconfigure.jackson.JacksonProperties" + ] + }, + { + "aliases": [], + "resource": "null", + "scope": "singleton", + "type": "org.springframework.boot.autoconfigure.jackson.JacksonProperties", + "bean": "spring.jackson-org.springframework.boot.autoconfigure.jackson.JacksonProperties", + "dependencies": [] + } + ], + "context": "application:9999" +}] diff --git a/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/requestmappings/sample.json b/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/actuator/sample.json similarity index 100% rename from plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/requestmappings/sample.json rename to plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/actuator/sample.json diff --git a/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/requestmappings/sample2.json b/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/actuator/sample2.json similarity index 100% rename from plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/requestmappings/sample2.json rename to plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/actuator/sample2.json diff --git a/plugins/org.springframework.ide.eclipse.boot.dash/META-INF/MANIFEST.MF b/plugins/org.springframework.ide.eclipse.boot.dash/META-INF/MANIFEST.MF index af12ab6c54..307d51b7bc 100644 --- a/plugins/org.springframework.ide.eclipse.boot.dash/META-INF/MANIFEST.MF +++ b/plugins/org.springframework.ide.eclipse.boot.dash/META-INF/MANIFEST.MF @@ -49,7 +49,8 @@ Require-Bundle: org.eclipse.ui, org.springframework.ide.eclipse.editor.support, javax.ws.rs;bundle-version="2.0.1", org.glassfish.jersey.core.jersey-client;bundle-version="2.22.1", - org.glassfish.jersey.core.jersey-common;bundle-version="2.22.1" + org.glassfish.jersey.core.jersey-common;bundle-version="2.22.1", + org.springframework.ide.eclipse.beans.ui.live Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-ActivationPolicy: lazy Bundle-ClassPath: ., @@ -60,7 +61,7 @@ Export-Package: org.springframework.ide.eclipse.boot.dash, org.springframework.ide.eclipse.boot.dash.cloudfoundry.packaging, org.springframework.ide.eclipse.boot.dash.livexp, org.springframework.ide.eclipse.boot.dash.model, - org.springframework.ide.eclipse.boot.dash.model.requestmappings, + org.springframework.ide.eclipse.boot.dash.model.actuator, org.springframework.ide.eclipse.boot.dash.model.runtargettypes, org.springframework.ide.eclipse.boot.dash.ngrok, org.springframework.ide.eclipse.boot.dash.util, diff --git a/plugins/org.springframework.ide.eclipse.boot.dash/plugin.xml b/plugins/org.springframework.ide.eclipse.boot.dash/plugin.xml index f3a75ef4c7..87d9e5c3d7 100644 --- a/plugins/org.springframework.ide.eclipse.boot.dash/plugin.xml +++ b/plugins/org.springframework.ide.eclipse.boot.dash/plugin.xml @@ -58,6 +58,12 @@ id="org.springframework.ide.eclipse.boot.dash.tab.RequestMappings" label="Request Mappings"> + + @@ -115,6 +121,20 @@ type="org.springframework.ide.eclipse.boot.dash.model.LocalCloudServiceDashElement"> + + + + + + + + diff --git a/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/cloudfoundry/CloudDashElement.java b/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/cloudfoundry/CloudDashElement.java index a4872c7979..4b2e0ea8da 100644 --- a/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/cloudfoundry/CloudDashElement.java +++ b/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/cloudfoundry/CloudDashElement.java @@ -13,11 +13,12 @@ import java.net.URI; import java.util.List; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeansModel; import org.springframework.ide.eclipse.boot.dash.model.BootDashModel; import org.springframework.ide.eclipse.boot.dash.model.WrappingBootDashElement; -import org.springframework.ide.eclipse.boot.dash.model.requestmappings.ActuatorClient; -import org.springframework.ide.eclipse.boot.dash.model.requestmappings.RequestMapping; -import org.springframework.ide.eclipse.boot.dash.model.requestmappings.RestActuatorClient; +import org.springframework.ide.eclipse.boot.dash.model.actuator.ActuatorClient; +import org.springframework.ide.eclipse.boot.dash.model.actuator.RequestMapping; +import org.springframework.ide.eclipse.boot.dash.model.actuator.RestActuatorClient; import org.springsource.ide.eclipse.commons.livexp.core.AsyncLiveExpression; import org.springsource.ide.eclipse.commons.livexp.core.LiveExpression; @@ -30,6 +31,7 @@ public CloudDashElement(BootDashModel bootDashModel, T delegate) { } private LiveExpression> liveRequestMappings; + private LiveExpression liveBeans; protected ActuatorClient getActuatorClient(URI target) { return new RestActuatorClient(target, getTypeLookup(), getRestClient()); @@ -62,6 +64,29 @@ protected ImmutableList compute() { return liveRequestMappings.getValue(); } + public LiveBeansModel getLiveBeans() { + synchronized (this) { + if (liveBeans == null) { + final LiveExpression actuatorUrl = getActuatorUrl(); + liveBeans = new AsyncLiveExpression(null, "Fetch beans for '"+getName()+"'") { + protected LiveBeansModel compute() { + URI target = actuatorUrl.getValue(); + if (target != null) { + ActuatorClient client = getActuatorClient(target); + return client.getBeans(); + } + return null; + } + + }; + liveBeans.dependsOn(actuatorUrl); + addElementState(liveBeans); + addDisposableChild(liveBeans); + } + } + return liveBeans.getValue(); + } + protected LiveExpression getActuatorUrl() { return LiveExpression.constant(null); } diff --git a/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/AbstractLaunchConfigurationsDashElement.java b/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/AbstractLaunchConfigurationsDashElement.java index c8f361f505..c2b6166526 100644 --- a/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/AbstractLaunchConfigurationsDashElement.java +++ b/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/AbstractLaunchConfigurationsDashElement.java @@ -36,15 +36,15 @@ import org.eclipse.jdt.core.IType; import org.eclipse.jdt.launching.SocketUtil; import org.eclipse.swt.widgets.Display; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeansModel; import org.springframework.ide.eclipse.boot.dash.livexp.PollingLiveExp; -import org.springframework.ide.eclipse.boot.dash.model.requestmappings.ActuatorClient; -import org.springframework.ide.eclipse.boot.dash.model.requestmappings.JMXActuatorClient; -import org.springframework.ide.eclipse.boot.dash.model.requestmappings.RequestMapping; +import org.springframework.ide.eclipse.boot.dash.model.actuator.ActuatorClient; +import org.springframework.ide.eclipse.boot.dash.model.actuator.JMXActuatorClient; +import org.springframework.ide.eclipse.boot.dash.model.actuator.RequestMapping; import org.springframework.ide.eclipse.boot.dash.ngrok.NGROKClient; import org.springframework.ide.eclipse.boot.dash.ngrok.NGROKLaunchTracker; import org.springframework.ide.eclipse.boot.dash.ngrok.NGROKTunnel; import org.springframework.ide.eclipse.boot.dash.util.CollectionUtils; -import org.springframework.ide.eclipse.boot.dash.util.DebugUtil; import org.springframework.ide.eclipse.boot.dash.util.LaunchConfRunStateTracker; import org.springframework.ide.eclipse.boot.dash.util.RunStateTracker.RunStateListener; import org.springframework.ide.eclipse.boot.launch.BootLaunchConfigurationDelegate; @@ -87,7 +87,7 @@ private static void debug(String string) { public static final EnumSet READY_STATES = EnumSet.of(RunState.RUNNING, RunState.DEBUGGING); - private static final Duration REQUEST_MAPPING_REFRESH_TIMEOUT = Duration.ofMinutes(2); + private static final Duration LIVE_DATA_REFRESH_TIMEOUT = Duration.ofMinutes(2); private LiveExpression runState; private LiveExpression livePort; @@ -99,6 +99,7 @@ private static void debug(String string) { private LiveExpression actuatorUrl; private PollingLiveExp> liveRequestMappings; + private PollingLiveExp liveBeans; public AbstractLaunchConfigurationsDashElement(LocalBootDashModel bootDashModel, T delegate) { super(bootDashModel, delegate); @@ -524,7 +525,7 @@ public List getLiveRequestMappings() { addDisposableChild(liveRequestMappings); runState.addListener((e, runstate) -> { if (READY_STATES.contains(runstate)) { - liveRequestMappings.refreshFor(REQUEST_MAPPING_REFRESH_TIMEOUT); + liveRequestMappings.refreshFor(LIVE_DATA_REFRESH_TIMEOUT); } else { liveRequestMappings.refreshOnce(); } @@ -534,6 +535,27 @@ public List getLiveRequestMappings() { } } + public LiveBeansModel getLiveBeans() { + synchronized (this) { + if (liveBeans == null) { + ActuatorClient client = getActuatorClient(); + liveBeans = PollingLiveExp.create(client::getBeans); + addElementState(liveBeans); + addDisposableChild(liveBeans); + runState.addListener((e, runstate) -> { + if (READY_STATES.contains(runstate)) { + // After the app is running refresh for 2 minutes every 5 sec + liveBeans.sleepBetweenRefreshes(Duration.ofSeconds(5)); + liveBeans.refreshFor(LIVE_DATA_REFRESH_TIMEOUT); + } else { + liveBeans.refreshOnce(); + } + }); + } + return liveBeans.getValue(); + } + } + private int getJmxPort() { for (ILaunchConfiguration c : getLaunchConfigs()) { for (ILaunch l : LaunchUtils.getLaunches(c)) { diff --git a/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/BootDashElement.java b/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/BootDashElement.java index 5a44cc8181..1b5fb5fda5 100644 --- a/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/BootDashElement.java +++ b/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/BootDashElement.java @@ -16,7 +16,8 @@ import org.eclipse.core.resources.IProject; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.jdt.core.IJavaProject; -import org.springframework.ide.eclipse.boot.dash.model.requestmappings.RequestMapping; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeansModel; +import org.springframework.ide.eclipse.boot.dash.model.actuator.RequestMapping; import org.springframework.ide.eclipse.boot.dash.views.sections.BootDashColumn; import org.springsource.ide.eclipse.commons.livexp.core.ObservableSet; @@ -51,6 +52,13 @@ public interface BootDashElement extends Nameable, Taggable { */ List getLiveRequestMappings(); + /** + * Get the beans from a running process. May return null if beans cannot be + * determined. (Thus, null means unknown, whereas an empty list + * means 'no beans') + */ + LiveBeansModel getLiveBeans(); + /** * Get the 'active' launch configuration. This may be null. *

diff --git a/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/WrappingBootDashElement.java b/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/WrappingBootDashElement.java index 07dbe3d0eb..7c74ff1e12 100644 --- a/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/WrappingBootDashElement.java +++ b/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/WrappingBootDashElement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015, 2016 Pivotal, Inc. + * Copyright (c) 2015, 2017 Pivotal, 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 @@ -17,14 +17,13 @@ import javax.ws.rs.client.ClientBuilder; import org.eclipse.core.runtime.ListenerList; -import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.JavaCore; +import org.springframework.ide.eclipse.beans.ui.live.model.TypeLookup; +import org.springframework.ide.eclipse.beans.ui.live.model.TypeLookupImpl; import org.springframework.ide.eclipse.boot.dash.BootDashActivator; import org.springframework.ide.eclipse.boot.dash.livexp.LiveSets; -import org.springframework.ide.eclipse.boot.dash.model.requestmappings.TypeLookup; import org.springframework.ide.eclipse.boot.dash.util.CancelationTokens; import org.springframework.ide.eclipse.boot.dash.util.CancelationTokens.CancelationToken; import org.springframework.ide.eclipse.boot.dash.util.Utils; @@ -110,19 +109,7 @@ public String toString() { protected TypeLookup getTypeLookup() { if (typeLookup==null) { - typeLookup = new TypeLookup() { - public IType findType(String fqName) { - try { - IJavaProject jp = getJavaProject(); - if (jp!=null) { - return jp.findType(fqName, new NullProgressMonitor()); - } - } catch (Exception e) { - BootDashActivator.log(e); - } - return null; - } - }; + typeLookup = new TypeLookupImpl(getName(), getProject()); } return typeLookup; } diff --git a/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/requestmappings/AbstractRequestMapping.java b/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/actuator/AbstractRequestMapping.java similarity index 87% rename from plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/requestmappings/AbstractRequestMapping.java rename to plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/actuator/AbstractRequestMapping.java index 905d0ebd81..5d20f872b3 100644 --- a/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/requestmappings/AbstractRequestMapping.java +++ b/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/actuator/AbstractRequestMapping.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015 Pivotal, Inc. + * Copyright (c) 2015, 2017 Pivotal, 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 @@ -8,13 +8,14 @@ * Contributors: * Pivotal, Inc. - initial API and implementation *******************************************************************************/ -package org.springframework.ide.eclipse.boot.dash.model.requestmappings; +package org.springframework.ide.eclipse.boot.dash.model.actuator; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IMethod; import org.eclipse.jdt.core.IPackageFragmentRoot; import org.eclipse.jdt.core.IType; -import org.springframework.ide.eclipse.boot.dash.BootDashActivator; +import org.springframework.ide.eclipse.beans.ui.live.model.TypeLookup; +import org.springframework.ide.eclipse.boot.util.Log; /** * @author Kris De Volder @@ -54,7 +55,7 @@ public IMethod getMethod() { } } } catch (Exception e) { - BootDashActivator.log(e); + Log.log(e); } return null; } @@ -70,7 +71,7 @@ public boolean isUserDefined() { } } } catch (Exception e) { - BootDashActivator.log(e); + Log.log(e); } return false; } diff --git a/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/requestmappings/ActuatorClient.java b/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/actuator/ActuatorClient.java similarity index 88% rename from plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/requestmappings/ActuatorClient.java rename to plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/actuator/ActuatorClient.java index 7a8321e8d8..b45587ddff 100644 --- a/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/requestmappings/ActuatorClient.java +++ b/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/actuator/ActuatorClient.java @@ -8,7 +8,7 @@ * Contributors: * Pivotal, Inc. - initial API and implementation *******************************************************************************/ -package org.springframework.ide.eclipse.boot.dash.model.requestmappings; +package org.springframework.ide.eclipse.boot.dash.model.actuator; import java.util.ArrayList; import java.util.Collection; @@ -20,7 +20,11 @@ import org.json.JSONException; import org.json.JSONObject; -import org.springframework.ide.eclipse.boot.dash.model.requestmappings.JLRMethodParser.JLRMethod; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeansJsonParser; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeansModel; +import org.springframework.ide.eclipse.beans.ui.live.model.TypeLookup; +import org.springframework.ide.eclipse.beans.ui.live.model.TypeLookupImpl; +import org.springframework.ide.eclipse.boot.dash.model.actuator.JLRMethodParser.JLRMethod; import org.springframework.ide.eclipse.boot.util.Log; import com.google.common.base.Objects; @@ -210,5 +214,19 @@ public List getRequestMappings() { return null; } + public LiveBeansModel getBeans() { + try { + String json = getBeansData(); + if (json != null) { + return new LiveBeansJsonParser(new TypeLookupImpl("", null), json).parse(); + } + } catch (Exception e) { + Log.log(e); + } + return null; + } + protected abstract String getRequestMappingData() throws Exception; + + protected abstract String getBeansData() throws Exception; } diff --git a/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/requestmappings/JLRMethodParser.java b/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/actuator/JLRMethodParser.java similarity index 95% rename from plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/requestmappings/JLRMethodParser.java rename to plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/actuator/JLRMethodParser.java index f99f6d2ab6..921539e7fb 100644 --- a/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/requestmappings/JLRMethodParser.java +++ b/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/actuator/JLRMethodParser.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015 Pivotal, Inc. + * Copyright (c) 2015, 2017 Pivotal, 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 @@ -8,7 +8,7 @@ * Contributors: * Pivotal, Inc. - initial API and implementation *******************************************************************************/ -package org.springframework.ide.eclipse.boot.dash.model.requestmappings; +package org.springframework.ide.eclipse.boot.dash.model.actuator; import java.util.Arrays; import java.util.Collections; @@ -80,7 +80,7 @@ public String getMethodName() { } - private static final Set MODIFIERS = Collections.unmodifiableSet(new HashSet(Arrays.asList( + private static final Set MODIFIERS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList( "public", "protected", "private", "abstract", "static", "final", "synchronized", "native", "strictfp" ))); diff --git a/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/requestmappings/JMXActuatorClient.java b/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/actuator/JMXActuatorClient.java similarity index 73% rename from plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/requestmappings/JMXActuatorClient.java rename to plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/actuator/JMXActuatorClient.java index 7114c1e2f8..1e8f13e22e 100644 --- a/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/requestmappings/JMXActuatorClient.java +++ b/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/actuator/JMXActuatorClient.java @@ -8,13 +8,14 @@ * Contributors: * Pivotal, Inc. - initial API and implementation *******************************************************************************/ -package org.springframework.ide.eclipse.boot.dash.model.requestmappings; +package org.springframework.ide.eclipse.boot.dash.model.actuator; import java.util.Set; import javax.inject.Provider; import javax.management.InstanceNotFoundException; +import org.springframework.ide.eclipse.beans.ui.live.model.TypeLookup; import org.springframework.ide.eclipse.boot.launch.util.JMXClient; import org.springsource.ide.eclipse.commons.livexp.util.ExceptionUtil; @@ -40,11 +41,16 @@ public OperationInfo(String objectName, String operationName) { } } - private static final OperationInfo[] OPERATIONS = { + private static final OperationInfo[] REQUEST_MAPPINGS_OPERATIONS = { new OperationInfo("org.springframework.boot:type=Endpoint,name=Mappings", "mappings"), //Boot 2.x new OperationInfo("org.springframework.boot:type=Endpoint,name=requestMappingEndpoint", "getData") //Boot 1.x }; + private static final OperationInfo[] BEANS_OPERATIONS = { + new OperationInfo("org.springframework.boot:type=Endpoint,name=Beans", "beans"), //Boot 2.x + new OperationInfo("org.springframework.boot:type=Endpoint,name=beansEndpoint", "getData") //Boot 1.x + }; + private JMXClient client = null; private Integer port = null; @@ -58,7 +64,32 @@ protected String getRequestMappingData() throws Exception { try { JMXClient client = getClient(); if (client!=null) { - for (OperationInfo op : OPERATIONS) { + for (OperationInfo op : REQUEST_MAPPINGS_OPERATIONS) { + try { + Object obj = client.callOperation(op.objectName, op.operationName); + if (obj!=null) { + return new ObjectMapper().writeValueAsString(obj); + } + } catch (InstanceNotFoundException e) { + //Ignore and try other mbean + } + } + } + } catch (Exception e) { + disposeClient(); //Client may be in broken state, do not reuse. + if (!isExpectedException(e)) { + throw e; + } + } + return null; + } + + @Override + protected String getBeansData() throws Exception { + try { + JMXClient client = getClient(); + if (client!=null) { + for (OperationInfo op : BEANS_OPERATIONS) { try { Object obj = client.callOperation(op.objectName, op.operationName); if (obj!=null) { diff --git a/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/requestmappings/RequestMapping.java b/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/actuator/RequestMapping.java similarity index 88% rename from plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/requestmappings/RequestMapping.java rename to plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/actuator/RequestMapping.java index 83d16a3669..39718bade7 100644 --- a/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/requestmappings/RequestMapping.java +++ b/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/actuator/RequestMapping.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015 Pivotal, Inc. + * Copyright (c) 2015, 2017 Pivotal, 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 @@ -8,7 +8,7 @@ * Contributors: * Pivotal, Inc. - initial API and implementation *******************************************************************************/ -package org.springframework.ide.eclipse.boot.dash.model.requestmappings; +package org.springframework.ide.eclipse.boot.dash.model.actuator; import org.eclipse.jdt.core.IMethod; import org.eclipse.jdt.core.IType; diff --git a/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/requestmappings/RestActuatorClient.java b/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/actuator/RestActuatorClient.java similarity index 82% rename from plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/requestmappings/RestActuatorClient.java rename to plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/actuator/RestActuatorClient.java index f55ee599d7..986821dcb5 100644 --- a/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/requestmappings/RestActuatorClient.java +++ b/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/actuator/RestActuatorClient.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015 Pivotal, Inc. + * Copyright (c) 2015, 2017 Pivotal, 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 @@ -8,13 +8,15 @@ * Contributors: * Pivotal, Inc. - initial API and implementation *******************************************************************************/ -package org.springframework.ide.eclipse.boot.dash.model.requestmappings; +package org.springframework.ide.eclipse.boot.dash.model.actuator; import java.net.URI; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; +import org.springframework.ide.eclipse.beans.ui.live.model.TypeLookup; + /** * Concretization of {@link ActuatorClient} which uses spring rest template to @@ -41,4 +43,10 @@ public RestActuatorClient(URI target, TypeLookup typeLookup, Client client) { protected String getRequestMappingData() throws Exception { return client.target(target).path("/mappings").request().get(String.class); } + + @Override + protected String getBeansData() throws Exception { + return null; + } + } diff --git a/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/views/AbstractBootDashElementsAction.java b/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/views/AbstractBootDashElementsAction.java index f73beafe9e..1c851f0616 100644 --- a/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/views/AbstractBootDashElementsAction.java +++ b/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/views/AbstractBootDashElementsAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015 Pivotal Software, Inc. + * Copyright (c) 2015, 2017 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 @@ -13,7 +13,7 @@ import java.util.Collection; import org.eclipse.jface.action.IAction; -import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; import org.springframework.ide.eclipse.boot.dash.livexp.MultiSelection; import org.springframework.ide.eclipse.boot.dash.model.BootDashElement; import org.springframework.ide.eclipse.boot.dash.model.BootDashModel.ElementStateListener; @@ -61,8 +61,8 @@ public AbstractBootDashElementsAction(BootDashViewModel model, MultiSelection bde = new LiveVariable<>(); @Override public void createControls(Composite parent, TabbedPropertySheetPage aTabbedPropertySheetPage) { @@ -50,7 +52,7 @@ public void setInput(IWorkbenchPart part, ISelection selection) { } else { Object inputObj = structuredSelection.getFirstElement(); Assert.isTrue(inputObj instanceof BootDashElement); - bde = (BootDashElement) inputObj; + bde.setValue((BootDashElement) inputObj); } } @@ -79,6 +81,10 @@ public void run() { } final protected BootDashElement getBootDashElement() { + return bde.getValue(); + } + + final protected LiveExpression getBootDashElementLiveExpression() { return bde; } diff --git a/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/views/properties/BeansPropertiesSection.java b/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/views/properties/BeansPropertiesSection.java new file mode 100644 index 0000000000..b6e936d0f2 --- /dev/null +++ b/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/views/properties/BeansPropertiesSection.java @@ -0,0 +1,177 @@ +/******************************************************************************* + * Copyright (c) 2017 Pivotal, 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Pivotal, Inc. - initial API and implementation + *******************************************************************************/ +package org.springframework.ide.eclipse.boot.dash.views.properties; + +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.custom.StackLayout; +import org.eclipse.swt.events.TreeEvent; +import org.eclipse.swt.events.TreeListener; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants; +import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; +import org.springframework.ide.eclipse.beans.ui.live.tree.LiveBeansTreeLabelProvider; +import org.springframework.ide.eclipse.beans.ui.live.tree.ResourceGroupedBeansContentProvider; +import org.springframework.ide.eclipse.boot.dash.model.BootDashElement; + +/** + * Live beans property section + * + * @author Alex Boyko + * + */ +public class BeansPropertiesSection extends AbstractBdePropertiesSection { + + private TreeViewer treeViewer; + private Label labelText; + private TabbedPropertySheetPage page; + private StackLayout layout; + + /** + * Searches for the upper level ScrolledComposite. Returns the passed composite if not found. + * @param composite + * @return + */ + private static Composite getScrolledComposite(Composite composite) { + Composite c = composite; + while(c != null && !(c instanceof ScrolledComposite)) { + c = c.getParent(); + } + return c == null ? composite : c; + } + + @Override + public void createControls(Composite parent, TabbedPropertySheetPage aTabbedPropertySheetPage) { + super.createControls(parent, aTabbedPropertySheetPage); + page = aTabbedPropertySheetPage; + + Composite composite = getWidgetFactory().createComposite(parent, SWT.NONE); + + // Layout variant to have owner composite size to be equal the client area size of the next upper level ScrolledComposite + composite.setLayout(layout = new StackLayout() { + @Override + protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) { + Point size = super.computeSize(composite, wHint, hHint, flushCache); + if (page.getControl() instanceof Composite) { + Composite container = getScrolledComposite(composite); + Rectangle r = container.getClientArea(); + return new Point(r.width, r.height); + } + return size; + } + }); + + layout.marginWidth = ITabbedPropertyConstants.HSPACE + 2; + layout.marginHeight = ITabbedPropertyConstants.VSPACE + 4; + + labelText = getWidgetFactory().createLabel(composite, "", SWT.WRAP); //$NON-NLS-1$ + + treeViewer = new TreeViewer(composite/*, SWT.NO_SCROLL*/); + treeViewer.setContentProvider(new BeansContentProvider(ResourceGroupedBeansContentProvider.INSTANCE)); + treeViewer.setLabelProvider(LiveBeansTreeLabelProvider.INSTANCE); + + treeViewer.getTree().addTreeListener (new TreeListener () { + @Override + public void treeExpanded (TreeEvent e) { + reflow(page); + } + @Override + public void treeCollapsed (TreeEvent e) { + reflow(page); + } + }); + + refreshControlsVisibility(); + + } + + public void setInput(IWorkbenchPart part, ISelection selection) { + super.setInput(part, selection); + treeViewer.setInput(getBootDashElement()); + } + + public void refresh() { + refreshControlsVisibility(); + BootDashElement bde = getBootDashElement(); + if (bde == null) { + labelText.setText("Select single element in Boot Dashboard to see live Beans"); + } else if (bde.getLiveBeans() == null) { + labelText.setText("'" + bde.getName() + "' must be running with JMX enabled; and actuator 'beans' endpoint must be enabled to obtain beans."); + } else { + labelText.setText(""); + } + treeViewer.refresh(); + reflow(page); + } + + private void reflow(TabbedPropertySheetPage page) { + final Composite target = page.getControl().getParent(); + if (target!=null) { + target.getDisplay().asyncExec(new Runnable() { + public void run() { + target.layout(true, true); + page.resizeScrolledComposite(); + } + }); + } + } + + private void refreshControlsVisibility() { + BootDashElement bde = getBootDashElement(); + if (bde == null || bde.getLiveRequestMappings() == null) { + layout.topControl = labelText; + } else { + layout.topControl = treeViewer.getTree(); + } + } + + private static class BeansContentProvider implements ITreeContentProvider { + + private ITreeContentProvider delegateContentProvider; + + BeansContentProvider(ITreeContentProvider delegate) { + this.delegateContentProvider = delegate; + } + + @Override + public Object[] getElements(Object inputElement) { + if (inputElement instanceof BootDashElement) { + BootDashElement bde = (BootDashElement) inputElement; + return delegateContentProvider.getElements(bde.getLiveBeans()); + } + return new Object[0]; + } + + @Override + public Object[] getChildren(Object parentElement) { + return delegateContentProvider.getChildren(parentElement); + } + + @Override + public Object getParent(Object element) { + return delegateContentProvider.getParent(element); + } + + @Override + public boolean hasChildren(Object element) { + return delegateContentProvider.hasChildren(element); + } + + } + +} diff --git a/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/views/properties/RequestMappingPropertiesSection.java b/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/views/properties/RequestMappingPropertiesSection.java index 1eaae8a45b..ff8360dcd6 100644 --- a/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/views/properties/RequestMappingPropertiesSection.java +++ b/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/views/properties/RequestMappingPropertiesSection.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015, 2016 Pivotal, Inc. + * Copyright (c) 2015, 2017 Pivotal, 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 @@ -41,11 +41,10 @@ import org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; import org.springframework.ide.eclipse.boot.dash.model.BootDashElement; -import org.springframework.ide.eclipse.boot.dash.model.requestmappings.RequestMapping; +import org.springframework.ide.eclipse.boot.dash.model.actuator.RequestMapping; import org.springframework.ide.eclipse.boot.dash.util.Utils; import org.springframework.ide.eclipse.boot.dash.views.RequestMappingLabelProvider; import org.springframework.ide.eclipse.boot.dash.views.RequestMappingsColumn; -import org.springsource.ide.eclipse.commons.livexp.core.LiveVariable; import org.springsource.ide.eclipse.commons.livexp.ui.Stylers; import org.springsource.ide.eclipse.commons.ui.SpringUIUtils; @@ -73,7 +72,7 @@ public void mouseDoubleClick(MouseEvent e) { RequestMappingsColumn col = RequestMappingsColumn.values()[colIdx]; switch (col) { case PATH: - BootDashElement bde = input.getValue(); + BootDashElement bde = getBootDashElement(); String url = Utils.createUrl(bde.getLiveHost(), bde.getLivePort(), rm.getPath()); if (url!=null) { openUrl(url); @@ -97,8 +96,6 @@ public void mouseDoubleClick(MouseEvent e) { private Label labelText; - private LiveVariable input = new LiveVariable<>(); - private static final Object[] NO_ELEMENTS = new Object[0]; private TabbedPropertySheetPage page; private Composite composite; @@ -151,7 +148,7 @@ public void createControls(Composite parent, TabbedPropertySheetPage aTabbedProp tv.setContentProvider(new ContentProvider()); tv.setComparator(sorter); // tv.setLabelProvider(labelProvider = new RequestMappingLabelProvider(tv.getTable().getFont(), input)); - tv.setInput(input.getValue()); + tv.setInput(getBootDashElement()); tv.getTable().setHeaderVisible(true); stylers = new Stylers(tv.getTable().getFont()); @@ -159,7 +156,7 @@ public void createControls(Composite parent, TabbedPropertySheetPage aTabbedProp for (RequestMappingsColumn colType : RequestMappingsColumn.values()) { TableViewerColumn col = new TableViewerColumn(tv, colType.getAlignment()); - col.setLabelProvider(new RequestMappingLabelProvider(stylers, input, colType)); + col.setLabelProvider(new RequestMappingLabelProvider(stylers, getBootDashElementLiveExpression(), colType)); TableColumn colWidget = col.getColumn(); colWidget.setText(colType.getLabel()); colWidget.setWidth(colType.getDefaultWidth()); @@ -172,7 +169,6 @@ public void createControls(Composite parent, TabbedPropertySheetPage aTabbedProp public void setInput(IWorkbenchPart part, ISelection selection) { super.setInput(part, selection); - input.setValue(getBootDashElement()); tv.setInput(getBootDashElement()); } diff --git a/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/views/sections/RequestMappingContentProposalProvider.java b/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/views/sections/RequestMappingContentProposalProvider.java index f2de423879..0e75024e2a 100644 --- a/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/views/sections/RequestMappingContentProposalProvider.java +++ b/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/views/sections/RequestMappingContentProposalProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015 Pivotal, Inc. + * Copyright (c) 2015, 2017 Pivotal, 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 @@ -16,7 +16,7 @@ import org.eclipse.jface.fieldassist.IContentProposal; import org.eclipse.jface.fieldassist.IContentProposalProvider; import org.springframework.ide.eclipse.boot.dash.model.BootDashElement; -import org.springframework.ide.eclipse.boot.dash.model.requestmappings.RequestMapping; +import org.springframework.ide.eclipse.boot.dash.model.actuator.RequestMapping; import org.springframework.ide.eclipse.editor.support.util.FuzzyMatcher; import org.springsource.ide.eclipse.commons.livexp.core.LiveExpression; diff --git a/plugins/org.springframework.ide.eclipse.boot.launch.livebean/META-INF/MANIFEST.MF b/plugins/org.springframework.ide.eclipse.boot.launch.livebean/META-INF/MANIFEST.MF index 7e12d39342..b260d26ea0 100644 --- a/plugins/org.springframework.ide.eclipse.boot.launch.livebean/META-INF/MANIFEST.MF +++ b/plugins/org.springframework.ide.eclipse.boot.launch.livebean/META-INF/MANIFEST.MF @@ -15,6 +15,7 @@ Require-Bundle: org.eclipse.ui, org.springframework.ide.eclipse.boot.launch, org.springsource.ide.eclipse.commons.ui, org.springsource.ide.eclipse.commons.livexp, - org.springsource.ide.eclipse.commons.frameworks.ui + org.springsource.ide.eclipse.commons.frameworks.ui, + org.springframework.ide.eclipse.beans.ui.live Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-ActivationPolicy: lazy diff --git a/plugins/org.springframework.ide.eclipse.boot.launch.livebean/src/org/springframework/ide/eclipse/boot/launch/livebean/OpenLiveBeansGraphAction.java b/plugins/org.springframework.ide.eclipse.boot.launch.livebean/src/org/springframework/ide/eclipse/boot/launch/livebean/OpenLiveBeansGraphAction.java index 123aac50b9..318a27efdc 100644 --- a/plugins/org.springframework.ide.eclipse.boot.launch.livebean/src/org/springframework/ide/eclipse/boot/launch/livebean/OpenLiveBeansGraphAction.java +++ b/plugins/org.springframework.ide.eclipse.boot.launch.livebean/src/org/springframework/ide/eclipse/boot/launch/livebean/OpenLiveBeansGraphAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014 Pivotal Software, Inc. + * Copyright (c) 2014, 2017 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 @@ -27,19 +27,17 @@ import org.eclipse.jface.viewers.ISelection; import org.eclipse.ui.IViewPart; import org.eclipse.ui.PlatformUI; -import org.springframework.ide.eclipse.beans.ui.livegraph.model.LiveBeansModel; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeansModel; import org.springframework.ide.eclipse.beans.ui.livegraph.model.LiveBeansModelGenerator; import org.springframework.ide.eclipse.beans.ui.livegraph.views.LiveBeansGraphView; -import org.springframework.ide.eclipse.boot.core.BootActivator; import org.springframework.ide.eclipse.boot.core.BootPropertyTester; import org.springframework.ide.eclipse.boot.launch.BootLaunchConfigurationDelegate; import org.springframework.ide.eclipse.boot.launch.livebean.JmxBeanSupport.Feature; +import org.springframework.ide.eclipse.boot.util.Log; import org.springsource.ide.eclipse.commons.frameworks.ui.internal.actions.AbstractActionDelegate; import org.springsource.ide.eclipse.commons.livexp.util.ExceptionUtil; import org.springsource.ide.eclipse.commons.ui.launch.LaunchUtils; -import org.springframework.ide.eclipse.boot.util.Log; - public class OpenLiveBeansGraphAction extends AbstractActionDelegate { private static final String HOST = "127.0.0.1"; @@ -95,7 +93,7 @@ private void connectToProject(IProject project) { } } catch (Exception e) { - BootActivator.log(e); + Log.log(e); MessageDialog.openError(getShell(), "Error", ExceptionUtil.getMessage(e)+"\n\n" + "Check the error log for more details"); } diff --git a/pom.xml b/pom.xml index 53e31b0b20..b434db112d 100644 --- a/pom.xml +++ b/pom.xml @@ -129,6 +129,7 @@ plugins/org.springframework.ide.eclipse.beans.ui plugins/org.springframework.ide.eclipse.beans.ui.editor plugins/org.springframework.ide.eclipse.beans.ui.graph + plugins/org.springframework.ide.eclipse.beans.ui.live plugins/org.springframework.ide.eclipse.beans.ui.livegraph plugins/org.springframework.ide.eclipse.beans.ui.refactoring plugins/org.springframework.ide.eclipse.beans.ui.search