Search in sources :

Example 91 with ILaunchConfiguration

use of org.eclipse.debug.core.ILaunchConfiguration in project webtools.servertools by eclipse.

the class GenericServerBehaviour method shutdown.

/**
 * Shuts down the server via the launch configuration.
 */
protected void shutdown(int state) {
    GenericServerRuntime runtime = getRuntimeDelegate();
    try {
        // $NON-NLS-1$
        Trace.trace(Trace.FINEST, "Stopping Server");
        if (state != IServer.STATE_STOPPED)
            setServerState(IServer.STATE_STOPPING);
        String configTypeID = getConfigTypeID();
        ILaunchManager mgr = DebugPlugin.getDefault().getLaunchManager();
        ILaunchConfigurationType type = mgr.getLaunchConfigurationType(configTypeID);
        String launchName = getStopLaunchName();
        String uniqueLaunchName = mgr.generateUniqueLaunchConfigurationNameFrom(launchName);
        ILaunchConfiguration conf = null;
        ILaunchConfiguration[] lch = mgr.getLaunchConfigurations(type);
        for (int i = 0; i < lch.length; i++) {
            if (launchName.equals(lch[i].getName())) {
                conf = lch[i];
                break;
            }
        }
        ILaunchConfigurationWorkingCopy wc = null;
        if (conf != null) {
            wc = conf.getWorkingCopy();
        } else {
            wc = type.newInstance(null, uniqueLaunchName);
        }
        // To stop from appearing in history lists
        wc.setAttribute(IDebugUIConstants.ATTR_PRIVATE, true);
        // Set the stop attribute so that we know we are stopping
        // $NON-NLS-1$
        wc.setAttribute(ATTR_STOP, "true");
        // Set the server ID so that we can distinguish stops
        wc.setAttribute(ATTR_SERVER_ID, this.getServer().getId());
        // Setup the launch config for stopping the server
        setupStopLaunchConfiguration(runtime, wc);
        // Launch the stop launch config
        wc.launch(ILaunchManager.RUN_MODE, new NullProgressMonitor());
    } catch (Exception e) {
        // $NON-NLS-1$
        Trace.trace(Trace.SEVERE, "Error stopping Server", e);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunchManager(org.eclipse.debug.core.ILaunchManager) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) CoreException(org.eclipse.core.runtime.CoreException)

Example 92 with ILaunchConfiguration

use of org.eclipse.debug.core.ILaunchConfiguration in project webtools.servertools by eclipse.

the class ServerPropertiesEditorSection method init.

public void init(final IEditorSite site, IEditorInput input) {
    super.init(site, input);
    if (server != null) {
        fServer = (GenericServer) server.loadAdapter(GenericServer.class, new NullProgressMonitor());
    }
    fPropertyChangeListener = new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals(GenericServerRuntime.SERVER_INSTANCE_PROPERTIES)) {
                if (!fUpdating) {
                    fUpdating = true;
                    updateControls();
                    fUpdating = false;
                }
            }
        }
    };
    server.addPropertyChangeListener(fPropertyChangeListener);
    fLaunchListener = new ILaunchesListener2() {

        public void launchesRemoved(ILaunch[] launches) {
        // Nothing to do
        }

        private ILaunchConfiguration getServerLaunchConfig(ILaunch[] launches) {
            for (int i = 0; i < launches.length; i++) {
                ILaunchConfiguration launchConfig = launches[i].getLaunchConfiguration();
                if (launchConfig != null) {
                    String serverId;
                    try {
                        serverId = launchConfig.getAttribute(GenericServerBehaviour.ATTR_SERVER_ID, (String) null);
                        if (fServer.getServer().getId().equals(serverId)) {
                            return launchConfig;
                        }
                    } catch (CoreException e) {
                    // Ignore
                    }
                }
            }
            return null;
        }

        public void launchesChanged(ILaunch[] launches) {
        // Nothing to do
        }

        public void launchesAdded(ILaunch[] launches) {
            ILaunchConfiguration lc = getServerLaunchConfig(launches);
            try {
                if (lc != null) {
                    if ("true".equals(lc.getAttribute(GenericServerBehaviour.ATTR_STOP, "false"))) {
                        // $NON-NLS-1$ //$NON-NLS-2$
                        site.getWorkbenchWindow().getWorkbench().getDisplay().asyncExec(new Runnable() {

                            public void run() {
                                IManagedForm managedForm = getManagedForm();
                                managedForm.getMessageManager().removeMessage(MESSAGE_ID_SERVER_RUNNING);
                                managedForm.getMessageManager().update();
                            }
                        });
                    } else {
                        site.getWorkbenchWindow().getWorkbench().getDisplay().asyncExec(new Runnable() {

                            public void run() {
                                getManagedForm().getMessageManager().addMessage(MESSAGE_ID_SERVER_RUNNING, GenericServerUIMessages.serverRunningCanNotSave, null, IMessageProvider.WARNING);
                            }
                        });
                    }
                }
            } catch (CoreException e) {
                GenericUiPlugin.getDefault().getLog().log(e.getStatus());
            }
        }

        public void launchesTerminated(ILaunch[] launches) {
            if (getServerLaunchConfig(launches) != null) {
                site.getWorkbenchWindow().getWorkbench().getDisplay().asyncExec(new Runnable() {

                    public void run() {
                        getManagedForm().getMessageManager().removeMessage(MESSAGE_ID_SERVER_RUNNING);
                    }
                });
            }
        }
    };
    getLaunchManager().addLaunchListener(fLaunchListener);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) PropertyChangeEvent(java.beans.PropertyChangeEvent) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) PropertyChangeListener(java.beans.PropertyChangeListener) CoreException(org.eclipse.core.runtime.CoreException) IManagedForm(org.eclipse.ui.forms.IManagedForm) ILaunch(org.eclipse.debug.core.ILaunch) ILaunchesListener2(org.eclipse.debug.core.ILaunchesListener2)

