diff --git a/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/StandardLocalJBossStartLaunchDelegate.java b/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/StandardLocalJBossStartLaunchDelegate.java index 8e6e0875a4..c98b5a1e94 100644 --- a/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/StandardLocalJBossStartLaunchDelegate.java +++ b/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/StandardLocalJBossStartLaunchDelegate.java @@ -21,10 +21,8 @@ import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.model.IBreakpoint; -import org.eclipse.debug.internal.core.BreakpointManager; import org.eclipse.jdt.debug.core.IJavaDebugTarget; import org.eclipse.jdt.debug.core.IJavaHotCodeReplaceListener; -import org.eclipse.jdt.debug.core.JDIDebugModel; import org.eclipse.jdt.launching.IVMInstall; import org.eclipse.osgi.util.NLS; import org.eclipse.wst.server.core.IModule; diff --git a/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/RSEJBoss7LaunchConfigurator.java b/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/RSEJBoss7LaunchConfigurator.java index 224f2f62d7..9d039b00dd 100644 --- a/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/RSEJBoss7LaunchConfigurator.java +++ b/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/RSEJBoss7LaunchConfigurator.java @@ -29,6 +29,7 @@ import org.jboss.ide.eclipse.as.core.util.IJBossRuntimeResourceConstants; import org.jboss.ide.eclipse.as.core.util.LaunchCommandPreferences; import org.jboss.ide.eclipse.as.core.util.ServerConverter; +import org.jboss.ide.eclipse.as.wtp.core.debug.RemoteDebugUtils; import org.jboss.ide.eclipse.as.wtp.core.util.ServerTCPIPMonitorUtil; /** @@ -173,12 +174,12 @@ protected String getLaunchDebugCommand(JBossServer jbossServer) throws CoreExcep } protected boolean attachDebugger() { - Boolean b = jbossServer.getServer().getAttribute(RSEJbossLaunchConstants.ATTACH_DEBUGGER, true); + Boolean b = jbossServer.getServer().getAttribute(RemoteDebugUtils.ATTACH_DEBUGGER, true); return b; } protected String getDebugPort() { - String dbugPort = jbossServer.getServer().getAttribute(RSEJbossLaunchConstants.DEBUG_PORT, new Integer(RSEJbossLaunchConstants.DEFAULT_DEBUG_PORT).toString()); + String dbugPort = jbossServer.getServer().getAttribute(RemoteDebugUtils.DEBUG_PORT, new Integer(RemoteDebugUtils.DEFAULT_DEBUG_PORT).toString()); return dbugPort; } diff --git a/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/StandardRSEJBossStartLaunchDelegate.java b/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/StandardRSEJBossStartLaunchDelegate.java index 8931e32da1..afb9dc8385 100644 --- a/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/StandardRSEJBossStartLaunchDelegate.java +++ b/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/StandardRSEJBossStartLaunchDelegate.java @@ -17,11 +17,8 @@ import org.eclipse.core.runtime.Status; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; -import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; -import org.eclipse.rse.core.subsystems.IServerLauncher; import org.eclipse.wst.server.core.IServer; import org.eclipse.wst.server.core.IServerListener; -import org.eclipse.wst.server.core.ServerEvent; import org.eclipse.wst.server.core.ServerUtil; import org.jboss.ide.eclipse.as.core.server.IServerStatePoller; import org.jboss.ide.eclipse.as.core.util.JBossServerBehaviorUtils; @@ -30,7 +27,6 @@ import org.jboss.ide.eclipse.as.wtp.core.debug.RemoteDebugUtils; import org.jboss.ide.eclipse.as.wtp.core.server.behavior.ControllableServerBehavior; import org.jboss.ide.eclipse.as.wtp.core.server.behavior.IControllableServerBehavior; -import org.jboss.tools.foundation.core.plugin.log.StatusFactory; /** * This is a launch configuration delegate for use with rse jboss servers. @@ -59,7 +55,7 @@ protected void actualLaunch(ILaunchConfiguration configuration, RSELaunchConfigProperties propertyUtil = new RSELaunchConfigProperties(); boolean detectStartupCommand = propertyUtil.isDetectStartupCommand(configuration, true); IServer server = ServerUtil.getServer(configuration); - boolean attachDebugger = server.getAttribute(RSEJbossLaunchConstants.ATTACH_DEBUGGER, true); + boolean attachDebugger = server.getAttribute(RemoteDebugUtils.ATTACH_DEBUGGER, true); if("debug".equals(mode) && detectStartupCommand && attachDebugger) { // Only manipulate the args and attach debugger if they're @@ -104,8 +100,9 @@ protected void afterVMRunner(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException { // Initiate Polling! IServer s = ServerUtil.getServer(configuration); - if( "debug".equals(mode)) { - // add a listener which will run the + boolean attachDebugger = s.getAttribute(RemoteDebugUtils.ATTACH_DEBUGGER, true); + if( "debug".equals(mode) && attachDebugger) { + // add a listener which will run the debugger once server is started IServerListener listener = createAttachDebuggerListener(); s.addServerListener(listener); } @@ -113,48 +110,9 @@ protected void afterVMRunner(ILaunchConfiguration configuration, String mode, } private IServerListener createAttachDebuggerListener() { - return new IServerListener() { - boolean serverSwitchesToState(ServerEvent event, int state) { - int eventKind = event.getKind(); - if ((eventKind & ServerEvent.SERVER_CHANGE) != 0) { - // server change event - if ((eventKind & ServerEvent.STATE_CHANGE) != 0) { - if( event.getServer().getServerState() == state ) { - return true; - } - } - } - return false; - } - public void serverChanged(ServerEvent event) { - if( serverSwitchesToState(event, IServer.STATE_STARTED)) { - event.getServer().removeServerListener(this); - IServer s = event.getServer(); - int debugPort = getDebugPort(s); - try { - attachRemoteDebugger(event.getServer(), debugPort, new NullProgressMonitor()); - } catch(CoreException ce) { - RSECorePlugin.pluginLog().logError(ce); - } - } else if( serverSwitchesToState(event, IServer.STATE_STOPPED)) { - event.getServer().removeServerListener(this); - } - } - }; + return RemoteDebugUtils.get().createAttachDebuggerListener(); } - protected int getDebugPort(IServer server) { - String debugPort = server.getAttribute(RSEJbossLaunchConstants.DEBUG_PORT, Integer.toString(RSEJbossLaunchConstants.DEFAULT_DEBUG_PORT)); - int port = -1; - try { - port = Integer.parseInt(debugPort); - } catch(NumberFormatException nfe) { - port = RSEJbossLaunchConstants.DEFAULT_DEBUG_PORT; - } - if( port < 1 ) - port = RSEJbossLaunchConstants.DEFAULT_DEBUG_PORT; - return port; - } /* * Synchronous check to see if server is currently up. @@ -181,48 +139,6 @@ protected boolean setServerAlreadyStarted(ILaunchConfiguration configuration, St protected void connectDebugger(ILaunchConfiguration configuration, String mode, IControllableServerBehavior beh) throws CoreException { - attachRemoteDebugger(beh.getServer(), getDebugPort(beh.getServer()), new NullProgressMonitor()); - } - - - private ILaunch attachRemoteDebugger(IServer server, int localDebugPort, IProgressMonitor monitor) - throws CoreException { - monitor.subTask("Attaching remote debugger"); - ILaunch ret = null; - RemoteDebugUtils debugUtils = RemoteDebugUtils.get(); - ILaunchConfiguration debuggerLaunchConfig = debugUtils.getRemoteDebuggerLaunchConfiguration(server); - ILaunchConfigurationWorkingCopy workingCopy; - if (debuggerLaunchConfig == null) { - workingCopy = debugUtils.createRemoteDebuggerLaunchConfiguration(server); - } else { - if (debugUtils.isRunning(debuggerLaunchConfig, localDebugPort)) { - return null; - } - workingCopy = debuggerLaunchConfig.getWorkingCopy(); - } - - debugUtils.setupRemoteDebuggerLaunchConfiguration(workingCopy, null, localDebugPort); - debuggerLaunchConfig = workingCopy.doSave(); - boolean launched = false; - try { - ret = debuggerLaunchConfig.launch("debug", new NullProgressMonitor()); - launched = true; - } catch (Exception e) { - e.printStackTrace(); - } - - if (!launched){ - throw toCoreException("Unable to start a remote debugger to localhost:"+localDebugPort); - } - - monitor.worked(10); - return ret; - } - private CoreException toCoreException(String msg, Exception e) { - return new CoreException(StatusFactory.errorStatus(RSECorePlugin.PLUGIN_ID, msg, e)); - } - - private CoreException toCoreException(String msg) { - return toCoreException(msg, null); + RemoteDebugUtils.get().attachRemoteDebugger(beh.getServer(), new NullProgressMonitor()); } } diff --git a/as/plugins/org.jboss.ide.eclipse.as.rse.ui/plugin.xml b/as/plugins/org.jboss.ide.eclipse.as.rse.ui/plugin.xml index 3b5c2f057b..6a05566d66 100644 --- a/as/plugins/org.jboss.ide.eclipse.as.rse.ui/plugin.xml +++ b/as/plugins/org.jboss.ide.eclipse.as.rse.ui/plugin.xml @@ -94,16 +94,7 @@ - - -
-
-
- + " + Messages.Configure + ""); //$NON-NLS-1$ //$NON-NLS-2$ + } + + @Override + protected void initialize() { + boolean shouldDetect = helper.getAttribute(detectXPathKey, true); + detect.setSelection(shouldDetect); + detect.setEnabled(defaultXPath != null); + link.setEnabled(shouldDetect); + text.setEnabled(!shouldDetect); + text.setEditable(!shouldDetect); + currentXPath = helper.getAttribute(currentXPathKey, defaultXPath); + if( shouldDetect ) { + text.setText(PortSection.findPortWithDefault(helper.getServer(), new Path(currentXPath), defaultValue, discoverOffset())); + } else + text.setText(helper.getAttribute(overrideValueKey, "")); //$NON-NLS-1$ + } + + @Override + protected void addListeners() { + super.addListeners(); + detect.addListener(SWT.Selection, listener); + link.addListener(SWT.Selection, createLinkListener()); + } + + protected Listener createLinkListener() { + return new Listener() { + public void handleEvent(Event event) { + ChangePortDialog dialog = getDialog(); + int result = dialog.open(); + if( result == Dialog.OK) { + currentXPath = dialog.getSelection(); + section.execute(getCommand()); + } + if( dialog.isModified() ) { + initialize(); + validate(); + } + text.setFocus(); + } + }; + } + public ChangePortDialog getDialog() { + return new ChangePortDialog(section.getShell(), getDialogInfo()); + } + + @Override + public ServerCommand getCommand() { + return new SetPortXPathCommand(helper.getWorkingCopy(), helper, changeValueCommandName, + overrideValueKey, detectXPathKey,currentXPathKey, defaultXPath, this); + } + protected ChangePortDialogInfo getDialogInfo() { + ChangePortDialogInfo info = new ChangePortDialogInfo(); + info.port = labelText; + info.defaultValue = defaultXPath; + info.server = helper.getWorkingCopy().getOriginal(); + info.currentXPath = currentXPath; + return info; + } + + @Override + public void validate() { + decoration.hide(); + String v = null; + String errorText; + if( detect.getSelection()) { + v = PortSection.findPort(helper.getServer(), new Path(defaultXPath)); + errorText = "This port cannot be automatically located. A default value is being displayed"; + } else { + v = text.getText(); + errorText = "The empty string is not a valid port."; + } + if( "".equals(v)) { + decoration.setDescriptionText(errorText); + decoration.show(); + } + } +} \ No newline at end of file diff --git a/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/PortSection.java b/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/ports/PortSection.java similarity index 54% rename from as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/PortSection.java rename to as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/ports/PortSection.java index c9ebd6cfa4..3ce12e4f9d 100644 --- a/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/PortSection.java +++ b/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/ports/PortSection.java @@ -8,7 +8,7 @@ * Contributors: * Red Hat, Inc. - initial API and implementation ******************************************************************************/ -package org.jboss.ide.eclipse.as.ui.editor; +package org.jboss.ide.eclipse.as.ui.editor.ports; import java.util.ArrayList; import java.util.Collections; @@ -19,46 +19,30 @@ import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.fieldassist.ControlDecoration; -import org.eclipse.jface.fieldassist.FieldDecoration; -import org.eclipse.jface.fieldassist.FieldDecorationRegistry; -import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.swt.SWT; -import org.eclipse.swt.events.VerifyEvent; -import org.eclipse.swt.events.VerifyListener; import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.layout.FormData; import org.eclipse.swt.layout.FormLayout; import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Link; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorSite; import org.eclipse.ui.forms.widgets.ExpandableComposite; import org.eclipse.ui.forms.widgets.FormToolkit; import org.eclipse.ui.forms.widgets.Section; import org.eclipse.wst.server.core.IServer; -import org.eclipse.wst.server.core.IServerWorkingCopy; import org.eclipse.wst.server.ui.editor.ServerEditorSection; -import org.eclipse.wst.server.ui.internal.command.ServerCommand; import org.jboss.ide.eclipse.as.core.extensions.descriptors.XPathCategory; import org.jboss.ide.eclipse.as.core.extensions.descriptors.XPathModel; import org.jboss.ide.eclipse.as.core.extensions.descriptors.XPathQuery; import org.jboss.ide.eclipse.as.core.util.ServerAttributeHelper; import org.jboss.ide.eclipse.as.ui.JBossServerUIPlugin; import org.jboss.ide.eclipse.as.ui.Messages; -import org.jboss.ide.eclipse.as.ui.dialogs.ChangePortDialog; -import org.jboss.ide.eclipse.as.ui.dialogs.ChangePortDialog.ChangePortDialogInfo; import org.jboss.tools.as.core.server.controllable.subsystems.internal.XPathsPortsController; import org.jboss.tools.foundation.core.expressions.ExpressionResolver; @@ -161,19 +145,7 @@ public void createSection(Composite parent) { } - public static interface IPortOffsetProvider { - public int getOffset(); - } - - public static interface IPortEditorExtension { - public void setServerAttributeHelper(ServerAttributeHelper helper); - public void setSection(PortSection section); - public void createControl(Composite parent); - public String getValue(); - public void refresh(); - } - - public static class JNDIPortEditorExtension extends PortEditorExtension { + public static class JNDIPortEditorExtension extends PortEditorXPathExtension { public JNDIPortEditorExtension() { super(Messages.EditorJNDIPort, XPathsPortsController.JNDI_PORT_DETECT_XPATH, @@ -185,7 +157,7 @@ public JNDIPortEditorExtension() { } } - public static class WebPortEditorExtension extends PortEditorExtension { + public static class WebPortEditorExtension extends PortEditorXPathExtension { public WebPortEditorExtension() { super(Messages.EditorWebPort, XPathsPortsController.WEB_PORT_DETECT_XPATH, @@ -197,7 +169,17 @@ public WebPortEditorExtension() { } } - public static class JBoss6JMXRMIPortEditorExtension extends PortEditorExtension { + public static class WebPortSettingEditorExtension extends PortEditorExtension { + public WebPortSettingEditorExtension() { + super(Messages.EditorWebPort, + XPathsPortsController.WEB_PORT, + XPathsPortsController.JBOSS_WEB_DEFAULT_PORT, + Messages.EditorChangeWebCommandName); + } + } + + + public static class JBoss6JMXRMIPortEditorExtension extends PortEditorXPathExtension { public JBoss6JMXRMIPortEditorExtension() { super(Messages.EditorJMXRMIPort, XPathsPortsController.JMX_RMI_PORT_DETECT_XPATH, @@ -210,7 +192,7 @@ public JBoss6JMXRMIPortEditorExtension() { } - public static class JBoss7ManagementPortEditorExtension extends PortEditorExtension { + public static class JBoss7ManagementPortEditorExtension extends PortEditorXPathExtension { public JBoss7ManagementPortEditorExtension() { super(Messages.EditorAS7ManagementPort, XPathsPortsController.AS7_MANAGEMENT_PORT_DETECT_XPATH, @@ -221,7 +203,7 @@ public JBoss7ManagementPortEditorExtension() { Messages.EditorChangeAS7ManagementCommandName); } } - public static class JBoss7PortOffsetEditorExtension extends PortEditorExtension implements IPortOffsetProvider { + public static class JBoss7PortOffsetEditorExtension extends PortEditorXPathExtension implements IPortOffsetProvider { public JBoss7PortOffsetEditorExtension() { super(Messages.EditorAS7PortOffset, XPathsPortsController.PORT_OFFSET_DETECT_XPATH, @@ -249,165 +231,6 @@ protected int discoverOffset() { } - public static abstract class PortEditorExtension implements IPortEditorExtension { - protected Button detect; - protected Text text; - protected Label label; - protected Link link; - protected String labelText, currentXPathKey, detectXPathKey, overrideValueKey, defaultXPath; - protected String currentXPath, changeValueCommandName; - protected ServerAttributeHelper helper; - protected Listener listener; - protected PortSection section; - protected int defaultValue; - private ControlDecoration decoration; - - public PortEditorExtension(String labelText, String currentXPathKey, - String detectXPathKey, String overrideValueKey, String defaultXPath, - int defaultValue, - String changeValueCommandName) { - this.labelText = labelText; - this.currentXPathKey = currentXPathKey; - this.detectXPathKey = detectXPathKey; - this.overrideValueKey = overrideValueKey; - this.defaultXPath = defaultXPath; - this.changeValueCommandName = changeValueCommandName; - this.defaultValue = defaultValue; - } - public void setServerAttributeHelper(ServerAttributeHelper helper) { - this.helper = helper; - } - public void setSection(PortSection section) { - this.section = section; - } - public void createControl(Composite parent) { - createUI(parent); - initialize(); - addListeners(); - - decoration = new ControlDecoration(text, - SWT.LEFT | SWT.TOP); - FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault() - .getFieldDecoration(FieldDecorationRegistry.DEC_WARNING); - decoration.setImage(fieldDecoration.getImage()); - validate(); - } - - protected void createUI(Composite parent) { - label = new Label(parent, SWT.NONE); - text = new Text(parent, SWT.SINGLE | SWT.BORDER); - detect = new Button(parent, SWT.CHECK); - link = new Link(parent, SWT.NONE); - - GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(label); - GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).minSize(80, 10).grab(true, false).applyTo(text); - GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(detect); - GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(link); - - label.setText(labelText); - detect.setText(Messages.EditorAutomaticallyDetectPort); - link.setText("" + Messages.Configure + ""); //$NON-NLS-1$ //$NON-NLS-2$ - - text.addVerifyListener(new VerifyListener() { - public void verifyText(VerifyEvent e) { - if( e.text == null || e.text.equals("")) - return; - try { - Integer i = Integer.parseInt(e.text); - } catch( NumberFormatException nfe ) { - e.doit = false; - } - } - }); - - - } - protected void initialize() { - boolean shouldDetect = helper.getAttribute(detectXPathKey, true); - detect.setSelection(shouldDetect); - detect.setEnabled(defaultXPath != null); - link.setEnabled(shouldDetect); - text.setEnabled(!shouldDetect); - text.setEditable(!shouldDetect); - currentXPath = helper.getAttribute(currentXPathKey, defaultXPath); - if( shouldDetect ) { - text.setText(findPortWithDefault(helper.getServer(), new Path(currentXPath), defaultValue, discoverOffset())); - } else - text.setText(helper.getAttribute(overrideValueKey, "")); //$NON-NLS-1$ - } - protected int discoverOffset() { - return section.getPortOffset(); - } - public void refresh() { - initialize(); - } - protected void addListeners() { - listener = new Listener() { - public void handleEvent(Event event) { - listenerEvent(event); - } - }; - text.addListener(SWT.Modify, listener); - detect.addListener(SWT.Selection, listener); - link.addListener(SWT.Selection, createLinkListener()); - } - protected void listenerEvent(Event event) { - section.execute(getCommand()); - } - - protected Listener createLinkListener() { - return new Listener() { - public void handleEvent(Event event) { - ChangePortDialog dialog = getDialog(); - int result = dialog.open(); - if( result == Dialog.OK) { - currentXPath = dialog.getSelection(); - section.execute(getCommand()); - } - if( dialog.isModified() ) { - initialize(); - validate(); - } - text.setFocus(); - } - }; - } - public ChangePortDialog getDialog() { - return new ChangePortDialog(section.getShell(), getDialogInfo()); - } - public ServerCommand getCommand() { - return new SetPortCommand(helper.getWorkingCopy(), helper, changeValueCommandName, - overrideValueKey, detectXPathKey,currentXPathKey, defaultXPath, this); - } - protected ChangePortDialogInfo getDialogInfo() { - ChangePortDialogInfo info = new ChangePortDialogInfo(); - info.port = labelText; - info.defaultValue = defaultXPath; - info.server = helper.getWorkingCopy().getOriginal(); - info.currentXPath = currentXPath; - return info; - } - public String getValue() { - return text.getText(); - } - public void validate() { - decoration.hide(); - String v = null; - String errorText; - if( detect.getSelection()) { - v = findPort(helper.getServer(), new Path(defaultXPath)); - errorText = "This port cannot be automatically located. A default value is being displayed"; - } else { - v = text.getText(); - errorText = "The empty string is not a valid port."; - } - if( "".equals(v)) { - decoration.setDescriptionText(errorText); - decoration.show(); - } - } - } - protected void createUI(Composite parent) { FormToolkit toolkit = new FormToolkit(parent.getDisplay()); Section section = toolkit.createSection(parent, ExpandableComposite.TWISTIE|ExpandableComposite.EXPANDED|ExpandableComposite.TITLE_BAR); @@ -459,84 +282,6 @@ protected String[] getXPathStrings() { return (String[]) list.toArray(new String[list.size()]); } - public static class SetPortCommand extends ServerCommand { - ServerAttributeHelper helper; - String textAttribute, overrideAttribute, overridePathAttribute; - String preText, prePath, defaultPath; - boolean preOverride; - Text text; - Button button; - Listener listener; - String xpath; - Link link; - PortSection pSection; - int defVal; - PortEditorExtension ext; - public SetPortCommand(IServerWorkingCopy server, ServerAttributeHelper helper, String name, - String textAttribute, String overrideAttribute, String overridePathAttribute, - String pathDefault, PortEditorExtension ext) { //Text text, Button button, String xpath, Listener listener) { - super(server, name); - this.helper = helper; - this.textAttribute = textAttribute; - this.overrideAttribute = overrideAttribute; - this.overridePathAttribute = overridePathAttribute; - this.defaultPath = pathDefault; - this.text = ext.text; - this.button = ext.detect; - this.listener = ext.listener; - this.xpath = ext.currentXPath; - this.link = ext.link; - this.pSection = ext.section; - this.defVal = ext.defaultValue; - this.ext = ext; - } - - public void execute() { - preText = helper.getAttribute(textAttribute, (String)null); - if( preText == null ) - preText = text.getText(); - prePath = helper.getAttribute(overridePathAttribute, (String)defaultPath); - preOverride = helper.getAttribute(overrideAttribute, true); - helper.setAttribute(textAttribute, text.getText()); - helper.setAttribute(overrideAttribute, button.getSelection()); - link.setEnabled(button.getSelection()); - helper.setAttribute(overridePathAttribute, xpath); - - text.setEnabled(!button.getSelection()); - text.setEditable(!button.getSelection()); - if( button.getSelection() ) { - text.removeListener(SWT.Modify, listener); - text.setText(findPortWithDefault(helper.getServer(), new Path(xpath), this.defVal, ext.discoverOffset())); - text.addListener(SWT.Modify, listener); - } - validate(); - } - - public void undo() { - // set new values - helper.setAttribute(textAttribute, preText); - helper.setAttribute(overrideAttribute, preOverride); - link.setEnabled(preOverride); - helper.setAttribute(overridePathAttribute, prePath); - - // update ui - text.removeListener(SWT.Modify, listener); - button.removeListener(SWT.Selection, listener); - - button.setSelection(preOverride); - text.setText(preText == null ? "" : preText); //$NON-NLS-1$ - text.setEnabled(!preOverride); - text.setEditable(!preOverride); - button.addListener(SWT.Selection, listener); - text.addListener(SWT.Modify, listener); - validate(); - } - - private void validate() { - ext.validate(); - } - } - protected static String findPortWithDefault(IServer server, IPath path, int defaultValue) { return findPortWithDefault(server, path, defaultValue, 0); } diff --git a/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/ports/SetPortCommand.java b/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/ports/SetPortCommand.java new file mode 100644 index 0000000000..4e829bb11d --- /dev/null +++ b/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/ports/SetPortCommand.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2016 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is 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: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.ide.eclipse.as.ui.editor.ports; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Text; +import org.eclipse.wst.server.core.IServerWorkingCopy; +import org.eclipse.wst.server.ui.internal.command.ServerCommand; +import org.jboss.ide.eclipse.as.core.util.ServerAttributeHelper; + +public class SetPortCommand extends ServerCommand { + ServerAttributeHelper helper; + String textAttribute; + String preText, prePath; + Text text; + Listener listener; + PortSection pSection; + int defVal; + PortEditorExtension ext; + + public SetPortCommand(IServerWorkingCopy server, ServerAttributeHelper helper, String name, + String textAttribute, PortEditorExtension ext) { + super(server, name); + this.helper = helper; + this.textAttribute = textAttribute; + this.text = ext.text; + this.listener = ext.listener; + this.pSection = ext.section; + this.defVal = ext.defaultValue; + this.ext = ext; + } + + public void execute() { + preText = helper.getAttribute(textAttribute, (String)null); + if( preText == null ) + preText = text.getText(); + helper.setAttribute(textAttribute, text.getText()); + validate(); + } + + public void undo() { + // set new values + helper.setAttribute(textAttribute, preText); + + // update ui + text.removeListener(SWT.Modify, listener); + text.setText(preText == null ? "" : preText); //$NON-NLS-1$ + text.addListener(SWT.Modify, listener); + validate(); + } + + private void validate() { + ext.validate(); + } +} \ No newline at end of file diff --git a/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/ports/SetPortXPathCommand.java b/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/ports/SetPortXPathCommand.java new file mode 100644 index 0000000000..990e9cf810 --- /dev/null +++ b/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/ports/SetPortXPathCommand.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2016 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is 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: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.ide.eclipse.as.ui.editor.ports; + +import org.eclipse.core.runtime.Path; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Link; +import org.eclipse.wst.server.core.IServerWorkingCopy; +import org.jboss.ide.eclipse.as.core.util.ServerAttributeHelper; + +public class SetPortXPathCommand extends SetPortCommand { + String overrideAttribute, overridePathAttribute; + String defaultPath; + boolean preOverride; + Button button; + String xpath; + Link link; + public SetPortXPathCommand(IServerWorkingCopy server, ServerAttributeHelper helper, String name, + String textAttribute, String overrideAttribute, String overridePathAttribute, + String pathDefault, PortEditorXPathExtension ext) { //Text text, Button button, String xpath, Listener listener) { + super(server, helper, name, textAttribute, ext); + this.overrideAttribute = overrideAttribute; + this.overridePathAttribute = overridePathAttribute; + this.defaultPath = pathDefault; + this.button = ext.detect; + this.xpath = ext.currentXPath; + this.link = ext.link; + } + + public void execute() { + preText = helper.getAttribute(textAttribute, (String)null); + if( preText == null ) + preText = text.getText(); + prePath = helper.getAttribute(overridePathAttribute, (String)defaultPath); + preOverride = helper.getAttribute(overrideAttribute, true); + helper.setAttribute(textAttribute, text.getText()); + helper.setAttribute(overrideAttribute, button.getSelection()); + link.setEnabled(button.getSelection()); + helper.setAttribute(overridePathAttribute, xpath); + + text.setEnabled(!button.getSelection()); + text.setEditable(!button.getSelection()); + if( button.getSelection() ) { + text.removeListener(SWT.Modify, listener); + text.setText(PortSection.findPortWithDefault(helper.getServer(), new Path(xpath), this.defVal, ext.discoverOffset())); + text.addListener(SWT.Modify, listener); + } + validate(); + } + + public void undo() { + // set new values + helper.setAttribute(textAttribute, preText); + helper.setAttribute(overrideAttribute, preOverride); + link.setEnabled(preOverride); + helper.setAttribute(overridePathAttribute, prePath); + + // update ui + text.removeListener(SWT.Modify, listener); + button.removeListener(SWT.Selection, listener); + + button.setSelection(preOverride); + text.setText(preText == null ? "" : preText); //$NON-NLS-1$ + text.setEnabled(!preOverride); + text.setEditable(!preOverride); + button.addListener(SWT.Selection, listener); + text.addListener(SWT.Modify, listener); + validate(); + } + + private void validate() { + ext.validate(); + } +} \ No newline at end of file diff --git a/as/plugins/org.jboss.ide.eclipse.as.ui/plugin.xml b/as/plugins/org.jboss.ide.eclipse.as.ui/plugin.xml index 07b6b00044..0f2fd3b807 100755 --- a/as/plugins/org.jboss.ide.eclipse.as.ui/plugin.xml +++ b/as/plugins/org.jboss.ide.eclipse.as.ui/plugin.xml @@ -183,11 +183,11 @@ order="10" typeIds="%AllJBossServerTypes"/>
+ typeIds="%AllJBTServerTypes"/>
+ +
+
+ + +
+ +
+
diff --git a/as/plugins/org.jboss.ide.eclipse.as.wtp.core/src/org/jboss/ide/eclipse/as/wtp/core/debug/RemoteDebugUtils.java b/as/plugins/org.jboss.ide.eclipse.as.wtp.core/src/org/jboss/ide/eclipse/as/wtp/core/debug/RemoteDebugUtils.java index 5304d79af1..0517f514c0 100644 --- a/as/plugins/org.jboss.ide.eclipse.as.wtp.core/src/org/jboss/ide/eclipse/as/wtp/core/debug/RemoteDebugUtils.java +++ b/as/plugins/org.jboss.ide.eclipse.as.wtp.core/src/org/jboss/ide/eclipse/as/wtp/core/debug/RemoteDebugUtils.java @@ -23,8 +23,10 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunch; @@ -34,9 +36,17 @@ import org.eclipse.debug.core.ILaunchManager; import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; import org.eclipse.wst.server.core.IServer; +import org.eclipse.wst.server.core.IServerListener; +import org.eclipse.wst.server.core.ServerEvent; +import org.jboss.ide.eclipse.as.core.server.UnitedServerListener; import org.jboss.ide.eclipse.as.wtp.core.ASWTPToolsPlugin; +import org.jboss.tools.foundation.core.plugin.log.StatusFactory; public class RemoteDebugUtils { + public static final String ATTACH_DEBUGGER = "org.jboss.ide.eclipse.as.core.server.launch.DebugLaunchConstants.ATTACH_DEBUGGER"; //$NON-NLS-1$ + public static final String DEBUG_PORT = "org.jboss.ide.eclipse.as.core.server.launch.DebugLaunchConstants.DEBUG_PORT"; //$NON-NLS-1$ + public static final int DEFAULT_DEBUG_PORT = 8787; + private ILaunchManager launchManager; public static RemoteDebugUtils get() { return get(DebugPlugin.getDefault().getLaunchManager()); @@ -70,13 +80,13 @@ public ILaunchConfigurationWorkingCopy createRemoteDebuggerLaunchConfiguration(I return workingCopy; } - public void setupRemoteDebuggerLaunchConfiguration(ILaunchConfigurationWorkingCopy workingCopy, IProject project, int debugPort) throws CoreException { + public void setupRemoteDebuggerLaunchConfiguration(ILaunchConfigurationWorkingCopy workingCopy, IProject project, int debugPort, String host) throws CoreException { String portString = String.valueOf(debugPort); workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_ALLOW_TERMINATE, false); workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_CONNECTOR, IJavaLaunchConfigurationConstants.ID_SOCKET_ATTACH_VM_CONNECTOR); Map connectMap = new HashMap<>(2); connectMap.put("port", portString); //$NON-NLS-1$ - connectMap.put("hostname", "localhost"); //$NON-NLS-1$ //$NON-NLS-2$ + connectMap.put("hostname", host); //$NON-NLS-1$ //$NON-NLS-2$ workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CONNECT_MAP, connectMap); if(project != null) { workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, project.getName()); @@ -127,4 +137,84 @@ private void terminate(ILaunch launch, Collection errors) { private Stream getLaunches() { return Stream.of(launchManager.getLaunches()); } + + + public IServerListener createAttachDebuggerListener() { + return new IServerListener() { + public void serverChanged(ServerEvent event) { + if( UnitedServerListener.serverSwitchesToState(event, IServer.STATE_STARTED)) { + event.getServer().removeServerListener(this); + IServer s = event.getServer(); + int debugPort = getDebugPort(s); + try { + attachRemoteDebugger(event.getServer(), debugPort, new NullProgressMonitor()); + } catch(CoreException ce) { + ASWTPToolsPlugin.pluginLog().logError(ce); + } + } else if( UnitedServerListener.serverSwitchesToState(event, IServer.STATE_STOPPED)) { + event.getServer().removeServerListener(this); + } + } + }; + } + + protected int getDebugPort(IServer server) { + String debugPort = server.getAttribute(DEBUG_PORT, Integer.toString(DEFAULT_DEBUG_PORT)); + int port = -1; + try { + port = Integer.parseInt(debugPort); + } catch(NumberFormatException nfe) { + port = DEFAULT_DEBUG_PORT; + } + if( port < 1 ) + port = DEFAULT_DEBUG_PORT; + return port; + } + + public ILaunch attachRemoteDebugger(IServer server, IProgressMonitor monitor) + throws CoreException { + return attachRemoteDebugger(server, getDebugPort(server), monitor); + } + + public ILaunch attachRemoteDebugger(IServer server, int localDebugPort, IProgressMonitor monitor) + throws CoreException { + monitor.subTask("Attaching remote debugger"); + ILaunch ret = null; + RemoteDebugUtils debugUtils = RemoteDebugUtils.get(); + ILaunchConfiguration debuggerLaunchConfig = debugUtils.getRemoteDebuggerLaunchConfiguration(server); + ILaunchConfigurationWorkingCopy workingCopy; + if (debuggerLaunchConfig == null) { + workingCopy = debugUtils.createRemoteDebuggerLaunchConfiguration(server); + } else { + if (debugUtils.isRunning(debuggerLaunchConfig, localDebugPort)) { + return null; + } + workingCopy = debuggerLaunchConfig.getWorkingCopy(); + } + + debugUtils.setupRemoteDebuggerLaunchConfiguration(workingCopy, null, localDebugPort, server.getHost()); + debuggerLaunchConfig = workingCopy.doSave(); + boolean launched = false; + try { + ret = debuggerLaunchConfig.launch("debug", new NullProgressMonitor()); + launched = true; + } catch (Exception e) { + e.printStackTrace(); + } + + if (!launched){ + throw toCoreException("Unable to start a remote debugger to localhost:"+localDebugPort); + } + + monitor.worked(10); + return ret; + } + + private CoreException toCoreException(String msg, Exception e) { + return new CoreException(StatusFactory.errorStatus(ASWTPToolsPlugin.PLUGIN_ID, msg, e)); + } + + private CoreException toCoreException(String msg) { + return toCoreException(msg, null); + } } diff --git a/as/plugins/org.jboss.ide.eclipse.as.wtp.core/src/org/jboss/ide/eclipse/as/wtp/core/server/launch/AbstractStartJavaServerLaunchDelegate.java b/as/plugins/org.jboss.ide.eclipse.as.wtp.core/src/org/jboss/ide/eclipse/as/wtp/core/server/launch/AbstractStartJavaServerLaunchDelegate.java index 49b0bfc4e7..2addd445d4 100644 --- a/as/plugins/org.jboss.ide.eclipse.as.wtp.core/src/org/jboss/ide/eclipse/as/wtp/core/server/launch/AbstractStartJavaServerLaunchDelegate.java +++ b/as/plugins/org.jboss.ide.eclipse.as.wtp.core/src/org/jboss/ide/eclipse/as/wtp/core/server/launch/AbstractStartJavaServerLaunchDelegate.java @@ -32,6 +32,7 @@ import org.jboss.ide.eclipse.as.wtp.core.ASWTPToolsPlugin; import org.jboss.ide.eclipse.as.wtp.core.Messages; import org.jboss.ide.eclipse.as.wtp.core.Trace; +import org.jboss.ide.eclipse.as.wtp.core.debug.RemoteDebugUtils; import org.jboss.ide.eclipse.as.wtp.core.server.behavior.ControllableServerBehavior; import org.jboss.ide.eclipse.as.wtp.core.server.behavior.IControllableServerBehavior; @@ -108,6 +109,13 @@ public boolean preLaunchCheck(ILaunchConfiguration configuration, String mode, I Trace.trace(Trace.STRING_FINEST, "Server is marked as ignore Launch. Marking as started."); //$NON-NLS-1$ ((ControllableServerBehavior)jbsBehavior).setRunMode(mode); ((ControllableServerBehavior)jbsBehavior).setServerStarting(); + boolean attachDebugger = server.getAttribute(RemoteDebugUtils.ATTACH_DEBUGGER, true); + if( "debug".equals(mode) && attachDebugger) { + // add a listener which will run the debugger once server is started + IServerListener listener = createAttachDebuggerListener(); + server.addServerListener(listener); + } + initiatePolling(server); return false; } @@ -266,4 +274,13 @@ protected boolean overrideHotcodeReplace(ILaunchConfiguration configuration, ILa return added; } + + + /* + * Attaching remote debugger + */ + + private IServerListener createAttachDebuggerListener() { + return RemoteDebugUtils.get().createAttachDebuggerListener(); + } }