From e45e177265566fcbbb2d36aa3516e4f398cd9626 Mon Sep 17 00:00:00 2001 From: Keith Chong Date: Wed, 4 Mar 2020 11:29:08 -0500 Subject: [PATCH] Use Java Remote Debug (attach) --- .../internal/CodewindEclipseApplication.java | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/dev/org.eclipse.codewind.core/src/org/eclipse/codewind/core/internal/CodewindEclipseApplication.java b/dev/org.eclipse.codewind.core/src/org/eclipse/codewind/core/internal/CodewindEclipseApplication.java index acd16fbde..3fd79f629 100644 --- a/dev/org.eclipse.codewind.core/src/org/eclipse/codewind/core/internal/CodewindEclipseApplication.java +++ b/dev/org.eclipse.codewind.core/src/org/eclipse/codewind/core/internal/CodewindEclipseApplication.java @@ -12,7 +12,9 @@ package org.eclipse.codewind.core.internal; import java.net.MalformedURLException; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Set; import org.eclipse.codewind.core.CodewindCorePlugin; @@ -44,6 +46,7 @@ import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.debug.core.ILaunchManager; import org.eclipse.debug.core.model.IDebugTarget; +import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; import org.eclipse.osgi.util.NLS; import org.eclipse.ui.console.ConsolePlugin; import org.eclipse.ui.console.IConsole; @@ -144,19 +147,35 @@ public void connectDebugger() { } return; } + final CodewindEclipseApplication app = this; Job job = new Job(Messages.ConnectDebugJob) { @Override protected IStatus run(IProgressMonitor monitor) { try { if (app.projectLanguage.isJava()) { - ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); - ILaunchConfigurationType launchConfigurationType = launchManager.getLaunchConfigurationType(CodewindLaunchConfigDelegate.LAUNCH_CONFIG_ID); - ILaunchConfigurationWorkingCopy workingCopy = launchConfigurationType.newInstance((IContainer) null, app.name); - CodewindLaunchConfigDelegate.setConfigAttributes(workingCopy, app); - ILaunchConfiguration launchConfig = workingCopy.doSave(); - ILaunch launch = launchConfig.launch(ILaunchManager.DEBUG_MODE, monitor); +// ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); +// ILaunchConfigurationType launchConfigurationType = launchManager.getLaunchConfigurationType(CodewindLaunchConfigDelegate.LAUNCH_CONFIG_ID); +// ILaunchConfigurationWorkingCopy workingCopy = launchConfigurationType.newInstance((IContainer) null, app.name); +// CodewindLaunchConfigDelegate.setConfigAttributes(workingCopy, app); +// ILaunchConfiguration launchConfig = workingCopy.doSave(); +// ILaunch launch = launchConfig.launch(ILaunchManager.DEBUG_MODE, monitor); +// app.setLaunch(launch); + + // Get rid of codewind delegate + ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager(); + ILaunchConfigurationType type = manager.getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_REMOTE_JAVA_APPLICATION); + final ILaunchConfigurationWorkingCopy debugConfiguration = type.newInstance(null, "NewDebug-" + app.name); + debugConfiguration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, app.name); + Map connectMapAttrs = new HashMap(); + connectMapAttrs.put("hostname", app.host); + connectMapAttrs.put("port", String.valueOf(app.getDebugPort())); + debugConfiguration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CONNECT_MAP, connectMapAttrs); + debugConfiguration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_CONNECTOR, "org.eclipse.jdt.launching.socketAttachConnector"); + ILaunchConfiguration launchConfig = debugConfiguration.doSave(); + ILaunch launch = launchConfig.launch(ILaunchManager.DEBUG_MODE, monitor); app.setLaunch(launch); + return Status.OK_STATUS; } else { IDebugLauncher launcher = CodewindCorePlugin.getDebugLauncher(app.projectLanguage.getId());