Example 93 with ILaunchConfiguration

use of org.eclipse.debug.core.ILaunchConfiguration in project webtools.servertools by eclipse.

the class OverviewEditorPart method createGeneralSection.

protected void createGeneralSection(Composite leftColumnComp, FormToolkit toolkit) {
    Section section = toolkit.createSection(leftColumnComp, ExpandableComposite.TITLE_BAR | Section.DESCRIPTION);
    section.setText(Messages.serverEditorOverviewGeneralSection);
    section.setDescription(Messages.serverEditorOverviewGeneralDescription);
    section.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));
    Composite composite = toolkit.createComposite(section);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    layout.marginHeight = 5;
    layout.marginWidth = 10;
    layout.verticalSpacing = 5;
    layout.horizontalSpacing = 5;
    composite.setLayout(layout);
    composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));
    IWorkbenchHelpSystem whs = PlatformUI.getWorkbench().getHelpSystem();
    whs.setHelp(composite, ContextIds.EDITOR_OVERVIEW_PAGE);
    toolkit.paintBordersFor(composite);
    section.setClient(composite);
    int decorationWidth = FieldDecorationRegistry.getDefault().getMaximumDecorationWidth();
    // server name
    if (server != null) {
        createLabel(toolkit, composite, Messages.serverEditorOverviewServerName);
        serverName = toolkit.createText(composite, server.getName());
        GridData data = new GridData(GridData.FILL_HORIZONTAL);
        data.horizontalSpan = 2;
        data.horizontalIndent = decorationWidth;
        serverName.setLayoutData(data);
        serverName.addModifyListener(new ModifyListener() {

            public void modifyText(ModifyEvent e) {
                if (updating)
                    return;
                updating = true;
                execute(new SetServerNameCommand(getServer(), serverName.getText(), new SetServerNameCommand.Validator() {

                    public void validate() {
                        OverviewEditorPart.this.validate();
                    }
                }));
                updating = false;
            }
        });
        whs.setHelp(serverName, ContextIds.EDITOR_SERVER);
        // hostname
        hostnameLabel = createLabel(toolkit, composite, Messages.serverEditorOverviewServerHostname);
        hostname = toolkit.createText(composite, server.getHost());
        hostnameDecoration = new ControlDecoration(hostname, SWT.TOP | SWT.LEAD);
        data = new GridData(GridData.FILL_HORIZONTAL);
        data.horizontalSpan = 2;
        data.horizontalIndent = decorationWidth;
        hostname.setLayoutData(data);
        hostname.addModifyListener(new ModifyListener() {

            public void modifyText(ModifyEvent e) {
                if (updating)
                    return;
                updating = true;
                execute(new SetServerHostnameCommand(getServer(), hostname.getText()));
                updating = false;
            }
        });
        whs.setHelp(hostname, ContextIds.EDITOR_HOSTNAME);
        FieldDecorationRegistry registry = FieldDecorationRegistry.getDefault();
        FieldDecoration fd = registry.getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
        hostnameDecoration.setImage(fd.getImage());
        hostnameDecoration.setDescriptionText(fd.getDescription());
        hostnameDecoration.hide();
        hostname.addFocusListener(new FocusListener() {

            public void focusGained(FocusEvent e) {
                hostnameDecoration.show();
            }

            public void focusLost(FocusEvent e) {
                hostnameDecoration.hide();
            }
        });
        // updateDecoration(hostnameDecoration, new Status(IStatus.INFO, ServerUIPlugin.PLUGIN_ID, "Press Ctrl-Space"));
        List<String> hosts = ServerUIPlugin.getPreferences().getHostnames();
        String[] hosts2 = hosts.toArray(new String[hosts.size()]);
        new AutoCompleteField(hostname, new TextContentAdapter(), hosts2);
    }
    // runtime
    if (server != null && server.getServerType() != null && server.getServerType().hasRuntime()) {
        final Hyperlink link = toolkit.createHyperlink(composite, Messages.serverEditorOverviewRuntime, SWT.NONE);
        final IServerWorkingCopy server2 = server;
        link.addHyperlinkListener(new HyperlinkAdapter() {

            public void linkActivated(HyperlinkEvent e) {
                IRuntime runtime = server2.getRuntime();
                if (runtime != null && ServerUIPlugin.hasWizardFragment(runtime.getRuntimeType().getId()))
                    editRuntime(runtime);
            }
        });
        final IRuntime runtime = server.getRuntime();
        if (runtime == null || !ServerUIPlugin.hasWizardFragment(runtime.getRuntimeType().getId()))
            link.setEnabled(false);
        IRuntimeType runtimeType = server.getServerType().getRuntimeType();
        runtimes = ServerUIPlugin.getRuntimes(runtimeType);
        runtimeCombo = new Combo(composite, SWT.READ_ONLY);
        GridData data = new GridData(GridData.FILL_HORIZONTAL);
        data.horizontalIndent = decorationWidth;
        data.horizontalSpan = 2;
        runtimeCombo.setLayoutData(data);
        updateRuntimeCombo();
        int size = runtimes.length;
        for (int i = 0; i < size; i++) {
            if (runtimes[i].equals(runtime))
                runtimeCombo.select(i);
        }
        runtimeCombo.addSelectionListener(new SelectionListener() {

            public void widgetSelected(SelectionEvent e) {
                try {
                    if (updating)
                        return;
                    updating = true;
                    IRuntime newRuntime = runtimes[runtimeCombo.getSelectionIndex()];
                    execute(new SetServerRuntimeCommand(getServer(), newRuntime));
                    link.setEnabled(newRuntime != null && ServerUIPlugin.hasWizardFragment(newRuntime.getRuntimeType().getId()));
                    updating = false;
                } catch (Exception ex) {
                // ignore
                }
            }

            public void widgetDefaultSelected(SelectionEvent e) {
                widgetSelected(e);
            }
        });
        whs.setHelp(runtimeCombo, ContextIds.EDITOR_RUNTIME);
        // add runtime listener
        runtimeListener = new IRuntimeLifecycleListener() {

            public void runtimeChanged(final IRuntime runtime2) {
                // may be name change of current runtime
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        if (runtime2.equals(getServer().getRuntime())) {
                            try {
                                if (updating)
                                    return;
                                updating = true;
                                execute(new SetServerRuntimeCommand(getServer(), runtime2));
                                updating = false;
                            } catch (Exception ex) {
                            // ignore
                            }
                        }
                        if (runtimeCombo != null && !runtimeCombo.isDisposed()) {
                            updateRuntimeCombo();
                            int size2 = runtimes.length;
                            for (int i = 0; i < size2; i++) {
                                if (runtimes[i].equals(runtime))
                                    runtimeCombo.select(i);
                            }
                        }
                    }
                });
            }

            public void runtimeAdded(final IRuntime runtime2) {
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        if (runtimeCombo != null && !runtimeCombo.isDisposed()) {
                            updateRuntimeCombo();
                            int size2 = runtimes.length;
                            for (int i = 0; i < size2; i++) {
                                if (runtimes[i].equals(runtime))
                                    runtimeCombo.select(i);
                            }
                        }
                    }
                });
            }

            public void runtimeRemoved(IRuntime runtime2) {
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        if (runtimeCombo != null && !runtimeCombo.isDisposed()) {
                            updateRuntimeCombo();
                            int size2 = runtimes.length;
                            for (int i = 0; i < size2; i++) {
                                if (runtimes[i].equals(runtime))
                                    runtimeCombo.select(i);
                            }
                        }
                    }
                });
            }
        };
        ServerCore.addRuntimeLifecycleListener(runtimeListener);
    }
    // server configuration path
    if (server != null && server.getServerType() != null && server.getServerType().hasServerConfiguration()) {
        createLabel(toolkit, composite, Messages.serverEditorOverviewServerConfigurationPath);
        IFolder folder = server.getServerConfiguration();
        if (folder == null)
            serverConfiguration = toolkit.createText(composite, Messages.elementUnknownName);
        else
            serverConfiguration = toolkit.createText(composite, "" + server.getServerConfiguration().getFullPath());
        serverConfiguration.setEditable(false);
        GridData data = new GridData(GridData.FILL_HORIZONTAL);
        data.horizontalIndent = decorationWidth;
        data.widthHint = 75;
        serverConfiguration.setLayoutData(data);
        whs.setHelp(serverConfiguration, ContextIds.EDITOR_CONFIGURATION);
        final IFolder currentFolder = server.getServerConfiguration();
        browse = toolkit.createButton(composite, Messages.serverEditorOverviewServerConfigurationBrowse, SWT.PUSH);
        browse.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent e) {
                ContainerSelectionDialog dialog = new ContainerSelectionDialog(serverConfiguration.getShell(), currentFolder, true, Messages.serverEditorOverviewServerConfigurationBrowseMessage);
                dialog.showClosedProjects(false);
                if (dialog.open() != Window.CANCEL) {
                    Object[] result = dialog.getResult();
                    if (result != null && result.length == 1) {
                        IPath path = (IPath) result[0];
                        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
                        IResource resource = root.findMember(path);
                        if (resource != null && resource instanceof IFolder) {
                            IFolder folder2 = (IFolder) resource;
                            if (updating)
                                return;
                            updating = true;
                            execute(new SetServerConfigurationFolderCommand(getServer(), folder2));
                            serverConfiguration.setText(folder2.getFullPath().toString());
                            updating = false;
                        }
                    }
                }
            }
        });
        browse.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
    }
    IServerType serverType = null;
    if (server != null && server.getServerType() != null) {
        serverType = server.getServerType();
        if (serverType.supportsLaunchMode(ILaunchManager.RUN_MODE) || serverType.supportsLaunchMode(ILaunchManager.DEBUG_MODE) || serverType.supportsLaunchMode(ILaunchManager.PROFILE_MODE)) {
            ILaunchConfigurationType launchType = ((ServerType) serverType).getLaunchConfigurationType();
            if (launchType != null && launchType.isPublic()) {
                final Hyperlink link = toolkit.createHyperlink(composite, Messages.serverEditorOverviewOpenLaunchConfiguration, SWT.NONE);
                GridData data = new GridData();
                data.horizontalSpan = 3;
                link.setLayoutData(data);
                link.addHyperlinkListener(new HyperlinkAdapter() {

                    public void linkActivated(HyperlinkEvent e) {
                        IEditorPart part = ((MultiPageEditorSite) getSite()).getMultiPageEditor();
                        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                        page.saveEditor(part, true);
                        try {
                            ILaunchConfiguration launchConfig = ((Server) getServer()).getLaunchConfiguration(true, null);
                            // TODO: use correct launch group
                            DebugUITools.openLaunchConfigurationPropertiesDialog(link.getShell(), launchConfig, "org.eclipse.debug.ui.launchGroup.run");
                        } catch (CoreException ce) {
                            if (Trace.SEVERE) {
                                Trace.trace(Trace.STRING_SEVERE, "Could not create launch configuration", ce);
                            }
                        }
                    }
                });
            }
        }
    }
    // Insertion of extension widgets. If the page modifier createControl is not implemented still
    // add the modifier to the listeners list.
    List<ServerEditorOverviewPageModifier> pageModifiersLst = getPageModifiers(serverType == null ? null : serverType.getId());
    for (ServerEditorOverviewPageModifier curPageModifier : pageModifiersLst) {
        if (server != null && server.getServerType() != null) {
            curPageModifier.setServerWorkingCopy(server);
            curPageModifier.setServerEditorPart(this);
            curPageModifier.setFormToolkit(toolkit);
            curPageModifier.createControl(ServerEditorOverviewPageModifier.UI_LOCATION.OVERVIEW, composite);
            curPageModifier.setUIControlListener(this);
        }
    }
}
Also used : ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ContainerSelectionDialog(org.eclipse.ui.dialogs.ContainerSelectionDialog) HyperlinkEvent(org.eclipse.ui.forms.events.HyperlinkEvent) GridLayout(org.eclipse.swt.layout.GridLayout) IWorkbenchHelpSystem(org.eclipse.ui.help.IWorkbenchHelpSystem) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ServerEditorOverviewPageModifier(org.eclipse.wst.server.ui.editor.ServerEditorOverviewPageModifier) GridData(org.eclipse.swt.layout.GridData) HyperlinkAdapter(org.eclipse.ui.forms.events.HyperlinkAdapter)

