提交 f44fc051 编写于 作者: S serge-rider

Debug candidates resolution fix

上级 59b6045b
......@@ -17,42 +17,33 @@
*/
package org.jkiss.dbeaver.debug.core;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.Adapters;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.osgi.util.NLS;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.dbeaver.debug.*;
import org.jkiss.dbeaver.debug.DBGConstants;
import org.jkiss.dbeaver.debug.DBGController;
import org.jkiss.dbeaver.debug.DBGResolver;
import org.jkiss.dbeaver.debug.core.model.DatabaseStackFrame;
import org.jkiss.dbeaver.debug.internal.core.DebugCoreActivator;
import org.jkiss.dbeaver.debug.internal.core.DebugCoreMessages;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.DBPScriptObject;
import org.jkiss.dbeaver.model.navigator.DBNDatabaseNode;
import org.jkiss.dbeaver.model.navigator.DBNModel;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.model.struct.rdb.DBSProcedure;
import org.jkiss.dbeaver.model.struct.rdb.DBSProcedureParameter;
import org.jkiss.dbeaver.utils.GeneralUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class DebugCore {
......@@ -66,14 +57,6 @@ public class DebugCore {
return abort(message, null);
}
public static ILaunchConfigurationWorkingCopy createConfiguration(IContainer container, String typeName,
String name) throws CoreException {
ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
ILaunchConfigurationType type = manager.getLaunchConfigurationType(typeName);
ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(container, name);
return workingCopy;
}
public static boolean canLaunch(ILaunchConfiguration configuration, String mode) {
if (configuration == null || !configuration.exists()) {
return false;
......@@ -92,8 +75,7 @@ public class DebugCore {
if (scope == null) {
return extracted;
}
for (int i = 0; i < scope.length; i++) {
Object object = scope[i];
for (Object object : scope) {
DBSObject adapted = Adapters.adapt(object, DBSObject.class, true);
if (adapted != null) {
extracted.add(adapted);
......@@ -154,16 +136,12 @@ public class DebugCore {
final DBNModel navigatorModel = DBeaverCore.getInstance().getNavigatorModel();
DBNDatabaseNode node = navigatorModel.getNodeByObject(new VoidProgressMonitor(), dbsObject, false);
if (node != null) {
String nodePath = node.getNodeItemPath();
DebugCore.postDebuggerSourceEvent(nodePath);
return nodePath;
return node.getNodeItemPath();
}
}
if (object instanceof String) {
// well, let's be positive and assume it's a node path already
String nodePath = (String) object;
DebugCore.postDebuggerSourceEvent(nodePath);
return nodePath;
return (String) object;
}
return null;
}
......@@ -171,15 +149,9 @@ public class DebugCore {
public static Map<String, Object> toBreakpointDescriptor(Map<String, Object> attributes) {
HashMap<String, Object> result = new HashMap<>();
result.put(IMarker.LINE_NUMBER, attributes.get(IMarker.LINE_NUMBER));
//result.put(PostgreDebugConstants.ATTR_PROCEDURE_OID, attributes.get(PostgreDebugConstants.ATTR_PROCEDURE_OID));
return result;
}
public static void postDebuggerSourceEvent(String nodePath) {
String encoded = GeneralUtils.encodeTopic(DBPScriptObject.OPTION_DEBUGGER_SOURCE);
DebugCoreActivator.getDefault().postEvent(encoded, nodePath);
}
public static DBSObject findDatabaseObject(DBGController controller, Object identifier, DBRProgressMonitor monitor) throws DBException {
DBPDataSourceContainer container = controller.getDataSourceContainer();
Map<String, Object> context = controller.getDebugConfiguration();
......
......@@ -90,7 +90,7 @@ public abstract class DatabaseLaunchShortcut implements ILaunchShortcut2 {
IEditorSite editorSite = editor.getEditorSite();
workbenchPartSite = editorSite;
ISelection selection = editorSite.getSelectionProvider().getSelection();
if (selection instanceof IStructuredSelection) {
if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
Object[] array = ((IStructuredSelection) selection).toArray();
searchAndLaunch(array, mode, getEditorEmptyMessage());
} else {
......@@ -176,7 +176,6 @@ public abstract class DatabaseLaunchShortcut implements ILaunchShortcut2 {
config = createConfiguration(launchable);
}
if (config != null) {
DebugCore.postDebuggerSourceEvent(config.getAttribute(DBGConstants.ATTR_NODE_PATH, (String) null));
DebugUITools.launch(config, mode);
}
}
......@@ -213,34 +212,30 @@ public abstract class DatabaseLaunchShortcut implements ILaunchShortcut2 {
return (DBSObject) dialog.getFirstResult();
}
protected List<ILaunchConfiguration> getCandidates(DBSObject launchable, ILaunchConfigurationType configType, Map<String, Object> databaseContext) {
List<ILaunchConfiguration> candidateConfigs = Collections.emptyList();
try {
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
ILaunchConfiguration[] configs = launchManager.getLaunchConfigurations(configType);
candidateConfigs = new ArrayList<>(configs.length);
for (ILaunchConfiguration config : configs) {
if (isCandidate(config, launchable, databaseContext)) {
candidateConfigs.add(config);
}
protected List<ILaunchConfiguration> getCandidates(DBSObject launchable, ILaunchConfigurationType configType, Map<String, Object> databaseContext) throws CoreException {
List<ILaunchConfiguration> candidateConfigs = new ArrayList<>();
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
ILaunchConfiguration[] configs = launchManager.getLaunchConfigurations(configType);
for (ILaunchConfiguration config : configs) {
if (isCandidate(config, launchable, databaseContext)) {
candidateConfigs.add(config);
}
} catch (CoreException e) {
log.log(e.getStatus());
}
return candidateConfigs;
}
protected boolean isCandidate(ILaunchConfiguration config, DBSObject launchable, Map<String, Object> databaseContext) {
protected boolean isCandidate(ILaunchConfiguration config, DBSObject launchable, Map<String, Object> databaseContext) throws CoreException {
if (!config.exists()) {
return false;
}
try {
String dsId = config.getAttribute(DBGConstants.ATTR_DATASOURCE_ID, (String) null);
return CommonUtils.equalObjects(dsId, launchable.getDataSource().getContainer().getId());
} catch (CoreException e) {
return false;
for (Map.Entry<String, Object> entry : databaseContext.entrySet()) {
if (!CommonUtils.equalObjects(config.getAttribute(entry.getKey(), (String) null), entry.getValue())) {
return false;
}
}
return true;
}
protected ILaunchConfiguration chooseConfiguration(List<ILaunchConfiguration> configList, String mode) {
......
......@@ -51,8 +51,6 @@ public class OpenDebugConfigurationHandler extends AbstractHandler implements IH
}
}
DebugLaunchDialogAction action = new DebugLaunchDialogAction();
action.run();
return null;
}
......
......@@ -35,12 +35,11 @@ public class DatabaseDebugLaunchShortcut extends DatabaseLaunchShortcut {
protected ILaunchConfiguration createConfiguration(DBSObject launchable) throws CoreException {
ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
ILaunchConfigurationType type = manager.getLaunchConfigurationType(CONFIG_TYPE);
ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null, "Database debug configuration");
return workingCopy;
return type.newInstance(null, "Database debug configuration");
}
@Override
protected boolean isCandidate(ILaunchConfiguration config, DBSObject launchable, Map<String, Object> databaseContext) {
protected boolean isCandidate(ILaunchConfiguration config, DBSObject launchable, Map<String, Object> databaseContext) throws CoreException {
return super.isCandidate(config, launchable, databaseContext);
}
......
......@@ -17,26 +17,15 @@
*/
package org.jkiss.dbeaver.ext.postgresql.debug.core;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.osgi.util.NLS;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.dbeaver.debug.DBGConstants;
import org.jkiss.dbeaver.debug.core.DebugCore;
import org.jkiss.dbeaver.ext.postgresql.debug.PostgreDebugConstants;
import org.jkiss.dbeaver.ext.postgresql.debug.internal.PostgreDebugCoreMessages;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreDataSource;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreProcedure;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.navigator.DBNDatabaseNode;
import org.jkiss.dbeaver.model.navigator.DBNModel;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.utils.CommonUtils;
import java.util.Map;
......@@ -45,35 +34,17 @@ public class PostgreSqlDebugCore {
public static final String BUNDLE_SYMBOLIC_NAME = "org.jkiss.dbeaver.ext.postgresql.debug.core"; //$NON-NLS-1$
public static final String CONFIGURATION_TYPE = BUNDLE_SYMBOLIC_NAME + '.' + "pgSQL";//$NON-NLS-1$
public static ILaunchConfigurationWorkingCopy createConfiguration(DBSObject launchable) throws CoreException {
boolean isInstance = launchable instanceof PostgreProcedure;
if (!isInstance) {
throw DebugCore.abort(PostgreDebugCoreMessages.PostgreSqlDebugCore_e_procedure_required);
}
PostgreProcedure procedure = (PostgreProcedure) launchable;
public static void saveFunction(PostgreProcedure procedure, Map<String, Object> configuration) {
PostgreDataSource dataSource = procedure.getDataSource();
DBPDataSourceContainer dataSourceContainer = dataSource.getContainer();
PostgreDatabase database = procedure.getDatabase();
PostgreSchema schema = procedure.getContainer();
String databaseName = database.getName();
String schemaName = schema.getName();
String procedureName = procedure.getName();
Object[] bindings = new Object[] { dataSourceContainer.getName(), databaseName, procedureName, schemaName };
String name = NLS.bind(PostgreDebugCoreMessages.PostgreSqlDebugCore_launch_configuration_name, bindings);
// Let's use metadata area for storage
IContainer container = null;
ILaunchConfigurationWorkingCopy workingCopy = DebugCore.createConfiguration(container, CONFIGURATION_TYPE,
name);
workingCopy.setAttribute(DBGConstants.ATTR_DATASOURCE_ID, dataSourceContainer.getId());
workingCopy.setAttribute(PostgreDebugConstants.ATTR_FUNCTION_OID, String.valueOf(procedure.getObjectId()));
String databaseName = procedure.getDatabase().getName();
String schemaName = procedure.getSchema().getName();
final DBNModel navigatorModel = DBeaverCore.getInstance().getNavigatorModel();
DBNDatabaseNode node = navigatorModel.getNodeByObject(new VoidProgressMonitor(), procedure, false);
workingCopy.setAttribute(DBGConstants.ATTR_NODE_PATH, node.getNodeItemPath());
return workingCopy;
configuration.put(DBGConstants.ATTR_DATASOURCE_ID, dataSourceContainer.getId());
configuration.put(PostgreDebugConstants.ATTR_DATABASE_NAME, databaseName);
configuration.put(PostgreDebugConstants.ATTR_SCHEMA_NAME, schemaName);
configuration.put(PostgreDebugConstants.ATTR_FUNCTION_OID, String.valueOf(procedure.getObjectId()));
}
public static PostgreProcedure resolveFunction(DBRProgressMonitor monitor, DBPDataSourceContainer dsContainer, Map<String, Object> configuration) throws DBException {
......
......@@ -46,9 +46,8 @@ public class PostgreDebugAdapterFactory implements IAdapterFactory {
} else if (adapterType == DBGResolver.class) {
if (adaptableObject instanceof DBPDataSourceContainer) {
DBPDataSourceContainer ds = (DBPDataSourceContainer) adaptableObject;
if (ds.getDataSource() instanceof PostgreDataSource) {
return adapterType.cast(
new PostgreResolver((PostgreDataSource) ds.getDataSource()));
if (ds.getDriver().getProviderId().equals("postgresql")) {
return adapterType.cast(new PostgreResolver(ds));
}
}
}
......
......@@ -19,9 +19,9 @@ package org.jkiss.dbeaver.ext.postgresql.debug.internal;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.debug.DBGResolver;
import org.jkiss.dbeaver.ext.postgresql.debug.PostgreDebugConstants;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreDataSource;
import org.jkiss.dbeaver.ext.postgresql.debug.core.PostgreSqlDebugCore;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreProcedure;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSObject;
......@@ -30,40 +30,23 @@ import java.util.Map;
public class PostgreResolver implements DBGResolver {
private final PostgreDataSource dataSource;
private final DBPDataSourceContainer dataSource;
public PostgreResolver(PostgreDataSource dataSource) {
public PostgreResolver(DBPDataSourceContainer dataSource) {
this.dataSource = dataSource;
}
@Override
public DBSObject resolveObject(Map<String, Object> context, Object identifier, DBRProgressMonitor monitor)
throws DBException {
Long oid = null;
final String errorIdentifier = String.format("Unknown procedure identifier %s", identifier);
if (identifier instanceof Number) {
Number number = (Number) identifier;
oid = number.longValue();
} else if (identifier instanceof String) {
String string = (String) identifier;
try {
oid = Long.parseLong(string);
} catch (NumberFormatException e) {
throw new DBException(errorIdentifier, e, dataSource);
}
}
if (oid == null) {
throw new DBException(errorIdentifier);
}
return dataSource.getDefaultInstance().getProcedure(monitor, oid);
return PostgreSqlDebugCore.resolveFunction(monitor, dataSource, context);
}
@Override
public Map<String, Object> resolveContext(DBSObject databaseObject) {
HashMap<String, Object> context = new HashMap<String, Object>();
if (databaseObject instanceof PostgreProcedure) {
PostgreProcedure procedure = (PostgreProcedure) databaseObject;
context.put(PostgreDebugConstants.ATTR_FUNCTION_OID, procedure.getObjectId());
PostgreSqlDebugCore.saveFunction((PostgreProcedure)databaseObject, context);
}
return context;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册