Example 94 with ILaunchConfiguration

use of org.eclipse.debug.core.ILaunchConfiguration in project jbosstools-openshift by jbosstools.

the class ExternalLaunchUtil method findExternalToolsLaunchConfig.

public static ILaunchConfigurationWorkingCopy findExternalToolsLaunchConfig(IServer s, String launchName) throws CoreException {
    ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
    ILaunchConfigurationType type = manager.getLaunchConfigurationType(EXTERNAL_TOOLS);
    ILaunchConfiguration[] all = manager.getLaunchConfigurations(type);
    for (int i = 0; i < all.length; i++) {
        if (all[i].getName().equals(launchName)) {
            return all[i].getWorkingCopy();
        }
    }
    ILaunchConfigurationWorkingCopy wc = type.newInstance(null, launchName);
    return wc;
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunchManager(org.eclipse.debug.core.ILaunchManager) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)

Example 95 with ILaunchConfiguration

use of org.eclipse.debug.core.ILaunchConfiguration in project jbosstools-openshift by jbosstools.

the class CDKLaunchEnvironmentUtil method createEnvironment.

public static Map<String, String> createEnvironment(IServer server, String password, String user) {
    Map<String, String> launchEnv = null;
    try {
        ILaunchConfiguration wc = server.getLaunchConfiguration(false, new NullProgressMonitor());
        if (wc != null)
            launchEnv = wc.getAttribute(IExternalLaunchConstants.ENVIRONMENT_VARS_KEY, (Map<String, String>) null);
    } catch (CoreException ce) {
        CDKCoreActivator.pluginLog().logWarning("Unable to load environment for vagrant status call. System environment will be used instead.");
    }
    HashMap<String, String> systemEnv = new HashMap<>(System.getenv());
    if (launchEnv != null) {
        Iterator<String> it = launchEnv.keySet().iterator();
        String k = null;
        while (it.hasNext()) {
            k = it.next();
            systemEnv.put(k, launchEnv.get(k));
        }
    }
    CDKServer cdkServer = (CDKServer) server.loadAdapter(CDKServer.class, new NullProgressMonitor());
    boolean passCredentials = cdkServer.passCredentials();
    String userKey = cdkServer.getUserEnvironmentKey();
    String passKey = cdkServer.getPasswordEnvironmentKey();
    if (passCredentials) {
        systemEnv.put(userKey, user);
        systemEnv.put(passKey, password);
    } else {
        systemEnv.remove(userKey);
        systemEnv.remove(passKey);
    }
    return systemEnv;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) CoreException(org.eclipse.core.runtime.CoreException) HashMap(java.util.HashMap) CDKServer(org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer)

Aggregations

ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)275 CoreException (org.eclipse.core.runtime.CoreException)100 ILaunchConfigurationWorkingCopy (org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)79 Test (org.junit.Test)72 ILaunchConfigurationType (org.eclipse.debug.core.ILaunchConfigurationType)51 ILaunchManager (org.eclipse.debug.core.ILaunchManager)41 ArrayList (java.util.ArrayList)37 ILaunch (org.eclipse.debug.core.ILaunch)37 IPath (org.eclipse.core.runtime.IPath)20 IProject (org.eclipse.core.resources.IProject)19 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)17 IStatus (org.eclipse.core.runtime.IStatus)16 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)16 IEditorPart (org.eclipse.ui.IEditorPart)15 IProcess (org.eclipse.debug.core.model.IProcess)14 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)14 IFile (org.eclipse.core.resources.IFile)13 Status (org.eclipse.core.runtime.Status)13 CachegrindViewPart (org.eclipse.linuxtools.internal.valgrind.cachegrind.CachegrindViewPart)13 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)11